esp32_nimble/
enums.rs

1use bitflags::bitflags;
2use esp_idf_svc::sys::*;
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4
5#[repr(u8)]
6#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
7pub enum SecurityIOCap {
8    /// DisplayOnly IO capability
9    DisplayOnly = BLE_HS_IO_DISPLAY_ONLY as _,
10    /// DisplayYesNo IO capability
11    DisplayYesNo = BLE_HS_IO_DISPLAY_YESNO as _,
12    /// KeyboardOnly IO capability
13    KeyboardOnly = BLE_HS_IO_KEYBOARD_ONLY as _,
14    /// NoInputNoOutput IO capability
15    NoInputNoOutput = BLE_HS_IO_NO_INPUT_OUTPUT as _,
16    /// KeyboardDisplay Only IO capability
17    KeyboardDisplay = BLE_HS_IO_KEYBOARD_DISPLAY as _,
18}
19
20#[repr(u32)]
21#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
22pub enum PowerLevel {
23    /// Corresponding to -12dbm
24    N12 = esp_power_level_t_ESP_PWR_LVL_N12 as _,
25    /// Corresponding to  -9dbm
26    N9 = esp_power_level_t_ESP_PWR_LVL_N9 as _,
27    /// Corresponding to  -6dbm
28    N6 = esp_power_level_t_ESP_PWR_LVL_N6 as _,
29    /// Corresponding to  -3dbm
30    N3 = esp_power_level_t_ESP_PWR_LVL_N3 as _,
31    /// Corresponding to   0dbm
32    N0 = esp_power_level_t_ESP_PWR_LVL_N0 as _,
33    /// Corresponding to  +3dbm
34    P3 = esp_power_level_t_ESP_PWR_LVL_P3 as _,
35    /// Corresponding to  +6dbm
36    P6 = esp_power_level_t_ESP_PWR_LVL_P6 as _,
37    /// Corresponding to  +9dbm
38    P9 = esp_power_level_t_ESP_PWR_LVL_P9 as _,
39}
40
41impl PowerLevel {
42    pub fn to_dbm(&self) -> i8 {
43        match self {
44            PowerLevel::N12 => -12,
45            PowerLevel::N9 => -9,
46            PowerLevel::N6 => -6,
47            PowerLevel::N3 => -3,
48            PowerLevel::N0 => 0,
49            PowerLevel::P3 => 3,
50            PowerLevel::P6 => 6,
51            PowerLevel::P9 => 9,
52        }
53    }
54}
55
56#[repr(u32)]
57#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
58pub enum PowerType {
59    /// For connection handle 0
60    ConnHdl0 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL0 as _,
61    /// For connection handle 1
62    ConnHdl1 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL1 as _,
63    /// For connection handle 2
64    ConnHdl2 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL2 as _,
65    /// For connection handle 3
66    ConnHdl3 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL3 as _,
67    /// For connection handle 4
68    ConnHdl4 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL4 as _,
69    /// For connection handle 5
70    ConnHdl5 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL5 as _,
71    /// For connection handle 6
72    ConnHdl6 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL6 as _,
73    /// For connection handle 7
74    ConnHdl7 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL7 as _,
75    /// For connection handle 8
76    ConnHdl8 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL8 as _,
77    /// For advertising
78    Advertising = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_ADV as _,
79    /// For scan
80    Scan = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_SCAN as _,
81    /// For default, if not set other, it will use default value
82    Default = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_DEFAULT as _,
83}
84
85#[repr(u8)]
86#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
87pub enum OwnAddrType {
88    Public = BLE_OWN_ADDR_PUBLIC as _,
89    Random = BLE_OWN_ADDR_RANDOM as _,
90    RpaPublicDefault = BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT as _,
91    RpaRandomDefault = BLE_OWN_ADDR_RPA_RANDOM_DEFAULT as _,
92}
93
94#[repr(u8)]
95#[derive(Copy, Clone, PartialEq, Debug)]
96pub enum ConnMode {
97    /// non-connectable (3.C.9.3.2)
98    Non = BLE_GAP_CONN_MODE_NON as _,
99    /// directed-connectable (3.C.9.3.3)
100    Dir = BLE_GAP_CONN_MODE_DIR as _,
101    /// undirected-connectable (3.C.9.3.4)
102    Und = BLE_GAP_CONN_MODE_UND as _,
103}
104
105#[repr(u8)]
106#[derive(Copy, Clone, PartialEq, Debug)]
107pub enum DiscMode {
108    /// non-discoverable; 3.C.9.2.2
109    Non = BLE_GAP_DISC_MODE_NON as _,
110    /// limited-discoverable; 3.C.9.2.3
111    Ltd = BLE_GAP_DISC_MODE_LTD as _,
112    /// general-discoverable; 3.C.9.2.4
113    Gen = BLE_GAP_DISC_MODE_GEN as _,
114}
115
116bitflags! {
117  #[repr(transparent)]
118  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
119  pub struct PairKeyDist: u8 {
120    /// Accept/Distribute the encryption key.
121    const ENC = BLE_SM_PAIR_KEY_DIST_ENC as _;
122    /// Accept/Distribute the ID key (IRK).
123    const ID = BLE_SM_PAIR_KEY_DIST_ID as _;
124    const SIGN = BLE_SM_PAIR_KEY_DIST_SIGN as _;
125    const LINK = BLE_SM_PAIR_KEY_DIST_LINK as _;
126  }
127}
128
129bitflags! {
130  #[repr(transparent)]
131  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
132  pub struct AuthReq: u8 {
133    /// allow bounding
134    const Bond = 0b001;
135    /// man in the middle protection
136    const Mitm = 0b010;
137    /// secure connection pairing
138    const Sc = 0b100;
139  }
140}
141
142#[derive(Copy, Clone, PartialEq, Debug)]
143pub enum AdvType {
144    /// indirect advertising
145    Ind,
146    /// direct advertising
147    DirectInd,
148    /// indirect scan response
149    ScanInd,
150    /// indirect advertising - not connectable
151    NonconnInd,
152    ScanResponse,
153    #[cfg(esp_idf_bt_nimble_ext_adv)]
154    Extended(u8),
155}
156
157impl AdvType {
158    pub(crate) fn from_event_type(event_type: u8) -> Self {
159        match event_type as u32 {
160            BLE_HCI_ADV_RPT_EVTYPE_ADV_IND => AdvType::Ind,
161            BLE_HCI_ADV_RPT_EVTYPE_DIR_IND => AdvType::DirectInd,
162            BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND => AdvType::ScanInd,
163            BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND => AdvType::NonconnInd,
164            BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP => AdvType::ScanResponse,
165            5.. => unreachable!(),
166        }
167    }
168}
169
170bitflags! {
171  #[repr(transparent)]
172  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
173  pub struct AdvFlag: u8 {
174    /// LE Limited Discoverable Mode
175    const DiscLimited = BLE_HS_ADV_F_DISC_LTD as _;
176    /// LE General Discoverable Mode
177    const DiscGeneral = BLE_HS_ADV_F_DISC_GEN as _;
178    /// BR/EDR Not Supported
179    const BrEdrUnsupported = BLE_HS_ADV_F_BREDR_UNSUP as _;
180    /// Simultaneous LE and BR/EDR to Same Device Capable (Controller)
181    const SimultaneousController = 0b01000;
182    /// Simultaneous LE and BR/EDR to Same Device Capable (Host)
183    const SimultaneousHost       = 0b10000;
184  }
185}
186
187#[repr(u8)]
188#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
189pub enum ScanFilterPolicy {
190    /// Scanner processes all advertising packets (white list not used)
191    /// except directed, connectable advertising packets not sent to the scanner.
192    NoWl = BLE_HCI_SCAN_FILT_NO_WL as _,
193    /// Scanner processes advertisements from white list only.
194    /// A connectable, directed advertisement is ignored unless it contains scanners address.
195    UseWl = BLE_HCI_SCAN_FILT_USE_WL as _,
196    /// Scanner process all advertising packets (white list not used).
197    /// A connectable, directed advertisement shall not be ignored if the InitA is a resolvable private address.
198    NoWlInitA = BLE_HCI_SCAN_FILT_NO_WL_INITA as _,
199    /// Scanner process advertisements from white list only.
200    /// A connectable, directed advertisement shall not be ignored if the InitA is a resolvable private address.
201    UseWlInitA = BLE_HCI_SCAN_FILT_USE_WL_INITA as _,
202}
203
204#[repr(u8)]
205#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
206pub enum AdvFilterPolicy {
207    /// No filtering
208    None = BLE_HCI_ADV_FILT_NONE as _,
209    /// only allow scan requests from those on the white list.
210    Scan = BLE_HCI_ADV_FILT_SCAN as _,
211    /// only allow connections from those on the white list.
212    Connect = BLE_HCI_ADV_FILT_CONN as _,
213    /// only allow scan/connections from those on the white list.
214    Both = BLE_HCI_ADV_FILT_BOTH as _,
215}
216
217#[repr(u8)]
218#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
219pub enum PrimPhy {
220    /// 1Mbps phy
221    Phy1M = BLE_HCI_LE_PHY_1M as _,
222    /// Coded phy
223    Coded = BLE_HCI_LE_PHY_CODED as _,
224}
225
226#[repr(u8)]
227#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
228pub enum SecPhy {
229    /// 1Mbps phy
230    Phy1M = BLE_HCI_LE_PHY_1M as _,
231    /// 2Mbps phy
232    Phy2M = BLE_HCI_LE_PHY_2M as _,
233    /// Coded phy
234    Coded = BLE_HCI_LE_PHY_CODED as _,
235}