diff --git a/include/esp32/esp32_bt_gap.h b/include/esp32/esp32_bt_gap.h index 386e1d0..0592360 100644 --- a/include/esp32/esp32_bt_gap.h +++ b/include/esp32/esp32_bt_gap.h @@ -40,6 +40,12 @@ bool mgos_bt_gap_get_pairing_enable(void); bool mgos_bt_gap_set_pairing_enable(bool pairing_enable); int mgos_bt_gap_get_num_paired_devices(void); + +/* + * Return list of paired devices; the caller should free it. + */ +bool mgos_bt_gap_get_paired_device_list(int *dev_num, struct mgos_bt_addr *list); + /* * These are actually async. TODO(rojer): Add callbacks to the API. * For now, just allow some time for the calls to complete. diff --git a/src/esp32/esp32_bt_gap.c b/src/esp32/esp32_bt_gap.c index 4b23dff..da90a5d 100644 --- a/src/esp32/esp32_bt_gap.c +++ b/src/esp32/esp32_bt_gap.c @@ -140,6 +140,25 @@ bool mgos_bt_gap_set_pairing_enable(bool pairing_enable) { } } +bool mgos_bt_gap_get_paired_device_list(int *dev_num, struct mgos_bt_addr *list) { +esp_ble_bond_dev_t *dev_list; +bool rc = true; + + if(*dev_num == 0) + return false; + if((dev_list = calloc(*dev_num, sizeof(esp_ble_bond_dev_t))) == NULL) + return false; + if(esp_ble_get_bond_device_list(dev_num, dev_list) == ESP_OK) { + for(int i=0; i<*dev_num; i++) { + memcpy(&list->addr, &dev_list[i].bd_addr, sizeof(esp_bd_addr_t)); + list->type = MGOS_BT_ADDR_TYPE_NONE; + ++list; + } + } else rc = false; + free(dev_list); + return rc; +} + void mgos_bt_gap_remove_paired_device(const esp_bd_addr_t addr) { esp_ble_remove_bond_device((uint8_t *) addr); }