All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix HOG profile incorrectly stripping off read report bytes.
@ 2020-11-20  1:42 Dean Camera
  2020-11-20 17:49 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 4+ messages in thread
From: Dean Camera @ 2020-11-20  1:42 UTC (permalink / raw)
  To: linux-bluetooth

If the HID subsystem requests a HID report to be read from the
device, we currently incorrectly strip off the first byte of the
response, if the device has report IDs set in the HID report
descriptor.

This is incorrect; unlike USB HID, the report ID is *not* included
in the HOG profile's HID reports, and instead exists out of band
in a descriptor on the report's bluetooth characteristic in the
device.

In this patch, we remove the erroneous stripping of the first
byte of the report, and (if report IDs are enabled) prepend the
report ID to the front of the result. This makes the HID report
returned indentical in format to that of a USB HID report, so
that the upper HID drivers can consume HOG device reports in the
same way as USB.
---
  profiles/input/hog-lib.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c
index 78018aad3..49d459e21 100644
--- a/profiles/input/hog-lib.c
+++ b/profiles/input/hog-lib.c
@@ -779,7 +779,8 @@ fail:
  static void get_report_cb(guint8 status, const guint8 *pdu, guint16 len,
  							gpointer user_data)
  {
-	struct bt_hog *hog = user_data;
+	struct report *report = user_data;
+	struct bt_hog *hog = report->hog;
  	struct uhid_event rsp;
  	int err;

@@ -808,13 +809,16 @@ static void get_report_cb(guint8 status, const 
guint8 *pdu, guint16 len,

  	--len;
  	++pdu;
+
  	if (hog->has_report_id && len > 0) {
-		--len;
-		++pdu;
+		rsp.u.get_report_reply.size = len + 1;
+		rsp.u.get_report_reply.data[0] = report->id;
+		memcpy(&rsp.u.get_report_reply.data[1], pdu, len);
+	}
+	else {
+		rsp.u.get_report_reply.size = len;
+		memcpy(rsp.u.get_report_reply.data, pdu, len);
  	}
-
-	rsp.u.get_report_reply.size = len;
-	memcpy(rsp.u.get_report_reply.data, pdu, len);

  exit:
  	rsp.u.get_report_reply.err = status;
@@ -846,7 +850,7 @@ static void get_report(struct uhid_event *ev, void 
*user_data)

  	hog->getrep_att = gatt_read_char(hog->attrib,
  						report->value_handle,
-						get_report_cb, hog);
+						get_report_cb, report);
  	if (!hog->getrep_att) {
  		err = ENOMEM;
  		goto fail;
-- 
2.29.2.windows.2


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

end of thread, other threads:[~2020-11-20 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  1:42 [PATCH] Fix HOG profile incorrectly stripping off read report bytes Dean Camera
2020-11-20 17:49 ` Luiz Augusto von Dentz
     [not found]   ` <CAHdu5-74egP-m3pUPKEb_TWHRm21DMnbqE2K119wGoO9TgXioQ@mail.gmail.com>
2020-11-20 22:00     ` Dean Camera
     [not found]       ` <CAHdu5-6MgMc9DQK=pAH0qHJYRy+aaJV98bG1ct+2tXyRv2yx-w@mail.gmail.com>
2020-11-20 22:22         ` Dean Camera

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.