Skip to content

Commit 7f888f8

Browse files
scan timeout for 4.2 controllers using new API
1 parent d1b367f commit 7f888f8

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -570,25 +570,21 @@ ble_error_t GenericGap::stopScan()
570570
{
571571
ble_error_t err;
572572

573-
if (is_extended_advertising_available()) {
574-
if (!_scan_enabled) {
575-
return BLE_ERROR_NONE;
576-
}
573+
if (!_scan_enabled) {
574+
return BLE_ERROR_NONE;
575+
}
577576

578-
_scan_enabled = false;
577+
_scan_enabled = false;
579578

579+
if (is_extended_advertising_available()) {
580580
err = _pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0);
581-
582-
if (err) {
583-
_scan_enabled = true;
584-
return err;
585-
}
586581
} else {
587582
err = _pal_gap.scan_enable(false, false);
583+
}
588584

589-
if (err) {
590-
return err;
591-
}
585+
if (err) {
586+
_scan_enabled = true;
587+
return err;
592588
}
593589

594590
// Stop address rotation if required
@@ -1210,6 +1206,8 @@ ble_error_t GenericGap::startRadioScan(const GapScanningParams &scanningParams)
12101206
return err;
12111207
}
12121208

1209+
_scan_enabled = true;
1210+
12131211
_scan_timeout.detach();
12141212
uint16_t timeout = scanningParams.getTimeout();
12151213
if (timeout) {
@@ -1484,6 +1482,12 @@ BLE_DEPRECATED_API_USE_END()
14841482

14851483
void GenericGap::on_scan_timeout()
14861484
{
1485+
/* if timeout happened on a 4.2 chip we need to stop the scan manually */
1486+
if (is_extended_advertising_available()) {
1487+
_pal_gap.scan_enable(false, false);
1488+
set_random_address_rotation(false);
1489+
}
1490+
14871491
if (!_scan_enabled) {
14881492
return;
14891493
}
@@ -2969,8 +2973,6 @@ ble_error_t GenericGap::startScan(
29692973
}
29702974

29712975
if (is_extended_advertising_available()) {
2972-
_scan_enabled = true;
2973-
29742976
ble_error_t err = _pal_gap.extended_scan_enable(
29752977
/* enable */true,
29762978
filtering,
@@ -2979,9 +2981,10 @@ ble_error_t GenericGap::startScan(
29792981
);
29802982

29812983
if (err) {
2982-
_scan_enabled = false;
29832984
return err;
29842985
}
2986+
2987+
_scan_enabled = true;
29852988
} else {
29862989
if (period.value() != 0) {
29872990
return BLE_ERROR_INVALID_PARAM;
@@ -2996,6 +2999,8 @@ ble_error_t GenericGap::startScan(
29962999
return err;
29973000
}
29983001

3002+
_scan_enabled = true;
3003+
29993004
_scan_timeout.detach();
30003005
if (duration.value()) {
30013006
_scan_timeout.attach_us(

0 commit comments

Comments
 (0)