Linux bluetooth development
 help / color / mirror / Atom feed
From: Weihong Guan <weihong.guan@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Weihong Guan <weihong.guan@gmail.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Subject: [PATCH] Bluetooth: hci_event: Use the fallback address when no Local RPA
Date: Fri, 27 Nov 2026 05:46:33 +0000	[thread overview]
Message-ID: <20261127054635.3146219-1-weihong.guan@gmail.com> (raw)

With privacy on, a controller doing LL privacy advertises with own
address type 0x03 (0x02 with a public identity): it makes an RPA from the
resolving list's local IRK if it has an entry to match, and falls back to
the random address (the public address) otherwise. Its LE Enhanced
Connection Complete then gives the Local RPA when it made one, and zeros
when it fell back.

As peripheral, le_conn_update_addr() takes the random address only for
own address type 0x01; for 0x03 with no Local RPA it records
hdev->bdaddr as the connection's own address, and type 0x03 with it.
SMP hashes both into its checks (resp_addr, resp_addr_type), while the
central used the random address the advertising came from, type 0x01:
pairing fails, Secure Connections with "DHKey check failed" (0x0b). It
does whenever the controller falls back, as it does for undirected
advertising with no resolving list entry for the advertising's peer
address.

Take the address the controller fell back to, by type: the random
address for 0x03, the public address for 0x02. The advertising set
terminated event, which fills in an extended advertising set's random
address, checks the same type.

Fixes: cafae4cd6255 ("Bluetooth: Fix handling of LE Enhanced Connection Complete")
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Weihong Guan <weihong.guan@gmail.com>
---
How it was found and tested: on a Raspberry Pi 5 running 7.4-rc2 with
net/bluetooth from bluetooth-next, bluetoothd stopped. The peripheral: an
nRF52840 dongle with Zephyr's hci_usb (LL privacy, legacy advertising
only), privacy on (btmgmt privacy on, add-adv -c -g): Linux advertises
with own address type 0x03 from the RPA it sets as the random address;
the controller has no resolving list entry for the advertising's peer
address, so it falls back to that address, and LE Enhanced Connection
Complete gives a Local RPA of zeros. The central: another nRF52840 dongle,
or a WCH CH583 running our open HCI controller firmware.

Steps: btmgmt pair -c 3 -t 2 <the peripheral's RPA> (Secure Connections,
Just Works, both confirmations answered over the management socket).

Without this patch: pairing failed in every run, 7 of 7 (CH583 central
four times, nRF52840 three); in each trace read, the peripheral answered
the central's DHKey Check with Pairing Failed, DHKey check failed (0x0b).
With it: paired, 4 of 4 (nRF52840 central three times, CH583 once). With the
peripheral's privacy off, paired with and without.

Only legacy advertising was run: this controller has no extended
advertising, so the advertising set terminated change is by reading.

 net/bluetooth/hci_event.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a9b6a6cca..6c1d18ea4 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -6323,14 +6323,27 @@ static void le_conn_update_addr(struct hci_conn *conn, bdaddr_t *bdaddr,
 						  &conn->init_addr_type);
 		}
 	} else {
-		conn->resp_addr_type = conn->hdev->adv_addr_type;
+		/* With own address type 0x02 or 0x03 and no Local RPA, the
+		 * controller had no RPA of its own to use and fell back to the
+		 * public address (0x02) or the random address (0x03).
+		 */
+		switch (conn->hdev->adv_addr_type) {
+		case ADDR_LE_DEV_PUBLIC_RESOLVED:
+			conn->resp_addr_type = ADDR_LE_DEV_PUBLIC;
+			break;
+		case ADDR_LE_DEV_RANDOM_RESOLVED:
+			conn->resp_addr_type = ADDR_LE_DEV_RANDOM;
+			break;
+		default:
+			conn->resp_addr_type = conn->hdev->adv_addr_type;
+		}
 		/* Check if the controller has set a Local RPA then it must be
 		 * used instead or hdev->rpa.
 		 */
 		if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) {
 			conn->resp_addr_type = ADDR_LE_DEV_RANDOM;
 			bacpy(&conn->resp_addr, local_rpa);
-		} else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) {
+		} else if (conn->resp_addr_type == ADDR_LE_DEV_RANDOM) {
 			/* In case of ext adv, resp_addr will be updated in
 			 * Adv Terminated event.
 			 */
@@ -6707,7 +6720,7 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
 		 */
 		conn->adv_instance = adv ? adv->instance : ev->handle;
 
-		if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM ||
+		if (conn->resp_addr_type != ADDR_LE_DEV_RANDOM ||
 		    bacmp(&conn->resp_addr, BDADDR_ANY))
 			goto unlock;
 
-- 
2.47.3


                 reply	other threads:[~2026-11-27  5:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127054635.3146219-1-weihong.guan@gmail.com \
    --to=weihong.guan@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox