Skip to content

Commit

Permalink
Merge pull request ARMmbed#10219 from paul-szczepanek-arm/fix-legacy-…
Browse files Browse the repository at this point in the history
…scan-timeout

BLE: fix scan timeout being called from interrupt
  • Loading branch information
Cruz Monrreal committed Mar 27, 2019
2 parents 7e7f4f5 + 82112b6 commit 4cdc3b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
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

0 comments on commit 4cdc3b7

Please sign in to comment.