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