Permalink
Browse files

Move HID->bus constant conversion for HID report types out of ihidev

into hidmt.

The HID code uses hid_feature, hid_input, and hid_output constants
to refer to report types internally that then need to be converted
to their bus-level counterparts before actually getting sent out (so
hid_feature becomes UHID_FEATURE_REPORT for USB,
I2C_HID_REPORT_TYPE_FEATURE for i2c).

This conversion was hard-coded in ihidev but ihidev_[gs]et_report
should assume the type passed is already an i2c-level define, not a
hid one.  This is how uhidev does it.

Add a conversion routine callback that any hidmt callers need to set
so that hidmt can convert hid constants to the bus-level versions.

Also add a similar conversion function to uhidev.

ok deraadt
  • Loading branch information...
jcs committed Aug 25, 2018
1 parent 3e20374 commit 253b28d04b9c6635c4d2e127060005b0bf7c3471
Showing with 39 additions and 21 deletions.
  1. +12 −4 sys/dev/hid/hidmt.c
  2. +2 −1 sys/dev/hid/hidmtvar.h
  3. +3 −12 sys/dev/i2c/ihidev.c
  4. +2 −1 sys/dev/i2c/ihidev.h
  5. +2 −1 sys/dev/i2c/imt.c
  6. +16 −1 sys/dev/usb/uhidev.c
  7. +2 −1 sys/dev/usb/uhidev.h
@@ -1,4 +1,4 @@
/* $OpenBSD: hidmt.c,v 1.7 2018/07/30 15:56:30 jcs Exp $ */
/* $OpenBSD: hidmt.c,v 1.8 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID multitouch driver for devices conforming to Windows Precision Touchpad
* standard
@@ -126,7 +126,11 @@ hidmt_setup(struct device *self, struct hidmt *mt, void *desc, int dlen)
capsize = hid_report_size(desc, dlen, hid_feature, mt->sc_rep_cap);
rep = malloc(capsize, M_DEVBUF, M_NOWAIT | M_ZERO);
if (mt->hidev_get_report(mt->sc_device, hid_feature, mt->sc_rep_cap,
if (mt->hidev_report_type_conv == NULL)
panic("no report type conversion function");
if (mt->hidev_get_report(mt->sc_device,
mt->hidev_report_type_conv(hid_feature), mt->sc_rep_cap,
rep, capsize)) {
printf("\n%s: failed getting capability report\n",
self->dv_xname);
@@ -278,8 +282,12 @@ hidmt_detach(struct hidmt *mt, int flags)
int
hidmt_set_input_mode(struct hidmt *mt, uint16_t mode)
{
return mt->hidev_set_report(mt->sc_device, hid_feature,
mt->sc_rep_config, &mode, 2);
if (mt->hidev_report_type_conv == NULL)
panic("no report type conversion function");
return mt->hidev_set_report(mt->sc_device,
mt->hidev_report_type_conv(hid_feature),
mt->sc_rep_config, &mode, sizeof(mode));
}
void
@@ -1,4 +1,4 @@
/* $OpenBSD: hidmtvar.h,v 1.5 2017/10/10 20:31:50 jcs Exp $ */
/* $OpenBSD: hidmtvar.h,v 1.6 2018/08/25 18:32:05 jcs Exp $ */
/*
* Copyright (c) 2016 joshua stein <jcs@openbsd.org>
*
@@ -39,6 +39,7 @@ struct hidmt {
#define HIDMT_REVY 0x0001 /* Y-axis is reversed ("natural" scrolling) */
struct device *sc_device;
int (*hidev_report_type_conv)(int);
int (*hidev_get_report)(struct device *, int, int, void *,
int);
int (*hidev_set_report)(struct device *, int, int, void *,
@@ -1,4 +1,4 @@
/* $OpenBSD: ihidev.c,v 1.16 2018/01/12 08:11:47 mlarkin Exp $ */
/* $OpenBSD: ihidev.c,v 1.17 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c driver
*
@@ -787,7 +787,6 @@ ihidev_get_report_desc(struct ihidev_softc *sc, void **desc, int *size)
*size = sc->sc_reportlen;
}
/* convert hid_* constants used throughout HID code to i2c HID equivalents */
int
ihidev_report_type_conv(int hid_type_id)
{
@@ -808,12 +807,8 @@ ihidev_get_report(struct device *dev, int type, int id, void *data, int len)
{
struct ihidev_softc *sc = (struct ihidev_softc *)dev;
struct i2c_hid_report_request rreq;
int ctype;
if ((ctype = ihidev_report_type_conv(type)) < 0)
return (1);
rreq.type = ctype;
rreq.type = type;
rreq.id = id;
rreq.data = data;
rreq.len = len;
@@ -831,12 +826,8 @@ ihidev_set_report(struct device *dev, int type, int id, void *data, int len)
{
struct ihidev_softc *sc = (struct ihidev_softc *)dev;
struct i2c_hid_report_request rreq;
int ctype;
if ((ctype = ihidev_report_type_conv(type)) < 0)
return (1);
rreq.type = ctype;
rreq.type = type;
rreq.id = id;
rreq.data = data;
rreq.len = len;
@@ -1,4 +1,4 @@
/* $OpenBSD: ihidev.h,v 1.5 2017/11/29 02:48:16 jcs Exp $ */
/* $OpenBSD: ihidev.h,v 1.6 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c driver
*
@@ -128,5 +128,6 @@ int ihidev_open(struct ihidev *);
void ihidev_close(struct ihidev *);
int ihidev_ioctl(struct ihidev *, u_long, caddr_t, int, struct proc *);
int ihidev_report_type_conv(int);
int ihidev_set_report(struct device *, int, int, void *, int);
int ihidev_get_report(struct device *, int, int, void *, int);
@@ -1,4 +1,4 @@
/* $OpenBSD: imt.c,v 1.2 2017/07/23 22:39:11 jcs Exp $ */
/* $OpenBSD: imt.c,v 1.3 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c multitouch trackpad driver for devices conforming to
* Windows Precision Touchpad standard
@@ -154,6 +154,7 @@ imt_attach(struct device *parent, struct device *self, void *aux)
/* assume everything has "natural scrolling" where Y axis is reversed */
mt->sc_flags = HIDMT_REVY;
mt->hidev_report_type_conv = ihidev_report_type_conv;
mt->hidev_get_report = imt_hidev_get_report;
mt->hidev_set_report = imt_hidev_set_report;
mt->sc_rep_input = sc->sc_rep_input;
@@ -1,4 +1,4 @@
/* $OpenBSD: uhidev.c,v 1.75 2017/04/08 02:57:25 deraadt Exp $ */
/* $OpenBSD: uhidev.c,v 1.76 2018/08/25 18:32:05 jcs Exp $ */
/* $NetBSD: uhidev.c,v 1.14 2003/03/11 16:44:00 augustss Exp $ */
/*
@@ -639,6 +639,21 @@ uhidev_close(struct uhidev *scd)
}
}
int
uhidev_report_type_conv(int hid_type_id)
{
switch (hid_type_id) {
case hid_input:
return UHID_INPUT_REPORT;
case hid_output:
return UHID_OUTPUT_REPORT;
case hid_feature:
return UHID_FEATURE_REPORT;
default:
return -1;
}
}
int
uhidev_set_report(struct uhidev_softc *sc, int type, int id, void *data,
int len)
@@ -1,4 +1,4 @@
/* $OpenBSD: uhidev.h,v 1.24 2016/01/09 02:01:06 jcs Exp $ */
/* $OpenBSD: uhidev.h,v 1.25 2018/08/25 18:32:05 jcs Exp $ */
/* $NetBSD: uhidev.h,v 1.3 2002/10/08 09:56:17 dan Exp $ */
/*
@@ -84,6 +84,7 @@ struct uhidev_attach_arg {
#define UHIDEV_CLAIM_ALLREPORTID 255
};
int uhidev_report_type_conv(int);
void uhidev_get_report_desc(struct uhidev_softc *, void **, int *);
int uhidev_open(struct uhidev *);
void uhidev_close(struct uhidev *);

0 comments on commit 253b28d

Please sign in to comment.