[PATCH v4 4/4] Bluetooth: find an RPA peer's connection parameters by its identity
From: Radek Podgorny
Date: Tue Nov 24 2026 - 04:31:53 EST
A bonded peer's connection parameters are stored under its identity
address, but hci_conn_params_lookup() matches only the exact address it
is given, so a caller holding the peer's RPA misses the entry.
hci_le_create_conn_sync() is such a caller: hci_connect_le() puts the
peer's cached RPA in conn->dst, and __hci_conn_add() no longer converts
it back when the controller cannot translate an identity address. The
connection is then created with the controller-wide defaults in hdev
instead of the peer's interval, latency and supervision timeout.
Resolve an RPA to its identity in hci_conn_params_lookup(), so every
caller finds the same entry whichever of the peer's addresses it holds.
The identity is looked up instead of the RPA, not after it: Pair Device
creates an entry under the RPA the peer had before bonding, and that
entry stays behind with default parameters. Matching it first would hand
it out for as long as the peer keeps that RPA. Such an entry is no
longer reachable by its RPA once the IRK is known; it is cleared with
the other disabled entries the next time all connection parameters are
loaded.
hci_conn_params_del() goes through the same lookup, so given a
resolvable RPA it now acts on the identity entry. hci_conn_params_add()
resolves the address once and uses the result both to look for an
existing entry and as the key of a new one, so a new entry is created
under the identity and a later lookup by the identity or by a rotated
RPA finds it. hci_connect_le_scan_cleanup() and le_conn_complete_evt()
free the explicit connect's entry they already hold instead of deleting
it by address, since that lookup now resolves the address again and
could reach another entry if the IRK arrived in between.
The returned entry can therefore hold a different address type than
the one the caller passed. load_conn_param() and load_conn_subrate()
look up the connection by the entry's address with the caller's type;
use the entry's type with it.
Set Device Flags and Get Device Flags given an RPA now act on the
identity's entry, where Set used to create a separate one under the RPA,
which only a lookup by that same RPA could find, and Get failed. Their
reply and the Device Flags Changed event still carry the address the
caller gave, as other mgmt commands do.
Fixes: 4914c4998961 ("Bluetooth: put the peer's on-air address on air when we cannot resolve")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Radek Podgorny <radek@xxxxxxxxxxx>
---
net/bluetooth/hci_conn.c | 3 ++-
net/bluetooth/hci_core.c | 30 ++++++++++++++++++++++++++----
net/bluetooth/hci_event.c | 4 ++--
net/bluetooth/mgmt.c | 4 ++--
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 791df930650e..c37271586345 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -117,7 +117,8 @@ void hci_connect_le_scan_cleanup(struct hci_conn *conn, u8 status)
switch (params->auto_connect) {
case HCI_AUTO_CONN_EXPLICIT:
- hci_conn_params_del(hdev, bdaddr, bdaddr_type);
+ hci_conn_params_free(params);
+ hci_update_passive_scan(hdev);
/* return instead of break to avoid duplicate scan update */
return;
case HCI_AUTO_CONN_DIRECT:
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index a87c92dccd4f..568c99bf86db 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2379,9 +2379,14 @@ void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr,
rcu_read_unlock();
}
-/* This function requires the caller holds hdev->lock */
-struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
- bdaddr_t *addr, u8 addr_type)
+/* Like hci_conn_params_lookup(), but without resolving an RPA to its
+ * identity.
+ *
+ * This function requires the caller holds hdev->lock.
+ */
+static struct hci_conn_params *__hci_conn_params_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr,
+ u8 addr_type)
{
struct hci_conn_params *params;
@@ -2395,6 +2400,17 @@ struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
return NULL;
}
+/* This function requires the caller holds hdev->lock */
+struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type)
+{
+ bdaddr_t id_addr;
+
+ hci_rpa_to_identity(hdev, &addr, &addr_type, &id_addr);
+
+ return __hci_conn_params_lookup(hdev, addr, addr_type);
+}
+
/* This function requires the caller holds hdev->lock or rcu_read_lock */
struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
bdaddr_t *addr, u8 addr_type)
@@ -2439,8 +2455,14 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
bdaddr_t *addr, u8 addr_type)
{
struct hci_conn_params *params;
+ bdaddr_t id_addr;
- params = hci_conn_params_lookup(hdev, addr, addr_type);
+ /* Resolve once, and use the result both to search and as the key
+ * of a new entry.
+ */
+ hci_rpa_to_identity(hdev, &addr, &addr_type, &id_addr);
+
+ params = __hci_conn_params_lookup(hdev, addr, addr_type);
if (params)
return params;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b6c7f9a9f55a..f7dbfb484d01 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -6551,8 +6551,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
switch (params->auto_connect) {
case HCI_AUTO_CONN_EXPLICIT:
- hci_conn_params_del(hdev, &conn->dst,
- conn->dst_type);
+ hci_conn_params_free(params);
+ hci_update_passive_scan(hdev);
break;
case HCI_AUTO_CONN_REPORT:
hci_pend_le_list_add(params,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d21538634bc3..64886b0a9091 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -8456,7 +8456,7 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
* a connection update.
*/
conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr,
- addr_type);
+ hci_param->addr_type);
if (conn && conn->role == HCI_ROLE_MASTER &&
(conn->le_conn_min_interval != min ||
conn->le_conn_max_interval != max ||
@@ -8571,7 +8571,7 @@ static int load_conn_subrate(struct sock *sk, struct hci_dev *hdev, void *data,
conn = hci_conn_hash_lookup_le(hdev,
&hci_param->addr,
- addr_type);
+ hci_param->addr_type);
if (conn && conn->state == BT_CONNECTED &&
(conn->le_rate_interval < min ||
conn->le_rate_interval > max ||
--
2.56.1