zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

usb.h (24748B) - Raw


      1 /*-
      2  * SPDX-License-Identifier: BSD-2-Clause
      3  *
      4  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
      5  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
      6  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 /*
     31  * This file contains standard definitions for the following USB
     32  * protocol versions:
     33  *
     34  * USB v1.0
     35  * USB v1.1
     36  * USB v2.0
     37  * USB v3.0
     38  */
     39 
     40 #ifndef _USB_STANDARD_H_
     41 #define	_USB_STANDARD_H_
     42 
     43 #if defined(_KERNEL) || defined(_STANDALONE)
     44 #ifndef USB_GLOBAL_INCLUDE_FILE
     45 #include "opt_usb.h"
     46 #endif
     47 
     48 /* Declare parent SYSCTL USB node. */
     49 #ifdef SYSCTL_DECL
     50 SYSCTL_DECL(_hw_usb);
     51 #endif
     52 
     53 #ifndef USB_GLOBAL_INCLUDE_FILE
     54 #include <sys/malloc.h>
     55 #endif
     56 
     57 MALLOC_DECLARE(M_USB);
     58 MALLOC_DECLARE(M_USBDEV);
     59 #endif	/* _KERNEL || _STANDALONE */
     60 
     61 #ifndef USB_GLOBAL_INCLUDE_FILE
     62 #include <dev/usb/usb_endian.h>
     63 #include <dev/usb/usb_freebsd.h>
     64 #endif
     65 
     66 #define	USB_STACK_VERSION 2000		/* 2.0 */
     67 
     68 /* Definition of some hardcoded USB constants. */
     69 
     70 #define	USB_MAX_IPACKET		8	/* initial USB packet size */
     71 #define	USB_EP_MAX (2*16)		/* hardcoded */
     72 #define	USB_ROOT_HUB_ADDR 1		/* index */
     73 #define	USB_MIN_DEVICES 2		/* unused + root HUB */
     74 #define	USB_UNCONFIG_INDEX 0xFF		/* internal use only */
     75 #define	USB_IFACE_INDEX_ANY 0xFF	/* internal use only */
     76 #define	USB_START_ADDR 0		/* default USB device BUS address
     77 					 * after USB bus reset */
     78 #define	USB_CONTROL_ENDPOINT 0		/* default control endpoint */
     79 
     80 #define	USB_FRAMES_PER_SECOND_FS 1000	/* full speed */
     81 #define	USB_FRAMES_PER_SECOND_HS 8000	/* high speed */
     82 
     83 #define	USB_FS_BYTES_PER_HS_UFRAME 188	/* bytes */
     84 #define	USB_HS_MICRO_FRAMES_MAX 8	/* units */
     85 
     86 #define	USB_ISOC_TIME_MAX 128		/* ms */
     87 
     88 /*
     89  * Minimum time a device needs to be powered down to go through a
     90  * power cycle. These values are not in the USB specification.
     91  */
     92 #define	USB_POWER_DOWN_TIME	200	/* ms */
     93 #define	USB_PORT_POWER_DOWN_TIME	100	/* ms */
     94 
     95 /* Definition of software USB power modes */
     96 #define	USB_POWER_MODE_OFF 0		/* turn off device */
     97 #define	USB_POWER_MODE_ON 1		/* always on */
     98 #define	USB_POWER_MODE_SAVE 2		/* automatic suspend and resume */
     99 #define	USB_POWER_MODE_SUSPEND 3	/* force suspend */
    100 #define	USB_POWER_MODE_RESUME 4		/* force resume */
    101 
    102 /* These are the values from the USB specification. */
    103 #define	USB_PORT_RESET_DELAY_SPEC	10	/* ms */
    104 #define	USB_PORT_ROOT_RESET_DELAY_SPEC	50	/* ms */
    105 #define	USB_PORT_RESET_RECOVERY_SPEC	10	/* ms */
    106 #define	USB_PORT_POWERUP_DELAY_SPEC	100	/* ms */
    107 #define	USB_PORT_RESUME_DELAY_SPEC	20	/* ms */
    108 #define	USB_SET_ADDRESS_SETTLE_SPEC	2	/* ms */
    109 #define	USB_RESUME_DELAY_SPEC		(20*5)	/* ms */
    110 #define	USB_RESUME_WAIT_SPEC		10	/* ms */
    111 #define	USB_RESUME_RECOVERY_SPEC	10	/* ms */
    112 #define	USB_EXTRA_POWER_UP_TIME_SPEC	0	/* ms */
    113 
    114 /* Allow for marginal and non-conforming devices. */
    115 #define	USB_PORT_RESET_DELAY		50	/* ms */
    116 #define	USB_PORT_ROOT_RESET_DELAY	200	/* ms */
    117 #define	USB_PORT_RESET_RECOVERY		10	/* ms */
    118 #define	USB_PORT_POWERUP_DELAY		300	/* ms */
    119 #define	USB_PORT_RESUME_DELAY		(20*2)	/* ms */
    120 #define	USB_SET_ADDRESS_SETTLE		10	/* ms */
    121 #define	USB_RESUME_DELAY		(50*5)	/* ms */
    122 #define	USB_RESUME_WAIT			50	/* ms */
    123 #define	USB_RESUME_RECOVERY		50	/* ms */
    124 #define	USB_EXTRA_POWER_UP_TIME		20	/* ms */
    125 #define	USB_ENUM_NICE_TIME		16	/* ms */
    126 
    127 #define	USB_MIN_POWER		100	/* mA */
    128 #define	USB_MAX_POWER		500	/* mA */
    129 
    130 #define	USB_BUS_RESET_DELAY	100	/* ms */
    131 
    132 /*
    133  * USB record layout in memory:
    134  *
    135  * - USB config 0
    136  *   - USB interfaces
    137  *     - USB alternative interfaces
    138  *       - USB endpoints
    139  *
    140  * - USB config 1
    141  *   - USB interfaces
    142  *     - USB alternative interfaces
    143  *       - USB endpoints
    144  */
    145 
    146 /* Declaration of USB records */
    147 
    148 struct usb_device_request {
    149 	uByte	bmRequestType;
    150 	uByte	bRequest;
    151 	uWord	wValue;
    152 	uWord	wIndex;
    153 	uWord	wLength;
    154 } __packed;
    155 typedef struct usb_device_request usb_device_request_t;
    156 
    157 #define	UT_WRITE		0x00
    158 #define	UT_READ			0x80
    159 #define	UT_STANDARD		0x00
    160 #define	UT_CLASS		0x20
    161 #define	UT_VENDOR		0x40
    162 #define	UT_DEVICE		0x00
    163 #define	UT_INTERFACE		0x01
    164 #define	UT_ENDPOINT		0x02
    165 #define	UT_OTHER		0x03
    166 
    167 #define	UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
    168 #define	UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
    169 #define	UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
    170 #define	UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
    171 #define	UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
    172 #define	UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
    173 #define	UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
    174 #define	UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
    175 #define	UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
    176 #define	UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
    177 #define	UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
    178 #define	UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
    179 #define	UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
    180 #define	UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
    181 #define	UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
    182 #define	UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
    183 #define	UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
    184 #define	UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
    185 #define	UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
    186 #define	UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
    187 #define	UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
    188 #define	UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
    189 
    190 /* Requests */
    191 #define	UR_GET_STATUS		0x00
    192 #define	UR_CLEAR_FEATURE	0x01
    193 #define	UR_SET_FEATURE		0x03
    194 #define	UR_SET_ADDRESS		0x05
    195 #define	UR_GET_DESCRIPTOR	0x06
    196 #define	UDESC_DEVICE		0x01
    197 #define	UDESC_CONFIG		0x02
    198 #define	UDESC_STRING		0x03
    199 #define	USB_LANGUAGE_TABLE	0x00	/* language ID string index */
    200 #define	UDESC_INTERFACE		0x04
    201 #define	UDESC_ENDPOINT		0x05
    202 #define	UDESC_DEVICE_QUALIFIER	0x06
    203 #define	UDESC_OTHER_SPEED_CONFIGURATION 0x07
    204 #define	UDESC_INTERFACE_POWER	0x08
    205 #define	UDESC_OTG		0x09
    206 #define	UDESC_DEBUG		0x0A
    207 #define	UDESC_IFACE_ASSOC	0x0B	/* interface association */
    208 #define	UDESC_BOS		0x0F	/* binary object store */
    209 #define	UDESC_DEVICE_CAPABILITY	0x10
    210 #define	UDESC_CS_DEVICE		0x21	/* class specific */
    211 #define	UDESC_CS_CONFIG		0x22
    212 #define	UDESC_CS_STRING		0x23
    213 #define	UDESC_CS_INTERFACE	0x24
    214 #define	UDESC_CS_ENDPOINT	0x25
    215 #define	UDESC_HUB		0x29
    216 #define	UDESC_SS_HUB		0x2A	/* super speed */
    217 #define	UDESC_ENDPOINT_SS_COMP	0x30	/* super speed */
    218 #define	UR_SET_DESCRIPTOR	0x07
    219 #define	UR_GET_CONFIG		0x08
    220 #define	UR_SET_CONFIG		0x09
    221 #define	UR_GET_INTERFACE	0x0a
    222 #define	UR_SET_INTERFACE	0x0b
    223 #define	UR_SYNCH_FRAME		0x0c
    224 #define	UR_SET_SEL		0x30
    225 #define	UR_ISOCH_DELAY		0x31
    226 
    227 /* HUB specific request */
    228 #define	UR_GET_BUS_STATE	0x02
    229 #define	UR_CLEAR_TT_BUFFER	0x08
    230 #define	UR_RESET_TT		0x09
    231 #define	UR_GET_TT_STATE		0x0a
    232 #define	UR_STOP_TT		0x0b
    233 #define	UR_SET_AND_TEST		0x0c	/* USB 2.0 only */
    234 #define	UR_SET_HUB_DEPTH	0x0c	/* USB 3.0 only */
    235 #define	USB_SS_HUB_DEPTH_MAX	5
    236 #define	UR_GET_PORT_ERR_COUNT	0x0d
    237 
    238 /* Feature numbers */
    239 #define	UF_ENDPOINT_HALT	0
    240 #define	UF_DEVICE_REMOTE_WAKEUP	1
    241 #define	UF_TEST_MODE		2
    242 #define	UF_U1_ENABLE		0x30
    243 #define	UF_U2_ENABLE		0x31
    244 #define	UF_LTM_ENABLE		0x32
    245 
    246 /* HUB specific features */
    247 #define	UHF_C_HUB_LOCAL_POWER	0
    248 #define	UHF_C_HUB_OVER_CURRENT	1
    249 #define	UHF_PORT_CONNECTION	0
    250 #define	UHF_PORT_ENABLE		1
    251 #define	UHF_PORT_SUSPEND	2
    252 #define	UHF_PORT_OVER_CURRENT	3
    253 #define	UHF_PORT_RESET		4
    254 #define	UHF_PORT_LINK_STATE	5
    255 #define	UHF_PORT_POWER		8
    256 #define	UHF_PORT_LOW_SPEED	9
    257 #define	UHF_PORT_L1		10
    258 #define	UHF_C_PORT_CONNECTION	16
    259 #define	UHF_C_PORT_ENABLE	17
    260 #define	UHF_C_PORT_SUSPEND	18
    261 #define	UHF_C_PORT_OVER_CURRENT	19
    262 #define	UHF_C_PORT_RESET	20
    263 #define	UHF_PORT_TEST		21
    264 #define	UHF_PORT_INDICATOR	22
    265 #define	UHF_C_PORT_L1		23
    266 
    267 /* SuperSpeed HUB specific features */
    268 #define	UHF_PORT_U1_TIMEOUT	23
    269 #define	UHF_PORT_U2_TIMEOUT	24
    270 #define	UHF_C_PORT_LINK_STATE	25
    271 #define	UHF_C_PORT_CONFIG_ERROR	26
    272 #define	UHF_PORT_REMOTE_WAKE_MASK	27
    273 #define	UHF_BH_PORT_RESET	28
    274 #define	UHF_C_BH_PORT_RESET	29
    275 #define	UHF_FORCE_LINKPM_ACCEPT	30
    276 
    277 /* SuperSpeed suspend support */
    278 #define	USB_INTERFACE_FUNC_SUSPEND 0
    279 #define	USB_INTERFACE_FUNC_SUSPEND_LP	(1 << 8)
    280 #define	USB_INTERFACE_FUNC_SUSPEND_RW	(1 << 9)
    281 
    282 struct usb_descriptor {
    283 	uByte	bLength;
    284 	uByte	bDescriptorType;
    285 	uByte	bDescriptorSubtype;
    286 } __packed;
    287 typedef struct usb_descriptor usb_descriptor_t;
    288 
    289 struct usb_device_descriptor {
    290 	uByte	bLength;
    291 	uByte	bDescriptorType;
    292 	uWord	bcdUSB;
    293 #define	UD_USB_2_0		0x0200
    294 #define	UD_USB_3_0		0x0300
    295 #define	UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02)
    296 #define	UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03)
    297 	uByte	bDeviceClass;
    298 	uByte	bDeviceSubClass;
    299 	uByte	bDeviceProtocol;
    300 	uByte	bMaxPacketSize;
    301 	/* The fields below are not part of the initial descriptor. */
    302 	uWord	idVendor;
    303 	uWord	idProduct;
    304 	uWord	bcdDevice;
    305 	uByte	iManufacturer;
    306 	uByte	iProduct;
    307 	uByte	iSerialNumber;
    308 	uByte	bNumConfigurations;
    309 } __packed;
    310 typedef struct usb_device_descriptor usb_device_descriptor_t;
    311 
    312 /* Binary Device Object Store (BOS) */
    313 struct usb_bos_descriptor {
    314 	uByte	bLength;
    315 	uByte	bDescriptorType;
    316 	uWord	wTotalLength;
    317 	uByte	bNumDeviceCaps;
    318 } __packed;
    319 typedef struct usb_bos_descriptor usb_bos_descriptor_t;
    320 
    321 /* Binary Device Object Store Capability */
    322 struct usb_bos_cap_descriptor {
    323 	uByte	bLength;
    324 	uByte	bDescriptorType;
    325 	uByte	bDevCapabilityType;
    326 #define	USB_DEVCAP_RESERVED	0x00
    327 #define	USB_DEVCAP_WUSB		0x01
    328 #define	USB_DEVCAP_USB2EXT	0x02
    329 #define	USB_DEVCAP_SUPER_SPEED	0x03
    330 #define	USB_DEVCAP_CONTAINER_ID	0x04
    331 	/* data ... */
    332 } __packed;
    333 typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t;
    334 
    335 struct usb_devcap_usb2ext_descriptor {
    336 	uByte	bLength;
    337 	uByte	bDescriptorType;
    338 	uByte	bDevCapabilityType;
    339 	uDWord	bmAttributes;
    340 #define	USB_V2EXT_LPM (1U << 1)
    341 #define	USB_V2EXT_BESL_SUPPORTED (1U << 2)
    342 #define	USB_V2EXT_BESL_BASELINE_VALID (1U << 3)
    343 #define	USB_V2EXT_BESL_DEEP_VALID (1U << 4)
    344 #define	USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF)
    345 #define	USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF)
    346 } __packed;
    347 typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t;
    348 
    349 struct usb_devcap_ss_descriptor {
    350 	uByte	bLength;
    351 	uByte	bDescriptorType;
    352 	uByte	bDevCapabilityType;
    353 	uByte	bmAttributes;
    354 	uWord	wSpeedsSupported;
    355 	uByte	bFunctionalitySupport;
    356 	uByte	bU1DevExitLat;
    357 	uWord	wU2DevExitLat;
    358 } __packed;
    359 typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t;
    360 
    361 struct usb_devcap_container_id_descriptor {
    362 	uByte	bLength;
    363 	uByte	bDescriptorType;
    364 	uByte	bDevCapabilityType;
    365 	uByte	bReserved;
    366 	uByte	bContainerID;
    367 } __packed;
    368 typedef struct usb_devcap_container_id_descriptor
    369 		usb_devcap_container_id_descriptor_t;
    370 
    371 /* Device class codes */
    372 #define	UDCLASS_IN_INTERFACE	0x00
    373 #define	UDCLASS_COMM		0x02
    374 #define	UDCLASS_HUB		0x09
    375 #define	UDSUBCLASS_HUB		0x00
    376 #define	UDPROTO_FSHUB		0x00
    377 #define	UDPROTO_HSHUBSTT	0x01
    378 #define	UDPROTO_HSHUBMTT	0x02
    379 #define	UDPROTO_SSHUB		0x03
    380 #define	UDCLASS_DIAGNOSTIC	0xdc
    381 #define	UDCLASS_WIRELESS	0xe0
    382 #define	UDSUBCLASS_RF		0x01
    383 #define	UDPROTO_BLUETOOTH	0x01
    384 #define	UDCLASS_VENDOR		0xff
    385 
    386 struct usb_config_descriptor {
    387 	uByte	bLength;
    388 	uByte	bDescriptorType;
    389 	uWord	wTotalLength;
    390 	uByte	bNumInterface;
    391 	uByte	bConfigurationValue;
    392 #define	USB_UNCONFIG_NO 0
    393 	uByte	iConfiguration;
    394 	uByte	bmAttributes;
    395 #define	UC_BUS_POWERED		0x80
    396 #define	UC_SELF_POWERED		0x40
    397 #define	UC_REMOTE_WAKEUP	0x20
    398 	uByte	bMaxPower;		/* max current in 2 mA units */
    399 #define	UC_POWER_FACTOR 2
    400 } __packed;
    401 typedef struct usb_config_descriptor usb_config_descriptor_t;
    402 
    403 struct usb_interface_descriptor {
    404 	uByte	bLength;
    405 	uByte	bDescriptorType;
    406 	uByte	bInterfaceNumber;
    407 	uByte	bAlternateSetting;
    408 	uByte	bNumEndpoints;
    409 	uByte	bInterfaceClass;
    410 	uByte	bInterfaceSubClass;
    411 	uByte	bInterfaceProtocol;
    412 	uByte	iInterface;
    413 } __packed;
    414 typedef struct usb_interface_descriptor usb_interface_descriptor_t;
    415 
    416 struct usb_interface_assoc_descriptor {
    417 	uByte	bLength;
    418 	uByte	bDescriptorType;
    419 	uByte	bFirstInterface;
    420 	uByte	bInterfaceCount;
    421 	uByte	bFunctionClass;
    422 	uByte	bFunctionSubClass;
    423 	uByte	bFunctionProtocol;
    424 	uByte	iFunction;
    425 } __packed;
    426 typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t;
    427 
    428 /* Interface class codes */
    429 #define	UICLASS_UNSPEC		0x00
    430 #define	UICLASS_AUDIO		0x01	/* audio */
    431 #define	UISUBCLASS_AUDIOCONTROL	1
    432 #define	UISUBCLASS_AUDIOSTREAM		2
    433 #define	UISUBCLASS_MIDISTREAM		3
    434 
    435 #define	UICLASS_CDC		0x02	/* communication */
    436 #define	UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
    437 #define	UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
    438 #define	UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
    439 #define	UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
    440 #define	UISUBCLASS_CAPI_CONTROLMODEL		5
    441 #define	UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
    442 #define	UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
    443 #define	UISUBCLASS_WIRELESS_HANDSET_CM 8
    444 #define	UISUBCLASS_DEVICE_MGMT 9
    445 #define	UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10
    446 #define	UISUBCLASS_OBEX 11
    447 #define	UISUBCLASS_ETHERNET_EMULATION_MODEL 12
    448 #define	UISUBCLASS_NETWORK_CONTROL_MODEL 13
    449 
    450 #define	UIPROTO_CDC_NONE		0
    451 #define	UIPROTO_CDC_AT			1
    452 #define	UIPROTO_CDC_EEM			7
    453 
    454 #define	UICLASS_HID		0x03
    455 #define	UISUBCLASS_BOOT		1
    456 #define	UIPROTO_BOOT_KEYBOARD	1
    457 #define	UIPROTO_MOUSE		2
    458 
    459 #define	UICLASS_PHYSICAL	0x05
    460 #define	UICLASS_IMAGE		0x06
    461 #define	UISUBCLASS_SIC		1	/* still image class */
    462 #define	UICLASS_PRINTER		0x07
    463 #define	UISUBCLASS_PRINTER	1
    464 #define	UIPROTO_PRINTER_UNI	1
    465 #define	UIPROTO_PRINTER_BI	2
    466 #define	UIPROTO_PRINTER_1284	3
    467 
    468 #define	UICLASS_MASS		0x08
    469 #define	UISUBCLASS_RBC		1
    470 #define	UISUBCLASS_SFF8020I	2
    471 #define	UISUBCLASS_QIC157	3
    472 #define	UISUBCLASS_UFI		4
    473 #define	UISUBCLASS_SFF8070I	5
    474 #define	UISUBCLASS_SCSI		6
    475 #define	UIPROTO_MASS_CBI_I	0
    476 #define	UIPROTO_MASS_CBI	1
    477 #define	UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
    478 #define	UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
    479 
    480 #define	UICLASS_HUB		0x09
    481 #define	UISUBCLASS_HUB		0
    482 #define	UIPROTO_FSHUB		0
    483 #define	UIPROTO_HSHUBSTT	0	/* Yes, same as previous */
    484 #define	UIPROTO_HSHUBMTT	1
    485 
    486 #define	UICLASS_CDC_DATA	0x0a
    487 #define	UISUBCLASS_DATA		0x00
    488 #define	UIPROTO_DATA_ISDNBRI		0x30	/* Physical iface */
    489 #define	UIPROTO_DATA_HDLC		0x31	/* HDLC */
    490 #define	UIPROTO_DATA_TRANSPARENT	0x32	/* Transparent */
    491 #define	UIPROTO_DATA_Q921M		0x50	/* Management for Q921 */
    492 #define	UIPROTO_DATA_Q921		0x51	/* Data for Q921 */
    493 #define	UIPROTO_DATA_Q921TM		0x52	/* TEI multiplexer for Q921 */
    494 #define	UIPROTO_DATA_V42BIS		0x90	/* Data compression */
    495 #define	UIPROTO_DATA_Q931		0x91	/* Euro-ISDN */
    496 #define	UIPROTO_DATA_V120		0x92	/* V.24 rate adaption */
    497 #define	UIPROTO_DATA_CAPI		0x93	/* CAPI 2.0 commands */
    498 #define	UIPROTO_DATA_HOST_BASED		0xfd	/* Host based driver */
    499 #define	UIPROTO_DATA_PUF		0xfe	/* see Prot. Unit Func. Desc. */
    500 #define	UIPROTO_DATA_VENDOR		0xff	/* Vendor specific */
    501 #define	UIPROTO_DATA_NCM		0x01	/* Network Control Model */
    502 
    503 #define	UICLASS_SMARTCARD	0x0b
    504 #define	UICLASS_FIRM_UPD	0x0c
    505 #define	UICLASS_SECURITY	0x0d
    506 #define	UICLASS_DIAGNOSTIC	0xdc
    507 #define	UICLASS_WIRELESS	0xe0
    508 #define	UISUBCLASS_RF			0x01
    509 #define	UIPROTO_BLUETOOTH		0x01
    510 #define	UIPROTO_RNDIS			0x03
    511 
    512 #define	UICLASS_IAD		0xEF	/* Interface Association Descriptor */
    513 #define	UISUBCLASS_SYNC			0x01
    514 #define	UIPROTO_ACTIVESYNC		0x01
    515 
    516 #define	UICLASS_APPL_SPEC	0xfe
    517 #define	UISUBCLASS_FIRMWARE_DOWNLOAD	1
    518 #define	UISUBCLASS_IRDA			2
    519 #define	UIPROTO_IRDA			0
    520 
    521 #define	UICLASS_VENDOR		0xff
    522 #define	UISUBCLASS_XBOX360_CONTROLLER	0x5d
    523 #define	UISUBCLASS_VENDOR	0xff
    524 #define	UIPROTO_XBOX360_GAMEPAD	0x01
    525 
    526 struct usb_endpoint_descriptor {
    527 	uByte	bLength;
    528 	uByte	bDescriptorType;
    529 	uByte	bEndpointAddress;
    530 #define	UE_GET_DIR(a)	((a) & 0x80)
    531 #define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
    532 #define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
    533 #define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
    534 #define	UE_DIR_RX	0xfd		/* for internal use only! */
    535 #define	UE_DIR_TX	0xfe		/* for internal use only! */
    536 #define	UE_DIR_ANY	0xff		/* for internal use only! */
    537 #define	UE_ADDR		0x0f
    538 #define	UE_ADDR_ANY	0xff		/* for internal use only! */
    539 #define	UE_GET_ADDR(a)	((a) & UE_ADDR)
    540 	uByte	bmAttributes;
    541 #define	UE_XFERTYPE	0x03
    542 #define	UE_CONTROL	0x00
    543 #define	UE_ISOCHRONOUS	0x01
    544 #define	UE_BULK	0x02
    545 #define	UE_INTERRUPT	0x03
    546 #define	UE_BULK_INTR	0xfe		/* for internal use only! */
    547 #define	UE_TYPE_ANY	0xff		/* for internal use only! */
    548 #define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
    549 #define	UE_ISO_TYPE	0x0c
    550 #define	UE_ISO_ASYNC	0x04
    551 #define	UE_ISO_ADAPT	0x08
    552 #define	UE_ISO_SYNC	0x0c
    553 #define	UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
    554 #define	UE_ISO_USAGE	0x30
    555 #define	UE_ISO_USAGE_DATA	0x00
    556 #define	UE_ISO_USAGE_FEEDBACK	0x10
    557 #define	UE_ISO_USAGE_IMPLICT_FB	0x20
    558 #define	UE_GET_ISO_USAGE(a)	((a) & UE_ISO_USAGE)
    559 	uWord	wMaxPacketSize;
    560 #define	UE_ZERO_MPS 0xFFFF		/* for internal use only */
    561 	uByte	bInterval;
    562 } __packed;
    563 typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
    564 
    565 struct usb_endpoint_ss_comp_descriptor {
    566 	uByte	bLength;
    567 	uByte	bDescriptorType;
    568 	uByte	bMaxBurst;
    569 	uByte	bmAttributes;
    570 #define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
    571 #define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
    572 	uWord	wBytesPerInterval;
    573 } __packed;
    574 typedef struct usb_endpoint_ss_comp_descriptor
    575 		usb_endpoint_ss_comp_descriptor_t;
    576 
    577 struct usb_string_descriptor {
    578 	uByte	bLength;
    579 	uByte	bDescriptorType;
    580 	uWord	bString[126];
    581 	uByte	bUnused;
    582 } __packed;
    583 typedef struct usb_string_descriptor usb_string_descriptor_t;
    584 
    585 #define	USB_MAKE_STRING_DESC(m,name)	\
    586 static const struct {			\
    587   uByte bLength;			\
    588   uByte bDescriptorType;		\
    589   uByte bData[sizeof((uint8_t []){m})];	\
    590 } __packed name = {			\
    591   .bLength = sizeof(name),		\
    592   .bDescriptorType = UDESC_STRING,	\
    593   .bData = { m },			\
    594 }
    595 
    596 struct usb_string_lang {
    597 	uByte bLength;
    598 	uByte bDescriptorType;
    599 	uByte bData[2];
    600 } __packed;
    601 typedef struct usb_string_lang usb_string_lang_t;
    602 
    603 struct usb_hub_descriptor {
    604 	uByte	bDescLength;
    605 	uByte	bDescriptorType;
    606 	uByte	bNbrPorts;
    607 	uWord	wHubCharacteristics;
    608 #define	UHD_PWR			0x0003
    609 #define	UHD_PWR_GANGED		0x0000
    610 #define	UHD_PWR_INDIVIDUAL	0x0001
    611 #define	UHD_PWR_NO_SWITCH	0x0002
    612 #define	UHD_COMPOUND		0x0004
    613 #define	UHD_OC			0x0018
    614 #define	UHD_OC_GLOBAL		0x0000
    615 #define	UHD_OC_INDIVIDUAL	0x0008
    616 #define	UHD_OC_NONE		0x0010
    617 #define	UHD_TT_THINK		0x0060
    618 #define	UHD_TT_THINK_8		0x0000
    619 #define	UHD_TT_THINK_16		0x0020
    620 #define	UHD_TT_THINK_24		0x0040
    621 #define	UHD_TT_THINK_32		0x0060
    622 #define	UHD_PORT_IND		0x0080
    623 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
    624 #define	UHD_PWRON_FACTOR 2
    625 	uByte	bHubContrCurrent;
    626 	uByte	DeviceRemovable[32];	/* max 255 ports */
    627 #define	UHD_NOT_REMOV(desc, i) \
    628     (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
    629 	uByte	PortPowerCtrlMask[1];	/* deprecated */
    630 } __packed;
    631 typedef struct usb_hub_descriptor usb_hub_descriptor_t;
    632 
    633 struct usb_hub_ss_descriptor {
    634 	uByte	bLength;
    635 	uByte	bDescriptorType;
    636 	uByte	bNbrPorts;
    637 	uWord	wHubCharacteristics;
    638 	uByte	bPwrOn2PwrGood;		/* delay in 2 ms units */
    639 	uByte	bHubContrCurrent;
    640 	uByte	bHubHdrDecLat;
    641 	uWord	wHubDelay;
    642 	uByte	DeviceRemovable[32];	/* max 255 ports */
    643 } __packed;
    644 typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t;
    645 
    646 /* minimum HUB descriptor (8-ports maximum) */
    647 struct usb_hub_descriptor_min {
    648 	uByte	bDescLength;
    649 	uByte	bDescriptorType;
    650 	uByte	bNbrPorts;
    651 	uWord	wHubCharacteristics;
    652 	uByte	bPwrOn2PwrGood;
    653 	uByte	bHubContrCurrent;
    654 	uByte	DeviceRemovable[1];
    655 	uByte	PortPowerCtrlMask[1];
    656 } __packed;
    657 typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t;
    658 
    659 struct usb_device_qualifier {
    660 	uByte	bLength;
    661 	uByte	bDescriptorType;
    662 	uWord	bcdUSB;
    663 	uByte	bDeviceClass;
    664 	uByte	bDeviceSubClass;
    665 	uByte	bDeviceProtocol;
    666 	uByte	bMaxPacketSize0;
    667 	uByte	bNumConfigurations;
    668 	uByte	bReserved;
    669 } __packed;
    670 typedef struct usb_device_qualifier usb_device_qualifier_t;
    671 
    672 struct usb_otg_descriptor {
    673 	uByte	bLength;
    674 	uByte	bDescriptorType;
    675 	uByte	bmAttributes;
    676 #define	UOTG_SRP	0x01
    677 #define	UOTG_HNP	0x02
    678 } __packed;
    679 typedef struct usb_otg_descriptor usb_otg_descriptor_t;
    680 
    681 /* OTG feature selectors */
    682 #define	UOTG_B_HNP_ENABLE	3
    683 #define	UOTG_A_HNP_SUPPORT	4
    684 #define	UOTG_A_ALT_HNP_SUPPORT	5
    685 
    686 struct usb_status {
    687 	uWord	wStatus;
    688 /* Device status flags */
    689 #define	UDS_SELF_POWERED		0x0001
    690 #define	UDS_REMOTE_WAKEUP		0x0002
    691 /* Endpoint status flags */
    692 #define	UES_HALT			0x0001
    693 } __packed;
    694 typedef struct usb_status usb_status_t;
    695 
    696 struct usb_hub_status {
    697 	uWord	wHubStatus;
    698 #define	UHS_LOCAL_POWER			0x0001
    699 #define	UHS_OVER_CURRENT		0x0002
    700 	uWord	wHubChange;
    701 } __packed;
    702 typedef struct usb_hub_status usb_hub_status_t;
    703 
    704 struct usb_port_status {
    705 	uWord	wPortStatus;
    706 #define	UPS_CURRENT_CONNECT_STATUS	0x0001
    707 #define	UPS_PORT_ENABLED		0x0002
    708 #define	UPS_SUSPEND			0x0004
    709 #define	UPS_OVERCURRENT_INDICATOR	0x0008
    710 #define	UPS_RESET			0x0010
    711 #define	UPS_PORT_L1			0x0020	/* USB 2.0 only */
    712 /* The link-state bits are valid for Super-Speed USB HUBs */
    713 #define	UPS_PORT_LINK_STATE_GET(x)	(((x) >> 5) & 0xF)
    714 #define	UPS_PORT_LINK_STATE_SET(x)	(((x) & 0xF) << 5)
    715 #define	UPS_PORT_LS_U0		0x00
    716 #define	UPS_PORT_LS_U1		0x01
    717 #define	UPS_PORT_LS_U2		0x02
    718 #define	UPS_PORT_LS_U3		0x03
    719 #define	UPS_PORT_LS_SS_DIS	0x04
    720 #define	UPS_PORT_LS_RX_DET	0x05
    721 #define	UPS_PORT_LS_SS_INA	0x06
    722 #define	UPS_PORT_LS_POLL	0x07
    723 #define	UPS_PORT_LS_RECOVER	0x08
    724 #define	UPS_PORT_LS_HOT_RST	0x09
    725 #define	UPS_PORT_LS_COMP_MODE	0x0A
    726 #define	UPS_PORT_LS_LOOPBACK	0x0B
    727 #define	UPS_PORT_LS_RESUME	0x0F
    728 #define	UPS_PORT_POWER			0x0100
    729 #define	UPS_PORT_POWER_SS		0x0200	/* super-speed only */
    730 #define	UPS_LOW_SPEED			0x0200
    731 #define	UPS_HIGH_SPEED			0x0400
    732 #define	UPS_OTHER_SPEED			0x0600	/* currently FreeBSD specific */
    733 #define	UPS_PORT_TEST			0x0800
    734 #define	UPS_PORT_INDICATOR		0x1000
    735 #define	UPS_PORT_MODE_DEVICE		0x8000	/* currently FreeBSD specific */
    736 	uWord	wPortChange;
    737 #define	UPS_C_CONNECT_STATUS		0x0001
    738 #define	UPS_C_PORT_ENABLED		0x0002
    739 #define	UPS_C_SUSPEND			0x0004
    740 #define	UPS_C_OVERCURRENT_INDICATOR	0x0008
    741 #define	UPS_C_PORT_RESET		0x0010
    742 #define	UPS_C_PORT_L1			0x0020	/* USB 2.0 only */
    743 #define	UPS_C_BH_PORT_RESET		0x0020	/* USB 3.0 only */
    744 #define	UPS_C_PORT_LINK_STATE		0x0040
    745 #define	UPS_C_PORT_CONFIG_ERROR		0x0080
    746 } __packed;
    747 typedef struct usb_port_status usb_port_status_t;
    748 
    749 /*
    750  * The "USB_SPEED" macros defines all the supported USB speeds.
    751  */
    752 enum usb_dev_speed {
    753 	USB_SPEED_VARIABLE,
    754 	USB_SPEED_LOW,
    755 	USB_SPEED_FULL,
    756 	USB_SPEED_HIGH,
    757 	USB_SPEED_SUPER,
    758 };
    759 #define	USB_SPEED_MAX	(USB_SPEED_SUPER+1)
    760 
    761 /*
    762  * The "USB_REV" macros defines all the supported USB revisions.
    763  */
    764 enum usb_revision {
    765 	USB_REV_UNKNOWN,
    766 	USB_REV_PRE_1_0,
    767 	USB_REV_1_0,
    768 	USB_REV_1_1,
    769 	USB_REV_2_0,
    770 	USB_REV_2_5,
    771 	USB_REV_3_0
    772 };
    773 #define	USB_REV_MAX	(USB_REV_3_0+1)
    774 
    775 /*
    776  * Supported host controller modes.
    777  */
    778 enum usb_hc_mode {
    779 	USB_MODE_HOST,		/* initiates transfers */
    780 	USB_MODE_DEVICE,	/* bus transfer target */
    781 	USB_MODE_DUAL		/* can be host or device */
    782 };
    783 #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
    784 
    785 /*
    786  * The "USB_STATE" enums define all the supported device states.
    787  */
    788 enum usb_dev_state {
    789 	USB_STATE_DETACHED,
    790 	USB_STATE_ATTACHED,
    791 	USB_STATE_POWERED,
    792 	USB_STATE_ADDRESSED,
    793 	USB_STATE_CONFIGURED,
    794 };
    795 #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
    796 
    797 /*
    798  * The "USB_EP_MODE" macros define all the currently supported
    799  * endpoint modes.
    800  */
    801 enum usb_ep_mode {
    802 	USB_EP_MODE_DEFAULT,
    803 	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
    804 	USB_EP_MODE_HW_MASS_STORAGE,
    805 	USB_EP_MODE_HW_SERIAL,
    806 	USB_EP_MODE_HW_ETHERNET_CDC,
    807 	USB_EP_MODE_HW_ETHERNET_NCM,
    808 	USB_EP_MODE_MAX
    809 };
    810 #endif					/* _USB_STANDARD_H_ */