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);
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