@@ -435,6 +435,7 @@ GenericGap::GenericGap(
435
435
_peripheral_privacy_configuration(default_peripheral_privacy_configuration),
436
436
_central_privacy_configuration(default_central_privacy_configuration),
437
437
_random_address_rotating(false ),
438
+ _scan_enabled(false ),
438
439
_advertising_timeout(),
439
440
_scan_timeout(),
440
441
_connection_event_handler(NULL ),
@@ -564,14 +565,26 @@ ble_error_t GenericGap::stopAdvertising()
564
565
ble_error_t GenericGap::stopScan ()
565
566
{
566
567
ble_error_t err;
568
+
567
569
if (is_extended_advertising_available ()) {
570
+ if (!_scan_enabled) {
571
+ return BLE_ERROR_NONE;
572
+ }
573
+
574
+ _scan_enabled = false ;
575
+
568
576
err = _pal_gap.extended_scan_enable (false , pal::duplicates_filter_t ::DISABLE, 0 , 0 );
577
+
578
+ if (err) {
579
+ _scan_enabled = true ;
580
+ return err;
581
+ }
569
582
} else {
570
583
err = _pal_gap.scan_enable (false , false );
571
- }
572
584
573
- if (err) {
574
- return err;
585
+ if (err) {
586
+ return err;
587
+ }
575
588
}
576
589
577
590
// Stop address rotation if required
@@ -1465,6 +1478,12 @@ BLE_DEPRECATED_API_USE_END()
1465
1478
1466
1479
void GenericGap::on_scan_timeout ()
1467
1480
{
1481
+ if (!_scan_enabled) {
1482
+ return ;
1483
+ }
1484
+
1485
+ _scan_enabled = false ;
1486
+
1468
1487
if (!_eventHandler) {
1469
1488
return ;
1470
1489
}
@@ -2368,6 +2387,9 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
2368
2387
ble_error_t status;
2369
2388
2370
2389
if (is_extended_advertising_available ()) {
2390
+
2391
+ _active_sets.clear (handle);
2392
+
2371
2393
status = _pal_gap.extended_advertising_enable (
2372
2394
/* enable ? */ false ,
2373
2395
/* number of advertising sets */ 1 ,
@@ -2377,24 +2399,26 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
2377
2399
);
2378
2400
2379
2401
if (status) {
2402
+ _active_sets.set (handle);
2380
2403
return status;
2381
2404
}
2382
2405
} else {
2383
2406
if (handle != LEGACY_ADVERTISING_HANDLE) {
2384
2407
return BLE_ERROR_INVALID_PARAM;
2385
2408
}
2386
2409
2410
+ _active_sets.clear (handle);
2411
+
2387
2412
status = _pal_gap.advertising_enable (false );
2388
2413
2389
2414
if (status) {
2415
+ _active_sets.set (handle);
2390
2416
return status;
2391
2417
}
2392
2418
2393
2419
_advertising_timeout.detach ();
2394
2420
}
2395
2421
2396
- _active_sets.clear (handle);
2397
-
2398
2422
return status;
2399
2423
}
2400
2424
@@ -2722,6 +2746,10 @@ void GenericGap::on_advertising_set_terminated(
2722
2746
uint8_t number_of_completed_extended_advertising_events
2723
2747
)
2724
2748
{
2749
+ if (!_active_sets.get (advertising_handle)) {
2750
+ return ;
2751
+ }
2752
+
2725
2753
_active_sets.clear (advertising_handle);
2726
2754
2727
2755
if (!_eventHandler) {
@@ -2875,12 +2903,19 @@ ble_error_t GenericGap::startScan(
2875
2903
}
2876
2904
2877
2905
if (is_extended_advertising_available ()) {
2878
- return _pal_gap.extended_scan_enable (
2906
+ _scan_enabled = true ;
2907
+
2908
+ ble_error_t err = _pal_gap.extended_scan_enable (
2879
2909
/* enable */ true ,
2880
2910
filtering,
2881
2911
duration.value (),
2882
2912
period.value ()
2883
2913
);
2914
+
2915
+ if (err) {
2916
+ _scan_enabled = false ;
2917
+ return err;
2918
+ }
2884
2919
} else {
2885
2920
if (period.value () != 0 ) {
2886
2921
return BLE_ERROR_INVALID_PARAM;
@@ -2902,9 +2937,9 @@ ble_error_t GenericGap::startScan(
2902
2937
microsecond_t (duration).value ()
2903
2938
);
2904
2939
}
2905
-
2906
- return BLE_ERROR_NONE;
2907
2940
}
2941
+
2942
+ return BLE_ERROR_NONE;
2908
2943
}
2909
2944
2910
2945
ble_error_t GenericGap::createSync (
0 commit comments