bluetooth_hci/
opcode.rs

1/// Newtype wrapper for a Bluetooth Opcode. Opcodes are used to indicate which command to send to
2/// the Controller as well as which command results are returned by the Command Complete and Command
3/// Status events.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub struct Opcode(pub u16);
6
7impl Opcode {
8    /// Create an opcode from the OGF (Opcode group field) and OCF (Opcode command field).
9    pub const fn new(ogf: u16, ocf: u16) -> Opcode {
10        Opcode((ogf << 10) | (ocf & 0x03ff))
11    }
12
13    /// Return the OGF (Opcode group field) of the opcode.
14    pub fn ogf(&self) -> u16 {
15        self.0 >> 10
16    }
17
18    /// Return the OCF (Opcode command field) of the opcode.
19    pub fn ocf(&self) -> u16 {
20        self.0 & 0x03ff
21    }
22}
23
24macro_rules! opcodes {
25    (
26        $(
27            $_ogf_comment:ident = $ogf:expr;
28            {
29                $(pub const $var:ident = $ocf:expr;)+
30            }
31        )+
32    ) => {
33        $($(
34            pub const $var: Opcode = Opcode::new($ogf, $ocf);
35        )+)+
36    }
37}
38
39opcodes! {
40    LinkControl = 0x0001;
41    {
42        pub const DISCONNECT = 0x0006;
43        pub const READ_REMOTE_VERSION_INFO = 0x001D;
44    }
45
46    ControllerOrBaseband = 0x0003;
47    {
48        pub const SET_EVENT_MASK = 0x0001;
49        pub const RESET = 0x0003;
50        pub const READ_TX_POWER_LEVEL = 0x002D;
51    }
52
53    InfoParam = 0x0004;
54    {
55        pub const READ_LOCAL_VERSION_INFO = 0x0001;
56        pub const READ_LOCAL_SUPPORTED_COMMANDS = 0x0002;
57        pub const READ_LOCAL_SUPPORTED_FEATURES = 0x0003;
58        pub const READ_BD_ADDR = 0x0009;
59    }
60
61    StatusParam = 0x0005;
62    {
63        pub const READ_RSSI = 0x0005;
64    }
65
66    LeCommands = 0x0008;
67    {
68        pub const LE_SET_EVENT_MASK = 0x0001;
69        pub const LE_READ_BUFFER_SIZE = 0x0002;
70        pub const LE_READ_LOCAL_SUPPORTED_FEATURES = 0x0003;
71        pub const LE_SET_RANDOM_ADDRESS = 0x0005;
72        pub const LE_SET_ADVERTISING_PARAMETERS = 0x0006;
73        pub const LE_READ_ADVERTISING_CHANNEL_TX_POWER = 0x0007;
74        pub const LE_SET_ADVERTISING_DATA = 0x0008;
75        pub const LE_SET_SCAN_RESPONSE_DATA = 0x0009;
76        pub const LE_SET_ADVERTISE_ENABLE = 0x000A;
77        pub const LE_SET_SCAN_PARAMETERS = 0x000B;
78        pub const LE_SET_SCAN_ENABLE = 0x000C;
79        pub const LE_CREATE_CONNECTION = 0x000D;
80        pub const LE_CREATE_CONNECTION_CANCEL = 0x000E;
81        pub const LE_READ_WHITE_LIST_SIZE = 0x000F;
82        pub const LE_CLEAR_WHITE_LIST = 0x0010;
83        pub const LE_ADD_DEVICE_TO_WHITE_LIST = 0x0011;
84        pub const LE_REMOVE_DEVICE_FROM_WHITE_LIST = 0x0012;
85        pub const LE_CONNECTION_UPDATE = 0x0013;
86        pub const LE_SET_HOST_CHANNEL_CLASSIFICATION = 0x0014;
87        pub const LE_READ_CHANNEL_MAP = 0x0015;
88        pub const LE_READ_REMOTE_USED_FEATURES = 0x0016;
89        pub const LE_ENCRYPT = 0x0017;
90        pub const LE_RAND = 0x0018;
91        pub const LE_START_ENCRYPTION = 0x0019;
92        pub const LE_LTK_REQUEST_REPLY = 0x001A;
93        pub const LE_LTK_REQUEST_NEGATIVE_REPLY = 0x001B;
94        pub const LE_READ_STATES = 0x001C;
95        pub const LE_RECEIVER_TEST = 0x001D;
96        pub const LE_TRANSMITTER_TEST = 0x001E;
97        pub const LE_TEST_END = 0x001F;
98    }
99}