espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.51k stars 7.26k forks source link

ESP32 ble scan whitelist, not work (IDFGH-4471) #6302

Closed JerryZheng89 closed 3 years ago

JerryZheng89 commented 3 years ago

Environment

Problem Description

when I change scan policy to BLE_SCAN_FILTER_ALLOW_ONLY_WLST, flow 3steps change in gatt_client example:

  1. update whitelist with my ble periperal address;
  2. set ble scan parameters
  3. start scan 30 seconds

or

  1. set ble scan paramters
  2. update whitelist with my ble periperal address;
  3. start scan 30 seconds

Expected Behavior

event list

  1. ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, start scan success
  2. ESP_GAP_BLE_SCAN_RESULT_EVT->ESP_GAP_SEARCH_INQ_RES_EVT, searched the device, which is in whitelist
  3. ESP_GAP_BLE_SCAN_RESULT_EVT->ESP_GAP_SEARCH_INQ_CMPL_EVT, search finished.

    Actual Behavior

    event list

  4. ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, start scan success
  5. ESP_GAP_BLE_SCAN_RESULT_EVT->ESP_GAP_SEARCH_INQ_CMPL_EVT, search finished.

Code to reproduce this issue

uint8_t whitelist_addr[6] = {0xc9, 0xa7, 0xab, 0x5e, 0x2d, 0xbe};

static esp_ble_scan_params_t ble_scan_params = {
    .scan_type              = BLE_SCAN_TYPE_ACTIVE,
    .own_addr_type          = BLE_ADDR_TYPE_PUBLIC,
    .scan_filter_policy     = BLE_SCAN_FILTER_ALLOW_ONLY_WLST,
    .scan_interval          = 0x50,
    .scan_window            = 0x30,
    .scan_duplicate         = BLE_SCAN_DUPLICATE_DISABLE
};

Debug Logs

I (418) boot: Disabling RNG early entropy source...
I (419) cpu_start: Pro cpu up.
I (422) cpu_start: Application information:
I (427) cpu_start: Project name:     gatt_client_demo
I (433) cpu_start: App version:      1
I (437) cpu_start: Compile time:     Dec 19 2020 23:48:58
I (443) cpu_start: ELF file SHA256:  b16071c68d527579...
I (449) cpu_start: ESP-IDF:          v4.2-47-g2532ddd9f
I (455) cpu_start: Starting app cpu, entry point is 0x40081854
......
I (0) cpu_start: Starting scheduler on APP CPU.
I (620) BTDM_INIT: BT controller compile version [3723d5b]
I (620) system_api: Base MAC address is not set
I (620) system_api: read default base MAC address from EFUSE
I (720) phy: phy_version: 4500, 0cd6843, Sep 17 2020, 15:37:07, 0, 0
I (1090) GATTC_DEMO: REG_EVT
I (1100) GATTC_DEMO: scan start success

sniffer

Although, the scan type, which I set is BLE_SCAN_TYPE_ACTIVE, I don't have seen any scan or response package in Wireshark within the 30 seconds.

Alvin1Zhang commented 3 years ago

Thanks for reporting, we will look into.

JerryZheng89 commented 3 years ago

Is threre any progress about this problems, or any suggestion to let me move forward? @Alvin1Zhang

xiewenxiang commented 3 years ago

The uint8_t whitelist_addr[6] = {0xc9, 0xa7, 0xab, 0x5e, 0x2d, 0xbe}; is Static Random Device Address.

Maybe you need to modify it this way esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_PUBLIC); => esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_RANDOM);

JerryZheng89 commented 3 years ago

The uint8_t whitelist_addr[6] = {0xc9, 0xa7, 0xab, 0x5e, 0x2d, 0xbe}; is Static Random Device Address.

Maybe you need to modify it this way esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_PUBLIC); => esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_RANDOM);

Is threre any method to add public address into white list? I will try your suggestion tomorrow. @xiewenxiang thanks

JerryZheng89 commented 3 years ago

The issue is solved, @xiewenxiang @Alvin1Zhang follow these steps:

  1. update whitelist with my ble periperal address;
  2. set ble scan parameters
  3. start scan 30 seconds change, whitelist update function addr type parameters:
    esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_RANDOM);

And it works well!!!

but I really don't konw why the wl_addr_type is random, i really think it is the public address, vevry confusing me!