summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2014-04-24 09:40:29 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2014-04-24 09:40:29 +0000
commitc135241bd7e45ac04f59d37425d886748c727cf2 (patch)
tree93f6349cf073ba1b16de2863ba2a43d1592caee1
parent3285ba15dcf88065741551f8381cfe8080104c07 (diff)
Change the usbd_*_report() family of functions to take a usbd_device
and a infaceno argument instead of an iface pointer. While here, remove some unused functions and inlined usbd_read_report_desc since it is used only once. This is part of plumbing required to convert the various USB HID devices to handle multiples report IDs. ok andre@
-rw-r--r--sys/dev/usb/uhidev.c48
-rw-r--r--sys/dev/usb/uhidev.h3
-rw-r--r--sys/dev/usb/ukbd.c7
-rw-r--r--sys/dev/usb/usbdi_util.c142
-rw-r--r--sys/dev/usb/usbdi_util.h27
5 files changed, 70 insertions, 157 deletions
diff --git a/sys/dev/usb/uhidev.c b/sys/dev/usb/uhidev.c
index e7c87d30d07..205fa8e9270 100644
--- a/sys/dev/usb/uhidev.c
+++ b/sys/dev/usb/uhidev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uhidev.c,v 1.58 2014/04/15 09:14:27 mpi Exp $ */
+/* $OpenBSD: uhidev.c,v 1.59 2014/04/24 09:40:28 mpi Exp $ */
/* $NetBSD: uhidev.c,v 1.14 2003/03/11 16:44:00 augustss Exp $ */
/*
@@ -132,14 +132,10 @@ uhidev_attach(struct device *parent, struct device *self, void *aux)
sc->sc_udev = uaa->device;
sc->sc_iface = uaa->iface;
+ sc->sc_ifaceno = uaa->ifaceno;
id = usbd_get_interface_descriptor(sc->sc_iface);
- usbd_set_idle(sc->sc_iface, 0, 0);
-#if 0
- if ((usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_NO_SET_PROTO) == 0 &&
- id->bInterfaceSubClass != UISUBCLASS_BOOT)
- usbd_set_protocol(sc->sc_iface, 1);
-#endif
+ usbd_set_idle(sc->sc_udev, sc->sc_ifaceno, 0, 0);
sc->sc_iep_addr = sc->sc_oep_addr = -1;
for (i = 0; i < id->bNumEndpoints; i++) {
@@ -186,11 +182,25 @@ uhidev_attach(struct device *parent, struct device *self, void *aux)
#endif /* !SMALL_KERNEL */
if (desc == NULL) {
- if (usbd_read_report_desc(sc->sc_iface, &desc, &size,
- M_USBDEV)) {
+ struct usb_hid_descriptor *hid;
+
+ hid = usbd_get_hid_descriptor(sc->sc_udev, id);
+ if (hid == NULL) {
printf("%s: no report descriptor\n", DEVNAME(sc));
return;
}
+ size = UGETW(hid->descrs[0].wDescriptorLength);
+ desc = malloc(size, M_USBDEV, M_NOWAIT);
+ if (desc == NULL) {
+ printf("%s: no memory\n", DEVNAME(sc));
+ return;
+ }
+ if (usbd_get_report_descriptor(sc->sc_udev, sc->sc_ifaceno,
+ desc, size)) {
+ printf("%s: XXX\n", DEVNAME(sc));
+ free(desc, M_USBDEV);
+ return;
+ }
}
sc->sc_repdesc = desc;
@@ -269,8 +279,9 @@ uhidev_use_rdesc(struct uhidev_softc *sc, int vendor, int product,
break;
case USB_PRODUCT_WACOM_GRAPHIRE3_4X5:
case USB_PRODUCT_WACOM_GRAPHIRE4_4X5:
- usbd_set_report(sc->sc_iface, UHID_FEATURE_REPORT, 2,
- &reportbuf, sizeof(reportbuf));
+ usbd_set_report(sc->sc_udev, sc->sc_ifaceno,
+ UHID_FEATURE_REPORT, 2, &reportbuf,
+ sizeof(reportbuf));
size = sizeof(uhid_graphire3_4x5_report_descr);
descptr = uhid_graphire3_4x5_report_descr;
break;
@@ -604,18 +615,19 @@ uhidev_close(struct uhidev *scd)
usbd_status
uhidev_set_report(struct uhidev *scd, int type, int id, void *data, int len)
{
+ struct uhidev_softc *sc = scd->sc_parent;
char *buf;
usbd_status retstat;
if (id == 0)
- return usbd_set_report(scd->sc_parent->sc_iface, type,
+ return usbd_set_report(sc->sc_udev, sc->sc_ifaceno, type,
id, data, len);
buf = malloc(len + 1, M_TEMP, M_WAITOK);
buf[0] = id;
memcpy(buf+1, data, len);
- retstat = usbd_set_report(scd->sc_parent->sc_iface, type,
+ retstat = usbd_set_report(sc->sc_udev, sc->sc_ifaceno, type,
id, buf, len + 1);
free(buf, M_TEMP);
@@ -627,11 +639,12 @@ usbd_status
uhidev_set_report_async(struct uhidev *scd, int type, int id, void *data,
int len)
{
+ struct uhidev_softc *sc = scd->sc_parent;
char *buf;
usbd_status retstat;
if (id == 0)
- return usbd_set_report_async(scd->sc_parent->sc_iface, type,
+ return usbd_set_report_async(sc->sc_udev, sc->sc_ifaceno, type,
id, data, len);
buf = malloc(len + 1, M_TEMP, M_NOWAIT);
@@ -640,7 +653,7 @@ uhidev_set_report_async(struct uhidev *scd, int type, int id, void *data,
buf[0] = id;
memcpy(buf+1, data, len);
- retstat = usbd_set_report_async(scd->sc_parent->sc_iface, type,
+ retstat = usbd_set_report_async(sc->sc_udev, sc->sc_ifaceno, type,
id, buf, len + 1);
/*
@@ -656,7 +669,10 @@ uhidev_set_report_async(struct uhidev *scd, int type, int id, void *data,
usbd_status
uhidev_get_report(struct uhidev *scd, int type, int id, void *data, int len)
{
- return usbd_get_report(scd->sc_parent->sc_iface, type, id, data, len);
+ struct uhidev_softc *sc = scd->sc_parent;
+
+ return usbd_get_report(sc->sc_udev, sc->sc_ifaceno, type,
+ id, data, len);
}
usbd_status
diff --git a/sys/dev/usb/uhidev.h b/sys/dev/usb/uhidev.h
index f0568ecbf82..4a5f9b05f82 100644
--- a/sys/dev/usb/uhidev.h
+++ b/sys/dev/usb/uhidev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: uhidev.h,v 1.19 2014/04/15 09:14:27 mpi Exp $ */
+/* $OpenBSD: uhidev.h,v 1.20 2014/04/24 09:40:28 mpi Exp $ */
/* $NetBSD: uhidev.h,v 1.3 2002/10/08 09:56:17 dan Exp $ */
/*
@@ -41,6 +41,7 @@ struct uhidev_softc {
struct device sc_dev; /* base device */
struct usbd_device *sc_udev;
struct usbd_interface *sc_iface;/* interface */
+ int sc_ifaceno; /* interface number */
struct usbd_pipe *sc_ipipe; /* input interrupt pipe */
struct usbd_xfer *sc_ixfer; /* read request */
int sc_iep_addr;
diff --git a/sys/dev/usb/ukbd.c b/sys/dev/usb/ukbd.c
index 1ae3679bb52..4c604e4205a 100644
--- a/sys/dev/usb/ukbd.c
+++ b/sys/dev/usb/ukbd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukbd.c,v 1.64 2014/04/15 09:14:27 mpi Exp $ */
+/* $OpenBSD: ukbd.c,v 1.65 2014/04/24 09:40:28 mpi Exp $ */
/* $NetBSD: ukbd.c,v 1.85 2003/03/11 16:44:00 augustss Exp $ */
/*
@@ -252,7 +252,10 @@ ukbd_attach(struct device *parent, struct device *self, void *aux)
uha->uaa->product == USB_PRODUCT_TOPRE_HHKB) {
/* ignore country code on purpose */
} else {
- hid = usbd_get_hid_descriptor(uha->uaa->iface);
+ usb_interface_descriptor_t *id;
+
+ id = usbd_get_interface_descriptor(uha->uaa->iface);
+ hid = usbd_get_hid_descriptor(uha->uaa->device, id);
if (hid->bCountryCode <= HCC_MAX)
layout = ukbd_countrylayout[hid->bCountryCode];
diff --git a/sys/dev/usb/usbdi_util.c b/sys/dev/usb/usbdi_util.c
index 439209de101..d80c7612bd0 100644
--- a/sys/dev/usb/usbdi_util.c
+++ b/sys/dev/usb/usbdi_util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi_util.c,v 1.35 2014/03/07 18:57:23 mpi Exp $ */
+/* $OpenBSD: usbdi_util.c,v 1.36 2014/04/24 09:40:28 mpi Exp $ */
/* $NetBSD: usbdi_util.c,v 1.40 2002/07/11 21:14:36 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.14 1999/11/17 22:33:50 n_hibma Exp $ */
@@ -56,13 +56,6 @@ extern int usbdebug;
#define DPRINTFN(n,x)
#endif
-static void
-usbd_interface2device_handle(struct usbd_interface *iface,
- struct usbd_device **dev)
-{
- *dev = iface->device;
-}
-
usbd_status
usbd_get_desc(struct usbd_device *dev, int type, int index, int len, void *desc)
{
@@ -199,153 +192,86 @@ usbd_set_port_feature(struct usbd_device *dev, int port, int sel)
}
usbd_status
-usbd_get_protocol(struct usbd_interface *iface, u_int8_t *report)
-{
- usb_interface_descriptor_t *id = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
- usb_device_request_t req;
-
- DPRINTFN(4, ("usbd_get_protocol: iface=%p, endpt=%d\n", iface,
- id->bInterfaceNumber));
- if (id == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
- req.bmRequestType = UT_READ_CLASS_INTERFACE;
- req.bRequest = UR_GET_PROTOCOL;
- USETW(req.wValue, 0);
- USETW(req.wIndex, id->bInterfaceNumber);
- USETW(req.wLength, 1);
- return (usbd_do_request(dev, &req, report));
-}
-
-usbd_status
-usbd_set_protocol(struct usbd_interface *iface, int report)
-{
- usb_interface_descriptor_t *id = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
- usb_device_request_t req;
-
- DPRINTFN(4, ("usbd_set_protocol: iface=%p, report=%d, endpt=%d\n",
- iface, report, id->bInterfaceNumber));
- if (id == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
- req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
- req.bRequest = UR_SET_PROTOCOL;
- USETW(req.wValue, report);
- USETW(req.wIndex, id->bInterfaceNumber);
- USETW(req.wLength, 0);
- return (usbd_do_request(dev, &req, 0));
-}
-
-usbd_status
-usbd_set_report(struct usbd_interface *iface, int type, int id, void *data,
- int len)
+usbd_set_report(struct usbd_device *dev, int ifaceno, int type, int id,
+ void *data, int len)
{
- usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
usb_device_request_t req;
DPRINTFN(4, ("usbd_set_report: len=%d\n", len));
- if (ifd == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
req.bRequest = UR_SET_REPORT;
USETW2(req.wValue, type, id);
- USETW(req.wIndex, ifd->bInterfaceNumber);
+ USETW(req.wIndex, ifaceno);
USETW(req.wLength, len);
return (usbd_do_request(dev, &req, data));
}
usbd_status
-usbd_set_report_async(struct usbd_interface *iface, int type, int id,
+usbd_set_report_async(struct usbd_device *dev, int ifaceno, int type, int id,
void *data, int len)
{
- usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
usb_device_request_t req;
DPRINTFN(4, ("usbd_set_report_async: len=%d\n", len));
- if (ifd == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
req.bRequest = UR_SET_REPORT;
USETW2(req.wValue, type, id);
- USETW(req.wIndex, ifd->bInterfaceNumber);
+ USETW(req.wIndex, ifaceno);
USETW(req.wLength, len);
return (usbd_do_request_async(dev, &req, data));
}
usbd_status
-usbd_get_report(struct usbd_interface *iface, int type, int id, void *data,
- int len)
+usbd_get_report(struct usbd_device *dev, int ifaceno, int type, int id,
+ void *data, int len)
{
- usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
usb_device_request_t req;
DPRINTFN(4, ("usbd_get_report: len=%d\n", len));
- if (ifd == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
req.bmRequestType = UT_READ_CLASS_INTERFACE;
req.bRequest = UR_GET_REPORT;
USETW2(req.wValue, type, id);
- USETW(req.wIndex, ifd->bInterfaceNumber);
+ USETW(req.wIndex, ifaceno);
USETW(req.wLength, len);
return (usbd_do_request(dev, &req, data));
}
usbd_status
-usbd_set_idle(struct usbd_interface *iface, int duration, int id)
+usbd_set_idle(struct usbd_device *dev, int ifaceno, int duration, int id)
{
- usb_interface_descriptor_t *ifd = usbd_get_interface_descriptor(iface);
- struct usbd_device *dev;
usb_device_request_t req;
DPRINTFN(4, ("usbd_set_idle: %d %d\n", duration, id));
- if (ifd == NULL)
- return (USBD_IOERROR);
- usbd_interface2device_handle(iface, &dev);
req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
req.bRequest = UR_SET_IDLE;
USETW2(req.wValue, duration, id);
- USETW(req.wIndex, ifd->bInterfaceNumber);
+ USETW(req.wIndex, ifaceno);
USETW(req.wLength, 0);
return (usbd_do_request(dev, &req, 0));
}
usbd_status
-usbd_get_report_descriptor(struct usbd_device *dev, int ifcno, int size,
- void *d)
+usbd_get_report_descriptor(struct usbd_device *dev, int ifaceno,
+ void *data, int len)
{
usb_device_request_t req;
req.bmRequestType = UT_READ_INTERFACE;
req.bRequest = UR_GET_DESCRIPTOR;
USETW2(req.wValue, UDESC_REPORT, 0); /* report id should be 0 */
- USETW(req.wIndex, ifcno);
- USETW(req.wLength, size);
- return (usbd_do_request(dev, &req, d));
+ USETW(req.wIndex, ifaceno);
+ USETW(req.wLength, len);
+ return (usbd_do_request(dev, &req, data));
}
struct usb_hid_descriptor *
-usbd_get_hid_descriptor(struct usbd_interface *ifc)
+usbd_get_hid_descriptor(struct usbd_device *dev, usb_interface_descriptor_t *id)
{
- usb_interface_descriptor_t *idesc = usbd_get_interface_descriptor(ifc);
- struct usbd_device *dev;
- usb_config_descriptor_t *cdesc;
+ usb_config_descriptor_t *cdesc = usbd_get_config_descriptor(dev);
struct usb_hid_descriptor *hd;
char *p, *end;
- if (idesc == NULL)
- return (0);
- usbd_interface2device_handle(ifc, &dev);
- cdesc = usbd_get_config_descriptor(dev);
-
- p = (char *)idesc + idesc->bLength;
+ p = (char *)id + id->bLength;
end = (char *)cdesc + UGETW(cdesc->wTotalLength);
for (; p < end; p += hd->bLength) {
@@ -359,36 +285,6 @@ usbd_get_hid_descriptor(struct usbd_interface *ifc)
}
usbd_status
-usbd_read_report_desc(struct usbd_interface *ifc, void **descp, int *sizep,
- int mem)
-{
- usb_interface_descriptor_t *id;
- struct usb_hid_descriptor *hid;
- struct usbd_device *dev;
- usbd_status err;
-
- usbd_interface2device_handle(ifc, &dev);
- id = usbd_get_interface_descriptor(ifc);
- if (id == NULL)
- return (USBD_INVAL);
- hid = usbd_get_hid_descriptor(ifc);
- if (hid == NULL)
- return (USBD_IOERROR);
- *sizep = UGETW(hid->descrs[0].wDescriptorLength);
- *descp = malloc(*sizep, mem, M_NOWAIT);
- if (*descp == NULL)
- return (USBD_NOMEM);
- err = usbd_get_report_descriptor(dev, id->bInterfaceNumber, *sizep,
- *descp);
- if (err) {
- free(*descp, mem);
- *descp = NULL;
- return (err);
- }
- return (USBD_NORMAL_COMPLETION);
-}
-
-usbd_status
usbd_get_config(struct usbd_device *dev, u_int8_t *conf)
{
usb_device_request_t req;
diff --git a/sys/dev/usb/usbdi_util.h b/sys/dev/usb/usbdi_util.h
index d140e7f8409..f33b0dcbfe5 100644
--- a/sys/dev/usb/usbdi_util.h
+++ b/sys/dev/usb/usbdi_util.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdi_util.h,v 1.24 2014/03/07 18:57:23 mpi Exp $ */
+/* $OpenBSD: usbdi_util.h,v 1.25 2014/04/24 09:40:28 mpi Exp $ */
/* $NetBSD: usbdi_util.h,v 1.28 2002/07/11 21:14:36 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi_util.h,v 1.9 1999/11/17 22:33:50 n_hibma Exp $ */
@@ -45,20 +45,17 @@ usbd_status usbd_get_device_status(struct usbd_device *, usb_status_t *);
usbd_status usbd_get_hub_status(struct usbd_device *, usb_hub_status_t *);
usbd_status usbd_get_hub_descriptor(struct usbd_device *,
usb_hub_descriptor_t *, uint8_t);
-usbd_status usbd_get_protocol(struct usbd_interface *dev, u_int8_t *report);
-usbd_status usbd_set_protocol(struct usbd_interface *dev, int report);
-usbd_status usbd_get_report_descriptor(struct usbd_device *dev, int ifcno,
- int size, void *d);
-struct usb_hid_descriptor *usbd_get_hid_descriptor(struct usbd_interface *ifc);
-usbd_status usbd_set_report(struct usbd_interface *iface, int type, int id,
- void *data,int len);
-usbd_status usbd_set_report_async(struct usbd_interface *iface, int type,
- int id, void *data, int len);
-usbd_status usbd_get_report(struct usbd_interface *iface, int type, int id,
- void *data, int len);
-usbd_status usbd_set_idle(struct usbd_interface *iface, int duration,int id);
-usbd_status usbd_read_report_desc(struct usbd_interface *ifc, void **descp,
- int *sizep, int mem);
+struct usb_hid_descriptor *usbd_get_hid_descriptor(struct usbd_device *,
+ usb_interface_descriptor_t *);
+usbd_status usbd_get_report(struct usbd_device *, int, int, int, void *,
+ int);
+usbd_status usbd_set_report(struct usbd_device *, int, int, int, void *,
+ int);
+usbd_status usbd_set_report_async(struct usbd_device *, int, int, int,
+ void *, int);
+usbd_status usbd_set_idle(struct usbd_device *, int, int, int);
+usbd_status usbd_get_report_descriptor(struct usbd_device *, int, void *,
+ int);
usbd_status usbd_get_config(struct usbd_device *dev, u_int8_t *conf);
usbd_status usbd_get_string_desc(struct usbd_device *dev, int sindex,
int langid,usb_string_descriptor_t *sdesc, int *sizep);