mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-24 09:57:22 +00:00
Added check to validate allowed random address
This commit is contained in:
committed by
Abhinav Kudnar
parent
28b42f4f14
commit
d8ca951e38
@@ -11,6 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Configure LE Data Length in controller (OGF = 0x08, OCF = 0x0022).
|
||||
*
|
||||
|
||||
@@ -176,6 +176,18 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_REPEAT_PAIRING_RETRY 1
|
||||
#define BLE_GAP_REPEAT_PAIRING_IGNORE 2
|
||||
|
||||
/**
|
||||
* @defgroup Mask for checking random address validity
|
||||
* @{
|
||||
*/
|
||||
/** Static random address check mask. */
|
||||
#define BLE_STATIC_RAND_ADDR_MASK 0xC0
|
||||
|
||||
/** Non RPA check mask. */
|
||||
#define BLE_NON_RPA_MASK 0x3F
|
||||
|
||||
/** @} */
|
||||
|
||||
/** Connection security state */
|
||||
struct ble_gap_sec_state {
|
||||
/** If connection is encrypted */
|
||||
|
||||
@@ -3264,6 +3264,7 @@ int
|
||||
ble_gap_ext_adv_set_addr(uint8_t instance, const ble_addr_t *addr)
|
||||
{
|
||||
int rc;
|
||||
ble_addr_t invalid_non_rpa_addr, invalid_static_rand_addr;
|
||||
|
||||
if (instance >= BLE_ADV_INSTANCES || addr->type != BLE_ADDR_RANDOM) {
|
||||
return BLE_HS_EINVAL;
|
||||
@@ -3273,6 +3274,35 @@ ble_gap_ext_adv_set_addr(uint8_t instance, const ble_addr_t *addr)
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
memset(&invalid_non_rpa_addr.val, 0xff, BLE_DEV_ADDR_LEN);
|
||||
memset(&invalid_static_rand_addr.val, 0x00, BLE_DEV_ADDR_LEN);
|
||||
|
||||
if ((addr->val[5] & BLE_STATIC_RAND_ADDR_MASK) == BLE_STATIC_RAND_ADDR_MASK) {
|
||||
invalid_static_rand_addr.val[5] = invalid_static_rand_addr.val[5] | BLE_STATIC_RAND_ADDR_MASK;
|
||||
|
||||
if (memcmp(invalid_non_rpa_addr.val, addr->val, BLE_DEV_ADDR_LEN) == 0 ||
|
||||
memcmp(invalid_static_rand_addr.val, addr->val, BLE_DEV_ADDR_LEN) == 0) {
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
} else if ((addr->val[5] | BLE_NON_RPA_MASK) == BLE_NON_RPA_MASK) {
|
||||
invalid_non_rpa_addr.val[5] = invalid_non_rpa_addr.val[5] & BLE_NON_RPA_MASK;
|
||||
|
||||
if (memcmp(invalid_non_rpa_addr.val, addr->val, BLE_DEV_ADDR_LEN) == 0 ||
|
||||
memcmp(invalid_static_rand_addr.val, addr->val, BLE_DEV_ADDR_LEN) == 0) {
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
} else {
|
||||
BLE_HS_LOG(ERROR, "Invalid random address \n");
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_ext_adv_set_addr_no_lock(instance, addr->val);
|
||||
ble_hs_unlock();
|
||||
|
||||
Reference in New Issue
Block a user