Skip to content

Commit 4cdc3b7

Browse files
author
Cruz Monrreal
authored
Merge pull request #10219 from paul-szczepanek-arm/fix-legacy-scan-timeout
BLE: fix scan timeout being called from interrupt
2 parents 7e7f4f5 + 82112b6 commit 4cdc3b7

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ class GenericGap :
782782
);
783783

784784
void on_scan_timeout_();
785-
785+
void process_legacy_scan_timeout();
786786

787787
private:
788788
pal::EventQueue &_event_queue;

features/FEATURE_BLE/source/generic/GenericGap.tpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,21 +1605,36 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
16051605
return;
16061606
}
16071607

1608-
/* if timeout happened on a 4.2 chip we need to stop the scan manually */
1608+
_scan_enabled = false;
1609+
16091610
if (!is_extended_advertising_available()) {
1610-
_pal_gap.scan_enable(false, false);
1611-
#if BLE_FEATURE_PRIVACY
1612-
set_random_address_rotation(false);
1613-
#endif
1611+
/* if timeout happened on a 4.2 chip this means legacy scanning and a timer timeout
1612+
* but we need to handle the event from user context - use the event queue to handle it */
1613+
_event_queue.post(
1614+
mbed::callback(
1615+
this,
1616+
&GenericGap::process_legacy_scan_timeout
1617+
)
1618+
);
1619+
} else {
1620+
if (_eventHandler) {
1621+
_eventHandler->onScanTimeout(ScanTimeoutEvent());
1622+
}
16141623
}
1624+
}
16151625

1616-
_scan_enabled = false;
1626+
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
1627+
void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::process_legacy_scan_timeout()
1628+
{
1629+
/* legacy scanning timed out is based on timer so we need to stop the scan manually */
1630+
_pal_gap.scan_enable(false, false);
1631+
#if BLE_FEATURE_PRIVACY
1632+
set_random_address_rotation(false);
1633+
#endif
16171634

1618-
if (!_eventHandler) {
1619-
return;
1635+
if (_eventHandler) {
1636+
_eventHandler->onScanTimeout(ScanTimeoutEvent());
16201637
}
1621-
1622-
_eventHandler->onScanTimeout(ScanTimeoutEvent());
16231638
}
16241639

16251640
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>

0 commit comments

Comments
 (0)