Skip to content

Commit 13a10f3

Browse files
committedDec 10, 2018
suppress scan timeout if we disabled scanning
1 parent a545da7 commit 13a10f3

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed
 

‎features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ class GenericGap :
726726
ble::address_t _random_static_identity_address;
727727
bool _random_address_rotating;
728728

729+
bool _scan_enabled;
729730
mbed::Timeout _advertising_timeout;
730731
mbed::Timeout _scan_timeout;
731732
mbed::Ticker _address_rotation_ticker;

‎features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ GenericGap::GenericGap(
435435
_peripheral_privacy_configuration(default_peripheral_privacy_configuration),
436436
_central_privacy_configuration(default_central_privacy_configuration),
437437
_random_address_rotating(false),
438+
_scan_enabled(false),
438439
_advertising_timeout(),
439440
_scan_timeout(),
440441
_connection_event_handler(NULL),
@@ -564,14 +565,26 @@ ble_error_t GenericGap::stopAdvertising()
564565
ble_error_t GenericGap::stopScan()
565566
{
566567
ble_error_t err;
568+
567569
if (is_extended_advertising_available()) {
570+
if (!_scan_enabled) {
571+
return BLE_ERROR_NONE;
572+
}
573+
574+
_scan_enabled = false;
575+
568576
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+
}
569582
} else {
570583
err = _pal_gap.scan_enable(false, false);
571-
}
572584

573-
if (err) {
574-
return err;
585+
if (err) {
586+
return err;
587+
}
575588
}
576589

577590
// Stop address rotation if required
@@ -1465,6 +1478,12 @@ BLE_DEPRECATED_API_USE_END()
14651478

14661479
void GenericGap::on_scan_timeout()
14671480
{
1481+
if (!_scan_enabled) {
1482+
return;
1483+
}
1484+
1485+
_scan_enabled = false;
1486+
14681487
if (!_eventHandler) {
14691488
return;
14701489
}
@@ -2368,6 +2387,9 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
23682387
ble_error_t status;
23692388

23702389
if (is_extended_advertising_available()) {
2390+
2391+
_active_sets.clear(handle);
2392+
23712393
status = _pal_gap.extended_advertising_enable(
23722394
/*enable ? */ false,
23732395
/* number of advertising sets */ 1,
@@ -2377,24 +2399,26 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
23772399
);
23782400

23792401
if (status) {
2402+
_active_sets.set(handle);
23802403
return status;
23812404
}
23822405
} else {
23832406
if (handle != LEGACY_ADVERTISING_HANDLE) {
23842407
return BLE_ERROR_INVALID_PARAM;
23852408
}
23862409

2410+
_active_sets.clear(handle);
2411+
23872412
status = _pal_gap.advertising_enable(false);
23882413

23892414
if (status) {
2415+
_active_sets.set(handle);
23902416
return status;
23912417
}
23922418

23932419
_advertising_timeout.detach();
23942420
}
23952421

2396-
_active_sets.clear(handle);
2397-
23982422
return status;
23992423
}
24002424

@@ -2722,6 +2746,10 @@ void GenericGap::on_advertising_set_terminated(
27222746
uint8_t number_of_completed_extended_advertising_events
27232747
)
27242748
{
2749+
if (!_active_sets.get(advertising_handle)) {
2750+
return;
2751+
}
2752+
27252753
_active_sets.clear(advertising_handle);
27262754

27272755
if (!_eventHandler) {
@@ -2875,12 +2903,19 @@ ble_error_t GenericGap::startScan(
28752903
}
28762904

28772905
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(
28792909
/* enable */true,
28802910
filtering,
28812911
duration.value(),
28822912
period.value()
28832913
);
2914+
2915+
if (err) {
2916+
_scan_enabled = false;
2917+
return err;
2918+
}
28842919
} else {
28852920
if (period.value() != 0) {
28862921
return BLE_ERROR_INVALID_PARAM;
@@ -2902,9 +2937,9 @@ ble_error_t GenericGap::startScan(
29022937
microsecond_t(duration).value()
29032938
);
29042939
}
2905-
2906-
return BLE_ERROR_NONE;
29072940
}
2941+
2942+
return BLE_ERROR_NONE;
29082943
}
29092944

29102945
ble_error_t GenericGap::createSync(

0 commit comments

Comments
 (0)