From a60ee37b8ffa9f6c0a3e635480680069a0f351a9 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Tue, 23 May 2023 15:04:50 +0200 Subject: [PATCH] nimble/ll: Fix encryption start procedure We need to update rx packet counter and direction bit after sending LL_START_ENC_RSP in central role as otherwise we will fail to decrypt LL_START_ENC_RSP from peripheral and will drop connection due to MIC failure. This only happens if peripheral replies with LL_START_ENC_RSP in the next slot after we send LL_START_ENC_RSP. If peripheral replies with an empty PDU instead, we will update direction bit on continuation and decryption on rx will be successful. --- nimble/controller/src/ble_ll_conn.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c index 78146f4f4..a4e672413 100644 --- a/nimble/controller/src/ble_ll_conn.c +++ b/nimble/controller/src/ble_ll_conn.c @@ -1372,6 +1372,9 @@ conn_tx_pdu: ble_phy_encrypt_iv_set(connsm->enc_data.iv); ble_phy_encrypt_counter_set(connsm->enc_data.tx_pkt_cntr, CONN_IS_CENTRAL(connsm)); + if (txend_func == NULL) { + txend_func = ble_ll_conn_continue_rx_encrypt; + } } else if (is_ctrl && (opcode == BLE_LL_CTRL_START_ENC_REQ)) { /* * Only the peripheral sends this and it gets sent unencrypted but