@@ -177,7 +177,7 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
177
177
178
178
ble_gap_adv_params_t adv_para = {0 };
179
179
180
- #if (NRF_SD_BLE_API_VERSION <= 2)
180
+ #if (NRF_SD_BLE_API_VERSION <= 2)
181
181
/* Allocate the stack's whitelist statically */
182
182
ble_gap_whitelist_t whitelist;
183
183
ble_gap_addr_t *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
@@ -197,13 +197,9 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
197
197
}
198
198
199
199
adv_para.p_whitelist = &whitelist;
200
- #else
201
- err = updateWhiteAndIdentityListInStack (nRF5xGap::purpose_avdvertising);
202
-
203
- if (err != BLE_ERROR_NONE) {
204
- return (ble_error_t )err;
205
- }
206
200
#endif
201
+ /* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
202
+
207
203
/* Start Advertising */
208
204
209
205
@@ -254,11 +250,7 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
254
250
scanParams.selective = scanningPolicyMode; /* *< If 1, ignore unknown devices (non whitelisted). */
255
251
scanParams.p_whitelist = &whitelist; /* *< Pointer to whitelist, NULL if none is given. */
256
252
#else
257
- uint32_t err = updateWhiteAndIdentityListInStack (nRF5xGap::purpose_scan_connect);
258
-
259
- if (err != BLE_ERROR_NONE) {
260
- return (ble_error_t )err;
261
- }
253
+ /* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
262
254
263
255
scanParams.use_whitelist = scanningPolicyMode;
264
256
scanParams.adv_dir_report = 0 ;
@@ -318,6 +310,7 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
318
310
const GapScanningParams *scanParamsIn)
319
311
{
320
312
ble_gap_addr_t addr;
313
+
321
314
addr.addr_type = peerAddrType;
322
315
memcpy (addr.addr , peerAddr, Gap::ADDR_LEN);
323
316
@@ -358,11 +351,7 @@ ble_error_t nRF5xGap::connect(const Address_t peerAddr,
358
351
scanParams.selective = scanningPolicyMode; /* *< If 1, ignore unknown devices (non whitelisted). */
359
352
scanParams.p_whitelist = &whitelist; /* *< Pointer to whitelist, NULL if none is given. */
360
353
#else
361
- uint32_t err = updateWhiteAndIdentityListInStack (nRF5xGap::purpose_scan_connect);
362
-
363
- if (err != BLE_ERROR_NONE) {
364
- return (ble_error_t )err;
365
- }
354
+ /* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
366
355
367
356
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0 ;
368
357
@@ -504,6 +493,7 @@ ble_error_t nRF5xGap::reset(void)
504
493
505
494
/* Clear the internal whitelist */
506
495
whitelistAddressesSize = 0 ;
496
+
507
497
508
498
return BLE_ERROR_NONE;
509
499
}
@@ -566,6 +556,7 @@ ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
566
556
cycle_mode = BLE_GAP_ADDR_CYCLE_MODE_NONE;
567
557
#else
568
558
privacy_params.privacy_mode = BLE_GAP_PRIVACY_MODE_OFF;
559
+ dev_addr.addr_type = type;
569
560
570
561
ASSERT_INT (ERROR_NONE, pm_id_addr_set (&dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
571
562
ASSERT_INT (ERROR_NONE, pm_privacy_set (&privacy_params), BLE_ERROR_PARAM_OUT_OF_RANGE);
@@ -588,8 +579,8 @@ ble_error_t nRF5xGap::setAddress(AddressType_t type, const Address_t address)
588
579
return BLE_ERROR_PARAM_OUT_OF_RANGE;
589
580
}
590
581
591
- dev_addr.addr_type = type;
592
582
#if (NRF_SD_BLE_API_VERSION <= 2)
583
+ dev_addr.addr_type = type;
593
584
ASSERT_INT (ERROR_NONE, sd_ble_gap_address_set (cycle_mode, &dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
594
585
#endif
595
586
@@ -731,10 +722,10 @@ uint8_t nRF5xGap::getMaxWhitelistSize(void) const
731
722
/* *************************************************************************/
732
723
ble_error_t nRF5xGap::getWhitelist (Gap::Whitelist_t &whitelistOut) const
733
724
{
734
- uint8_t i;
725
+ uint32_t i;
735
726
for (i = 0 ; i < whitelistAddressesSize && i < whitelistOut.capacity ; ++i) {
736
- memcpy ( &whitelistOut.addresses [i].address , &whitelistAddresses[whitelistAddressesSize ].addr , sizeof (whitelistOut.addresses [i ].address ));
737
- whitelistOut.addresses [i].type = static_cast <BLEProtocol::AddressType_t> (whitelistAddresses[whitelistAddressesSize ].addr_type );
727
+ memcpy ( &whitelistOut.addresses [i].address , &whitelistAddresses[i ].addr , sizeof (whitelistOut.addresses [0 ].address ));
728
+ whitelistOut.addresses [i].type = static_cast <BLEProtocol::AddressType_t> (whitelistAddresses[i ].addr_type );
738
729
739
730
740
731
}
@@ -780,20 +771,24 @@ ble_error_t nRF5xGap::setWhitelist(const Gap::Whitelist_t &whitelistIn)
780
771
}
781
772
782
773
/* Test for invalid parameters before we change the internal state */
783
- for (uint8_t i = 0 ; i < whitelistIn.size ; ++i) {
774
+ for (uint32_t i = 0 ; i < whitelistIn.size ; ++i) {
784
775
if (whitelistIn.addresses [i].type == BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE) {
785
776
/* This is not allowed because it is completely meaningless */
786
777
return BLE_ERROR_INVALID_PARAM;
787
778
}
788
779
}
789
780
790
- whitelistAddressesSize = 0 ;
791
- for ( uint8_t i = 0 ; i < whitelistIn. size ; ++i) {
792
- memcpy (&whitelistAddresses[whitelistAddressesSize]. addr , &whitelistIn. addresses [i]. address , sizeof (whitelistAddresses[whitelistAddressesSize]. addr ));
793
- whitelistAddresses[whitelistAddressesSize]. addr_type = static_cast < uint8_t > ( whitelistIn.addresses [i].type );
794
- whitelistAddressesSize++ ;
781
+ whitelistAddressesSize = whitelistIn. size ;
782
+
783
+ for ( uint32_t i = 0 ; i < whitelistIn. size ; ++i) {
784
+ memcpy (& whitelistAddresses[i]. addr , & whitelistIn.addresses [i].address , sizeof (whitelistAddresses[ 0 ]. addr ) );
785
+ whitelistAddresses[i]. addr_type = static_cast < uint8_t > (whitelistIn. addresses [i]. type ) ;
795
786
}
796
787
788
+ #if (NRF_SD_BLE_API_VERSION >= 3)
789
+ updateWhiteAndIdentityListInStack ();
790
+ #endif
791
+
797
792
return BLE_ERROR_NONE;
798
793
}
799
794
@@ -1183,32 +1178,17 @@ ble_error_t nRF5xGap::applyWhiteIdentityList(GapWhiteAndIdentityList_t &gapAdrHe
1183
1178
}
1184
1179
}
1185
1180
1186
- ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack (whiteAndIdentityListPurpose_t purpose )
1181
+ ble_error_t nRF5xGap::updateWhiteAndIdentityListInStack ()
1187
1182
{
1188
1183
GapWhiteAndIdentityList_t whiteAndIdentityList;
1189
- uint32_t err;
1190
- bool provide_settings;
1191
-
1192
- if (purpose == nRF5xGap::purpose_avdvertising) {
1193
- provide_settings = (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) ? true : false ;
1194
- } else { // It must be nRF5xGap::purpose_scan_connect.
1195
- provide_settings = (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) ? true : false ;
1196
- }
1197
-
1184
+ uint32_t err;
1198
1185
1199
- /* Add missing IRKs to nRF5xGap's whitelist from the bond table held by the Peer Manager */
1200
- if (provide_settings) {
1201
- err = getStackWhiteIdentityList (whiteAndIdentityList);
1186
+ err = getStackWhiteIdentityList (whiteAndIdentityList);
1202
1187
1203
- if (err != BLE_ERROR_NONE) {
1204
- return (ble_error_t )err;
1205
- }
1206
- } else {
1207
- whiteAndIdentityList.addrs_cnt = 0 ;
1208
- whiteAndIdentityList.identities_cnt = 0 ;
1188
+ if (err != BLE_ERROR_NONE) {
1189
+ return (ble_error_t )err;
1209
1190
}
1210
-
1211
-
1191
+
1212
1192
return applyWhiteIdentityList (whiteAndIdentityList);
1213
1193
}
1214
1194
#endif
0 commit comments