Skip to content

Commit f08ac2e

Browse files
author
Donatien Garnier
authored
Merge pull request #52 from pan-/fix-privacy-nrf52
Fix privacy nrf52
2 parents fa9ab03 + db4d14c commit f08ac2e

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,11 @@ ble_error_t nRF5xGap::connect(
501501
return BLE_ERROR_INVALID_PARAM;
502502
}
503503

504-
return connect(peerAddr, legacy_address, connectionParams, scanParamsIn);
504+
bool identity =
505+
peerAddrType == peer_address_type_t::PUBLIC_IDENTITY ||
506+
peerAddrType == peer_address_type_t::RANDOM_STATIC_IDENTITY;
507+
508+
return connect(peerAddr, legacy_address, connectionParams, scanParamsIn, identity);
505509
}
506510

507511

@@ -510,6 +514,16 @@ ble_error_t nRF5xGap::connect(
510514
LegacyAddressType_t peerAddrType,
511515
const ConnectionParams_t *connectionParams,
512516
const GapScanningParams *scanParamsIn
517+
) {
518+
return connect(peerAddr, peerAddrType, connectionParams, scanParamsIn, false);
519+
}
520+
521+
ble_error_t nRF5xGap::connect(
522+
const Address_t peerAddr,
523+
LegacyAddressType_t peerAddrType,
524+
const ConnectionParams_t *connectionParams,
525+
const GapScanningParams *scanParamsIn,
526+
bool identity
513527
) {
514528
ble_gap_addr_t addr;
515529
ble_gap_addr_t* addr_ptr = &addr;
@@ -585,23 +599,16 @@ ble_error_t nRF5xGap::connect(
585599

586600
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0;
587601

588-
if ((addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)
589-
|| (addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE)) {
590-
/* If a device is using Resolvable Private Addresses Section 1.3.2.2 (Core spec v4.2 volume 6 part B),
591-
it shall also have an Identity Address that is either a Public or Random Static address type.”
592-
To establish a connection, a static address must be provided by the application to the SoftDevice.
593-
The SoftDevice resolves the address and connects to the right device if it is available. */
594-
addr.addr_id_peer = 1;
595-
addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
596-
} else {
597-
addr.addr_id_peer = 0;
598-
}
599-
600602
if (_privacy_enabled) {
601603
bool enable_resolution =
602604
_central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE;
603605

604606
update_identities_list(enable_resolution);
607+
608+
if (enable_resolution && identity) {
609+
addr.addr_id_peer = 1;
610+
}
611+
605612
set_private_resolvable_address();
606613
}
607614

@@ -1333,6 +1340,9 @@ void nRF5xGap::on_connection(Gap::Handle_t handle, const ble_gap_evt_connected_t
13331340
memcpy(own_address, evt.own_addr.addr, sizeof(own_address));
13341341
#else
13351342
getAddress(&own_addr_type, own_address.data());
1343+
if (_privacy_enabled) {
1344+
own_addr_type = LegacyAddressType::RANDOM_PRIVATE_RESOLVABLE;
1345+
}
13361346
#endif
13371347

13381348
#if (NRF_SD_BLE_API_VERSION <= 2)
@@ -1422,7 +1432,9 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
14221432
bool peer_address_resolved = evt.peer_addr.addr_id_peer;
14231433

14241434
if (_privacy_enabled &&
1425-
peer_address_resolved == false &&
1435+
evt.peer_addr.addr_type == BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE &&
1436+
peer_address_resolved == false &&
1437+
get_sm().get_resolving_list().size() > 0 &&
14261438
_central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER
14271439
) {
14281440
return;

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF52/source/nRF5xGap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor {
8888
virtual ble_error_t stopAdvertising(void);
8989
virtual ble_error_t connect(const Address_t, ble::peer_address_type_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
9090
virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
91+
ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity);
9192
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
9293
virtual ble_error_t disconnect(DisconnectionReason_t reason);
9394

0 commit comments

Comments
 (0)