Component/bt: add random address check for set_rand_addr()

This commit is contained in:
zhiweijian 2017-09-14 15:45:24 +08:00
parent 25b0a4f514
commit 691c8693e6
2 changed files with 19 additions and 4 deletions

View file

@ -760,16 +760,27 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
if (rand_addr != NULL) {
if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK)
== BT_STATIC_RAND_ADDR_MASK) {
/*
A static 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 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
*/
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
invalid_rand_addr_b[BD_ADDR_LEN - 1] = invalid_rand_addr_b[BD_ADDR_LEN - 1] | BT_STATIC_RAND_ADDR_MASK;
if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
&& 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);
} else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom address, the high bit should be 0x11xx");
LOG_ERROR("Invalid random address, the high bit should be 0b11, the random part shall not be to 1 or 0");
}
} else {
param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
LOG_ERROR("Invalid randrom addressm, the address value is NULL");
LOG_ERROR("Invalid random addressm, the address value is NULL");
}
msg.sig = BTC_SIG_API_CB;

View file

@ -677,6 +677,10 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK
if (!privacy_mode) { /* if privacy disabled, always use public address */
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC;
p_cb->privacy_mode = BTM_PRIVACY_NONE;
if (random_cb && random_cb->set_local_privacy_cback){
(*random_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
random_cb->set_local_privacy_cback = NULL;
}
} else { /* privacy is turned on*/
/* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */
p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM;