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