@@ -171,6 +171,9 @@ nRF5xGap::nRF5xGap() :
171
171
_connections_role()
172
172
{
173
173
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
174
+ #if (NRF_SD_BLE_API_VERSION >= 6)
175
+ m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
176
+ #endif
174
177
}
175
178
/* *************************************************************************/
176
179
/* !
@@ -236,13 +239,37 @@ ble_error_t nRF5xGap::setAdvertisingData_(const GapAdvertisingData &advData, con
236
239
// }
237
240
// }
238
241
242
+ #if (NRF_SD_BLE_API_VERSION >= 6)
243
+ /* sd_ble_gap_adv_data_set has been decprecated */
244
+ if (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET) {
245
+ /* This is for updating advdata*/
246
+ ble_gap_adv_data_t adv_data = {0 };
247
+ adv_data.adv_data .p_data = const_cast <uint8_t *>(advData.getPayload ());
248
+ adv_data.adv_data .len = advData.getPayloadLen ();
249
+ adv_data.scan_rsp_data .p_data = const_cast <uint8_t *>(scanResponse.getPayload ());
250
+ adv_data.scan_rsp_data .len = scanResponse.getPayloadLen ();
251
+
252
+ ASSERT_TRUE (ERROR_NONE ==
253
+ sd_ble_gap_adv_stop (m_advHandle),
254
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
255
+
256
+ ASSERT_TRUE (ERROR_NONE ==
257
+ sd_ble_gap_adv_set_configure (&m_advHandle, &adv_data, NULL ),
258
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
259
+
260
+ ASSERT_TRUE (ERROR_NONE ==
261
+ sd_ble_gap_adv_start (m_advHandle, NRF_CONNECTION_TAG),
262
+ BLE_ERROR_PARAM_OUT_OF_RANGE);
263
+ }
264
+ #else
239
265
/* Send advertising data! */
240
266
ASSERT_TRUE (ERROR_NONE ==
241
267
sd_ble_gap_adv_data_set (advData.getPayload (),
242
268
advData.getPayloadLen (),
243
269
scanResponse.getPayload (),
244
270
scanResponse.getPayloadLen ()),
245
271
BLE_ERROR_PARAM_OUT_OF_RANGE);
272
+ #endif
246
273
247
274
/* Make sure the GAP Service appearance value is aligned with the
248
275
*appearance from GapAdvertisingData */
@@ -373,14 +400,56 @@ ble_error_t nRF5xGap::startAdvertising_(const GapAdvertisingParams ¶ms)
373
400
374
401
/* Start Advertising */
375
402
403
+ #if (NRF_SD_BLE_API_VERSION >= 6)
376
404
405
+ /* FIXME: Must be chanaged if extended paramters added into GapAdvertisingParams */
406
+ switch (params.getAdvertisingType ()) {
407
+ case GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED:
408
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
409
+ break ;
410
+
411
+ case GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED:
412
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED;
413
+ break ;
414
+
415
+ case GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED:
416
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
417
+ break ;
418
+
419
+ case GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED:
420
+ adv_para.properties .type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
421
+ break ;
422
+
423
+ default :
424
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
425
+ break ;
426
+ }
427
+
428
+ adv_para.interval = params.getIntervalInADVUnits (); // advertising interval (in units of 0.625 ms)
429
+ adv_para.duration = params.getTimeout () * 100 ; // units have been changed from seconds to 10ms units.
430
+ memset (adv_para.channel_mask , 0 , sizeof (adv_para.channel_mask ));
431
+ adv_para.filter_policy = advertisingPolicyMode; // BLE_GAP_ADV_FP_ANY
432
+ adv_para.primary_phy = BLE_GAP_PHY_1MBPS; /* Use _preferred_tx_phys if validated */
433
+ adv_para.p_peer_addr = NULL ;
434
+
435
+ m_adv_data.adv_data .p_data = const_cast <uint8_t *>(_advPayload.getPayload ());
436
+ m_adv_data.adv_data .len = _advPayload.getPayloadLen ();
437
+ m_adv_data.scan_rsp_data .p_data = const_cast <uint8_t *>(_scanResponse.getPayload ());
438
+ m_adv_data.scan_rsp_data .len = _scanResponse.getPayloadLen ();
439
+ #else
377
440
adv_para.type = params.getAdvertisingType ();
378
441
adv_para.p_peer_addr = NULL ; // Undirected advertisement
379
442
adv_para.fp = advertisingPolicyMode;
380
443
adv_para.interval = params.getIntervalInADVUnits (); // advertising interval (in units of 0.625 ms)
381
444
adv_para.timeout = params.getTimeout ();
445
+ #endif
382
446
383
- #if (NRF_SD_BLE_API_VERSION >= 5)
447
+
448
+ #if (NRF_SD_BLE_API_VERSION >= 6)
449
+ if ((err = sd_ble_gap_adv_set_configure (&m_advHandle, &m_adv_data, &adv_para) == ERROR_NONE)) {
450
+ err = sd_ble_gap_adv_start (m_advHandle, NRF_CONNECTION_TAG);
451
+ }
452
+ #elif (NRF_SD_BLE_API_VERSION == 5)
384
453
err = sd_ble_gap_adv_start (&adv_para, NRF_CONNECTION_TAG);
385
454
#else
386
455
err = sd_ble_gap_adv_start (&adv_para);
@@ -427,15 +496,29 @@ ble_error_t nRF5xGap::startRadioScan_(const GapScanningParams &scanningParams)
427
496
#else
428
497
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
429
498
499
+ #if (NRF_SD_BLE_API_VERSION >= 6)
500
+ scanParams.filter_policy = scanningPolicyMode;
501
+ #else
430
502
scanParams.use_whitelist = scanningPolicyMode;
431
503
scanParams.adv_dir_report = 0 ;
504
+ #endif
432
505
#endif
433
506
507
+ #if (NRF_SD_BLE_API_VERSION >= 6)
508
+ scanParams.extended = 0 ;
509
+ memset (scanParams.channel_mask , 0 , sizeof (scanParams.channel_mask ));
510
+ scanParams.scan_phys = BLE_GAP_PHY_1MBPS; /* Use _preferred_rx_phys if validated */
511
+
512
+ scanParams.interval = scanningParams.getInterval (); /* *< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
513
+ scanParams.window = scanningParams.getWindow (); /* *< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
514
+ scanParams.timeout = scanningParams.getTimeout ()*100 ; /* *< Scan timeout between 0x0001 and 0xFFFF in 10 ms units, 0x0000 disables timeout. */
515
+ #else
434
516
scanParams.active = scanningParams.getActiveScanning (); /* *< If 1, perform active scanning (scan requests). */
435
517
436
518
scanParams.interval = scanningParams.getInterval (); /* *< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
437
519
scanParams.window = scanningParams.getWindow (); /* *< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
438
520
scanParams.timeout = scanningParams.getTimeout (); /* *< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
521
+ #endif
439
522
440
523
if (_privacy_enabled) {
441
524
bool enable_resolution =
@@ -450,9 +533,20 @@ ble_error_t nRF5xGap::startRadioScan_(const GapScanningParams &scanningParams)
450
533
}
451
534
}
452
535
536
+ #if (NRF_SD_BLE_API_VERSION >= 6)
537
+ m_scan_buffer.p_data = m_raw_scan_buffer;
538
+ m_scan_buffer.len = sizeof (m_raw_scan_buffer);
539
+ m_resume_scanning = true ;
540
+ // if (sd_ble_gap_scan_start(&scanParams, &m_scan_buffer) != NRF_SUCCESS) {
541
+ uint32_t res = sd_ble_gap_scan_start (&scanParams, &m_scan_buffer);
542
+ if (res != NRF_SUCCESS) {
543
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
544
+ }
545
+ #else
453
546
if (sd_ble_gap_scan_start (&scanParams) != NRF_SUCCESS) {
454
547
return BLE_ERROR_PARAM_OUT_OF_RANGE;
455
548
}
549
+ #endif
456
550
457
551
return BLE_ERROR_NONE;
458
552
}
@@ -485,7 +579,11 @@ ble_error_t nRF5xGap::stopScan_(void) {
485
579
ble_error_t nRF5xGap::stopAdvertising_ (void )
486
580
{
487
581
/* Stop Advertising */
582
+ #if (NRF_SD_BLE_API_VERSION >= 6)
583
+ ASSERT_TRUE (ERROR_NONE == sd_ble_gap_adv_stop (m_advHandle), BLE_ERROR_PARAM_OUT_OF_RANGE);
584
+ #else
488
585
ASSERT_TRUE (ERROR_NONE == sd_ble_gap_adv_stop (), BLE_ERROR_PARAM_OUT_OF_RANGE);
586
+ #endif
489
587
490
588
state.advertising = 0 ;
491
589
@@ -631,8 +729,11 @@ ble_error_t nRF5xGap::connect(
631
729
}
632
730
#else
633
731
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
634
-
732
+ #if (NRF_SD_BLE_API_VERSION >= 6)
733
+ scanParams.filter_policy |= (whitelistAddressesSize) ? 1 : 0 ;
734
+ #else
635
735
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0 ;
736
+ #endif
636
737
637
738
if (_privacy_enabled) {
638
739
bool enable_resolution =
@@ -661,6 +762,10 @@ ble_error_t nRF5xGap::connect(
661
762
scanParams.timeout = _scanningParams.getTimeout (); /* *< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
662
763
}
663
764
765
+ #if NRF_SD_BLE_API_VERSION >= 6
766
+ m_resume_scanning = false ;
767
+ #endif
768
+
664
769
#if NRF_SD_BLE_API_VERSION >= 5
665
770
uint32_t rc = sd_ble_gap_connect (addr_ptr, &scanParams, &connParams, NRF_CONNECTION_TAG);
666
771
#else
@@ -706,6 +811,9 @@ ble_error_t nRF5xGap::setPreferredPhys_(
706
811
uint8_t preferred_rx_phys = rxPhys? rxPhys->value () : 0 ;
707
812
708
813
#ifdef S140
814
+ #if (NRF_SD_BLE_API_VERSION) >= 6
815
+ /* Set _preferred_tx_phys and _preferred_rx_phys here, used when start advertising or scanning */
816
+ #else
709
817
ble_opt_t opt = { 0 };
710
818
opt.gap_opt .preferred_phys .tx_phys = preferred_tx_phys;
711
819
opt.gap_opt .preferred_phys .rx_phys = preferred_rx_phys;
@@ -726,7 +834,7 @@ ble_error_t nRF5xGap::setPreferredPhys_(
726
834
default :
727
835
return BLE_ERROR_UNSPECIFIED;
728
836
}
729
-
837
+ # endif
730
838
#endif
731
839
732
840
_preferred_tx_phys = preferred_tx_phys;
@@ -741,7 +849,7 @@ ble_error_t nRF5xGap::setPhy_(
741
849
const ble::phy_set_t * rxPhys,
742
850
CodedSymbolPerBit_t codedSymbol
743
851
) {
744
- #ifdef S140
852
+ #if defined( S140) && ((NRF_SD_BLE_API_VERSION) < 6)
745
853
return BLE_ERROR_NOT_IMPLEMENTED;
746
854
#else
747
855
// TODO handle coded symbol once supported by the softdevice.
@@ -851,6 +959,9 @@ ble_error_t nRF5xGap::reset_(void)
851
959
852
960
/* Clear derived class members */
853
961
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
962
+ #if (NRF_SD_BLE_API_VERSION >= 6)
963
+ m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
964
+ #endif
854
965
855
966
/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
856
967
advertisingPolicyMode = ADV_POLICY_IGNORE_WHITELIST;
@@ -1019,7 +1130,25 @@ ble_error_t nRF5xGap::getAppearance_(GapAdvertisingData::Appearance *appearanceP
1019
1130
ble_error_t nRF5xGap::setTxPower_ (int8_t txPower)
1020
1131
{
1021
1132
unsigned rc;
1133
+ #if (NRF_SD_BLE_API_VERSION >= 6)
1134
+ /* FIXME: This has to change API for specified paramter */
1135
+ uint16_t handle = 0 ;
1136
+ rc = NRF_SUCCESS;
1137
+ if ((handle = getConnectionHandle ()) != BLE_CONN_HANDLE_INVALID) {
1138
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_CONN, handle, txPower);
1139
+ }
1140
+ if ((rc == NRF_SUCCESS) && (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET)) {
1141
+ handle = (uint16_t )m_advHandle;
1142
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_ADV, handle, txPower);
1143
+ }
1144
+ if (rc == NRF_SUCCESS) {
1145
+ rc = sd_ble_gap_tx_power_set (BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0 /* This is ingored for ROLE_SCAN_INIT*/ , txPower);
1146
+ }
1147
+
1148
+ if (rc != NRF_SUCCESS) {
1149
+ #else
1022
1150
if ((rc = sd_ble_gap_tx_power_set (txPower)) != NRF_SUCCESS) {
1151
+ #endif
1023
1152
switch (rc) {
1024
1153
case NRF_ERROR_BUSY:
1025
1154
return BLE_STACK_BUSY;
@@ -1564,6 +1693,34 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
1564
1693
);
1565
1694
const uint8_t * peer_address = evt.peer_addr .addr ;
1566
1695
1696
+ #if (NRF_SD_BLE_API_VERSION >= 6)
1697
+ GapAdvertisingParams::AdvertisingType_t type;
1698
+ if (evt.type .connectable && !evt.type .directed ) {
1699
+ type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
1700
+ } else if (evt.type .connectable && evt.type .directed ) {
1701
+ type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
1702
+ } else if (evt.type .scannable && !evt.type .directed ) {
1703
+ type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
1704
+ } else if (!evt.type .connectable && !evt.type .directed ) {
1705
+ type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
1706
+ } else {
1707
+ // wrong condition
1708
+ }
1709
+ processAdvertisementReport (
1710
+ peer_address,
1711
+ evt.rssi ,
1712
+ (evt.type .scan_response ? 1 : 0 ),
1713
+ type,
1714
+ evt.data .len ,
1715
+ evt.data .p_data ,
1716
+ peer_addr_type
1717
+ );
1718
+
1719
+ /* If no action for connecting, must call sd_ble_gap_scan_start() aging for resuming scanning */
1720
+ if (m_resume_scanning) {
1721
+ sd_ble_gap_scan_start (NULL , &m_scan_buffer);
1722
+ }
1723
+ #else
1567
1724
processAdvertisementReport (
1568
1725
peer_address,
1569
1726
evt.rssi ,
@@ -1573,6 +1730,7 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
1573
1730
evt.data ,
1574
1731
peer_addr_type
1575
1732
);
1733
+ #endif
1576
1734
}
1577
1735
1578
1736
ble_error_t nRF5xGap::get_role (ble::connection_handle_t connection, Role_t& role) {
@@ -1656,7 +1814,6 @@ void nRF5xGap::on_phy_update(
1656
1814
);
1657
1815
}
1658
1816
1659
- #ifndef S140
1660
1817
void nRF5xGap::on_phy_update_request (
1661
1818
Handle_t connection,
1662
1819
const ble_gap_evt_phy_update_request_t & evt
@@ -1676,7 +1833,6 @@ void nRF5xGap::on_phy_update_request(
1676
1833
1677
1834
sd_ble_gap_phy_update (connection, &phys);
1678
1835
}
1679
- #endif
1680
1836
1681
1837
1682
1838
0 commit comments