use bitflags::bitflags;
use esp_idf_svc::sys::*;
use num_enum::{IntoPrimitive, TryFromPrimitive};
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum SecurityIOCap {
DisplayOnly = BLE_HS_IO_DISPLAY_ONLY as _,
DisplayYesNo = BLE_HS_IO_DISPLAY_YESNO as _,
KeyboardOnly = BLE_HS_IO_KEYBOARD_ONLY as _,
NoInputNoOutput = BLE_HS_IO_NO_INPUT_OUTPUT as _,
KeyboardDisplay = BLE_HS_IO_KEYBOARD_DISPLAY as _,
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PowerLevel {
N12 = esp_power_level_t_ESP_PWR_LVL_N12 as _,
N9 = esp_power_level_t_ESP_PWR_LVL_N9 as _,
N6 = esp_power_level_t_ESP_PWR_LVL_N6 as _,
N3 = esp_power_level_t_ESP_PWR_LVL_N3 as _,
N0 = esp_power_level_t_ESP_PWR_LVL_N0 as _,
P3 = esp_power_level_t_ESP_PWR_LVL_P3 as _,
P6 = esp_power_level_t_ESP_PWR_LVL_P6 as _,
P9 = esp_power_level_t_ESP_PWR_LVL_P9 as _,
}
impl PowerLevel {
pub fn to_dbm(&self) -> i8 {
match self {
PowerLevel::N12 => -12,
PowerLevel::N9 => -9,
PowerLevel::N6 => -6,
PowerLevel::N3 => -3,
PowerLevel::N0 => 0,
PowerLevel::P3 => 3,
PowerLevel::P6 => 6,
PowerLevel::P9 => 9,
}
}
}
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PowerType {
ConnHdl0 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL0 as _,
ConnHdl1 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL1 as _,
ConnHdl2 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL2 as _,
ConnHdl3 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL3 as _,
ConnHdl4 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL4 as _,
ConnHdl5 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL5 as _,
ConnHdl6 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL6 as _,
ConnHdl7 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL7 as _,
ConnHdl8 = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_CONN_HDL8 as _,
Advertising = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_ADV as _,
Scan = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_SCAN as _,
Default = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_DEFAULT as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum OwnAddrType {
Public = BLE_OWN_ADDR_PUBLIC as _,
Random = BLE_OWN_ADDR_RANDOM as _,
RpaPublicDefault = BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT as _,
RpaRandomDefault = BLE_OWN_ADDR_RPA_RANDOM_DEFAULT as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum ConnMode {
Non = BLE_GAP_CONN_MODE_NON as _,
Dir = BLE_GAP_CONN_MODE_DIR as _,
Und = BLE_GAP_CONN_MODE_UND as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum DiscMode {
Non = BLE_GAP_DISC_MODE_NON as _,
Ltd = BLE_GAP_DISC_MODE_LTD as _,
Gen = BLE_GAP_DISC_MODE_GEN as _,
}
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PairKeyDist: u8 {
const ENC = BLE_SM_PAIR_KEY_DIST_ENC as _;
const ID = BLE_SM_PAIR_KEY_DIST_ID as _;
const SIGN = BLE_SM_PAIR_KEY_DIST_SIGN as _;
const LINK = BLE_SM_PAIR_KEY_DIST_LINK as _;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AuthReq: u8 {
const Bond = 0b001;
const Mitm = 0b010;
const Sc = 0b100;
}
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum AdvType {
Ind,
DirectInd,
ScanInd,
NonconnInd,
ScanResponse,
#[cfg(esp_idf_bt_nimble_ext_adv)]
Extended(u8),
}
impl AdvType {
pub(crate) fn from_event_type(event_type: u8) -> Self {
match event_type as u32 {
BLE_HCI_ADV_RPT_EVTYPE_ADV_IND => AdvType::Ind,
BLE_HCI_ADV_RPT_EVTYPE_DIR_IND => AdvType::DirectInd,
BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND => AdvType::ScanInd,
BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND => AdvType::NonconnInd,
BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP => AdvType::ScanResponse,
5.. => unreachable!(),
}
}
}
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AdvFlag: u8 {
const DiscLimited = BLE_HS_ADV_F_DISC_LTD as _;
const DiscGeneral = BLE_HS_ADV_F_DISC_GEN as _;
const BrEdrUnsupported = BLE_HS_ADV_F_BREDR_UNSUP as _;
const SimultaneousController = 0b01000;
const SimultaneousHost = 0b10000;
}
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
pub enum ScanFilterPolicy {
NoWl = BLE_HCI_SCAN_FILT_NO_WL as _,
UseWl = BLE_HCI_SCAN_FILT_USE_WL as _,
NoWlInitA = BLE_HCI_SCAN_FILT_NO_WL_INITA as _,
UseWlInitA = BLE_HCI_SCAN_FILT_USE_WL_INITA as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug, IntoPrimitive)]
pub enum AdvFilterPolicy {
None = BLE_HCI_ADV_FILT_NONE as _,
Scan = BLE_HCI_ADV_FILT_SCAN as _,
Connect = BLE_HCI_ADV_FILT_CONN as _,
Both = BLE_HCI_ADV_FILT_BOTH as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
pub enum PrimPhy {
Phy1M = BLE_HCI_LE_PHY_1M as _,
Coded = BLE_HCI_LE_PHY_CODED as _,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug, TryFromPrimitive, IntoPrimitive)]
pub enum SecPhy {
Phy1M = BLE_HCI_LE_PHY_1M as _,
Phy2M = BLE_HCI_LE_PHY_2M as _,
Coded = BLE_HCI_LE_PHY_CODED as _,
}