All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] device: Check presence of ServiceRecords when loading from store
@ 2025-04-25 14:44 Frédéric Danis
  2025-04-25 16:06 ` [BlueZ] " bluez.test.bot
  2025-04-25 19:01 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Frédéric Danis @ 2025-04-25 14:44 UTC (permalink / raw)
  To: linux-bluetooth

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(-)

diff --git a/src/device.c b/src/device.c
index 7d0b35cb1..2ee319c4f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [BlueZ] device: Check presence of ServiceRecords when loading from store
  2025-04-25 14:44 [PATCH BlueZ] device: Check presence of ServiceRecords when loading from store Frédéric Danis
@ 2025-04-25 16:06 ` bluez.test.bot
  2025-04-25 19:01 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2025-04-25 16:06 UTC (permalink / raw)
  To: linux-bluetooth, frederic.danis

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ] device: Check presence of ServiceRecords when loading from store
  2025-04-25 14:44 [PATCH BlueZ] device: Check presence of ServiceRecords when loading from store Frédéric Danis
  2025-04-25 16:06 ` [BlueZ] " bluez.test.bot
@ 2025-04-25 19:01 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2025-04-25 19:01 UTC (permalink / raw)
  To: =?utf-8?b?RnLDqWTDqXJpYyBEYW5pcyA8ZnJlZGVyaWMuZGFuaXNAY29sbGFib3JhLmNvbT4=?=
  Cc: linux-bluetooth

Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

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
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-25 19:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-25 14:44 [PATCH BlueZ] device: Check presence of ServiceRecords when loading from store Frédéric Danis
2025-04-25 16:06 ` [BlueZ] " bluez.test.bot
2025-04-25 19:01 ` [PATCH BlueZ] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.