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