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 = BLE_HS_IO_DISPLAY_ONLY as _,
10 DisplayYesNo = BLE_HS_IO_DISPLAY_YESNO as _,
12 KeyboardOnly = BLE_HS_IO_KEYBOARD_ONLY as _,
14 NoInputNoOutput = BLE_HS_IO_NO_INPUT_OUTPUT as _,
16 KeyboardDisplay = BLE_HS_IO_KEYBOARD_DISPLAY as _,
18}
19
20#[repr(u32)]
21#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
22pub enum PowerLevel {
23 N12 = esp_power_level_t_ESP_PWR_LVL_N12 as _,
25 N9 = esp_power_level_t_ESP_PWR_LVL_N9 as _,
27 N6 = esp_power_level_t_ESP_PWR_LVL_N6 as _,
29 N3 = esp_power_level_t_ESP_PWR_LVL_N3 as _,
31 N0 = esp_power_level_t_ESP_PWR_LVL_N0 as _,
33 P3 = esp_power_level_t_ESP_PWR_LVL_P3 as _,
35 P6 = esp_power_level_t_ESP_PWR_LVL_P6 as _,
37 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 ConnHdl0 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL0 as _,
61 ConnHdl1 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL1 as _,
63 ConnHdl2 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL2 as _,
65 ConnHdl3 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL3 as _,
67 ConnHdl4 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL4 as _,
69 ConnHdl5 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL5 as _,
71 ConnHdl6 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL6 as _,
73 ConnHdl7 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL7 as _,
75 ConnHdl8 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL8 as _,
77 Advertising = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_ADV as _,
79 Scan = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_SCAN as _,
81 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 = BLE_GAP_CONN_MODE_NON as _,
99 Dir = BLE_GAP_CONN_MODE_DIR as _,
101 Und = BLE_GAP_CONN_MODE_UND as _,
103}
104
105#[repr(u8)]
106#[derive(Copy, Clone, PartialEq, Debug)]
107pub enum DiscMode {
108 Non = BLE_GAP_DISC_MODE_NON as _,
110 Ltd = BLE_GAP_DISC_MODE_LTD as _,
112 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 const ENC = BLE_SM_PAIR_KEY_DIST_ENC as _;
122 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 const Bond = 0b001;
135 const Mitm = 0b010;
137 const Sc = 0b100;
139 }
140}
141
142#[derive(Copy, Clone, PartialEq, Debug)]
143pub enum AdvType {
144 Ind,
146 DirectInd,
148 ScanInd,
150 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 const DiscLimited = BLE_HS_ADV_F_DISC_LTD as _;
176 const DiscGeneral = BLE_HS_ADV_F_DISC_GEN as _;
178 const BrEdrUnsupported = BLE_HS_ADV_F_BREDR_UNSUP as _;
180 const SimultaneousController = 0b01000;
182 const SimultaneousHost = 0b10000;
184 }
185}
186
187#[repr(u8)]
188#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
189pub enum ScanFilterPolicy {
190 NoWl = BLE_HCI_SCAN_FILT_NO_WL as _,
193 UseWl = BLE_HCI_SCAN_FILT_USE_WL as _,
196 NoWlInitA = BLE_HCI_SCAN_FILT_NO_WL_INITA as _,
199 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 None = BLE_HCI_ADV_FILT_NONE as _,
209 Scan = BLE_HCI_ADV_FILT_SCAN as _,
211 Connect = BLE_HCI_ADV_FILT_CONN as _,
213 Both = BLE_HCI_ADV_FILT_BOTH as _,
215}
216
217#[repr(u8)]
218#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
219pub enum PrimPhy {
220 Phy1M = BLE_HCI_LE_PHY_1M as _,
222 Coded = BLE_HCI_LE_PHY_CODED as _,
224}
225
226#[repr(u8)]
227#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
228pub enum SecPhy {
229 Phy1M = BLE_HCI_LE_PHY_1M as _,
231 Phy2M = BLE_HCI_LE_PHY_2M as _,
233 Coded = BLE_HCI_LE_PHY_CODED as _,
235}