public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/2] input: device: Browse SDP records if not cached
Date: Wed, 16 Apr 2025 17:55:02 +0200	[thread overview]
Message-ID: <20250416155503.250763-2-frederic.danis@collabora.com> (raw)
In-Reply-To: <20250416155503.250763-1-frederic.danis@collabora.com>

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 tries to retrieve the SDP record from the remote HID then
to add the HIDP connection.
---
 profiles/input/device.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index b162c0bc7..c1bb5588d 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -86,6 +86,7 @@ struct input_device {
 	bool			virtual_cable_unplug;
 	uint8_t			type;
 	unsigned int		idle_timer;
+	bool			sdp_rediscover;
 };
 
 static int idle_timeout = 0;
@@ -1045,6 +1046,22 @@ static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
 	return FALSE;
 }
 
+static void input_device_update_rec(struct input_device *idev);
+static int hidp_add_connection(struct input_device *idev);
+
+static void hidp_sdp_cb(struct btd_device *dev, int err, void *user_data)
+{
+	struct input_device *idev = user_data;
+
+	DBG("");
+
+	/* Attempt to update SDP record if it had changed */
+	input_device_update_rec(idev);
+
+	if (hidp_add_connection(idev) < 0)
+		btd_service_disconnect(idev->service);
+}
+
 static int hidp_add_connection(struct input_device *idev)
 {
 	struct hidp_connadd_req *req;
@@ -1061,6 +1078,18 @@ static int hidp_add_connection(struct input_device *idev)
 	if (err < 0) {
 		error("Could not parse HID SDP record: %s (%d)", strerror(-err),
 									-err);
+		if (err == -ENOENT && !idev->sdp_rediscover) {
+			err = device_discover_services(idev->device);
+			if (err < 0) {
+				error("Could not discover services: %s (%d)",
+							strerror(-err), -err);
+				goto cleanup;
+			}
+
+			idev->sdp_rediscover = TRUE;
+			device_wait_for_svc_complete(idev->device,
+				hidp_sdp_cb, idev);
+		}
 		goto cleanup;
 	}
 
-- 
2.43.0


  reply	other threads:[~2025-04-16 15:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16 15:55 [PATCH BlueZ 1/2] device: Reset svc_resolved on device_discover_services() request Frédéric Danis
2025-04-16 15:55 ` Frédéric Danis [this message]
2025-04-16 17:39 ` [BlueZ,1/2] " bluez.test.bot
2025-04-24 17:06 ` 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=20250416155503.250763-2-frederic.danis@collabora.com \
    --to=frederic.danis@collabora.com \
    --cc=linux-bluetooth@vger.kernel.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