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