feat(ble): Add duplicate filter feature enable on ble for h2.

This commit is contained in:
Geng Yuchao 2023-06-15 17:13:48 +08:00
parent 2310c68966
commit fbb88ef979
3 changed files with 120 additions and 1 deletions

View File

@ -402,3 +402,59 @@ 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.

View File

@ -583,6 +583,67 @@ 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);
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;
}
/**
* @brief Config scan duplicate option mode from menuconfig (Adapt to the old configuration method.)
*/
void ble_controller_scan_duplicate_config()
{
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;
} 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(0xFF);
ble_vhci_disc_duplicate_mode_enable(duplicate_mode);
ble_vhci_disc_duplicate_set_max_cache_size(cache_size);
}
esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
{
uint8_t mac[6];
@ -668,6 +729,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);

View File

@ -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, \