Skip to content

Commit 7c27c50

Browse files
committed
Fix the implementation of the GET_REPORT command. While it does need
an extra byte to send a report ID >= 15, the report we recieve always has the report ID in a single byte. ok jcs@
1 parent f62159b commit 7c27c50

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

sys/dev/i2c/ihidev.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ihidev.c,v 1.39 2025/01/13 15:33:34 kirill Exp $ */
1+
/* $OpenBSD: ihidev.c,v 1.40 2025/06/20 22:00:49 kettenis Exp $ */
22
/*
33
* HID-over-i2c driver
44
*
@@ -367,8 +367,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg)
367367
int cmdlen = 7;
368368
int dataoff = 4;
369369
int report_id = rreq->id;
370-
int report_id_len = 1;
371-
int report_len = rreq->len + 2;
370+
int report_len = rreq->len + 2 + 1;
372371
int d;
373372
uint8_t *tmprep;
374373

@@ -386,7 +385,6 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg)
386385
if (report_id >= 15) {
387386
cmd[dataoff++] = report_id;
388387
report_id = 15;
389-
report_id_len = 2;
390388
} else
391389
cmdlen--;
392390

@@ -396,13 +394,12 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg)
396394
cmd[dataoff] = sc->hid_desc.wDataRegister >> 8;
397395

398396
/*
399-
* 7.2.2.2 - Response will be a 2-byte length value, the report
400-
* id with length determined above, and then the report.
401-
* Allocate rreq->len + 2 + 2 bytes, read into that temporary
397+
* 7.2.2.2 - Response will be a 2-byte length value,
398+
* the report id, and then the report.
399+
* Allocate rreq->len + 2 + 1 bytes, read into that temporary
402400
* buffer, and then copy only the report back out to
403401
* rreq->data.
404402
*/
405-
report_len += report_id_len;
406403
tmprep = malloc(report_len, M_DEVBUF, M_WAITOK | M_ZERO);
407404

408405
/* type 3 id 8: 22 00 38 02 23 00 */
@@ -414,11 +411,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg)
414411
DPRINTF(("%s: response size %d != expected length %d\n",
415412
sc->sc_dev.dv_xname, d, report_len));
416413

417-
if (report_id_len == 2)
418-
d = tmprep[2] | tmprep[3] << 8;
419-
else
420-
d = tmprep[2];
421-
414+
d = tmprep[2];
422415
if (d != rreq->id) {
423416
DPRINTF(("%s: response report id %d != %d\n",
424417
sc->sc_dev.dv_xname, d, rreq->id));
@@ -432,7 +425,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg)
432425
DPRINTF((" %.2x", tmprep[i]));
433426
DPRINTF(("\n"));
434427

435-
memcpy(rreq->data, tmprep + 2 + report_id_len, rreq->len);
428+
memcpy(rreq->data, tmprep + 2 + 1, rreq->len);
436429
free(tmprep, M_DEVBUF, report_len);
437430

438431
break;

0 commit comments

Comments
 (0)