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
8eeaea0c58
commit
f9a646879b
@ -13,7 +13,7 @@
|
|||||||
#include "btc/btc_manage.h"
|
#include "btc/btc_manage.h"
|
||||||
#include "btc_gap_ble.h"
|
#include "btc_gap_ble.h"
|
||||||
#include "btc/btc_ble_storage.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)
|
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);
|
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)
|
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
|
||||||
{
|
{
|
||||||
|
@ -1627,13 +1627,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:
|
* @param[in] rand_addr: The address to be configured. Refer to the table below for possible address subtypes:
|
||||||
*
|
*
|
||||||
* | address [47:46] | Address Type |
|
* | address [47:46] | Address Type | Corresponding API |
|
||||||
* |-----------------|--------------------------|
|
* |-----------------|-----------------------------|----------------------------------------|
|
||||||
* | 0b00 | Non-Resolvable Private |
|
* | 0b00 | Non-Resolvable Private | esp_ble_gap_addr_create_nrpa |
|
||||||
* | | Address |
|
* | | Address (NRPA) | |
|
||||||
* |-----------------|--------------------------|
|
* |-----------------|-----------------------------|----------------------------------------|
|
||||||
* | 0b11 | Static Random Address |
|
* | 0b11 | Static Random Address | esp_ble_gap_addr_create_static |
|
||||||
* |-----------------|--------------------------|
|
* |-----------------|-----------------------------|----------------------------------------|
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* - ESP_OK : success
|
* - ESP_OK : success
|
||||||
@ -1642,6 +1642,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);
|
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
|
* @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.
|
* before generating and starting to use a new resolvable private address.
|
||||||
@ -1669,8 +1685,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);
|
esp_err_t esp_ble_gap_clear_rand_addr(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable/disable privacy (including address resolution) on the local device
|
* @brief Enable/disable privacy (including address resolution) on the local device
|
||||||
*
|
*
|
||||||
@ -1985,7 +1999,6 @@ esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr);
|
|||||||
*/
|
*/
|
||||||
int esp_ble_get_bond_device_num(void);
|
int esp_ble_get_bond_device_num(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the device from the security database list of peer device.
|
* @brief Get the device from the security database list of peer device.
|
||||||
* It will return the device bonded information immediately.
|
* It will return the device bonded information immediately.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user