Skip to content

Commit a0b5b60

Browse files
paul-szczepanek-armadbridge
authored andcommitted
scan timeout for 4.2 controllers using new API
1 parent 3180422 commit a0b5b60

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) {
@@ -1482,6 +1480,12 @@ BLE_DEPRECATED_API_USE_END()
14821480

14831481
void GenericGap::on_scan_timeout()
14841482
{
1483+
/* if timeout happened on a 4.2 chip we need to stop the scan manually */
1484+
if (is_extended_advertising_available()) {
1485+
_pal_gap.scan_enable(false, false);
1486+
set_random_address_rotation(false);
1487+
}
1488+
14851489
if (!_scan_enabled) {
14861490
return;
14871491
}
@@ -2906,8 +2910,6 @@ ble_error_t GenericGap::startScan(
29062910
}
29072911

29082912
if (is_extended_advertising_available()) {
2909-
_scan_enabled = true;
2910-
29112913
ble_error_t err = _pal_gap.extended_scan_enable(
29122914
/* enable */true,
29132915
filtering,
@@ -2916,9 +2918,10 @@ ble_error_t GenericGap::startScan(
29162918
);
29172919

29182920
if (err) {
2919-
_scan_enabled = false;
29202921
return err;
29212922
}
2923+
2924+
_scan_enabled = true;
29222925
} else {
29232926
if (period.value() != 0) {
29242927
return BLE_ERROR_INVALID_PARAM;
@@ -2933,6 +2936,8 @@ ble_error_t GenericGap::startScan(
29332936
return err;
29342937
}
29352938

2939+
_scan_enabled = true;
2940+
29362941
_scan_timeout.detach();
29372942
if (duration.value()) {
29382943
_scan_timeout.attach_us(

0 commit comments

Comments
 (0)