From 13519a67b3481262af5703dd4f2412d6d450610f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 7 Jun 2024 21:45:21 +0300 Subject: [PATCH] Bluetooth: Host: Avoid processing "no change" encryption changes If the new encryption state is the same as the old one, there's no point in doing additional processing or callbacks. Simply log a warning and ignore the HCI event in such a case. Signed-off-by: Johan Hedberg (cherry picked from commit bf363d7c3e4614ebc9b7e7a051657ae6fde6283b) --- subsys/bluetooth/host/hci_core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index a9eb0d0d1afd015..0abe7c62d9a9d9b 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -1756,6 +1756,12 @@ static void hci_encrypt_change(struct net_buf *buf) return; } + if (conn->encrypt == evt->encrypt) { + LOG_WRN("No change to encryption state (encrypt 0x%02x)", evt->encrypt); + bt_conn_unref(conn); + return; + } + conn->encrypt = evt->encrypt; #if defined(CONFIG_BT_SMP)