Skip to content

Commit

Permalink
Merge branch 'develop' into address
Browse files Browse the repository at this point in the history
  • Loading branch information
taks authored Nov 14, 2023
2 parents 9d7c354 + bc7ee70 commit d253ec8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ pub enum OwnAddrType {
RpaRandomDefault = esp_idf_sys::BLE_OWN_ADDR_RPA_RANDOM_DEFAULT as _,
}

#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum ConnMode {
/// non-connectable (3.C.9.3.2)
Non = esp_idf_sys::BLE_GAP_CONN_MODE_NON as _,
/// directed-connectable (3.C.9.3.3)
Dir = esp_idf_sys::BLE_GAP_CONN_MODE_DIR as _,
/// undirected-connectable (3.C.9.3.4)
Und = esp_idf_sys::BLE_GAP_CONN_MODE_UND as _,
}

bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
19 changes: 15 additions & 4 deletions src/server/ble_advertising.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ffi::c_void;

use crate::{ble, enums::PowerType, utilities::BleUuid, BLEDevice, BLEReturnCode, BLEServer};
use crate::{ble, enums::*, utilities::BleUuid, BLEDevice, BLEReturnCode, BLEServer};
use alloc::{ffi::CString, vec::Vec};
use once_cell::sync::Lazy;

Expand Down Expand Up @@ -204,6 +204,12 @@ impl BLEAdvertising {
}
}

/// Set the type of advertisment to use.
pub fn advertisement_type(&mut self, adv_type: ConnMode) -> &mut Self {
self.adv_params.conn_mode = adv_type as _;
self
}

/// Set if scan response is available.
pub fn scan_response(&mut self, value: bool) -> &mut Self {
self.scan_response = value;
Expand All @@ -227,9 +233,14 @@ impl BLEAdvertising {
}
}

self.adv_params.disc_mode = esp_idf_sys::BLE_GAP_DISC_MODE_GEN as _;
self.adv_data.flags =
(esp_idf_sys::BLE_HS_ADV_F_DISC_GEN | esp_idf_sys::BLE_HS_ADV_F_BREDR_UNSUP) as _;
if self.adv_params.conn_mode == (ConnMode::Non as _) && !self.scan_response {
self.adv_params.disc_mode = esp_idf_sys::BLE_GAP_DISC_MODE_NON as _;
self.adv_data.flags = 0;
} else {
self.adv_params.disc_mode = esp_idf_sys::BLE_GAP_DISC_MODE_GEN as _;
self.adv_data.flags =
(esp_idf_sys::BLE_HS_ADV_F_DISC_GEN | esp_idf_sys::BLE_HS_ADV_F_BREDR_UNSUP) as _;
}

if !self.custom_adv_data && !self.adv_data_set {
let mut payload_len: u8 = if self.adv_data.flags > 0 { 2 + 1 } else { 0 };
Expand Down

0 comments on commit d253ec8

Please sign in to comment.