diff mbox series

[scarthgap] bluez5: backport patch to fix address type when loading keys

Message ID 20250107192301.62009-1-hiagofranco@gmail.com
State New
Headers show
Series [scarthgap] bluez5: backport patch to fix address type when loading keys | expand

Commit Message

Hiago De Franco Jan. 7, 2025, 7:23 p.m. UTC
From: Hiago De Franco <hiago.franco@toradex.com>

With Linux kernel v6.6, due to commit 59b047bc9808 ("Bluetooth:
MGMT/SMP: Fix address type when using SMP over BREDR/LE"), an error
might occur when trying to automatically repair a bluetooth device, as
the key might store using a wrong/invalid address type. This happens
only with bluez5 version 5.72:

HCI Event: Link Key Request (0x17) plen 6 bdaddr 8C:98:6B:7A:BD:F0
HCI Command: Link Key Request Negative Reply (0x01|0x000c) plen 6 bdaddr 8C:98:6B:7A:BD:F0

This was already solved upstream, therefore backport the patch to fix
this issue.

Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
---
 meta/recipes-connectivity/bluez5/bluez5.inc   |  1 +
 ...ix-up-address-type-when-loading-keys.patch | 52 +++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 meta/recipes-connectivity/bluez5/bluez5/0001-adapter-Fix-up-address-type-when-loading-keys.patch
diff mbox series

Patch

diff --git a/meta/recipes-connectivity/bluez5/bluez5.inc b/meta/recipes-connectivity/bluez5/bluez5.inc
index 3f2f096aaccb..9cbeb5e99f0d 100644
--- a/meta/recipes-connectivity/bluez5/bluez5.inc
+++ b/meta/recipes-connectivity/bluez5/bluez5.inc
@@ -54,6 +54,7 @@  SRC_URI = "${KERNELORG_MIRROR}/linux/bluetooth/bluez-${PV}.tar.xz \
            ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', '', 'file://0001-Allow-using-obexd-without-systemd-in-the-user-sessio.patch', d)} \
            file://0001-tests-add-a-target-for-building-tests-without-runnin.patch \
            file://0001-test-gatt-Fix-hung-issue.patch \
+           file://0001-adapter-Fix-up-address-type-when-loading-keys.patch \
            "
 S = "${WORKDIR}/bluez-${PV}"
 
diff --git a/meta/recipes-connectivity/bluez5/bluez5/0001-adapter-Fix-up-address-type-when-loading-keys.patch b/meta/recipes-connectivity/bluez5/bluez5/0001-adapter-Fix-up-address-type-when-loading-keys.patch
new file mode 100644
index 000000000000..a2c067b5faa6
--- /dev/null
+++ b/meta/recipes-connectivity/bluez5/bluez5/0001-adapter-Fix-up-address-type-when-loading-keys.patch
@@ -0,0 +1,52 @@ 
+From 366a8c522b648f47147de4852c5c030d69b916b3 Mon Sep 17 00:00:00 2001
+From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
+Date: Wed, 28 Aug 2024 11:30:16 -0400
+Subject: [PATCH] adapter: Fix up address type when loading keys
+
+Due to kernel change 59b047bc9808
+("Bluetooth: MGMT/SMP: Fix address type when using SMP over BREDR/LE")
+some keys maybe store using the wrong/invalid address type as per MGMT
+API, so this attempts to fix them up.
+
+Fixes: https://github.com/bluez/bluez/issues/875
+Upstream-Status: Backport [366a8c522b648f47147de4852c5c030d69b916b3]
+Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
+---
+ src/adapter.c | 20 ++++++++++++++++++--
+ 1 file changed, 18 insertions(+), 2 deletions(-)
+
+diff --git a/src/adapter.c b/src/adapter.c
+index 245de4456868..9f44bdefa5f4 100644
+--- a/src/adapter.c
++++ b/src/adapter.c
+@@ -5017,12 +5017,28 @@ static void load_devices(struct btd_adapter *adapter)
+ 			goto free;
+ 		}
+ 
+-		if (key_info)
++		if (key_info) {
++			/* Fix up address type if it was stored with the wrong
++			 * address type since Load Link Keys are only meant to
++			 * work with BR/EDR addresses as per MGMT documentation.
++			 */
++			if (key_info->bdaddr_type != BDADDR_BREDR)
++				key_info->bdaddr_type = BDADDR_BREDR;
++
+ 			adapter->load_keys = g_slist_append(adapter->load_keys,
+ 								key_info);
++		}
++
++		if (ltk_info) {
++			/* Fix up address type if it was stored with the wrong
++			 * address type since Load Long Term Keys are only meant
++			 * to work with LE addresses as per MGMT documentation.
++			 */
++			if (ltk_info->bdaddr_type == BDADDR_BREDR)
++				ltk_info->bdaddr_type = BDADDR_LE_PUBLIC;
+ 
+-		if (ltk_info)
+ 			ltks = g_slist_append(ltks, ltk_info);
++		}
+ 
+ 		if (peripheral_ltk_info)
+ 			ltks = g_slist_append(ltks, peripheral_ltk_info);