1 //! This module lets us classify AttOpcodes to determine how to handle them
2
3 use crate::packets::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::ERROR_RESPONSE => OperationType::Response,
27 AttOpcode::EXCHANGE_MTU_RESPONSE => OperationType::Response,
28 AttOpcode::FIND_INFORMATION_RESPONSE => OperationType::Response,
29 AttOpcode::FIND_BY_TYPE_VALUE_RESPONSE => OperationType::Response,
30 AttOpcode::READ_BY_TYPE_RESPONSE => OperationType::Response,
31 AttOpcode::READ_RESPONSE => OperationType::Response,
32 AttOpcode::READ_BLOB_RESPONSE => OperationType::Response,
33 AttOpcode::READ_MULTIPLE_RESPONSE => OperationType::Response,
34 AttOpcode::READ_BY_GROUP_TYPE_RESPONSE => OperationType::Response,
35 AttOpcode::WRITE_RESPONSE => OperationType::Response,
36 AttOpcode::PREPARE_WRITE_RESPONSE => OperationType::Response,
37 AttOpcode::EXECUTE_WRITE_RESPONSE => OperationType::Response,
38 AttOpcode::READ_MULTIPLE_VARIABLE_RESPONSE => OperationType::Response,
39
40 AttOpcode::EXCHANGE_MTU_REQUEST => OperationType::Request,
41 AttOpcode::FIND_INFORMATION_REQUEST => OperationType::Request,
42 AttOpcode::FIND_BY_TYPE_VALUE_REQUEST => OperationType::Request,
43 AttOpcode::READ_BY_TYPE_REQUEST => OperationType::Request,
44 AttOpcode::READ_REQUEST => OperationType::Request,
45 AttOpcode::READ_BLOB_REQUEST => OperationType::Request,
46 AttOpcode::READ_MULTIPLE_REQUEST => OperationType::Request,
47 AttOpcode::READ_BY_GROUP_TYPE_REQUEST => OperationType::Request,
48 AttOpcode::WRITE_REQUEST => OperationType::Request,
49 AttOpcode::PREPARE_WRITE_REQUEST => OperationType::Request,
50 AttOpcode::EXECUTE_WRITE_REQUEST => OperationType::Request,
51 AttOpcode::READ_MULTIPLE_VARIABLE_REQUEST => OperationType::Request,
52
53 AttOpcode::WRITE_COMMAND => OperationType::Command,
54 AttOpcode::SIGNED_WRITE_COMMAND => OperationType::Command,
55
56 AttOpcode::HANDLE_VALUE_NOTIFICATION => OperationType::Notification,
57
58 AttOpcode::HANDLE_VALUE_INDICATION => OperationType::Indication,
59
60 AttOpcode::HANDLE_VALUE_CONFIRMATION => OperationType::Confirmation,
61 }
62 }
63