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 9257bfecf20f413ad3c3da540b22d319105cd846 Author: Andrzej Kaczmarek <[email protected]> AuthorDate: Thu Sep 29 00:53:02 2022 +0200 nimble/ll: Fix backoff handling for aux scan We should update backoff after receiving scan response PDU instead of waiting for complete chain to be received. This also fixes problem where we try to update backoff in an invalid state, i.e. backoff_count is non-zero. It happens if we start to scan response chain with backoff_count=0 and before complete chain is scanned we scan another pdu which fails. This updates backoff_count to non-zero value so when we finish scanning chain and try to update backoff, the backoff_count value is non-zero which is considered an invalid state. [Core 5.3, Vol 6, Part B, 4.4.3.2] --- nimble/controller/src/ble_ll_scan.c | 6 ++---- nimble/controller/src/ble_ll_scan_aux.c | 31 +++++++++++++------------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 010fe150..75441bb5 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -1535,10 +1535,8 @@ ble_ll_scan_send_scan_req(uint8_t pdu_type, uint8_t *rxbuf, BLE_LL_ASSERT(scansm->scan_rsp_pending == 0); /* We want to send a request. See if backoff allows us */ - if (scansm->backoff_count > 0) { - if (--scansm->backoff_count != 0) { - return false; - } + if (ble_ll_scan_backoff_kick() != 0) { + return false; } #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) diff --git a/nimble/controller/src/ble_ll_scan_aux.c b/nimble/controller/src/ble_ll_scan_aux.c index 01e516fd..57d79f92 100644 --- a/nimble/controller/src/ble_ll_scan_aux.c +++ b/nimble/controller/src/ble_ll_scan_aux.c @@ -198,21 +198,6 @@ ble_ll_scan_aux_free(struct ble_ll_scan_aux_data *aux) os_memblock_put(&aux_data_pool, aux); } -static void -ble_ll_scan_aux_update_scan_backoff(struct ble_ll_scan_aux_data *aux) -{ - if (!(aux->flags & BLE_LL_SCAN_AUX_F_W4_SCAN_RSP) && - !(aux->flags & BLE_LL_SCAN_AUX_F_SCANNED)) { - return; - } - - if ((aux->hci_state & BLE_LL_SCAN_AUX_H_DONE) && - !(aux->hci_state & BLE_LL_SCAN_AUX_H_TRUNCATED)) { - ble_ll_scan_backoff_update(1); - } else { - ble_ll_scan_backoff_update(0); - } -} static inline bool ble_ll_scan_aux_need_truncation(struct ble_ll_scan_aux_data *aux) @@ -670,7 +655,10 @@ ble_ll_scan_aux_break_ev(struct ble_npl_event *ev) ble_ll_hci_ev_send_ext_adv_truncated_report(aux); } - ble_ll_scan_aux_update_scan_backoff(aux); + /* Update backoff if we were waiting for scan response */ + if (aux->flags & BLE_LL_SCAN_AUX_F_W4_SCAN_RSP) { + ble_ll_scan_backoff_update(0); + } ble_ll_scan_aux_free(aux); ble_ll_scan_chk_resume(); @@ -1658,7 +1646,15 @@ ble_ll_scan_aux_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *rxhdr) aux->hci_state |= BLE_LL_SCAN_AUX_H_DONE; } - ble_ll_scan_aux_update_scan_backoff(aux); + /* Update backoff if we were waiting for scan response */ + if (aux->flags & BLE_LL_SCAN_AUX_F_W4_SCAN_RSP) { + ble_ll_scan_backoff_update(0); + } + } else if (rxinfo->flags & BLE_MBUF_HDR_F_SCAN_RSP_RXD) { + /* We assume scan success when AUX_SCAN_RSP is received, no need to + * wait for complete chain (Core 5.3, Vol 6, Part B, 4.4.3.1). + */ + ble_ll_scan_backoff_update(1); } if (aux->hci_state & BLE_LL_SCAN_AUX_H_DONE) { @@ -1736,7 +1732,6 @@ ble_ll_scan_aux_rx_pkt_in(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *rxhdr) if ((aux->hci_state & BLE_LL_SCAN_AUX_H_DONE) && (!(rxinfo->flags & BLE_MBUF_HDR_F_AUX_PTR_WAIT) || (ble_ll_sched_rmv_elem(&aux->sch) == 0))) { - ble_ll_scan_aux_update_scan_backoff(aux); ble_ll_scan_aux_free(aux); }
