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