Skip to content

Commit ea7075a

Browse files
committed
Use a single macro to detect if scan duplicate filtering is enabled
1 parent 002abf9 commit ea7075a

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/NimBLEDevice.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,11 @@ ble_gap_event_listener NimBLEDevice::m_listener{};
9898
std::vector<NimBLEAddress> NimBLEDevice::m_whiteList{};
9999
uint8_t NimBLEDevice::m_ownAddrType{BLE_OWN_ADDR_PUBLIC};
100100

101-
# ifdef ESP_PLATFORM
102-
# if CONFIG_BTDM_BLE_SCAN_DUPL
103-
uint16_t NimBLEDevice::m_scanDuplicateSize{CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE};
104-
uint8_t NimBLEDevice::m_scanFilterMode{CONFIG_BTDM_SCAN_DUPL_TYPE};
101+
# if NIMBLE_CPP_SCAN_DUPL_ENABLED
102+
uint16_t NimBLEDevice::m_scanDuplicateSize{100};
103+
uint8_t NimBLEDevice::m_scanFilterMode{0};
105104
uint16_t NimBLEDevice::m_scanDuplicateResetTime{0};
106-
# elif CONFIG_BT_LE_SCAN_DUPL
107-
uint16_t NimBLEDevice::m_scanDuplicateSize{CONFIG_BT_LE_LL_DUP_SCAN_LIST_COUNT};
108-
uint8_t NimBLEDevice::m_scanFilterMode{CONFIG_BT_LE_SCAN_DUPL_TYPE};
109-
uint16_t NimBLEDevice::m_scanDuplicateResetTime{0};
105+
# if SOC_ESP_NIMBLE_CONTROLLER
110106
extern "C" int ble_vhci_disc_duplicate_set_max_cache_size(int max_cache_size);
111107
extern "C" int ble_vhci_disc_duplicate_set_period_refresh_time(int refresh_period_time);
112108
extern "C" int ble_vhci_disc_duplicate_mode_disable(int mode);
@@ -914,23 +910,25 @@ bool NimBLEDevice::init(const std::string& deviceName) {
914910
bt_cfg.nimble_max_connections = MYNEWT_VAL(BLE_MAX_CONNECTIONS);
915911
# endif
916912

917-
# if CONFIG_BTDM_BLE_SCAN_DUPL
913+
# if NIMBLE_CPP_SCAN_DUPL_ENABLED
914+
# if !SOC_ESP_NIMBLE_CONTROLLER
918915
bt_cfg.normal_adv_size = m_scanDuplicateSize;
919916
bt_cfg.scan_duplicate_type = m_scanFilterMode;
920-
# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
917+
bt_cfg.scan_duplicate_mode = 0; // Ensure normal filter mode, could be set to mesh in default config
918+
# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
921919
bt_cfg.dup_list_refresh_period = m_scanDuplicateResetTime;
922-
# endif
923-
# elif CONFIG_BT_LE_SCAN_DUPL
920+
# endif
921+
# else // SOC_ESP_NIMBLE_CONTROLLER
924922
bt_cfg.ble_ll_rsp_dup_list_count = m_scanDuplicateSize;
925923
bt_cfg.ble_ll_adv_dup_list_count = m_scanDuplicateSize;
926-
# endif
924+
# endif // SOC_ESP_NIMBLE_CONTROLLER
927925
err = esp_bt_controller_init(&bt_cfg);
928926
if (err != ESP_OK) {
929927
NIMBLE_LOGE(LOG_TAG, "esp_bt_controller_init() failed; err=%d", err);
930928
return false;
931929
}
932930

933-
# if CONFIG_BT_LE_SCAN_DUPL
931+
# if SOC_ESP_NIMBLE_CONTROLLER
934932
int mode = (1UL << 4); // FILTER_DUPLICATE_EXCEPTION_FOR_MESH
935933
switch (m_scanFilterMode) {
936934
case 1:
@@ -940,14 +938,15 @@ bool NimBLEDevice::init(const std::string& deviceName) {
940938
mode |= ((1UL << 2) | (1UL << 3)); // FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_ADVDATA
941939
break;
942940
default:
943-
mode |= (1UL << 0) | (1UL << 2); // FILTER_DUPLICATE_PDUTYPE | FILTER_DUPLICATE_ADDRESS
941+
mode |= ((1UL << 0) | (1UL << 2)); // FILTER_DUPLICATE_PDUTYPE | FILTER_DUPLICATE_ADDRESS
944942
}
945943

946944
ble_vhci_disc_duplicate_mode_disable(0xFFFFFFFF);
947945
ble_vhci_disc_duplicate_mode_enable(mode);
948946
ble_vhci_disc_duplicate_set_max_cache_size(m_scanDuplicateSize);
949947
ble_vhci_disc_duplicate_set_period_refresh_time(m_scanDuplicateResetTime);
950-
# endif
948+
# endif // SOC_ESP_NIMBLE_CONTROLLER
949+
# endif // NIMBLE_CPP_SCAN_DUPL_ENABLED
951950

952951
err = esp_bt_controller_enable(ESP_BT_MODE_BLE);
953952
if (err != ESP_OK) {

src/NimBLEDevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# ifndef CONFIG_IDF_TARGET_ESP32P4
2525
# include <esp_bt.h>
2626
# endif
27+
# define NIMBLE_CPP_SCAN_DUPL_ENABLED \
28+
(CONFIG_BTDM_BLE_SCAN_DUPL || CONFIG_BT_LE_SCAN_DUPL || CONFIG_BT_CTRL_BLE_SCAN_DUPL)
2729
# endif
2830

2931
# if defined(CONFIG_NIMBLE_CPP_IDF)
@@ -243,7 +245,7 @@ class NimBLEDevice {
243245
# endif
244246

245247
# ifdef ESP_PLATFORM
246-
# if CONFIG_BTDM_BLE_SCAN_DUPL || CONFIG_BT_LE_SCAN_DUPL
248+
# if NIMBLE_CPP_SCAN_DUPL_ENABLED
247249
static uint16_t m_scanDuplicateSize;
248250
static uint8_t m_scanFilterMode;
249251
static uint16_t m_scanDuplicateResetTime;

0 commit comments

Comments
 (0)