Skip to content

Commit

Permalink
Added some functions to BLESecurity
Browse files Browse the repository at this point in the history
  • Loading branch information
taks committed Nov 8, 2023
1 parent 405773e commit 8cacbf7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ble_security.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::enums;

pub struct BLESecurity {
passkey: u32,
}
Expand Down Expand Up @@ -31,4 +32,16 @@ impl BLESecurity {
unsafe { esp_idf_sys::ble_hs_cfg.sm_io_cap = iocap as _ };
self
}

/// If we are the initiator of the security procedure this sets the keys we will distribute.
pub fn set_security_init_key(&mut self, init_key: enums::PairKeyDist) -> &mut Self {
unsafe { esp_idf_sys::ble_hs_cfg.sm_our_key_dist = init_key.bits() };
self
}

/// Set the keys we are willing to accept during pairing.
pub fn set_security_resp_key(&mut self, resp_key: enums::PairKeyDist) -> &mut Self {
unsafe { esp_idf_sys::ble_hs_cfg.sm_their_key_dist = init_key.bits() };
self
}
}
12 changes: 12 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bitflags::bitflags;
use esp_idf_sys::*;

#[repr(u8)]
Expand Down Expand Up @@ -79,3 +80,14 @@ pub enum PowerType {
/// For default, if not set other, it will use default value
Default = esp_ble_power_type_t_ESP_BLE_PWR_TYPE_DEFAULT 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 _;
}
}

0 comments on commit 8cacbf7

Please sign in to comment.