1 /* $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ */
3 /* Also already merged from NetBSD:
4 * $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $
11 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
13 * Copyright (c) 1998 The NetBSD Foundation, Inc.
14 * All rights reserved.
16 * This code is derived from software contributed to The NetBSD Foundation
17 * by Lennart Augustsson (lennart@augustsson.net) at
18 * Carlstedt Research & Technology.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
29 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
43 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
46 #include <sys/stdint.h>
47 #include <sys/stddef.h>
48 #include <sys/param.h>
49 #include <sys/queue.h>
50 #include <sys/types.h>
51 #include <sys/systm.h>
52 #include <sys/kernel.h>
54 #include <sys/module.h>
56 #include <sys/mutex.h>
57 #include <sys/condvar.h>
58 #include <sys/sysctl.h>
60 #include <sys/unistd.h>
61 #include <sys/callout.h>
62 #include <sys/malloc.h>
65 #include <sys/fcntl.h>
68 #include <dev/usb/usb.h>
69 #include <dev/usb/usbdi.h>
70 #include <dev/usb/usbdi_util.h>
71 #include <dev/usb/usbhid.h>
72 #include <dev/usb/usb_ioctl.h>
74 #define USB_DEBUG_VAR uhid_debug
75 #include <dev/usb/usb_debug.h>
77 #include <dev/usb/input/usb_rdesc.h>
78 #include <dev/usb/quirk/usb_quirk.h>
81 static int uhid_debug = 0;
83 static SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
85 SYSCTL_INT(_hw_usb_uhid, OID_AUTO, debug, CTLFLAG_RWTUN,
86 &uhid_debug, 0, "Debug level");
89 #define UHID_BSIZE 1024 /* bytes, buffer size */
90 #define UHID_FRAME_NUM 50 /* bytes, frame number */
101 struct usb_fifo_sc sc_fifo;
104 struct usb_xfer *sc_xfer[UHID_N_TRANSFER];
105 struct usb_device *sc_udev;
106 void *sc_repdesc_ptr;
112 uint16_t sc_repdesc_size;
115 uint8_t sc_iface_index;
120 #define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */
121 #define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are
125 static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()};
126 static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()};
127 static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()};
131 static device_probe_t uhid_probe;
132 static device_attach_t uhid_attach;
133 static device_detach_t uhid_detach;
135 static usb_callback_t uhid_intr_write_callback;
136 static usb_callback_t uhid_intr_read_callback;
137 static usb_callback_t uhid_write_callback;
138 static usb_callback_t uhid_read_callback;
140 static usb_fifo_cmd_t uhid_start_read;
141 static usb_fifo_cmd_t uhid_stop_read;
142 static usb_fifo_cmd_t uhid_start_write;
143 static usb_fifo_cmd_t uhid_stop_write;
144 static usb_fifo_open_t uhid_open;
145 static usb_fifo_close_t uhid_close;
146 static usb_fifo_ioctl_t uhid_ioctl;
148 static struct usb_fifo_methods uhid_fifo_methods = {
149 .f_open = &uhid_open,
150 .f_close = &uhid_close,
151 .f_ioctl = &uhid_ioctl,
152 .f_start_read = &uhid_start_read,
153 .f_stop_read = &uhid_stop_read,
154 .f_start_write = &uhid_start_write,
155 .f_stop_write = &uhid_stop_write,
156 .basename[0] = "uhid",
160 uhid_intr_write_callback(struct usb_xfer *xfer, usb_error_t error)
162 struct uhid_softc *sc = usbd_xfer_softc(xfer);
163 struct usb_page_cache *pc;
166 switch (USB_GET_STATE(xfer)) {
167 case USB_ST_TRANSFERRED:
170 pc = usbd_xfer_get_frame(xfer, 0);
171 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
172 0, usbd_xfer_max_len(xfer), &actlen, 0)) {
173 usbd_xfer_set_frame_len(xfer, 0, actlen);
174 usbd_transfer_submit(xfer);
179 if (error != USB_ERR_CANCELLED) {
180 /* try to clear stall first */
181 usbd_xfer_set_stall(xfer);
189 uhid_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
191 struct uhid_softc *sc = usbd_xfer_softc(xfer);
192 struct usb_page_cache *pc;
195 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
197 switch (USB_GET_STATE(xfer)) {
198 case USB_ST_TRANSFERRED:
199 DPRINTF("transferred!\n");
201 pc = usbd_xfer_get_frame(xfer, 0);
204 * If the ID byte is non zero we allow descriptors
205 * having multiple sizes:
207 if ((actlen >= (int)sc->sc_isize) ||
208 ((actlen > 0) && (sc->sc_iid != 0))) {
209 /* limit report length to the maximum */
210 if (actlen > (int)sc->sc_isize)
211 actlen = sc->sc_isize;
212 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc,
216 DPRINTF("ignored transfer, %d bytes\n", actlen);
221 if (usb_fifo_put_bytes_max(
222 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
223 usbd_xfer_set_frame_len(xfer, 0, sc->sc_isize);
224 usbd_transfer_submit(xfer);
229 if (error != USB_ERR_CANCELLED) {
230 /* try to clear stall first */
231 usbd_xfer_set_stall(xfer);
239 uhid_fill_set_report(struct usb_device_request *req, uint8_t iface_no,
240 uint8_t type, uint8_t id, uint16_t size)
242 req->bmRequestType = UT_WRITE_CLASS_INTERFACE;
243 req->bRequest = UR_SET_REPORT;
244 USETW2(req->wValue, type, id);
245 req->wIndex[0] = iface_no;
247 USETW(req->wLength, size);
251 uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no,
252 uint8_t type, uint8_t id, uint16_t size)
254 req->bmRequestType = UT_READ_CLASS_INTERFACE;
255 req->bRequest = UR_GET_REPORT;
256 USETW2(req->wValue, type, id);
257 req->wIndex[0] = iface_no;
259 USETW(req->wLength, size);
263 uhid_write_callback(struct usb_xfer *xfer, usb_error_t error)
265 struct uhid_softc *sc = usbd_xfer_softc(xfer);
266 struct usb_device_request req;
267 struct usb_page_cache *pc;
268 uint32_t size = sc->sc_osize;
272 switch (USB_GET_STATE(xfer)) {
273 case USB_ST_TRANSFERRED:
275 /* try to extract the ID byte */
277 pc = usbd_xfer_get_frame(xfer, 0);
278 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
283 usbd_copy_out(pc, 0, &id, 1);
295 pc = usbd_xfer_get_frame(xfer, 1);
296 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
297 0, UHID_BSIZE, &actlen, 1)) {
298 if (actlen != size) {
302 (&req, sc->sc_iface_no,
303 UHID_OUTPUT_REPORT, id, size);
305 pc = usbd_xfer_get_frame(xfer, 0);
306 usbd_copy_in(pc, 0, &req, sizeof(req));
308 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
309 usbd_xfer_set_frame_len(xfer, 1, size);
310 usbd_xfer_set_frames(xfer, size ? 2 : 1);
311 usbd_transfer_submit(xfer);
318 usb_fifo_get_data_error(sc->sc_fifo.fp[USB_FIFO_TX]);
324 uhid_read_callback(struct usb_xfer *xfer, usb_error_t error)
326 struct uhid_softc *sc = usbd_xfer_softc(xfer);
327 struct usb_device_request req;
328 struct usb_page_cache *pc;
330 pc = usbd_xfer_get_frame(xfer, 0);
332 switch (USB_GET_STATE(xfer)) {
333 case USB_ST_TRANSFERRED:
334 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc, sizeof(req),
340 if (usb_fifo_put_bytes_max(sc->sc_fifo.fp[USB_FIFO_RX]) > 0) {
343 (&req, sc->sc_iface_no, UHID_INPUT_REPORT,
344 sc->sc_iid, sc->sc_isize);
346 usbd_copy_in(pc, 0, &req, sizeof(req));
348 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
349 usbd_xfer_set_frame_len(xfer, 1, sc->sc_isize);
350 usbd_xfer_set_frames(xfer, sc->sc_isize ? 2 : 1);
351 usbd_transfer_submit(xfer);
357 usb_fifo_put_data_error(sc->sc_fifo.fp[USB_FIFO_RX]);
362 static const struct usb_config uhid_config[UHID_N_TRANSFER] = {
364 [UHID_INTR_DT_WR] = {
365 .type = UE_INTERRUPT,
366 .endpoint = UE_ADDR_ANY,
367 .direction = UE_DIR_OUT,
368 .flags = {.pipe_bof = 1,.no_pipe_ok = 1, },
369 .bufsize = UHID_BSIZE,
370 .callback = &uhid_intr_write_callback,
373 [UHID_INTR_DT_RD] = {
374 .type = UE_INTERRUPT,
375 .endpoint = UE_ADDR_ANY,
376 .direction = UE_DIR_IN,
377 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
378 .bufsize = UHID_BSIZE,
379 .callback = &uhid_intr_read_callback,
382 [UHID_CTRL_DT_WR] = {
384 .endpoint = 0x00, /* Control pipe */
385 .direction = UE_DIR_ANY,
386 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
387 .callback = &uhid_write_callback,
388 .timeout = 1000, /* 1 second */
391 [UHID_CTRL_DT_RD] = {
393 .endpoint = 0x00, /* Control pipe */
394 .direction = UE_DIR_ANY,
395 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
396 .callback = &uhid_read_callback,
397 .timeout = 1000, /* 1 second */
402 uhid_start_read(struct usb_fifo *fifo)
404 struct uhid_softc *sc = usb_fifo_softc(fifo);
406 if (sc->sc_flags & UHID_FLAG_IMMED) {
407 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_RD]);
409 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_RD]);
414 uhid_stop_read(struct usb_fifo *fifo)
416 struct uhid_softc *sc = usb_fifo_softc(fifo);
418 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_RD]);
419 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_RD]);
423 uhid_start_write(struct usb_fifo *fifo)
425 struct uhid_softc *sc = usb_fifo_softc(fifo);
427 if ((sc->sc_flags & UHID_FLAG_IMMED) ||
428 sc->sc_xfer[UHID_INTR_DT_WR] == NULL) {
429 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_WR]);
431 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_WR]);
436 uhid_stop_write(struct usb_fifo *fifo)
438 struct uhid_softc *sc = usb_fifo_softc(fifo);
440 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_WR]);
441 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_WR]);
445 uhid_get_report(struct uhid_softc *sc, uint8_t type,
446 uint8_t id, void *kern_data, void *user_data,
450 uint8_t free_data = 0;
452 if (kern_data == NULL) {
453 kern_data = malloc(len, M_USBDEV, M_WAITOK);
454 if (kern_data == NULL) {
460 err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
461 len, sc->sc_iface_index, type, id);
468 err = copyout(kern_data, user_data, len);
475 free(kern_data, M_USBDEV);
481 uhid_set_report(struct uhid_softc *sc, uint8_t type,
482 uint8_t id, void *kern_data, void *user_data,
486 uint8_t free_data = 0;
488 if (kern_data == NULL) {
489 kern_data = malloc(len, M_USBDEV, M_WAITOK);
490 if (kern_data == NULL) {
495 err = copyin(user_data, kern_data, len);
500 err = usbd_req_set_report(sc->sc_udev, NULL, kern_data,
501 len, sc->sc_iface_index, type, id);
508 free(kern_data, M_USBDEV);
514 uhid_open(struct usb_fifo *fifo, int fflags)
516 struct uhid_softc *sc = usb_fifo_softc(fifo);
519 * The buffers are one byte larger than maximum so that one
520 * can detect too large read/writes and short transfers:
522 if (fflags & FREAD) {
524 mtx_lock(&sc->sc_mtx);
525 sc->sc_flags &= ~UHID_FLAG_IMMED;
526 mtx_unlock(&sc->sc_mtx);
528 if (usb_fifo_alloc_buffer(fifo,
529 sc->sc_isize + 1, UHID_FRAME_NUM)) {
533 if (fflags & FWRITE) {
534 if (usb_fifo_alloc_buffer(fifo,
535 sc->sc_osize + 1, UHID_FRAME_NUM)) {
543 uhid_close(struct usb_fifo *fifo, int fflags)
545 if (fflags & (FREAD | FWRITE)) {
546 usb_fifo_free_buffer(fifo);
551 uhid_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
554 struct uhid_softc *sc = usb_fifo_softc(fifo);
555 struct usb_gen_descriptor *ugd;
561 case USB_GET_REPORT_DESC:
563 if (sc->sc_repdesc_size > ugd->ugd_maxlen) {
564 size = ugd->ugd_maxlen;
566 size = sc->sc_repdesc_size;
568 ugd->ugd_actlen = size;
569 if (ugd->ugd_data == NULL)
570 break; /* descriptor length only */
571 error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size);
575 if (!(fflags & FREAD)) {
583 error = uhid_get_report(sc, UHID_INPUT_REPORT,
584 sc->sc_iid, NULL, NULL, sc->sc_isize);
588 mtx_lock(&sc->sc_mtx);
589 sc->sc_flags |= UHID_FLAG_IMMED;
590 mtx_unlock(&sc->sc_mtx);
592 mtx_lock(&sc->sc_mtx);
593 sc->sc_flags &= ~UHID_FLAG_IMMED;
594 mtx_unlock(&sc->sc_mtx);
599 if (!(fflags & FREAD)) {
604 switch (ugd->ugd_report_type) {
605 case UHID_INPUT_REPORT:
609 case UHID_OUTPUT_REPORT:
613 case UHID_FEATURE_REPORT:
621 copyin(ugd->ugd_data, &id, 1);
622 error = uhid_get_report(sc, ugd->ugd_report_type, id,
623 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
627 if (!(fflags & FWRITE)) {
632 switch (ugd->ugd_report_type) {
633 case UHID_INPUT_REPORT:
637 case UHID_OUTPUT_REPORT:
641 case UHID_FEATURE_REPORT:
649 copyin(ugd->ugd_data, &id, 1);
650 error = uhid_set_report(sc, ugd->ugd_report_type, id,
651 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
654 case USB_GET_REPORT_ID:
655 *(int *)addr = 0; /* XXX: we only support reportid 0? */
665 static const STRUCT_USB_HOST_ID uhid_devs[] = {
666 /* generic HID class */
667 {USB_IFACE_CLASS(UICLASS_HID),},
668 /* the Xbox 360 gamepad doesn't use the HID class */
669 {USB_IFACE_CLASS(UICLASS_VENDOR),
670 USB_IFACE_SUBCLASS(UISUBCLASS_XBOX360_CONTROLLER),
671 USB_IFACE_PROTOCOL(UIPROTO_XBOX360_GAMEPAD),},
675 uhid_probe(device_t dev)
677 struct usb_attach_arg *uaa = device_get_ivars(dev);
684 if (uaa->usb_mode != USB_MODE_HOST)
687 error = usbd_lookup_id_by_uaa(uhid_devs, sizeof(uhid_devs), uaa);
691 if (usb_test_quirk(uaa, UQ_HID_IGNORE))
695 * Don't attach to mouse and keyboard devices, hence then no
696 * "nomatch" event is generated and then ums and ukbd won't
697 * attach properly when loaded.
699 if ((uaa->info.bInterfaceClass == UICLASS_HID) &&
700 (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
701 (((uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD) &&
702 !usb_test_quirk(uaa, UQ_KBD_IGNORE)) ||
703 ((uaa->info.bInterfaceProtocol == UIPROTO_MOUSE) &&
704 !usb_test_quirk(uaa, UQ_UMS_IGNORE))))
707 /* Check for mandatory multitouch usages to give wmt(4) a chance */
708 if (!usb_test_quirk(uaa, UQ_WMT_IGNORE)) {
709 error = usbd_req_get_hid_desc(uaa->device, NULL,
710 &buf, &len, M_USBDEV, uaa->info.bIfaceIndex);
711 /* Let HID decscriptor-less devices to be handled at attach */
713 if (hid_locate(buf, len,
714 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACT_MAX),
715 hid_feature, 0, NULL, NULL, NULL) &&
717 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACTID),
718 hid_input, 0, NULL, NULL, NULL)) {
726 return (BUS_PROBE_GENERIC);
730 uhid_attach(device_t dev)
732 struct usb_attach_arg *uaa = device_get_ivars(dev);
733 struct uhid_softc *sc = device_get_softc(dev);
734 int unit = device_get_unit(dev);
737 DPRINTFN(10, "sc=%p\n", sc);
739 device_set_usb_desc(dev);
741 mtx_init(&sc->sc_mtx, "uhid lock", NULL, MTX_DEF | MTX_RECURSE);
743 sc->sc_udev = uaa->device;
745 sc->sc_iface_no = uaa->info.bIfaceNum;
746 sc->sc_iface_index = uaa->info.bIfaceIndex;
748 error = usbd_transfer_setup(uaa->device,
749 &uaa->info.bIfaceIndex, sc->sc_xfer, uhid_config,
750 UHID_N_TRANSFER, sc, &sc->sc_mtx);
753 DPRINTF("error=%s\n", usbd_errstr(error));
756 if (uaa->info.idVendor == USB_VENDOR_WACOM) {
758 /* the report descriptor for the Wacom Graphire is broken */
760 if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) {
762 sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr);
763 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire_report_descr);
764 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
766 } else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
768 static uint8_t reportbuf[] = {2, 2, 2};
771 * The Graphire3 needs 0x0202 to be written to
772 * feature report ID 2 before it'll start
773 * returning digitizer data.
775 error = usbd_req_set_report(uaa->device, NULL,
776 reportbuf, sizeof(reportbuf),
777 uaa->info.bIfaceIndex, UHID_FEATURE_REPORT, 2);
780 DPRINTF("set report failed, error=%s (ignored)\n",
783 sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr);
784 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire3_4x5_report_descr);
785 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
787 } else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) &&
788 (uaa->info.bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER) &&
789 (uaa->info.bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD)) {
790 static const uint8_t reportbuf[3] = {1, 3, 0};
792 * Turn off the four LEDs on the gamepad which
793 * are blinking by default:
795 error = usbd_req_set_report(uaa->device, NULL,
796 __DECONST(void *, reportbuf), sizeof(reportbuf),
797 uaa->info.bIfaceIndex, UHID_OUTPUT_REPORT, 0);
799 DPRINTF("set output report failed, error=%s (ignored)\n",
802 /* the Xbox 360 gamepad has no report descriptor */
803 sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr);
804 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_xb360gp_report_descr);
805 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
807 if (sc->sc_repdesc_ptr == NULL) {
809 error = usbd_req_get_hid_desc(uaa->device, NULL,
810 &sc->sc_repdesc_ptr, &sc->sc_repdesc_size,
811 M_USBDEV, uaa->info.bIfaceIndex);
814 device_printf(dev, "no report descriptor\n");
818 error = usbd_req_set_idle(uaa->device, NULL,
819 uaa->info.bIfaceIndex, 0, 0);
822 DPRINTF("set idle failed, error=%s (ignored)\n",
825 sc->sc_isize = hid_report_size
826 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
828 sc->sc_osize = hid_report_size
829 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
831 sc->sc_fsize = hid_report_size
832 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
834 if (sc->sc_isize > UHID_BSIZE) {
835 DPRINTF("input size is too large, "
836 "%d bytes (truncating)\n",
838 sc->sc_isize = UHID_BSIZE;
840 if (sc->sc_osize > UHID_BSIZE) {
841 DPRINTF("output size is too large, "
842 "%d bytes (truncating)\n",
844 sc->sc_osize = UHID_BSIZE;
846 if (sc->sc_fsize > UHID_BSIZE) {
847 DPRINTF("feature size is too large, "
848 "%d bytes (truncating)\n",
850 sc->sc_fsize = UHID_BSIZE;
853 error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx,
854 &uhid_fifo_methods, &sc->sc_fifo,
855 unit, -1, uaa->info.bIfaceIndex,
856 UID_ROOT, GID_OPERATOR, 0644);
860 return (0); /* success */
868 uhid_detach(device_t dev)
870 struct uhid_softc *sc = device_get_softc(dev);
872 usb_fifo_detach(&sc->sc_fifo);
874 usbd_transfer_unsetup(sc->sc_xfer, UHID_N_TRANSFER);
876 if (sc->sc_repdesc_ptr) {
877 if (!(sc->sc_flags & UHID_FLAG_STATIC_DESC)) {
878 free(sc->sc_repdesc_ptr, M_USBDEV);
881 mtx_destroy(&sc->sc_mtx);
886 static devclass_t uhid_devclass;
888 static device_method_t uhid_methods[] = {
889 DEVMETHOD(device_probe, uhid_probe),
890 DEVMETHOD(device_attach, uhid_attach),
891 DEVMETHOD(device_detach, uhid_detach),
896 static driver_t uhid_driver = {
898 .methods = uhid_methods,
899 .size = sizeof(struct uhid_softc),
902 DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, NULL, 0);
903 MODULE_DEPEND(uhid, usb, 1, 1, 1);
904 MODULE_VERSION(uhid, 1);
905 USB_PNP_HOST_INFO(uhid_devs);