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