From 65716bde509975501782cbe2c74556cd4e5d7eca Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Thu, 4 Aug 2022 11:28:14 +0200 Subject: [PATCH] nimble/ll: Fix spurious MIC failure We should only check MIC failures on new PDUs. If we acked encrypted packet, but peer did not receive that ack, the encryption counter will be different on both sides for next packet. This is ok since we should drop retransmission anyway. However, MIC failure is always set by phy and failure is checked in LL before checking for retransmissions, so it does not quite work as expected. --- nimble/controller/src/ble_ll_conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c index 4d1bf85e5..ec758bffe 100644 --- a/nimble/controller/src/ble_ll_conn.c +++ b/nimble/controller/src/ble_ll_conn.c @@ -3365,9 +3365,10 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr) hdr_byte = rxbuf[0]; acl_len = rxbuf[1]; llid = hdr_byte & BLE_LL_DATA_HDR_LLID_MASK; + rxd_sn = hdr_byte & BLE_LL_DATA_HDR_SN_MASK; #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) - if (BLE_MBUF_HDR_MIC_FAILURE(hdr)) { + if (BLE_MBUF_HDR_MIC_FAILURE(hdr) && (rxd_sn != connsm->last_rxd_sn)) { STATS_INC(ble_ll_conn_stats, mic_failures); ble_ll_conn_timeout(connsm, BLE_ERR_CONN_TERM_MIC); goto conn_rx_data_pdu_end; @@ -3431,7 +3432,6 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr) * Discard the received PDU if the sequence number is the same * as the last received sequence number */ - rxd_sn = hdr_byte & BLE_LL_DATA_HDR_SN_MASK; if (rxd_sn == connsm->last_rxd_sn) { STATS_INC(ble_ll_conn_stats, data_pdu_rx_dup); goto conn_rx_data_pdu_end;