Skip to content

Commit 393f3da

Browse files
committed
Merge branch 'feature/btdm_add_get_local_used_addr_API' into 'master'
Component/bt: add esp_ble_gap_get_local_used_addr() API See merge request idf/esp-idf!2137
2 parents 7133e14 + 8a78860 commit 393f3da

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

components/bt/bluedroid/api/esp_gap_ble_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ esp_err_t esp_ble_gap_set_device_name(const char *name)
268268
return esp_bt_dev_set_device_name(name);
269269
}
270270

271+
esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type)
272+
{
273+
if(esp_bluedroid_get_status() != (ESP_BLUEDROID_STATUS_ENABLED)) {
274+
LOG_ERROR("%s, bluedroid status error", __func__);
275+
return ESP_FAIL;
276+
}
277+
if(!BTM_BleGetCurrentAddress(local_used_addr, addr_type)) {
278+
return ESP_FAIL;
279+
}
280+
return ESP_OK;
281+
}
282+
271283
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
272284
{
273285
if (((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA)) &&

components/bt/bluedroid/api/include/esp_gap_ble_api.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,18 @@ esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
830830
*/
831831
esp_err_t esp_ble_gap_set_device_name(const char *name);
832832

833-
833+
/**
834+
* @brief This function is called to get local used address and adress type.
835+
* uint8_t *esp_bt_dev_get_address(void) get the public address
836+
*
837+
* @param[in] local_used_addr - current local used ble address (six bytes)
838+
* @param[in] addr_type - ble address type
839+
*
840+
* @return - ESP_OK : success
841+
* - other : failed
842+
*
843+
*/
844+
esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type);
834845
/**
835846
* @brief This function is called to get ADV data for a specific type.
836847
*

components/bt/bluedroid/stack/btm/btm_ble_gap.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,37 @@ tBTM_STATUS BTM_BleSetRandAddress(BD_ADDR rand_addr)
16041604
}
16051605
}
16061606

1607+
/*******************************************************************************
1608+
**
1609+
** Function BTM_BleGetCurrentAddress
1610+
**
1611+
** Description This function is called to get local used BLE address.
1612+
**
1613+
** Parameters: None.
1614+
**
1615+
** Returns success or fail
1616+
**
1617+
*******************************************************************************/
1618+
BOOLEAN BTM_BleGetCurrentAddress(BD_ADDR addr, uint8_t *addr_type)
1619+
{
1620+
if(addr == NULL || addr_type == NULL) {
1621+
BTM_TRACE_ERROR("%s addr or addr_type is NULL\n", __func__);
1622+
return FALSE;
1623+
}
1624+
if(btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) {
1625+
*addr_type = BLE_ADDR_RANDOM;
1626+
memcpy(addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN);
1627+
} else if(btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_PUBLIC) {
1628+
*addr_type = BLE_ADDR_PUBLIC;
1629+
memcpy(addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN);
1630+
} else {
1631+
BTM_TRACE_ERROR("%s\n", __func__);
1632+
memset(addr, 0, BD_ADDR_LEN);
1633+
return FALSE;
1634+
}
1635+
return TRUE;
1636+
}
1637+
16071638
/*******************************************************************************
16081639
**
16091640
** Function BTM_CheckAdvData

components/bt/bluedroid/stack/include/btm_ble_api.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,19 @@ void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback);
15411541
//extern
15421542
UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length);
15431543

1544+
/*******************************************************************************
1545+
**
1546+
** Function BTM_BleGetCurrentAddress
1547+
**
1548+
** Description This function is called to get local used BLE address.
1549+
**
1550+
** Parameters: None.
1551+
**
1552+
** Returns success or fail
1553+
**
1554+
*******************************************************************************/
1555+
BOOLEAN BTM_BleGetCurrentAddress(BD_ADDR addr, uint8_t *addr_type);
1556+
15441557
/*******************************************************************************
15451558
**
15461559
** Function BTM__BLEReadDiscoverability

0 commit comments

Comments
 (0)