FreeBSD kernel usb device Code
usb_msctest.c
Go to the documentation of this file.
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 2008-2022 Hans Petter Selasky.
6 * Copyright (c) 2021-2022 Idwer Vollering.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/*
31 * The following file contains code that will detect USB autoinstall
32 * disks.
33 */
34
35#ifdef USB_GLOBAL_INCLUDE_FILE
36#include USB_GLOBAL_INCLUDE_FILE
37#else
38#include <sys/stdint.h>
39#include <sys/stddef.h>
40#include <sys/param.h>
41#include <sys/queue.h>
42#include <sys/types.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/bus.h>
46#include <sys/module.h>
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/condvar.h>
50#include <sys/sysctl.h>
51#include <sys/sx.h>
52#include <sys/unistd.h>
53#include <sys/callout.h>
54#include <sys/malloc.h>
55#include <sys/priv.h>
56
57#include <dev/usb/usb.h>
58#include <dev/usb/usbdi.h>
59#include <dev/usb/usbdi_util.h>
60
61#define USB_DEBUG_VAR usb_debug
62
63#include <dev/usb/usb_busdma.h>
64#include <dev/usb/usb_process.h>
66#include <dev/usb/usb_msctest.h>
67#include <dev/usb/usb_debug.h>
68#include <dev/usb/usb_device.h>
69#include <dev/usb/usb_request.h>
70#include <dev/usb/usb_util.h>
72#endif /* USB_GLOBAL_INCLUDE_FILE */
73
74enum {
82};
83
84enum {
88};
89
90#define SCSI_MAX_LEN MAX(SCSI_FIXED_BLOCK_SIZE, USB_MSCTEST_BULK_SIZE)
91#define SCSI_INQ_LEN 0x24
92#define SCSI_SENSE_LEN 0xFF
93#define SCSI_FIXED_BLOCK_SIZE 512 /* bytes */
94
95static uint8_t scsi_test_unit_ready[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
96static uint8_t scsi_inquiry[] = { 0x12, 0x00, 0x00, 0x00, SCSI_INQ_LEN, 0x00 };
97static uint8_t scsi_rezero_init[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
98static uint8_t scsi_start_unit[] = { 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00 };
99static uint8_t scsi_stop_unit[] = { 0x1b, 0x00, 0x00, 0x00, 0x02, 0x00 };
100static uint8_t scsi_ztestor_eject[] = { 0x85, 0x01, 0x01, 0x01, 0x18, 0x01,
101 0x01, 0x01, 0x01, 0x01, 0x00, 0x00 };
102static uint8_t scsi_cmotech_eject[] = { 0xff, 0x52, 0x44, 0x45, 0x56, 0x43,
103 0x48, 0x47 };
104static uint8_t scsi_huawei_eject[] = { 0x11, 0x06, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00 };
107static uint8_t scsi_huawei_eject2[] = { 0x11, 0x06, 0x20, 0x00, 0x00, 0x01,
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00 };
110static uint8_t scsi_tct_eject[] = { 0x06, 0xf5, 0x04, 0x02, 0x52, 0x70 };
111static uint8_t scsi_sync_cache[] = { 0x35, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00 };
113static uint8_t scsi_request_sense[] = { 0x03, 0x00, 0x00, 0x00, 0x12, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
115static uint8_t scsi_read_capacity[] = { 0x25, 0x00, 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00 };
117static uint8_t scsi_prevent_removal[] = { 0x1e, 0, 0, 0, 1, 0 };
118static uint8_t scsi_allow_removal[] = { 0x1e, 0, 0, 0, 0, 0 };
119
120#ifndef USB_MSCTEST_BULK_SIZE
121#define USB_MSCTEST_BULK_SIZE 64 /* dummy */
122#endif
123
124#define ERR_CSW_FAILED -1
125
126/* Command Block Wrapper */
127struct bbb_cbw {
129#define CBWSIGNATURE 0x43425355
133#define CBWFLAGS_OUT 0x00
134#define CBWFLAGS_IN 0x80
137#define CBWCDBLENGTH 16
140
141/* Command Status Wrapper */
142struct bbb_csw {
144#define CSWSIGNATURE 0x53425355
148#define CSWSTATUS_GOOD 0x0
149#define CSWSTATUS_FAILED 0x1
150#define CSWSTATUS_PHASE 0x2
151} __packed;
152
154 struct mtx mtx;
155 struct cv cv;
156 struct bbb_cbw *cbw;
157 struct bbb_csw *csw;
158
160
161 uint8_t *data_ptr;
162
163 usb_size_t data_len; /* bytes */
164 usb_size_t data_rem; /* bytes */
168
169 uint8_t cmd_len; /* bytes */
170 uint8_t dir;
171 uint8_t lun;
172 uint8_t state;
173 uint8_t status_try;
174 int error;
175
176 uint8_t *buffer;
177};
178
186
187static void bbb_done(struct bbb_transfer *, int);
188static void bbb_transfer_start(struct bbb_transfer *, uint8_t);
189static void bbb_data_clear_stall_callback(struct usb_xfer *, uint8_t,
190 uint8_t);
191static int bbb_command_start(struct bbb_transfer *, uint8_t, uint8_t,
192 void *, size_t, void *, size_t, usb_timeout_t);
193static struct bbb_transfer *bbb_attach(struct usb_device *, uint8_t, uint8_t);
194static void bbb_detach(struct bbb_transfer *);
195
196static const struct usb_config bbb_config[ST_MAX] = {
197 [ST_COMMAND] = {
198 .type = UE_BULK,
199 .endpoint = UE_ADDR_ANY,
200 .direction = UE_DIR_OUT,
201 .bufsize = sizeof(struct bbb_cbw),
202 .callback = &bbb_command_callback,
203 .timeout = 4 * USB_MS_HZ, /* 4 seconds */
204 },
205
206 [ST_DATA_RD] = {
207 .type = UE_BULK,
208 .endpoint = UE_ADDR_ANY,
209 .direction = UE_DIR_IN,
210 .bufsize = SCSI_MAX_LEN,
211 .flags = {.proxy_buffer = 1,.short_xfer_ok = 1,},
212 .callback = &bbb_data_read_callback,
213 .timeout = 4 * USB_MS_HZ, /* 4 seconds */
214 },
215
216 [ST_DATA_RD_CS] = {
217 .type = UE_CONTROL,
218 .endpoint = 0x00, /* Control pipe */
219 .direction = UE_DIR_ANY,
220 .bufsize = sizeof(struct usb_device_request),
221 .callback = &bbb_data_rd_cs_callback,
222 .timeout = 1 * USB_MS_HZ, /* 1 second */
223 },
224
225 [ST_DATA_WR] = {
226 .type = UE_BULK,
227 .endpoint = UE_ADDR_ANY,
228 .direction = UE_DIR_OUT,
229 .bufsize = SCSI_MAX_LEN,
230 .flags = {.ext_buffer = 1,.proxy_buffer = 1,},
231 .callback = &bbb_data_write_callback,
232 .timeout = 4 * USB_MS_HZ, /* 4 seconds */
233 },
234
235 [ST_DATA_WR_CS] = {
236 .type = UE_CONTROL,
237 .endpoint = 0x00, /* Control pipe */
238 .direction = UE_DIR_ANY,
239 .bufsize = sizeof(struct usb_device_request),
240 .callback = &bbb_data_wr_cs_callback,
241 .timeout = 1 * USB_MS_HZ, /* 1 second */
242 },
243
244 [ST_STATUS] = {
245 .type = UE_BULK,
246 .endpoint = UE_ADDR_ANY,
247 .direction = UE_DIR_IN,
248 .bufsize = sizeof(struct bbb_csw),
249 .flags = {.short_xfer_ok = 1,},
250 .callback = &bbb_status_callback,
251 .timeout = 1 * USB_MS_HZ, /* 1 second */
252 },
253};
254
255static const struct usb_config bbb_raw_config[1] = {
256 [0] = {
258 .endpoint = UE_ADDR_ANY,
259 .direction = UE_DIR_OUT,
260 .bufsize = SCSI_MAX_LEN,
261 .flags = {.ext_buffer = 1,.proxy_buffer = 1,},
262 .callback = &bbb_raw_write_callback,
263 .timeout = 1 * USB_MS_HZ, /* 1 second */
264 },
265};
266
267static void
269{
270 sc->error = error;
271 sc->state = ST_COMMAND;
272 sc->status_try = 1;
273 cv_signal(&sc->cv);
274}
275
276static void
277bbb_transfer_start(struct bbb_transfer *sc, uint8_t xfer_index)
278{
279 sc->state = xfer_index;
280 usbd_transfer_start(sc->xfer[xfer_index]);
281}
282
283static void
285 uint8_t next_xfer, uint8_t stall_xfer)
286{
287 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
288
289 if (usbd_clear_stall_callback(xfer, sc->xfer[stall_xfer])) {
290 switch (USB_GET_STATE(xfer)) {
291 case USB_ST_SETUP:
293 bbb_transfer_start(sc, next_xfer);
294 break;
295 default:
297 break;
298 }
299 }
300}
301
302static void
304{
305 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
306 uint32_t tag;
307
308 switch (USB_GET_STATE(xfer)) {
311 (sc, ((sc->dir == DIR_IN) ? ST_DATA_RD :
312 (sc->dir == DIR_OUT) ? ST_DATA_WR :
313 ST_STATUS));
314 break;
315
316 case USB_ST_SETUP:
317 sc->status_try = 0;
318 tag = UGETDW(sc->cbw->dCBWTag) + 1;
320 USETDW(sc->cbw->dCBWTag, tag);
321 USETDW(sc->cbw->dCBWDataTransferLength, (uint32_t)sc->data_len);
322 sc->cbw->bCBWFlags = ((sc->dir == DIR_IN) ? CBWFLAGS_IN : CBWFLAGS_OUT);
323 sc->cbw->bCBWLUN = sc->lun;
324 sc->cbw->bCDBLength = sc->cmd_len;
325 if (sc->cbw->bCDBLength > sizeof(sc->cbw->CBWCDB)) {
326 sc->cbw->bCDBLength = sizeof(sc->cbw->CBWCDB);
327 DPRINTFN(0, "Truncating long command\n");
328 }
330 sizeof(struct bbb_cbw));
332 break;
333
334 default: /* Error */
335 bbb_done(sc, error);
336 break;
337 }
338}
339
340static void
342{
343 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
345 int actlen, sumlen;
346
347 usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
348
349 switch (USB_GET_STATE(xfer)) {
351 sc->data_rem -= actlen;
352 sc->data_ptr += actlen;
353 sc->actlen += actlen;
354
355 if (actlen < sumlen) {
356 /* short transfer */
357 sc->data_rem = 0;
358 }
359 case USB_ST_SETUP:
360 DPRINTF("max_bulk=%d, data_rem=%d\n",
361 max_bulk, sc->data_rem);
362
363 if (sc->data_rem == 0) {
365 break;
366 }
367 if (max_bulk > sc->data_rem) {
368 max_bulk = sc->data_rem;
369 }
371 usbd_xfer_set_frame_data(xfer, 0, sc->data_ptr, max_bulk);
373 break;
374
375 default: /* Error */
376 if (error == USB_ERR_CANCELLED) {
377 bbb_done(sc, error);
378 } else {
380 }
381 break;
382 }
383}
384
385static void
387{
389 ST_DATA_RD);
390}
391
392static void
394{
395 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
397 int actlen, sumlen;
398
399 usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
400
401 switch (USB_GET_STATE(xfer)) {
403 sc->data_rem -= actlen;
404 sc->data_ptr += actlen;
405 sc->actlen += actlen;
406
407 if (actlen < sumlen) {
408 /* short transfer */
409 sc->data_rem = 0;
410 }
411 case USB_ST_SETUP:
412 DPRINTF("max_bulk=%d, data_rem=%d\n",
413 max_bulk, sc->data_rem);
414
415 if (sc->data_rem == 0) {
417 break;
418 }
419 if (max_bulk > sc->data_rem) {
420 max_bulk = sc->data_rem;
421 }
423 usbd_xfer_set_frame_data(xfer, 0, sc->data_ptr, max_bulk);
425 break;
426
427 default: /* Error */
428 if (error == USB_ERR_CANCELLED) {
429 bbb_done(sc, error);
430 } else {
432 }
433 break;
434 }
435}
436
437static void
439{
441 ST_DATA_WR);
442}
443
444static void
446{
447 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
448 int actlen;
449 int sumlen;
450
451 usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
452
453 switch (USB_GET_STATE(xfer)) {
455
456 /* very simple status check */
457
458 if (actlen < (int)sizeof(struct bbb_csw)) {
460 } else if (sc->csw->bCSWStatus == CSWSTATUS_GOOD) {
461 bbb_done(sc, 0); /* success */
462 } else {
463 bbb_done(sc, ERR_CSW_FAILED); /* error */
464 }
465 break;
466
467 case USB_ST_SETUP:
469 sizeof(struct bbb_csw));
471 break;
472
473 default:
474 DPRINTF("Failed to read CSW: %s, try %d\n",
476
477 if (error == USB_ERR_CANCELLED || sc->status_try) {
478 bbb_done(sc, error);
479 } else {
480 sc->status_try = 1;
482 }
483 break;
484 }
485}
486
487static void
489{
490 struct bbb_transfer *sc = usbd_xfer_softc(xfer);
492 int actlen, sumlen;
493
494 usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
495
496 switch (USB_GET_STATE(xfer)) {
498 sc->data_rem -= actlen;
499 sc->data_ptr += actlen;
500 sc->actlen += actlen;
501
502 if (actlen < sumlen) {
503 /* short transfer */
504 sc->data_rem = 0;
505 }
506 case USB_ST_SETUP:
507 DPRINTF("max_bulk=%d, data_rem=%d\n",
508 max_bulk, sc->data_rem);
509
510 if (sc->data_rem == 0) {
511 bbb_done(sc, 0);
512 break;
513 }
514 if (max_bulk > sc->data_rem) {
515 max_bulk = sc->data_rem;
516 }
518 usbd_xfer_set_frame_data(xfer, 0, sc->data_ptr, max_bulk);
520 break;
521
522 default: /* Error */
523 bbb_done(sc, error);
524 break;
525 }
526}
527
528/*------------------------------------------------------------------------*
529 * bbb_command_start - execute a SCSI command synchronously
530 *
531 * Return values
532 * 0: Success
533 * Else: Failure
534 *------------------------------------------------------------------------*/
535static int
536bbb_command_start(struct bbb_transfer *sc, uint8_t dir, uint8_t lun,
537 void *data_ptr, size_t data_len, void *cmd_ptr, size_t cmd_len,
539{
540 sc->lun = lun;
541 sc->dir = data_len ? dir : DIR_NONE;
542 sc->data_ptr = data_ptr;
543 sc->data_len = data_len;
544 sc->data_rem = data_len;
546 sc->actlen = 0;
547 sc->error = 0;
548 sc->cmd_len = cmd_len;
549 memset(&sc->cbw->CBWCDB, 0, sizeof(sc->cbw->CBWCDB));
550 memcpy(&sc->cbw->CBWCDB, cmd_ptr, cmd_len);
551 DPRINTFN(1, "SCSI cmd = %*D\n", (int)cmd_len, (char *)sc->cbw->CBWCDB, ":");
552
553 USB_MTX_LOCK(&sc->mtx);
555
556 while (usbd_transfer_pending(sc->xfer[sc->state])) {
557 cv_wait(&sc->cv, &sc->mtx);
558 }
559 USB_MTX_UNLOCK(&sc->mtx);
560 return (sc->error);
561}
562
563/*------------------------------------------------------------------------*
564 * bbb_raw_write - write a raw BULK message synchronously
565 *
566 * Return values
567 * 0: Success
568 * Else: Failure
569 *------------------------------------------------------------------------*/
570static int
571bbb_raw_write(struct bbb_transfer *sc, const void *data_ptr, size_t data_len,
573{
574 sc->data_ptr = __DECONST(void *, data_ptr);
575 sc->data_len = data_len;
576 sc->data_rem = data_len;
578 sc->actlen = 0;
579 sc->error = 0;
580
581 DPRINTFN(1, "BULK DATA = %*D\n", (int)data_len,
582 (const char *)data_ptr, ":");
583
584 USB_MTX_LOCK(&sc->mtx);
586 while (usbd_transfer_pending(sc->xfer[0]))
587 cv_wait(&sc->cv, &sc->mtx);
588 USB_MTX_UNLOCK(&sc->mtx);
589 return (sc->error);
590}
591
592static struct bbb_transfer *
593bbb_attach(struct usb_device *udev, uint8_t iface_index,
594 uint8_t bInterfaceClass)
595{
596 struct usb_interface *iface;
598 const struct usb_config *pconfig;
599 struct bbb_transfer *sc;
600 usb_error_t err;
601 int nconfig;
602
603#if USB_HAVE_MSCTEST_DETACH
604 uint8_t do_unlock;
605
606 /* Prevent re-enumeration */
607 do_unlock = usbd_enum_lock(udev);
608
609 /*
610 * Make sure any driver which is hooked up to this interface,
611 * like umass is gone:
612 */
613 usb_detach_device(udev, iface_index, 0);
614
615 if (do_unlock)
616 usbd_enum_unlock(udev);
617#endif
618
619 iface = usbd_get_iface(udev, iface_index);
620 if (iface == NULL)
621 return (NULL);
622
623 id = iface->idesc;
624 if (id == NULL || id->bInterfaceClass != bInterfaceClass)
625 return (NULL);
626
627 switch (id->bInterfaceClass) {
628 case UICLASS_MASS:
629 switch (id->bInterfaceSubClass) {
630 case UISUBCLASS_SCSI:
631 case UISUBCLASS_UFI:
634 break;
635 default:
636 return (NULL);
637 }
638 switch (id->bInterfaceProtocol) {
640 case UIPROTO_MASS_BBB:
641 break;
642 default:
643 return (NULL);
644 }
645 pconfig = bbb_config;
646 nconfig = ST_MAX;
647 break;
648 case UICLASS_HID:
649 switch (id->bInterfaceSubClass) {
650 case 0:
651 break;
652 default:
653 return (NULL);
654 }
655 pconfig = bbb_raw_config;
656 nconfig = 1;
657 break;
658 default:
659 return (NULL);
660 }
661
662 sc = malloc(sizeof(*sc), M_USB, M_WAITOK | M_ZERO);
663 mtx_init(&sc->mtx, "USB autoinstall", NULL, MTX_DEF);
664 cv_init(&sc->cv, "WBBB");
665
666 err = usbd_transfer_setup(udev, &iface_index, sc->xfer, pconfig,
667 nconfig, sc, &sc->mtx);
668 if (err) {
669 bbb_detach(sc);
670 return (NULL);
671 }
672 switch (id->bInterfaceClass) {
673 case UICLASS_MASS:
674 /* store pointer to DMA buffers */
676 sc->xfer[ST_DATA_RD], 0);
677 sc->buffer_size =
680 sc->xfer[ST_COMMAND], 0);
682 sc->xfer[ST_STATUS], 0);
683 break;
684 default:
685 break;
686 }
687 return (sc);
688}
689
690static void
692{
694 mtx_destroy(&sc->mtx);
695 cv_destroy(&sc->cv);
696 free(sc, M_USB);
697}
698
699/*------------------------------------------------------------------------*
700 * usb_iface_is_cdrom
701 *
702 * Return values:
703 * 1: This interface is an auto install disk (CD-ROM)
704 * 0: Not an auto install disk.
705 *------------------------------------------------------------------------*/
706int
707usb_iface_is_cdrom(struct usb_device *udev, uint8_t iface_index)
708{
709 struct bbb_transfer *sc;
710 uint8_t timeout;
711 uint8_t is_cdrom;
712 uint8_t sid_type;
713 int err;
714
715 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
716 if (sc == NULL)
717 return (0);
718
719 is_cdrom = 0;
720 timeout = 4; /* tries */
721 while (--timeout) {
722 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,
724 USB_MS_HZ);
725
726 if (err == 0 && sc->actlen > 0) {
727 sid_type = sc->buffer[0] & 0x1F;
728 if (sid_type == 0x05)
729 is_cdrom = 1;
730 break;
731 } else if (err != ERR_CSW_FAILED)
732 break; /* non retryable error */
733 usb_pause_mtx(NULL, hz);
734 }
735 bbb_detach(sc);
736 return (is_cdrom);
737}
738
739static uint8_t
740usb_msc_get_max_lun(struct usb_device *udev, uint8_t iface_index)
741{
742 struct usb_device_request req;
743 usb_error_t err;
744 uint8_t buf = 0;
745
746 /* The Get Max Lun command is a class-specific request. */
747 req.bmRequestType = UT_READ_CLASS_INTERFACE;
748 req.bRequest = 0xFE; /* GET_MAX_LUN */
749 USETW(req.wValue, 0);
750 req.wIndex[0] = iface_index;
751 req.wIndex[1] = 0;
752 USETW(req.wLength, 1);
753
754 err = usbd_do_request(udev, NULL, &req, &buf);
755 if (err)
756 buf = 0;
757
758 return (buf);
759}
760
761#define USB_ADD_QUIRK(udev, any, which) do { \
762 if (usb_get_manufacturer(udev) != NULL && usb_get_product(udev) != NULL) { \
763 DPRINTFN(0, #which " set for USB mass storage device %s %s (0x%04x:0x%04x)\n", \
764 usb_get_manufacturer(udev), \
765 usb_get_product(udev), \
766 UGETW(udev->ddesc.idVendor), \
767 UGETW(udev->ddesc.idProduct)); \
768 } else { \
769 DPRINTFN(0, #which " set for USB mass storage device, 0x%04x:0x%04x\n", \
770 UGETW(udev->ddesc.idVendor), \
771 UGETW(udev->ddesc.idProduct)); \
772 } \
773 usbd_add_dynamic_quirk(udev, which); \
774 any = 1; \
775} while (0)
776
778usb_msc_auto_quirk(struct usb_device *udev, uint8_t iface_index,
779 const struct usb_attach_arg *uaa)
780{
781 struct bbb_transfer *sc;
782 uint8_t timeout;
783 uint8_t is_no_direct;
784 uint8_t sid_type;
785 uint8_t any_quirk;
786 int err;
787
788 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
789 if (sc == NULL)
790 return (0);
791
792 any_quirk = 0;
793
794 /*
795 * Some devices need a delay after that the configuration
796 * value is set to function properly:
797 */
798 usb_pause_mtx(NULL, hz);
799
800 if (usb_test_quirk(uaa, UQ_MSC_NO_GETMAXLUN) == 0 &&
801 usb_msc_get_max_lun(udev, iface_index) == 0) {
802 DPRINTF("Device has only got one LUN.\n");
803 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_GETMAXLUN);
804 }
805
806 is_no_direct = 1;
807 for (timeout = 4; timeout != 0; timeout--) {
808 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,
810 USB_MS_HZ);
811
812 if (err == 0 && sc->actlen > 0) {
813 sid_type = sc->buffer[0] & 0x1F;
814 if (sid_type == 0x00)
815 is_no_direct = 0;
816 break;
817 } else if (err != ERR_CSW_FAILED) {
818 DPRINTF("Device is not responding "
819 "properly to SCSI INQUIRY command.\n");
820 goto error; /* non retryable error */
821 }
822 usb_pause_mtx(NULL, hz);
823 }
824
825 if (is_no_direct) {
826 DPRINTF("Device is not direct access.\n");
827 goto done;
828 }
829
831 err = bbb_command_start(sc, DIR_NONE, 0, NULL, 0,
833 USB_MS_HZ);
834
835 if (err != 0) {
836 if (err != ERR_CSW_FAILED)
837 goto error;
839 }
840 }
841
843 err = bbb_command_start(sc, DIR_NONE, 0, NULL, 0,
845 USB_MS_HZ);
846
847 if (err == 0) {
848 err = bbb_command_start(sc, DIR_NONE, 0, NULL, 0,
850 USB_MS_HZ);
851 }
852
853 if (err != 0) {
854 if (err != ERR_CSW_FAILED)
855 goto error;
856 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_PREVENT_ALLOW);
857 }
858 }
859
860 timeout = 1;
861
862retry_sync_cache:
863 err = bbb_command_start(sc, DIR_NONE, 0, NULL, 0,
865 USB_MS_HZ);
866
867 if (err != 0) {
868 if (err != ERR_CSW_FAILED)
869 goto error;
870
871 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_SYNC_CACHE);
872 } else {
873 /*
874 * Certain Kingston memory sticks fail the first
875 * read capacity after a synchronize cache command
876 * has been issued. Disable the synchronize cache
877 * command for such devices.
878 */
879
880 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer, 8,
882 USB_MS_HZ);
883
884 if (err != 0) {
885 if (err != ERR_CSW_FAILED)
886 goto error;
887
888 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer, 8,
890 USB_MS_HZ);
891
892 if (err == 0) {
893 if (timeout--)
894 goto retry_sync_cache;
895
896 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_SYNC_CACHE);
897 } else {
898 if (err != ERR_CSW_FAILED)
899 goto error;
900 }
901 }
902 }
903
904 if (usb_test_quirk(uaa, UQ_MSC_NO_START_STOP) == 0) {
905 err = bbb_command_start(sc, DIR_NONE, 0, NULL, 0,
907 USB_MS_HZ);
908
909 if (err != 0) {
910 if (err != ERR_CSW_FAILED)
911 goto error;
912 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_START_STOP);
913 }
914 }
915
916 /* clear sense status of any failed commands on the device */
917
918 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,
920 USB_MS_HZ);
921
922 DPRINTF("Inquiry = %d\n", err);
923
924 if (err != 0) {
925 if (err != ERR_CSW_FAILED)
926 goto error;
927 }
928
929 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,
932
933 DPRINTF("Request sense = %d\n", err);
934
935 if (err != 0) {
936 if (err != ERR_CSW_FAILED)
937 goto error;
938 }
939 goto done;
940
941error:
942 /* Apply most quirks */
943 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_SYNC_CACHE);
944 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_PREVENT_ALLOW);
946 USB_ADD_QUIRK(udev, any_quirk, UQ_MSC_NO_START_STOP);
947done:
948 bbb_detach(sc);
949
950 if (any_quirk) {
951 /* Unconfigure device, to clear software data toggle. */
953
954 /* Need to re-enumerate the device to clear its state. */
955 usbd_req_re_enumerate(udev, NULL);
956 return (USB_ERR_STALLED);
957 }
958
959 /* No quirks were added, continue as usual. */
960 return (0);
961}
962
964usb_msc_eject(struct usb_device *udev, uint8_t iface_index, int method)
965{
966 struct bbb_transfer *sc;
967 usb_error_t err;
968
969 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
970 if (sc == NULL)
971 return (USB_ERR_INVAL);
972
973 switch (method) {
975 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
977 USB_MS_HZ);
978 DPRINTF("Test unit ready status: %s\n", usbd_errstr(err));
979 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
981 USB_MS_HZ);
982 break;
983 case MSC_EJECT_REZERO:
984 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
986 USB_MS_HZ);
987 break;
989 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
991 USB_MS_HZ);
992 break;
994 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
996 USB_MS_HZ);
997 break;
998 case MSC_EJECT_HUAWEI:
999 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
1001 USB_MS_HZ);
1002 break;
1003 case MSC_EJECT_HUAWEI2:
1004 err = bbb_command_start(sc, DIR_IN, 0, NULL, 0,
1006 USB_MS_HZ);
1007 break;
1008 case MSC_EJECT_TCT:
1009 /*
1010 * TCTMobile needs DIR_IN flag. To get it, we
1011 * supply a dummy data with the command.
1012 */
1013 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,
1015 sizeof(scsi_tct_eject), USB_MS_HZ);
1016 break;
1017 default:
1018 DPRINTF("Unknown eject method (%d)\n", method);
1019 bbb_detach(sc);
1020 return (USB_ERR_INVAL);
1021 }
1022
1023 DPRINTF("Eject CD command status: %s\n", usbd_errstr(err));
1024
1025 bbb_detach(sc);
1026 return (0);
1027}
1028
1030usb_dymo_eject(struct usb_device *udev, uint8_t iface_index)
1031{
1032 static const uint8_t data[3] = { 0x1b, 0x5a, 0x01 };
1033 struct bbb_transfer *sc;
1034 usb_error_t err;
1035
1036 sc = bbb_attach(udev, iface_index, UICLASS_HID);
1037 if (sc == NULL)
1038 return (USB_ERR_INVAL);
1039 err = bbb_raw_write(sc, data, sizeof(data), USB_MS_HZ);
1040 bbb_detach(sc);
1041 return (err);
1042}
1043
1045usb_msc_read_10(struct usb_device *udev, uint8_t iface_index,
1046 uint32_t lba, uint32_t blocks, void *buffer)
1047{
1048 struct bbb_transfer *sc;
1049 uint8_t cmd[10];
1050 usb_error_t err;
1051
1052 cmd[0] = 0x28; /* READ_10 */
1053 cmd[1] = 0;
1054 cmd[2] = lba >> 24;
1055 cmd[3] = lba >> 16;
1056 cmd[4] = lba >> 8;
1057 cmd[5] = lba >> 0;
1058 cmd[6] = 0;
1059 cmd[7] = blocks >> 8;
1060 cmd[8] = blocks;
1061 cmd[9] = 0;
1062
1063 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
1064 if (sc == NULL)
1065 return (USB_ERR_INVAL);
1066
1067 err = bbb_command_start(sc, DIR_IN, 0, buffer,
1068 blocks * SCSI_FIXED_BLOCK_SIZE, cmd, 10, USB_MS_HZ);
1069
1070 bbb_detach(sc);
1071
1072 return (err);
1073}
1074
1076usb_msc_write_10(struct usb_device *udev, uint8_t iface_index,
1077 uint32_t lba, uint32_t blocks, void *buffer)
1078{
1079 struct bbb_transfer *sc;
1080 uint8_t cmd[10];
1081 usb_error_t err;
1082
1083 cmd[0] = 0x2a; /* WRITE_10 */
1084 cmd[1] = 0;
1085 cmd[2] = lba >> 24;
1086 cmd[3] = lba >> 16;
1087 cmd[4] = lba >> 8;
1088 cmd[5] = lba >> 0;
1089 cmd[6] = 0;
1090 cmd[7] = blocks >> 8;
1091 cmd[8] = blocks;
1092 cmd[9] = 0;
1093
1094 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
1095 if (sc == NULL)
1096 return (USB_ERR_INVAL);
1097
1098 err = bbb_command_start(sc, DIR_OUT, 0, buffer,
1099 blocks * SCSI_FIXED_BLOCK_SIZE, cmd, 10, USB_MS_HZ);
1100
1101 bbb_detach(sc);
1102
1103 return (err);
1104}
1105
1107usb_msc_read_capacity(struct usb_device *udev, uint8_t iface_index,
1108 uint32_t *lba_last, uint32_t *block_size)
1109{
1110 struct bbb_transfer *sc;
1111 usb_error_t err;
1112
1113 sc = bbb_attach(udev, iface_index, UICLASS_MASS);
1114 if (sc == NULL)
1115 return (USB_ERR_INVAL);
1116
1117 err = bbb_command_start(sc, DIR_IN, 0, sc->buffer, 8,
1119 USB_MS_HZ);
1120
1121 *lba_last =
1122 (sc->buffer[0] << 24) |
1123 (sc->buffer[1] << 16) |
1124 (sc->buffer[2] << 8) |
1125 (sc->buffer[3]);
1126
1127 *block_size =
1128 (sc->buffer[4] << 24) |
1129 (sc->buffer[5] << 16) |
1130 (sc->buffer[6] << 8) |
1131 (sc->buffer[7]);
1132
1133 /* we currently only support one block size */
1134 if (*block_size != SCSI_FIXED_BLOCK_SIZE)
1135 err = USB_ERR_INVAL;
1136
1137 bbb_detach(sc);
1138
1139 return (err);
1140}
struct @109 error
uint8_t id
Definition: if_usievar.h:4
uint16_t data
uByte CBWCDB[CBWCDBLENGTH]
Definition: usb_msctest.c:138
uDWord dCBWSignature
Definition: usb_msctest.c:128
uDWord dCBWTag
Definition: usb_msctest.c:130
uDWord dCBWDataTransferLength
Definition: usb_msctest.c:131
uByte bCBWFlags
Definition: usb_msctest.c:132
uByte bCBWLUN
Definition: usb_msctest.c:135
uByte bCDBLength
Definition: usb_msctest.c:136
uDWord dCSWDataResidue
Definition: usb_msctest.c:146
uDWord dCSWTag
Definition: usb_msctest.c:145
uByte bCSWStatus
Definition: usb_msctest.c:147
uDWord dCSWSignature
Definition: usb_msctest.c:143
usb_frlength_t actlen
Definition: usb_msctest.c:166
uint8_t status_try
Definition: usb_msctest.c:173
struct bbb_cbw * cbw
Definition: usb_msctest.c:156
struct mtx mtx
Definition: usb_msctest.c:154
usb_size_t data_rem
Definition: usb_msctest.c:164
uint8_t * data_ptr
Definition: usb_msctest.c:161
usb_timeout_t data_timeout
Definition: usb_msctest.c:165
uint8_t lun
Definition: usb_msctest.c:171
usb_size_t data_len
Definition: usb_msctest.c:163
uint8_t cmd_len
Definition: usb_msctest.c:169
uint8_t * buffer
Definition: usb_msctest.c:176
struct bbb_csw * csw
Definition: usb_msctest.c:157
struct cv cv
Definition: usb_msctest.c:155
uint8_t dir
Definition: usb_msctest.c:170
usb_frlength_t buffer_size
Definition: usb_msctest.c:167
struct usb_xfer * xfer[ST_MAX]
Definition: usb_msctest.c:159
uint8_t state
Definition: usb_msctest.c:172
uint8_t type
Definition: usbdi.h:238
struct usb_interface_descriptor * idesc
Definition: usbdi.h:175
#define DPRINTF(...)
Definition: umass.c:179
#define UE_DIR_ANY
Definition: usb.h:535
#define UIPROTO_MASS_BBB
Definition: usb.h:477
#define UE_ADDR_ANY
Definition: usb.h:537
#define UE_BULK
Definition: usb.h:543
#define UE_BULK_INTR
Definition: usb.h:545
#define UISUBCLASS_SCSI
Definition: usb.h:473
#define UT_READ_CLASS_INTERFACE
Definition: usb.h:173
#define USB_UNCONFIG_INDEX
Definition: usb.h:75
#define UISUBCLASS_SFF8070I
Definition: usb.h:472
#define UE_DIR_IN
Definition: usb.h:531
#define UICLASS_HID
Definition: usb.h:453
#define UE_DIR_OUT
Definition: usb.h:532
#define UISUBCLASS_SFF8020I
Definition: usb.h:469
#define UISUBCLASS_UFI
Definition: usb.h:471
#define UE_CONTROL
Definition: usb.h:541
#define UICLASS_MASS
Definition: usb.h:467
#define UIPROTO_MASS_BBB_OLD
Definition: usb.h:476
uint8_t usbd_enum_lock(struct usb_device *udev)
Definition: usb_device.c:2896
usb_error_t usbd_set_config_index(struct usb_device *udev, uint8_t index)
Definition: usb_device.c:672
void usbd_enum_unlock(struct usb_device *udev)
Definition: usb_device.c:2936
void usb_detach_device(struct usb_device *udev, uint8_t iface_index, uint8_t flag)
Definition: usb_device.c:1264
struct usb_interface * usbd_get_iface(struct usb_device *udev, uint8_t iface_index)
Definition: usb_device.c:2370
uint8_t uByte
Definition: usb_endian.h:41
#define USETW(w, v)
Definition: usb_endian.h:77
#define USETDW(w, v)
Definition: usb_endian.h:82
#define UGETDW(w)
Definition: usb_endian.h:57
uint8_t uDWord[4]
Definition: usb_endian.h:43
const char * usbd_errstr(usb_error_t err)
Definition: usb_error.c:93
uint32_t usb_frlength_t
Definition: usb_freebsd.h:100
uint32_t usb_timeout_t
Definition: usb_freebsd.h:99
uint32_t usb_size_t
Definition: usb_freebsd.h:102
const void * req
Definition: usb_if.m:51
static uint8_t scsi_sync_cache[]
Definition: usb_msctest.c:111
static void bbb_done(struct bbb_transfer *, int)
Definition: usb_msctest.c:268
int usb_iface_is_cdrom(struct usb_device *udev, uint8_t iface_index)
Definition: usb_msctest.c:707
#define USB_ADD_QUIRK(udev, any, which)
Definition: usb_msctest.c:761
#define CSWSTATUS_GOOD
Definition: usb_msctest.c:148
usb_error_t usb_dymo_eject(struct usb_device *udev, uint8_t iface_index)
Definition: usb_msctest.c:1030
#define CBWSIGNATURE
Definition: usb_msctest.c:129
static uint8_t scsi_read_capacity[]
Definition: usb_msctest.c:115
#define SCSI_SENSE_LEN
Definition: usb_msctest.c:92
#define CBWCDBLENGTH
Definition: usb_msctest.c:137
static uint8_t scsi_prevent_removal[]
Definition: usb_msctest.c:117
static uint8_t scsi_cmotech_eject[]
Definition: usb_msctest.c:102
static uint8_t scsi_rezero_init[]
Definition: usb_msctest.c:97
#define SCSI_INQ_LEN
Definition: usb_msctest.c:91
static uint8_t scsi_stop_unit[]
Definition: usb_msctest.c:99
static void bbb_data_clear_stall_callback(struct usb_xfer *, uint8_t, uint8_t)
Definition: usb_msctest.c:284
static usb_callback_t bbb_raw_write_callback
Definition: usb_msctest.c:185
static uint8_t scsi_start_unit[]
Definition: usb_msctest.c:98
static uint8_t scsi_huawei_eject[]
Definition: usb_msctest.c:104
@ ST_MAX
Definition: usb_msctest.c:81
@ ST_DATA_RD_CS
Definition: usb_msctest.c:77
@ ST_DATA_WR
Definition: usb_msctest.c:78
@ ST_DATA_WR_CS
Definition: usb_msctest.c:79
@ ST_DATA_RD
Definition: usb_msctest.c:76
@ ST_STATUS
Definition: usb_msctest.c:80
@ ST_COMMAND
Definition: usb_msctest.c:75
struct bbb_cbw __packed
static uint8_t scsi_huawei_eject2[]
Definition: usb_msctest.c:107
static uint8_t scsi_allow_removal[]
Definition: usb_msctest.c:118
static usb_callback_t bbb_command_callback
Definition: usb_msctest.c:179
static const struct usb_config bbb_config[ST_MAX]
Definition: usb_msctest.c:196
static void bbb_detach(struct bbb_transfer *)
Definition: usb_msctest.c:691
static int bbb_raw_write(struct bbb_transfer *sc, const void *data_ptr, size_t data_len, usb_timeout_t data_timeout)
Definition: usb_msctest.c:571
static int bbb_command_start(struct bbb_transfer *, uint8_t, uint8_t, void *, size_t, void *, size_t, usb_timeout_t)
Definition: usb_msctest.c:536
static uint8_t scsi_tct_eject[]
Definition: usb_msctest.c:110
static usb_callback_t bbb_data_rd_cs_callback
Definition: usb_msctest.c:181
static const struct usb_config bbb_raw_config[1]
Definition: usb_msctest.c:255
static uint8_t scsi_test_unit_ready[]
Definition: usb_msctest.c:95
static struct bbb_transfer * bbb_attach(struct usb_device *, uint8_t, uint8_t)
Definition: usb_msctest.c:593
static uint8_t scsi_ztestor_eject[]
Definition: usb_msctest.c:100
@ DIR_NONE
Definition: usb_msctest.c:87
@ DIR_IN
Definition: usb_msctest.c:85
@ DIR_OUT
Definition: usb_msctest.c:86
usb_error_t usb_msc_write_10(struct usb_device *udev, uint8_t iface_index, uint32_t lba, uint32_t blocks, void *buffer)
Definition: usb_msctest.c:1076
static usb_callback_t bbb_status_callback
Definition: usb_msctest.c:184
#define ERR_CSW_FAILED
Definition: usb_msctest.c:124
usb_error_t usb_msc_eject(struct usb_device *udev, uint8_t iface_index, int method)
Definition: usb_msctest.c:964
#define SCSI_FIXED_BLOCK_SIZE
Definition: usb_msctest.c:93
usb_error_t usb_msc_read_10(struct usb_device *udev, uint8_t iface_index, uint32_t lba, uint32_t blocks, void *buffer)
Definition: usb_msctest.c:1045
static usb_callback_t bbb_data_write_callback
Definition: usb_msctest.c:182
#define SCSI_MAX_LEN
Definition: usb_msctest.c:90
static uint8_t scsi_inquiry[]
Definition: usb_msctest.c:96
#define CBWFLAGS_OUT
Definition: usb_msctest.c:133
static usb_callback_t bbb_data_read_callback
Definition: usb_msctest.c:180
static void bbb_transfer_start(struct bbb_transfer *, uint8_t)
Definition: usb_msctest.c:277
static usb_callback_t bbb_data_wr_cs_callback
Definition: usb_msctest.c:183
static uint8_t scsi_request_sense[]
Definition: usb_msctest.c:113
#define CBWFLAGS_IN
Definition: usb_msctest.c:134
static uint8_t usb_msc_get_max_lun(struct usb_device *udev, uint8_t iface_index)
Definition: usb_msctest.c:740
usb_error_t usb_msc_read_capacity(struct usb_device *udev, uint8_t iface_index, uint32_t *lba_last, uint32_t *block_size)
Definition: usb_msctest.c:1107
usb_error_t usb_msc_auto_quirk(struct usb_device *udev, uint8_t iface_index, const struct usb_attach_arg *uaa)
Definition: usb_msctest.c:778
@ MSC_EJECT_HUAWEI
Definition: usb_msctest.h:37
@ MSC_EJECT_TCT
Definition: usb_msctest.h:39
@ MSC_EJECT_ZTESTOR
Definition: usb_msctest.h:35
@ MSC_EJECT_HUAWEI2
Definition: usb_msctest.h:38
@ MSC_EJECT_REZERO
Definition: usb_msctest.h:34
@ MSC_EJECT_STOPUNIT
Definition: usb_msctest.h:33
@ MSC_EJECT_CMOTECH
Definition: usb_msctest.h:36
@ UQ_MSC_NO_TEST_UNIT_READY
Definition: usb_quirk.h:73
@ UQ_MSC_NO_START_STOP
Definition: usb_quirk.h:75
@ UQ_MSC_NO_PREVENT_ALLOW
Definition: usb_quirk.h:79
@ UQ_MSC_NO_GETMAXLUN
Definition: usb_quirk.h:76
@ UQ_MSC_NO_SYNC_CACHE
Definition: usb_quirk.h:80
uint8_t usb_test_quirk(const struct usb_attach_arg *uaa, uint16_t quirk)
Definition: usb_device.c:2631
usb_error_t usbd_req_re_enumerate(struct usb_device *udev, struct mtx *mtx)
Definition: usb_request.c:2054
void usbd_xfer_set_timeout(struct usb_xfer *xfer, int t)
void usbd_transfer_submit(struct usb_xfer *xfer)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, void *ptr, usb_frlength_t len)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, struct usb_xfer *xfer2)
void * usbd_xfer_get_frame_buffer(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
Definition: usb_transfer.c:987
void usbd_transfer_start(struct usb_xfer *xfer)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
uint8_t usbd_transfer_pending(struct usb_xfer *xfer)
void usb_pause_mtx(struct mtx *mtx, int timo)
Definition: usb_util.c:135
#define USB_MS_HZ
Definition: usbdi.h:118
#define USB_MTX_UNLOCK(_m)
Definition: usbdi.h:458
#define USB_MTX_LOCK(_m)
Definition: usbdi.h:453
#define USB_ST_SETUP
Definition: usbdi.h:502
usb_error_t
Definition: usbdi.h:45
@ USB_ERR_SHORT_XFER
Definition: usbdi.h:67
@ USB_ERR_STALLED
Definition: usbdi.h:68
@ USB_ERR_CANCELLED
Definition: usbdi.h:51
@ USB_ERR_INVAL
Definition: usbdi.h:49
#define USB_ST_TRANSFERRED
Definition: usbdi.h:503
void() usb_callback_t(struct usb_xfer *, usb_error_t)
Definition: usbdi.h:94
#define USB_GET_STATE(xfer)
Definition: usbdi.h:515
#define usbd_do_request(u, m, r, d)
Definition: usbdi.h:596
uint8_t bInterfaceClass
Definition: usbdi.h:45