uhidev.c revision 1.45
1/*	$NetBSD: uhidev.c,v 1.45 2009/11/12 19:58:27 dyoung Exp $	*/
2
3/*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
35 */
36
37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.45 2009/11/12 19:58:27 dyoung Exp $");
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/malloc.h>
44#include <sys/signalvar.h>
45#include <sys/device.h>
46#include <sys/ioctl.h>
47#include <sys/conf.h>
48
49#include <dev/usb/usb.h>
50#include <dev/usb/usbhid.h>
51
52#include <dev/usb/usbdevs.h>
53#include <dev/usb/usbdi.h>
54#include <dev/usb/usbdi_util.h>
55#include <dev/usb/hid.h>
56#include <dev/usb/usb_quirks.h>
57
58#include <dev/usb/uhidev.h>
59
60/* Report descriptor for broken Wacom Graphire */
61#include <dev/usb/ugraphire_rdesc.h>
62
63#include "locators.h"
64
65#ifdef UHIDEV_DEBUG
66#define DPRINTF(x)	if (uhidevdebug) logprintf x
67#define DPRINTFN(n,x)	if (uhidevdebug>(n)) logprintf x
68int	uhidevdebug = 0;
69#else
70#define DPRINTF(x)
71#define DPRINTFN(n,x)
72#endif
73
74Static void uhidev_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
75
76Static int uhidev_maxrepid(void *, int);
77Static int uhidevprint(void *, const char *);
78
79int uhidev_match(device_t, cfdata_t, void *);
80void uhidev_attach(device_t, device_t, void *);
81void uhidev_childdet(device_t, device_t);
82int uhidev_detach(device_t, int);
83int uhidev_activate(device_t, enum devact);
84extern struct cfdriver uhidev_cd;
85CFATTACH_DECL2_NEW(uhidev, sizeof(struct uhidev_softc), uhidev_match,
86    uhidev_attach, uhidev_detach, uhidev_activate, NULL, uhidev_childdet);
87
88USB_MATCH(uhidev)
89{
90	USB_IFMATCH_START(uhidev, uaa);
91
92	if (uaa->class != UICLASS_HID)
93		return (UMATCH_NONE);
94	if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE)
95		return (UMATCH_NONE);
96	return (UMATCH_IFACECLASS_GENERIC);
97}
98
99USB_ATTACH(uhidev)
100{
101	USB_IFATTACH_START(uhidev, sc, uaa);
102	usbd_interface_handle iface = uaa->iface;
103	usb_interface_descriptor_t *id;
104	usb_endpoint_descriptor_t *ed;
105	struct uhidev_attach_arg uha;
106	device_t dev;
107	struct uhidev *csc;
108	int maxinpktsize, size, nrepid, repid, repsz;
109	int *repsizes;
110	int i;
111	void *desc;
112	const void *descptr;
113	usbd_status err;
114	char *devinfop;
115	int locs[UHIDBUSCF_NLOCS];
116
117	sc->sc_dev = self;
118	sc->sc_udev = uaa->device;
119	sc->sc_iface = iface;
120
121	aprint_naive("\n");
122	aprint_normal("\n");
123
124	id = usbd_get_interface_descriptor(iface);
125
126	devinfop = usbd_devinfo_alloc(uaa->device, 0);
127	aprint_normal_dev(self, "%s, iclass %d/%d\n",
128	       devinfop, id->bInterfaceClass, id->bInterfaceSubClass);
129	usbd_devinfo_free(devinfop);
130
131	if (!pmf_device_register(self, NULL, NULL))
132		aprint_error_dev(self, "couldn't establish power handler\n");
133
134	(void)usbd_set_idle(iface, 0, 0);
135#if 0
136
137	qflags = usbd_get_quirks(sc->sc_udev)->uq_flags;
138	if ((qflags & UQ_NO_SET_PROTO) == 0 &&
139	    id->bInterfaceSubClass != UISUBCLASS_BOOT)
140		(void)usbd_set_protocol(iface, 1);
141#endif
142
143	maxinpktsize = 0;
144	sc->sc_iep_addr = sc->sc_oep_addr = -1;
145	for (i = 0; i < id->bNumEndpoints; i++) {
146		ed = usbd_interface2endpoint_descriptor(iface, i);
147		if (ed == NULL) {
148			aprint_error_dev(self,
149			    "could not read endpoint descriptor\n");
150			sc->sc_dying = 1;
151			USB_ATTACH_ERROR_RETURN;
152		}
153
154		DPRINTFN(10,("uhidev_attach: bLength=%d bDescriptorType=%d "
155		    "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
156		    " bInterval=%d\n",
157		    ed->bLength, ed->bDescriptorType,
158		    ed->bEndpointAddress & UE_ADDR,
159		    UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out",
160		    ed->bmAttributes & UE_XFERTYPE,
161		    UGETW(ed->wMaxPacketSize), ed->bInterval));
162
163		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
164		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
165			maxinpktsize = UGETW(ed->wMaxPacketSize);
166			sc->sc_iep_addr = ed->bEndpointAddress;
167		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
168		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
169			sc->sc_oep_addr = ed->bEndpointAddress;
170		} else {
171			aprint_verbose_dev(self, "endpoint %d: ignored\n", i);
172		}
173	}
174
175	/*
176	 * Check that we found an input interrupt endpoint. The output interrupt
177	 * endpoint is optional
178	 */
179	if (sc->sc_iep_addr == -1) {
180		aprint_error_dev(self, "no input interrupt endpoint\n");
181		sc->sc_dying = 1;
182		USB_ATTACH_ERROR_RETURN;
183	}
184
185	/* XXX need to extend this */
186	descptr = NULL;
187	if (uaa->vendor == USB_VENDOR_WACOM) {
188		static uByte reportbuf[] = {2, 2, 2};
189
190		/* The report descriptor for the Wacom Graphire is broken. */
191		switch (uaa->product) {
192		case USB_PRODUCT_WACOM_GRAPHIRE:
193			size = sizeof uhid_graphire_report_descr;
194			descptr = uhid_graphire_report_descr;
195			break;
196
197		case USB_PRODUCT_WACOM_GRAPHIRE3_4X5:
198		case USB_PRODUCT_WACOM_GRAPHIRE3_6X8:
199		case USB_PRODUCT_WACOM_GRAPHIRE4_4X5: /* The 6x8 too? */
200			/*
201			 * The Graphire3 needs 0x0202 to be written to
202			 * feature report ID 2 before it'll start
203			 * returning digitizer data.
204			 */
205			usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 2,
206			    &reportbuf, sizeof reportbuf);
207
208			size = sizeof uhid_graphire3_4x5_report_descr;
209			descptr = uhid_graphire3_4x5_report_descr;
210			break;
211		default:
212			/* Keep descriptor */
213			break;
214		}
215	}
216
217	if (descptr) {
218		desc = malloc(size, M_USBDEV, M_NOWAIT);
219		if (desc == NULL)
220			err = USBD_NOMEM;
221		else {
222			err = USBD_NORMAL_COMPLETION;
223			memcpy(desc, descptr, size);
224		}
225	} else {
226		desc = NULL;
227		err = usbd_read_report_desc(uaa->iface, &desc, &size,
228		    M_USBDEV);
229	}
230	if (err) {
231		aprint_error_dev(self, "no report descriptor\n");
232		sc->sc_dying = 1;
233		USB_ATTACH_ERROR_RETURN;
234	}
235
236	if (uaa->vendor == USB_VENDOR_HOSIDEN &&
237	    uaa->product == USB_PRODUCT_HOSIDEN_PPP) {
238		static uByte reportbuf[] = { 1 };
239		/*
240		 *  This device was sold by Konami with its ParaParaParadise
241		 *  game for PlayStation2.  It needs to be "turned on"
242		 *  before it will send any reports.
243		 */
244
245		usbd_set_report(uaa->iface, UHID_FEATURE_REPORT, 0,
246		    &reportbuf, sizeof reportbuf);
247	}
248
249	sc->sc_repdesc = desc;
250	sc->sc_repdesc_size = size;
251
252	uha.uaa = uaa;
253	nrepid = uhidev_maxrepid(desc, size);
254	if (nrepid < 0)
255		USB_ATTACH_SUCCESS_RETURN;
256	if (nrepid > 0)
257		aprint_normal_dev(self, "%d report ids\n", nrepid);
258	nrepid++;
259	repsizes = malloc(nrepid * sizeof(*repsizes), M_TEMP, M_NOWAIT);
260	if (repsizes == NULL)
261		goto nomem;
262	sc->sc_subdevs = malloc(nrepid * sizeof(device_t),
263				M_USBDEV, M_NOWAIT | M_ZERO);
264	if (sc->sc_subdevs == NULL) {
265		free(repsizes, M_TEMP);
266nomem:
267		aprint_error_dev(self, "no memory\n");
268		USB_ATTACH_ERROR_RETURN;
269	}
270
271	/* Just request max packet size for the interrupt pipe */
272	sc->sc_isize = maxinpktsize;
273	sc->sc_nrepid = nrepid;
274
275	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
276			   USBDEV(sc->sc_dev));
277
278	for (repid = 0; repid < nrepid; repid++) {
279		repsz = hid_report_size(desc, size, hid_input, repid);
280		DPRINTF(("uhidev_match: repid=%d, repsz=%d\n", repid, repsz));
281		repsizes[repid] = repsz;
282	}
283
284	DPRINTF(("uhidev_attach: isize=%d\n", sc->sc_isize));
285
286	uha.parent = sc;
287	for (repid = 0; repid < nrepid; repid++) {
288		DPRINTF(("uhidev_match: try repid=%d\n", repid));
289		if (hid_report_size(desc, size, hid_input, repid) == 0 &&
290		    hid_report_size(desc, size, hid_output, repid) == 0 &&
291		    hid_report_size(desc, size, hid_feature, repid) == 0) {
292			;	/* already NULL in sc->sc_subdevs[repid] */
293		} else {
294			uha.reportid = repid;
295			locs[UHIDBUSCF_REPORTID] = repid;
296
297			dev = config_found_sm_loc(self,
298				"uhidbus", locs, &uha,
299				uhidevprint, config_stdsubmatch);
300			sc->sc_subdevs[repid] = dev;
301			if (dev != NULL) {
302				csc = device_private(dev);
303				csc->sc_in_rep_size = repsizes[repid];
304#ifdef DIAGNOSTIC
305				DPRINTF(("uhidev_match: repid=%d dev=%p\n",
306					 repid, dev));
307				if (csc->sc_intr == NULL) {
308					free(repsizes, M_TEMP);
309					aprint_error_dev(self,
310					    "sc_intr == NULL\n");
311					USB_ATTACH_ERROR_RETURN;
312				}
313#endif
314#if NRND > 0
315				rnd_attach_source(&csc->rnd_source,
316						  USBDEVNAME(dev),
317						  RND_TYPE_TTY, 0);
318#endif
319			}
320		}
321	}
322	free(repsizes, M_TEMP);
323
324	USB_ATTACH_SUCCESS_RETURN;
325}
326
327int
328uhidev_maxrepid(void *buf, int len)
329{
330	struct hid_data *d;
331	struct hid_item h;
332	int maxid;
333
334	maxid = -1;
335	h.report_ID = 0;
336	for (d = hid_start_parse(buf, len, hid_none); hid_get_item(d, &h); )
337		if (h.report_ID > maxid)
338			maxid = h.report_ID;
339	hid_end_parse(d);
340	return (maxid);
341}
342
343int
344uhidevprint(void *aux, const char *pnp)
345{
346	struct uhidev_attach_arg *uha = aux;
347
348	if (pnp)
349		aprint_normal("uhid at %s", pnp);
350	if (uha->reportid != 0)
351		aprint_normal(" reportid %d", uha->reportid);
352	return (UNCONF);
353}
354
355int
356uhidev_activate(device_t self, enum devact act)
357{
358	struct uhidev_softc *sc = device_private(self);
359
360	switch (act) {
361	case DVACT_DEACTIVATE:
362		sc->sc_dying = 1;
363		return 0;
364	default:
365		return EOPNOTSUPP;
366	}
367}
368
369void
370uhidev_childdet(device_t self, device_t child)
371{
372	int i;
373	struct uhidev_softc *sc = device_private(self);
374
375	for (i = 0; i < sc->sc_nrepid; i++) {
376		if (sc->sc_subdevs[i] == child)
377			break;
378	}
379	KASSERT(i < sc->sc_nrepid);
380	sc->sc_subdevs[i] = NULL;
381}
382
383USB_DETACH(uhidev)
384{
385	USB_DETACH_START(uhidev, sc);
386	int i, rv;
387#if NRND > 0
388	struct uhidev *csc;
389#endif
390
391	DPRINTF(("uhidev_detach: sc=%p flags=%d\n", sc, flags));
392
393	sc->sc_dying = 1;
394	if (sc->sc_ipipe != NULL)
395		usbd_abort_pipe(sc->sc_ipipe);
396
397	if (sc->sc_repdesc != NULL)
398		free(sc->sc_repdesc, M_USBDEV);
399
400	rv = 0;
401	for (i = 0; i < sc->sc_nrepid; i++) {
402		if (sc->sc_subdevs[i] != NULL) {
403#if NRND > 0
404			csc = device_private(sc->sc_subdevs[i]);
405			rnd_detach_source(&csc->rnd_source);
406#endif
407			rv |= config_detach(sc->sc_subdevs[i], flags);
408		}
409	}
410
411	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
412			   USBDEV(sc->sc_dev));
413
414	pmf_device_deregister(self);
415
416	return (rv);
417}
418
419void
420uhidev_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
421{
422	struct uhidev_softc *sc = addr;
423	device_t cdev;
424	struct uhidev *scd;
425	u_char *p;
426	u_int rep;
427	u_int32_t cc;
428
429	usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
430
431#ifdef UHIDEV_DEBUG
432	if (uhidevdebug > 5) {
433		u_int32_t i;
434
435		DPRINTF(("uhidev_intr: status=%d cc=%d\n", status, cc));
436		DPRINTF(("uhidev_intr: data ="));
437		for (i = 0; i < cc; i++)
438			DPRINTF((" %02x", sc->sc_ibuf[i]));
439		DPRINTF(("\n"));
440	}
441#endif
442
443	if (status == USBD_CANCELLED)
444		return;
445
446	if (status != USBD_NORMAL_COMPLETION) {
447		DPRINTF(("%s: interrupt status=%d\n", USBDEVNAME(sc->sc_dev),
448			 status));
449		usbd_clear_endpoint_stall_async(sc->sc_ipipe);
450		return;
451	}
452
453	p = sc->sc_ibuf;
454	if (sc->sc_nrepid != 1)
455		rep = *p++, cc--;
456	else
457		rep = 0;
458	if (rep >= sc->sc_nrepid) {
459		printf("uhidev_intr: bad repid %d\n", rep);
460		return;
461	}
462	cdev = sc->sc_subdevs[rep];
463	if (!cdev)
464		return;
465	scd = device_private(cdev);
466	DPRINTFN(5,("uhidev_intr: rep=%d, scd=%p state=0x%x\n",
467		    rep, scd, scd ? scd->sc_state : 0));
468	if (!(scd->sc_state & UHIDEV_OPEN))
469		return;
470	if (scd->sc_in_rep_size > cc) {
471		printf("%s: bad input length %d != %d\n",
472		       USBDEVNAME(sc->sc_dev), scd->sc_in_rep_size, cc);
473		return;
474	}
475#if NRND > 0
476	rnd_add_uint32(&scd->rnd_source, (uintptr_t)(sc->sc_ibuf));
477#endif
478	scd->sc_intr(scd, p, cc);
479}
480
481void
482uhidev_get_report_desc(struct uhidev_softc *sc, void **desc, int *size)
483{
484	*desc = sc->sc_repdesc;
485	*size = sc->sc_repdesc_size;
486}
487
488int
489uhidev_open(struct uhidev *scd)
490{
491	struct uhidev_softc *sc = scd->sc_parent;
492	usbd_status err;
493	int error;
494
495	DPRINTF(("uhidev_open: open pipe, state=%d refcnt=%d\n",
496		 scd->sc_state, sc->sc_refcnt));
497
498	if (scd->sc_state & UHIDEV_OPEN)
499		return (EBUSY);
500	scd->sc_state |= UHIDEV_OPEN;
501	if (sc->sc_refcnt++)
502		return (0);
503
504	if (sc->sc_isize == 0)
505		return (0);
506
507	sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
508
509	/* Set up input interrupt pipe. */
510	DPRINTF(("uhidev_open: isize=%d, ep=0x%02x\n", sc->sc_isize,
511		 sc->sc_iep_addr));
512
513	err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_iep_addr,
514		  USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_ibuf,
515		  sc->sc_isize, uhidev_intr, USBD_DEFAULT_INTERVAL);
516	if (err != USBD_NORMAL_COMPLETION) {
517		DPRINTF(("uhidopen: usbd_open_pipe_intr failed, "
518		    "error=%d\n", err));
519		error = EIO;
520		goto out1;
521	}
522
523	/*
524	 * Set up output interrupt pipe if an output interrupt endpoint
525	 * exists.
526	 */
527	if (sc->sc_oep_addr != -1) {
528		DPRINTF(("uhidev_open: oep=0x%02x\n", sc->sc_oep_addr));
529
530		err = usbd_open_pipe(sc->sc_iface, sc->sc_oep_addr,
531		    0, &sc->sc_opipe);
532
533		if (err != USBD_NORMAL_COMPLETION) {
534			DPRINTF(("uhidev_open: usbd_open_pipe failed, "
535			    "error=%d\n", err));
536			error = EIO;
537			goto out2;
538		}
539		DPRINTF(("uhidev_open: sc->sc_opipe=%p\n", sc->sc_opipe));
540
541		sc->sc_oxfer = usbd_alloc_xfer(sc->sc_udev);
542		if (sc->sc_oxfer == NULL) {
543			DPRINTF(("uhidev_open: couldn't allocate an xfer\n"));
544			error = ENOMEM;
545			goto out3;
546		}
547	}
548
549	return (0);
550out3:
551	/* Abort output pipe */
552	usbd_close_pipe(sc->sc_opipe);
553out2:
554	/* Abort input pipe */
555	usbd_close_pipe(sc->sc_ipipe);
556out1:
557	DPRINTF(("uhidev_open: failed in someway"));
558	free(sc->sc_ibuf, M_USBDEV);
559	scd->sc_state &= ~UHIDEV_OPEN;
560	sc->sc_refcnt = 0;
561	sc->sc_ipipe = NULL;
562	sc->sc_opipe = NULL;
563	sc->sc_oxfer = NULL;
564	return error;
565}
566
567void
568uhidev_close(struct uhidev *scd)
569{
570	struct uhidev_softc *sc = scd->sc_parent;
571
572	if (!(scd->sc_state & UHIDEV_OPEN))
573		return;
574	scd->sc_state &= ~UHIDEV_OPEN;
575	if (--sc->sc_refcnt)
576		return;
577	DPRINTF(("uhidev_close: close pipe\n"));
578
579	if (sc->sc_oxfer != NULL)
580		usbd_free_xfer(sc->sc_oxfer);
581
582	/* Disable interrupts. */
583	if (sc->sc_opipe != NULL) {
584		usbd_abort_pipe(sc->sc_opipe);
585		usbd_close_pipe(sc->sc_opipe);
586		sc->sc_opipe = NULL;
587	}
588
589	if (sc->sc_ipipe != NULL) {
590		usbd_abort_pipe(sc->sc_ipipe);
591		usbd_close_pipe(sc->sc_ipipe);
592		sc->sc_ipipe = NULL;
593	}
594
595	if (sc->sc_ibuf != NULL) {
596		free(sc->sc_ibuf, M_USBDEV);
597		sc->sc_ibuf = NULL;
598	}
599}
600
601usbd_status
602uhidev_set_report(struct uhidev *scd, int type, void *data, int len)
603{
604	char *buf;
605	usbd_status retstat;
606
607	if (scd->sc_report_id == 0)
608		return usbd_set_report(scd->sc_parent->sc_iface, type,
609				       scd->sc_report_id, data, len);
610
611	buf = malloc(len + 1, M_TEMP, M_WAITOK);
612	buf[0] = scd->sc_report_id;
613	memcpy(buf+1, data, len);
614
615	retstat = usbd_set_report(scd->sc_parent->sc_iface, type,
616				  scd->sc_report_id, buf, len + 1);
617
618	free(buf, M_TEMP);
619
620	return retstat;
621}
622
623void
624uhidev_set_report_async(struct uhidev *scd, int type, void *data, int len)
625{
626	/* XXX */
627	char buf[100];
628	if (scd->sc_report_id) {
629		buf[0] = scd->sc_report_id;
630		memcpy(buf+1, data, len);
631		len++;
632		data = buf;
633	}
634
635	usbd_set_report_async(scd->sc_parent->sc_iface, type,
636			      scd->sc_report_id, data, len);
637}
638
639usbd_status
640uhidev_get_report(struct uhidev *scd, int type, void *data, int len)
641{
642	return usbd_get_report(scd->sc_parent->sc_iface, type,
643			       scd->sc_report_id, data, len);
644}
645
646usbd_status
647uhidev_write(struct uhidev_softc *sc, void *data, int len)
648{
649
650	DPRINTF(("uhidev_write: data=%p, len=%d\n", data, len));
651
652	if (sc->sc_opipe == NULL)
653		return USBD_INVAL;
654
655#ifdef UHIDEV_DEBUG
656	if (uhidevdebug > 50) {
657
658		u_int32_t i;
659		u_int8_t *d = data;
660
661		DPRINTF(("uhidev_write: data ="));
662		for (i = 0; i < len; i++)
663			DPRINTF((" %02x", d[i]));
664		DPRINTF(("\n"));
665	}
666#endif
667	return usbd_intr_transfer(sc->sc_oxfer, sc->sc_opipe, 0,
668	    USBD_NO_TIMEOUT, data, &len, "uhidevwi");
669}
670