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