From: Weihong Guan <weihong.guan@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Weihong Guan <weihong.guan@gmail.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Marcel Holtmann <marcel@holtmann.org>
Subject: [PATCH BlueZ] device: Set Address Resolution on bonded devices
Date: Fri, 4 Dec 2026 16:41:58 +0000 [thread overview]
Message-ID: <20261204164201.865006-1-weihong.guan@gmail.com> (raw)
adapter_set_device_flags() sets DEVICE_FLAG_ADDRESS_RESOLUTION, with LL
privacy and CentralAddressResolution on and the device having privacy,
but only when another flag is being set: on Add Device's completion
(devices on the auto-connect list), WakeAllowed and PAST. A bonded device
with an IRK that is never added to the connect list, such as a GATT
peripheral connected with Device1.Connect, never gets the flag. The
kernel then keeps its IRK out of the controller's resolving list while
scanning with the accept list, and once the device moves to a new RPA it
can no longer be connected.
Set the flag, under the same conditions, when a persistent IRK is stored
and for the devices loaded from storage. The latter after Load
Connection Parameters, which frees the kernel's params for devices that
aren't on the connect list, and the flag with them.
Assisted-by: Claude:claude-opus-5.5
---
Following the discussion of a kernel patch that worked around this:
https://lore.kernel.org/linux-bluetooth/CABBYNZLacLbzyTdMe38zW-soErk3BpP7Fm7zqik7PF81bm=Fag@mail.gmail.com/
Tested on a Raspberry Pi 5 (7.4-rc2 with bluetooth-next's net/bluetooth),
an nRF52840 with LL privacy as the adapter and a CH583 using an RPA as
the peer: pair with it through bluetoothd, the peer moves to a new RPA,
Device1.Connect by the bond; then again after the peer reboots.
- master without this patch: no Set Device Flags for the peer, its IRK
never in the resolving list, both reconnects fail
(le-connection-abort-by-local).
- with it: Set Device Flags (Address Resolution) as the IRK arrives, the
IRK in the resolving list, both reconnects encrypted from the bond,
4 runs of 4.
- with it, the bond stored, bluetoothd restarted on a freshly loaded
kernel stack: the flag set after Load Connection Parameters, the first
Device1.Connect succeeds. Set before it, the flag was lost and the
connect timed out.
src/adapter.c | 11 +++++++++++
src/device.c | 34 ++++++++++++++++++++++++++++++++--
src/device.h | 1 +
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 7bdabf9..dc63f6f 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4977,6 +4977,11 @@ static void probe_devices(void *user_data)
device_resolved_drivers(device_get_adapter(device), device);
}
+static void set_addr_resolution(void *data, void *user_data)
+{
+ device_set_addr_resolution(data);
+}
+
static bool load_bredr_defaults(struct btd_adapter *adapter,
struct mgmt_tlv_list *list,
struct btd_br_defaults *defaults)
@@ -5414,6 +5419,10 @@ free:
g_slist_free_full(irks, g_free);
load_conn_params(adapter, params);
g_slist_free_full(params, g_free);
+ /* After Load Connection Parameters: it frees the kernel's params
+ * for devices not on the connect list, and the flag with them.
+ */
+ g_slist_foreach(added_devices, set_addr_resolution, NULL);
load_conn_subrate(adapter, subrates);
queue_destroy(subrates, free);
@@ -9568,6 +9577,8 @@ static void new_irk_callback(uint16_t index, uint16_t length,
store_irk(adapter, &addr->bdaddr, addr->type, irk->val);
btd_device_set_temporary(device, false);
+
+ device_set_addr_resolution(device);
}
void btd_adapter_store_conn_param(struct btd_adapter *adapter,
diff --git a/src/device.c b/src/device.c
index 720b4af..93bf722 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1761,7 +1761,7 @@ void device_set_wake_allowed(struct btd_device *device, bool wake_allowed,
set_wake_allowed_complete, device);
}
-static void set_past_complete(uint8_t status, uint16_t length,
+static void set_flags_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_rp_set_device_flags *rp = param;
@@ -1805,12 +1805,42 @@ void device_set_past_support(struct btd_device *device, bool value)
flags &= ~DEVICE_FLAG_PAST;
err = adapter_set_device_flags(device->adapter, device, flags,
- set_past_complete, device);
+ set_flags_complete, device);
if (err)
error("Failed to set past support: %s", strerror(-err));
}
+/* Set Address Resolution on a device with privacy, as
+ * adapter_set_device_flags() does when another flag is set: a device that
+ * is never added to the connect list would otherwise not get it, and the
+ * kernel then keeps its IRK out of the resolving list.
+ */
+void device_set_addr_resolution(struct btd_device *device)
+{
+ uint32_t flags;
+ int err;
+
+ if (!device || device->bdaddr_type == BDADDR_BREDR)
+ return;
+
+ if (!btd_adapter_has_settings(device->adapter,
+ MGMT_SETTING_LL_PRIVACY) ||
+ !btd_opts.defaults.le.addr_resolution ||
+ !device_get_privacy(device))
+ return;
+
+ flags = device->current_flags | device->pending_flags;
+ if (flags & DEVICE_FLAG_ADDRESS_RESOLUTION)
+ return;
+
+ err = adapter_set_device_flags(device->adapter, device,
+ flags | DEVICE_FLAG_ADDRESS_RESOLUTION,
+ set_flags_complete, device);
+ if (err)
+ error("Failed to set address resolution: %s", strerror(-err));
+}
+
static gboolean
dev_property_get_wake_allowed(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
diff --git a/src/device.h b/src/device.h
index 4527c16..7eea33a 100644
--- a/src/device.h
+++ b/src/device.h
@@ -183,6 +183,7 @@ void device_set_wake_allowed(struct btd_device *device, bool wake_allowed,
guint32 id);
void device_set_past_support(struct btd_device *device, bool value);
+void device_set_addr_resolution(struct btd_device *device);
void device_set_refresh_discovery(struct btd_device *dev, bool refresh);
--
2.47.3
next reply other threads:[~2026-12-04 16:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:41 Weihong Guan [this message]
2026-12-04 23:59 ` [BlueZ] device: Set Address Resolution on bonded devices bluez.test.bot
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=20261204164201.865006-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