Home | History | Annotate | Line # | Download | only in usb
usb.h revision 1.106.4.1
      1 /*	$NetBSD: usb.h,v 1.106.4.1 2014/08/13 21:50:39 riz Exp $	*/
      2 /*	$FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 1998 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 (at) 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  *
     21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 
     35 #ifndef _USB_H_
     36 #define _USB_H_
     37 
     38 #include <sys/types.h>
     39 #include <sys/time.h>
     40 
     41 #include <sys/ioctl.h>
     42 
     43 #if defined(_KERNEL_OPT)
     44 #include "opt_usb.h"	/* for USB_DEBUG */
     45 #endif
     46 
     47 #if defined(_KERNEL)
     48 #include <sys/mallocvar.h>
     49 
     50 MALLOC_DECLARE(M_USB);
     51 MALLOC_DECLARE(M_USBDEV);
     52 MALLOC_DECLARE(M_USBHC);
     53 
     54 #include <sys/device.h>
     55 
     56 #endif
     57 
     58 #ifdef USB_DEBUG
     59 #define ATU_DEBUG 1
     60 #define AUE_DEBUG 1
     61 #define AUVITEK_I2C_DEBUG 1
     62 #define AXE_DEBUG 1
     63 #define CUE_DEBUG 1
     64 #define DWC2_DEBUG 1
     65 #define EHCI_DEBUG 1
     66 #define EZLOAD_DEBUG 1
     67 #define KUE_DEBUG 1
     68 #define OHCI_DEBUG 1
     69 #define OTUS_DEBUG 1
     70 #define RUM_DEBUG 1
     71 #define RUN_DEBUG 1
     72 #define UARK_DEBUG 1
     73 #define UATP_DEBUG 1
     74 #define UAUDIO_DEBUG 1
     75 #define UBERRY_DEBUG 1
     76 #define UBSA_DEBUG 1
     77 #define UBT_DEBUG 1
     78 #define UCHCOM_DEBUG 1
     79 #define UCOM_DEBUG 1
     80 #define UCYCOM_DEBUG 1
     81 #define UDAV_DEBUG 1
     82 #define UDL_DEBUG 1
     83 #define UDSBR_DEBUG 1
     84 #define UFTDI_DEBUG 1
     85 #define UGENSA_DEBUG 1
     86 #define UGEN_DEBUG 1
     87 #define UHCI_DEBUG 1
     88 #define UHIDEV_DEBUG 1
     89 #define UHID_DEBUG 1
     90 #define UHMODEM_DEBUG 1
     91 #define UHSO_DEBUG 1
     92 #define UHUB_DEBUG 1
     93 #define UIPAD_DEBUG 1
     94 #define UIPAQ_DEBUG 1
     95 #define UIRDA_DEBUG 1
     96 #define UISDATA_DEBUG 1
     97 #define UKBD_DEBUG 1
     98 #define UKYOPON_DEBUG 1
     99 #define ULPT_DEBUG 1
    100 #define UMASS_DEBUG 1
    101 #define UMCT_DEBUG 1
    102 #define UMIDIQUIRK_DEBUG 1
    103 #define UMIDI_DEBUG 1
    104 #define UMODEM_DEBUG 1
    105 #define UMS_DEBUG 1
    106 #define UPGT_DEBUG 1
    107 #define UPLCOM_DEBUG 1
    108 #define UPL_DEBUG 1
    109 #define URAL_DEBUG 1
    110 #define URIO_DEBUG 1
    111 #define URL_DEBUG 1
    112 #define URNDIS_DEBUG 1
    113 #define URTWN_DEBUG 1
    114 #define URTW_DEBUG 1
    115 #define USB_DEBUG 1
    116 #define USCANNER_DEBUG 1
    117 #define USLSA_DEBUG 1
    118 #define USSCANNER_DEBUG 1
    119 #define USTIR_DEBUG 1
    120 #define UTHUM_DEBUG 1
    121 #define UTOPPY_DEBUG 1
    122 #define UTS_DEBUG 1
    123 #define UVIDEO_DEBUG 1
    124 #define UVISOR_DEBUG 1
    125 #define UVSCOM_DEBUG 1
    126 #define UYUREX_DEBUG 1
    127 #define UZCOM_DEBUG 1
    128 #define XHCI_DEBUG 1
    129 #define ZYD_DEBUG 1
    130 #define Static
    131 #else
    132 #define Static static
    133 #endif
    134 
    135 #define USB_STACK_VERSION 2
    136 
    137 #define USB_MAX_DEVICES 128
    138 #define USB_MIN_DEVICES 2               /* unused + root HUB */
    139 #define USB_START_ADDR 0
    140 
    141 #define USB_CONTROL_ENDPOINT 0
    142 #define USB_MAX_ENDPOINTS 16
    143 
    144 #define USB_FRAMES_PER_SECOND 1000
    145 #define USB_UFRAMES_PER_FRAME 8
    146 
    147 /*
    148  * The USB records contain some unaligned little-endian word
    149  * components.  The U[SG]ETW macros take care of both the alignment
    150  * and endian problem and should always be used to access non-byte
    151  * values.
    152  */
    153 typedef u_int8_t uByte;
    154 typedef u_int8_t uWord[2];
    155 typedef u_int8_t uDWord[4];
    156 
    157 #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
    158 
    159 #if 1
    160 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
    161 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
    162 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
    163 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
    164 		     (w)[1] = (u_int8_t)((v) >> 8), \
    165 		     (w)[2] = (u_int8_t)((v) >> 16), \
    166 		     (w)[3] = (u_int8_t)((v) >> 24))
    167 #else
    168 /*
    169  * On little-endian machines that can handle unaligned accesses
    170  * (e.g. i386) these macros can be replaced by the following.
    171  */
    172 #define UGETW(w) (*(u_int16_t *)(w))
    173 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
    174 #define UGETDW(w) (*(u_int32_t *)(w))
    175 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
    176 #endif
    177 
    178 #define UPACKED __packed
    179 
    180 typedef struct {
    181 	uByte		bmRequestType;
    182 	uByte		bRequest;
    183 	uWord		wValue;
    184 	uWord		wIndex;
    185 	uWord		wLength;
    186 } UPACKED usb_device_request_t;
    187 
    188 #define UT_GET_DIR(a) ((a) & 0x80)
    189 #define UT_WRITE		0x00
    190 #define UT_READ			0x80
    191 
    192 #define UT_GET_TYPE(a) ((a) & 0x60)
    193 #define UT_STANDARD		0x00
    194 #define UT_CLASS		0x20
    195 #define UT_VENDOR		0x40
    196 
    197 #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
    198 #define UT_DEVICE		0x00
    199 #define UT_INTERFACE		0x01
    200 #define UT_ENDPOINT		0x02
    201 #define UT_OTHER		0x03
    202 
    203 #define UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
    204 #define UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
    205 #define UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
    206 #define UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
    207 #define UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
    208 #define UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
    209 #define UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
    210 #define UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
    211 #define UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
    212 #define UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
    213 #define UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
    214 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
    215 #define UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
    216 #define UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
    217 #define UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
    218 #define UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
    219 #define UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
    220 #define UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
    221 #define UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
    222 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
    223 #define UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
    224 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
    225 
    226 /* Standard Requests Codes from the USB 2.0 spec, table 9-4 */
    227 #define UR_GET_STATUS		0x00
    228 #define UR_CLEAR_FEATURE	0x01
    229 #define UR_SET_FEATURE		0x03
    230 #define UR_SET_ADDRESS		0x05
    231 #define UR_GET_DESCRIPTOR	0x06
    232 #define  UDESC_DEVICE		0x01
    233 #define  UDESC_CONFIG		0x02
    234 #define  UDESC_STRING		0x03
    235 #define  UDESC_INTERFACE	0x04
    236 #define  UDESC_ENDPOINT		0x05
    237 #define  UDESC_DEVICE_QUALIFIER	0x06
    238 #define  UDESC_OTHER_SPEED_CONFIGURATION 0x07
    239 #define  UDESC_INTERFACE_POWER	0x08
    240 #define  UDESC_OTG		0x09
    241 #define  UDESC_DEBUG		0x0a
    242 #define  UDESC_INTERFACE_ASSOC	0x0b
    243 #define  UDESC_CS_DEVICE	0x21	/* class specific */
    244 #define  UDESC_CS_CONFIG	0x22
    245 #define  UDESC_CS_STRING	0x23
    246 #define  UDESC_CS_INTERFACE	0x24
    247 #define  UDESC_CS_ENDPOINT	0x25
    248 #define  UDESC_HUB		0x29
    249 #define  UDESC_SSHUB		0x2a
    250 #define UR_SET_DESCRIPTOR	0x07
    251 #define UR_GET_CONFIG		0x08
    252 #define UR_SET_CONFIG		0x09
    253 #define UR_GET_INTERFACE	0x0a
    254 #define UR_SET_INTERFACE	0x0b
    255 #define UR_SYNCH_FRAME		0x0c
    256 
    257 /*
    258  * Feature selectors. USB 2.0 spec, table 9-6 and OTG and EH suppliment,
    259  * table 6-2
    260  */
    261 #define UF_ENDPOINT_HALT	0
    262 #define UF_DEVICE_REMOTE_WAKEUP	1
    263 #define UF_TEST_MODE		2
    264 #define UF_DEVICE_B_HNP_ENABLE	3
    265 #define UF_DEVICE_A_HNP_SUPPORT	4
    266 #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
    267 
    268 #define USB_MAX_IPACKET		8 /* maximum size of the initial packet */
    269 
    270 #define USB_2_MAX_CTRL_PACKET	64
    271 #define USB_2_MAX_BULK_PACKET	512
    272 
    273 #define USB_3_MAX_CTRL_PACKET	512
    274 
    275 typedef struct {
    276 	uByte		bLength;
    277 	uByte		bDescriptorType;
    278 } UPACKED usb_descriptor_t;
    279 
    280 typedef struct {
    281 	uByte		bLength;
    282 	uByte		bDescriptorType;
    283 	uWord		bcdUSB;
    284 #define UD_USB_2_0		0x0200
    285 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
    286 	uByte		bDeviceClass;
    287 	uByte		bDeviceSubClass;
    288 	uByte		bDeviceProtocol;
    289 	uByte		bMaxPacketSize;
    290 	/* The fields below are not part of the initial descriptor. */
    291 	uWord		idVendor;
    292 	uWord		idProduct;
    293 	uWord		bcdDevice;
    294 	uByte		iManufacturer;
    295 	uByte		iProduct;
    296 	uByte		iSerialNumber;
    297 	uByte		bNumConfigurations;
    298 } UPACKED usb_device_descriptor_t;
    299 #define USB_DEVICE_DESCRIPTOR_SIZE 18
    300 
    301 typedef struct {
    302 	uByte		bLength;
    303 	uByte		bDescriptorType;
    304 	uWord		wTotalLength;
    305 	uByte		bNumInterface;
    306 	uByte		bConfigurationValue;
    307 	uByte		iConfiguration;
    308 	uByte		bmAttributes;
    309 #define UC_ATTR_MBO		0x80
    310 #define UC_SELF_POWERED		0x40
    311 #define UC_REMOTE_WAKEUP	0x20
    312 	uByte		bMaxPower; /* max current in 2 mA units */
    313 #define UC_POWER_FACTOR 2
    314 } UPACKED usb_config_descriptor_t;
    315 #define USB_CONFIG_DESCRIPTOR_SIZE 9
    316 
    317 typedef struct {
    318 	uByte		bLength;
    319 	uByte		bDescriptorType;
    320 	uByte		bInterfaceNumber;
    321 	uByte		bAlternateSetting;
    322 	uByte		bNumEndpoints;
    323 	uByte		bInterfaceClass;
    324 	uByte		bInterfaceSubClass;
    325 	uByte		bInterfaceProtocol;
    326 	uByte		iInterface;
    327 } UPACKED usb_interface_descriptor_t;
    328 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
    329 
    330 typedef struct {
    331 	uByte		bLength;
    332 	uByte		bDescriptorType;
    333 	uByte		bFirstInterface;
    334 	uByte		bInterfaceCount;
    335 	uByte		bFunctionClass;
    336 	uByte		bFunctionSubClass;
    337 	uByte		bFunctionProtocol;
    338 	uByte		iFunction;
    339 } UPACKED usb_interface_assoc_descriptor_t;
    340 #define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
    341 
    342 typedef struct {
    343 	uByte		bLength;
    344 	uByte		bDescriptorType;
    345 	uByte		bEndpointAddress;
    346 #define UE_GET_DIR(a)	((a) & 0x80)
    347 #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
    348 #define UE_DIR_IN	0x80
    349 #define UE_DIR_OUT	0x00
    350 #define UE_ADDR		0x0f
    351 #define UE_GET_ADDR(a)	((a) & UE_ADDR)
    352 	uByte		bmAttributes;
    353 #define UE_XFERTYPE	0x03
    354 #define  UE_CONTROL	0x00
    355 #define  UE_ISOCHRONOUS	0x01
    356 #define  UE_BULK	0x02
    357 #define  UE_INTERRUPT	0x03
    358 #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
    359 #define UE_ISO_TYPE	0x0c
    360 #define  UE_ISO_ASYNC	0x04
    361 #define  UE_ISO_ADAPT	0x08
    362 #define  UE_ISO_SYNC	0x0c
    363 #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
    364 	uWord		wMaxPacketSize;
    365 #define UE_GET_TRANS(a)		(((a) >> 11) & 0x3)
    366 #define UE_GET_SIZE(a)		((a) & 0x7ff)
    367 	uByte		bInterval;
    368 } UPACKED usb_endpoint_descriptor_t;
    369 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
    370 
    371 typedef struct {
    372 	uByte		bLength;
    373 	uByte		bDescriptorType;
    374 	uWord		bString[126];
    375 } UPACKED usb_string_descriptor_t;
    376 #define USB_MAX_STRING_LEN 128
    377 #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
    378 #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
    379 
    380 /* Hub specific request */
    381 #define UR_GET_BUS_STATE	0x02
    382 #define UR_CLEAR_TT_BUFFER	0x08
    383 #define UR_RESET_TT		0x09
    384 #define UR_GET_TT_STATE		0x0a
    385 #define UR_STOP_TT		0x0b
    386 
    387 /*
    388  * Hub features from USB 2.0 spec, table 11-17 and updated by the
    389  * LPM ECN table 4-7.
    390  */
    391 #define UHF_C_HUB_LOCAL_POWER	0
    392 #define UHF_C_HUB_OVER_CURRENT	1
    393 #define UHF_PORT_CONNECTION	0
    394 #define UHF_PORT_ENABLE		1
    395 #define UHF_PORT_SUSPEND	2
    396 #define UHF_PORT_OVER_CURRENT	3
    397 #define UHF_PORT_RESET		4
    398 #define UHF_PORT_POWER		8
    399 #define UHF_PORT_LOW_SPEED	9
    400 #define UHF_PORT_L1		10
    401 #define UHF_C_PORT_CONNECTION	16
    402 #define UHF_C_PORT_ENABLE	17
    403 #define UHF_C_PORT_SUSPEND	18
    404 #define UHF_C_PORT_OVER_CURRENT	19
    405 #define UHF_C_PORT_RESET	20
    406 #define UHF_PORT_TEST		21
    407 #define UHF_PORT_INDICATOR	22
    408 #define UHF_C_PORT_L1		23
    409 
    410 typedef struct {
    411 	uByte		bDescLength;
    412 	uByte		bDescriptorType;
    413 	uByte		bNbrPorts;
    414 	uWord		wHubCharacteristics;
    415 #define UHD_PWR			0x0003
    416 #define  UHD_PWR_GANGED		0x0000
    417 #define  UHD_PWR_INDIVIDUAL	0x0001
    418 #define  UHD_PWR_NO_SWITCH	0x0002
    419 #define UHD_COMPOUND		0x0004
    420 #define UHD_OC			0x0018
    421 #define  UHD_OC_GLOBAL		0x0000
    422 #define  UHD_OC_INDIVIDUAL	0x0008
    423 #define  UHD_OC_NONE		0x0010
    424 #define UHD_TT_THINK		0x0060
    425 #define  UHD_TT_THINK_8		0x0000
    426 #define  UHD_TT_THINK_16	0x0020
    427 #define  UHD_TT_THINK_24	0x0040
    428 #define  UHD_TT_THINK_32	0x0060
    429 #define UHD_PORT_IND		0x0080
    430 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
    431 #define UHD_PWRON_FACTOR 2
    432 	uByte		bHubContrCurrent;
    433 	uByte		DeviceRemovable[32]; /* max 255 ports */
    434 #define UHD_NOT_REMOV(desc, i) \
    435     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
    436 	/* deprecated */ uByte		PortPowerCtrlMask[1];
    437 } UPACKED usb_hub_descriptor_t;
    438 #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
    439 
    440 typedef struct {
    441 	uByte		bLength;
    442 	uByte		bDescriptorType;
    443 	uWord		bcdUSB;
    444 	uByte		bDeviceClass;
    445 	uByte		bDeviceSubClass;
    446 	uByte		bDeviceProtocol;
    447 	uByte		bMaxPacketSize0;
    448 	uByte		bNumConfigurations;
    449 	uByte		bReserved;
    450 } UPACKED usb_device_qualifier_t;
    451 #define USB_DEVICE_QUALIFIER_SIZE 10
    452 
    453 typedef struct {
    454 	uByte		bLength;
    455 	uByte		bDescriptorType;
    456 	uByte		bmAttributes;
    457 #define UOTG_SRP	0x01
    458 #define UOTG_HNP	0x02
    459 } UPACKED usb_otg_descriptor_t;
    460 
    461 /* OTG feature selectors */
    462 #define UOTG_B_HNP_ENABLE	3
    463 #define UOTG_A_HNP_SUPPORT	4
    464 #define UOTG_A_ALT_HNP_SUPPORT	5
    465 
    466 typedef struct {
    467 	uByte		bLength;
    468 	uByte		bDescriptorType;
    469 	uByte		bDebugInEndpoint;
    470 	uByte		bDebugOutEndpoint;
    471 } UPACKED usb_debug_descriptor_t;
    472 
    473 typedef struct {
    474 	uWord		wStatus;
    475 /* Device status flags */
    476 #define UDS_SELF_POWERED		0x0001
    477 #define UDS_REMOTE_WAKEUP		0x0002
    478 /* Endpoint status flags */
    479 #define UES_HALT			0x0001
    480 } UPACKED usb_status_t;
    481 
    482 typedef struct {
    483 	uWord		wHubStatus;
    484 #define UHS_LOCAL_POWER			0x0001
    485 #define UHS_OVER_CURRENT		0x0002
    486 	uWord		wHubChange;
    487 } UPACKED usb_hub_status_t;
    488 
    489 typedef struct {
    490 	uWord		wPortStatus;
    491 #define UPS_CURRENT_CONNECT_STATUS	0x0001
    492 #define UPS_PORT_ENABLED		0x0002
    493 #define UPS_SUSPEND			0x0004
    494 #define UPS_OVERCURRENT_INDICATOR	0x0008
    495 #define UPS_RESET			0x0010
    496 #define UPS_PORT_L1			0x0020
    497 #define UPS_PORT_POWER			0x0100
    498 #define UPS_FULL_SPEED			0x0000	/* for completeness */
    499 #define UPS_LOW_SPEED			0x0200
    500 #define UPS_HIGH_SPEED			0x0400
    501 #define UPS_PORT_TEST			0x0800
    502 #define UPS_PORT_INDICATOR		0x1000
    503 	uWord		wPortChange;
    504 #define UPS_C_CONNECT_STATUS		0x0001
    505 #define UPS_C_PORT_ENABLED		0x0002
    506 #define UPS_C_SUSPEND			0x0004
    507 #define UPS_C_OVERCURRENT_INDICATOR	0x0008
    508 #define UPS_C_PORT_RESET		0x0010
    509 #define UPS_C_PORT_L1			0x0020
    510 } UPACKED usb_port_status_t;
    511 
    512 /* Device class codes */
    513 #define UDCLASS_IN_INTERFACE	0x00
    514 #define UDCLASS_COMM		0x02
    515 #define UDCLASS_HUB		0x09
    516 #define  UDSUBCLASS_HUB		0x00
    517 #define  UDPROTO_FSHUB		0x00
    518 #define  UDPROTO_HSHUBSTT	0x01
    519 #define  UDPROTO_HSHUBMTT	0x02
    520 #define  UDPROTO_SSHUB		0x03
    521 #define UDCLASS_DIAGNOSTIC	0xdc
    522 #define UDCLASS_WIRELESS	0xe0
    523 #define  UDSUBCLASS_RF		0x01
    524 #define   UDPROTO_BLUETOOTH	0x01
    525 #define UDCLASS_VENDOR		0xff
    526 
    527 /* Interface class codes */
    528 #define UICLASS_UNSPEC		0x00
    529 
    530 #define UICLASS_AUDIO		0x01
    531 #define  UISUBCLASS_AUDIOCONTROL	1
    532 #define  UISUBCLASS_AUDIOSTREAM		2
    533 #define  UISUBCLASS_MIDISTREAM		3
    534 
    535 #define UICLASS_VIDEO		0x0E
    536 #define  UISUBCLASS_VIDEOCONTROL	1
    537 #define  UISUBCLASS_VIDEOSTREAMING	2
    538 #define  UISUBCLASS_VIDEOCOLLECTION	3
    539 
    540 #define UICLASS_CDC		0x02 /* communication */
    541 #define	 UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
    542 #define  UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
    543 #define	 UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
    544 #define	 UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
    545 #define	 UISUBCLASS_CAPI_CONTROLMODEL		5
    546 #define	 UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
    547 #define	 UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
    548 #define	  UIPROTO_CDC_NOCLASS			0 /* no class specific
    549 						     protocol required */
    550 #define   UIPROTO_CDC_AT			1
    551 
    552 #define UICLASS_HID		0x03
    553 #define  UISUBCLASS_BOOT	1
    554 #define  UIPROTO_BOOT_KEYBOARD	1
    555 #define  UIPROTO_MOUSE		2
    556 
    557 #define UICLASS_PHYSICAL	0x05
    558 
    559 #define UICLASS_IMAGE		0x06
    560 
    561 #define UICLASS_PRINTER		0x07
    562 #define  UISUBCLASS_PRINTER	1
    563 #define  UIPROTO_PRINTER_UNI	1
    564 #define  UIPROTO_PRINTER_BI	2
    565 #define  UIPROTO_PRINTER_1284	3
    566 
    567 #define UICLASS_MASS		0x08
    568 #define  UISUBCLASS_RBC		1
    569 #define  UISUBCLASS_SFF8020I	2
    570 #define  UISUBCLASS_QIC157	3
    571 #define  UISUBCLASS_UFI		4
    572 #define  UISUBCLASS_SFF8070I	5
    573 #define  UISUBCLASS_SCSI	6
    574 #define  UIPROTO_MASS_CBI_I	0
    575 #define  UIPROTO_MASS_CBI	1
    576 #define  UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
    577 #define  UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
    578 
    579 #define UICLASS_HUB		0x09
    580 #define  UISUBCLASS_HUB		0
    581 #define  UIPROTO_FSHUB		0
    582 #define  UIPROTO_HSHUBSTT	0 /* Yes, same as previous */
    583 #define  UIPROTO_HSHUBMTT	1
    584 
    585 #define UICLASS_CDC_DATA	0x0a
    586 #define  UISUBCLASS_DATA		0
    587 #define   UIPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
    588 #define   UIPROTO_DATA_HDLC		0x31    /* HDLC */
    589 #define   UIPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
    590 #define   UIPROTO_DATA_Q921M		0x50    /* Management for Q921 */
    591 #define   UIPROTO_DATA_Q921		0x51    /* Data for Q921 */
    592 #define   UIPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
    593 #define   UIPROTO_DATA_V42BIS		0x90    /* Data compression */
    594 #define   UIPROTO_DATA_Q931		0x91    /* Euro-ISDN */
    595 #define   UIPROTO_DATA_V120		0x92    /* V.24 rate adaption */
    596 #define   UIPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
    597 #define   UIPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
    598 #define   UIPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
    599 #define   UIPROTO_DATA_VENDOR		0xff    /* Vendor specific */
    600 
    601 #define UICLASS_SMARTCARD	0x0b
    602 
    603 /*#define UICLASS_FIRM_UPD	0x0c*/
    604 
    605 #define UICLASS_SECURITY	0x0d
    606 
    607 #define UICLASS_DIAGNOSTIC	0xdc
    608 
    609 #define UICLASS_WIRELESS	0xe0
    610 #define  UISUBCLASS_RF			0x01
    611 #define   UIPROTO_BLUETOOTH		0x01
    612 #define   UIPROTO_RNDIS			0x03
    613 
    614 #define UICLASS_APPL_SPEC	0xfe
    615 #define  UISUBCLASS_FIRMWARE_DOWNLOAD	1
    616 #define  UISUBCLASS_IRDA		2
    617 #define  UIPROTO_IRDA			0
    618 
    619 #define UICLASS_VENDOR		0xff
    620 
    621 
    622 #define USB_HUB_MAX_DEPTH 5
    623 
    624 /*
    625  * Minimum time a device needs to be powered down to go through
    626  * a power cycle.  XXX Are these time in the spec?
    627  */
    628 #define USB_POWER_DOWN_TIME	200 /* ms */
    629 #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
    630 
    631 #if 0
    632 /* These are the values from the spec. */
    633 #define USB_PORT_RESET_DELAY	10  /* ms */
    634 #define USB_PORT_ROOT_RESET_DELAY 50  /* ms */
    635 #define USB_PORT_RESET_RECOVERY	10  /* ms */
    636 #define USB_PORT_POWERUP_DELAY	100 /* ms */
    637 #define USB_SET_ADDRESS_SETTLE	2   /* ms */
    638 #define USB_RESUME_DELAY	(20*5)  /* ms */
    639 #define USB_RESUME_WAIT		10  /* ms */
    640 #define USB_RESUME_RECOVERY	10  /* ms */
    641 #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
    642 #else
    643 /* Allow for marginal (i.e. non-conforming) devices. */
    644 #define USB_PORT_RESET_DELAY	50  /* ms */
    645 #define USB_PORT_ROOT_RESET_DELAY 250  /* ms */
    646 #define USB_PORT_RESET_RECOVERY	250  /* ms */
    647 #define USB_PORT_POWERUP_DELAY	300 /* ms */
    648 #define USB_SET_ADDRESS_SETTLE	10  /* ms */
    649 #define USB_RESUME_DELAY	(50*5)  /* ms */
    650 #define USB_RESUME_WAIT		50  /* ms */
    651 #define USB_RESUME_RECOVERY	50  /* ms */
    652 #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
    653 #endif
    654 
    655 #define USB_MIN_POWER		100 /* mA */
    656 #define USB_MAX_POWER		500 /* mA */
    657 
    658 #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
    659 
    660 
    661 #define USB_UNCONFIG_NO 0
    662 #define USB_UNCONFIG_INDEX (-1)
    663 
    664 
    665 /* Packet IDs */
    666 #define UPID_RESERVED	0xf0
    667 #define UPID_OUT	0xe1
    668 #define UPID_ACK	0xd2
    669 #define UPID_DATA0	0xc3
    670 #define UPID_PING	0xb4
    671 #define UPID_SOF	0xa5
    672 #define UPID_NYET	0x96
    673 #define UPID_DATA2	0x87
    674 #define UPID_SPLIT	0x78
    675 #define UPID_IN		0x69
    676 #define UPID_NAK	0x5a
    677 #define UPID_DATA1	0x4b
    678 #define UPID_ERR	0x3c
    679 #define UPID_PREAMBLE	0x3c
    680 #define UPID_SETUP	0x2d
    681 #define UPID_STALL	0x1e
    682 #define UPID_MDATA	0x0f
    683 
    684 
    685 /*** ioctl() related stuff ***/
    686 
    687 struct usb_ctl_request {
    688 	int	ucr_addr;
    689 	usb_device_request_t ucr_request;
    690 	void	*ucr_data;
    691 	int	ucr_flags;
    692 #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
    693 	int	ucr_actlen;		/* actual length transferred */
    694 };
    695 
    696 struct usb_alt_interface {
    697 	int	uai_config_index;
    698 	int	uai_interface_index;
    699 	int	uai_alt_no;
    700 };
    701 
    702 #define USB_CURRENT_CONFIG_INDEX (-1)
    703 #define USB_CURRENT_ALT_INDEX (-1)
    704 
    705 struct usb_config_desc {
    706 	int	ucd_config_index;
    707 	usb_config_descriptor_t ucd_desc;
    708 };
    709 
    710 struct usb_interface_desc {
    711 	int	uid_config_index;
    712 	int	uid_interface_index;
    713 	int	uid_alt_index;
    714 	usb_interface_descriptor_t uid_desc;
    715 };
    716 
    717 struct usb_endpoint_desc {
    718 	int	ued_config_index;
    719 	int	ued_interface_index;
    720 	int	ued_alt_index;
    721 	int	ued_endpoint_index;
    722 	usb_endpoint_descriptor_t ued_desc;
    723 };
    724 
    725 struct usb_full_desc {
    726 	int	ufd_config_index;
    727 	u_int	ufd_size;
    728 	u_char	*ufd_data;
    729 };
    730 
    731 struct usb_string_desc {
    732 	int	usd_string_index;
    733 	int	usd_language_id;
    734 	usb_string_descriptor_t usd_desc;
    735 };
    736 
    737 struct usb_ctl_report_desc {
    738 	int	ucrd_size;
    739 	u_char	ucrd_data[1024];	/* filled data size will vary */
    740 };
    741 
    742 typedef struct { u_int32_t cookie; } usb_event_cookie_t;
    743 
    744 #define USB_MAX_DEVNAMES 4
    745 #define USB_MAX_DEVNAMELEN 16
    746 struct usb_device_info {
    747 	u_int8_t	udi_bus;
    748 	u_int8_t	udi_addr;	/* device address */
    749 	usb_event_cookie_t udi_cookie;
    750 	char		udi_product[USB_MAX_ENCODED_STRING_LEN];
    751 	char		udi_vendor[USB_MAX_ENCODED_STRING_LEN];
    752 	char		udi_release[8];
    753 	char		udi_serial[USB_MAX_ENCODED_STRING_LEN];
    754 	u_int16_t	udi_productNo;
    755 	u_int16_t	udi_vendorNo;
    756 	u_int16_t	udi_releaseNo;
    757 	u_int8_t	udi_class;
    758 	u_int8_t	udi_subclass;
    759 	u_int8_t	udi_protocol;
    760 	u_int8_t	udi_config;
    761 	u_int8_t	udi_speed;
    762 #define USB_SPEED_LOW  1
    763 #define USB_SPEED_FULL 2
    764 #define USB_SPEED_HIGH 3
    765 #define USB_SPEED_SUPER 4
    766 	int		udi_power;	/* power consumption in mA, 0 if selfpowered */
    767 	int		udi_nports;
    768 	char		udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    769 	u_int8_t	udi_ports[16];/* hub only: addresses of devices on ports */
    770 #define USB_PORT_ENABLED 0xff
    771 #define USB_PORT_SUSPENDED 0xfe
    772 #define USB_PORT_POWERED 0xfd
    773 #define USB_PORT_DISABLED 0xfc
    774 };
    775 
    776 /* <=3.0 had this layout of the structure */
    777 struct usb_device_info_old {
    778         u_int8_t        udi_bus;
    779         u_int8_t        udi_addr;       /* device address */
    780         usb_event_cookie_t udi_cookie;
    781         char            udi_product[USB_MAX_STRING_LEN];
    782         char            udi_vendor[USB_MAX_STRING_LEN];
    783         char            udi_release[8];
    784         u_int16_t       udi_productNo;
    785         u_int16_t       udi_vendorNo;
    786         u_int16_t       udi_releaseNo;
    787         u_int8_t        udi_class;
    788         u_int8_t        udi_subclass;
    789         u_int8_t        udi_protocol;
    790         u_int8_t        udi_config;
    791         u_int8_t        udi_speed;
    792         int             udi_power;      /* power consumption in mA, 0 if selfpowered */
    793         int             udi_nports;
    794         char            udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    795         u_int8_t        udi_ports[16];/* hub only: addresses of devices on ports */
    796 };
    797 
    798 struct usb_ctl_report {
    799 	int	ucr_report;
    800 	u_char	ucr_data[1024];	/* filled data size will vary */
    801 };
    802 
    803 struct usb_device_stats {
    804 	u_long	uds_requests[4];	/* indexed by transfer type UE_* */
    805 };
    806 
    807 struct usb_bulk_ra_wb_opt {
    808 	u_int	ra_wb_buffer_size;
    809 	u_int	ra_wb_request_size;
    810 };
    811 
    812 /* Events that can be read from /dev/usb */
    813 struct usb_event {
    814 	int			ue_type;
    815 #define USB_EVENT_CTRLR_ATTACH 1
    816 #define USB_EVENT_CTRLR_DETACH 2
    817 #define USB_EVENT_DEVICE_ATTACH 3
    818 #define USB_EVENT_DEVICE_DETACH 4
    819 #define USB_EVENT_DRIVER_ATTACH 5
    820 #define USB_EVENT_DRIVER_DETACH 6
    821 #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
    822 #define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH)
    823 	struct timespec		ue_time;
    824 	union {
    825 		struct {
    826 			int			ue_bus;
    827 		} ue_ctrlr;
    828 		struct usb_device_info		ue_device;
    829 		struct {
    830 			usb_event_cookie_t	ue_cookie;
    831 			char			ue_devname[16];
    832 		} ue_driver;
    833 	} u;
    834 };
    835 
    836 /* old <=3.0 compat event */
    837 struct usb_event_old {
    838 	int                     ue_type;
    839 	struct timespec         ue_time;
    840 	union {
    841 		struct {
    842 			int                     ue_bus;
    843 		} ue_ctrlr;
    844 		struct usb_device_info_old          ue_device;
    845 		struct {
    846 			usb_event_cookie_t      ue_cookie;
    847 			char                    ue_devname[16];
    848 		} ue_driver;
    849 	} u;
    850 };
    851 
    852 
    853 /* USB controller */
    854 #define USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
    855 #define USB_SETDEBUG		_IOW ('U', 2, int)
    856 #define USB_DISCOVER		_IO  ('U', 3)
    857 #define USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
    858 #define USB_DEVICEINFO_OLD	_IOWR('U', 4, struct usb_device_info_old)
    859 #define USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
    860 
    861 /* Generic HID device */
    862 #define USB_GET_REPORT_DESC	_IOR ('U', 21, struct usb_ctl_report_desc)
    863 #define USB_SET_IMMED		_IOW ('U', 22, int)
    864 #define USB_GET_REPORT		_IOWR('U', 23, struct usb_ctl_report)
    865 #define USB_SET_REPORT		_IOW ('U', 24, struct usb_ctl_report)
    866 #define USB_GET_REPORT_ID	_IOR ('U', 25, int)
    867 
    868 /* Generic USB device */
    869 #define USB_GET_CONFIG		_IOR ('U', 100, int)
    870 #define USB_SET_CONFIG		_IOW ('U', 101, int)
    871 #define USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
    872 #define USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
    873 #define USB_GET_NO_ALT		_IOWR('U', 104, struct usb_alt_interface)
    874 #define USB_GET_DEVICE_DESC	_IOR ('U', 105, usb_device_descriptor_t)
    875 #define USB_GET_CONFIG_DESC	_IOWR('U', 106, struct usb_config_desc)
    876 #define USB_GET_INTERFACE_DESC	_IOWR('U', 107, struct usb_interface_desc)
    877 #define USB_GET_ENDPOINT_DESC	_IOWR('U', 108, struct usb_endpoint_desc)
    878 #define USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_full_desc)
    879 #define USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_string_desc)
    880 #define USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
    881 #define USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
    882 #define USB_GET_DEVICEINFO_OLD	_IOR ('U', 112, struct usb_device_info_old)
    883 #define USB_SET_SHORT_XFER	_IOW ('U', 113, int)
    884 #define USB_SET_TIMEOUT		_IOW ('U', 114, int)
    885 #define USB_SET_BULK_RA		_IOW ('U', 115, int)
    886 #define USB_SET_BULK_WB		_IOW ('U', 116, int)
    887 #define USB_SET_BULK_RA_OPT	_IOW ('U', 117, struct usb_bulk_ra_wb_opt)
    888 #define USB_SET_BULK_WB_OPT	_IOW ('U', 118, struct usb_bulk_ra_wb_opt)
    889 
    890 /* Modem device */
    891 #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
    892 #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
    893 
    894 #endif /* _USB_H_ */
    895