diff --git a/nimble/host/include/host/ble_esp_gap.h b/nimble/host/include/host/ble_esp_gap.h index e0977f48e..634c91143 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -112,6 +112,15 @@ int ble_gap_wl_read_size(uint8_t *size); */ int ble_gap_host_check_status(void); +/** + * This API is called to get local used address and address type. + * + * @param addr On success, locally used address will be stored here. + * + * @return 0 on success; nonzero on failure. +*/ +int ble_gap_get_local_used_addr(ble_addr_t *addr); + #if MYNEWT_VAL(BLE_HCI_VS) #if MYNEWT_VAL(BLE_POWER_CONTROL) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 65975ee63..6916a4ecd 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -805,6 +805,27 @@ ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask, #endif } +int ble_gap_get_local_used_addr(ble_addr_t *addr) +{ + uint8_t own_addr_type = 0; + const uint8_t *out_id_addr; + int rc; + + if (addr == NULL) { + return ESP_FAIL; + } + + own_addr_type = ble_gap_slave[0].our_addr_type; + + rc = ble_hs_id_addr(own_addr_type, &out_id_addr,NULL); + + if (rc == 0) { + addr->type = own_addr_type; + memcpy(addr->val, out_id_addr, BLE_DEV_ADDR_LEN); + } + + return rc; +} /***************************************************************************** * $misc * *****************************************************************************/