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