From: Archie Pusaka <apusaka@google.com>
To: linux-bluetooth <linux-bluetooth@vger.kernel.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: CrosBT Upstreaming <chromeos-bluetooth-upstreaming@chromium.org>,
Archie Pusaka <apusaka@chromium.org>,
Alain Michaud <alainm@chromium.org>,
Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Subject: [Bluez PATCH v2 3/3] input/device: Send UHID_DESTROY upon disconnection
Date: Mon, 3 Aug 2020 14:52:24 +0800 [thread overview]
Message-ID: <20200803145200.Bluez.v2.3.Icf343eb0ccd09fc96a897594ca12dc1a44903126@changeid> (raw)
In-Reply-To: <20200803145200.Bluez.v2.1.Ibf5508171632eebb66a6cd0ed2fa87bfac078f74@changeid>
From: Archie Pusaka <apusaka@chromium.org>
According to the uhid documentation: "If your device disconnects,
you should send an UHID_DESTROY event"
Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---
Changes in v2:
-Split into three patches, now this only handles UHID_DESTROY
profiles/input/device.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 757290080..8fc04be37 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -117,6 +117,7 @@ bool input_get_classic_bonded_only(void)
static void input_device_enter_reconnect_mode(struct input_device *idev);
static int connection_disconnect(struct input_device *idev, uint32_t flags);
+static int uhid_disconnect(struct input_device *idev);
static bool input_device_bonded(struct input_device *idev)
{
@@ -393,6 +394,10 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
if (!idev->ctrl_io && idev->virtual_cable_unplug)
virtual_cable_unplug(idev);
+ /* If connection abruptly ended, uhid might be not yet disconnected */
+ if (idev->uhid_created)
+ uhid_disconnect(idev);
+
return FALSE;
}
@@ -969,6 +974,28 @@ static int uhid_connadd(struct input_device *idev, struct hidp_connadd_req *req)
return err;
}
+static int uhid_disconnect(struct input_device *idev)
+{
+ int err;
+ struct uhid_event ev;
+
+ if (!idev->uhid_created)
+ return 0;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.type = UHID_DESTROY;
+
+ err = bt_uhid_send(idev->uhid, &ev);
+ if (err < 0) {
+ error("bt_uhid_send: %s", strerror(-err));
+ return err;
+ }
+
+ idev->uhid_created = false;
+
+ return err;
+}
+
static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
gpointer data)
{
@@ -1127,7 +1154,7 @@ static int connection_disconnect(struct input_device *idev, uint32_t flags)
idev->virtual_cable_unplug = true;
if (idev->uhid)
- return 0;
+ return uhid_disconnect(idev);
else
return ioctl_disconnect(idev, flags);
}
--
2.28.0.163.g6104cc2f0b6-goog
next prev parent reply other threads:[~2020-08-03 6:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 6:52 [Bluez PATCH v2 1/3] input/device: Replace UHID_FEATURE with UHID_GET_REPORT Archie Pusaka
2020-08-03 6:52 ` [Bluez PATCH v2 2/3] input/device: Implement handle for UHID_SET_REPORT Archie Pusaka
2020-08-03 6:52 ` Archie Pusaka [this message]
2020-08-03 20:01 ` [Bluez PATCH v2 1/3] input/device: Replace UHID_FEATURE with UHID_GET_REPORT Luiz Augusto von Dentz
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=20200803145200.Bluez.v2.3.Icf343eb0ccd09fc96a897594ca12dc1a44903126@changeid \
--to=apusaka@google.com \
--cc=abhishekpandit@chromium.org \
--cc=alainm@chromium.org \
--cc=apusaka@chromium.org \
--cc=chromeos-bluetooth-upstreaming@chromium.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).