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