123cd1385SRemy Bohmer /* 223cd1385SRemy Bohmer * This file holds USB constants and structures that are needed for 323cd1385SRemy Bohmer * USB device APIs. These are used by the USB device model, which is 423cd1385SRemy Bohmer * defined in chapter 9 of the USB 2.0 specification and in the 523cd1385SRemy Bohmer * Wireless USB 1.0 (spread around). Linux has several APIs in C that 623cd1385SRemy Bohmer * need these: 723cd1385SRemy Bohmer * 823cd1385SRemy Bohmer * - the master/host side Linux-USB kernel driver API; 923cd1385SRemy Bohmer * - the "usbfs" user space API; and 1023cd1385SRemy Bohmer * - the Linux "gadget" slave/device/peripheral side driver API. 1123cd1385SRemy Bohmer * 1223cd1385SRemy Bohmer * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems 1323cd1385SRemy Bohmer * act either as a USB master/host or as a USB slave/device. That means 1423cd1385SRemy Bohmer * the master and slave side APIs benefit from working well together. 1523cd1385SRemy Bohmer * 1623cd1385SRemy Bohmer * There's also "Wireless USB", using low power short range radios for 1723cd1385SRemy Bohmer * peripheral interconnection but otherwise building on the USB framework. 1823cd1385SRemy Bohmer * 1923cd1385SRemy Bohmer * Note all descriptors are declared '__attribute__((packed))' so that: 2023cd1385SRemy Bohmer * 2123cd1385SRemy Bohmer * [a] they never get padded, either internally (USB spec writers 2223cd1385SRemy Bohmer * probably handled that) or externally; 2323cd1385SRemy Bohmer * 2423cd1385SRemy Bohmer * [b] so that accessing bigger-than-a-bytes fields will never 2523cd1385SRemy Bohmer * generate bus errors on any platform, even when the location of 2623cd1385SRemy Bohmer * its descriptor inside a bundle isn't "naturally aligned", and 2723cd1385SRemy Bohmer * 2823cd1385SRemy Bohmer * [c] for consistency, removing all doubt even when it appears to 2923cd1385SRemy Bohmer * someone that the two other points are non-issues for that 3023cd1385SRemy Bohmer * particular descriptor type. 3123cd1385SRemy Bohmer */ 3223cd1385SRemy Bohmer 3323cd1385SRemy Bohmer #ifndef __LINUX_USB_CH9_H 3423cd1385SRemy Bohmer #define __LINUX_USB_CH9_H 3523cd1385SRemy Bohmer 3623cd1385SRemy Bohmer #include <linux/types.h> /* __u8 etc */ 3782651c39SIlya Yanok #include <asm/byteorder.h> /* le16_to_cpu */ 38f903a20dSVivek Gautam #include <asm/unaligned.h> /* get_unaligned() */ 3923cd1385SRemy Bohmer 4023cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 4123cd1385SRemy Bohmer 4223cd1385SRemy Bohmer /* CONTROL REQUEST SUPPORT */ 4323cd1385SRemy Bohmer 4423cd1385SRemy Bohmer /* 4523cd1385SRemy Bohmer * USB directions 4623cd1385SRemy Bohmer * 4723cd1385SRemy Bohmer * This bit flag is used in endpoint descriptors' bEndpointAddress field. 4823cd1385SRemy Bohmer * It's also one of three fields in control requests bRequestType. 4923cd1385SRemy Bohmer */ 5023cd1385SRemy Bohmer #define USB_DIR_OUT 0 /* to device */ 5123cd1385SRemy Bohmer #define USB_DIR_IN 0x80 /* to host */ 5223cd1385SRemy Bohmer 5323cd1385SRemy Bohmer /* 5423cd1385SRemy Bohmer * USB types, the second of three bRequestType fields 5523cd1385SRemy Bohmer */ 5623cd1385SRemy Bohmer #define USB_TYPE_MASK (0x03 << 5) 5723cd1385SRemy Bohmer #define USB_TYPE_STANDARD (0x00 << 5) 5823cd1385SRemy Bohmer #define USB_TYPE_CLASS (0x01 << 5) 5923cd1385SRemy Bohmer #define USB_TYPE_VENDOR (0x02 << 5) 6023cd1385SRemy Bohmer #define USB_TYPE_RESERVED (0x03 << 5) 6123cd1385SRemy Bohmer 6223cd1385SRemy Bohmer /* 6323cd1385SRemy Bohmer * USB recipients, the third of three bRequestType fields 6423cd1385SRemy Bohmer */ 6523cd1385SRemy Bohmer #define USB_RECIP_MASK 0x1f 6623cd1385SRemy Bohmer #define USB_RECIP_DEVICE 0x00 6723cd1385SRemy Bohmer #define USB_RECIP_INTERFACE 0x01 6823cd1385SRemy Bohmer #define USB_RECIP_ENDPOINT 0x02 6923cd1385SRemy Bohmer #define USB_RECIP_OTHER 0x03 7023cd1385SRemy Bohmer /* From Wireless USB 1.0 */ 7123cd1385SRemy Bohmer #define USB_RECIP_PORT 0x04 7223cd1385SRemy Bohmer #define USB_RECIP_RPIPE 0x05 7323cd1385SRemy Bohmer 7423cd1385SRemy Bohmer /* 7523cd1385SRemy Bohmer * Standard requests, for the bRequest field of a SETUP packet. 7623cd1385SRemy Bohmer * 7723cd1385SRemy Bohmer * These are qualified by the bRequestType field, so that for example 7823cd1385SRemy Bohmer * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved 7923cd1385SRemy Bohmer * by a GET_STATUS request. 8023cd1385SRemy Bohmer */ 8123cd1385SRemy Bohmer #define USB_REQ_GET_STATUS 0x00 8223cd1385SRemy Bohmer #define USB_REQ_CLEAR_FEATURE 0x01 8323cd1385SRemy Bohmer #define USB_REQ_SET_FEATURE 0x03 8423cd1385SRemy Bohmer #define USB_REQ_SET_ADDRESS 0x05 8523cd1385SRemy Bohmer #define USB_REQ_GET_DESCRIPTOR 0x06 8623cd1385SRemy Bohmer #define USB_REQ_SET_DESCRIPTOR 0x07 8723cd1385SRemy Bohmer #define USB_REQ_GET_CONFIGURATION 0x08 8823cd1385SRemy Bohmer #define USB_REQ_SET_CONFIGURATION 0x09 8923cd1385SRemy Bohmer #define USB_REQ_GET_INTERFACE 0x0A 9023cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE 0x0B 9123cd1385SRemy Bohmer #define USB_REQ_SYNCH_FRAME 0x0C 9282651c39SIlya Yanok #define USB_REQ_SET_SEL 0x30 9382651c39SIlya Yanok #define USB_REQ_SET_ISOCH_DELAY 0x31 9423cd1385SRemy Bohmer 9523cd1385SRemy Bohmer #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */ 9623cd1385SRemy Bohmer #define USB_REQ_GET_ENCRYPTION 0x0E 9723cd1385SRemy Bohmer #define USB_REQ_RPIPE_ABORT 0x0E 9823cd1385SRemy Bohmer #define USB_REQ_SET_HANDSHAKE 0x0F 9923cd1385SRemy Bohmer #define USB_REQ_RPIPE_RESET 0x0F 10023cd1385SRemy Bohmer #define USB_REQ_GET_HANDSHAKE 0x10 10123cd1385SRemy Bohmer #define USB_REQ_SET_CONNECTION 0x11 10223cd1385SRemy Bohmer #define USB_REQ_SET_SECURITY_DATA 0x12 10323cd1385SRemy Bohmer #define USB_REQ_GET_SECURITY_DATA 0x13 10423cd1385SRemy Bohmer #define USB_REQ_SET_WUSB_DATA 0x14 10523cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_WRITE 0x15 10623cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_READ 0x16 10723cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE_DS 0x17 10823cd1385SRemy Bohmer 10982651c39SIlya Yanok /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command, 11082651c39SIlya Yanok * used by hubs to put ports into a new L1 suspend state, except that it 11182651c39SIlya Yanok * forgot to define its number ... 11282651c39SIlya Yanok */ 11382651c39SIlya Yanok 11423cd1385SRemy Bohmer /* 11523cd1385SRemy Bohmer * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and 11623cd1385SRemy Bohmer * are read as a bit array returned by USB_REQ_GET_STATUS. (So there 11782651c39SIlya Yanok * are at most sixteen features of each type.) Hubs may also support a 11882651c39SIlya Yanok * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend. 11923cd1385SRemy Bohmer */ 12023cd1385SRemy Bohmer #define USB_DEVICE_SELF_POWERED 0 /* (read only) */ 12123cd1385SRemy Bohmer #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */ 12223cd1385SRemy Bohmer #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */ 12323cd1385SRemy Bohmer #define USB_DEVICE_BATTERY 2 /* (wireless) */ 12423cd1385SRemy Bohmer #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */ 12523cd1385SRemy Bohmer #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/ 12623cd1385SRemy Bohmer #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */ 12723cd1385SRemy Bohmer #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */ 12823cd1385SRemy Bohmer #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */ 12923cd1385SRemy Bohmer 13082651c39SIlya Yanok /* 13182651c39SIlya Yanok * Test Mode Selectors 13282651c39SIlya Yanok * See USB 2.0 spec Table 9-7 13382651c39SIlya Yanok */ 13482651c39SIlya Yanok #define TEST_J 1 13582651c39SIlya Yanok #define TEST_K 2 13682651c39SIlya Yanok #define TEST_SE0_NAK 3 13782651c39SIlya Yanok #define TEST_PACKET 4 13882651c39SIlya Yanok #define TEST_FORCE_EN 5 13982651c39SIlya Yanok 14082651c39SIlya Yanok /* 14182651c39SIlya Yanok * New Feature Selectors as added by USB 3.0 14282651c39SIlya Yanok * See USB 3.0 spec Table 9-6 14382651c39SIlya Yanok */ 14482651c39SIlya Yanok #define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */ 14582651c39SIlya Yanok #define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */ 14682651c39SIlya Yanok #define USB_DEVICE_LTM_ENABLE 50 /* dev may send LTM */ 14782651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND 0 /* function suspend */ 14882651c39SIlya Yanok 14982651c39SIlya Yanok #define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00 15082651c39SIlya Yanok /* 15182651c39SIlya Yanok * Suspend Options, Table 9-7 USB 3.0 spec 15282651c39SIlya Yanok */ 15382651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0)) 15482651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1)) 15582651c39SIlya Yanok 15623cd1385SRemy Bohmer #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */ 15723cd1385SRemy Bohmer 15882651c39SIlya Yanok /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */ 15982651c39SIlya Yanok #define USB_DEV_STAT_U1_ENABLED 2 /* transition into U1 state */ 16082651c39SIlya Yanok #define USB_DEV_STAT_U2_ENABLED 3 /* transition into U2 state */ 16182651c39SIlya Yanok #define USB_DEV_STAT_LTM_ENABLED 4 /* Latency tolerance messages */ 16223cd1385SRemy Bohmer 16323cd1385SRemy Bohmer /** 16423cd1385SRemy Bohmer * struct usb_ctrlrequest - SETUP data for a USB device control request 16523cd1385SRemy Bohmer * @bRequestType: matches the USB bmRequestType field 16623cd1385SRemy Bohmer * @bRequest: matches the USB bRequest field 16723cd1385SRemy Bohmer * @wValue: matches the USB wValue field (le16 byte order) 16823cd1385SRemy Bohmer * @wIndex: matches the USB wIndex field (le16 byte order) 16923cd1385SRemy Bohmer * @wLength: matches the USB wLength field (le16 byte order) 17023cd1385SRemy Bohmer * 17123cd1385SRemy Bohmer * This structure is used to send control requests to a USB device. It matches 17223cd1385SRemy Bohmer * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the 17323cd1385SRemy Bohmer * USB spec for a fuller description of the different fields, and what they are 17423cd1385SRemy Bohmer * used for. 17523cd1385SRemy Bohmer * 17623cd1385SRemy Bohmer * Note that the driver for any interface can issue control requests. 17723cd1385SRemy Bohmer * For most devices, interfaces don't coordinate with each other, so 17823cd1385SRemy Bohmer * such requests may be made at any time. 17923cd1385SRemy Bohmer */ 18023cd1385SRemy Bohmer struct usb_ctrlrequest { 18123cd1385SRemy Bohmer __u8 bRequestType; 18223cd1385SRemy Bohmer __u8 bRequest; 18323cd1385SRemy Bohmer __le16 wValue; 18423cd1385SRemy Bohmer __le16 wIndex; 18523cd1385SRemy Bohmer __le16 wLength; 18623cd1385SRemy Bohmer } __attribute__ ((packed)); 18723cd1385SRemy Bohmer 18823cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 18923cd1385SRemy Bohmer 19023cd1385SRemy Bohmer /* 19123cd1385SRemy Bohmer * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or 19223cd1385SRemy Bohmer * (rarely) accepted by SET_DESCRIPTOR. 19323cd1385SRemy Bohmer * 19423cd1385SRemy Bohmer * Note that all multi-byte values here are encoded in little endian 19582651c39SIlya Yanok * byte order "on the wire". Within the kernel and when exposed 19682651c39SIlya Yanok * through the Linux-USB APIs, they are not converted to cpu byte 19782651c39SIlya Yanok * order; it is the responsibility of the client code to do this. 19882651c39SIlya Yanok * The single exception is when device and configuration descriptors (but 19982651c39SIlya Yanok * not other descriptors) are read from usbfs (i.e. /proc/bus/usb/BBB/DDD); 20082651c39SIlya Yanok * in this case the fields are converted to host endianness by the kernel. 20123cd1385SRemy Bohmer */ 20223cd1385SRemy Bohmer 20323cd1385SRemy Bohmer /* 20423cd1385SRemy Bohmer * Descriptor types ... USB 2.0 spec table 9.5 20523cd1385SRemy Bohmer */ 20623cd1385SRemy Bohmer #define USB_DT_DEVICE 0x01 20723cd1385SRemy Bohmer #define USB_DT_CONFIG 0x02 20823cd1385SRemy Bohmer #define USB_DT_STRING 0x03 20923cd1385SRemy Bohmer #define USB_DT_INTERFACE 0x04 21023cd1385SRemy Bohmer #define USB_DT_ENDPOINT 0x05 21123cd1385SRemy Bohmer #define USB_DT_DEVICE_QUALIFIER 0x06 21223cd1385SRemy Bohmer #define USB_DT_OTHER_SPEED_CONFIG 0x07 21323cd1385SRemy Bohmer #define USB_DT_INTERFACE_POWER 0x08 21423cd1385SRemy Bohmer /* these are from a minor usb 2.0 revision (ECN) */ 21523cd1385SRemy Bohmer #define USB_DT_OTG 0x09 21623cd1385SRemy Bohmer #define USB_DT_DEBUG 0x0a 21723cd1385SRemy Bohmer #define USB_DT_INTERFACE_ASSOCIATION 0x0b 21823cd1385SRemy Bohmer /* these are from the Wireless USB spec */ 21923cd1385SRemy Bohmer #define USB_DT_SECURITY 0x0c 22023cd1385SRemy Bohmer #define USB_DT_KEY 0x0d 22123cd1385SRemy Bohmer #define USB_DT_ENCRYPTION_TYPE 0x0e 22223cd1385SRemy Bohmer #define USB_DT_BOS 0x0f 22323cd1385SRemy Bohmer #define USB_DT_DEVICE_CAPABILITY 0x10 22423cd1385SRemy Bohmer #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11 22523cd1385SRemy Bohmer #define USB_DT_WIRE_ADAPTER 0x21 22623cd1385SRemy Bohmer #define USB_DT_RPIPE 0x22 22782651c39SIlya Yanok #define USB_DT_CS_RADIO_CONTROL 0x23 22882651c39SIlya Yanok /* From the T10 UAS specification */ 22982651c39SIlya Yanok #define USB_DT_PIPE_USAGE 0x24 23082651c39SIlya Yanok /* From the USB 3.0 spec */ 23182651c39SIlya Yanok #define USB_DT_SS_ENDPOINT_COMP 0x30 23223cd1385SRemy Bohmer 23323cd1385SRemy Bohmer /* Conventional codes for class-specific descriptors. The convention is 23423cd1385SRemy Bohmer * defined in the USB "Common Class" Spec (3.11). Individual class specs 23523cd1385SRemy Bohmer * are authoritative for their usage, not the "common class" writeup. 23623cd1385SRemy Bohmer */ 23723cd1385SRemy Bohmer #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE) 23823cd1385SRemy Bohmer #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG) 23923cd1385SRemy Bohmer #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING) 24023cd1385SRemy Bohmer #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE) 24123cd1385SRemy Bohmer #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT) 24223cd1385SRemy Bohmer 24323cd1385SRemy Bohmer /* All standard descriptors have these 2 fields at the beginning */ 24423cd1385SRemy Bohmer struct usb_descriptor_header { 24523cd1385SRemy Bohmer __u8 bLength; 24623cd1385SRemy Bohmer __u8 bDescriptorType; 24723cd1385SRemy Bohmer } __attribute__ ((packed)); 24823cd1385SRemy Bohmer 24982651c39SIlya Yanok 25082651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 25182651c39SIlya Yanok 25282651c39SIlya Yanok /* USB_DT_DEVICE: Device descriptor */ 25382651c39SIlya Yanok struct usb_device_descriptor { 25482651c39SIlya Yanok __u8 bLength; 25582651c39SIlya Yanok __u8 bDescriptorType; 25682651c39SIlya Yanok 25782651c39SIlya Yanok __le16 bcdUSB; 25882651c39SIlya Yanok __u8 bDeviceClass; 25982651c39SIlya Yanok __u8 bDeviceSubClass; 26082651c39SIlya Yanok __u8 bDeviceProtocol; 26182651c39SIlya Yanok __u8 bMaxPacketSize0; 26282651c39SIlya Yanok __le16 idVendor; 26382651c39SIlya Yanok __le16 idProduct; 26482651c39SIlya Yanok __le16 bcdDevice; 26582651c39SIlya Yanok __u8 iManufacturer; 26682651c39SIlya Yanok __u8 iProduct; 26782651c39SIlya Yanok __u8 iSerialNumber; 26882651c39SIlya Yanok __u8 bNumConfigurations; 26982651c39SIlya Yanok } __attribute__ ((packed)); 27082651c39SIlya Yanok 27123cd1385SRemy Bohmer #define USB_DT_DEVICE_SIZE 18 27223cd1385SRemy Bohmer 27323cd1385SRemy Bohmer 27423cd1385SRemy Bohmer /* 27523cd1385SRemy Bohmer * Device and/or Interface Class codes 27623cd1385SRemy Bohmer * as found in bDeviceClass or bInterfaceClass 27723cd1385SRemy Bohmer * and defined by www.usb.org documents 27823cd1385SRemy Bohmer */ 27923cd1385SRemy Bohmer #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ 28023cd1385SRemy Bohmer #define USB_CLASS_AUDIO 1 28123cd1385SRemy Bohmer #define USB_CLASS_COMM 2 28223cd1385SRemy Bohmer #define USB_CLASS_HID 3 28323cd1385SRemy Bohmer #define USB_CLASS_PHYSICAL 5 28423cd1385SRemy Bohmer #define USB_CLASS_STILL_IMAGE 6 28523cd1385SRemy Bohmer #define USB_CLASS_PRINTER 7 28623cd1385SRemy Bohmer #define USB_CLASS_MASS_STORAGE 8 28723cd1385SRemy Bohmer #define USB_CLASS_HUB 9 28823cd1385SRemy Bohmer #define USB_CLASS_CDC_DATA 0x0a 28923cd1385SRemy Bohmer #define USB_CLASS_CSCID 0x0b /* chip+ smart card */ 29023cd1385SRemy Bohmer #define USB_CLASS_CONTENT_SEC 0x0d /* content security */ 29123cd1385SRemy Bohmer #define USB_CLASS_VIDEO 0x0e 29223cd1385SRemy Bohmer #define USB_CLASS_WIRELESS_CONTROLLER 0xe0 29323cd1385SRemy Bohmer #define USB_CLASS_MISC 0xef 29423cd1385SRemy Bohmer #define USB_CLASS_APP_SPEC 0xfe 29523cd1385SRemy Bohmer #define USB_CLASS_VENDOR_SPEC 0xff 29623cd1385SRemy Bohmer 29782651c39SIlya Yanok #define USB_SUBCLASS_VENDOR_SPEC 0xff 29882651c39SIlya Yanok 29923cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 30023cd1385SRemy Bohmer 30123cd1385SRemy Bohmer /* USB_DT_CONFIG: Configuration descriptor information. 30223cd1385SRemy Bohmer * 30323cd1385SRemy Bohmer * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the 30423cd1385SRemy Bohmer * descriptor type is different. Highspeed-capable devices can look 30523cd1385SRemy Bohmer * different depending on what speed they're currently running. Only 30623cd1385SRemy Bohmer * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG 30723cd1385SRemy Bohmer * descriptors. 30823cd1385SRemy Bohmer */ 30923cd1385SRemy Bohmer struct usb_config_descriptor { 31023cd1385SRemy Bohmer __u8 bLength; 31123cd1385SRemy Bohmer __u8 bDescriptorType; 31223cd1385SRemy Bohmer 31323cd1385SRemy Bohmer __le16 wTotalLength; 31423cd1385SRemy Bohmer __u8 bNumInterfaces; 31523cd1385SRemy Bohmer __u8 bConfigurationValue; 31623cd1385SRemy Bohmer __u8 iConfiguration; 31723cd1385SRemy Bohmer __u8 bmAttributes; 31823cd1385SRemy Bohmer __u8 bMaxPower; 31923cd1385SRemy Bohmer } __attribute__ ((packed)); 32023cd1385SRemy Bohmer 32123cd1385SRemy Bohmer #define USB_DT_CONFIG_SIZE 9 32223cd1385SRemy Bohmer 32323cd1385SRemy Bohmer /* from config descriptor bmAttributes */ 32423cd1385SRemy Bohmer #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */ 32523cd1385SRemy Bohmer #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ 32623cd1385SRemy Bohmer #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ 32723cd1385SRemy Bohmer #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */ 32823cd1385SRemy Bohmer 32982651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 33082651c39SIlya Yanok 33182651c39SIlya Yanok /* USB_DT_STRING: String descriptor */ 33282651c39SIlya Yanok struct usb_string_descriptor { 33382651c39SIlya Yanok __u8 bLength; 33482651c39SIlya Yanok __u8 bDescriptorType; 33582651c39SIlya Yanok 33682651c39SIlya Yanok __le16 wData[1]; /* UTF-16LE encoded */ 33782651c39SIlya Yanok } __attribute__ ((packed)); 33882651c39SIlya Yanok 33923cd1385SRemy Bohmer /* note that "string" zero is special, it holds language codes that 34023cd1385SRemy Bohmer * the device supports, not Unicode characters. 34123cd1385SRemy Bohmer */ 34223cd1385SRemy Bohmer 34382651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 34482651c39SIlya Yanok 34582651c39SIlya Yanok /* USB_DT_INTERFACE: Interface descriptor */ 34682651c39SIlya Yanok struct usb_interface_descriptor { 34782651c39SIlya Yanok __u8 bLength; 34882651c39SIlya Yanok __u8 bDescriptorType; 34982651c39SIlya Yanok 35082651c39SIlya Yanok __u8 bInterfaceNumber; 35182651c39SIlya Yanok __u8 bAlternateSetting; 35282651c39SIlya Yanok __u8 bNumEndpoints; 35382651c39SIlya Yanok __u8 bInterfaceClass; 35482651c39SIlya Yanok __u8 bInterfaceSubClass; 35582651c39SIlya Yanok __u8 bInterfaceProtocol; 35682651c39SIlya Yanok __u8 iInterface; 35782651c39SIlya Yanok } __attribute__ ((packed)); 35882651c39SIlya Yanok 35923cd1385SRemy Bohmer #define USB_DT_INTERFACE_SIZE 9 36082651c39SIlya Yanok 36182651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 36282651c39SIlya Yanok 36382651c39SIlya Yanok /* USB_DT_ENDPOINT: Endpoint descriptor */ 36482651c39SIlya Yanok struct usb_endpoint_descriptor { 36582651c39SIlya Yanok __u8 bLength; 36682651c39SIlya Yanok __u8 bDescriptorType; 36782651c39SIlya Yanok 36882651c39SIlya Yanok __u8 bEndpointAddress; 36982651c39SIlya Yanok __u8 bmAttributes; 37082651c39SIlya Yanok __le16 wMaxPacketSize; 37182651c39SIlya Yanok __u8 bInterval; 37282651c39SIlya Yanok 37382651c39SIlya Yanok /* NOTE: these two are _only_ in audio endpoints. */ 37482651c39SIlya Yanok /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */ 37582651c39SIlya Yanok __u8 bRefresh; 37682651c39SIlya Yanok __u8 bSynchAddress; 37782651c39SIlya Yanok } __attribute__ ((packed)); 37882651c39SIlya Yanok 37923cd1385SRemy Bohmer #define USB_DT_ENDPOINT_SIZE 7 38023cd1385SRemy Bohmer #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ 38123cd1385SRemy Bohmer 38223cd1385SRemy Bohmer 38323cd1385SRemy Bohmer /* 38423cd1385SRemy Bohmer * Endpoints 38523cd1385SRemy Bohmer */ 38623cd1385SRemy Bohmer #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ 38723cd1385SRemy Bohmer #define USB_ENDPOINT_DIR_MASK 0x80 38823cd1385SRemy Bohmer 38923cd1385SRemy Bohmer #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ 39023cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_CONTROL 0 39123cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_ISOC 1 39223cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_BULK 2 39323cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_INT 3 39423cd1385SRemy Bohmer #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 39523cd1385SRemy Bohmer 39682651c39SIlya Yanok /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */ 39782651c39SIlya Yanok #define USB_ENDPOINT_INTRTYPE 0x30 39882651c39SIlya Yanok #define USB_ENDPOINT_INTR_PERIODIC (0 << 4) 39982651c39SIlya Yanok #define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4) 40082651c39SIlya Yanok 40182651c39SIlya Yanok #define USB_ENDPOINT_SYNCTYPE 0x0c 40282651c39SIlya Yanok #define USB_ENDPOINT_SYNC_NONE (0 << 2) 40382651c39SIlya Yanok #define USB_ENDPOINT_SYNC_ASYNC (1 << 2) 40482651c39SIlya Yanok #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2) 40582651c39SIlya Yanok #define USB_ENDPOINT_SYNC_SYNC (3 << 2) 40682651c39SIlya Yanok 40782651c39SIlya Yanok #define USB_ENDPOINT_USAGE_MASK 0x30 40882651c39SIlya Yanok #define USB_ENDPOINT_USAGE_DATA 0x00 40982651c39SIlya Yanok #define USB_ENDPOINT_USAGE_FEEDBACK 0x10 41082651c39SIlya Yanok #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */ 41182651c39SIlya Yanok 41282651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 41382651c39SIlya Yanok 41482651c39SIlya Yanok /** 41582651c39SIlya Yanok * usb_endpoint_num - get the endpoint's number 41682651c39SIlya Yanok * @epd: endpoint to be checked 41782651c39SIlya Yanok * 41882651c39SIlya Yanok * Returns @epd's number: 0 to 15. 41982651c39SIlya Yanok */ 42082651c39SIlya Yanok static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd) 42182651c39SIlya Yanok { 42282651c39SIlya Yanok return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 42382651c39SIlya Yanok } 42482651c39SIlya Yanok 42582651c39SIlya Yanok /** 42682651c39SIlya Yanok * usb_endpoint_type - get the endpoint's transfer type 42782651c39SIlya Yanok * @epd: endpoint to be checked 42882651c39SIlya Yanok * 42982651c39SIlya Yanok * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according 43082651c39SIlya Yanok * to @epd's transfer type. 43182651c39SIlya Yanok */ 43282651c39SIlya Yanok static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd) 43382651c39SIlya Yanok { 43482651c39SIlya Yanok return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 43582651c39SIlya Yanok } 43682651c39SIlya Yanok 43782651c39SIlya Yanok /** 43882651c39SIlya Yanok * usb_endpoint_dir_in - check if the endpoint has IN direction 43982651c39SIlya Yanok * @epd: endpoint to be checked 44082651c39SIlya Yanok * 44182651c39SIlya Yanok * Returns true if the endpoint is of type IN, otherwise it returns false. 44282651c39SIlya Yanok */ 44382651c39SIlya Yanok static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) 44482651c39SIlya Yanok { 44582651c39SIlya Yanok return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); 44682651c39SIlya Yanok } 44782651c39SIlya Yanok 44882651c39SIlya Yanok /** 44982651c39SIlya Yanok * usb_endpoint_dir_out - check if the endpoint has OUT direction 45082651c39SIlya Yanok * @epd: endpoint to be checked 45182651c39SIlya Yanok * 45282651c39SIlya Yanok * Returns true if the endpoint is of type OUT, otherwise it returns false. 45382651c39SIlya Yanok */ 45482651c39SIlya Yanok static inline int usb_endpoint_dir_out( 45582651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 45682651c39SIlya Yanok { 45782651c39SIlya Yanok return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); 45882651c39SIlya Yanok } 45982651c39SIlya Yanok 46082651c39SIlya Yanok /** 46182651c39SIlya Yanok * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type 46282651c39SIlya Yanok * @epd: endpoint to be checked 46382651c39SIlya Yanok * 46482651c39SIlya Yanok * Returns true if the endpoint is of type bulk, otherwise it returns false. 46582651c39SIlya Yanok */ 46682651c39SIlya Yanok static inline int usb_endpoint_xfer_bulk( 46782651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 46882651c39SIlya Yanok { 46982651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 47082651c39SIlya Yanok USB_ENDPOINT_XFER_BULK); 47182651c39SIlya Yanok } 47282651c39SIlya Yanok 47382651c39SIlya Yanok /** 47482651c39SIlya Yanok * usb_endpoint_xfer_control - check if the endpoint has control transfer type 47582651c39SIlya Yanok * @epd: endpoint to be checked 47682651c39SIlya Yanok * 47782651c39SIlya Yanok * Returns true if the endpoint is of type control, otherwise it returns false. 47882651c39SIlya Yanok */ 47982651c39SIlya Yanok static inline int usb_endpoint_xfer_control( 48082651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 48182651c39SIlya Yanok { 48282651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 48382651c39SIlya Yanok USB_ENDPOINT_XFER_CONTROL); 48482651c39SIlya Yanok } 48582651c39SIlya Yanok 48682651c39SIlya Yanok /** 48782651c39SIlya Yanok * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type 48882651c39SIlya Yanok * @epd: endpoint to be checked 48982651c39SIlya Yanok * 49082651c39SIlya Yanok * Returns true if the endpoint is of type interrupt, otherwise it returns 49182651c39SIlya Yanok * false. 49282651c39SIlya Yanok */ 49382651c39SIlya Yanok static inline int usb_endpoint_xfer_int( 49482651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 49582651c39SIlya Yanok { 49682651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 49782651c39SIlya Yanok USB_ENDPOINT_XFER_INT); 49882651c39SIlya Yanok } 49982651c39SIlya Yanok 50082651c39SIlya Yanok /** 50182651c39SIlya Yanok * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type 50282651c39SIlya Yanok * @epd: endpoint to be checked 50382651c39SIlya Yanok * 50482651c39SIlya Yanok * Returns true if the endpoint is of type isochronous, otherwise it returns 50582651c39SIlya Yanok * false. 50682651c39SIlya Yanok */ 50782651c39SIlya Yanok static inline int usb_endpoint_xfer_isoc( 50882651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 50982651c39SIlya Yanok { 51082651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 51182651c39SIlya Yanok USB_ENDPOINT_XFER_ISOC); 51282651c39SIlya Yanok } 51382651c39SIlya Yanok 51482651c39SIlya Yanok /** 51582651c39SIlya Yanok * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN 51682651c39SIlya Yanok * @epd: endpoint to be checked 51782651c39SIlya Yanok * 51882651c39SIlya Yanok * Returns true if the endpoint has bulk transfer type and IN direction, 51982651c39SIlya Yanok * otherwise it returns false. 52082651c39SIlya Yanok */ 52182651c39SIlya Yanok static inline int usb_endpoint_is_bulk_in( 52282651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 52382651c39SIlya Yanok { 52482651c39SIlya Yanok return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd); 52582651c39SIlya Yanok } 52682651c39SIlya Yanok 52782651c39SIlya Yanok /** 52882651c39SIlya Yanok * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT 52982651c39SIlya Yanok * @epd: endpoint to be checked 53082651c39SIlya Yanok * 53182651c39SIlya Yanok * Returns true if the endpoint has bulk transfer type and OUT direction, 53282651c39SIlya Yanok * otherwise it returns false. 53382651c39SIlya Yanok */ 53482651c39SIlya Yanok static inline int usb_endpoint_is_bulk_out( 53582651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 53682651c39SIlya Yanok { 53782651c39SIlya Yanok return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd); 53882651c39SIlya Yanok } 53982651c39SIlya Yanok 54082651c39SIlya Yanok /** 54182651c39SIlya Yanok * usb_endpoint_is_int_in - check if the endpoint is interrupt IN 54282651c39SIlya Yanok * @epd: endpoint to be checked 54382651c39SIlya Yanok * 54482651c39SIlya Yanok * Returns true if the endpoint has interrupt transfer type and IN direction, 54582651c39SIlya Yanok * otherwise it returns false. 54682651c39SIlya Yanok */ 54782651c39SIlya Yanok static inline int usb_endpoint_is_int_in( 54882651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 54982651c39SIlya Yanok { 55082651c39SIlya Yanok return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd); 55182651c39SIlya Yanok } 55282651c39SIlya Yanok 55382651c39SIlya Yanok /** 55482651c39SIlya Yanok * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT 55582651c39SIlya Yanok * @epd: endpoint to be checked 55682651c39SIlya Yanok * 55782651c39SIlya Yanok * Returns true if the endpoint has interrupt transfer type and OUT direction, 55882651c39SIlya Yanok * otherwise it returns false. 55982651c39SIlya Yanok */ 56082651c39SIlya Yanok static inline int usb_endpoint_is_int_out( 56182651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 56282651c39SIlya Yanok { 56382651c39SIlya Yanok return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd); 56482651c39SIlya Yanok } 56582651c39SIlya Yanok 56682651c39SIlya Yanok /** 56782651c39SIlya Yanok * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN 56882651c39SIlya Yanok * @epd: endpoint to be checked 56982651c39SIlya Yanok * 57082651c39SIlya Yanok * Returns true if the endpoint has isochronous transfer type and IN direction, 57182651c39SIlya Yanok * otherwise it returns false. 57282651c39SIlya Yanok */ 57382651c39SIlya Yanok static inline int usb_endpoint_is_isoc_in( 57482651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 57582651c39SIlya Yanok { 57682651c39SIlya Yanok return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd); 57782651c39SIlya Yanok } 57882651c39SIlya Yanok 57982651c39SIlya Yanok /** 58082651c39SIlya Yanok * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT 58182651c39SIlya Yanok * @epd: endpoint to be checked 58282651c39SIlya Yanok * 58382651c39SIlya Yanok * Returns true if the endpoint has isochronous transfer type and OUT direction, 58482651c39SIlya Yanok * otherwise it returns false. 58582651c39SIlya Yanok */ 58682651c39SIlya Yanok static inline int usb_endpoint_is_isoc_out( 58782651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 58882651c39SIlya Yanok { 58982651c39SIlya Yanok return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd); 59082651c39SIlya Yanok } 59182651c39SIlya Yanok 59282651c39SIlya Yanok /** 59382651c39SIlya Yanok * usb_endpoint_maxp - get endpoint's max packet size 59482651c39SIlya Yanok * @epd: endpoint to be checked 59582651c39SIlya Yanok * 59682651c39SIlya Yanok * Returns @epd's max packet 59782651c39SIlya Yanok */ 59882651c39SIlya Yanok static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd) 59982651c39SIlya Yanok { 600f903a20dSVivek Gautam return __le16_to_cpu(get_unaligned(&epd->wMaxPacketSize)); 60182651c39SIlya Yanok } 60282651c39SIlya Yanok 60382651c39SIlya Yanok static inline int usb_endpoint_interrupt_type( 60482651c39SIlya Yanok const struct usb_endpoint_descriptor *epd) 60582651c39SIlya Yanok { 60682651c39SIlya Yanok return epd->bmAttributes & USB_ENDPOINT_INTRTYPE; 60782651c39SIlya Yanok } 60882651c39SIlya Yanok 60982651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 61082651c39SIlya Yanok 61182651c39SIlya Yanok /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */ 61282651c39SIlya Yanok struct usb_ss_ep_comp_descriptor { 61382651c39SIlya Yanok __u8 bLength; 61482651c39SIlya Yanok __u8 bDescriptorType; 61582651c39SIlya Yanok 61682651c39SIlya Yanok __u8 bMaxBurst; 61782651c39SIlya Yanok __u8 bmAttributes; 61882651c39SIlya Yanok __le16 wBytesPerInterval; 61982651c39SIlya Yanok } __attribute__ ((packed)); 62082651c39SIlya Yanok 62182651c39SIlya Yanok #define USB_DT_SS_EP_COMP_SIZE 6 62282651c39SIlya Yanok 62382651c39SIlya Yanok /* Bits 4:0 of bmAttributes if this is a bulk endpoint */ 62482651c39SIlya Yanok static inline int 62582651c39SIlya Yanok usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp) 62682651c39SIlya Yanok { 62782651c39SIlya Yanok int max_streams; 62882651c39SIlya Yanok 62982651c39SIlya Yanok if (!comp) 63082651c39SIlya Yanok return 0; 63182651c39SIlya Yanok 63282651c39SIlya Yanok max_streams = comp->bmAttributes & 0x1f; 63382651c39SIlya Yanok 63482651c39SIlya Yanok if (!max_streams) 63582651c39SIlya Yanok return 0; 63682651c39SIlya Yanok 63782651c39SIlya Yanok max_streams = 1 << max_streams; 63882651c39SIlya Yanok 63982651c39SIlya Yanok return max_streams; 64082651c39SIlya Yanok } 64182651c39SIlya Yanok 64282651c39SIlya Yanok /* Bits 1:0 of bmAttributes if this is an isoc endpoint */ 64382651c39SIlya Yanok #define USB_SS_MULT(p) (1 + ((p) & 0x3)) 64423cd1385SRemy Bohmer 64523cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 64623cd1385SRemy Bohmer 64723cd1385SRemy Bohmer /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */ 64823cd1385SRemy Bohmer struct usb_qualifier_descriptor { 64923cd1385SRemy Bohmer __u8 bLength; 65023cd1385SRemy Bohmer __u8 bDescriptorType; 65123cd1385SRemy Bohmer 65223cd1385SRemy Bohmer __le16 bcdUSB; 65323cd1385SRemy Bohmer __u8 bDeviceClass; 65423cd1385SRemy Bohmer __u8 bDeviceSubClass; 65523cd1385SRemy Bohmer __u8 bDeviceProtocol; 65623cd1385SRemy Bohmer __u8 bMaxPacketSize0; 65723cd1385SRemy Bohmer __u8 bNumConfigurations; 65823cd1385SRemy Bohmer __u8 bRESERVED; 65923cd1385SRemy Bohmer } __attribute__ ((packed)); 66023cd1385SRemy Bohmer 66123cd1385SRemy Bohmer 66223cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 66323cd1385SRemy Bohmer 66423cd1385SRemy Bohmer /* USB_DT_OTG (from OTG 1.0a supplement) */ 66523cd1385SRemy Bohmer struct usb_otg_descriptor { 66623cd1385SRemy Bohmer __u8 bLength; 66723cd1385SRemy Bohmer __u8 bDescriptorType; 66823cd1385SRemy Bohmer 66923cd1385SRemy Bohmer __u8 bmAttributes; /* support for HNP, SRP, etc */ 67023cd1385SRemy Bohmer } __attribute__ ((packed)); 67123cd1385SRemy Bohmer 67223cd1385SRemy Bohmer /* from usb_otg_descriptor.bmAttributes */ 67323cd1385SRemy Bohmer #define USB_OTG_SRP (1 << 0) 67423cd1385SRemy Bohmer #define USB_OTG_HNP (1 << 1) /* swap host/device roles */ 67523cd1385SRemy Bohmer 67623cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 67723cd1385SRemy Bohmer 67823cd1385SRemy Bohmer /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */ 67923cd1385SRemy Bohmer struct usb_debug_descriptor { 68023cd1385SRemy Bohmer __u8 bLength; 68123cd1385SRemy Bohmer __u8 bDescriptorType; 68223cd1385SRemy Bohmer 68323cd1385SRemy Bohmer /* bulk endpoints with 8 byte maxpacket */ 68423cd1385SRemy Bohmer __u8 bDebugInEndpoint; 68523cd1385SRemy Bohmer __u8 bDebugOutEndpoint; 68623cd1385SRemy Bohmer } __attribute__((packed)); 68723cd1385SRemy Bohmer 68823cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 68923cd1385SRemy Bohmer 69023cd1385SRemy Bohmer /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */ 69123cd1385SRemy Bohmer struct usb_interface_assoc_descriptor { 69223cd1385SRemy Bohmer __u8 bLength; 69323cd1385SRemy Bohmer __u8 bDescriptorType; 69423cd1385SRemy Bohmer 69523cd1385SRemy Bohmer __u8 bFirstInterface; 69623cd1385SRemy Bohmer __u8 bInterfaceCount; 69723cd1385SRemy Bohmer __u8 bFunctionClass; 69823cd1385SRemy Bohmer __u8 bFunctionSubClass; 69923cd1385SRemy Bohmer __u8 bFunctionProtocol; 70023cd1385SRemy Bohmer __u8 iFunction; 70123cd1385SRemy Bohmer } __attribute__ ((packed)); 70223cd1385SRemy Bohmer 70323cd1385SRemy Bohmer 70423cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 70523cd1385SRemy Bohmer 70623cd1385SRemy Bohmer /* USB_DT_SECURITY: group of wireless security descriptors, including 70723cd1385SRemy Bohmer * encryption types available for setting up a CC/association. 70823cd1385SRemy Bohmer */ 70923cd1385SRemy Bohmer struct usb_security_descriptor { 71023cd1385SRemy Bohmer __u8 bLength; 71123cd1385SRemy Bohmer __u8 bDescriptorType; 71223cd1385SRemy Bohmer 71323cd1385SRemy Bohmer __le16 wTotalLength; 71423cd1385SRemy Bohmer __u8 bNumEncryptionTypes; 71523cd1385SRemy Bohmer } __attribute__((packed)); 71623cd1385SRemy Bohmer 71723cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 71823cd1385SRemy Bohmer 71923cd1385SRemy Bohmer /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys 72023cd1385SRemy Bohmer * may be retrieved. 72123cd1385SRemy Bohmer */ 72223cd1385SRemy Bohmer struct usb_key_descriptor { 72323cd1385SRemy Bohmer __u8 bLength; 72423cd1385SRemy Bohmer __u8 bDescriptorType; 72523cd1385SRemy Bohmer 72623cd1385SRemy Bohmer __u8 tTKID[3]; 72723cd1385SRemy Bohmer __u8 bReserved; 72823cd1385SRemy Bohmer __u8 bKeyData[0]; 72923cd1385SRemy Bohmer } __attribute__((packed)); 73023cd1385SRemy Bohmer 73123cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 73223cd1385SRemy Bohmer 73323cd1385SRemy Bohmer /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */ 73423cd1385SRemy Bohmer struct usb_encryption_descriptor { 73523cd1385SRemy Bohmer __u8 bLength; 73623cd1385SRemy Bohmer __u8 bDescriptorType; 73723cd1385SRemy Bohmer 73823cd1385SRemy Bohmer __u8 bEncryptionType; 73923cd1385SRemy Bohmer #define USB_ENC_TYPE_UNSECURE 0 74023cd1385SRemy Bohmer #define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */ 74123cd1385SRemy Bohmer #define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */ 74223cd1385SRemy Bohmer #define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */ 74323cd1385SRemy Bohmer __u8 bEncryptionValue; /* use in SET_ENCRYPTION */ 74423cd1385SRemy Bohmer __u8 bAuthKeyIndex; 74523cd1385SRemy Bohmer } __attribute__((packed)); 74623cd1385SRemy Bohmer 74723cd1385SRemy Bohmer 74823cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 74923cd1385SRemy Bohmer 75082651c39SIlya Yanok /* USB_DT_BOS: group of device-level capabilities */ 75123cd1385SRemy Bohmer struct usb_bos_descriptor { 75223cd1385SRemy Bohmer __u8 bLength; 75323cd1385SRemy Bohmer __u8 bDescriptorType; 75423cd1385SRemy Bohmer 75523cd1385SRemy Bohmer __le16 wTotalLength; 75623cd1385SRemy Bohmer __u8 bNumDeviceCaps; 75723cd1385SRemy Bohmer } __attribute__((packed)); 75823cd1385SRemy Bohmer 75982651c39SIlya Yanok #define USB_DT_BOS_SIZE 5 76023cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 76123cd1385SRemy Bohmer 76223cd1385SRemy Bohmer /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */ 76323cd1385SRemy Bohmer struct usb_dev_cap_header { 76423cd1385SRemy Bohmer __u8 bLength; 76523cd1385SRemy Bohmer __u8 bDescriptorType; 76623cd1385SRemy Bohmer __u8 bDevCapabilityType; 76723cd1385SRemy Bohmer } __attribute__((packed)); 76823cd1385SRemy Bohmer 76923cd1385SRemy Bohmer #define USB_CAP_TYPE_WIRELESS_USB 1 77023cd1385SRemy Bohmer 77123cd1385SRemy Bohmer struct usb_wireless_cap_descriptor { /* Ultra Wide Band */ 77223cd1385SRemy Bohmer __u8 bLength; 77323cd1385SRemy Bohmer __u8 bDescriptorType; 77423cd1385SRemy Bohmer __u8 bDevCapabilityType; 77523cd1385SRemy Bohmer 77623cd1385SRemy Bohmer __u8 bmAttributes; 77723cd1385SRemy Bohmer #define USB_WIRELESS_P2P_DRD (1 << 1) 77823cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_MASK (3 << 2) 77923cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_SELF (1 << 2) 78023cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_DIRECTED (2 << 2) 78123cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_NONE (3 << 2) 78223cd1385SRemy Bohmer __le16 wPHYRates; /* bit rates, Mbps */ 78323cd1385SRemy Bohmer #define USB_WIRELESS_PHY_53 (1 << 0) /* always set */ 78423cd1385SRemy Bohmer #define USB_WIRELESS_PHY_80 (1 << 1) 78523cd1385SRemy Bohmer #define USB_WIRELESS_PHY_107 (1 << 2) /* always set */ 78623cd1385SRemy Bohmer #define USB_WIRELESS_PHY_160 (1 << 3) 78723cd1385SRemy Bohmer #define USB_WIRELESS_PHY_200 (1 << 4) /* always set */ 78823cd1385SRemy Bohmer #define USB_WIRELESS_PHY_320 (1 << 5) 78923cd1385SRemy Bohmer #define USB_WIRELESS_PHY_400 (1 << 6) 79023cd1385SRemy Bohmer #define USB_WIRELESS_PHY_480 (1 << 7) 79123cd1385SRemy Bohmer __u8 bmTFITXPowerInfo; /* TFI power levels */ 79223cd1385SRemy Bohmer __u8 bmFFITXPowerInfo; /* FFI power levels */ 79323cd1385SRemy Bohmer __le16 bmBandGroup; 79423cd1385SRemy Bohmer __u8 bReserved; 79523cd1385SRemy Bohmer } __attribute__((packed)); 79623cd1385SRemy Bohmer 79782651c39SIlya Yanok /* USB 2.0 Extension descriptor */ 79882651c39SIlya Yanok #define USB_CAP_TYPE_EXT 2 79982651c39SIlya Yanok 80082651c39SIlya Yanok struct usb_ext_cap_descriptor { /* Link Power Management */ 80182651c39SIlya Yanok __u8 bLength; 80282651c39SIlya Yanok __u8 bDescriptorType; 80382651c39SIlya Yanok __u8 bDevCapabilityType; 80482651c39SIlya Yanok __le32 bmAttributes; 80582651c39SIlya Yanok #define USB_LPM_SUPPORT (1 << 1) /* supports LPM */ 80682651c39SIlya Yanok #define USB_BESL_SUPPORT (1 << 2) /* supports BESL */ 80782651c39SIlya Yanok #define USB_BESL_BASELINE_VALID (1 << 3) /* Baseline BESL valid*/ 80882651c39SIlya Yanok #define USB_BESL_DEEP_VALID (1 << 4) /* Deep BESL valid */ 80982651c39SIlya Yanok #define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8) 81082651c39SIlya Yanok #define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12) 81182651c39SIlya Yanok } __attribute__((packed)); 81282651c39SIlya Yanok 81382651c39SIlya Yanok #define USB_DT_USB_EXT_CAP_SIZE 7 81482651c39SIlya Yanok 81582651c39SIlya Yanok /* 81682651c39SIlya Yanok * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB 81782651c39SIlya Yanok * specific device level capabilities 81882651c39SIlya Yanok */ 81982651c39SIlya Yanok #define USB_SS_CAP_TYPE 3 82082651c39SIlya Yanok struct usb_ss_cap_descriptor { /* Link Power Management */ 82182651c39SIlya Yanok __u8 bLength; 82282651c39SIlya Yanok __u8 bDescriptorType; 82382651c39SIlya Yanok __u8 bDevCapabilityType; 82482651c39SIlya Yanok __u8 bmAttributes; 82582651c39SIlya Yanok #define USB_LTM_SUPPORT (1 << 1) /* supports LTM */ 82682651c39SIlya Yanok __le16 wSpeedSupported; 82782651c39SIlya Yanok #define USB_LOW_SPEED_OPERATION (1) /* Low speed operation */ 82882651c39SIlya Yanok #define USB_FULL_SPEED_OPERATION (1 << 1) /* Full speed operation */ 82982651c39SIlya Yanok #define USB_HIGH_SPEED_OPERATION (1 << 2) /* High speed operation */ 83082651c39SIlya Yanok #define USB_5GBPS_OPERATION (1 << 3) /* Operation at 5Gbps */ 83182651c39SIlya Yanok __u8 bFunctionalitySupport; 83282651c39SIlya Yanok __u8 bU1devExitLat; 83382651c39SIlya Yanok __le16 bU2DevExitLat; 83482651c39SIlya Yanok } __attribute__((packed)); 83582651c39SIlya Yanok 83682651c39SIlya Yanok #define USB_DT_USB_SS_CAP_SIZE 10 83782651c39SIlya Yanok 83882651c39SIlya Yanok /* 83982651c39SIlya Yanok * Container ID Capability descriptor: Defines the instance unique ID used to 84082651c39SIlya Yanok * identify the instance across all operating modes 84182651c39SIlya Yanok */ 84282651c39SIlya Yanok #define CONTAINER_ID_TYPE 4 84382651c39SIlya Yanok struct usb_ss_container_id_descriptor { 84482651c39SIlya Yanok __u8 bLength; 84582651c39SIlya Yanok __u8 bDescriptorType; 84682651c39SIlya Yanok __u8 bDevCapabilityType; 84782651c39SIlya Yanok __u8 bReserved; 84882651c39SIlya Yanok __u8 ContainerID[16]; /* 128-bit number */ 84982651c39SIlya Yanok } __attribute__((packed)); 85082651c39SIlya Yanok 85182651c39SIlya Yanok #define USB_DT_USB_SS_CONTN_ID_SIZE 20 85223cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 85323cd1385SRemy Bohmer 85423cd1385SRemy Bohmer /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with 85523cd1385SRemy Bohmer * each endpoint descriptor for a wireless device 85623cd1385SRemy Bohmer */ 85723cd1385SRemy Bohmer struct usb_wireless_ep_comp_descriptor { 85823cd1385SRemy Bohmer __u8 bLength; 85923cd1385SRemy Bohmer __u8 bDescriptorType; 86023cd1385SRemy Bohmer 86123cd1385SRemy Bohmer __u8 bMaxBurst; 86223cd1385SRemy Bohmer __u8 bMaxSequence; 86323cd1385SRemy Bohmer __le16 wMaxStreamDelay; 86423cd1385SRemy Bohmer __le16 wOverTheAirPacketSize; 86523cd1385SRemy Bohmer __u8 bOverTheAirInterval; 86623cd1385SRemy Bohmer __u8 bmCompAttributes; 86723cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */ 86823cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_NO 0 86923cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SWITCH 1 87023cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SCALE 2 87123cd1385SRemy Bohmer } __attribute__((packed)); 87223cd1385SRemy Bohmer 87323cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 87423cd1385SRemy Bohmer 87523cd1385SRemy Bohmer /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless 87623cd1385SRemy Bohmer * host and a device for connection set up, mutual authentication, and 87723cd1385SRemy Bohmer * exchanging short lived session keys. The handshake depends on a CC. 87823cd1385SRemy Bohmer */ 87923cd1385SRemy Bohmer struct usb_handshake { 88023cd1385SRemy Bohmer __u8 bMessageNumber; 88123cd1385SRemy Bohmer __u8 bStatus; 88223cd1385SRemy Bohmer __u8 tTKID[3]; 88323cd1385SRemy Bohmer __u8 bReserved; 88423cd1385SRemy Bohmer __u8 CDID[16]; 88523cd1385SRemy Bohmer __u8 nonce[16]; 88623cd1385SRemy Bohmer __u8 MIC[8]; 88723cd1385SRemy Bohmer } __attribute__((packed)); 88823cd1385SRemy Bohmer 88923cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 89023cd1385SRemy Bohmer 89123cd1385SRemy Bohmer /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC). 89223cd1385SRemy Bohmer * A CC may also be set up using non-wireless secure channels (including 89323cd1385SRemy Bohmer * wired USB!), and some devices may support CCs with multiple hosts. 89423cd1385SRemy Bohmer */ 89523cd1385SRemy Bohmer struct usb_connection_context { 89623cd1385SRemy Bohmer __u8 CHID[16]; /* persistent host id */ 89723cd1385SRemy Bohmer __u8 CDID[16]; /* device id (unique w/in host context) */ 89823cd1385SRemy Bohmer __u8 CK[16]; /* connection key */ 89923cd1385SRemy Bohmer } __attribute__((packed)); 90023cd1385SRemy Bohmer 90123cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/ 90223cd1385SRemy Bohmer 90323cd1385SRemy Bohmer /* USB 2.0 defines three speeds, here's how Linux identifies them */ 90423cd1385SRemy Bohmer 90523cd1385SRemy Bohmer enum usb_device_speed { 90623cd1385SRemy Bohmer USB_SPEED_UNKNOWN = 0, /* enumerating */ 90723cd1385SRemy Bohmer USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ 90823cd1385SRemy Bohmer USB_SPEED_HIGH, /* usb 2.0 */ 90982651c39SIlya Yanok USB_SPEED_WIRELESS, /* wireless (usb 2.5) */ 91082651c39SIlya Yanok USB_SPEED_SUPER, /* usb 3.0 */ 91123cd1385SRemy Bohmer }; 91223cd1385SRemy Bohmer 91382651c39SIlya Yanok #ifdef __KERNEL__ 91482651c39SIlya Yanok 91582651c39SIlya Yanok /** 91682651c39SIlya Yanok * usb_speed_string() - Returns human readable-name of the speed. 91782651c39SIlya Yanok * @speed: The speed to return human-readable name for. If it's not 91882651c39SIlya Yanok * any of the speeds defined in usb_device_speed enum, string for 91982651c39SIlya Yanok * USB_SPEED_UNKNOWN will be returned. 92082651c39SIlya Yanok */ 92182651c39SIlya Yanok extern const char *usb_speed_string(enum usb_device_speed speed); 92282651c39SIlya Yanok 92382651c39SIlya Yanok #endif 92482651c39SIlya Yanok 92523cd1385SRemy Bohmer enum usb_device_state { 92623cd1385SRemy Bohmer /* NOTATTACHED isn't in the USB spec, and this state acts 92723cd1385SRemy Bohmer * the same as ATTACHED ... but it's clearer this way. 92823cd1385SRemy Bohmer */ 92923cd1385SRemy Bohmer USB_STATE_NOTATTACHED = 0, 93023cd1385SRemy Bohmer 93123cd1385SRemy Bohmer /* chapter 9 and authentication (wireless) device states */ 93223cd1385SRemy Bohmer USB_STATE_ATTACHED, 93323cd1385SRemy Bohmer USB_STATE_POWERED, /* wired */ 93423cd1385SRemy Bohmer USB_STATE_RECONNECTING, /* auth */ 93582651c39SIlya Yanok USB_STATE_UNAUTHENTICATED, /* auth */ 93623cd1385SRemy Bohmer USB_STATE_DEFAULT, /* limited function */ 93723cd1385SRemy Bohmer USB_STATE_ADDRESS, 93823cd1385SRemy Bohmer USB_STATE_CONFIGURED, /* most functions */ 93923cd1385SRemy Bohmer 94023cd1385SRemy Bohmer USB_STATE_SUSPENDED 94123cd1385SRemy Bohmer 94223cd1385SRemy Bohmer /* NOTE: there are actually four different SUSPENDED 94323cd1385SRemy Bohmer * states, returning to POWERED, DEFAULT, ADDRESS, or 94423cd1385SRemy Bohmer * CONFIGURED respectively when SOF tokens flow again. 94582651c39SIlya Yanok * At this level there's no difference between L1 and L2 94682651c39SIlya Yanok * suspend states. (L2 being original USB 1.1 suspend.) 94723cd1385SRemy Bohmer */ 94823cd1385SRemy Bohmer }; 94923cd1385SRemy Bohmer 95082651c39SIlya Yanok enum usb3_link_state { 95182651c39SIlya Yanok USB3_LPM_U0 = 0, 95282651c39SIlya Yanok USB3_LPM_U1, 95382651c39SIlya Yanok USB3_LPM_U2, 95482651c39SIlya Yanok USB3_LPM_U3 95582651c39SIlya Yanok }; 95682651c39SIlya Yanok 95782651c39SIlya Yanok /* 95882651c39SIlya Yanok * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1. 95982651c39SIlya Yanok * 0xff means the parent hub will accept transitions to U1, but will not 96082651c39SIlya Yanok * initiate a transition. 96182651c39SIlya Yanok * 96282651c39SIlya Yanok * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to 96382651c39SIlya Yanok * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved 96482651c39SIlya Yanok * values. 96582651c39SIlya Yanok * 96682651c39SIlya Yanok * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2. 96782651c39SIlya Yanok * 0xff means the parent hub will accept transitions to U2, but will not 96882651c39SIlya Yanok * initiate a transition. 96982651c39SIlya Yanok * 97082651c39SIlya Yanok * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to 97182651c39SIlya Yanok * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2 97282651c39SIlya Yanok * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means 97382651c39SIlya Yanok * 65.024ms. 97482651c39SIlya Yanok */ 97582651c39SIlya Yanok #define USB3_LPM_DISABLED 0x0 97682651c39SIlya Yanok #define USB3_LPM_U1_MAX_TIMEOUT 0x7F 97782651c39SIlya Yanok #define USB3_LPM_U2_MAX_TIMEOUT 0xFE 97882651c39SIlya Yanok #define USB3_LPM_DEVICE_INITIATED 0xFF 97982651c39SIlya Yanok 98082651c39SIlya Yanok struct usb_set_sel_req { 98182651c39SIlya Yanok __u8 u1_sel; 98282651c39SIlya Yanok __u8 u1_pel; 98382651c39SIlya Yanok __le16 u2_sel; 98482651c39SIlya Yanok __le16 u2_pel; 98582651c39SIlya Yanok } __attribute__ ((packed)); 98682651c39SIlya Yanok 98782651c39SIlya Yanok /* 98882651c39SIlya Yanok * The Set System Exit Latency control transfer provides one byte each for 98982651c39SIlya Yanok * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each 99082651c39SIlya Yanok * are two bytes long. 99182651c39SIlya Yanok */ 99282651c39SIlya Yanok #define USB3_LPM_MAX_U1_SEL_PEL 0xFF 99382651c39SIlya Yanok #define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF 99482651c39SIlya Yanok 99582651c39SIlya Yanok /*-------------------------------------------------------------------------*/ 99682651c39SIlya Yanok 99782651c39SIlya Yanok /* 99882651c39SIlya Yanok * As per USB compliance update, a device that is actively drawing 99982651c39SIlya Yanok * more than 100mA from USB must report itself as bus-powered in 100082651c39SIlya Yanok * the GetStatus(DEVICE) call. 100182651c39SIlya Yanok * http://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34 100282651c39SIlya Yanok */ 100382651c39SIlya Yanok #define USB_SELF_POWER_VBUS_MAX_DRAW 100 100482651c39SIlya Yanok 1005*f84c052aSSimon Glass /** 1006*f84c052aSSimon Glass * struct usb_string - wraps a C string and its USB id 1007*f84c052aSSimon Glass * @id:the (nonzero) ID for this string 1008*f84c052aSSimon Glass * @s:the string, in UTF-8 encoding 1009*f84c052aSSimon Glass * 1010*f84c052aSSimon Glass * If you're using usb_gadget_get_string(), use this to wrap a string 1011*f84c052aSSimon Glass * together with its ID. 1012*f84c052aSSimon Glass */ 1013*f84c052aSSimon Glass struct usb_string { 1014*f84c052aSSimon Glass u8 id; 1015*f84c052aSSimon Glass const char *s; 1016*f84c052aSSimon Glass }; 1017*f84c052aSSimon Glass 101823cd1385SRemy Bohmer #endif /* __LINUX_USB_CH9_H */ 1019