Problem reading PID key from bonded device list using GAP ble API

slivingston
Posts: 6
Joined: Fri Nov 03, 2017 12:54 am

Problem reading PID key from bonded device list using GAP ble API

Postby slivingston » Thu Feb 22, 2018 3:02 am

I am trying to add devices to a white list. Some of the devices are using privacy mode, which means they are changing their address frequently. So I cannot just add the last bda to the white list. I was assuming I could use the static address exchanged during bonding. Aside from not finding any documentation or examples for doing this, I am using the esp_gap_ble_api.h structures and trying to read the static_addr from the pid key. Here is an example of my code:

Code: Select all

    
    int dev_num = esp_ble_get_bond_device_num();

    esp_ble_bond_dev_t *dev_list = (esp_ble_bond_dev_t *)malloc(sizeof(esp_ble_bond_dev_t) * dev_num);
    esp_ble_get_bond_device_list(&dev_num, dev_list);
    for (int i = 0; i < dev_num; i++) {
        esp_ble_pid_keys_t *deviceKey = &(dev_list[i].bond_key.pid_key);
        ESP_LOGI(TAG, "pid key addr type = %d", deviceKey->addr_type);
        ESP_LOGI(TAG, "pid static_addr:");
        ESP_LOGI(TAG, ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(deviceKey->static_addr));
        if (deviceKey->addr_type == BLE_ADDR_TYPE_RANDOM) {
            ESP_LOGI(TAG, "Adding private static address to white list.");
            esp_err_t result = esp_ble_gap_update_whitelist(true, deviceKey->static_addr);
            if (result != ESP_OK) {
                ESP_LOGI(TAG, "Error updating white list - %d.", result);
            }
        } else {
            ESP_LOGI(TAG, "Adding public address to white list.");
            ESP_LOGI(TAG, ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(dev_list[i].bd_addr));
            esp_err_t result = esp_ble_gap_update_whitelist(true, dev_list[i].bd_addr);
            if (result != ESP_OK) {
                ESP_LOGI(TAG, "Error updating white list - %d.", result);
            }
        }
    }
    free(dev_list);
Instead of the expected address types and static addresses, I am reading:
I (30619) gatts_controller: pid key addr type = 1830487040
I (30620) gatts_controller: pid static_addr:
I (30620) gatts_controller: 7e:2f:41:ce:ce:ce
I (30620) gatts_controller: Adding public address to white list.
I (30620) gatts_controller: 7d:b3:d6:6c:b3:ef
I (30621) gatts_controller: pid key addr type = 741305344
I (30621) gatts_controller: pid static_addr:
I (30621) gatts_controller: e4:d1:27:ce:ce:ce
I (30622) gatts_controller: Adding public address to white list.
I (30622) gatts_controller: 6c:2f:2c:e4:d1:27

Who is online

Users browsing this forum: No registered users and 13 guests