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]
This commit is contained in:
Andrzej Kaczmarek
2022-09-29 00:53:02 +02:00
parent ef03c7c1c6
commit 9257bfecf2
2 changed files with 15 additions and 22 deletions
+2 -4
View File
@@ -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)
+13 -18
View File
@@ -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);
}