From 56c5dbce26aa3aa15193dfb118d6fc4383b5872c Mon Sep 17 00:00:00 2001 From: Mark Wang Date: Tue, 27 May 2025 20:34:25 +0800 Subject: [PATCH] bluetooth: improve the controller address resolution enablement If the controller resolving list is cleared by HCI_LE_Clear_Resolving_List, don't need to enable the controller address resolution. Signed-off-by: Mark Wang --- subsys/bluetooth/host/id.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/id.c b/subsys/bluetooth/host/id.c index 926175f8b33b..77e65ed06a39 100644 --- a/subsys/bluetooth/host/id.c +++ b/subsys/bluetooth/host/id.c @@ -1011,6 +1011,7 @@ void bt_id_add(struct bt_keys *keys) struct bt_conn *conn; int err; + bool enable_controller_res = true; LOG_DBG("addr %s", bt_addr_le_str(&keys->addr)); @@ -1067,6 +1068,10 @@ void bt_id_add(struct bt_keys *keys) err = addr_res_enable(BT_HCI_ADDR_RES_DISABLE); if (err) { LOG_WRN("Failed to disable address resolution"); + /* If it fails to disable, it should already be enabled, + * don't need to enable again. + */ + enable_controller_res = false; goto done; } } @@ -1074,6 +1079,10 @@ void bt_id_add(struct bt_keys *keys) if (bt_dev.le.rl_entries == bt_dev.le.rl_size) { LOG_WRN("Resolving list size exceeded. Switching to host."); + /* Since the controller resolving list is cleared, + * don't need to enable the address resolution. + */ + enable_controller_res = false; err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_CLEAR_RL, NULL, NULL); if (err) { LOG_ERR("Failed to clear resolution list"); @@ -1114,7 +1123,9 @@ void bt_id_add(struct bt_keys *keys) } done: - addr_res_enable(BT_HCI_ADDR_RES_ENABLE); + if (enable_controller_res) { + addr_res_enable(BT_HCI_ADDR_RES_ENABLE); + } #if defined(CONFIG_BT_OBSERVER) if (scan_enabled) {