Home | History | Annotate | Line # | Download | only in usb
usb.h revision 1.115.6.1
      1 /*	$NetBSD: usb.h,v 1.115.6.1 2023/01/19 10:57:50 martin Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 #ifndef _USB_H_
     35 #define _USB_H_
     36 
     37 #include <sys/types.h>
     38 #include <sys/time.h>
     39 
     40 #include <sys/ioctl.h>
     41 
     42 #if defined(_KERNEL)
     43 
     44 #include <sys/device.h>
     45 
     46 #endif
     47 
     48 #ifdef USB_DEBUG
     49 #define Static
     50 #else
     51 #define Static static
     52 #endif
     53 
     54 #define USB_STACK_VERSION 2
     55 
     56 #define USB_MAX_DEVICES		128		/* 0, 1-127 */
     57 #define USB_MIN_DEVICES		2               /* unused + root HUB */
     58 #define USB_START_ADDR		0
     59 
     60 #define USB_CONTROL_ENDPOINT 0
     61 #define USB_MAX_ENDPOINTS 16
     62 
     63 #define USB_FRAMES_PER_SECOND 1000
     64 #define USB_UFRAMES_PER_FRAME 8
     65 
     66 /*
     67  * The USB records contain some unaligned little-endian word
     68  * components.  The U[SG]ETW macros take care of both the alignment
     69  * and endian problem and should always be used to access non-byte
     70  * values.
     71  */
     72 typedef uint8_t uByte;
     73 typedef uint8_t uWord[2];
     74 typedef uint8_t uDWord[4];
     75 
     76 #define USETW2(w,h,l) ((w)[0] = (uint8_t)(l), (w)[1] = (uint8_t)(h))
     77 
     78 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
     79 #define USETW(w,v) ((w)[0] = (uint8_t)(v), (w)[1] = (uint8_t)((v) >> 8))
     80 #define USETWD(val) { (uint8_t)(val), (uint8_t)((val) >> 8) }
     81 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) |	\
     82 	    ((uint32_t)(w)[3] << 24))
     83 #define USETDW(w,v) ((w)[0] = (uint8_t)(v), \
     84 		     (w)[1] = (uint8_t)((v) >> 8), \
     85 		     (w)[2] = (uint8_t)((v) >> 16), \
     86 		     (w)[3] = (uint8_t)((v) >> 24))
     87 #define UPACKED __packed
     88 
     89 typedef struct {
     90 	uByte		bmRequestType;
     91 	uByte		bRequest;
     92 	uWord		wValue;
     93 	uWord		wIndex;
     94 	uWord		wLength;
     95 } UPACKED usb_device_request_t;
     96 
     97 #define UT_GET_DIR(a) ((a) & 0x80)
     98 #define UT_WRITE		0x00
     99 #define UT_READ			0x80
    100 
    101 #define UT_GET_TYPE(a) ((a) & 0x60)
    102 #define UT_STANDARD		0x00
    103 #define UT_CLASS		0x20
    104 #define UT_VENDOR		0x40
    105 
    106 #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
    107 #define UT_DEVICE		0x00
    108 #define UT_INTERFACE		0x01
    109 #define UT_ENDPOINT		0x02
    110 #define UT_OTHER		0x03
    111 
    112 #define UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
    113 #define UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
    114 #define UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
    115 #define UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
    116 #define UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
    117 #define UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
    118 #define UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
    119 #define UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
    120 #define UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
    121 #define UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
    122 #define UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
    123 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
    124 #define UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
    125 #define UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
    126 #define UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
    127 #define UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
    128 #define UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
    129 #define UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
    130 #define UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
    131 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
    132 #define UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
    133 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
    134 
    135 /* Standard Requests Codes from the USB 2.0 spec, table 9-4 */
    136 #define UR_GET_STATUS		0x00
    137 #define UR_CLEAR_FEATURE	0x01
    138 #define UR_SET_FEATURE		0x03
    139 #define UR_SET_ADDRESS		0x05
    140 #define UR_GET_DESCRIPTOR	0x06
    141 #define  UDESC_DEVICE		0x01
    142 #define  UDESC_CONFIG		0x02
    143 #define  UDESC_STRING		0x03
    144 #define  UDESC_INTERFACE	0x04
    145 #define  UDESC_ENDPOINT		0x05
    146 #define  UDESC_DEVICE_QUALIFIER	0x06
    147 #define  UDESC_OTHER_SPEED_CONFIGURATION 0x07
    148 #define  UDESC_INTERFACE_POWER	0x08
    149 #define  UDESC_OTG		0x09
    150 #define  UDESC_DEBUG		0x0a
    151 #define  UDESC_INTERFACE_ASSOC	0x0b
    152 #define  UDESC_BOS		0x0f
    153 #define  UDESC_DEVICE_CAPABILITY 0x10
    154 #define  UDESC_CS_DEVICE	0x21	/* class specific */
    155 #define  UDESC_CS_CONFIG	0x22
    156 #define  UDESC_CS_STRING	0x23
    157 #define  UDESC_CS_INTERFACE	0x24
    158 #define  UDESC_CS_ENDPOINT	0x25
    159 #define  UDESC_HUB		0x29
    160 #define  UDESC_SS_HUB		0x2a	/* super speed */
    161 #define  UDESC_ENDPOINT_SS_COMP 0x30	/* super speed */
    162 #define  UDESC_ENDPOINT_ISOCH_SSP_COMP	0x31
    163 #define UR_SET_DESCRIPTOR	0x07
    164 #define UR_GET_CONFIG		0x08
    165 #define UR_SET_CONFIG		0x09
    166 #define UR_GET_INTERFACE	0x0a
    167 #define UR_SET_INTERFACE	0x0b
    168 #define UR_SYNCH_FRAME		0x0c
    169 #define UR_SET_ENCRYPTION	0x0d
    170 #define UR_GET_ENCRYPTION	0x0e
    171 #define UR_SET_HANDSHAKE	0x0f
    172 #define UR_GET_HANDSHAKE	0x10
    173 #define UR_SET_CONNECTION	0x11
    174 #define UR_SET_SECURITY_DATA	0x12
    175 #define UR_GET_SECURITY_DATA	0x13
    176 #define UR_SET_WUSB_DATA	0x14
    177 #define UR_LOOPBACK_DATA_WRITE	0x15
    178 #define UR_LOOPBACK_DATA_READ	0x16
    179 #define UR_SET_INTERFACE_DS	0x17
    180 #define UR_SET_SEL		0x30
    181 #define UR_SET_ISOCH_DELAY	0x31
    182 
    183 /*
    184  * Feature selectors. USB 2.0 spec, table 9-6 and OTG and EH suppliment,
    185  * table 6-2
    186  */
    187 #define UF_ENDPOINT_HALT	0
    188 #define UF_INTERFACE_FUNCTION_SUSPEND	0
    189 #define UF_DEVICE_REMOTE_WAKEUP	1
    190 #define UF_TEST_MODE		2
    191 #define UF_DEVICE_B_HNP_ENABLE	3
    192 #define UF_DEVICE_A_HNP_SUPPORT	4
    193 #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
    194 #define UF_DEVICE_WUSB_DEVICE	6
    195 #define UF_U1_ENABLE		0x30
    196 #define UF_U2_ENABLE		0x31
    197 #define UF_LTM_ENABLE		0x32
    198 
    199 #define USB_MAX_IPACKET		8 /* maximum size of the initial packet */
    200 
    201 #define USB_2_MAX_CTRL_PACKET	64
    202 #define USB_2_MAX_BULK_PACKET	512
    203 
    204 #define USB_3_MAX_CTRL_PACKET	512
    205 
    206 typedef struct {
    207 	uByte		bLength;
    208 	uByte		bDescriptorType;
    209 } UPACKED usb_descriptor_t;
    210 
    211 typedef struct {
    212 	uByte		bLength;
    213 	uByte		bDescriptorType;
    214 	uWord		bcdUSB;
    215 #define UD_USB_2_0		0x0200
    216 #define UD_USB_3_0		0x0300
    217 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
    218 #define UD_IS_USB3(d) (UGETW((d)->bcdUSB) >= UD_USB_3_0)
    219 	uByte		bDeviceClass;
    220 	uByte		bDeviceSubClass;
    221 	uByte		bDeviceProtocol;
    222 	uByte		bMaxPacketSize;
    223 	/* The fields below are not part of the initial descriptor. */
    224 	uWord		idVendor;
    225 	uWord		idProduct;
    226 	uWord		bcdDevice;
    227 	uByte		iManufacturer;
    228 	uByte		iProduct;
    229 	uByte		iSerialNumber;
    230 	uByte		bNumConfigurations;
    231 } UPACKED usb_device_descriptor_t;
    232 #define USB_DEVICE_DESCRIPTOR_SIZE 18
    233 
    234 typedef struct {
    235 	uByte		bLength;
    236 	uByte		bDescriptorType;
    237 	uWord		wTotalLength;
    238 	uByte		bNumInterface;
    239 	uByte		bConfigurationValue;
    240 	uByte		iConfiguration;
    241 	uByte		bmAttributes;
    242 #define UC_ATTR_MBO		0x80
    243 #define UC_SELF_POWERED		0x40
    244 #define UC_REMOTE_WAKEUP	0x20
    245 	uByte		bMaxPower; /* max current in 2 mA units */
    246 #define UC_POWER_FACTOR 2
    247 #define UC_POWER_FACTOR_SS 8
    248 } UPACKED usb_config_descriptor_t;
    249 #define USB_CONFIG_DESCRIPTOR_SIZE 9
    250 
    251 typedef struct {
    252 	uByte		bLength;
    253 	uByte		bDescriptorType;
    254 	uByte		bInterfaceNumber;
    255 	uByte		bAlternateSetting;
    256 	uByte		bNumEndpoints;
    257 	uByte		bInterfaceClass;
    258 	uByte		bInterfaceSubClass;
    259 	uByte		bInterfaceProtocol;
    260 	uByte		iInterface;
    261 } UPACKED usb_interface_descriptor_t;
    262 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
    263 
    264 typedef struct {
    265 	uByte		bLength;
    266 	uByte		bDescriptorType;
    267 	uByte		bFirstInterface;
    268 	uByte		bInterfaceCount;
    269 	uByte		bFunctionClass;
    270 	uByte		bFunctionSubClass;
    271 	uByte		bFunctionProtocol;
    272 	uByte		iFunction;
    273 } UPACKED usb_interface_assoc_descriptor_t;
    274 #define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
    275 
    276 typedef struct {
    277 	uByte		bLength;
    278 	uByte		bDescriptorType;
    279 	uByte		bEndpointAddress;
    280 #define UE_GET_DIR(a)	((a) & 0x80)
    281 #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
    282 #define UE_DIR_IN	0x80
    283 #define UE_DIR_OUT	0x00
    284 #define UE_ADDR		0x0f
    285 #define UE_GET_ADDR(a)	((a) & UE_ADDR)
    286 	uByte		bmAttributes;
    287 #define UE_XFERTYPE	0x03
    288 #define  UE_CONTROL	0x00
    289 #define  UE_ISOCHRONOUS	0x01
    290 #define  UE_BULK	0x02
    291 #define  UE_INTERRUPT	0x03
    292 #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
    293 #define UE_ISO_TYPE	0x0c
    294 #define  UE_ISO_ASYNC	0x04
    295 #define  UE_ISO_ADAPT	0x08
    296 #define  UE_ISO_SYNC	0x0c
    297 #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
    298 	uWord		wMaxPacketSize;
    299 #define UE_GET_TRANS(a)		(((a) >> 11) & 0x3)
    300 #define UE_GET_SIZE(a)		((a) & 0x7ff)
    301 	uByte		bInterval;
    302 } UPACKED usb_endpoint_descriptor_t;
    303 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
    304 
    305 typedef struct {
    306 	uByte		bLength;
    307 	uByte		bDescriptorType;
    308 	uByte		bMaxBurst;
    309 	uByte		bmAttributes;
    310 #define UE_GET_BULK_STREAMS_MASK	__BITS(4,0)
    311 #define UE_GET_BULK_STREAMS(x)		__SHIFTOUT(x, UE_GET_BULK_STREAMS_MASK)
    312 #define UE_GET_SS_ISO_MULT_MASK		__BITS(1,0)
    313 #define UE_GET_SS_ISO_MULT(x)		__SHIFTOUT(x, UE_GET_SS_ISO_MULT_MASK)
    314 #define UE_GET_SS_ISO_SSP_MASK		__BIT(7)
    315 #define UE_GET_SS_ISO_SSP(x)		__SHIFTOUT(x, UE_GET_SS_ISO_SSP_MASK)
    316 	/* The fields below are only valid for periodic endpoints */
    317 	uWord		wBytesPerInterval;
    318 } UPACKED usb_endpoint_ss_comp_descriptor_t;
    319 #define USB_ENDPOINT_SS_COMP_DESCRIPTOR_SIZE 6
    320 
    321 /* USB 3.0 9.6.2, Table 9-12 */
    322 typedef struct {
    323 	uByte		bLength;
    324 	uByte		bDescriptorType;
    325 	uWord		wTotalLength;
    326 	uByte		bNumDeviceCaps;
    327 } UPACKED usb_bos_descriptor_t;
    328 #define USB_BOS_DESCRIPTOR_SIZE 5
    329 
    330 /* common members of device capability descriptors */
    331 typedef struct {
    332 	uByte		bLength;
    333 	uByte		bDescriptorType;
    334 	uByte		bDevCapabilityType;
    335 /* Table 9-14 */
    336 #define USB_DEVCAP_RESERVED			0x00
    337 #define USB_DEVCAP_WUSB				0x01
    338 #define USB_DEVCAP_USB2EXT			0x02
    339 #define USB_DEVCAP_SUPER_SPEED			0x03
    340 #define USB_DEVCAP_CONTAINER_ID			0x04
    341 #define USB_DEVCAP_PLATFORM			0x05
    342 #define USB_DEVCAP_POWER_DELIVERY_CAPABILITY	0x06
    343 #define USB_DEVCAP_BATTERY_INFO_CAPABILITY	0x07
    344 #define USB_DEVCAP_PD_CONSUMER_PORT_CAPABILITY	0x08
    345 #define USB_DEVCAP_PD_PROVIDER_PORT_CAPABILITY	0x09
    346 #define USB_DEVCAP_SUPERSPEED_PLUS		0x0a
    347 #define USB_DEVCAP_PRECISION_TIME_MEASUREMENT	0x0b
    348 #define USB_DEVCAP_WUSB_EXT			0x0c
    349 	/* data ... */
    350 } UPACKED usb_device_capability_descriptor_t;
    351 #define USB_DEVICE_CAPABILITY_DESCRIPTOR_SIZE 3 /* at least */
    352 
    353 /* 9.6.2.1 */
    354 typedef struct {
    355 	uByte		bLength;
    356 	uByte		bDescriptorType;
    357 	uByte		bDevCapabilityType;
    358 	uDWord		bmAttributes;
    359 #define USB_DEVCAP_V2EXT_LPM			__BIT(1)
    360 #define USB_DEVCAP_V2EXT_BESL_SUPPORTED		__BIT(2)
    361 #define USB_DEVCAP_V2EXT_BESL_BASELINE_VALID	__BIT(3)
    362 #define USB_DEVCAP_V2EXT_BESL_DEEP_VALID	__BIT(4)
    363 #define USB_DEVCAP_V2EXT_BESL_BASELINE_MASK	__BITS(11, 8)
    364 #define USB_DEVCAP_V2EXT_BESL_BASELINE_GET(x)	__SHIFTOUT(x, USB_V2EXT_BESL_BASELINE_MASK)
    365 #define USB_DEVCAP_V2EXT_BESL_DEEP_MASK		__BITS(15, 12)
    366 #define USB_DEVCAP_V2EXT_BESL_DEEP_GET(x)	__SHIFTOUT(x, USB_V2EXT_BESL_DEEP_MASK)
    367 } UPACKED usb_devcap_usb2ext_descriptor_t;
    368 #define USB_DEVCAP_USB2EXT_DESCRIPTOR_SIZE 7
    369 
    370 /* 9.6.2.2 */
    371 typedef struct {
    372 	uByte		bLength;
    373 	uByte		bDescriptorType;
    374 	uByte		bDevCapabilityType;
    375 	uByte		bmAttributes;
    376 #define USB_DEVCAP_SS_LTM __BIT(1)
    377 	uWord		wSpeedsSupported;
    378 #define USB_DEVCAP_SS_SPEED_LS __BIT(0)
    379 #define USB_DEVCAP_SS_SPEED_FS __BIT(1)
    380 #define USB_DEVCAP_SS_SPEED_HS __BIT(2)
    381 #define USB_DEVCAP_SS_SPEED_SS __BIT(3)
    382 	uByte		bFunctionalitySupport;
    383 	uByte		bU1DevExitLat;
    384 	uWord		wU2DevExitLat;
    385 } UPACKED usb_devcap_ss_descriptor_t;
    386 #define USB_DEVCAP_SS_DESCRIPTOR_SIZE 10
    387 
    388 /* 9.6.2.4 */
    389 typedef struct {
    390 	uByte		bLength;
    391 	uByte		bDescriptorType;
    392 	uByte		bDevCapabilityType;
    393 	uByte		bReserved;
    394 	uByte		ContainerID[16];
    395 } UPACKED usb_devcap_container_id_descriptor_t;
    396 #define USB_DEVCAP_CONTAINER_ID_DESCRIPTOR_SIZE 20
    397 
    398 typedef struct {
    399 	uByte		bLength;
    400 	uByte		bDescriptorType;
    401 	uByte		bDevCapabilityType;
    402 	uByte		bReserved;
    403 	uByte		PlatformCapabilityUUID[16];
    404 	uByte		CapabilityData[0];
    405 } UPACKED usb_devcap_platform_descriptor_t;
    406 #define USB_DEVCAP_PLATFORM_DESCRIPTOR_SIZE 20
    407 
    408 /* usb 3.1 ch 9.6.2.5 */
    409 typedef struct {
    410 	uByte		bLength;
    411 	uByte		bDescriptorType;
    412 	uByte		bDevCapabilityType;
    413 	uByte		bReserved;
    414 	uDWord		bmAttributes;
    415 #define	USB_DEVCAP_SSP_SSAC(x)			__SHIFTOUT(x, __BITS(4,0))
    416 #define	USB_DEVCAP_SSP_SSIC(x)			__SHIFTOUT(x, __BITS(8,5))
    417 	uWord		wFunctionalitySupport;
    418 #define	USB_DEVCAP_SSP_SSID(x)			__SHIFTOUT(x, __BITS(3,0))
    419 #define	USB_DEVCAP_SSP_MIN_RXLANE_COUNT(x)	__SHIFTOUT(x, __BITS(11,8))
    420 #define	USB_DEVCAP_SSP_MIN_TXLANE_COUNT(x)	__SHIFTOUT(x, __BITS(15,12))
    421 	uWord		wReserved;
    422 	uDWord		bmSublinkSpeedAttr[0];
    423 #define	USB_DEVCAP_SSP_SSID(x)			__SHIFTOUT(x, __BITS(3,0))
    424 #define	USB_DEVCAP_SSP_LSE(x)			__SHIFTOUT(x, __BITS(5,4))
    425 #define	USB_DEVCAP_SSP_ST(x)			__SHIFTOUT(x, __BITS(7,6))
    426 #define	USB_DEVCAP_SSP_LP(x)			__SHIFTOUT(x, __BITS(15,14))
    427 #define	USB_DEVCAP_SSP_LSM(x)			__SHIFTOUT(x, __BITS(31,16))
    428 } UPACKED usb_devcap_ssp_descriptor_t;
    429 #define USB_DEVCAP_SSP_DESCRIPTOR_SIZE 12 /* variable length */
    430 
    431 typedef struct {
    432 	uByte		bLength;
    433 	uByte		bDescriptorType;
    434 	uWord		bString[126];
    435 } UPACKED usb_string_descriptor_t;
    436 #define USB_MAX_STRING_LEN 128
    437 #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
    438 #define USB_MAX_ENCODED_STRING_LEN (USB_MAX_STRING_LEN * 3) /* UTF8 */
    439 
    440 /* Hub specific request */
    441 #define UR_GET_BUS_STATE	0x02
    442 #define UR_CLEAR_TT_BUFFER	0x08
    443 #define UR_RESET_TT		0x09
    444 #define UR_GET_TT_STATE		0x0a
    445 #define UR_STOP_TT		0x0b
    446 #define UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
    447 #define UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
    448 #define UR_GET_PORT_ERR_COUNT	0x0d
    449 /* Port Status Type for GET_STATUS,  USB 3.1 10.16.2.6 and Table 10-12 */
    450 #define  UR_PST_PORT_STATUS	0
    451 #define  UR_PST_PD_STATUS	1
    452 #define  UR_PST_EXT_PORT_STATUS	2
    453 
    454 /*
    455  * Hub features from USB 2.0 spec, table 11-17 and updated by the
    456  * LPM ECN table 4-7.
    457  */
    458 #define UHF_C_HUB_LOCAL_POWER	0
    459 #define UHF_C_HUB_OVER_CURRENT	1
    460 #define UHF_PORT_CONNECTION	0
    461 #define UHF_PORT_ENABLE		1
    462 #define UHF_PORT_SUSPEND	2
    463 #define UHF_PORT_OVER_CURRENT	3
    464 #define UHF_PORT_RESET		4
    465 #define UHF_PORT_LINK_STATE	5
    466 #define UHF_PORT_POWER		8
    467 #define UHF_PORT_LOW_SPEED	9
    468 #define UHF_PORT_L1		10
    469 #define UHF_C_PORT_CONNECTION	16
    470 #define UHF_C_PORT_ENABLE	17
    471 #define UHF_C_PORT_SUSPEND	18
    472 #define UHF_C_PORT_OVER_CURRENT	19
    473 #define UHF_C_PORT_RESET	20
    474 #define UHF_PORT_TEST		21
    475 #define UHF_PORT_INDICATOR	22
    476 #define UHF_C_PORT_L1		23
    477 
    478 /* SS HUB specific features */
    479 #define UHF_PORT_U1_TIMEOUT	23
    480 #define UHF_PORT_U2_TIMEOUT	24
    481 #define UHF_C_PORT_LINK_STATE	25
    482 #define UHF_C_PORT_CONFIG_ERROR	26
    483 #define UHF_PORT_REMOTE_WAKE_MASK	27
    484 #define UHF_BH_PORT_RESET	28
    485 #define UHF_C_BH_PORT_RESET	29
    486 #define UHF_FORCE_LINKPM_ACCEPT	30
    487 
    488 typedef struct {
    489 	uByte		bDescLength;
    490 	uByte		bDescriptorType;
    491 	uByte		bNbrPorts;
    492 #define UHD_NPORTS_MAX		255
    493 	uWord		wHubCharacteristics;
    494 #define UHD_PWR			0x0003
    495 #define  UHD_PWR_GANGED		0x0000
    496 #define  UHD_PWR_INDIVIDUAL	0x0001
    497 #define  UHD_PWR_NO_SWITCH	0x0002
    498 #define UHD_COMPOUND		0x0004
    499 #define UHD_OC			0x0018
    500 #define  UHD_OC_GLOBAL		0x0000
    501 #define  UHD_OC_INDIVIDUAL	0x0008
    502 #define  UHD_OC_NONE		0x0010
    503 #define UHD_TT_THINK		0x0060
    504 #define  UHD_TT_THINK_8		0x0000
    505 #define  UHD_TT_THINK_16	0x0020
    506 #define  UHD_TT_THINK_24	0x0040
    507 #define  UHD_TT_THINK_32	0x0060
    508 #define UHD_PORT_IND		0x0080
    509 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
    510 #define UHD_PWRON_FACTOR 2
    511 	uByte		bHubContrCurrent;
    512 	uByte		DeviceRemovable[32]; /* max 255 ports */
    513 #define UHD_NOT_REMOV(desc, i) \
    514     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
    515 	/* deprecated */ uByte		PortPowerCtrlMask[1];
    516 } UPACKED usb_hub_descriptor_t;
    517 #define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
    518 
    519 typedef struct {
    520 	uByte		bLength;
    521 	uByte		bDescriptorType;
    522 	uByte		bNbrPorts;
    523 #define UHD_SS_NPORTS_MAX	15
    524 	uWord		wHubCharacteristics;
    525 	uByte		bPwrOn2PwrGood;	/* delay in 2 ms units */
    526 	uByte		bHubContrCurrent;
    527 	uByte		bHubHdrDecLat;
    528 	uWord		wHubDelay;	/* forward delay in nanosec */
    529 	uByte		DeviceRemovable[2]; /* max 15 ports */
    530 } UPACKED usb_hub_ss_descriptor_t;
    531 #define USB_HUB_SS_DESCRIPTOR_SIZE 12
    532 
    533 typedef struct {
    534 	uByte		bLength;
    535 	uByte		bDescriptorType;
    536 	uWord		bcdUSB;
    537 	uByte		bDeviceClass;
    538 	uByte		bDeviceSubClass;
    539 	uByte		bDeviceProtocol;
    540 	uByte		bMaxPacketSize0;
    541 	uByte		bNumConfigurations;
    542 	uByte		bReserved;
    543 } UPACKED usb_device_qualifier_t;
    544 #define USB_DEVICE_QUALIFIER_SIZE 10
    545 
    546 typedef struct {
    547 	uByte		bLength;
    548 	uByte		bDescriptorType;
    549 	uByte		bmAttributes;
    550 #define UOTG_SRP	0x01
    551 #define UOTG_HNP	0x02
    552 } UPACKED usb_otg_descriptor_t;
    553 
    554 /* OTG feature selectors */
    555 #define UOTG_B_HNP_ENABLE	3
    556 #define UOTG_A_HNP_SUPPORT	4
    557 #define UOTG_A_ALT_HNP_SUPPORT	5
    558 
    559 typedef struct {
    560 	uByte		bLength;
    561 	uByte		bDescriptorType;
    562 	uByte		bDebugInEndpoint;
    563 	uByte		bDebugOutEndpoint;
    564 } UPACKED usb_debug_descriptor_t;
    565 
    566 typedef struct {
    567 	uWord		wStatus;
    568 /* Device status flags */
    569 #define UDS_SELF_POWERED		0x0001
    570 #define UDS_REMOTE_WAKEUP		0x0002
    571 /* Endpoint status flags */
    572 #define UES_HALT			0x0001
    573 } UPACKED usb_status_t;
    574 
    575 typedef struct {
    576 	uWord		wHubStatus;
    577 #define UHS_LOCAL_POWER			0x0001
    578 #define UHS_OVER_CURRENT		0x0002
    579 	uWord		wHubChange;
    580 } UPACKED usb_hub_status_t;
    581 
    582 typedef struct {
    583 	uWord		wPortStatus;
    584 #define UPS_CURRENT_CONNECT_STATUS	0x0001
    585 #define UPS_PORT_ENABLED		0x0002
    586 #define UPS_SUSPEND			0x0004
    587 #define UPS_OVERCURRENT_INDICATOR	0x0008
    588 #define UPS_RESET			0x0010
    589 #define UPS_PORT_L1			0x0020
    590 #define UPS_PORT_LS_MASK		__BITS(8,5)
    591 #define UPS_PORT_LS_GET(x)		__SHIFTOUT(x, UPS_PORT_LS_MASK)
    592 #define UPS_PORT_LS_SET(x)		__SHIFTIN(x, UPS_PORT_LS_MASK)
    593 #define UPS_PORT_LS_U0			0x00
    594 #define UPS_PORT_LS_U1			0x01
    595 #define UPS_PORT_LS_U2			0x02
    596 #define UPS_PORT_LS_U3			0x03
    597 #define UPS_PORT_LS_SS_DIS		0x04
    598 #define UPS_PORT_LS_RX_DET		0x05
    599 #define UPS_PORT_LS_SS_INA		0x06
    600 #define UPS_PORT_LS_POLL		0x07
    601 #define UPS_PORT_LS_RECOVER		0x08
    602 #define UPS_PORT_LS_HOT_RST		0x09
    603 #define UPS_PORT_LS_COMP_MODE		0x0a
    604 #define UPS_PORT_LS_LOOPBACK		0x0b
    605 #define UPS_PORT_LS_RESUME		0x0f
    606 #define UPS_PORT_POWER			0x0100
    607 #define UPS_PORT_POWER_SS		0x0200
    608 #define UPS_FULL_SPEED			0x0000	/* for completeness */
    609 #define UPS_LOW_SPEED			0x0200
    610 #define UPS_HIGH_SPEED			0x0400
    611 #define UPS_PORT_TEST			0x0800
    612 #define UPS_PORT_INDICATOR		0x1000
    613 #define UPS_OTHER_SPEED			0x2000	/* currently NetBSD specific */
    614 	uWord		wPortChange;
    615 #define UPS_C_CONNECT_STATUS		0x0001
    616 #define UPS_C_PORT_ENABLED		0x0002
    617 #define UPS_C_SUSPEND			0x0004
    618 #define UPS_C_OVERCURRENT_INDICATOR	0x0008
    619 #define UPS_C_PORT_RESET		0x0010
    620 #define UPS_C_PORT_L1			0x0020
    621 #define UPS_C_BH_PORT_RESET		0x0020
    622 #define UPS_C_PORT_LINK_STATE		0x0040
    623 #define UPS_C_PORT_CONFIG_ERROR		0x0080
    624 } UPACKED usb_port_status_t;
    625 
    626 /* 10.16.2.6 */
    627 /* Valid when port status type is UR_PST_EXT_PORT_STATUS. */
    628 typedef struct {
    629 	uWord		wPortStatus;
    630 	uWord		wPortChange;
    631 	uDWord		dwExtPortStatus;
    632 } UPACKED usb_port_status_ext_t;
    633 
    634 /* Device class codes */
    635 #define UDCLASS_IN_INTERFACE	0x00
    636 #define UDCLASS_COMM		0x02
    637 #define UDCLASS_HUB		0x09
    638 #define  UDSUBCLASS_HUB		0x00
    639 #define  UDPROTO_FSHUB		0x00
    640 #define  UDPROTO_HSHUBSTT	0x01
    641 #define  UDPROTO_HSHUBMTT	0x02
    642 #define  UDPROTO_SSHUB		0x03
    643 #define UDCLASS_DIAGNOSTIC	0xdc
    644 #define UDCLASS_WIRELESS	0xe0
    645 #define  UDSUBCLASS_RF		0x01
    646 #define   UDPROTO_BLUETOOTH	0x01
    647 #define UDCLASS_VENDOR		0xff
    648 
    649 /* Interface class codes */
    650 #define UICLASS_UNSPEC		0x00
    651 
    652 #define UICLASS_AUDIO		0x01
    653 #define  UISUBCLASS_AUDIOCONTROL	1
    654 #define  UISUBCLASS_AUDIOSTREAM		2
    655 #define  UISUBCLASS_MIDISTREAM		3
    656 
    657 #define UICLASS_VIDEO		0x0e
    658 #define  UISUBCLASS_VIDEOCONTROL	1
    659 #define  UISUBCLASS_VIDEOSTREAMING	2
    660 #define  UISUBCLASS_VIDEOCOLLECTION	3
    661 
    662 #define UICLASS_CDC		0x02 /* communication */
    663 #define	 UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
    664 #define  UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
    665 #define	 UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
    666 #define	 UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
    667 #define	 UISUBCLASS_CAPI_CONTROLMODEL		5
    668 #define	 UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
    669 #define	 UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
    670 #define	  UIPROTO_CDC_NOCLASS			0 /* no class specific
    671 						     protocol required */
    672 #define   UIPROTO_CDC_AT			1
    673 
    674 #define UICLASS_HID		0x03
    675 #define  UISUBCLASS_BOOT	1
    676 #define  UIPROTO_BOOT_KEYBOARD	1
    677 #define  UIPROTO_MOUSE		2
    678 
    679 #define UICLASS_PHYSICAL	0x05
    680 
    681 #define UICLASS_IMAGE		0x06
    682 
    683 #define UICLASS_PRINTER		0x07
    684 #define  UISUBCLASS_PRINTER	1
    685 #define  UIPROTO_PRINTER_UNI	1
    686 #define  UIPROTO_PRINTER_BI	2
    687 #define  UIPROTO_PRINTER_1284	3
    688 
    689 #define UICLASS_MASS		0x08
    690 #define  UISUBCLASS_RBC		1
    691 #define  UISUBCLASS_SFF8020I	2
    692 #define  UISUBCLASS_QIC157	3
    693 #define  UISUBCLASS_UFI		4
    694 #define  UISUBCLASS_SFF8070I	5
    695 #define  UISUBCLASS_SCSI	6
    696 #define  UIPROTO_MASS_CBI_I	0
    697 #define  UIPROTO_MASS_CBI	1
    698 #define  UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
    699 #define  UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
    700 #define  UIPROTO_MASS_UAS	98	/* USB Attached SCSI */
    701 
    702 #define UICLASS_HUB		0x09
    703 #define  UISUBCLASS_HUB		0
    704 #define  UIPROTO_FSHUB		0
    705 #define  UIPROTO_HSHUBSTT	0 /* Yes, same as previous */
    706 #define  UIPROTO_HSHUBMTT	1
    707 
    708 #define UICLASS_CDC_DATA	0x0a
    709 #define  UISUBCLASS_DATA		0
    710 #define   UIPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
    711 #define   UIPROTO_DATA_HDLC		0x31    /* HDLC */
    712 #define   UIPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
    713 #define   UIPROTO_DATA_Q921M		0x50    /* Management for Q921 */
    714 #define   UIPROTO_DATA_Q921		0x51    /* Data for Q921 */
    715 #define   UIPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
    716 #define   UIPROTO_DATA_V42BIS		0x90    /* Data compression */
    717 #define   UIPROTO_DATA_Q931		0x91    /* Euro-ISDN */
    718 #define   UIPROTO_DATA_V120		0x92    /* V.24 rate adaption */
    719 #define   UIPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
    720 #define   UIPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
    721 #define   UIPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
    722 #define   UIPROTO_DATA_VENDOR		0xff    /* Vendor specific */
    723 
    724 #define UICLASS_SMARTCARD	0x0b
    725 
    726 /*#define UICLASS_FIRM_UPD	0x0c*/
    727 
    728 #define UICLASS_SECURITY	0x0d
    729 
    730 #define UICLASS_DIAGNOSTIC	0xdc
    731 
    732 #define UICLASS_WIRELESS	0xe0
    733 #define  UISUBCLASS_RF			0x01
    734 #define   UIPROTO_BLUETOOTH		0x01
    735 #define   UIPROTO_RNDIS			0x03
    736 
    737 #define UICLASS_APPL_SPEC	0xfe
    738 #define  UISUBCLASS_FIRMWARE_DOWNLOAD	1
    739 #define  UISUBCLASS_IRDA		2
    740 #define  UIPROTO_IRDA			0
    741 
    742 #define UICLASS_VENDOR		0xff
    743 
    744 
    745 #define USB_HUB_MAX_DEPTH 5
    746 
    747 /*
    748  * Minimum time a device needs to be powered down to go through
    749  * a power cycle.  XXX Are these time in the spec?
    750  */
    751 #define USB_POWER_DOWN_TIME	200 /* ms */
    752 #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
    753 
    754 #if 0
    755 /* These are the values from the spec. */
    756 #define USB_PORT_RESET_DELAY	10  /* ms */
    757 #define USB_PORT_ROOT_RESET_DELAY 50  /* ms */
    758 #define USB_PORT_RESET_RECOVERY	10  /* ms */
    759 #define USB_PORT_POWERUP_DELAY	100 /* ms */
    760 #define USB_SET_ADDRESS_SETTLE	2   /* ms */
    761 #define USB_RESUME_DELAY	(20*5)  /* ms */
    762 #define USB_RESUME_WAIT		10  /* ms */
    763 #define USB_RESUME_RECOVERY	10  /* ms */
    764 #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
    765 #else
    766 /* Allow for marginal (i.e. non-conforming) devices. */
    767 #define USB_PORT_RESET_DELAY	50  /* ms */
    768 #define USB_PORT_ROOT_RESET_DELAY 250  /* ms */
    769 #define USB_PORT_RESET_RECOVERY	250  /* ms */
    770 #define USB_PORT_POWERUP_DELAY	300 /* ms */
    771 #define USB_SET_ADDRESS_SETTLE	10  /* ms */
    772 #define USB_RESUME_DELAY	(50*5)  /* ms */
    773 #define USB_RESUME_WAIT		50  /* ms */
    774 #define USB_RESUME_RECOVERY	50  /* ms */
    775 #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
    776 #endif
    777 
    778 #define USB_MIN_POWER		100 /* mA */
    779 #define USB_MIN_POWER_SS	150 /* mA */
    780 #define USB_MAX_POWER		500 /* mA */
    781 #define USB_MAX_POWER_SS	900 /* mA */
    782 
    783 #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
    784 
    785 
    786 #define USB_UNCONFIG_NO 0
    787 #define USB_UNCONFIG_INDEX (-1)
    788 
    789 
    790 /* Packet IDs */
    791 #define UPID_RESERVED	0xf0
    792 #define UPID_OUT	0xe1
    793 #define UPID_ACK	0xd2
    794 #define UPID_DATA0	0xc3
    795 #define UPID_PING	0xb4
    796 #define UPID_SOF	0xa5
    797 #define UPID_NYET	0x96
    798 #define UPID_DATA2	0x87
    799 #define UPID_SPLIT	0x78
    800 #define UPID_IN		0x69
    801 #define UPID_NAK	0x5a
    802 #define UPID_DATA1	0x4b
    803 #define UPID_ERR	0x3c
    804 #define UPID_PREAMBLE	0x3c
    805 #define UPID_SETUP	0x2d
    806 #define UPID_STALL	0x1e
    807 #define UPID_MDATA	0x0f
    808 
    809 
    810 /*** ioctl() related stuff ***/
    811 
    812 struct usb_ctl_request {
    813 	int	ucr_addr;
    814 	usb_device_request_t ucr_request;
    815 	void	*ucr_data;
    816 	int	ucr_flags;
    817 #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
    818 	int	ucr_actlen;		/* actual length transferred */
    819 };
    820 
    821 struct usb_alt_interface {
    822 	int	uai_config_index;
    823 	int	uai_interface_index;
    824 	int	uai_alt_no;
    825 };
    826 
    827 #define USB_CURRENT_CONFIG_INDEX (-1)
    828 #define USB_CURRENT_ALT_INDEX (-1)
    829 
    830 struct usb_config_desc {
    831 	int	ucd_config_index;
    832 	usb_config_descriptor_t ucd_desc;
    833 };
    834 
    835 struct usb_interface_desc {
    836 	int	uid_config_index;
    837 	int	uid_interface_index;
    838 	int	uid_alt_index;
    839 	usb_interface_descriptor_t uid_desc;
    840 };
    841 
    842 struct usb_endpoint_desc {
    843 	int	ued_config_index;
    844 	int	ued_interface_index;
    845 	int	ued_alt_index;
    846 	int	ued_endpoint_index;
    847 	usb_endpoint_descriptor_t ued_desc;
    848 };
    849 
    850 struct usb_full_desc {
    851 	int	ufd_config_index;
    852 	u_int	ufd_size;
    853 	u_char	*ufd_data;
    854 };
    855 
    856 struct usb_string_desc {
    857 	int	usd_string_index;
    858 	int	usd_language_id;
    859 	usb_string_descriptor_t usd_desc;
    860 };
    861 
    862 struct usb_ctl_report_desc {
    863 	int	ucrd_size;
    864 	u_char	ucrd_data[1024];	/* filled data size will vary */
    865 };
    866 
    867 typedef struct { uint32_t cookie; } usb_event_cookie_t;
    868 
    869 #define USB_MAX_DEVNAMES 4
    870 #define USB_MAX_DEVNAMELEN 16
    871 struct usb_device_info {
    872 	uint8_t		udi_bus;
    873 	uint8_t		udi_addr;	/* device address */
    874 	usb_event_cookie_t udi_cookie;
    875 	char		udi_product[USB_MAX_ENCODED_STRING_LEN];
    876 	char		udi_vendor[USB_MAX_ENCODED_STRING_LEN];
    877 	char		udi_release[8];
    878 	char		udi_serial[USB_MAX_ENCODED_STRING_LEN];
    879 	uint16_t	udi_productNo;
    880 	uint16_t	udi_vendorNo;
    881 	uint16_t	udi_releaseNo;
    882 	uint8_t		udi_class;
    883 	uint8_t		udi_subclass;
    884 	uint8_t		udi_protocol;
    885 	uint8_t		udi_config;
    886 	uint8_t		udi_speed;
    887 #define USB_SPEED_LOW  1
    888 #define USB_SPEED_FULL 2
    889 #define USB_SPEED_HIGH 3
    890 #define USB_SPEED_SUPER 4
    891 #define USB_SPEED_SUPER_PLUS 5
    892 #define USB_IS_SS(X) ((X) == USB_SPEED_SUPER || (X) == USB_SPEED_SUPER_PLUS)
    893 	int		udi_power;	/* power consumption in mA, 0 if selfpowered */
    894 	int		udi_nports;
    895 	char		udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    896 	uint8_t		udi_ports[16];/* hub only: addresses of devices on ports */
    897 #define USB_PORT_ENABLED 0xff
    898 #define USB_PORT_SUSPENDED 0xfe
    899 #define USB_PORT_POWERED 0xfd
    900 #define USB_PORT_DISABLED 0xfc
    901 };
    902 
    903 /* <=3.0 had this layout of the structure */
    904 struct usb_device_info_old {
    905 	uint8_t		udi_bus;
    906 	uint8_t		udi_addr;       /* device address */
    907 	usb_event_cookie_t udi_cookie;
    908 	char		udi_product[USB_MAX_STRING_LEN];
    909 	char		udi_vendor[USB_MAX_STRING_LEN];
    910 	char		udi_release[8];
    911 	uint16_t	udi_productNo;
    912 	uint16_t	udi_vendorNo;
    913 	uint16_t	udi_releaseNo;
    914 	uint8_t		udi_class;
    915 	uint8_t		udi_subclass;
    916 	uint8_t		udi_protocol;
    917 	uint8_t		udi_config;
    918 	uint8_t		udi_speed;
    919 	int		udi_power;      /* power consumption in mA, 0 if selfpowered */
    920 	int		udi_nports;
    921 	char		udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
    922 	uint8_t		udi_ports[16];/* hub only: addresses of devices on ports */
    923 };
    924 
    925 struct usb_ctl_report {
    926 	int	ucr_report;
    927 	u_char	ucr_data[1024];	/* filled data size will vary */
    928 };
    929 
    930 struct usb_device_stats {
    931 	u_long	uds_requests[4];	/* indexed by transfer type UE_* */
    932 };
    933 
    934 struct usb_bulk_ra_wb_opt {
    935 	u_int	ra_wb_buffer_size;
    936 	u_int	ra_wb_request_size;
    937 };
    938 
    939 /* Events that can be read from /dev/usb */
    940 struct usb_event {
    941 	int			ue_type;
    942 #define USB_EVENT_CTRLR_ATTACH 1
    943 #define USB_EVENT_CTRLR_DETACH 2
    944 #define USB_EVENT_DEVICE_ATTACH 3
    945 #define USB_EVENT_DEVICE_DETACH 4
    946 #define USB_EVENT_DRIVER_ATTACH 5
    947 #define USB_EVENT_DRIVER_DETACH 6
    948 #define USB_EVENT_IS_ATTACH(n) ((n) == USB_EVENT_CTRLR_ATTACH || (n) == USB_EVENT_DEVICE_ATTACH || (n) == USB_EVENT_DRIVER_ATTACH)
    949 #define USB_EVENT_IS_DETACH(n) ((n) == USB_EVENT_CTRLR_DETACH || (n) == USB_EVENT_DEVICE_DETACH || (n) == USB_EVENT_DRIVER_DETACH)
    950 	struct timespec		ue_time;
    951 	union {
    952 		struct {
    953 			int			ue_bus;
    954 		} ue_ctrlr;
    955 		struct usb_device_info		ue_device;
    956 		struct {
    957 			usb_event_cookie_t	ue_cookie;
    958 			char			ue_devname[16];
    959 		} ue_driver;
    960 	} u;
    961 };
    962 
    963 /* old <=3.0 compat event */
    964 struct usb_event_old {
    965 	int                     ue_type;
    966 	struct timespec         ue_time;
    967 	union {
    968 		struct {
    969 			int                     ue_bus;
    970 		} ue_ctrlr;
    971 		struct usb_device_info_old          ue_device;
    972 		struct {
    973 			usb_event_cookie_t      ue_cookie;
    974 			char                    ue_devname[16];
    975 		} ue_driver;
    976 	} u;
    977 };
    978 
    979 
    980 /* USB controller */
    981 #define USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
    982 #define USB_SETDEBUG		_IOW ('U', 2, int)
    983 #define USB_DISCOVER		_IO  ('U', 3)
    984 #define USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
    985 #define USB_DEVICEINFO_OLD	_IOWR('U', 4, struct usb_device_info_old)
    986 #define USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
    987 
    988 /* Generic HID device */
    989 #define USB_GET_REPORT_DESC	_IOR ('U', 21, struct usb_ctl_report_desc)
    990 #define USB_SET_IMMED		_IOW ('U', 22, int)
    991 #define USB_GET_REPORT		_IOWR('U', 23, struct usb_ctl_report)
    992 #define USB_SET_REPORT		_IOW ('U', 24, struct usb_ctl_report)
    993 #define USB_GET_REPORT_ID	_IOR ('U', 25, int)
    994 
    995 /* Generic USB device */
    996 #define USB_GET_CONFIG		_IOR ('U', 100, int)
    997 #define USB_SET_CONFIG		_IOW ('U', 101, int)
    998 #define USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
    999 #define USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
   1000 #define USB_GET_NO_ALT		_IOWR('U', 104, struct usb_alt_interface)
   1001 #define USB_GET_DEVICE_DESC	_IOR ('U', 105, usb_device_descriptor_t)
   1002 #define USB_GET_CONFIG_DESC	_IOWR('U', 106, struct usb_config_desc)
   1003 #define USB_GET_INTERFACE_DESC	_IOWR('U', 107, struct usb_interface_desc)
   1004 #define USB_GET_ENDPOINT_DESC	_IOWR('U', 108, struct usb_endpoint_desc)
   1005 #define USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_full_desc)
   1006 #define USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_string_desc)
   1007 #define USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
   1008 #define USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
   1009 #define USB_GET_DEVICEINFO_OLD	_IOR ('U', 112, struct usb_device_info_old)
   1010 #define USB_SET_SHORT_XFER	_IOW ('U', 113, int)
   1011 #define USB_SET_TIMEOUT		_IOW ('U', 114, int)
   1012 #define USB_SET_BULK_RA		_IOW ('U', 115, int)
   1013 #define USB_SET_BULK_WB		_IOW ('U', 116, int)
   1014 #define USB_SET_BULK_RA_OPT	_IOW ('U', 117, struct usb_bulk_ra_wb_opt)
   1015 #define USB_SET_BULK_WB_OPT	_IOW ('U', 118, struct usb_bulk_ra_wb_opt)
   1016 
   1017 /* Modem device */
   1018 #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
   1019 #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
   1020 
   1021 #endif /* _USB_H_ */
   1022