You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2020/06/30 20:40:23 UTC
[mynewt-nimble] 02/03: nimble/ll: Fix race in scan stop
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit fcc306f47b37b63c73c6728eaa84add8ae5f6e54
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jun 30 01:26:40 2020 +0200
nimble/ll: Fix race in scan stop
We should better disable PHY before cleaning up scansm. This way we
avoid e.g. scenario when extended scanner was active, but PDU was
received after ext_scanning flag was cleared so such PDU would be
marked incorrectly.
---
nimble/controller/src/ble_ll_scan.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index c17a9c8..930d88a 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -1125,6 +1125,22 @@ ble_ll_scan_sm_stop(int chk_disable)
scansm = &g_ble_ll_scan_sm;
os_cputime_timer_stop(&scansm->scan_timer);
+ /* Only set state if we are currently in a scan window */
+ if (chk_disable) {
+ OS_ENTER_CRITICAL(sr);
+ lls = ble_ll_state_get();
+
+ if ((lls == BLE_LL_STATE_SCANNING) ||
+ (lls == BLE_LL_STATE_INITIATING && chk_disable == 1)) {
+ /* Disable phy */
+ ble_phy_disable();
+
+ /* Set LL state to standby */
+ ble_ll_state_set(BLE_LL_STATE_STANDBY);
+ }
+ OS_EXIT_CRITICAL(sr);
+ }
+
OS_ENTER_CRITICAL(sr);
/* Disable scanning state machine */
@@ -1149,22 +1165,6 @@ ble_ll_scan_sm_stop(int chk_disable)
/* Count # of times stopped */
STATS_INC(ble_ll_stats, scan_stops);
- /* Only set state if we are currently in a scan window */
- if (chk_disable) {
- OS_ENTER_CRITICAL(sr);
- lls = ble_ll_state_get();
-
- if ((lls == BLE_LL_STATE_SCANNING) ||
- (lls == BLE_LL_STATE_INITIATING && chk_disable == 1)) {
- /* Disable phy */
- ble_phy_disable();
-
- /* Set LL state to standby */
- ble_ll_state_set(BLE_LL_STATE_STANDBY);
- }
- OS_EXIT_CRITICAL(sr);
- }
-
/* No need for RF anymore */
OS_ENTER_CRITICAL(sr);
ble_ll_rfmgmt_scan_changed(false, 0);