diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index 6640c93243..ec1d6752d7 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -13,7 +13,7 @@ #include "btc/btc_manage.h" #include "btc_gap_ble.h" #include "btc/btc_ble_storage.h" - +#include "esp_random.h" esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback) { @@ -188,6 +188,25 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_err_t esp_ble_gap_addr_create_static(esp_bd_addr_t rand_addr) +{ + // Static device address: First two bits are '11', rest is random + rand_addr[0] = 0xC0 | (esp_random() & 0x3F); + for (int i = 1; i < 6; i++) { + rand_addr[i] = esp_random() & 0xFF; // Randomize remaining bits + } + return ESP_OK; +} + +esp_err_t esp_ble_gap_addr_create_nrpa(esp_bd_addr_t rand_addr) +{ + // Non-resolvable private address: First two bits are '00', rest is random + rand_addr[0] = (esp_random() & 0x3F); + for (int i = 1; i < 6; i++) { + rand_addr[i] = esp_random() & 0xFF; // Randomize remaining bits + } + return ESP_OK; +} esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr) { @@ -223,6 +242,29 @@ esp_err_t esp_ble_gap_set_resolvable_private_address_timeout(uint16_t rpa_timeou return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } + +esp_err_t esp_ble_gap_add_device_to_resolving_list(esp_bd_addr_t peer_addr, uint8_t addr_type, uint8_t *peer_irk) +{ + ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); + + if (addr_type > BLE_ADDR_TYPE_RANDOM ||!peer_addr || (addr_type && ((peer_addr[0] & 0xC0) != 0xC0))) { + return ESP_ERR_INVALID_ARG; + } + + btc_msg_t msg = {0}; + btc_ble_gap_args_t arg; + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_ADD_DEVICE_TO_RESOLVING_LIST; + + memcpy(arg.add_dev_to_resolving_list.addr, peer_addr, ESP_BD_ADDR_LEN); + arg.add_dev_to_resolving_list.addr_type = addr_type; + memcpy(arg.add_dev_to_resolving_list.irk, peer_irk, ESP_PEER_IRK_LEN); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + esp_err_t esp_ble_gap_clear_rand_addr(void) { btc_msg_t msg; diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h index 1941901417..182f87600d 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -19,7 +19,7 @@ extern "C" { return ESP_ERR_INVALID_STATE; \ } -#define ESP_BT_STATUS_BASE_FOR_HCI_ERR 0X0100 /* base for coverting HCI error code to ESP status */ +#define ESP_BT_STATUS_BASE_FOR_HCI_ERR 0X0100 /* base for converting HCI error code to ESP status */ /* relate to BT_STATUS_xxx in bt_def.h */ /// Status Return Value @@ -163,6 +163,9 @@ typedef enum { /// Bluetooth address length #define ESP_BD_ADDR_LEN 6 +/// Bluetooth peer irk +#define ESP_PEER_IRK_LEN 16 + /// Bluetooth device address typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index 5134cde0f1..7cbe67116a 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -225,7 +225,8 @@ typedef enum { // BLE_INCLUDED ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT, /*!< When clear advertising complete, the event comes */ ESP_GAP_BLE_SET_RPA_TIMEOUT_COMPLETE_EVT, /*!< When set the Resolvable Private Address (RPA) timeout completes, the event comes */ - ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT, /*!< When vendor hci command complete, the event comes */ + ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT, /*!< when add a device to the resolving list completes, the event comes*/ + ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT, /*!< When vendor hci command complete, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1159,6 +1160,13 @@ typedef union { struct ble_rpa_timeout_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate the set RPA timeout operation success status */ } set_rpa_timeout_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_RPA_TIMEOUT_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT + */ + struct ble_add_dev_to_resolving_list_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicates the success status of adding a device to the resolving list */ + } add_dev_to_resolving_list_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT */ + /** * @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */ @@ -1635,13 +1643,13 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_ * * @param[in] rand_addr: The address to be configured. Refer to the table below for possible address subtypes: * - * | address [47:46] | Address Type | - * |-----------------|--------------------------| - * | 0b00 | Non-Resolvable Private | - * | | Address | - * |-----------------|--------------------------| - * | 0b11 | Static Random Address | - * |-----------------|--------------------------| + * | address [47:46] | Address Type | Corresponding API | + * |-----------------|-----------------------------|----------------------------------------| + * | 0b00 | Non-Resolvable Private | esp_ble_gap_addr_create_nrpa | + * | | Address (NRPA) | | + * |-----------------|-----------------------------|----------------------------------------| + * | 0b11 | Static Random Address | esp_ble_gap_addr_create_static | + * |-----------------|-----------------------------|----------------------------------------| * * @return * - ESP_OK : success @@ -1650,6 +1658,22 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_ */ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); +/** + * @brief Create a static device address + * @param[out] rand_addr: Pointer to the buffer where the static device address will be stored. + * @return - ESP_OK : Success + * - Other : Failed + */ +esp_err_t esp_ble_gap_addr_create_static(esp_bd_addr_t rand_addr); + +/** + * @brief Create a non-resolvable private address (NRPA) + * @param[out] rand_addr: Pointer to the buffer where the NRPA will be stored. + * @return - ESP_OK : Success + * - Other : Failed + */ +esp_err_t esp_ble_gap_addr_create_nrpa(esp_bd_addr_t rand_addr); + /** * @brief This function sets the length of time the Controller uses a Resolvable Private Address * before generating and starting to use a new resolvable private address. @@ -1667,6 +1691,27 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); */ esp_err_t esp_ble_gap_set_resolvable_private_address_timeout(uint16_t rpa_timeout); + +/** + * @brief This function adds a device to the resolving list used to generate and resolve Resolvable Private Addresses + * in the Controller. + * + * @note Note: This function shall not be used when address resolution is enabled in the Controller and: + * - Advertising (other than periodic advertising) is enabled, + * - Scanning is enabled, or + * - an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or HCI_LE_Periodic_Advertising_Create_Sync command is pending. + * This command may be used at any time when address resolution is disabled in the Controller. + * The added device shall be set to Network Privacy mode. + * + * @param[in] peer_addr: The peer identity address of the device to be added to the resolving list. + * @param[in] addr_type: The address type of the peer identity address (BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM). + * @param[in] peer_irk: The Identity Resolving Key (IRK) of the device. + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_add_device_to_resolving_list(esp_bd_addr_t peer_addr, uint8_t addr_type, uint8_t *peer_irk); /** * @brief This function clears the random address for the application * @@ -1677,8 +1722,6 @@ esp_err_t esp_ble_gap_set_resolvable_private_address_timeout(uint16_t rpa_timeou */ esp_err_t esp_ble_gap_clear_rand_addr(void); - - /** * @brief Enable/disable privacy (including address resolution) on the local device * @@ -1993,7 +2036,6 @@ esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr); */ int esp_ble_get_bond_device_num(void); - /** * @brief Get the device from the security database list of peer device. * It will return the device bonded information immediately. diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 3ddfad9f49..a0c50972c7 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5827,6 +5827,15 @@ void bta_dm_ble_gap_set_rpa_timeout(tBTA_DM_MSG *p_data) BTM_BleSetRpaTimeout(p_data->set_rpa_timeout.rpa_timeout,p_data->set_rpa_timeout.p_set_rpa_timeout_cback); } +void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data) +{ + APPL_TRACE_API("%s", __func__); + BTM_BleAddDevToResolvingList(p_data->add_dev_to_resolving_list.addr, + p_data->add_dev_to_resolving_list.addr_type, + p_data->add_dev_to_resolving_list.irk, + p_data->add_dev_to_resolving_list.p_add_dev_to_resolving_list_callback); +} + #if (BLE_50_FEATURE_SUPPORT == TRUE) void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data) { diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index 54e9efaf27..399cde0405 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -2918,6 +2918,40 @@ void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK } } +/******************************************************************************* +** +** Function BTA_DmBleAddDevToResolvingList +** +** Description This function adds a device to the resolving list of the +** Bluetooth controller. The resolving list is used for resolving +** the identity of devices using resolvable private addresses (RPAs). +** +** Parameters addr: Bluetooth device address to be added to the resolving list +** addr_type: Type of the address (public or random) +** irk: Identity Resolving Key (IRK) of the device +** add_dev_to_resolving_list_callback: Callback function to be invoked +** upon completion of the operation +** +** Returns void +** +*******************************************************************************/ +void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, + uint8_t addr_type, + PEER_IRK irk, + tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback) +{ + tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST *p_msg; + if ((p_msg = (tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST))) != NULL) { + memset(p_msg, 0, sizeof(tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST)); + p_msg->hdr.event = BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT; + memcpy(p_msg->addr, addr, BD_ADDR_LEN); // Copy the device address to the message + p_msg->addr_type = addr_type; // Assign the address type to the message + memcpy(p_msg->irk, irk, PEER_IRK_LEN); // Copy the IRK to the message + p_msg->p_add_dev_to_resolving_list_callback = add_dev_to_resolving_list_callback; + bta_sys_sendmsg(p_msg); + } +} + void BTA_DmClearRandAddress(void) { tBTA_DM_APT_CLEAR_ADDR *p_msg; diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index b357c06ef5..6242593c73 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -233,6 +233,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_ble_gap_dtm_stop, /* BTA_DM_API_DTM_STOP_EVT */ bta_dm_ble_gap_clear_adv, /* BTA_DM_API_BLE_CLEAR_ADV_EVT */ bta_dm_ble_gap_set_rpa_timeout, /* BTA_DM_API_SET_RPA_TIMEOUT_EVT */ + bta_dm_ble_gap_add_dev_to_resolving_list, /* BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT */ #endif }; diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index a8bb5c880e..c4be563785 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -224,6 +224,7 @@ enum { BTA_DM_API_DTM_STOP_EVT, BTA_DM_API_BLE_CLEAR_ADV_EVT, BTA_DM_API_SET_RPA_TIMEOUT_EVT, + BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT, #endif BTA_DM_MAX_EVT }; @@ -789,6 +790,14 @@ typedef struct { tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback; } tBTA_DM_API_SET_RPA_TIMEOUT; +typedef struct { + BT_HDR hdr; // Event header + esp_bd_addr_t addr; // Bluetooth device address + UINT8 addr_type; // Type of the address + UINT8 irk[PEER_IRK_LEN]; // Identity Resolving Key (IRK) + tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback; // Callback function pointer +} tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST; + /* set adv parameter for BLE advertising */ typedef struct { BT_HDR hdr; @@ -1294,6 +1303,7 @@ typedef union { tBTA_DM_APT_SET_DEV_ADDR set_addr; tBTA_DM_APT_CLEAR_ADDR clear_addr; tBTA_DM_API_SET_RPA_TIMEOUT set_rpa_timeout; + tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST add_dev_to_resolving_list; tBTA_DM_API_BLE_MULTI_ADV_ENB ble_multi_adv_enb; tBTA_DM_API_BLE_MULTI_ADV_PARAM ble_multi_adv_param; tBTA_DM_API_BLE_MULTI_ADV_DATA ble_multi_adv_data; @@ -1789,6 +1799,7 @@ extern void bta_dm_ble_gap_dtm_rx_start(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_dtm_stop(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_clear_adv(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_set_rpa_timeout(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data); #if (BLE_50_FEATURE_SUPPORT == TRUE) extern void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_dtm_enhance_rx_start(tBTA_DM_MSG *p_data); diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index cc2a3d66c6..de1657de8d 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -435,6 +435,8 @@ typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK; typedef tBTM_SET_RPA_TIMEOUT_CMPL_CBACK tBTA_SET_RPA_TIMEOUT_CMPL_CBACK; +typedef tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK; + typedef tBTM_CMPL_CB tBTA_CMPL_CB; typedef tBTM_VSC_CMPL tBTA_VSC_CMPL; @@ -2615,6 +2617,10 @@ extern void BTA_DmBleStopAdvertising(void); extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback); extern void BTA_DmClearRandAddress(void); extern void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback); +extern void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, + uint8_t addr_type, + PEER_IRK irk, + tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback); #endif #if BLE_INCLUDED == TRUE diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 27849250d1..b0b21147ee 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -907,6 +907,25 @@ static void btc_set_rpa_timeout_callback(UINT8 status) } } +static void btc_add_dev_to_resolving_list_callback(UINT8 status) +{ + esp_ble_gap_cb_param_t param; + bt_status_t ret; + btc_msg_t msg = {0}; + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BLE; + msg.act = ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT; + + param.add_dev_to_resolving_list_cmpl.status = btc_btm_status_to_esp_status(status); + + ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); + + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + #if (SMP_INCLUDED == TRUE) static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status) { @@ -1425,6 +1444,14 @@ static void btc_ble_set_rpa_timeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CM BTA_DmBleSetRpaTimeout(rpa_timeout,set_rpa_timeout_cback); } +static void btc_ble_add_device_to_resolving_list(BD_ADDR addr, + uint8_t addr_type, + uint8_t irk[], + tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback) +{ + BTA_DmBleAddDevToResolvingList(addr, addr_type, irk, add_dev_to_resolving_list_callback); +} + static void btc_ble_clear_rand_addr (void) { BTA_DmClearRandAddress(); @@ -1883,6 +1910,13 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) btc_ble_set_rpa_timeout(arg->set_rpa_timeout.rpa_timeout,btc_set_rpa_timeout_callback); break; } + case BTC_GAP_BLE_ACT_ADD_DEVICE_TO_RESOLVING_LIST: { + btc_ble_add_device_to_resolving_list(arg->add_dev_to_resolving_list.addr, + arg->add_dev_to_resolving_list.addr_type, + arg->add_dev_to_resolving_list.irk, + btc_add_dev_to_resolving_list_callback); + break; + } case BTC_GAP_BLE_ACT_CLEAR_RAND_ADDRESS: { btc_ble_clear_rand_addr(); break; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index f790804cb4..2547d6afff 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -103,6 +103,7 @@ typedef enum { BTC_GAP_BLE_ACT_CLEAR_ADV, #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE) BTC_GAP_BLE_ACT_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, + BTC_GAP_BLE_ACT_ADD_DEVICE_TO_RESOLVING_LIST, BTC_GAP_BLE_ACT_VENDOR_HCI_CMD_EVT, } btc_gap_ble_act_t; @@ -145,6 +146,12 @@ typedef union { struct set_rpa_timeout_args { uint16_t rpa_timeout; } set_rpa_timeout; + //BTC_GAP_BLE_ACT_ADD_DEVICE_TO_RESOLVING_LIST + struct add_dev_to_resolving_list_args { + esp_bd_addr_t addr; + uint8_t addr_type; + uint8_t irk[PEER_IRK_LEN]; + } add_dev_to_resolving_list; //BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, struct cfg_local_privacy_args { bool privacy_enable; diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index df5d2e06a7..bcd019d6df 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -4712,6 +4712,20 @@ BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout,tBTM_SET_RPA_TIMEOUT_CMPL_CBAC return TRUE; } +BOOLEAN BTM_BleAddDevToResolvingList(BD_ADDR addr, + uint8_t addr_type, + uint8_t irk[], + tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback) +{ + UINT8 *local_irk = btm_cb.devcb.id_keys.irk; + if ((btsnd_hcic_ble_add_device_resolving_list(addr_type, addr, irk, local_irk)) != TRUE) { + BTM_TRACE_ERROR("Add device to resolving list error"); + return FALSE; + } + btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb = p_add_dev_to_resolving_list_callback; + return TRUE; +} + bool btm_ble_adv_pkt_ready(void) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c index 546eff3d47..4c8ff65207 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c @@ -275,6 +275,14 @@ void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) { UINT8 status; STREAM_TO_UINT8(status, p); + if (btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb) { + tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_cb = btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb; + if (p_cb) { + (*p_cb)(status); + } + } else { + BTM_TRACE_DEBUG("no resolving list callback"); + } BTM_TRACE_DEBUG("%s status = %d", __func__, status); diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index 74a9705e79..182d15dfb3 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -236,6 +236,7 @@ tBTM_CMPL_CB *p_ble_channels_cmpl_cb; /* Callback function to be called tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_ble_set_rpa_timeout_cmpl_cb; /* Callback function to be called When ble set rpa timeout is completed */ +tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_cmpl_cb; tBTM_CMPL_CB *p_le_test_cmd_cmpl_cb; /* Callback function to be called when LE test mode command has been sent successfully */ diff --git a/components/bt/host/bluedroid/stack/include/stack/bt_types.h b/components/bt/host/bluedroid/stack/include/stack/bt_types.h index be803d50d2..d9fdaf2df8 100644 --- a/components/bt/host/bluedroid/stack/include/stack/bt_types.h +++ b/components/bt/host/bluedroid/stack/include/stack/bt_types.h @@ -676,6 +676,11 @@ typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...); typedef uint8_t BD_ADDR[BD_ADDR_LEN]; #endif +/* peer irk */ +#ifndef PEER_IRK_LEN +#define PEER_IRK_LEN 16 +typedef uint8_t PEER_IRK[PEER_IRK_LEN]; +#endif // From bd.c /***************************************************************************** diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 189de9c14b..8e0687ec90 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -198,6 +198,8 @@ typedef void (tBTM_UPDATE_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_o typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); typedef void (tBTM_SET_RPA_TIMEOUT_CMPL_CBACK) (UINT8 status); + +typedef void (tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK) (UINT8 status); /******************************* ** Device Coexist status ********************************/ diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 545e95819b..a9842e85f4 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -2667,6 +2667,27 @@ BOOLEAN BTM_BleClearAdv(tBTM_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback); *******************************************************************************/ BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout, tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback); +/******************************************************************************* +** +** Function BTM_BleAddDevToResolvingList +** +** Description This function is called to add a device to the resolving list +** used to generate and resolve Resolvable Private Addresses (RPAs) +** in the Bluetooth Controller. +** +** Parameters addr - The address of the device to be added to the resolving list. +** addr_type - The address type of the device (public or random). +** irk - The Identity Resolving Key (IRK) of the device. +** p_add_dev_to_resolving_list_callback - Callback function to be called when the operation is completed. +** +** Returns TRUE if the operation was successful, otherwise FALSE. +** +*******************************************************************************/ +BOOLEAN BTM_BleAddDevToResolvingList(BD_ADDR addr, + uint8_t addr_type, + uint8_t irk[], + tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback); + /* #ifdef __cplusplus } diff --git a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h index 6fc5e74006..b7d64edd99 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h @@ -625,7 +625,7 @@ BOOLEAN btsnd_hcic_write_voice_settings(UINT16 flags); /* Write Voice BOOLEAN btsnd_hcic_write_auto_flush_tout(UINT16 handle, - UINT16 timeout); /* Write Retransmit Timout */ + UINT16 timeout); /* Write Retransmit Timeout */ #define HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT 4