mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(ble/bluedroid): Support create BLE static random address and NRPA
This commit is contained in:
parent
36c9953588
commit
9ae6007b5b
@ -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)
|
||||
{
|
||||
|
@ -1643,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
|
||||
@ -1658,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.
|
||||
@ -1706,7 +1722,6 @@ esp_err_t esp_ble_gap_add_device_to_resolving_list(esp_bd_addr_t peer_addr, uint
|
||||
*/
|
||||
esp_err_t esp_ble_gap_clear_rand_addr(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable/disable privacy (including address resolution) on the local device
|
||||
*
|
||||
@ -2021,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.
|
||||
|
Loading…
Reference in New Issue
Block a user