Skip to content

BLE: fix scan timeout being called from interrupt #10219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/ble/generic/GenericGap.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class GenericGap :
);

void on_scan_timeout_();

void process_legacy_scan_timeout();

private:
pal::EventQueue &_event_queue;
Expand Down
35 changes: 25 additions & 10 deletions features/FEATURE_BLE/source/generic/GenericGap.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,21 +1605,36 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
return;
}

/* if timeout happened on a 4.2 chip we need to stop the scan manually */
_scan_enabled = false;

if (!is_extended_advertising_available()) {
_pal_gap.scan_enable(false, false);
#if BLE_FEATURE_PRIVACY
set_random_address_rotation(false);
#endif
/* if timeout happened on a 4.2 chip this means legacy scanning and a timer timeout
* but we need to handle the event from user context - use the event queue to handle it */
_event_queue.post(
mbed::callback(
this,
&GenericGap::process_legacy_scan_timeout
)
);
} else {
if (_eventHandler) {
_eventHandler->onScanTimeout(ScanTimeoutEvent());
}
}
}

_scan_enabled = false;
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::process_legacy_scan_timeout()
{
/* legacy scanning timed out is based on timer so we need to stop the scan manually */
_pal_gap.scan_enable(false, false);
#if BLE_FEATURE_PRIVACY
set_random_address_rotation(false);
#endif

if (!_eventHandler) {
return;
if (_eventHandler) {
_eventHandler->onScanTimeout(ScanTimeoutEvent());
}

_eventHandler->onScanTimeout(ScanTimeoutEvent());
}

template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
Expand Down