Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity
@ 2026-11-24  9:30 Radek Podgorny
  2026-11-24  9:30 ` [PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Radek Podgorny @ 2026-11-24  9:30 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Luiz Augusto von Dentz, Johan Hedberg, Jakub Pawlowski,
	linux-bluetooth, linux-kernel, Radek Podgorny

v4 answers Luiz's question on v3 about hci_conn_params_add() resolving
the address before a lookup that resolves it again, and fixes what
Sashiko raised on v3:
https://lore.kernel.org/all/CABBYNZLFtpr8xFjnimRZ9VKOsEgUV-Gzf61bomK4u+SMEyqBxA@mail.gmail.com/
https://sashiko.dev/#/patchset/20261109-for-upstream-le-conn-params-rpa-v3-1-ad1225bb0b8f%40podgorny.cz

The single v3 patch is now four. Patch 4 is the v3 fix itself. The
first three fix bugs in bluetooth-next that it exposes or sits next to,
and each stands on its own:

1. hci_connect_le() keeps pointing into an IRK after leaving RCU.
2. A connect to a peer's RPA misses the connection the peer already
   has under its identity and adds a second hci_conn.
3. A second advertising report before LE Create Connection is sent
   adds a second hci_conn for a peer dialled under its RPA.
4. The connection is created with the controller-wide defaults instead
   of the peer's own parameters.

Patches 3 and 4 use helpers added in patch 2; patch 1 is independent.

Tested on v7.3.5 (the flags tests need &c->flags there) on a Raspberry
Pi CYW43455 central and a peer on a resolvable private address whose
parameters are loaded under its identity: first with three successive
builds of v4 applied as one patch (17 of 17 connects), then with this
series for three days (6 of 6 forced reconnects and 179 connects in
normal use). Every connect was one Create Connection to the RPA,
including across RPA rotations between attempts, and those captured on
air carried the identity's parameters. With the peer connected, an
L2CAP connect to its current or a previous RPA now finds the existing
connection, as one to its identity does; without the changes it adds a
second hci_conn under the RPA and waits until it times out. Not
exercised: a controller that resolves the address itself and a peer
with no cached RPA, which this controller and peer cannot reach, and a
second advertising report before LE Create Connection is sent.

Known limitations, raised by a local Sashiko run and left as they are:

- Patch 3: if an explicit connect was made to a peer's RPA before its
  IRK was known, auto-connect to the identity gets -EBUSY until whoever
  made that connect cancels it, which for Pair Device is userspace: a
  connect that was never started has no timeout. Reusing that
  connection instead hands the auto-connect params a reference they do
  not own. Avoiding both needs the explicit connect moved to the
  identity when the IRK is added, which is a separate change.
- Patch 2: Cancel Pair Device by an RPA no longer finds a pairing
  started by that RPA when the IRK was already known. It now behaves as
  a pairing started by the identity, which is how bluetoothd starts one
  for a peer whose IRK it holds.

Per Documentation/process/generated-content.rst: the patches and this
message were done with the Claude coding assistant (model as in the
Assisted-by trailer). The prompts asked it to fix the issues Sashiko
raised on v2 and v3 and the question raised on v3, then to review the
result with a local run of Sashiko and with Sashiko's published review
prompts, and fix what that turned up. The author directed the work and
reviewed the result.

---
Changes in v4:
- Split into four patches (Sashiko)
- hci_conn_params_add(): resolve once, through a new
  __hci_conn_params_lookup() that does not resolve again (Luiz, Sashiko)
- New patch 2, hci_connect_le_scan(): resolve an RPA to the identity
  first, so a connect to an RPA neither creates its connection under
  the RPA nor misses one the peer already has under its identity
  (Sashiko). Add Device, which Sashiko also named, accepts only
  identity addresses
- New patch 3, hci_connect_le(): when the lookup by address misses,
  find the peer's connection by IRK and refuse it with -EBUSY, also
  while scanning, since a scanning one then belongs to other params. A
  second advertising report before LE Create Connection is sent no
  longer creates a second hci_conn (Sashiko). This replaces v3's reuse
  of a scanning connection found by IRK, which patch 2 makes
  unnecessary
- New patch 1: copy the RPA dialled out of the IRK under RCU
- Rebased on bluetooth-next
- Link to v3: https://patch.msgid.link/20261109-for-upstream-le-conn-params-rpa-v3-1-ad1225bb0b8f@podgorny.cz

Changes in v3:
- Look up the identity instead of the RPA, not after it, so an entry
  left under the peer's pre-bonding RPA cannot shadow it
- Copy the identity out of the IRK under rcu_read_lock(), since SMP can
  free the IRK without hdev->lock
- hci_conn_params_add() stores a new entry under the identity
- load_conn_param() and load_conn_subrate(): look up the connection with
  the entry's address type
- hci_connect_le(): find the scanning connection of a connect made to
  the peer's RPA by its IRK, so it is not duplicated once the identity
  entry is pending, even after the peer has moved to a new RPA, and
  also when the controller resolved the advertisement or no RPA is
  cached for the peer. Kept in this patch, since on its own it would
  leave a reference imbalance until the lookup is fixed
- Rebased on bluetooth-next
- Link to v2: https://patch.msgid.link/20261104120138.1165715-1-radek@podgorny.cz

Changes in v2:
- Resolve the RPA inside hci_conn_params_lookup() rather than at the
  hci_le_create_conn_sync() call site, as Luiz suggested, so no other
  caller can miss the entry
- Rebased on bluetooth-next
- Link to v1: https://patch.msgid.link/20261101-for-upstream-le-conn-params-rpa-v1-1-988629a09bc9@podgorny.cz

---
Radek Podgorny (4):
      Bluetooth: copy the peer's RPA out of its IRK under RCU
      Bluetooth: connect to an RPA as to the identity behind it
      Bluetooth: refuse to dial a peer whose connection is under its RPA
      Bluetooth: find an RPA peer's connection parameters by its identity

 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_conn.c         | 75 ++++++++++++++++++++++++++++++++++++++--
 net/bluetooth/hci_core.c         | 50 ++++++++++++++++++++++++---
 net/bluetooth/hci_event.c        |  4 +--
 net/bluetooth/mgmt.c             |  4 +--
 5 files changed, 125 insertions(+), 10 deletions(-)
---
base-commit: ffb95458a0f70dcab620eee0ecf5ef7750971b2f
change-id: 20261101-for-upstream-le-conn-params-rpa-f2334fb5dda7

-- 
Radek Podgorny <radek@podgorny.cz>


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH] Bluetooth: find an RPA peer's connection parameters by its identity
@ 2026-11-01 17:20 Radek Podgorny
  2026-11-01 19:57 ` bluez.test.bot
  0 siblings, 1 reply; 8+ messages in thread
From: Radek Podgorny @ 2026-11-01 17:20 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Luiz Augusto von Dentz, linux-bluetooth, linux-kernel,
	Radek Podgorny

hci_le_create_conn_sync() looks up the peer's connection parameters by
conn->dst. Those parameters are stored under the identity address, but
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 lookup then misses, and the connection is created with the
controller-wide defaults in hdev instead of the peer's interval, latency
and supervision timeout.

Resolve an RPA to its identity before the lookup, as
hci_connect_le_scan_cleanup() does. The other lookups by conn->dst run
after le_conn_complete_evt() has resolved it, so they are not affected.

Measured with btmon on a BCM4345C0 against a bonded peer that rotates
RPAs, with stored parameters of interval 12, latency 0 and timeout 600,
over six forced reconnects each way on v7.3.1:

                       before          after
  requested interval   30.00-50.00 ms  15.00-15.00 ms
  requested timeout    420 ms          6000 ms
  link interval        48.75 ms        15.00 ms
  link timeout         420 ms          6000 ms

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@podgorny.cz>
---
This is the follow-up to the on-air address patch that Luiz said could
be done on top:
https://lore.kernel.org/linux-bluetooth/CABBYNZ+5zV8xzhHZKTUQYT4tLHaZAO7iiKOEsKuT8aA+YNLjPQ@mail.gmail.com/

What this does not establish:
 - tested on v7.3.1, not on bluetooth-next; the patch applies to both
   and bluetooth-next was only build-tested
 - it shows the stored parameters now reach the controller. It does not
   show that links are more reliable: all twelve reconnects succeeded,
   with or without the patch

Per Documentation/process/generated-content.rst: the patch, this message
and the btmon test runs were done with the Claude coding assistant
(model as in the Assisted-by trailer). The prompts asked it to fix the
lookup miss named in the on-air address review, then to measure the
result on the author's van, with and without the patch. The author
directed the work and reviewed the result.
---
 net/bluetooth/hci_sync.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 9d829c20c31604..810d6f5143342a 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7018,6 +7018,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
 {
 	struct hci_cp_le_create_conn cp;
 	struct hci_conn_params *params;
+	struct smp_irk *irk;
 	u8 own_addr_type;
 	int err;
 	struct hci_conn *conn = data;
@@ -7057,7 +7058,16 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
 
 	hci_dev_lock(hdev);
 
-	params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
+	/* conn->dst may hold the peer's RPA, but connection parameters are
+	 * stored under its identity address.
+	 */
+	irk = hci_get_irk(hdev, &conn->dst, conn->dst_type);
+	if (irk)
+		params = hci_conn_params_lookup(hdev, &irk->bdaddr,
+						irk->addr_type);
+	else
+		params = hci_conn_params_lookup(hdev, &conn->dst,
+						conn->dst_type);
 	if (params) {
 		conn->le_conn_min_interval = params->conn_min_interval;
 		conn->le_conn_max_interval = params->conn_max_interval;

---
base-commit: 42b8c2d729268a65a2d98064e8dc59ff53646b14
change-id: 20261101-for-upstream-le-conn-params-rpa-f2334fb5dda7

-- 
Radek Podgorny <radek@podgorny.cz>


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-24 18:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  9:30 [PATCH v4 0/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
2026-11-24  9:30 ` [PATCH v4 1/4] Bluetooth: copy the peer's RPA out of its IRK under RCU Radek Podgorny
2026-11-24 18:48   ` Bluetooth: find an RPA peer's connection parameters by its identity bluez.test.bot
2026-11-24  9:30 ` [PATCH v4 2/4] Bluetooth: connect to an RPA as to the identity behind it Radek Podgorny
2026-11-24 16:35   ` Luiz Augusto von Dentz
2026-11-24  9:30 ` [PATCH v4 3/4] Bluetooth: refuse to dial a peer whose connection is under its RPA Radek Podgorny
2026-11-24  9:31 ` [PATCH v4 4/4] Bluetooth: find an RPA peer's connection parameters by its identity Radek Podgorny
  -- strict thread matches above, loose matches on Subject: below --
2026-11-01 17:20 [PATCH] " Radek Podgorny
2026-11-01 19:57 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox