mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
component/bt: refactor ble random address setting
This commit is contained in:
@ -897,7 +897,7 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
|
|||||||
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
|
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function sets the random address for the application
|
* @brief This function sets the static Random Address and Non-Resolvable Private Address for the application
|
||||||
*
|
*
|
||||||
* @param[in] rand_addr: the random address which should be setting
|
* @param[in] rand_addr: the random address which should be setting
|
||||||
*
|
*
|
||||||
|
@ -856,22 +856,38 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *
|
|||||||
• The two most significant bits of the address shall be equal to 1
|
• The two most significant bits of the address shall be equal to 1
|
||||||
• All bits of the random part of the address shall not be equal to 1
|
• All bits of the random part of the address shall not be equal to 1
|
||||||
• All bits of the random part of the address shall not be equal to 0
|
• All bits of the random part of the address shall not be equal to 0
|
||||||
|
A non-resolvable private address is a 48-bit randomly generated address and shall meet the following requirements:
|
||||||
|
• The two most significant bits of the address shall be equal to 0
|
||||||
|
• All bits of the random part of the address shall not be equal to 1
|
||||||
|
• All bits of the random part of the address shall not be equal to 0
|
||||||
*/
|
*/
|
||||||
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
|
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
|
||||||
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
|
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
|
||||||
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
|
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
|
||||||
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
|
|
||||||
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
|
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK) {
|
||||||
&& memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
|
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
|
||||||
&& memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
|
if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0) {
|
||||||
BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback);
|
BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback);
|
||||||
} else {
|
} else {
|
||||||
|
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
||||||
|
BTC_TRACE_ERROR("Invalid static random address, the high bit should be 0b11, bits of the random part shall not be all 1 or 0");
|
||||||
|
}
|
||||||
|
} else if ((rand_addr[0] | BT_NON_RPA_MASK) == BT_NON_RPA_MASK) {
|
||||||
|
invalid_rand_addr_a[0] = invalid_rand_addr_a[0] & BT_NON_RPA_MASK;
|
||||||
|
if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0) {
|
||||||
|
BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback);
|
||||||
|
} else {
|
||||||
|
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
||||||
|
BTC_TRACE_ERROR("Invalid non-resolvable private address, the high bit should be 0b00, bits of the random part shall not be all 1 or 0");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
||||||
BTC_TRACE_ERROR("Invalid random address, the high bit should be 0b11, bits of the random part shall not be all 1 or 0");
|
BTC_TRACE_ERROR("Invalid random address type");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR);
|
||||||
BTC_TRACE_ERROR("Invalid random addressm, the address value is NULL");
|
BTC_TRACE_ERROR("Invalid address, the address value is NULL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ typedef bool BOOLEAN;
|
|||||||
#define BT_EVT_MASK 0xFF00
|
#define BT_EVT_MASK 0xFF00
|
||||||
#define BT_SUB_EVT_MASK 0x00FF
|
#define BT_SUB_EVT_MASK 0x00FF
|
||||||
#define BT_STATIC_RAND_ADDR_MASK 0xC0
|
#define BT_STATIC_RAND_ADDR_MASK 0xC0
|
||||||
|
#define BT_NON_RPA_MASK 0x3F
|
||||||
/* To Bluetooth Upper Layers */
|
/* To Bluetooth Upper Layers */
|
||||||
/************************************/
|
/************************************/
|
||||||
#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* L2CAP event */
|
#define BT_EVT_TO_BTU_L2C_EVT 0x0900 /* L2CAP event */
|
||||||
|
Reference in New Issue
Block a user