mirror of https://github.com/ARMmbed/mbed-os.git
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.pull/13759/head
parent
8fe2d7ebbe
commit
e4b317c1b1
|
@ -33,6 +33,9 @@
|
||||||
#include "source/pal/PalSecurityManager.h"
|
#include "source/pal/PalSecurityManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Cordio defines the random address used by connection to be the global one
|
||||||
|
#define CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION 1
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
MBED_STATIC_ASSERT(BLE_GAP_MAX_ADVERTISING_SETS < 0xFF, "BLE_GAP_MAX_ADVERTISING_SETS must be less than 255");
|
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(
|
||||||
if (is_extended_advertising_available()) {
|
if (is_extended_advertising_available()) {
|
||||||
// Addresses can be updated if the set is not advertising
|
// Addresses can be updated if the set is not advertising
|
||||||
if (!_active_sets.get(handle)) {
|
if (!_active_sets.get(handle)) {
|
||||||
|
#if CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION
|
||||||
|
_pal_gap.set_random_address(*random_address);
|
||||||
|
#endif
|
||||||
_pal_gap.set_advertising_set_random_address(handle, *random_address);
|
_pal_gap.set_advertising_set_random_address(handle, *random_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2324,7 +2330,7 @@ void Gap::signal_connection_complete(
|
||||||
address_resolved = true;
|
address_resolved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif BLE_ROLE_CENTRAL
|
#endif
|
||||||
|
|
||||||
#if BLE_ROLE_PERIPHERAL
|
#if BLE_ROLE_PERIPHERAL
|
||||||
if (event.getOwnRole() == connection_role_t::PERIPHERAL) {
|
if (event.getOwnRole() == connection_role_t::PERIPHERAL) {
|
||||||
|
@ -3207,7 +3213,7 @@ void Gap::on_address_resolution_completed(
|
||||||
|
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
#endif BLE_ROLE_OBSERVER
|
#endif // BLE_ROLE_OBSERVER
|
||||||
#endif // BLE_FEATURE_PRIVACY
|
#endif // BLE_FEATURE_PRIVACY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3264,6 +3270,7 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
|
||||||
bool advertising_use_main_address = true;
|
bool advertising_use_main_address = true;
|
||||||
// Extended advertising is a special case as the address isn't shared with
|
// Extended advertising is a special case as the address isn't shared with
|
||||||
// the main address.
|
// the main address.
|
||||||
|
#if !CORDIO_GLOBAL_RANDOM_ADDRESS_FOR_CONNECTION
|
||||||
#if BLE_FEATURE_EXTENDED_ADVERTISING
|
#if BLE_FEATURE_EXTENDED_ADVERTISING
|
||||||
if (is_extended_advertising_available()) {
|
if (is_extended_advertising_available()) {
|
||||||
if (operation == controller_operation_t::advertising) {
|
if (operation == controller_operation_t::advertising) {
|
||||||
|
@ -3277,6 +3284,8 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// For other cases we first compute the address being used and then compares
|
// For other cases we first compute the address being used and then compares
|
||||||
// it to the address to use to determine if the address is correct or not.
|
// it to the address to use to determine if the address is correct or not.
|
||||||
|
|
Loading…
Reference in New Issue