Skip to content

Commit 755cf5f

Browse files
committed
BLE NRF51: Defer connection to a common function.
The soft device is not consistent as it is required to force the connection to a resolved resolvable address so it should be known if the target is an identity address.
1 parent d427fcf commit 755cf5f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,30 @@ ble_error_t nRF5xGap::connect(
458458
return BLE_ERROR_INVALID_PARAM;
459459
}
460460

461-
return connect(peerAddr, legacy_address, connectionParams, scanParamsIn);
461+
bool identity =
462+
peerAddrType == peer_address_type_t::PUBLIC_IDENTITY ||
463+
peerAddrType == peer_address_type_t::RANDOM_STATIC_IDENTITY;
464+
465+
return connect(peerAddr, legacy_address, connectionParams, scanParamsIn, identity);
462466
}
463467

464468
ble_error_t nRF5xGap::connect(
465469
const Address_t peerAddr,
466470
LegacyAddressType_t peerAddrType,
467471
const ConnectionParams_t *connectionParams,
468472
const GapScanningParams *scanParamsIn
473+
) {
474+
return connect(peerAddr, peerAddrType, connectionParams, scanParamsIn, /* identity */ false);
475+
}
476+
477+
478+
479+
ble_error_t nRF5xGap::connect(
480+
const Address_t peerAddr,
481+
LegacyAddressType_t peerAddrType,
482+
const ConnectionParams_t *connectionParams,
483+
const GapScanningParams *scanParamsIn,
484+
bool identity
469485
) {
470486
ble_gap_addr_t addr;
471487
ble_gap_addr_t* addr_ptr = &addr;
@@ -485,7 +501,7 @@ ble_error_t nRF5xGap::connect(
485501
connParams.conn_sup_timeout = 600;
486502
}
487503

488-
ble_gap_scan_params_t scanParams ={0};
504+
ble_gap_scan_params_t scanParams = { 0 };
489505

490506
#if (NRF_SD_BLE_API_VERSION <= 2)
491507
/* Allocate the stack's whitelist statically */
@@ -513,6 +529,11 @@ ble_error_t nRF5xGap::connect(
513529
whitelistIrkPtrs[i] = (ble_gap_irk_t*) entries[i].peer_irk.data();
514530
}
515531
whitelist.irk_count = limit;
532+
533+
if (identity) {
534+
scanParams.selective = true;
535+
addr_ptr = NULL;
536+
}
516537
}
517538

518539
set_private_resolvable_address();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor {
8080
virtual ble_error_t stopAdvertising(void);
8181
virtual ble_error_t connect(const Address_t, ble::peer_address_type_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
8282
virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams);
83+
ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams, bool identity);
8384
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
8485
virtual ble_error_t disconnect(DisconnectionReason_t reason);
8586

0 commit comments

Comments
 (0)