From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796402528; b=gDQy2D6Ts1UErBdF1CLcBq1V6pGTtX5/stIY32v2MRGie8X1ufdcFDAA07ScNyiOTE/5 awHPOjxA/Z76idHjfjPQ0atIFmayHOE7/D/U7k8rmP3+p+jHFCL3tmMCNXHihjcS545m6 jAOMjYdq6/SihfxQ0A83HM98lrduRAxRMJaXJzXAzf+mjA9ZuKgXOVPrOOhEH3R3KjWIJ eE0DcuJxO1qZjK1YOLGbvnNrtQV7lPojrK/t2Zp/nveO2/aEhqkoxnIBrIU5X6imisIjg 7xBXmkAETJXOPZp0gHpp5wuwpAgI6bNMwuSxPI1nnHZxeUq6tmuzTWzvytc2Ne5nHVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796402528; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=fdzy9Rz//3sAH9RM1WSo9oe69+NUqW/5ZnsXfMH8leY=; b=b9VI2Sja6dO3WgCo+uxOS0Kh85H9AiTNR88bdf/TNahto5iKIrkRCBaV/eIftxnxETzK 4diDwfY8H+OjmsZd2CMjeC/PDs6yjl4gkIlBUpjyvVPVtYsRa6gXappcTCdLQ8e0Gz3XC 5ASi7gXnU1mqiUnXYckEcf8Z7a9uLAM86w8M8qTErRjpok2l82VundKtjtIMTeOCiaMg4 Ckl1fouIgzqqyLU9+GXw4Evj5mEFtaArEGCCZBeDZZV4GLh1f4cibK6DkO6c6pK4EZ+V5 m/EFzha0INmcaDAPuqR6u2iVA9CjMI7FeOZ8Iu2Mv44Kk37lEUL5SG7Quhr6zvpvQ+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xnZef8a1; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC7C0606A322 for ; Fri, 4 Dec 2026 16:42:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC7C0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xnZef8a1 Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-387504e1934so1240380eec.1 for ; Fri, 04 Dec 2026 08:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796402527; x=1797007327; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=fdzy9Rz//3sAH9RM1WSo9oe69+NUqW/5ZnsXfMH8leY=; b=xnZef8a1V3pMizow/8nWF1xI+PspsTu73ef2pj+x/1FBxATuXzMraPaK03w9FMMHEb rzKmkmJbwDXgI0sxxdwkNqx7zPq4LfixLKFD1ILfRq4CKfSjL9tk0HtUML+kgtEmeaHk xLRE8zaLQRrQ44mXLt0RETMXLnJfgjcE7GTOnWLviQ5I87LLpGm9cveqm+46SApWx+tn t7/T2ZLCdWJJXVAMZjAtFE5xUov/8+alSlyV4FdMeeUqkD9cqAI6U+SW0MRZxIUEPkBi Ii1fsKQME3kRbDTJ+e2SskpIm3R2vvGAYJydqpqbrB/077+W1knlqRTQ4btR4PbQpV6U jR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796402527; x=1797007327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fdzy9Rz//3sAH9RM1WSo9oe69+NUqW/5ZnsXfMH8leY=; b=Irc5erRuZdhISXM8XwZXhIOyOOXLTjtD2jBQI1Isjo7Ubd9iVTXvcEYQwwQJGrV4tf MOMraoV048bxlYuUI6ER1eBwarDMOUxOxd4fVCPE7lH1UGhPbQ/Q43UJXv/ve5jy4tME SE6u8S8Mr9d7jNGa8sDbbEBUg1r4+h7DJzBQB95eaO1M3tmtmLBpDCTDNvQH/VUn1ugS fLdygRiKyIjV1jObMP52DGdLxMtsiO/x20Mkt2Oh1gV2uqyHRLT576T5vpNQfKFEvU1J hjGYdrUxd5SWgqSv5T3RFoqLctM4LkDpyJDW3eUUTNxpXWSFxDaNt374b4mIsRkSvSyL t5Hg== X-Gm-Message-State: AB4q+uEM6hJtU/z2GPlS14Rg6kHE0uVjCfNK0GVO5nQmKZFr03uJuJH7 gYJGqD5ivw6TjE0wL7IQbtALpVszXYt6FEuGDtVlsIw3Fzc6lJR55Gpw4Ofym1YF X-Gm-Gg: AZFdTZfqaT4bmDUKx7vZqUgxJlvPulXslMWB+ykFi8OyNB9Ib4gIrKahBSt3SWBO/4I 2EUKmUX1pxzAdFSkvCvMakfdLEgrqHJhTeoA/RznCOxH4ey66A5E/F99oWKB/TrKz17nMXTC0yR 476aywuxiWLNxeu3GFE4NCFv8PL7QHffIqBv4OmIxvFd4MFoD3efCRPyvnQuwyb9pvV9bkpoKg6 ViaKvU9xJ8x5V8LN0pXgVFxED+ejfw2NSdcFSw+SZy3qcyPyylIOno8DqIaXBHW6ay/HK2//dp4 5wW2A/98qikiMrAwmwLVvvn10iMJa6zzwKzATl5OeDEMGPmedvvU7EOY9PQmEbErPSDF5K2RXLp aGQj5YCH36Y6XH1iJlJK8bea49ENvx281a4eRqBmeSbIZAjdwSDZj/QXSxsxbdHlFzdIAuvw1xo y/aN4eC+qcSpL++BkmonzaCns1o4zjsPqXaSCg5fk6EGy1ayip9OdCN1M63Kjy2mCtxzGksl4ih Jedpxh3CwSD+ypopC5qCebm0QrR2tOmSLudH/GWlBtwpr9e6uv5pXdYgkWP6YUHrXGpmLC1psx8 33NETJpb0HTTljjQYw7QiqRQs+/8fNIcLDxjC8JHb+kIF/LOjc4I5bxdGKDeFF6YjjcktoBjK/k = X-Received: by 2002:a05:7301:4307:b0:378:1191:43ca with SMTP id 5a478bee46e88-387521575a0mr2501825eec.18.1796402525747; Fri, 04 Dec 2026 08:42:05 -0800 (PST) Received: from localhost.localdomain ([96.44.128.241]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5c89sm14494498eec.18.2026.12.04.08.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:42:05 -0800 (PST) From: Weihong Guan To: linux-bluetooth@vger.kernel.org Cc: Weihong Guan , Luiz Augusto von Dentz , Marcel Holtmann Subject: [PATCH BlueZ] device: Set Address Resolution on bonded devices Date: Fri, 4 Dec 2026 16:41:58 +0000 Message-ID: <20261204164201.865006-1-weihong.guan@gmail.com> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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