@@ -144,6 +144,9 @@ nRF5xGap::nRF5xGap() : Gap(),
144
144
_connections_role()
145
145
{
146
146
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
147
+ #if (NRF_SD_BLE_API_VERSION >= 6)
148
+ m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
149
+ #endif
147
150
}
148
151
/* *************************************************************************/
149
152
/* !
@@ -209,13 +212,37 @@ ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, cons
209
212
// }
210
213
// }
211
214
215
+ #if (NRF_SD_BLE_API_VERSION >= 6)
216
+ /* sd_ble_gap_adv_data_set has been decprecated */
217
+ if (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET) {
218
+ /* This is for updating advdata*/
219
+ ble_gap_adv_data_t adv_data = {0 };
220
+ adv_data.adv_data .p_data = const_cast <uint8_t *>(advData.getPayload ());
221
+ adv_data.adv_data .len = advData.getPayloadLen ();
222
+ adv_data.scan_rsp_data .p_data = const_cast <uint8_t *>(scanResponse.getPayload ());
223
+ adv_data.scan_rsp_data .len = scanResponse.getPayloadLen ();
224
+
225
+ ASSERT_TRUE (ERROR_NONE ==
226
+ sd_ble_gap_adv_stop (m_advHandle),
227
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
228
+
229
+ ASSERT_TRUE (ERROR_NONE ==
230
+ sd_ble_gap_adv_set_configure (&m_advHandle, &adv_data, NULL ),
231
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
232
+
233
+ ASSERT_TRUE (ERROR_NONE ==
234
+ sd_ble_gap_adv_start (m_advHandle, NRF_CONNECTION_TAG),
235
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
236
+ }
237
+ #else
212
238
/* Send advertising data! */
213
239
ASSERT_TRUE (ERROR_NONE ==
214
240
sd_ble_gap_adv_data_set (advData.getPayload (),
215
241
advData.getPayloadLen (),
216
242
scanResponse.getPayload (),
217
243
scanResponse.getPayloadLen ()),
218
244
BLE_ERROR_PARAM_OUT_OF_RANGE);
245
+ #endif
219
246
220
247
/* Make sure the GAP Service appearance value is aligned with the
221
248
*appearance from GapAdvertisingData */
@@ -346,14 +373,56 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams ¶ms)
346
373
347
374
/* Start Advertising */
348
375
376
+ #if (NRF_SD_BLE_API_VERSION >= 6)
349
377
378
+ /* FIXME: Must be chanaged if extended paramters added into GapAdvertisingParams */
379
+ switch (params.getAdvertisingType ()) {
380
+ case GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED:
381
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
382
+ break ;
383
+
384
+ case GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED:
385
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED;
386
+ break ;
387
+
388
+ case GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED:
389
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
390
+ break ;
391
+
392
+ case GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED:
393
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
394
+ break ;
395
+
396
+ default :
397
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
398
+ break ;
399
+ }
400
+
401
+ adv_para.interval = params.getIntervalInADVUnits (); // advertising interval (in units of 0.625 ms)
402
+ adv_para.duration = params.getTimeout () * 100 ; // units have been changed from seconds to 10ms units.
403
+ memset (adv_para.channel_mask , 0 , sizeof (adv_para.channel_mask ));
404
+ adv_para.filter_policy = advertisingPolicyMode; // BLE_GAP_ADV_FP_ANY
405
+ adv_para.primary_phy = BLE_GAP_PHY_1MBPS; /* Use _preferred_tx_phys if validated */
406
+ adv_para.p_peer_addr = NULL ;
407
+
408
+ m_adv_data.adv_data .p_data = const_cast <uint8_t *>(_advPayload.getPayload ());
409
+ m_adv_data.adv_data .len = _advPayload.getPayloadLen ();
410
+ m_adv_data.scan_rsp_data .p_data = const_cast <uint8_t *>(_scanResponse.getPayload ());
411
+ m_adv_data.scan_rsp_data .len = _scanResponse.getPayloadLen ();
412
+ #else
350
413
adv_para.type = params.getAdvertisingType ();
351
414
adv_para.p_peer_addr = NULL ; // Undirected advertisement
352
415
adv_para.fp = advertisingPolicyMode;
353
416
adv_para.interval = params.getIntervalInADVUnits (); // advertising interval (in units of 0.625 ms)
354
417
adv_para.timeout = params.getTimeout ();
418
+ #endif
355
419
356
- #if (NRF_SD_BLE_API_VERSION >= 5)
420
+
421
+ #if (NRF_SD_BLE_API_VERSION >= 6)
422
+ if ((err = sd_ble_gap_adv_set_configure (&m_advHandle, &m_adv_data, &adv_para) == ERROR_NONE)) {
423
+ err = sd_ble_gap_adv_start (m_advHandle, NRF_CONNECTION_TAG);
424
+ }
425
+ #elif (NRF_SD_BLE_API_VERSION == 5)
357
426
err = sd_ble_gap_adv_start (&adv_para, NRF_CONNECTION_TAG);
358
427
#else
359
428
err = sd_ble_gap_adv_start (&adv_para);
@@ -400,15 +469,29 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
400
469
#else
401
470
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
402
471
472
+ #if (NRF_SD_BLE_API_VERSION >= 6)
473
+ scanParams.filter_policy = scanningPolicyMode;
474
+ #else
403
475
scanParams.use_whitelist = scanningPolicyMode;
404
476
scanParams.adv_dir_report = 0 ;
477
+ #endif
405
478
#endif
406
479
480
+ #if (NRF_SD_BLE_API_VERSION >= 6)
481
+ scanParams.extended = 0 ;
482
+ memset (scanParams.channel_mask , 0 , sizeof (scanParams.channel_mask ));
483
+ scanParams.scan_phys = BLE_GAP_PHY_1MBPS; /* Use _preferred_rx_phys if validated */
484
+
485
+ scanParams.interval = scanningParams.getInterval (); /* *< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
486
+ scanParams.window = scanningParams.getWindow (); /* *< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
487
+ scanParams.timeout = scanningParams.getTimeout ()*100 ; /* *< Scan timeout between 0x0001 and 0xFFFF in 10 ms units, 0x0000 disables timeout. */
488
+ #else
407
489
scanParams.active = scanningParams.getActiveScanning (); /* *< If 1, perform active scanning (scan requests). */
408
490
409
491
scanParams.interval = scanningParams.getInterval (); /* *< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
410
492
scanParams.window = scanningParams.getWindow (); /* *< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
411
493
scanParams.timeout = scanningParams.getTimeout (); /* *< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
494
+ #endif
412
495
413
496
if (_privacy_enabled) {
414
497
bool enable_resolution =
@@ -423,9 +506,20 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
423
506
}
424
507
}
425
508
509
+ #if (NRF_SD_BLE_API_VERSION >= 6)
510
+ m_scan_buffer.p_data = m_raw_scan_buffer;
511
+ m_scan_buffer.len = sizeof (m_raw_scan_buffer);
512
+ m_resume_scanning = true ;
513
+ // if (sd_ble_gap_scan_start(&scanParams, &m_scan_buffer) != NRF_SUCCESS) {
514
+ uint32_t res = sd_ble_gap_scan_start (&scanParams, &m_scan_buffer);
515
+ if (res != NRF_SUCCESS) {
516
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
517
+ }
518
+ #else
426
519
if (sd_ble_gap_scan_start (&scanParams) != NRF_SUCCESS) {
427
520
return BLE_ERROR_PARAM_OUT_OF_RANGE;
428
521
}
522
+ #endif
429
523
430
524
return BLE_ERROR_NONE;
431
525
}
@@ -458,7 +552,11 @@ ble_error_t nRF5xGap::stopScan(void) {
458
552
ble_error_t nRF5xGap::stopAdvertising (void )
459
553
{
460
554
/* Stop Advertising */
555
+ #if (NRF_SD_BLE_API_VERSION >= 6)
556
+ ASSERT_TRUE (ERROR_NONE == sd_ble_gap_adv_stop (m_advHandle), BLE_ERROR_PARAM_OUT_OF_RANGE);
557
+ #else
461
558
ASSERT_TRUE (ERROR_NONE == sd_ble_gap_adv_stop (), BLE_ERROR_PARAM_OUT_OF_RANGE);
559
+ #endif
462
560
463
561
state.advertising = 0 ;
464
562
@@ -604,8 +702,11 @@ ble_error_t nRF5xGap::connect(
604
702
}
605
703
#else
606
704
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
607
-
705
+ #if (NRF_SD_BLE_API_VERSION >= 6)
706
+ scanParams.filter_policy |= (whitelistAddressesSize) ? 1 : 0 ;
707
+ #else
608
708
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0 ;
709
+ #endif
609
710
610
711
if (_privacy_enabled) {
611
712
bool enable_resolution =
@@ -634,6 +735,10 @@ ble_error_t nRF5xGap::connect(
634
735
scanParams.timeout = _scanningParams.getTimeout (); /* *< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
635
736
}
636
737
738
+ #if NRF_SD_BLE_API_VERSION >= 6
739
+ m_resume_scanning = false ;
740
+ #endif
741
+
637
742
#if NRF_SD_BLE_API_VERSION >= 5
638
743
uint32_t rc = sd_ble_gap_connect (addr_ptr, &scanParams, &connParams, NRF_CONNECTION_TAG);
639
744
#else
@@ -679,6 +784,9 @@ ble_error_t nRF5xGap::setPreferredPhys(
679
784
uint8_t preferred_rx_phys = rxPhys? rxPhys->value () : 0 ;
680
785
681
786
#ifdef S140
787
+ #if (NRF_SD_BLE_API_VERSION) >= 6
788
+ /* Set _preferred_tx_phys and _preferred_rx_phys here, used when start advertising or scanning */
789
+ #else
682
790
ble_opt_t opt = { 0 };
683
791
opt.gap_opt .preferred_phys .tx_phys = preferred_tx_phys;
684
792
opt.gap_opt .preferred_phys .rx_phys = preferred_rx_phys;
@@ -699,7 +807,7 @@ ble_error_t nRF5xGap::setPreferredPhys(
699
807
default :
700
808
return BLE_ERROR_UNSPECIFIED;
701
809
}
702
-
810
+ # endif
703
811
#endif
704
812
705
813
_preferred_tx_phys = preferred_tx_phys;
@@ -714,7 +822,7 @@ ble_error_t nRF5xGap::setPhy(
714
822
const ble::phy_set_t * rxPhys,
715
823
CodedSymbolPerBit_t codedSymbol
716
824
) {
717
- #ifdef S140
825
+ #if defined( S140) && ((NRF_SD_BLE_API_VERSION) < 6)
718
826
return BLE_ERROR_NOT_IMPLEMENTED;
719
827
#else
720
828
// TODO handle coded symbol once supported by the softdevice.
@@ -824,6 +932,9 @@ ble_error_t nRF5xGap::reset(void)
824
932
825
933
/* Clear derived class members */
826
934
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
935
+ #if (NRF_SD_BLE_API_VERSION >= 6)
936
+ m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
937
+ #endif
827
938
828
939
/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
829
940
advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
@@ -992,7 +1103,25 @@ ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
992
1103
ble_error_t nRF5xGap::setTxPower (int8_t txPower)
993
1104
{
994
1105
unsigned rc;
1106
+ #if (NRF_SD_BLE_API_VERSION >= 6)
1107
+ /* FIXME: This has to change API for specified paramter */
1108
+ uint16_t handle = 0 ;
1109
+ rc = NRF_SUCCESS;
1110
+ if ((handle = getConnectionHandle ()) != BLE_CONN_HANDLE_INVALID) {
1111
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_CONN, handle, txPower);
1112
+ }
1113
+ if ((rc == NRF_SUCCESS) && (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET)) {
1114
+ handle = (uint16_t )m_advHandle;
1115
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_ADV, handle, txPower);
1116
+ }
1117
+ if (rc == NRF_SUCCESS) {
1118
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0 /* This is ingored for ROLE_SCAN_INIT*/ , txPower);
1119
+ }
1120
+
1121
+ if (rc != NRF_SUCCESS) {
1122
+ #else
995
1123
if ((rc = sd_ble_gap_tx_power_set (txPower)) != NRF_SUCCESS) {
1124
+ #endif
996
1125
switch (rc) {
997
1126
case NRF_ERROR_BUSY:
998
1127
return BLE_STACK_BUSY;
@@ -1543,6 +1672,34 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
1543
1672
);
1544
1673
const uint8_t * peer_address = evt.peer_addr .addr ;
1545
1674
1675
+ #if (NRF_SD_BLE_API_VERSION >= 6)
1676
+ GapAdvertisingParams::AdvertisingType_t type;
1677
+ if (evt.type .connectable && !evt.type .directed ) {
1678
+ type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
1679
+ } else if (evt.type .connectable && evt.type .directed ) {
1680
+ type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
1681
+ } else if (evt.type .scannable && !evt.type .directed ) {
1682
+ type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
1683
+ } else if (!evt.type .connectable && !evt.type .directed ) {
1684
+ type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
1685
+ } else {
1686
+ // wrong condition
1687
+ }
1688
+ processAdvertisementReport (
1689
+ peer_address,
1690
+ evt.rssi ,
1691
+ (evt.type .scan_response ? 1 : 0 ),
1692
+ type,
1693
+ evt.data .len ,
1694
+ evt.data .p_data ,
1695
+ peer_addr_type
1696
+ );
1697
+
1698
+ /* If no action for connecting, must call sd_ble_gap_scan_start() aging for resuming scanning */
1699
+ if (m_resume_scanning) {
1700
+ sd_ble_gap_scan_start (NULL , &m_scan_buffer);
1701
+ }
1702
+ #else
1546
1703
processAdvertisementReport (
1547
1704
peer_address,
1548
1705
evt.rssi ,
@@ -1552,6 +1709,7 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
1552
1709
evt.data ,
1553
1710
peer_addr_type
1554
1711
);
1712
+ #endif
1555
1713
}
1556
1714
1557
1715
ble_error_t nRF5xGap::get_role (ble::connection_handle_t connection, Role_t& role) {
@@ -1635,7 +1793,6 @@ void nRF5xGap::on_phy_update(
1635
1793
);
1636
1794
}
1637
1795
1638
- #ifndef S140
1639
1796
void nRF5xGap::on_phy_update_request (
1640
1797
Handle_t connection,
1641
1798
const ble_gap_evt_phy_update_request_t & evt
@@ -1655,7 +1812,6 @@ void nRF5xGap::on_phy_update_request(
1655
1812
1656
1813
sd_ble_gap_phy_update (connection, &phys);
1657
1814
}
1658
- #endif
1659
1815
1660
1816
1661
1817
0 commit comments