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