diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index db991124dd..dde650827c 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -422,3 +422,74 @@ config BT_LE_USE_ESP_TIMER help Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer + +config BT_LE_SCAN_DUPL + bool "BLE Scan Duplicate Options" + default y + help + This select enables parameters setting of BLE scan duplicate. + +choice BT_LE_SCAN_DUPL_TYPE + prompt "Scan Duplicate Type" + default BT_LE_SCAN_DUPL_TYPE_DEVICE + depends on BT_LE_SCAN_DUPL + help + Scan duplicate have three ways. one is "Scan Duplicate By Device Address", This way is to use + advertiser address filtering. The adv packet of the same address is only allowed to be reported once. + Another way is "Scan Duplicate By Device Address And Advertising Data". This way is to use advertising + data and device address filtering. All different adv packets with the same address are allowed to be + reported. The last way is "Scan Duplicate By Advertising Data". This way is to use advertising data + filtering. All same advertising data only allow to be reported once even though they are from + different devices. + + config BT_LE_SCAN_DUPL_TYPE_DEVICE + bool "Scan Duplicate By Device Address" + help + This way is to use advertiser address filtering. The adv packet of the same address is only + allowed to be reported once + + config BT_LE_SCAN_DUPL_TYPE_DATA + bool "Scan Duplicate By Advertising Data" + help + This way is to use advertising data filtering. All same advertising data only allow to be reported + once even though they are from different devices. + + config BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE + bool "Scan Duplicate By Device Address And Advertising Data" + help + This way is to use advertising data and device address filtering. All different adv packets with + the same address are allowed to be reported. +endchoice + +config BT_LE_SCAN_DUPL_TYPE + int + depends on BT_LE_SCAN_DUPL + default 0 if BT_LE_SCAN_DUPL_TYPE_DEVICE + default 1 if BT_LE_SCAN_DUPL_TYPE_DATA + default 2 if BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE + default 0 + +config BT_LE_SCAN_DUPL_CACHE_SIZE + int "Maximum number of devices in scan duplicate filter" + depends on BT_LE_SCAN_DUPL + range 10 1000 + default 100 + help + Maximum number of devices which can be recorded in scan duplicate filter. + When the maximum amount of device in the filter is reached, the cache will be refreshed. + +config BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD + int "Duplicate scan list refresh period (seconds)" + depends on BT_LE_SCAN_DUPL + range 0 1000 + default 0 + help + If the period value is non-zero, the controller will periodically clear the device information + stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared + until the scanning is disabled. Duplicate advertisements for this period should not be sent to the + Host in advertising report events. + There are two scenarios where the ADV packet will be repeatedly reported: + 1. The duplicate scan cache is full, the controller will delete the oldest device information and + add new device information. + 2. When the refresh period is up, the controller will clear all device information and start filtering + again. diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 4cd73dbc78..3881045da1 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -617,6 +617,74 @@ void controller_sleep_deinit(void) #endif //CONFIG_PM_ENABLE } +typedef enum { + FILTER_DUPLICATE_PDUTYPE = BIT(0), + FILTER_DUPLICATE_LENGTH = BIT(1), + FILTER_DUPLICATE_ADDRESS = BIT(2), + FILTER_DUPLICATE_ADVDATA = BIT(3), + FILTER_DUPLICATE_DEFAULT = FILTER_DUPLICATE_PDUTYPE | FILTER_DUPLICATE_ADDRESS, + FILTER_DUPLICATE_PDU_ALL = 0xF, + FILTER_DUPLICATE_EXCEPTION_FOR_MESH = BIT(4), + FILTER_DUPLICATE_AD_TYPE = BIT(5), +}disc_duplicate_mode_t; + + +extern void filter_duplicate_mode_enable(disc_duplicate_mode_t mode); +extern void filter_duplicate_mode_disable(disc_duplicate_mode_t mode); +extern void filter_duplicate_set_ring_list_max_num(uint32_t max_num); +extern void scan_duplicate_cache_refresh_set_time(uint32_t period_time); + +int +ble_vhci_disc_duplicate_mode_enable(int mode) +{ + // TODO: use vendor hci to update + filter_duplicate_mode_enable(mode); + return true; +} + +int +ble_vhci_disc_duplicate_mode_disable(int mode) +{ + // TODO: use vendor hci to update + filter_duplicate_mode_disable(mode); + return true; +} + +int ble_vhci_disc_duplicate_set_max_cache_size(int max_cache_size){ + // TODO: use vendor hci to update + filter_duplicate_set_ring_list_max_num(max_cache_size); + return true; +} + +int ble_vhci_disc_duplicate_set_period_refresh_time(int refresh_period_time){ + // TODO: use vendor hci to update + scan_duplicate_cache_refresh_set_time(refresh_period_time); + return true; +} + +/** + * @brief Config scan duplicate option mode from menuconfig (Adapt to the old configuration method.) + */ +void ble_controller_scan_duplicate_config(void) +{ + uint32_t duplicate_mode = FILTER_DUPLICATE_DEFAULT; + uint32_t cache_size = CONFIG_BT_LE_SCAN_DUPL_CACHE_SIZE; + if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 0) { + duplicate_mode = FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_PDUTYPE; + } else if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 1) { + duplicate_mode = FILTER_DUPLICATE_ADVDATA; + } else if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 2) { + duplicate_mode = FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_ADVDATA; + } + + duplicate_mode |= FILTER_DUPLICATE_EXCEPTION_FOR_MESH; + + ble_vhci_disc_duplicate_mode_disable(0xFFFFFFFF); + ble_vhci_disc_duplicate_mode_enable(duplicate_mode); + ble_vhci_disc_duplicate_set_max_cache_size(cache_size); + ble_vhci_disc_duplicate_set_period_refresh_time(CONFIG_BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD); +} + esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) { uint8_t mac[6]; @@ -730,6 +798,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto free_controller; } + ble_controller_scan_duplicate_config(); + ret = controller_sleep_init(); if (ret != ESP_OK) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret); diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 6eef0428e8..7d8d7463d4 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -422,3 +422,75 @@ config BT_LE_USE_ESP_TIMER help Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer + +config BT_LE_SCAN_DUPL + bool "BLE Scan Duplicate Options" + default y + help + This select enables parameters setting of BLE scan duplicate. + +choice BT_LE_SCAN_DUPL_TYPE + prompt "Scan Duplicate Type" + default BT_LE_SCAN_DUPL_TYPE_DEVICE + depends on BT_LE_SCAN_DUPL + help + Scan duplicate have three ways. one is "Scan Duplicate By Device Address", This way is to use + advertiser address filtering. The adv packet of the same address is only allowed to be reported once. + Another way is "Scan Duplicate By Device Address And Advertising Data". This way is to use advertising + data and device address filtering. All different adv packets with the same address are allowed to be + reported. The last way is "Scan Duplicate By Advertising Data". This way is to use advertising data + filtering. All same advertising data only allow to be reported once even though they are from + different devices. + + config BT_LE_SCAN_DUPL_TYPE_DEVICE + bool "Scan Duplicate By Device Address" + help + This way is to use advertiser address filtering. The adv packet of the same address is only + allowed to be reported once + + config BT_LE_SCAN_DUPL_TYPE_DATA + bool "Scan Duplicate By Advertising Data" + help + This way is to use advertising data filtering. All same advertising data only allow to be reported + once even though they are from different devices. + + config BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE + bool "Scan Duplicate By Device Address And Advertising Data" + help + This way is to use advertising data and device address filtering. All different adv packets with + the same address are allowed to be reported. +endchoice + +config BT_LE_SCAN_DUPL_TYPE + int + depends on BT_LE_SCAN_DUPL + default 0 if BT_LE_SCAN_DUPL_TYPE_DEVICE + default 1 if BT_LE_SCAN_DUPL_TYPE_DATA + default 2 if BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE + default 0 + + +config BT_LE_SCAN_DUPL_CACHE_SIZE + int "Maximum number of devices in scan duplicate filter" + depends on BT_LE_SCAN_DUPL + range 10 1000 + default 100 + help + Maximum number of devices which can be recorded in scan duplicate filter. + When the maximum amount of device in the filter is reached, the cache will be refreshed. + +config BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD + int "Duplicate scan list refresh period (seconds)" + depends on BT_LE_SCAN_DUPL + range 0 1000 + default 0 + help + If the period value is non-zero, the controller will periodically clear the device information + stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared + until the scanning is disabled. Duplicate advertisements for this period should not be sent to the + Host in advertising report events. + There are two scenarios where the ADV packet will be repeatedly reported: + 1. The duplicate scan cache is full, the controller will delete the oldest device information and + add new device information. + 2. When the refresh period is up, the controller will clear all device information and start filtering + again. diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 9e11fc3d0f..75bcd995e9 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -615,6 +615,74 @@ void controller_sleep_deinit(void) #endif //CONFIG_PM_ENABLE } +typedef enum { + FILTER_DUPLICATE_PDUTYPE = BIT(0), + FILTER_DUPLICATE_LENGTH = BIT(1), + FILTER_DUPLICATE_ADDRESS = BIT(2), + FILTER_DUPLICATE_ADVDATA = BIT(3), + FILTER_DUPLICATE_DEFAULT = FILTER_DUPLICATE_PDUTYPE | FILTER_DUPLICATE_ADDRESS, + FILTER_DUPLICATE_PDU_ALL = 0xF, + FILTER_DUPLICATE_EXCEPTION_FOR_MESH = BIT(4), + FILTER_DUPLICATE_AD_TYPE = BIT(5), +}disc_duplicate_mode_t; + + +extern void filter_duplicate_mode_enable(disc_duplicate_mode_t mode); +extern void filter_duplicate_mode_disable(disc_duplicate_mode_t mode); +extern void filter_duplicate_set_ring_list_max_num(uint32_t max_num); +extern void scan_duplicate_cache_refresh_set_time(uint32_t period_time); + +int +ble_vhci_disc_duplicate_mode_enable(int mode) +{ + // TODO: use vendor hci to update + filter_duplicate_mode_enable(mode); + return true; +} + +int +ble_vhci_disc_duplicate_mode_disable(int mode) +{ + // TODO: use vendor hci to update + filter_duplicate_mode_disable(mode); + return true; +} + +int ble_vhci_disc_duplicate_set_max_cache_size(int max_cache_size){ + // TODO: use vendor hci to update + filter_duplicate_set_ring_list_max_num(max_cache_size); + return true; +} + +int ble_vhci_disc_duplicate_set_period_refresh_time(int refresh_period_time){ + // TODO: use vendor hci to update + scan_duplicate_cache_refresh_set_time(refresh_period_time); + return true; +} + +/** + * @brief Config scan duplicate option mode from menuconfig (Adapt to the old configuration method.) + */ +void ble_controller_scan_duplicate_config(void) +{ + uint32_t duplicate_mode = FILTER_DUPLICATE_DEFAULT; + uint32_t cache_size = CONFIG_BT_LE_SCAN_DUPL_CACHE_SIZE; + if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 0) { + duplicate_mode = FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_PDUTYPE; + } else if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 1) { + duplicate_mode = FILTER_DUPLICATE_ADVDATA; + } else if (CONFIG_BT_LE_SCAN_DUPL_TYPE == 2) { + duplicate_mode = FILTER_DUPLICATE_ADDRESS | FILTER_DUPLICATE_ADVDATA; + } + + duplicate_mode |= FILTER_DUPLICATE_EXCEPTION_FOR_MESH; + + ble_vhci_disc_duplicate_mode_disable(0xFFFFFFFF); + ble_vhci_disc_duplicate_mode_enable(duplicate_mode); + ble_vhci_disc_duplicate_set_max_cache_size(cache_size); + ble_vhci_disc_duplicate_set_period_refresh_time(CONFIG_BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD); +} + esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) { uint8_t mac[6]; @@ -720,6 +788,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto free_controller; } + ble_controller_scan_duplicate_config(); + ret = controller_sleep_init(); if (ret != ESP_OK) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret); diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index 0d0361ea8d..ddd61e9a27 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit 0d0361ea8de61566575d7a8a97f2d7fd81538981 +Subproject commit ddd61e9a276926496437665dd217cba2850db6b9 diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index f54d378894..b207a7da7a 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit f54d3788941a701aca151a66654c812e080e876c +Subproject commit b207a7da7a9758dbccea0dba1023fd36c47b3e65 diff --git a/components/bt/include/esp32c6/include/esp_bt.h b/components/bt/include/esp32c6/include/esp_bt.h index f8eb6a2af9..929d73c4bc 100644 --- a/components/bt/include/esp32c6/include/esp_bt.h +++ b/components/bt/include/esp32c6/include/esp_bt.h @@ -256,7 +256,7 @@ typedef struct { .sleep_en = NIMBLE_SLEEP_ENABLE, \ .coex_phy_coded_tx_rx_time_limit = DEFAULT_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF, \ .dis_scan_backoff = NIMBLE_DISABLE_SCAN_BACKOFF, \ - .ble_scan_classify_filter_enable = 0, \ + .ble_scan_classify_filter_enable = 1, \ .main_xtal_freq = CONFIG_XTAL_FREQ, \ .version_num = efuse_hal_chip_revision(), \ .cpu_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ, \ diff --git a/components/bt/include/esp32h2/include/esp_bt.h b/components/bt/include/esp32h2/include/esp_bt.h index 316a24627c..4b3c4af323 100644 --- a/components/bt/include/esp32h2/include/esp_bt.h +++ b/components/bt/include/esp32h2/include/esp_bt.h @@ -258,7 +258,7 @@ typedef struct { .sleep_en = NIMBLE_SLEEP_ENABLE, \ .coex_phy_coded_tx_rx_time_limit = DEFAULT_BT_LE_COEX_PHY_CODED_TX_RX_TLIM_EFF, \ .dis_scan_backoff = NIMBLE_DISABLE_SCAN_BACKOFF, \ - .ble_scan_classify_filter_enable = 0, \ + .ble_scan_classify_filter_enable = 1, \ .main_xtal_freq = CONFIG_XTAL_FREQ, \ .cpu_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ, \ .ignore_wl_for_direct_adv = 0, \