aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2024-04-09 13:52:27 -0400
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2024-04-10 09:57:03 -0400
commitb163e2bd03034cfbdbf449f85144917497bb1799 (patch)
tree02da98a6ba530ad3babeba1406b40a6064527cd0
parent528f5a8c7d76a77ba6aa95b425986315cbecf3b3 (diff)
hog-lib: Destroy uHID device if there is traffic while disconnected
This attempts to destroy input device if there is an attempt to communicate with it while disconnected.
-rw-r--r--profiles/input/hog-lib.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c
index 0291adb6eb..2d8d0f359e 100644
--- a/profiles/input/hog-lib.c
+++ b/profiles/input/hog-lib.c
@@ -825,6 +825,19 @@ static void set_report_cb(guint8 status, const guint8 *pdu,
error("bt_uhid_set_report_reply: %s", strerror(-err));
}
+static void uhid_destroy(struct bt_hog *hog)
+{
+ int err;
+
+ bt_uhid_unregister_all(hog->uhid);
+
+ err = bt_uhid_destroy(hog->uhid);
+ if (err < 0) {
+ error("bt_uhid_destroy: %s", strerror(-err));
+ return;
+ }
+}
+
static void set_report(struct uhid_event *ev, void *user_data)
{
struct bt_hog *hog = user_data;
@@ -833,6 +846,14 @@ static void set_report(struct uhid_event *ev, void *user_data)
int size;
int err;
+ /* Destroy input device if there is an attempt to communicate with it
+ * while disconnected.
+ */
+ if (hog->attrib == NULL) {
+ uhid_destroy(hog);
+ return;
+ }
+
/* uhid never sends reqs in parallel; if there's a req, it timed out */
if (hog->setrep_att) {
g_attrib_cancel(hog->attrib, hog->setrep_att);
@@ -856,11 +877,6 @@ static void set_report(struct uhid_event *ev, void *user_data)
--size;
}
- if (hog->attrib == NULL) {
- err = -ENOTCONN;
- goto fail;
- }
-
DBG("Sending report type %d ID %d to handle 0x%X", report->type,
report->id, report->value_handle);
@@ -928,6 +944,14 @@ static void get_report(struct uhid_event *ev, void *user_data)
struct report *report;
guint8 err;
+ /* Destroy input device if there is an attempt to communicate with it
+ * while disconnected.
+ */
+ if (hog->attrib == NULL) {
+ uhid_destroy(hog);
+ return;
+ }
+
/* uhid never sends reqs in parallel; if there's a req, it timed out */
if (hog->getrep_att) {
g_attrib_cancel(hog->attrib, hog->getrep_att);
@@ -1204,19 +1228,6 @@ static bool cancel_gatt_req(const void *data, const void *user_data)
return g_attrib_cancel(hog->attrib, req->id);
}
-static void uhid_destroy(struct bt_hog *hog)
-{
- int err;
-
- bt_uhid_unregister_all(hog->uhid);
-
- err = bt_uhid_destroy(hog->uhid);
- if (err < 0) {
- error("bt_uhid_destroy: %s", strerror(-err));
- return;
- }
-}
-
static void hog_free(void *data)
{
struct bt_hog *hog = data;