Skip to contentSkip to conversation

device: Check presence of ServiceRecords when loading from store

PATCH Applied Frédéric Danis 3 participants 3 messages Apr 25, 2025 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device: Check presence of ServiceRecords when loading from store

For a HID paired device, if the cache file containing the SDP records is not present this will prevent the device to connect and need to remove it and pair again.

Current bluetoothd traces:
src/shared/mgmt.c:can_read_data() [0x0000] event 0x000b src/adapter.c:connected_callback() hci0 device EC:83:50:76:BD:67
connected eir_len 31
src/shared/mgmt.c:can_read_data() [0x0000] event 0x0006 profiles/input/server.c:connect_event_cb() Incoming connection from
EC:83:50:76:BD:67 on PSM 17
profiles/input/device.c:input_device_set_channel() idev 0x5580c6a331b0
psm 17
profiles/input/server.c:confirm_event_cb() profiles/input/server.c:connect_event_cb() Incoming connection from
EC:83:50:76:BD:67 on PSM 19
profiles/input/device.c:input_device_set_channel() idev 0x5580c6a331b0
psm 19
profiles/input/device.c:hidp_add_connection() Could not parse HID SDP
record: No such file or directory (2)
profiles/input/device.c:ctrl_watch_cb() Device EC:83:50:76:BD:67
disconnected
profiles/input/device.c:intr_watch_cb() Device EC:83:50:76:BD:67
disconnected

This commit sets BREDR svc_resolved to false if the ServiceRecords entry is not present in the cache file, triggering service rediscover on next device connection.

---
 src/device.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)
src/device.c +33 -4
index 7d0b35cb1..2ee319c4f 100644
@@ -4091,10 +4091,37 @@ next:
 	uuids = g_key_file_get_string_list(key_file, "General", "Services",
 						NULL, NULL);
 	if (uuids) {
+		char filename[PATH_MAX];
+		char device_addr[18];
+		struct stat st;
+		GKeyFile *key_file = g_key_file_new();
+		GError *gerr = NULL;
+
 		load_services(device, uuids);
 
-		/* Discovered services restored from storage */
-		device->bredr_state.svc_resolved = true;
+		ba2str(&device->bdaddr, device_addr);
+		create_filename(filename, PATH_MAX, "/%s/cache/%s",
+			btd_adapter_get_storage_dir(device->adapter),
+			device_addr);
+
+		/* Check if ServiceRecords cached group exists */
+		if (stat(filename, &st) < 0) {
+			DBG("Missing cache file for ServiceRecords");
+			device->bredr_state.svc_resolved = false;
+		} else if (!g_key_file_load_from_file(key_file, filename,
+							0, &gerr)) {
+			DBG("Unable to load key file from %s: (%s)", filename,
+								gerr->message);
+			g_clear_error(&gerr);
+			device->bredr_state.svc_resolved = false;
+		} else if (!g_key_file_has_group(key_file, "ServiceRecords")) {
+			DBG("Missing ServiceRecords from cache file");
+			device->bredr_state.svc_resolved = false;
+		} else {
+			/* Discovered services restored from storage */
+			device->bredr_state.svc_resolved = true;
+		}
+		g_key_file_free(key_file);
 	}
 
 	/* Load device id */
@@ -6852,8 +6879,10 @@ unsigned int device_wait_for_svc_complete(struct btd_device *dev,
 
 	if (state->svc_resolved || !btd_opts.reverse_discovery)
 		cb->idle_id = g_idle_add(svc_idle_cb, cb);
-	else if (dev->discov_timer > 0) {
-		timeout_remove(dev->discov_timer);
+	else {
+		if (dev->discov_timer > 0)
+			timeout_remove(dev->discov_timer);
+
 		dev->discov_timer = timeout_add_seconds(
 						0,
 						start_discovery,
Signature · 1 line
2.43.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=957071

---Test result---

Test Summary:

CheckPatch                    PENDING   0.30 seconds
GitLint                       PENDING   0.25 seconds
BuildEll                      PASS      20.42 seconds
BluezMake                     PASS      2631.74 seconds
MakeCheck                     PASS      19.90 seconds
MakeDistcheck                 PASS      196.39 seconds
CheckValgrind                 PASS      271.42 seconds
CheckSmatch                   PASS      300.92 seconds
bluezmakeextell               PASS      126.82 seconds
IncrementalBuild              PENDING   0.22 seconds
ScanBuild                     PASS      891.17 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Frédéric Danis
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 25 lines · On Fri, 25 Apr 2025 16:44:18 +0200 you wrote:

For a HID paired device, if the cache file containing the SDP records is not present this will prevent the device to connect and need to remove it and pair again.

Current bluetoothd traces:
src/shared/mgmt.c:can_read_data() [0x0000] event 0x000b src/adapter.c:connected_callback() hci0 device EC:83:50:76:BD:67
connected eir_len 31
src/shared/mgmt.c:can_read_data() [0x0000] event 0x0006 profiles/input/server.c:connect_event_cb() Incoming connection from
EC:83:50:76:BD:67 on PSM 17
profiles/input/device.c:input_device_set_channel() idev 0x5580c6a331b0
psm 17
profiles/input/server.c:confirm_event_cb() profiles/input/server.c:connect_event_cb() Incoming connection from
EC:83:50:76:BD:67 on PSM 19
profiles/input/device.c:input_device_set_channel() idev 0x5580c6a331b0
psm 19
profiles/input/device.c:hidp_add_connection() Could not parse HID SDP
record: No such file or directory (2)
profiles/input/device.c:ctrl_watch_cb() Device EC:83:50:76:BD:67
disconnected
profiles/input/device.c:intr_watch_cb() Device EC:83:50:76:BD:67
disconnected

Quoted 1 line

[...]

Here is the summary with links:
- [BlueZ] device: Check presence of ServiceRecords when loading from store

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c3b6f4e4b456

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html