usb.h revision 184610
1/* $FreeBSD: head/sys/dev/usb2/include/usb2_standard.h 184610 2008-11-04 02:31:03Z alfred $ */ 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#ifndef _USB2_STANDARD_H_ 30#define _USB2_STANDARD_H_ 31 32#include <dev/usb2/include/usb2_endian.h> 33 34/* 35 * Minimum time a device needs to be powered down to go through a 36 * power cycle. These values are not in the USB specification. 37 */ 38#define USB_POWER_DOWN_TIME 200 /* ms */ 39#define USB_PORT_POWER_DOWN_TIME 100 /* ms */ 40 41#if 0 42/* These are the values from the USB specification. */ 43#define USB_PORT_RESET_DELAY 10 /* ms */ 44#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */ 45#define USB_PORT_RESET_RECOVERY 10 /* ms */ 46#define USB_PORT_POWERUP_DELAY 100 /* ms */ 47#define USB_SET_ADDRESS_SETTLE 2 /* ms */ 48#define USB_RESUME_DELAY (20*5) /* ms */ 49#define USB_RESUME_WAIT 10 /* ms */ 50#define USB_RESUME_RECOVERY 10 /* ms */ 51#define USB_EXTRA_POWER_UP_TIME 0 /* ms */ 52#else 53/* Allow for marginal and non-conforming devices. */ 54#define USB_PORT_RESET_DELAY 50 /* ms */ 55#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */ 56#define USB_PORT_RESET_RECOVERY 250 /* ms */ 57#define USB_PORT_POWERUP_DELAY 300 /* ms */ 58#define USB_SET_ADDRESS_SETTLE 10 /* ms */ 59#define USB_RESUME_DELAY (50*5) /* ms */ 60#define USB_RESUME_WAIT 50 /* ms */ 61#define USB_RESUME_RECOVERY 50 /* ms */ 62#define USB_EXTRA_POWER_UP_TIME 20 /* ms */ 63#endif 64 65#define USB_MIN_POWER 100 /* mA */ 66#define USB_MAX_POWER 500 /* mA */ 67 68#define USB_BUS_RESET_DELAY 100 /* ms */ 69 70/* 71 * USB record layout in memory: 72 * 73 * - USB config 0 74 * - USB interfaces 75 * - USB alternative interfaces 76 * - USB pipes 77 * 78 * - USB config 1 79 * - USB interfaces 80 * - USB alternative interfaces 81 * - USB pipes 82 */ 83 84/* Declaration of USB records */ 85 86struct usb2_device_request { 87 uByte bmRequestType; 88 uByte bRequest; 89 uWord wValue; 90 uWord wIndex; 91 uWord wLength; 92} __packed; 93 94#define UT_WRITE 0x00 95#define UT_READ 0x80 96#define UT_STANDARD 0x00 97#define UT_CLASS 0x20 98#define UT_VENDOR 0x40 99#define UT_DEVICE 0x00 100#define UT_INTERFACE 0x01 101#define UT_ENDPOINT 0x02 102#define UT_OTHER 0x03 103 104#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE) 105#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE) 106#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT) 107#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE) 108#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE) 109#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT) 110#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE) 111#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE) 112#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER) 113#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT) 114#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE) 115#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE) 116#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER) 117#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT) 118#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE) 119#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE) 120#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER) 121#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT) 122#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE) 123#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE) 124#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER) 125#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT) 126 127/* Requests */ 128#define UR_GET_STATUS 0x00 129#define UR_CLEAR_FEATURE 0x01 130#define UR_SET_FEATURE 0x03 131#define UR_SET_ADDRESS 0x05 132#define UR_GET_DESCRIPTOR 0x06 133#define UDESC_DEVICE 0x01 134#define UDESC_CONFIG 0x02 135#define UDESC_STRING 0x03 136#define USB_LANGUAGE_TABLE 0x00 /* Index of the language ID table 137 * string */ 138#define UDESC_INTERFACE 0x04 139#define UDESC_ENDPOINT 0x05 140#define UDESC_DEVICE_QUALIFIER 0x06 141#define UDESC_OTHER_SPEED_CONFIGURATION 0x07 142#define UDESC_INTERFACE_POWER 0x08 143#define UDESC_OTG 0x09 144#define UDESC_CS_DEVICE 0x21 /* class specific */ 145#define UDESC_CS_CONFIG 0x22 146#define UDESC_CS_STRING 0x23 147#define UDESC_CS_INTERFACE 0x24 148#define UDESC_CS_ENDPOINT 0x25 149#define UDESC_HUB 0x29 150#define UR_SET_DESCRIPTOR 0x07 151#define UR_GET_CONFIG 0x08 152#define UR_SET_CONFIG 0x09 153#define UR_GET_INTERFACE 0x0a 154#define UR_SET_INTERFACE 0x0b 155#define UR_SYNCH_FRAME 0x0c 156 157/* HUB specific request */ 158#define UR_GET_BUS_STATE 0x02 159#define UR_CLEAR_TT_BUFFER 0x08 160#define UR_RESET_TT 0x09 161#define UR_GET_TT_STATE 0x0a 162#define UR_STOP_TT 0x0b 163 164/* Feature numbers */ 165#define UF_ENDPOINT_HALT 0 166#define UF_DEVICE_REMOTE_WAKEUP 1 167#define UF_TEST_MODE 2 168 169/* HUB specific features */ 170#define UHF_C_HUB_LOCAL_POWER 0 171#define UHF_C_HUB_OVER_CURRENT 1 172#define UHF_PORT_CONNECTION 0 173#define UHF_PORT_ENABLE 1 174#define UHF_PORT_SUSPEND 2 175#define UHF_PORT_OVER_CURRENT 3 176#define UHF_PORT_RESET 4 177#define UHF_PORT_POWER 8 178#define UHF_PORT_LOW_SPEED 9 179#define UHF_C_PORT_CONNECTION 16 180#define UHF_C_PORT_ENABLE 17 181#define UHF_C_PORT_SUSPEND 18 182#define UHF_C_PORT_OVER_CURRENT 19 183#define UHF_C_PORT_RESET 20 184#define UHF_PORT_TEST 21 185#define UHF_PORT_INDICATOR 22 186 187struct usb2_descriptor { 188 uByte bLength; 189 uByte bDescriptorType; 190 uByte bDescriptorSubtype; 191} __packed; 192 193struct usb2_device_descriptor { 194 uByte bLength; 195 uByte bDescriptorType; 196 uWord bcdUSB; 197#define UD_USB_2_0 0x0200 198#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0) 199 uByte bDeviceClass; 200 uByte bDeviceSubClass; 201 uByte bDeviceProtocol; 202 uByte bMaxPacketSize; 203 /* The fields below are not part of the initial descriptor. */ 204 uWord idVendor; 205 uWord idProduct; 206 uWord bcdDevice; 207 uByte iManufacturer; 208 uByte iProduct; 209 uByte iSerialNumber; 210 uByte bNumConfigurations; 211} __packed; 212 213/* Device class codes */ 214#define UDCLASS_IN_INTERFACE 0x00 215#define UDCLASS_COMM 0x02 216#define UDCLASS_HUB 0x09 217#define UDSUBCLASS_HUB 0x00 218#define UDPROTO_FSHUB 0x00 219#define UDPROTO_HSHUBSTT 0x01 220#define UDPROTO_HSHUBMTT 0x02 221#define UDCLASS_DIAGNOSTIC 0xdc 222#define UDCLASS_WIRELESS 0xe0 223#define UDSUBCLASS_RF 0x01 224#define UDPROTO_BLUETOOTH 0x01 225#define UDCLASS_VENDOR 0xff 226 227struct usb2_config_descriptor { 228 uByte bLength; 229 uByte bDescriptorType; 230 uWord wTotalLength; 231 uByte bNumInterface; 232 uByte bConfigurationValue; 233#define USB_UNCONFIG_NO 0 234 uByte iConfiguration; 235 uByte bmAttributes; 236#define UC_BUS_POWERED 0x80 237#define UC_SELF_POWERED 0x40 238#define UC_REMOTE_WAKEUP 0x20 239 uByte bMaxPower; /* max current in 2 mA units */ 240#define UC_POWER_FACTOR 2 241} __packed; 242 243struct usb2_interface_descriptor { 244 uByte bLength; 245 uByte bDescriptorType; 246 uByte bInterfaceNumber; 247 uByte bAlternateSetting; 248 uByte bNumEndpoints; 249 uByte bInterfaceClass; 250 uByte bInterfaceSubClass; 251 uByte bInterfaceProtocol; 252 uByte iInterface; 253} __packed; 254 255/* Interface class codes */ 256#define UICLASS_UNSPEC 0x00 257#define UICLASS_AUDIO 0x01 /* audio */ 258#define UISUBCLASS_AUDIOCONTROL 1 259#define UISUBCLASS_AUDIOSTREAM 2 260#define UISUBCLASS_MIDISTREAM 3 261 262#define UICLASS_CDC 0x02 /* communication */ 263#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1 264#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2 265#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3 266#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4 267#define UISUBCLASS_CAPI_CONTROLMODEL 5 268#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6 269#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7 270#define UISUBCLASS_WIRELESS_HANDSET_CM 8 271#define UISUBCLASS_DEVICE_MGMT 9 272#define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10 273#define UISUBCLASS_OBEX 11 274#define UISUBCLASS_ETHERNET_EMULATION_MODEL 12 275 276#define UIPROTO_CDC_AT 1 277#define UIPROTO_CDC_ETH_512X4 0x76 /* FreeBSD specific */ 278 279#define UICLASS_HID 0x03 280#define UISUBCLASS_BOOT 1 281#define UIPROTO_BOOT_KEYBOARD 1 282#define UIPROTO_MOUSE 2 283 284#define UICLASS_PHYSICAL 0x05 285#define UICLASS_IMAGE 0x06 286#define UISUBCLASS_SIC 1 /* still image class */ 287#define UICLASS_PRINTER 0x07 288#define UISUBCLASS_PRINTER 1 289#define UIPROTO_PRINTER_UNI 1 290#define UIPROTO_PRINTER_BI 2 291#define UIPROTO_PRINTER_1284 3 292 293#define UICLASS_MASS 0x08 294#define UISUBCLASS_RBC 1 295#define UISUBCLASS_SFF8020I 2 296#define UISUBCLASS_QIC157 3 297#define UISUBCLASS_UFI 4 298#define UISUBCLASS_SFF8070I 5 299#define UISUBCLASS_SCSI 6 300#define UIPROTO_MASS_CBI_I 0 301#define UIPROTO_MASS_CBI 1 302#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */ 303#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */ 304 305#define UICLASS_HUB 0x09 306#define UISUBCLASS_HUB 0 307#define UIPROTO_FSHUB 0 308#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */ 309#define UIPROTO_HSHUBMTT 1 310 311#define UICLASS_CDC_DATA 0x0a 312#define UISUBCLASS_DATA 0 313#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */ 314#define UIPROTO_DATA_HDLC 0x31 /* HDLC */ 315#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */ 316#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */ 317#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */ 318#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */ 319#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */ 320#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */ 321#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */ 322#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */ 323#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */ 324#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */ 325#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */ 326 327#define UICLASS_SMARTCARD 0x0b 328#define UICLASS_FIRM_UPD 0x0c 329#define UICLASS_SECURITY 0x0d 330#define UICLASS_DIAGNOSTIC 0xdc 331#define UICLASS_WIRELESS 0xe0 332#define UISUBCLASS_RF 0x01 333#define UIPROTO_BLUETOOTH 0x01 334 335#define UICLASS_APPL_SPEC 0xfe 336#define UISUBCLASS_FIRMWARE_DOWNLOAD 1 337#define UISUBCLASS_IRDA 2 338#define UIPROTO_IRDA 0 339 340#define UICLASS_VENDOR 0xff 341#define UISUBCLASS_XBOX360_CONTROLLER 0x5d 342#define UIPROTO_XBOX360_GAMEPAD 0x01 343 344struct usb2_endpoint_descriptor { 345 uByte bLength; 346 uByte bDescriptorType; 347 uByte bEndpointAddress; 348#define UE_GET_DIR(a) ((a) & 0x80) 349#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7)) 350#define UE_DIR_IN 0x80 351#define UE_DIR_OUT 0x00 352#define UE_DIR_ANY 0xff /* for internal use only! */ 353#define UE_ADDR 0x0f 354#define UE_ADDR_ANY 0xff /* for internal use only! */ 355#define UE_GET_ADDR(a) ((a) & UE_ADDR) 356 uByte bmAttributes; 357#define UE_XFERTYPE 0x03 358#define UE_CONTROL 0x00 359#define UE_ISOCHRONOUS 0x01 360#define UE_BULK 0x02 361#define UE_INTERRUPT 0x03 362#define UE_BULK_INTR 0xfe /* for internal use only! */ 363#define UE_TYPE_ANY 0xff /* for internal use only! */ 364#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE) 365#define UE_ISO_TYPE 0x0c 366#define UE_ISO_ASYNC 0x04 367#define UE_ISO_ADAPT 0x08 368#define UE_ISO_SYNC 0x0c 369#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE) 370 uWord wMaxPacketSize; 371#define UE_ZERO_MPS 0xFFFF /* for internal use only */ 372 uByte bInterval; 373} __packed; 374 375struct usb2_string_descriptor { 376 uByte bLength; 377 uByte bDescriptorType; 378 uWord bString[126]; 379 uByte bUnused; 380} __packed; 381 382#define USB_MAKE_STRING_DESC(m,name) \ 383struct name { \ 384 uByte bLength; \ 385 uByte bDescriptorType; \ 386 uByte bData[sizeof((uint8_t []){m})]; \ 387} __packed; \ 388static const struct name name = { \ 389 .bLength = sizeof(struct name), \ 390 .bDescriptorType = UDESC_STRING, \ 391 .bData = { m }, \ 392} 393 394struct usb2_hub_descriptor { 395 uByte bDescLength; 396 uByte bDescriptorType; 397 uByte bNbrPorts; 398 uWord wHubCharacteristics; 399#define UHD_PWR 0x0003 400#define UHD_PWR_GANGED 0x0000 401#define UHD_PWR_INDIVIDUAL 0x0001 402#define UHD_PWR_NO_SWITCH 0x0002 403#define UHD_COMPOUND 0x0004 404#define UHD_OC 0x0018 405#define UHD_OC_GLOBAL 0x0000 406#define UHD_OC_INDIVIDUAL 0x0008 407#define UHD_OC_NONE 0x0010 408#define UHD_TT_THINK 0x0060 409#define UHD_TT_THINK_8 0x0000 410#define UHD_TT_THINK_16 0x0020 411#define UHD_TT_THINK_24 0x0040 412#define UHD_TT_THINK_32 0x0060 413#define UHD_PORT_IND 0x0080 414 uByte bPwrOn2PwrGood; /* delay in 2 ms units */ 415#define UHD_PWRON_FACTOR 2 416 uByte bHubContrCurrent; 417 uByte DeviceRemovable[32]; /* max 255 ports */ 418#define UHD_NOT_REMOV(desc, i) \ 419 (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1) 420 /* deprecated */ uByte PortPowerCtrlMask[1]; 421} __packed; 422 423/* minimum HUB descriptor (8-ports maximum) */ 424struct usb2_hub_descriptor_min { 425 uByte bDescLength; 426 uByte bDescriptorType; 427 uByte bNbrPorts; 428 uWord wHubCharacteristics; 429 uByte bPwrOn2PwrGood; 430 uByte bHubContrCurrent; 431 uByte DeviceRemovable[1]; 432 uByte PortPowerCtrlMask[1]; 433} __packed; 434 435struct usb2_device_qualifier { 436 uByte bLength; 437 uByte bDescriptorType; 438 uWord bcdUSB; 439 uByte bDeviceClass; 440 uByte bDeviceSubClass; 441 uByte bDeviceProtocol; 442 uByte bMaxPacketSize0; 443 uByte bNumConfigurations; 444 uByte bReserved; 445} __packed; 446 447struct usb2_otg_descriptor { 448 uByte bLength; 449 uByte bDescriptorType; 450 uByte bmAttributes; 451#define UOTG_SRP 0x01 452#define UOTG_HNP 0x02 453} __packed; 454 455/* OTG feature selectors */ 456#define UOTG_B_HNP_ENABLE 3 457#define UOTG_A_HNP_SUPPORT 4 458#define UOTG_A_ALT_HNP_SUPPORT 5 459 460struct usb2_status { 461 uWord wStatus; 462/* Device status flags */ 463#define UDS_SELF_POWERED 0x0001 464#define UDS_REMOTE_WAKEUP 0x0002 465/* Endpoint status flags */ 466#define UES_HALT 0x0001 467} __packed; 468 469struct usb2_hub_status { 470 uWord wHubStatus; 471#define UHS_LOCAL_POWER 0x0001 472#define UHS_OVER_CURRENT 0x0002 473 uWord wHubChange; 474} __packed; 475 476struct usb2_port_status { 477 uWord wPortStatus; 478#define UPS_CURRENT_CONNECT_STATUS 0x0001 479#define UPS_PORT_ENABLED 0x0002 480#define UPS_SUSPEND 0x0004 481#define UPS_OVERCURRENT_INDICATOR 0x0008 482#define UPS_RESET 0x0010 483#define UPS_PORT_MODE_DEVICE 0x0020 /* currently FreeBSD specific */ 484#define UPS_PORT_POWER 0x0100 485#define UPS_LOW_SPEED 0x0200 486#define UPS_HIGH_SPEED 0x0400 487#define UPS_PORT_TEST 0x0800 488#define UPS_PORT_INDICATOR 0x1000 489 uWord wPortChange; 490#define UPS_C_CONNECT_STATUS 0x0001 491#define UPS_C_PORT_ENABLED 0x0002 492#define UPS_C_SUSPEND 0x0004 493#define UPS_C_OVERCURRENT_INDICATOR 0x0008 494#define UPS_C_PORT_RESET 0x0010 495} __packed; 496 497#endif /* _USB2_STANDARD_H_ */ 498