-/* $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 $ */
/*
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++) {
#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;
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;
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);
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);
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);
/*
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
-/* $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 $ */
#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)
{
}
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) {
return (0);
}
-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)
{
-/* $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 $ */
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);