1 //! This module lets us classify AttOpcodes to determine how to handle them
2
3 use crate::packets::att::AttOpcode;
4
5 /// The type of ATT operation performed by the packet
6 /// (see Core Spec 5.3 Vol 3F 3.3 Attribute PDU for details)
7 pub enum OperationType {
8 /// Client -> server, no response expected
9 Command,
10 /// Client -> server, response expected
11 Request,
12 /// Server -> client, response to a request
13 Response,
14 /// Server -> client, no response expected
15 Notification,
16 /// Server -> client, response expected
17 Indication,
18 /// Client -> server, response to an indication
19 Confirmation,
20 }
21
22 /// Classify an opcode by its operation type. Note that this could be done using
23 /// bitmasking, but is done explicitly for clarity.
classify_opcode(opcode: AttOpcode) -> OperationType24 pub fn classify_opcode(opcode: AttOpcode) -> OperationType {
25 match opcode {
26 AttOpcode::ErrorResponse => OperationType::Response,
27 AttOpcode::ExchangeMtuResponse => OperationType::Response,
28 AttOpcode::FindInformationResponse => OperationType::Response,
29 AttOpcode::FindByTypeValueResponse => OperationType::Response,
30 AttOpcode::ReadByTypeResponse => OperationType::Response,
31 AttOpcode::ReadResponse => OperationType::Response,
32 AttOpcode::ReadBlobResponse => OperationType::Response,
33 AttOpcode::ReadMultipleResponse => OperationType::Response,
34 AttOpcode::ReadByGroupTypeResponse => OperationType::Response,
35 AttOpcode::WriteResponse => OperationType::Response,
36 AttOpcode::PrepareWriteResponse => OperationType::Response,
37 AttOpcode::ExecuteWriteResponse => OperationType::Response,
38 AttOpcode::ReadMultipleVariableResponse => OperationType::Response,
39
40 AttOpcode::ExchangeMtuRequest => OperationType::Request,
41 AttOpcode::FindInformationRequest => OperationType::Request,
42 AttOpcode::FindByTypeValueRequest => OperationType::Request,
43 AttOpcode::ReadByTypeRequest => OperationType::Request,
44 AttOpcode::ReadRequest => OperationType::Request,
45 AttOpcode::ReadBlobRequest => OperationType::Request,
46 AttOpcode::ReadMultipleRequest => OperationType::Request,
47 AttOpcode::ReadByGroupTypeRequest => OperationType::Request,
48 AttOpcode::WriteRequest => OperationType::Request,
49 AttOpcode::PrepareWriteRequest => OperationType::Request,
50 AttOpcode::ExecuteWriteRequest => OperationType::Request,
51 AttOpcode::ReadMultipleVariableRequest => OperationType::Request,
52
53 AttOpcode::WriteCommand => OperationType::Command,
54 AttOpcode::SignedWriteCommand => OperationType::Command,
55
56 AttOpcode::HandleValueNotification => OperationType::Notification,
57
58 AttOpcode::HandleValueIndication => OperationType::Indication,
59
60 AttOpcode::HandleValueConfirmation => OperationType::Confirmation,
61 }
62 }
63