From a396bdd30a07239dc131f10627b8a7a4e89f25f2 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 5 May 2025 12:57:46 +0200 Subject: [PATCH] Bluetooth: Controller: Fix missing connection handle invalidate Fix missing connection handle invalidate on Controller power up. The connection context are zero-initialized on startup and calls to `ll_connected_get()` would incorrectly return a valid connection context pointer for connection handle 0. Relates to commit fa02dc4d02fd ("Bluetooth: Controller: Fix missing reset of connection handle"). Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/ull_conn.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index d62067a22fb..f408473b32f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -781,6 +781,7 @@ int ull_conn_reset(void) (void)ull_central_reset(); #endif /* CONFIG_BT_CENTRAL */ + /* Stop any active ticker related to connection roles */ for (handle = 0U; handle < CONFIG_BT_MAX_CONN; handle++) { disable(handle); } @@ -1667,6 +1668,14 @@ static int init_reset(void) mem_init(conn_pool, sizeof(struct ll_conn), sizeof(conn_pool) / sizeof(struct ll_conn), &conn_free); + /* Invalidate connection handles, refer to ll_connected_get() */ + for (uint16_t handle = 0U; handle < CONFIG_BT_MAX_CONN; handle++) { + struct ll_conn *conn; + + conn = ll_conn_get(handle); + conn->lll.handle = LLL_HANDLE_INVALID; + } + /* Initialize tx pool. */ mem_init(mem_conn_tx.pool, CONN_TX_BUF_SIZE, CONN_DATA_BUFFERS, &mem_conn_tx.free); @@ -1836,7 +1845,6 @@ static inline void disable(uint16_t handle) conn, &conn->lll); LL_ASSERT_INFO2(err == 0 || err == -EALREADY, handle, err); - conn->lll.handle = LLL_HANDLE_INVALID; conn->lll.link_tx_free = NULL; }