From 30dac7cd8c694bdeaee0c596612259b3ef4a2966 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 23 May 2018 17:16:27 +0100 Subject: [PATCH 1/3] BLE NRF52: Fix identity address flag in connection request. --- .../TARGET_NRF52/source/nRF5xGap.cpp | 33 +++++++++++-------- .../TARGET_NRF52/source/nRF5xGap.h | 1 + 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp index 7e72e35a22..ae6abae00e 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp @@ -501,7 +501,11 @@ ble_error_t nRF5xGap::connect( return BLE_ERROR_INVALID_PARAM; } - return connect(peerAddr, legacy_address, connectionParams, scanParamsIn); + bool identity = + peerAddrType == peer_address_type_t::PUBLIC_IDENTITY || + peerAddrType == peer_address_type_t::RANDOM_STATIC_IDENTITY; + + return connect(peerAddr, legacy_address, connectionParams, scanParamsIn, identity); } @@ -510,6 +514,16 @@ ble_error_t nRF5xGap::connect( LegacyAddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParamsIn +) { + return connect(peerAddr, peerAddrType, connectionParams, scanParamsIn, false); +} + +ble_error_t nRF5xGap::connect( + const Address_t peerAddr, + LegacyAddressType_t peerAddrType, + const ConnectionParams_t *connectionParams, + const GapScanningParams *scanParamsIn, + bool identity ) { ble_gap_addr_t addr; ble_gap_addr_t* addr_ptr = &addr; @@ -585,23 +599,16 @@ ble_error_t nRF5xGap::connect( scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0; - if ((addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) - || (addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE)) { - /* If a device is using Resolvable Private Addresses Section 1.3.2.2 (Core spec v4.2 volume 6 part B), - it shall also have an Identity Address that is either a Public or Random Static address type.” - To establish a connection, a static address must be provided by the application to the SoftDevice. - The SoftDevice resolves the address and connects to the right device if it is available. */ - addr.addr_id_peer = 1; - addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; - } else { - addr.addr_id_peer = 0; - } - if (_privacy_enabled) { bool enable_resolution = _central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE; update_identities_list(enable_resolution); + + if (enable_resolution && identity) { + addr.addr_id_peer = 1; + } + set_private_resolvable_address(); } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.h index 27cabc9981..c8ef171ca4 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.h @@ -88,6 +88,7 @@ public: virtual ble_error_t stopAdvertising(void); virtual ble_error_t connect(const Address_t, ble::peer_address_type_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams); virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams); + ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity); virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); virtual ble_error_t disconnect(DisconnectionReason_t reason); From ef208912a6ae58aa4b71f55f409fc6d5e8e1cf0f Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 23 May 2018 17:18:17 +0100 Subject: [PATCH 2/3] BLE NRF52: Report correct own address type for connection The function that gets the address doesn't work when privacy is enabled; report own address as private resolvable. --- .../targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp index ae6abae00e..e2c76f2c05 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp @@ -1340,6 +1340,9 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t memcpy(own_address, evt.own_addr.addr, sizeof(own_address)); #else getAddress(&own_addr_type, own_address.data()); + if (_privacy_enabled) { + own_addr_type = LegacyAddressType::RANDOM_PRIVATE_RESOLVABLE; + } #endif #if (NRF_SD_BLE_API_VERSION <= 2) From db4d14c89d46fb64795e8c7501f04415d597bc0b Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Wed, 23 May 2018 17:18:56 +0100 Subject: [PATCH 3/3] BLE NRF52: Fix advertising filtering when no bonds are present. --- .../targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp index e2c76f2c05..a5053b23f4 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp @@ -1432,7 +1432,9 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) { bool peer_address_resolved = evt.peer_addr.addr_id_peer; if (_privacy_enabled && - peer_address_resolved == false && + evt.peer_addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE && + peer_address_resolved == false && + get_sm().get_resolving_list().size() > 0 && _central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER ) { return;