bluedroid: fix ble ext adv rand addr setting for NRPA

This commit is contained in:
chenjianhua 2023-05-06 15:20:08 +08:00
parent d7a927190b
commit 90f52cf0c7

View File

@ -302,10 +302,26 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr)
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));
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK) {
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK; 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 (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) == 0
&& memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 || memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) == 0) {
&& memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){ status = BTM_ILLEGAL_VALUE;
goto end;
}
} 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) {
status = BTM_ILLEGAL_VALUE;
goto end;
}
} else {
BTM_TRACE_ERROR("%s invalid random address", __func__);
status = BTM_ILLEGAL_VALUE;
goto end;
}
// set random address // set random address
if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) { if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)", BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)",
@ -318,11 +334,6 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr)
BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr); BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr);
} }
} }
} else {
BTM_TRACE_ERROR("%s invalid random address", __func__);
status = BTM_ILLEGAL_VALUE;
goto end;
}
end: end:
cb_params.status = status; cb_params.status = status;