Skip to content

Commit cd8462b

Browse files
nimble/ll: Fix assert on aux unref during scan
This fixes assert in ble_ll_scan_aux_data_unref() during scan under heavy load. This happens when we scanned an aux with auxptr, but we failed to schedule scan for pointed aux. What happens in above scenario is that scan error is already set due to failed scheduling, but we still send complete received aux. That is ok, but we do not check for error that is already set and do not mark data as truncated which results in an assert: if any data were sent to host, it's expected that we'll have either truncated or completed flag set on last unref. The fix is to set truncated flag properly on last chunk of data from mentioned aux.
1 parent f815866 commit cd8462b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

nimble/controller/src/ble_ll_scan.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,10 +2687,16 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t *adva, uint8_t adva_type,
26872687

26882688
/*
26892689
* We need another event if either there are still some data left to
2690-
* send in current PDU or scan is not completed. The only exception is
2691-
* when this is a scannable event which is not a scan response.
2690+
* send in current PDU or scan is not completed. There are two exceptions
2691+
* though:
2692+
* - we sent all data from this PDU and there is scan error set already;
2693+
* it may be set before entering current function due to failed aux
2694+
* scan scheduling
2695+
* - this is a scannable event which is not a scan response
26922696
*/
2693-
need_event = ((offset < datalen) || (aux_data && !(aux_data->flags_ll & BLE_LL_AUX_FLAG_SCAN_COMPLETE))) && !is_scannable_aux;
2697+
need_event = ((offset < datalen) || (aux_data && !(aux_data->flags_ll & BLE_LL_AUX_FLAG_SCAN_COMPLETE))) &&
2698+
!((offset == datalen) && (aux_data->flags_ll & BLE_LL_AUX_FLAG_SCAN_ERROR)) &&
2699+
!is_scannable_aux;
26942700

26952701
if (need_event) {
26962702
/*

0 commit comments

Comments
 (0)