Skip to content

Commit 67ec632

Browse files
author
Donatien Garnier
committed
Added update_random_address() implementation in GenericGap
1 parent 3523cdb commit 67ec632

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,16 +1377,40 @@ void GenericGap::set_random_address_rotation(bool enable)
13771377

13781378
void GenericGap::update_random_address()
13791379
{
1380-
ble::address_t address;
1381-
13821380
if(!_random_address_rotating)
13831381
{
13841382
// This event might have been queued before we disabled address rotation
13851383
return;
13861384
}
13871385

1388-
// TODO: Placeholder: Get random data
1389-
// Build a non-resolvable private address
1386+
ble::address_t address;
1387+
1388+
do {
1389+
byte_array_t<8> random_data;
1390+
1391+
ble_error_t ret = _pal_sm.get_random_data(random_data);
1392+
if (ret != BLE_ERROR_NONE) {
1393+
// Abort
1394+
return;
1395+
}
1396+
1397+
// Build a non-resolvable private address as specified in the Core 4.2 spec, Vol 6, Part B, 1.3.2.2
1398+
// Mask out two MSbs
1399+
random_data[5] &= 0x3F;
1400+
1401+
// Copy to address - will copy first 6 bytes
1402+
address = ble::address_t(random_data.data());
1403+
1404+
if(!is_random_private_non_resolvable_address(address.data()))
1405+
{
1406+
// If address is invalid, which is unlikely (all 0s or all 1s), try again
1407+
// If implementation is faulty, we'll get stuck here
1408+
continue;
1409+
}
1410+
1411+
// Address is valid
1412+
break;
1413+
} while(true);
13901414

13911415
ble_error_t err = _pal_gap.set_random_address(
13921416
address

0 commit comments

Comments
 (0)