[PATCH v5 3/4] Bluetooth: connect to an RPA as to the identity behind it

From: Radek Podgorny

Date: Wed Nov 25 2026 - 18:37:22 EST


A connect made to a peer's RPA through hci_connect_le_scan(), from Pair
Device, an L2CAP socket or a CIS, looks for an existing connection by
that RPA only. A bonded peer's established connection is kept under its
identity, so the lookup misses it and a second hci_conn is created under
the RPA. An L2CAP connect to the RPA of a connected peer does exactly
that on v7.3.5. The connect also marks params under the RPA for itself,
while the peer's advertising reports are resolved to its identity before
check_pending_le_conn() looks params up, so it is never started and
waits until it is cancelled.

Resolve an RPA to the identity first, through a new
hci_rpa_to_identity(), so the connect proceeds as one made to the
identity: it finds the peer's connection, also one hci_connect_le() is
still creating under an RPA, through the fallback by IRK the previous
patch adds to hci_conn_hash_lookup_le(), and marks the identity's
params.
hci_connect_le() still puts the RPA on air when the controller cannot
resolve it. SMP can free the IRK without hdev->lock, so the identity is
copied out under rcu_read_lock().

An L2CAP channel keeps the address it was connected to, here the RPA,
also when its connection is under the identity, as it already does when
le_conn_complete_evt() moves a new connection to the identity.

Fixes: f75113a26008 ("Bluetooth: add hci_connect_le_scan")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Radek Podgorny <radek@xxxxxxxxxxx>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 7 +++++++
net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++
3 files changed, 31 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 071131f08c0a..fa2d139574d2 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1904,6 +1904,8 @@ int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
u8 type);
void hci_bdaddr_list_clear(struct list_head *list);

+void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr,
+ u8 *addr_type, bdaddr_t *id_addr);
struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
bdaddr_t *addr, u8 addr_type);
struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 5676671d813c..fdebaf3c1982 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1851,6 +1851,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
enum conn_reasons conn_reason)
{
struct hci_conn *conn;
+ bdaddr_t id_addr;

/* Let's make sure that le is enabled.*/
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
@@ -1860,6 +1861,12 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
return ERR_PTR(-EOPNOTSUPP);
}

+ /* Connect to the peer as if by its identity, under which its
+ * connection and parameters are kept. hci_connect_le() puts its RPA
+ * on air when the controller cannot resolve it.
+ */
+ hci_rpa_to_identity(hdev, &dst, &dst_type, &id_addr);
+
/* Some devices send ATT messages as soon as the physical link is
* established. To be able to handle these ATT messages, the user-
* space first establishes the connection and then starts the pairing
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 024960e9af66..eb48488ab395 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2359,6 +2359,28 @@ int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
return 0;
}

+/* A peer we hold the IRK of is tracked under its identity address, so
+ * point *addr and *addr_type at the identity behind an RPA we can resolve.
+ * SMP can free the IRK without hdev->lock, so the identity is copied to
+ * @id_addr before leaving the RCU read-side section.
+ *
+ * This function requires the caller holds hdev->lock.
+ */
+void hci_rpa_to_identity(struct hci_dev *hdev, bdaddr_t **addr,
+ u8 *addr_type, bdaddr_t *id_addr)
+{
+ struct smp_irk *irk;
+
+ rcu_read_lock();
+ irk = hci_get_irk(hdev, *addr, *addr_type);
+ if (irk) {
+ bacpy(id_addr, &irk->bdaddr);
+ *addr = id_addr;
+ *addr_type = irk->addr_type;
+ }
+ 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)

--
2.56.1