From e1842ccd8797e569c32a90d6e6b794dbd8186c30 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 13 Oct 2020 16:16:17 +0100 Subject: [PATCH 1/2] BLE: Workaround for WB55 connection event The connection event reported by the WB55 is incorrect if controller privacy is not enable and the peer connects with an unknown private resolvable address: The RPA field contains the connection address (it should be empty) and the peer address is all FF while it should be equal to the connection address. --- .../source/cordio/source/PalGapImpl.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h b/connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h index 9b4e99fbbc0..3ea3fd41e83 100644 --- a/connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h +++ b/connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h @@ -364,18 +364,30 @@ class PalGap final : public ble::PalGap { static GapConnectionCompleteEvent convert(const hciLeConnCmplEvt_t *conn_evt) { + const bdAddr_t *peer_rpa = &conn_evt->peerRpa; + const bdAddr_t *peer_address = &conn_evt->peerAddr; + +#if defined(TARGET_MCU_STM32WB55xx) + const bdAddr_t invalidAddress = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + if (conn_evt->addrType == DM_ADDR_RANDOM && + memcmp(peer_address, invalidAddress, sizeof(invalidAddress)) == 0 && + memcmp(peer_rpa, invalidAddress, sizeof(invalidAddress) != 0) + ) { + std::swap(peer_rpa, peer_address); + } +#endif return GapConnectionCompleteEvent( conn_evt->status, // note the usage of the stack handle, not the HCI handle conn_evt->hdr.param, (connection_role_t::type) conn_evt->role, (peer_address_type_t::type) conn_evt->addrType, - conn_evt->peerAddr, + *peer_address, conn_evt->connInterval, conn_evt->connLatency, conn_evt->supTimeout, conn_evt->localRpa, - conn_evt->peerRpa + *peer_rpa ); } }; From 2a4a097a9358c911bff62d07d4ff817a0b0af73c Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 13 Oct 2020 16:16:48 +0100 Subject: [PATCH 2/2] BLE: Take advantage of controller based address resolution on WB55 --- connectivity/FEATURE_BLE/mbed_lib.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/connectivity/FEATURE_BLE/mbed_lib.json b/connectivity/FEATURE_BLE/mbed_lib.json index 75c368dcb68..ad105f5b662 100644 --- a/connectivity/FEATURE_BLE/mbed_lib.json +++ b/connectivity/FEATURE_BLE/mbed_lib.json @@ -112,6 +112,9 @@ "target_overrides": { "MCU_NRF52840": { "ble-gap-host-based-private-address-resolution": false + }, + "NUCLEO_WB55RG": { + "ble-gap-host-based-private-address-resolution": false } } }