|
66 | 66 | # if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) |
67 | 67 | # include "NimBLEServer.h" |
68 | 68 | # if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 0 |
69 | | -# include "NimBLEL2CAPServer.h" |
| 69 | +# include "NimBLEL2CAPServer.h" |
70 | 70 | # endif |
71 | 71 | # endif |
72 | 72 |
|
@@ -113,9 +113,18 @@ std::vector<NimBLEAddress> NimBLEDevice::m_whiteList{}; |
113 | 113 | uint8_t NimBLEDevice::m_ownAddrType{BLE_OWN_ADDR_PUBLIC}; |
114 | 114 |
|
115 | 115 | # ifdef ESP_PLATFORM |
116 | | -# ifdef CONFIG_BTDM_BLE_SCAN_DUPL |
| 116 | +# if CONFIG_BTDM_BLE_SCAN_DUPL |
117 | 117 | uint16_t NimBLEDevice::m_scanDuplicateSize{CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE}; |
118 | 118 | uint8_t NimBLEDevice::m_scanFilterMode{CONFIG_BTDM_SCAN_DUPL_TYPE}; |
| 119 | +uint16_t NimBLEDevice::m_scanDuplicateResetTime{0}; |
| 120 | +# elif CONFIG_BT_LE_SCAN_DUPL |
| 121 | +uint16_t NimBLEDevice::m_scanDuplicateSize{CONFIG_BT_LE_LL_DUP_SCAN_LIST_COUNT}; |
| 122 | +uint8_t NimBLEDevice::m_scanFilterMode{CONFIG_BT_LE_SCAN_DUPL_TYPE}; |
| 123 | +uint16_t NimBLEDevice::m_scanDuplicateResetTime{0}; |
| 124 | +extern "C" int ble_vhci_disc_duplicate_set_max_cache_size(int max_cache_size); |
| 125 | +extern "C" int ble_vhci_disc_duplicate_set_period_refresh_time(int refresh_period_time); |
| 126 | +extern "C" int ble_vhci_disc_duplicate_mode_disable(int mode); |
| 127 | +extern "C" int ble_vhci_disc_duplicate_mode_enable(int mode); |
119 | 128 | # endif |
120 | 129 | # endif |
121 | 130 |
|
@@ -258,7 +267,7 @@ NimBLEScan* NimBLEDevice::getScan() { |
258 | 267 | } // getScan |
259 | 268 |
|
260 | 269 | # ifdef ESP_PLATFORM |
261 | | -# ifdef CONFIG_BTDM_BLE_SCAN_DUPL |
| 270 | +# if CONFIG_BTDM_BLE_SCAN_DUPL || CONFIG_BT_LE_SCAN_DUPL |
262 | 271 | /** |
263 | 272 | * @brief Set the duplicate filter cache size for filtering scanned devices. |
264 | 273 | * @param [in] size The number of advertisements filtered before the cache is reset.\n |
@@ -305,7 +314,26 @@ void NimBLEDevice::setScanFilterMode(uint8_t mode) { |
305 | 314 |
|
306 | 315 | m_scanFilterMode = mode; |
307 | 316 | } |
308 | | -# endif // CONFIG_BTDM_BLE_SCAN_DUPL |
| 317 | + |
| 318 | +/** |
| 319 | + * @brief Set the time in seconds to reset the duplicate cache. |
| 320 | + * @param [in] time The time in seconds to reset the cache. |
| 321 | + * @details When the cache is reset all scanned devices will be reported again |
| 322 | + * even if already seen in the current scan. If set to 0 the cache will never be reset. |
| 323 | + */ |
| 324 | +void NimBLEDevice::setScanDuplicateCacheResetTime(uint16_t time) { |
| 325 | + if (m_initialized) { |
| 326 | + NIMBLE_LOGE(LOG_TAG, "Cannot change scan cache reset time while initialized"); |
| 327 | + return; |
| 328 | + } else if (time > 1000) { |
| 329 | + NIMBLE_LOGE(LOG_TAG, "Invalid scan cache reset time"); |
| 330 | + return; |
| 331 | + } |
| 332 | + |
| 333 | + NIMBLE_LOGD(LOG_TAG, "Set duplicate cache reset time to: %u", time); |
| 334 | + m_scanDuplicateResetTime = time; |
| 335 | +} |
| 336 | +# endif // CONFIG_BTDM_BLE_SCAN_DUPL || CONFIG_BT_LE_SCAN_DUPL |
309 | 337 | # endif // ESP_PLATFORM |
310 | 338 | # endif // #if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER) |
311 | 339 |
|
@@ -900,16 +928,39 @@ bool NimBLEDevice::init(const std::string& deviceName) { |
900 | 928 | bt_cfg.nimble_max_connections = CONFIG_BT_NIMBLE_MAX_CONNECTIONS; |
901 | 929 | # endif |
902 | 930 |
|
903 | | -# ifdef CONFIG_BTDM_BLE_SCAN_DUPL |
904 | | - bt_cfg.normal_adv_size = m_scanDuplicateSize; |
905 | | - bt_cfg.scan_duplicate_type = m_scanFilterMode; |
| 931 | +# if CONFIG_BTDM_BLE_SCAN_DUPL |
| 932 | + bt_cfg.normal_adv_size = m_scanDuplicateSize; |
| 933 | + bt_cfg.scan_duplicate_type = m_scanFilterMode; |
| 934 | + bt_cfg.dup_list_refresh_period = m_scanDuplicateResetTime; |
| 935 | +# elif CONFIG_BT_LE_SCAN_DUPL |
| 936 | + bt_cfg.ble_ll_rsp_dup_list_count = m_scanDuplicateSize; |
| 937 | + bt_cfg.ble_ll_adv_dup_list_count = m_scanDuplicateSize; |
906 | 938 | # endif |
907 | 939 | err = esp_bt_controller_init(&bt_cfg); |
908 | 940 | if (err != ESP_OK) { |
909 | 941 | NIMBLE_LOGE(LOG_TAG, "esp_bt_controller_init() failed; err=%d", err); |
910 | 942 | return false; |
911 | 943 | } |
912 | 944 |
|
| 945 | +# if CONFIG_BT_LE_SCAN_DUPL |
| 946 | + int mode = (1UL << 4); // FILTER_DUPLICATE_EXCEPTION_FOR_MESH |
| 947 | + switch (m_scanFilterMode) { |
| 948 | + case 1: |
| 949 | + mode |= (1UL << 3); // FILTER_DUPLICATE_ADVDATA |
| 950 | + break; |
| 951 | + case 2: |
| 952 | + mode |= ((1UL << 2) | (1UL << 3)); // FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_ADVDATA |
| 953 | + break; |
| 954 | + default: |
| 955 | + mode |= (1UL << 0) | (1UL << 2); // FILTER_DUPLICATE_PDUTYPE | FILTER_DUPLICATE_ADDRESS |
| 956 | + } |
| 957 | + |
| 958 | + ble_vhci_disc_duplicate_mode_disable(0xFFFFFFFF); |
| 959 | + ble_vhci_disc_duplicate_mode_enable(mode); |
| 960 | + ble_vhci_disc_duplicate_set_max_cache_size(m_scanDuplicateSize); |
| 961 | + ble_vhci_disc_duplicate_set_period_refresh_time(m_scanDuplicateResetTime); |
| 962 | +# endif |
| 963 | + |
913 | 964 | err = esp_bt_controller_enable(ESP_BT_MODE_BLE); |
914 | 965 | if (err != ESP_OK) { |
915 | 966 | NIMBLE_LOGE(LOG_TAG, "esp_bt_controller_enable() failed; err=%d", err); |
|
0 commit comments