Skip to content

Commit e4b317c

Browse files
committed
BLE: Add workaround for cordio use of global random address
In Cordio, the global random address is used when the local device is connected instead of the advertising set one. This can cause pairing to fail if the advertising set address and the global random address are different. This workaround forces the global random address to be set when advertising is started and extended advertising is present.
1 parent 8fe2d7e commit e4b317c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "source/pal/PalSecurityManager.h"
3434

3535

36+
// Cordio defines the random address used by connection to be the global one
37+
#define CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION 1
38+
3639
using namespace std::chrono;
3740

3841
MBED_STATIC_ASSERT(BLE_GAP_MAX_ADVERTISING_SETS < 0xFF, "BLE_GAP_MAX_ADVERTISING_SETS must be less than 255");
@@ -1928,6 +1931,9 @@ ble_error_t Gap::startAdvertising(
19281931
if (is_extended_advertising_available()) {
19291932
// Addresses can be updated if the set is not advertising
19301933
if (!_active_sets.get(handle)) {
1934+
#if CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION
1935+
_pal_gap.set_random_address(*random_address);
1936+
#endif
19311937
_pal_gap.set_advertising_set_random_address(handle, *random_address);
19321938
}
19331939

@@ -2324,7 +2330,7 @@ void Gap::signal_connection_complete(
23242330
address_resolved = true;
23252331
}
23262332
}
2327-
#endif BLE_ROLE_CENTRAL
2333+
#endif
23282334

23292335
#if BLE_ROLE_PERIPHERAL
23302336
if (event.getOwnRole() == connection_role_t::PERIPHERAL) {
@@ -3207,7 +3213,7 @@ void Gap::on_address_resolution_completed(
32073213

32083214
delete event;
32093215
}
3210-
#endif BLE_ROLE_OBSERVER
3216+
#endif // BLE_ROLE_OBSERVER
32113217
#endif // BLE_FEATURE_PRIVACY
32123218
}
32133219

@@ -3264,6 +3270,7 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
32643270
bool advertising_use_main_address = true;
32653271
// Extended advertising is a special case as the address isn't shared with
32663272
// the main address.
3273+
#if !CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION
32673274
#if BLE_FEATURE_EXTENDED_ADVERTISING
32683275
if (is_extended_advertising_available()) {
32693276
if (operation == controller_operation_t::advertising) {
@@ -3277,6 +3284,8 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
32773284
}
32783285
}
32793286
#endif
3287+
#endif
3288+
32803289

32813290
// For other cases we first compute the address being used and then compares
32823291
// it to the address to use to determine if the address is correct or not.

0 commit comments

Comments
 (0)