| 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 | /* |
| 3 | * This file holds USB constants and structures that are needed for |
| 4 | * USB device APIs. These are used by the USB device model, which is |
| 5 | * defined in chapter 9 of the USB 2.0 specification and in the |
| 6 | * Wireless USB 1.0 spec (now defunct). Linux has several APIs in C that |
| 7 | * need these: |
| 8 | * |
| 9 | * - the master/host side Linux-USB kernel driver API; |
| 10 | * - the "usbfs" user space API; and |
| 11 | * - the Linux "gadget" slave/device/peripheral side driver API. |
| 12 | * |
| 13 | * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems |
| 14 | * act either as a USB master/host or as a USB slave/device. That means |
| 15 | * the master and slave side APIs benefit from working well together. |
| 16 | * |
| 17 | * Note all descriptors are declared '__attribute__((packed))' so that: |
| 18 | * |
| 19 | * [a] they never get padded, either internally (USB spec writers |
| 20 | * probably handled that) or externally; |
| 21 | * |
| 22 | * [b] so that accessing bigger-than-a-bytes fields will never |
| 23 | * generate bus errors on any platform, even when the location of |
| 24 | * its descriptor inside a bundle isn't "naturally aligned", and |
| 25 | * |
| 26 | * [c] for consistency, removing all doubt even when it appears to |
| 27 | * someone that the two other points are non-issues for that |
| 28 | * particular descriptor type. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __LINUX_USB_CH9_H |
| 32 | #define __LINUX_USB_CH9_H |
| 33 | |
| 34 | #include <linux/types.h>	/* __u8 etc */ |
| 35 | #include <asm/byteorder.h>	/* le16_to_cpu */ |
| 36 | |
| 37 | /*-------------------------------------------------------------------------*/ |
| 38 | |
| 39 | /* CONTROL REQUEST SUPPORT */ |
| 40 | |
| 41 | /* |
| 42 | * USB directions |
| 43 | * |
| 44 | * This bit flag is used in endpoint descriptors' bEndpointAddress field. |
| 45 | * It's also one of three fields in control requests bRequestType. |
| 46 | */ |
| 47 | #define USB_DIR_OUT			0		/* to device */ |
| 48 | #define USB_DIR_IN			0x80		/* to host */ |
| 49 | |
| 50 | /* |
| 51 | * USB types, the second of three bRequestType fields |
| 52 | */ |
| 53 | #define USB_TYPE_MASK			(0x03 << 5) |
| 54 | #define USB_TYPE_STANDARD		(0x00 << 5) |
| 55 | #define USB_TYPE_CLASS			(0x01 << 5) |
| 56 | #define USB_TYPE_VENDOR			(0x02 << 5) |
| 57 | #define USB_TYPE_RESERVED		(0x03 << 5) |
| 58 | |
| 59 | /* |
| 60 | * USB recipients, the third of three bRequestType fields |
| 61 | */ |
| 62 | #define USB_RECIP_MASK			0x1f |
| 63 | #define USB_RECIP_DEVICE		0x00 |
| 64 | #define USB_RECIP_INTERFACE		0x01 |
| 65 | #define USB_RECIP_ENDPOINT		0x02 |
| 66 | #define USB_RECIP_OTHER			0x03 |
| 67 | /* From Wireless USB 1.0 */ |
| 68 | #define USB_RECIP_PORT			0x04 |
| 69 | #define USB_RECIP_RPIPE		0x05 |
| 70 | |
| 71 | /* |
| 72 | * Standard requests, for the bRequest field of a SETUP packet. |
| 73 | * |
| 74 | * These are qualified by the bRequestType field, so that for example |
| 75 | * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved |
| 76 | * by a GET_STATUS request. |
| 77 | */ |
| 78 | #define USB_REQ_GET_STATUS		0x00 |
| 79 | #define USB_REQ_CLEAR_FEATURE		0x01 |
| 80 | #define USB_REQ_SET_FEATURE		0x03 |
| 81 | #define USB_REQ_SET_ADDRESS		0x05 |
| 82 | #define USB_REQ_GET_DESCRIPTOR		0x06 |
| 83 | #define USB_REQ_SET_DESCRIPTOR		0x07 |
| 84 | #define USB_REQ_GET_CONFIGURATION	0x08 |
| 85 | #define USB_REQ_SET_CONFIGURATION	0x09 |
| 86 | #define USB_REQ_GET_INTERFACE		0x0A |
| 87 | #define USB_REQ_SET_INTERFACE		0x0B |
| 88 | #define USB_REQ_SYNCH_FRAME		0x0C |
| 89 | #define USB_REQ_SET_SEL			0x30 |
| 90 | #define USB_REQ_SET_ISOCH_DELAY		0x31 |
| 91 | |
| 92 | #define USB_REQ_SET_ENCRYPTION		0x0D	/* Wireless USB */ |
| 93 | #define USB_REQ_GET_ENCRYPTION		0x0E |
| 94 | #define USB_REQ_RPIPE_ABORT		0x0E |
| 95 | #define USB_REQ_SET_HANDSHAKE		0x0F |
| 96 | #define USB_REQ_RPIPE_RESET		0x0F |
| 97 | #define USB_REQ_GET_HANDSHAKE		0x10 |
| 98 | #define USB_REQ_SET_CONNECTION		0x11 |
| 99 | #define USB_REQ_SET_SECURITY_DATA	0x12 |
| 100 | #define USB_REQ_GET_SECURITY_DATA	0x13 |
| 101 | #define USB_REQ_SET_WUSB_DATA		0x14 |
| 102 | #define USB_REQ_LOOPBACK_DATA_WRITE	0x15 |
| 103 | #define USB_REQ_LOOPBACK_DATA_READ	0x16 |
| 104 | #define USB_REQ_SET_INTERFACE_DS	0x17 |
| 105 | #define USB_REQ_AUTH_IN			0x18 |
| 106 | #define USB_REQ_AUTH_OUT		0x19 |
| 107 | |
| 108 | /* specific requests for USB Power Delivery */ |
| 109 | #define USB_REQ_GET_PARTNER_PDO		20 |
| 110 | #define USB_REQ_GET_BATTERY_STATUS	21 |
| 111 | #define USB_REQ_SET_PDO			22 |
| 112 | #define USB_REQ_GET_VDM			23 |
| 113 | #define USB_REQ_SEND_VDM		24 |
| 114 | |
| 115 | /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command, |
| 116 | * used by hubs to put ports into a new L1 suspend state, except that it |
| 117 | * forgot to define its number ... |
| 118 | */ |
| 119 | |
| 120 | /* |
| 121 | * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and |
| 122 | * are read as a bit array returned by USB_REQ_GET_STATUS. (So there |
| 123 | * are at most sixteen features of each type.) Hubs may also support a |
| 124 | * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend. |
| 125 | */ |
| 126 | #define USB_DEVICE_SELF_POWERED				0	/* (read only) */ |
| 127 | #define USB_DEVICE_REMOTE_WAKEUP			1	/* dev may initiate wakeup */ |
| 128 | #define USB_DEVICE_TEST_MODE				2	/* (wired high speed only) */ |
| 129 | #define USB_DEVICE_BATTERY				2	/* (wireless) */ |
| 130 | #define USB_DEVICE_B_HNP_ENABLE				3	/* (otg) dev may initiate HNP */ |
| 131 | #define USB_DEVICE_WUSB_DEVICE				3	/* (wireless)*/ |
| 132 | #define USB_DEVICE_A_HNP_SUPPORT			4	/* (otg) RH port supports HNP */ |
| 133 | #define USB_DEVICE_A_ALT_HNP_SUPPORT			5	/* (otg) other RH port does */ |
| 134 | #define USB_DEVICE_DEBUG_MODE				6	/* (special devices only) */ |
| 135 | |
| 136 | #define USB_DEVICE_BULK_MAX_PACKET_UPDATE		8	/* (eUSB2v2) bump maxpacket to 1024 */ |
| 137 | |
| 138 | /* |
| 139 | * Test Mode Selectors |
| 140 | * See USB 2.0 spec Table 9-7 |
| 141 | */ |
| 142 | #define	USB_TEST_J		1 |
| 143 | #define	USB_TEST_K		2 |
| 144 | #define	USB_TEST_SE0_NAK	3 |
| 145 | #define	USB_TEST_PACKET		4 |
| 146 | #define	USB_TEST_FORCE_ENABLE	5 |
| 147 | |
| 148 | /* Status Type */ |
| 149 | #define USB_STATUS_TYPE_STANDARD	0 |
| 150 | #define USB_STATUS_TYPE_PTM		1 |
| 151 | |
| 152 | /* |
| 153 | * New Feature Selectors as added by USB 3.0 |
| 154 | * See USB 3.0 spec Table 9-7 |
| 155 | */ |
| 156 | #define USB_DEVICE_U1_ENABLE	48	/* dev may initiate U1 transition */ |
| 157 | #define USB_DEVICE_U2_ENABLE	49	/* dev may initiate U2 transition */ |
| 158 | #define USB_DEVICE_LTM_ENABLE	50	/* dev may send LTM */ |
| 159 | #define USB_INTRF_FUNC_SUSPEND	0	/* function suspend */ |
| 160 | |
| 161 | #define USB_INTR_FUNC_SUSPEND_OPT_MASK	0xFF00 |
| 162 | /* |
| 163 | * Suspend Options, Table 9-8 USB 3.0 spec |
| 164 | */ |
| 165 | #define USB_INTRF_FUNC_SUSPEND_LP	(1 << (8 + 0)) |
| 166 | #define USB_INTRF_FUNC_SUSPEND_RW	(1 << (8 + 1)) |
| 167 | |
| 168 | /* |
| 169 | * Interface status, Figure 9-5 USB 3.0 spec |
| 170 | */ |
| 171 | #define USB_INTRF_STAT_FUNC_RW_CAP 1 |
| 172 | #define USB_INTRF_STAT_FUNC_RW 2 |
| 173 | |
| 174 | #define USB_ENDPOINT_HALT		0	/* IN/OUT will STALL */ |
| 175 | |
| 176 | /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */ |
| 177 | #define USB_DEV_STAT_U1_ENABLED		2	/* transition into U1 state */ |
| 178 | #define USB_DEV_STAT_U2_ENABLED		3	/* transition into U2 state */ |
| 179 | #define USB_DEV_STAT_LTM_ENABLED	4	/* Latency tolerance messages */ |
| 180 | |
| 181 | /* |
| 182 | * Feature selectors from Table 9-8 USB Power Delivery spec |
| 183 | */ |
| 184 | #define USB_DEVICE_BATTERY_WAKE_MASK	40 |
| 185 | #define USB_DEVICE_OS_IS_PD_AWARE	41 |
| 186 | #define USB_DEVICE_POLICY_MODE		42 |
| 187 | #define USB_PORT_PR_SWAP		43 |
| 188 | #define USB_PORT_GOTO_MIN		44 |
| 189 | #define USB_PORT_RETURN_POWER		45 |
| 190 | #define USB_PORT_ACCEPT_PD_REQUEST	46 |
| 191 | #define USB_PORT_REJECT_PD_REQUEST	47 |
| 192 | #define USB_PORT_PORT_PD_RESET		48 |
| 193 | #define USB_PORT_C_PORT_PD_CHANGE	49 |
| 194 | #define USB_PORT_CABLE_PD_RESET		50 |
| 195 | #define USB_DEVICE_CHARGING_POLICY	54 |
| 196 | |
| 197 | /** |
| 198 | * struct usb_ctrlrequest - SETUP data for a USB device control request |
| 199 | * @bRequestType: matches the USB bmRequestType field |
| 200 | * @bRequest: matches the USB bRequest field |
| 201 | * @wValue: matches the USB wValue field (le16 byte order) |
| 202 | * @wIndex: matches the USB wIndex field (le16 byte order) |
| 203 | * @wLength: matches the USB wLength field (le16 byte order) |
| 204 | * |
| 205 | * This structure is used to send control requests to a USB device. It matches |
| 206 | * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the |
| 207 | * USB spec for a fuller description of the different fields, and what they are |
| 208 | * used for. |
| 209 | * |
| 210 | * Note that the driver for any interface can issue control requests. |
| 211 | * For most devices, interfaces don't coordinate with each other, so |
| 212 | * such requests may be made at any time. |
| 213 | */ |
| 214 | struct usb_ctrlrequest { |
| 215 | 	__u8 bRequestType; |
| 216 | 	__u8 bRequest; |
| 217 | 	__le16 wValue; |
| 218 | 	__le16 wIndex; |
| 219 | 	__le16 wLength; |
| 220 | } __attribute__ ((packed)); |
| 221 | |
| 222 | /*-------------------------------------------------------------------------*/ |
| 223 | |
| 224 | /* |
| 225 | * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or |
| 226 | * (rarely) accepted by SET_DESCRIPTOR. |
| 227 | * |
| 228 | * Note that all multi-byte values here are encoded in little endian |
| 229 | * byte order "on the wire". Within the kernel and when exposed |
| 230 | * through the Linux-USB APIs, they are not converted to cpu byte |
| 231 | * order; it is the responsibility of the client code to do this. |
| 232 | * The single exception is when device and configuration descriptors (but |
| 233 | * not other descriptors) are read from character devices |
| 234 | * (i.e. /dev/bus/usb/BBB/DDD); |
| 235 | * in this case the fields are converted to host endianness by the kernel. |
| 236 | */ |
| 237 | |
| 238 | /* |
| 239 | * Descriptor types ... USB 2.0 spec table 9.5 |
| 240 | */ |
| 241 | #define USB_DT_DEVICE			0x01 |
| 242 | #define USB_DT_CONFIG			0x02 |
| 243 | #define USB_DT_STRING			0x03 |
| 244 | #define USB_DT_INTERFACE		0x04 |
| 245 | #define USB_DT_ENDPOINT			0x05 |
| 246 | #define USB_DT_DEVICE_QUALIFIER		0x06 |
| 247 | #define USB_DT_OTHER_SPEED_CONFIG	0x07 |
| 248 | #define USB_DT_INTERFACE_POWER		0x08 |
| 249 | /* these are from a minor usb 2.0 revision (ECN) */ |
| 250 | #define USB_DT_OTG			0x09 |
| 251 | #define USB_DT_DEBUG			0x0a |
| 252 | #define USB_DT_INTERFACE_ASSOCIATION	0x0b |
| 253 | /* these are from the Wireless USB spec */ |
| 254 | #define USB_DT_SECURITY			0x0c |
| 255 | #define USB_DT_KEY			0x0d |
| 256 | #define USB_DT_ENCRYPTION_TYPE		0x0e |
| 257 | #define USB_DT_BOS			0x0f |
| 258 | #define USB_DT_DEVICE_CAPABILITY	0x10 |
| 259 | #define USB_DT_WIRELESS_ENDPOINT_COMP	0x11 |
| 260 | /* From the eUSB2 spec */ |
| 261 | #define USB_DT_EUSB2_ISOC_ENDPOINT_COMP	0x12 |
| 262 | /* From Wireless USB spec */ |
| 263 | #define USB_DT_WIRE_ADAPTER		0x21 |
| 264 | /* From USB Device Firmware Upgrade Specification, Revision 1.1 */ |
| 265 | #define USB_DT_DFU_FUNCTIONAL		0x21 |
| 266 | /* these are from the Wireless USB spec */ |
| 267 | #define USB_DT_RPIPE			0x22 |
| 268 | #define USB_DT_CS_RADIO_CONTROL		0x23 |
| 269 | /* From the T10 UAS specification */ |
| 270 | #define USB_DT_PIPE_USAGE		0x24 |
| 271 | /* From the USB 3.0 spec */ |
| 272 | #define	USB_DT_SS_ENDPOINT_COMP		0x30 |
| 273 | /* From the USB 3.1 spec */ |
| 274 | #define	USB_DT_SSP_ISOC_ENDPOINT_COMP	0x31 |
| 275 | |
| 276 | /* Conventional codes for class-specific descriptors. The convention is |
| 277 | * defined in the USB "Common Class" Spec (3.11). Individual class specs |
| 278 | * are authoritative for their usage, not the "common class" writeup. |
| 279 | */ |
| 280 | #define USB_DT_CS_DEVICE		(USB_TYPE_CLASS | USB_DT_DEVICE) |
| 281 | #define USB_DT_CS_CONFIG		(USB_TYPE_CLASS | USB_DT_CONFIG) |
| 282 | #define USB_DT_CS_STRING		(USB_TYPE_CLASS | USB_DT_STRING) |
| 283 | #define USB_DT_CS_INTERFACE		(USB_TYPE_CLASS | USB_DT_INTERFACE) |
| 284 | #define USB_DT_CS_ENDPOINT		(USB_TYPE_CLASS | USB_DT_ENDPOINT) |
| 285 | |
| 286 | /* All standard descriptors have these 2 fields at the beginning */ |
| 287 | struct usb_descriptor_header { |
| 288 | 	__u8 bLength; |
| 289 | 	__u8 bDescriptorType; |
| 290 | } __attribute__ ((packed)); |
| 291 | |
| 292 | |
| 293 | /*-------------------------------------------------------------------------*/ |
| 294 | |
| 295 | /* USB_DT_DEVICE: Device descriptor */ |
| 296 | struct usb_device_descriptor { |
| 297 | 	__u8 bLength; |
| 298 | 	__u8 bDescriptorType; |
| 299 | |
| 300 | 	__le16 bcdUSB; |
| 301 | 	__u8 bDeviceClass; |
| 302 | 	__u8 bDeviceSubClass; |
| 303 | 	__u8 bDeviceProtocol; |
| 304 | 	__u8 bMaxPacketSize0; |
| 305 | 	__le16 idVendor; |
| 306 | 	__le16 idProduct; |
| 307 | 	__le16 bcdDevice; |
| 308 | 	__u8 iManufacturer; |
| 309 | 	__u8 iProduct; |
| 310 | 	__u8 iSerialNumber; |
| 311 | 	__u8 bNumConfigurations; |
| 312 | } __attribute__ ((packed)); |
| 313 | |
| 314 | #define USB_DT_DEVICE_SIZE		18 |
| 315 | |
| 316 | |
| 317 | /* |
| 318 | * Device and/or Interface Class codes |
| 319 | * as found in bDeviceClass or bInterfaceClass |
| 320 | * and defined by www.usb.org documents |
| 321 | */ |
| 322 | #define USB_CLASS_PER_INTERFACE		0	/* for DeviceClass */ |
| 323 | #define USB_CLASS_AUDIO			1 |
| 324 | #define USB_CLASS_COMM			2 |
| 325 | #define USB_CLASS_HID			3 |
| 326 | #define USB_CLASS_PHYSICAL		5 |
| 327 | #define USB_CLASS_STILL_IMAGE		6 |
| 328 | #define USB_CLASS_PRINTER		7 |
| 329 | #define USB_CLASS_MASS_STORAGE		8 |
| 330 | #define USB_CLASS_HUB			9 |
| 331 | #define USB_CLASS_CDC_DATA		0x0a |
| 332 | #define USB_CLASS_CSCID			0x0b	/* chip+ smart card */ |
| 333 | #define USB_CLASS_CONTENT_SEC		0x0d	/* content security */ |
| 334 | #define USB_CLASS_VIDEO			0x0e |
| 335 | #define USB_CLASS_WIRELESS_CONTROLLER	0xe0 |
| 336 | #define USB_CLASS_PERSONAL_HEALTHCARE	0x0f |
| 337 | #define USB_CLASS_AUDIO_VIDEO		0x10 |
| 338 | #define USB_CLASS_BILLBOARD		0x11 |
| 339 | #define USB_CLASS_USB_TYPE_C_BRIDGE	0x12 |
| 340 | #define USB_CLASS_MCTP			0x14 |
| 341 | #define USB_CLASS_MISC			0xef |
| 342 | #define USB_CLASS_APP_SPEC		0xfe |
| 343 | #define USB_SUBCLASS_DFU			0x01 |
| 344 | |
| 345 | #define USB_CLASS_VENDOR_SPEC		0xff |
| 346 | #define USB_SUBCLASS_VENDOR_SPEC		0xff |
| 347 | |
| 348 | /*-------------------------------------------------------------------------*/ |
| 349 | |
| 350 | /* USB_DT_CONFIG: Configuration descriptor information. |
| 351 | * |
| 352 | * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the |
| 353 | * descriptor type is different. Highspeed-capable devices can look |
| 354 | * different depending on what speed they're currently running. Only |
| 355 | * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG |
| 356 | * descriptors. |
| 357 | */ |
| 358 | struct usb_config_descriptor { |
| 359 | 	__u8 bLength; |
| 360 | 	__u8 bDescriptorType; |
| 361 | |
| 362 | 	__le16 wTotalLength; |
| 363 | 	__u8 bNumInterfaces; |
| 364 | 	__u8 bConfigurationValue; |
| 365 | 	__u8 iConfiguration; |
| 366 | 	__u8 bmAttributes; |
| 367 | 	__u8 bMaxPower; |
| 368 | } __attribute__ ((packed)); |
| 369 | |
| 370 | #define USB_DT_CONFIG_SIZE		9 |
| 371 | |
| 372 | /* from config descriptor bmAttributes */ |
| 373 | #define USB_CONFIG_ATT_ONE		(1 << 7)	/* must be set */ |
| 374 | #define USB_CONFIG_ATT_SELFPOWER	(1 << 6)	/* self powered */ |
| 375 | #define USB_CONFIG_ATT_WAKEUP		(1 << 5)	/* can wakeup */ |
| 376 | #define USB_CONFIG_ATT_BATTERY		(1 << 4)	/* battery powered */ |
| 377 | |
| 378 | /*-------------------------------------------------------------------------*/ |
| 379 | |
| 380 | /* USB String descriptors can contain at most 126 characters. */ |
| 381 | #define USB_MAX_STRING_LEN	126 |
| 382 | |
| 383 | /* USB_DT_STRING: String descriptor */ |
| 384 | struct usb_string_descriptor { |
| 385 | 	__u8 bLength; |
| 386 | 	__u8 bDescriptorType; |
| 387 | |
| 388 | 	union { |
| 389 | 		__le16 legacy_padding; |
| 390 | 		__DECLARE_FLEX_ARRAY(__le16, wData);	/* UTF-16LE encoded */ |
| 391 | 	}; |
| 392 | } __attribute__ ((packed)); |
| 393 | |
| 394 | /* note that "string" zero is special, it holds language codes that |
| 395 | * the device supports, not Unicode characters. |
| 396 | */ |
| 397 | |
| 398 | /*-------------------------------------------------------------------------*/ |
| 399 | |
| 400 | /* USB_DT_INTERFACE: Interface descriptor */ |
| 401 | struct usb_interface_descriptor { |
| 402 | 	__u8 bLength; |
| 403 | 	__u8 bDescriptorType; |
| 404 | |
| 405 | 	__u8 bInterfaceNumber; |
| 406 | 	__u8 bAlternateSetting; |
| 407 | 	__u8 bNumEndpoints; |
| 408 | 	__u8 bInterfaceClass; |
| 409 | 	__u8 bInterfaceSubClass; |
| 410 | 	__u8 bInterfaceProtocol; |
| 411 | 	__u8 iInterface; |
| 412 | } __attribute__ ((packed)); |
| 413 | |
| 414 | #define USB_DT_INTERFACE_SIZE		9 |
| 415 | |
| 416 | /*-------------------------------------------------------------------------*/ |
| 417 | |
| 418 | /* USB_DT_ENDPOINT: Endpoint descriptor */ |
| 419 | struct usb_endpoint_descriptor { |
| 420 | 	__u8 bLength; |
| 421 | 	__u8 bDescriptorType; |
| 422 | |
| 423 | 	__u8 bEndpointAddress; |
| 424 | 	__u8 bmAttributes; |
| 425 | 	__le16 wMaxPacketSize; |
| 426 | 	__u8 bInterval; |
| 427 | |
| 428 | 	/* NOTE: these two are _only_ in audio endpoints. */ |
| 429 | 	/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */ |
| 430 | 	__u8 bRefresh; |
| 431 | 	__u8 bSynchAddress; |
| 432 | } __attribute__ ((packed)); |
| 433 | |
| 434 | #define USB_DT_ENDPOINT_SIZE		7 |
| 435 | #define USB_DT_ENDPOINT_AUDIO_SIZE	9	/* Audio extension */ |
| 436 | |
| 437 | |
| 438 | /* |
| 439 | * Endpoints |
| 440 | */ |
| 441 | #define USB_ENDPOINT_NUMBER_MASK	0x0f	/* in bEndpointAddress */ |
| 442 | #define USB_ENDPOINT_DIR_MASK		0x80 |
| 443 | |
| 444 | #define USB_ENDPOINT_XFERTYPE_MASK	0x03	/* in bmAttributes */ |
| 445 | #define USB_ENDPOINT_XFER_CONTROL	0 |
| 446 | #define USB_ENDPOINT_XFER_ISOC		1 |
| 447 | #define USB_ENDPOINT_XFER_BULK		2 |
| 448 | #define USB_ENDPOINT_XFER_INT		3 |
| 449 | #define USB_ENDPOINT_MAX_ADJUSTABLE	0x80 |
| 450 | |
| 451 | #define USB_ENDPOINT_MAXP_MASK	0x07ff |
| 452 | #define USB_EP_MAXP_MULT_SHIFT	11 |
| 453 | #define USB_EP_MAXP_MULT_MASK	(3 << USB_EP_MAXP_MULT_SHIFT) |
| 454 | #define USB_EP_MAXP_MULT(m) \ |
| 455 | 	(((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT) |
| 456 | |
| 457 | /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */ |
| 458 | #define USB_ENDPOINT_INTRTYPE		0x30 |
| 459 | #define USB_ENDPOINT_INTR_PERIODIC	(0 << 4) |
| 460 | #define USB_ENDPOINT_INTR_NOTIFICATION	(1 << 4) |
| 461 | |
| 462 | #define USB_ENDPOINT_SYNCTYPE		0x0c |
| 463 | #define USB_ENDPOINT_SYNC_NONE		(0 << 2) |
| 464 | #define USB_ENDPOINT_SYNC_ASYNC		(1 << 2) |
| 465 | #define USB_ENDPOINT_SYNC_ADAPTIVE	(2 << 2) |
| 466 | #define USB_ENDPOINT_SYNC_SYNC		(3 << 2) |
| 467 | |
| 468 | #define USB_ENDPOINT_USAGE_MASK		0x30 |
| 469 | #define USB_ENDPOINT_USAGE_DATA		0x00 |
| 470 | #define USB_ENDPOINT_USAGE_FEEDBACK	0x10 |
| 471 | #define USB_ENDPOINT_USAGE_IMPLICIT_FB	0x20	/* Implicit feedback Data endpoint */ |
| 472 | |
| 473 | /*-------------------------------------------------------------------------*/ |
| 474 | |
| 475 | /** |
| 476 | * usb_endpoint_num - get the endpoint's number |
| 477 | * @epd: endpoint to be checked |
| 478 | * |
| 479 | * Returns @epd's number: 0 to 15. |
| 480 | */ |
| 481 | static __inline__ int usb_endpoint_num(const struct usb_endpoint_descriptor *epd) |
| 482 | { |
| 483 | 	return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * usb_endpoint_type - get the endpoint's transfer type |
| 488 | * @epd: endpoint to be checked |
| 489 | * |
| 490 | * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according |
| 491 | * to @epd's transfer type. |
| 492 | */ |
| 493 | static __inline__ int usb_endpoint_type(const struct usb_endpoint_descriptor *epd) |
| 494 | { |
| 495 | 	return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * usb_endpoint_dir_in - check if the endpoint has IN direction |
| 500 | * @epd: endpoint to be checked |
| 501 | * |
| 502 | * Returns true if the endpoint is of type IN, otherwise it returns false. |
| 503 | */ |
| 504 | static __inline__ int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) |
| 505 | { |
| 506 | 	return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * usb_endpoint_dir_out - check if the endpoint has OUT direction |
| 511 | * @epd: endpoint to be checked |
| 512 | * |
| 513 | * Returns true if the endpoint is of type OUT, otherwise it returns false. |
| 514 | */ |
| 515 | static __inline__ int usb_endpoint_dir_out( |
| 516 | 				const struct usb_endpoint_descriptor *epd) |
| 517 | { |
| 518 | 	return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type |
| 523 | * @epd: endpoint to be checked |
| 524 | * |
| 525 | * Returns true if the endpoint is of type bulk, otherwise it returns false. |
| 526 | */ |
| 527 | static __inline__ int usb_endpoint_xfer_bulk( |
| 528 | 				const struct usb_endpoint_descriptor *epd) |
| 529 | { |
| 530 | 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 531 | 		USB_ENDPOINT_XFER_BULK); |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * usb_endpoint_xfer_control - check if the endpoint has control transfer type |
| 536 | * @epd: endpoint to be checked |
| 537 | * |
| 538 | * Returns true if the endpoint is of type control, otherwise it returns false. |
| 539 | */ |
| 540 | static __inline__ int usb_endpoint_xfer_control( |
| 541 | 				const struct usb_endpoint_descriptor *epd) |
| 542 | { |
| 543 | 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 544 | 		USB_ENDPOINT_XFER_CONTROL); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type |
| 549 | * @epd: endpoint to be checked |
| 550 | * |
| 551 | * Returns true if the endpoint is of type interrupt, otherwise it returns |
| 552 | * false. |
| 553 | */ |
| 554 | static __inline__ int usb_endpoint_xfer_int( |
| 555 | 				const struct usb_endpoint_descriptor *epd) |
| 556 | { |
| 557 | 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 558 | 		USB_ENDPOINT_XFER_INT); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type |
| 563 | * @epd: endpoint to be checked |
| 564 | * |
| 565 | * Returns true if the endpoint is of type isochronous, otherwise it returns |
| 566 | * false. |
| 567 | */ |
| 568 | static __inline__ int usb_endpoint_xfer_isoc( |
| 569 | 				const struct usb_endpoint_descriptor *epd) |
| 570 | { |
| 571 | 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 572 | 		USB_ENDPOINT_XFER_ISOC); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN |
| 577 | * @epd: endpoint to be checked |
| 578 | * |
| 579 | * Returns true if the endpoint has bulk transfer type and IN direction, |
| 580 | * otherwise it returns false. |
| 581 | */ |
| 582 | static __inline__ int usb_endpoint_is_bulk_in( |
| 583 | 				const struct usb_endpoint_descriptor *epd) |
| 584 | { |
| 585 | 	return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT |
| 590 | * @epd: endpoint to be checked |
| 591 | * |
| 592 | * Returns true if the endpoint has bulk transfer type and OUT direction, |
| 593 | * otherwise it returns false. |
| 594 | */ |
| 595 | static __inline__ int usb_endpoint_is_bulk_out( |
| 596 | 				const struct usb_endpoint_descriptor *epd) |
| 597 | { |
| 598 | 	return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd); |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * usb_endpoint_is_int_in - check if the endpoint is interrupt IN |
| 603 | * @epd: endpoint to be checked |
| 604 | * |
| 605 | * Returns true if the endpoint has interrupt transfer type and IN direction, |
| 606 | * otherwise it returns false. |
| 607 | */ |
| 608 | static __inline__ int usb_endpoint_is_int_in( |
| 609 | 				const struct usb_endpoint_descriptor *epd) |
| 610 | { |
| 611 | 	return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd); |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT |
| 616 | * @epd: endpoint to be checked |
| 617 | * |
| 618 | * Returns true if the endpoint has interrupt transfer type and OUT direction, |
| 619 | * otherwise it returns false. |
| 620 | */ |
| 621 | static __inline__ int usb_endpoint_is_int_out( |
| 622 | 				const struct usb_endpoint_descriptor *epd) |
| 623 | { |
| 624 | 	return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd); |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN |
| 629 | * @epd: endpoint to be checked |
| 630 | * |
| 631 | * Returns true if the endpoint has isochronous transfer type and IN direction, |
| 632 | * otherwise it returns false. |
| 633 | */ |
| 634 | static __inline__ int usb_endpoint_is_isoc_in( |
| 635 | 				const struct usb_endpoint_descriptor *epd) |
| 636 | { |
| 637 | 	return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT |
| 642 | * @epd: endpoint to be checked |
| 643 | * |
| 644 | * Returns true if the endpoint has isochronous transfer type and OUT direction, |
| 645 | * otherwise it returns false. |
| 646 | */ |
| 647 | static __inline__ int usb_endpoint_is_isoc_out( |
| 648 | 				const struct usb_endpoint_descriptor *epd) |
| 649 | { |
| 650 | 	return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd); |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * usb_endpoint_maxp - get endpoint's max packet size |
| 655 | * @epd: endpoint to be checked |
| 656 | * |
| 657 | * Returns @epd's max packet bits [10:0] |
| 658 | */ |
| 659 | static __inline__ int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd) |
| 660 | { |
| 661 | 	return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK; |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * usb_endpoint_maxp_mult - get endpoint's transactional opportunities |
| 666 | * @epd: endpoint to be checked |
| 667 | * |
| 668 | * Return @epd's wMaxPacketSize[12:11] + 1 |
| 669 | */ |
| 670 | static __inline__ int |
| 671 | usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd) |
| 672 | { |
| 673 | 	int maxp = __le16_to_cpu(epd->wMaxPacketSize); |
| 674 | |
| 675 | 	return USB_EP_MAXP_MULT(maxp) + 1; |
| 676 | } |
| 677 | |
| 678 | static __inline__ int usb_endpoint_interrupt_type( |
| 679 | 		const struct usb_endpoint_descriptor *epd) |
| 680 | { |
| 681 | 	return epd->bmAttributes & USB_ENDPOINT_INTRTYPE; |
| 682 | } |
| 683 | |
| 684 | /*-------------------------------------------------------------------------*/ |
| 685 | |
| 686 | /* USB_DT_EUSB2_ISOC_ENDPOINT_COMP: eUSB2 Isoch Endpoint Companion descriptor */ |
| 687 | struct usb_eusb2_isoc_ep_comp_descriptor { |
| 688 | 	__u8	bLength; |
| 689 | 	__u8	bDescriptorType; |
| 690 | 	__le16	wMaxPacketSize; |
| 691 | 	__le32	dwBytesPerInterval; |
| 692 | } __attribute__ ((packed)); |
| 693 | |
| 694 | #define USB_DT_EUSB2_ISOC_EP_COMP_SIZE	8 |
| 695 | |
| 696 | /*-------------------------------------------------------------------------*/ |
| 697 | |
| 698 | /* USB_DT_SSP_ISOC_ENDPOINT_COMP: SuperSpeedPlus Isochronous Endpoint Companion |
| 699 | * descriptor |
| 700 | */ |
| 701 | struct usb_ssp_isoc_ep_comp_descriptor { |
| 702 | 	__u8 bLength; |
| 703 | 	__u8 bDescriptorType; |
| 704 | 	__le16 wReseved; |
| 705 | 	__le32 dwBytesPerInterval; |
| 706 | } __attribute__ ((packed)); |
| 707 | |
| 708 | #define USB_DT_SSP_ISOC_EP_COMP_SIZE		8 |
| 709 | |
| 710 | /*-------------------------------------------------------------------------*/ |
| 711 | |
| 712 | /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */ |
| 713 | struct usb_ss_ep_comp_descriptor { |
| 714 | 	__u8 bLength; |
| 715 | 	__u8 bDescriptorType; |
| 716 | |
| 717 | 	__u8 bMaxBurst; |
| 718 | 	__u8 bmAttributes; |
| 719 | 	__le16 wBytesPerInterval; |
| 720 | } __attribute__ ((packed)); |
| 721 | |
| 722 | #define USB_DT_SS_EP_COMP_SIZE		6 |
| 723 | |
| 724 | /* Bits 4:0 of bmAttributes if this is a bulk endpoint */ |
| 725 | static __inline__ int |
| 726 | usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp) |
| 727 | { |
| 728 | 	int		max_streams; |
| 729 | |
| 730 | 	if (!comp) |
| 731 | 		return 0; |
| 732 | |
| 733 | 	max_streams = comp->bmAttributes & 0x1f; |
| 734 | |
| 735 | 	if (!max_streams) |
| 736 | 		return 0; |
| 737 | |
| 738 | 	max_streams = 1 << max_streams; |
| 739 | |
| 740 | 	return max_streams; |
| 741 | } |
| 742 | |
| 743 | /* Bits 1:0 of bmAttributes if this is an isoc endpoint */ |
| 744 | #define USB_SS_MULT(p)			(1 + ((p) & 0x3)) |
| 745 | /* Bit 7 of bmAttributes if a SSP isoc endpoint companion descriptor exists */ |
| 746 | #define USB_SS_SSP_ISOC_COMP(p)		((p) & (1 << 7)) |
| 747 | |
| 748 | /*-------------------------------------------------------------------------*/ |
| 749 | |
| 750 | /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */ |
| 751 | struct usb_qualifier_descriptor { |
| 752 | 	__u8 bLength; |
| 753 | 	__u8 bDescriptorType; |
| 754 | |
| 755 | 	__le16 bcdUSB; |
| 756 | 	__u8 bDeviceClass; |
| 757 | 	__u8 bDeviceSubClass; |
| 758 | 	__u8 bDeviceProtocol; |
| 759 | 	__u8 bMaxPacketSize0; |
| 760 | 	__u8 bNumConfigurations; |
| 761 | 	__u8 bRESERVED; |
| 762 | } __attribute__ ((packed)); |
| 763 | |
| 764 | |
| 765 | /*-------------------------------------------------------------------------*/ |
| 766 | |
| 767 | /* USB_DT_OTG (from OTG 1.0a supplement) */ |
| 768 | struct usb_otg_descriptor { |
| 769 | 	__u8 bLength; |
| 770 | 	__u8 bDescriptorType; |
| 771 | |
| 772 | 	__u8 bmAttributes;	/* support for HNP, SRP, etc */ |
| 773 | } __attribute__ ((packed)); |
| 774 | |
| 775 | /* USB_DT_OTG (from OTG 2.0 supplement) */ |
| 776 | struct usb_otg20_descriptor { |
| 777 | 	__u8 bLength; |
| 778 | 	__u8 bDescriptorType; |
| 779 | |
| 780 | 	__u8 bmAttributes;	/* support for HNP, SRP and ADP, etc */ |
| 781 | 	__le16 bcdOTG;		/* OTG and EH supplement release number |
| 782 | 				 * in binary-coded decimal(i.e. 2.0 is 0200H) |
| 783 | 				 */ |
| 784 | } __attribute__ ((packed)); |
| 785 | |
| 786 | /* from usb_otg_descriptor.bmAttributes */ |
| 787 | #define USB_OTG_SRP		(1 << 0) |
| 788 | #define USB_OTG_HNP		(1 << 1)	/* swap host/device roles */ |
| 789 | #define USB_OTG_ADP		(1 << 2)	/* support ADP */ |
| 790 | /* OTG 3.0 */ |
| 791 | #define USB_OTG_RSP		(1 << 3)	/* support RSP */ |
| 792 | |
| 793 | #define OTG_STS_SELECTOR	0xF000		/* OTG status selector */ |
| 794 | /*-------------------------------------------------------------------------*/ |
| 795 | |
| 796 | /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */ |
| 797 | struct usb_debug_descriptor { |
| 798 | 	__u8 bLength; |
| 799 | 	__u8 bDescriptorType; |
| 800 | |
| 801 | 	/* bulk endpoints with 8 byte maxpacket */ |
| 802 | 	__u8 bDebugInEndpoint; |
| 803 | 	__u8 bDebugOutEndpoint; |
| 804 | } __attribute__((packed)); |
| 805 | |
| 806 | /*-------------------------------------------------------------------------*/ |
| 807 | |
| 808 | /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */ |
| 809 | struct usb_interface_assoc_descriptor { |
| 810 | 	__u8 bLength; |
| 811 | 	__u8 bDescriptorType; |
| 812 | |
| 813 | 	__u8 bFirstInterface; |
| 814 | 	__u8 bInterfaceCount; |
| 815 | 	__u8 bFunctionClass; |
| 816 | 	__u8 bFunctionSubClass; |
| 817 | 	__u8 bFunctionProtocol; |
| 818 | 	__u8 iFunction; |
| 819 | } __attribute__ ((packed)); |
| 820 | |
| 821 | #define USB_DT_INTERFACE_ASSOCIATION_SIZE	8 |
| 822 | |
| 823 | /*-------------------------------------------------------------------------*/ |
| 824 | |
| 825 | /* USB_DT_SECURITY: group of wireless security descriptors, including |
| 826 | * encryption types available for setting up a CC/association. |
| 827 | */ |
| 828 | struct usb_security_descriptor { |
| 829 | 	__u8 bLength; |
| 830 | 	__u8 bDescriptorType; |
| 831 | |
| 832 | 	__le16 wTotalLength; |
| 833 | 	__u8 bNumEncryptionTypes; |
| 834 | } __attribute__((packed)); |
| 835 | |
| 836 | /*-------------------------------------------------------------------------*/ |
| 837 | |
| 838 | /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys |
| 839 | * may be retrieved. |
| 840 | */ |
| 841 | struct usb_key_descriptor { |
| 842 | 	__u8 bLength; |
| 843 | 	__u8 bDescriptorType; |
| 844 | |
| 845 | 	__u8 tTKID[3]; |
| 846 | 	__u8 bReserved; |
| 847 | 	__u8 bKeyData[]; |
| 848 | } __attribute__((packed)); |
| 849 | |
| 850 | /*-------------------------------------------------------------------------*/ |
| 851 | |
| 852 | /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */ |
| 853 | struct usb_encryption_descriptor { |
| 854 | 	__u8 bLength; |
| 855 | 	__u8 bDescriptorType; |
| 856 | |
| 857 | 	__u8 bEncryptionType; |
| 858 | #define	USB_ENC_TYPE_UNSECURE		0 |
| 859 | #define	USB_ENC_TYPE_WIRED		1	/* non-wireless mode */ |
| 860 | #define	USB_ENC_TYPE_CCM_1		2	/* aes128/cbc session */ |
| 861 | #define	USB_ENC_TYPE_RSA_1		3	/* rsa3072/sha1 auth */ |
| 862 | 	__u8 bEncryptionValue;		/* use in SET_ENCRYPTION */ |
| 863 | 	__u8 bAuthKeyIndex; |
| 864 | } __attribute__((packed)); |
| 865 | |
| 866 | |
| 867 | /*-------------------------------------------------------------------------*/ |
| 868 | |
| 869 | /* USB_DT_BOS: group of device-level capabilities */ |
| 870 | struct usb_bos_descriptor { |
| 871 | 	__u8 bLength; |
| 872 | 	__u8 bDescriptorType; |
| 873 | |
| 874 | 	__le16 wTotalLength; |
| 875 | 	__u8 bNumDeviceCaps; |
| 876 | } __attribute__((packed)); |
| 877 | |
| 878 | #define USB_DT_BOS_SIZE		5 |
| 879 | /*-------------------------------------------------------------------------*/ |
| 880 | |
| 881 | /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */ |
| 882 | struct usb_dev_cap_header { |
| 883 | 	__u8 bLength; |
| 884 | 	__u8 bDescriptorType; |
| 885 | 	__u8 bDevCapabilityType; |
| 886 | } __attribute__((packed)); |
| 887 | |
| 888 | #define	USB_CAP_TYPE_WIRELESS_USB	1 |
| 889 | |
| 890 | struct usb_wireless_cap_descriptor {	/* Ultra Wide Band */ |
| 891 | 	__u8 bLength; |
| 892 | 	__u8 bDescriptorType; |
| 893 | 	__u8 bDevCapabilityType; |
| 894 | |
| 895 | 	__u8 bmAttributes; |
| 896 | #define	USB_WIRELESS_P2P_DRD		(1 << 1) |
| 897 | #define	USB_WIRELESS_BEACON_MASK	(3 << 2) |
| 898 | #define	USB_WIRELESS_BEACON_SELF	(1 << 2) |
| 899 | #define	USB_WIRELESS_BEACON_DIRECTED	(2 << 2) |
| 900 | #define	USB_WIRELESS_BEACON_NONE	(3 << 2) |
| 901 | 	__le16 wPHYRates;	/* bit rates, Mbps */ |
| 902 | #define	USB_WIRELESS_PHY_53		(1 << 0)	/* always set */ |
| 903 | #define	USB_WIRELESS_PHY_80		(1 << 1) |
| 904 | #define	USB_WIRELESS_PHY_107		(1 << 2)	/* always set */ |
| 905 | #define	USB_WIRELESS_PHY_160		(1 << 3) |
| 906 | #define	USB_WIRELESS_PHY_200		(1 << 4)	/* always set */ |
| 907 | #define	USB_WIRELESS_PHY_320		(1 << 5) |
| 908 | #define	USB_WIRELESS_PHY_400		(1 << 6) |
| 909 | #define	USB_WIRELESS_PHY_480		(1 << 7) |
| 910 | 	__u8 bmTFITXPowerInfo;	/* TFI power levels */ |
| 911 | 	__u8 bmFFITXPowerInfo;	/* FFI power levels */ |
| 912 | 	__le16 bmBandGroup; |
| 913 | 	__u8 bReserved; |
| 914 | } __attribute__((packed)); |
| 915 | |
| 916 | #define USB_DT_USB_WIRELESS_CAP_SIZE	11 |
| 917 | |
| 918 | /* USB 2.0 Extension descriptor */ |
| 919 | #define	USB_CAP_TYPE_EXT		2 |
| 920 | |
| 921 | struct usb_ext_cap_descriptor {		/* Link Power Management */ |
| 922 | 	__u8 bLength; |
| 923 | 	__u8 bDescriptorType; |
| 924 | 	__u8 bDevCapabilityType; |
| 925 | 	__le32 bmAttributes; |
| 926 | #define USB_LPM_SUPPORT			(1 << 1)	/* supports LPM */ |
| 927 | #define USB_BESL_SUPPORT		(1 << 2)	/* supports BESL */ |
| 928 | #define USB_BESL_BASELINE_VALID		(1 << 3)	/* Baseline BESL valid*/ |
| 929 | #define USB_BESL_DEEP_VALID		(1 << 4)	/* Deep BESL valid */ |
| 930 | #define USB_SET_BESL_BASELINE(p)	(((p) & 0xf) << 8) |
| 931 | #define USB_SET_BESL_DEEP(p)		(((p) & 0xf) << 12) |
| 932 | #define USB_GET_BESL_BASELINE(p)	(((p) & (0xf << 8)) >> 8) |
| 933 | #define USB_GET_BESL_DEEP(p)		(((p) & (0xf << 12)) >> 12) |
| 934 | } __attribute__((packed)); |
| 935 | |
| 936 | #define USB_DT_USB_EXT_CAP_SIZE	7 |
| 937 | |
| 938 | /* |
| 939 | * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB |
| 940 | * specific device level capabilities |
| 941 | */ |
| 942 | #define		USB_SS_CAP_TYPE		3 |
| 943 | struct usb_ss_cap_descriptor {		/* Link Power Management */ |
| 944 | 	__u8 bLength; |
| 945 | 	__u8 bDescriptorType; |
| 946 | 	__u8 bDevCapabilityType; |
| 947 | 	__u8 bmAttributes; |
| 948 | #define USB_LTM_SUPPORT			(1 << 1) /* supports LTM */ |
| 949 | 	__le16 wSpeedSupported; |
| 950 | #define USB_LOW_SPEED_OPERATION		(1)	 /* Low speed operation */ |
| 951 | #define USB_FULL_SPEED_OPERATION	(1 << 1) /* Full speed operation */ |
| 952 | #define USB_HIGH_SPEED_OPERATION	(1 << 2) /* High speed operation */ |
| 953 | #define USB_5GBPS_OPERATION		(1 << 3) /* Operation at 5Gbps */ |
| 954 | 	__u8 bFunctionalitySupport; |
| 955 | 	__u8 bU1devExitLat; |
| 956 | 	__le16 bU2DevExitLat; |
| 957 | } __attribute__((packed)); |
| 958 | |
| 959 | #define USB_DT_USB_SS_CAP_SIZE	10 |
| 960 | |
| 961 | /* |
| 962 | * Container ID Capability descriptor: Defines the instance unique ID used to |
| 963 | * identify the instance across all operating modes |
| 964 | */ |
| 965 | #define	CONTAINER_ID_TYPE	4 |
| 966 | struct usb_ss_container_id_descriptor { |
| 967 | 	__u8 bLength; |
| 968 | 	__u8 bDescriptorType; |
| 969 | 	__u8 bDevCapabilityType; |
| 970 | 	__u8 bReserved; |
| 971 | 	__u8 ContainerID[16]; /* 128-bit number */ |
| 972 | } __attribute__((packed)); |
| 973 | |
| 974 | #define USB_DT_USB_SS_CONTN_ID_SIZE	20 |
| 975 | |
| 976 | /* |
| 977 | * Platform Device Capability descriptor: Defines platform specific device |
| 978 | * capabilities |
| 979 | */ |
| 980 | #define	USB_PLAT_DEV_CAP_TYPE	5 |
| 981 | struct usb_plat_dev_cap_descriptor { |
| 982 | 	__u8 bLength; |
| 983 | 	__u8 bDescriptorType; |
| 984 | 	__u8 bDevCapabilityType; |
| 985 | 	__u8 bReserved; |
| 986 | 	__u8 UUID[16]; |
| 987 | 	__u8 CapabilityData[]; |
| 988 | } __attribute__((packed)); |
| 989 | |
| 990 | #define USB_DT_USB_PLAT_DEV_CAP_SIZE(capability_data_size)	(20 + capability_data_size) |
| 991 | |
| 992 | /* |
| 993 | * SuperSpeed Plus USB Capability descriptor: Defines the set of |
| 994 | * SuperSpeed Plus USB specific device level capabilities |
| 995 | */ |
| 996 | #define	USB_SSP_CAP_TYPE	0xa |
| 997 | struct usb_ssp_cap_descriptor { |
| 998 | 	__u8 bLength; |
| 999 | 	__u8 bDescriptorType; |
| 1000 | 	__u8 bDevCapabilityType; |
| 1001 | 	__u8 bReserved; |
| 1002 | 	__le32 bmAttributes; |
| 1003 | #define USB_SSP_SUBLINK_SPEED_ATTRIBS	(0x1f << 0) /* sublink speed entries */ |
| 1004 | #define USB_SSP_SUBLINK_SPEED_IDS	(0xf << 5) /* speed ID entries */ |
| 1005 | 	__le16 wFunctionalitySupport; |
| 1006 | #define USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID	(0xf) |
| 1007 | #define USB_SSP_MIN_RX_LANE_COUNT		(0xf << 8) |
| 1008 | #define USB_SSP_MIN_TX_LANE_COUNT		(0xf << 12) |
| 1009 | 	__le16 wReserved; |
| 1010 | 	union { |
| 1011 | 		__le32 legacy_padding; |
| 1012 | 		/* list of sublink speed attrib entries */ |
| 1013 | 		__DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr); |
| 1014 | 	}; |
| 1015 | #define USB_SSP_SUBLINK_SPEED_SSID	(0xf)		/* sublink speed ID */ |
| 1016 | #define USB_SSP_SUBLINK_SPEED_LSE	(0x3 << 4)	/* Lanespeed exponent */ |
| 1017 | #define USB_SSP_SUBLINK_SPEED_LSE_BPS		0 |
| 1018 | #define USB_SSP_SUBLINK_SPEED_LSE_KBPS		1 |
| 1019 | #define USB_SSP_SUBLINK_SPEED_LSE_MBPS		2 |
| 1020 | #define USB_SSP_SUBLINK_SPEED_LSE_GBPS		3 |
| 1021 | |
| 1022 | #define USB_SSP_SUBLINK_SPEED_ST	(0x3 << 6)	/* Sublink type */ |
| 1023 | #define USB_SSP_SUBLINK_SPEED_ST_SYM_RX		0 |
| 1024 | #define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX	1 |
| 1025 | #define USB_SSP_SUBLINK_SPEED_ST_SYM_TX		2 |
| 1026 | #define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX	3 |
| 1027 | |
| 1028 | #define USB_SSP_SUBLINK_SPEED_RSVD	(0x3f << 8)	/* Reserved */ |
| 1029 | #define USB_SSP_SUBLINK_SPEED_LP	(0x3 << 14)	/* Link protocol */ |
| 1030 | #define USB_SSP_SUBLINK_SPEED_LP_SS		0 |
| 1031 | #define USB_SSP_SUBLINK_SPEED_LP_SSP		1 |
| 1032 | |
| 1033 | #define USB_SSP_SUBLINK_SPEED_LSM	(0xff << 16)	/* Lanespeed mantissa */ |
| 1034 | } __attribute__((packed)); |
| 1035 | |
| 1036 | /* |
| 1037 | * USB Power Delivery Capability Descriptor: |
| 1038 | * Defines capabilities for PD |
| 1039 | */ |
| 1040 | /* Defines the various PD Capabilities of this device */ |
| 1041 | #define USB_PD_POWER_DELIVERY_CAPABILITY	0x06 |
| 1042 | /* Provides information on each battery supported by the device */ |
| 1043 | #define USB_PD_BATTERY_INFO_CAPABILITY		0x07 |
| 1044 | /* The Consumer characteristics of a Port on the device */ |
| 1045 | #define USB_PD_PD_CONSUMER_PORT_CAPABILITY	0x08 |
| 1046 | /* The provider characteristics of a Port on the device */ |
| 1047 | #define USB_PD_PD_PROVIDER_PORT_CAPABILITY	0x09 |
| 1048 | |
| 1049 | struct usb_pd_cap_descriptor { |
| 1050 | 	__u8 bLength; |
| 1051 | 	__u8 bDescriptorType; |
| 1052 | 	__u8 bDevCapabilityType; /* set to USB_PD_POWER_DELIVERY_CAPABILITY */ |
| 1053 | 	__u8 bReserved; |
| 1054 | 	__le32 bmAttributes; |
| 1055 | #define USB_PD_CAP_BATTERY_CHARGING	(1 << 1) /* supports Battery Charging specification */ |
| 1056 | #define USB_PD_CAP_USB_PD		(1 << 2) /* supports USB Power Delivery specification */ |
| 1057 | #define USB_PD_CAP_PROVIDER		(1 << 3) /* can provide power */ |
| 1058 | #define USB_PD_CAP_CONSUMER		(1 << 4) /* can consume power */ |
| 1059 | #define USB_PD_CAP_CHARGING_POLICY	(1 << 5) /* supports CHARGING_POLICY feature */ |
| 1060 | #define USB_PD_CAP_TYPE_C_CURRENT	(1 << 6) /* supports power capabilities defined in the USB Type-C Specification */ |
| 1061 | |
| 1062 | #define USB_PD_CAP_PWR_AC		(1 << 8) |
| 1063 | #define USB_PD_CAP_PWR_BAT		(1 << 9) |
| 1064 | #define USB_PD_CAP_PWR_USE_V_BUS	(1 << 14) |
| 1065 | |
| 1066 | 	__le16 bmProviderPorts; /* Bit zero refers to the UFP of the device */ |
| 1067 | 	__le16 bmConsumerPorts; |
| 1068 | 	__le16 bcdBCVersion; |
| 1069 | 	__le16 bcdPDVersion; |
| 1070 | 	__le16 bcdUSBTypeCVersion; |
| 1071 | } __attribute__((packed)); |
| 1072 | |
| 1073 | struct usb_pd_cap_battery_info_descriptor { |
| 1074 | 	__u8 bLength; |
| 1075 | 	__u8 bDescriptorType; |
| 1076 | 	__u8 bDevCapabilityType; |
| 1077 | 	/* Index of string descriptor shall contain the user friendly name for this battery */ |
| 1078 | 	__u8 iBattery; |
| 1079 | 	/* Index of string descriptor shall contain the Serial Number String for this battery */ |
| 1080 | 	__u8 iSerial; |
| 1081 | 	__u8 iManufacturer; |
| 1082 | 	__u8 bBatteryId; /* uniquely identifies this battery in status Messages */ |
| 1083 | 	__u8 bReserved; |
| 1084 | 	/* |
| 1085 | 	 * Shall contain the Battery Charge value above which this |
| 1086 | 	 * battery is considered to be fully charged but not necessarily |
| 1087 | 	 * “topped off.” |
| 1088 | 	 */ |
| 1089 | 	__le32 dwChargedThreshold; /* in mWh */ |
| 1090 | 	/* |
| 1091 | 	 * Shall contain the minimum charge level of this battery such |
| 1092 | 	 * that above this threshold, a device can be assured of being |
| 1093 | 	 * able to power up successfully (see Battery Charging 1.2). |
| 1094 | 	 */ |
| 1095 | 	__le32 dwWeakThreshold; /* in mWh */ |
| 1096 | 	__le32 dwBatteryDesignCapacity; /* in mWh */ |
| 1097 | 	__le32 dwBatteryLastFullchargeCapacity; /* in mWh */ |
| 1098 | } __attribute__((packed)); |
| 1099 | |
| 1100 | struct usb_pd_cap_consumer_port_descriptor { |
| 1101 | 	__u8 bLength; |
| 1102 | 	__u8 bDescriptorType; |
| 1103 | 	__u8 bDevCapabilityType; |
| 1104 | 	__u8 bReserved; |
| 1105 | 	__u8 bmCapabilities; |
| 1106 | /* port will oerate under: */ |
| 1107 | #define USB_PD_CAP_CONSUMER_BC		(1 << 0) /* BC */ |
| 1108 | #define USB_PD_CAP_CONSUMER_PD		(1 << 1) /* PD */ |
| 1109 | #define USB_PD_CAP_CONSUMER_TYPE_C	(1 << 2) /* USB Type-C Current */ |
| 1110 | 	__le16 wMinVoltage; /* in 50mV units */ |
| 1111 | 	__le16 wMaxVoltage; /* in 50mV units */ |
| 1112 | 	__u16 wReserved; |
| 1113 | 	__le32 dwMaxOperatingPower; /* in 10 mW - operating at steady state */ |
| 1114 | 	__le32 dwMaxPeakPower; /* in 10mW units - operating at peak power */ |
| 1115 | 	__le32 dwMaxPeakPowerTime; /* in 100ms units - duration of peak */ |
| 1116 | #define USB_PD_CAP_CONSUMER_UNKNOWN_PEAK_POWER_TIME 0xffff |
| 1117 | } __attribute__((packed)); |
| 1118 | |
| 1119 | struct usb_pd_cap_provider_port_descriptor { |
| 1120 | 	__u8 bLength; |
| 1121 | 	__u8 bDescriptorType; |
| 1122 | 	__u8 bDevCapabilityType; |
| 1123 | 	__u8 bReserved1; |
| 1124 | 	__u8 bmCapabilities; |
| 1125 | /* port will oerate under: */ |
| 1126 | #define USB_PD_CAP_PROVIDER_BC		(1 << 0) /* BC */ |
| 1127 | #define USB_PD_CAP_PROVIDER_PD		(1 << 1) /* PD */ |
| 1128 | #define USB_PD_CAP_PROVIDER_TYPE_C	(1 << 2) /* USB Type-C Current */ |
| 1129 | 	__u8 bNumOfPDObjects; |
| 1130 | 	__u8 bReserved2; |
| 1131 | 	__le32 wPowerDataObject[]; |
| 1132 | } __attribute__((packed)); |
| 1133 | |
| 1134 | /* |
| 1135 | * Precision time measurement capability descriptor: advertised by devices and |
| 1136 | * hubs that support PTM |
| 1137 | */ |
| 1138 | #define	USB_PTM_CAP_TYPE	0xb |
| 1139 | struct usb_ptm_cap_descriptor { |
| 1140 | 	__u8 bLength; |
| 1141 | 	__u8 bDescriptorType; |
| 1142 | 	__u8 bDevCapabilityType; |
| 1143 | } __attribute__((packed)); |
| 1144 | |
| 1145 | #define USB_DT_USB_PTM_ID_SIZE		3 |
| 1146 | /* |
| 1147 | * The size of the descriptor for the Sublink Speed Attribute Count |
| 1148 | * (SSAC) specified in bmAttributes[4:0]. SSAC is zero-based |
| 1149 | */ |
| 1150 | #define USB_DT_USB_SSP_CAP_SIZE(ssac)	(12 + (ssac + 1) * 4) |
| 1151 | |
| 1152 | /*-------------------------------------------------------------------------*/ |
| 1153 | |
| 1154 | struct usb_authentication_capability_descriptor { |
| 1155 | 	__u8 bLength; |
| 1156 | 	__u8 bDescriptorType; /* set to USB_DT_DEVICE_CAPABILITY */ |
| 1157 | 	__u8 bmAttributes; |
| 1158 | |
| 1159 | 	__u8 bcdProtocolVersion; |
| 1160 | 	__u8 bcdCapability; |
| 1161 | } __attribute__((packed)); |
| 1162 | |
| 1163 | /*-------------------------------------------------------------------------*/ |
| 1164 | |
| 1165 | /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with |
| 1166 | * each endpoint descriptor for a wireless device |
| 1167 | */ |
| 1168 | struct usb_wireless_ep_comp_descriptor { |
| 1169 | 	__u8 bLength; |
| 1170 | 	__u8 bDescriptorType; |
| 1171 | |
| 1172 | 	__u8 bMaxBurst; |
| 1173 | 	__u8 bMaxSequence; |
| 1174 | 	__le16 wMaxStreamDelay; |
| 1175 | 	__le16 wOverTheAirPacketSize; |
| 1176 | 	__u8 bOverTheAirInterval; |
| 1177 | 	__u8 bmCompAttributes; |
| 1178 | #define USB_ENDPOINT_SWITCH_MASK	0x03	/* in bmCompAttributes */ |
| 1179 | #define USB_ENDPOINT_SWITCH_NO		0 |
| 1180 | #define USB_ENDPOINT_SWITCH_SWITCH	1 |
| 1181 | #define USB_ENDPOINT_SWITCH_SCALE	2 |
| 1182 | } __attribute__((packed)); |
| 1183 | |
| 1184 | /*-------------------------------------------------------------------------*/ |
| 1185 | |
| 1186 | /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless |
| 1187 | * host and a device for connection set up, mutual authentication, and |
| 1188 | * exchanging short lived session keys. The handshake depends on a CC. |
| 1189 | */ |
| 1190 | struct usb_handshake { |
| 1191 | 	__u8 bMessageNumber; |
| 1192 | 	__u8 bStatus; |
| 1193 | 	__u8 tTKID[3]; |
| 1194 | 	__u8 bReserved; |
| 1195 | 	__u8 CDID[16]; |
| 1196 | 	__u8 nonce[16]; |
| 1197 | 	__u8 MIC[8]; |
| 1198 | } __attribute__((packed)); |
| 1199 | |
| 1200 | /*-------------------------------------------------------------------------*/ |
| 1201 | |
| 1202 | /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC). |
| 1203 | * A CC may also be set up using non-wireless secure channels (including |
| 1204 | * wired USB!), and some devices may support CCs with multiple hosts. |
| 1205 | */ |
| 1206 | struct usb_connection_context { |
| 1207 | 	__u8 CHID[16];		/* persistent host id */ |
| 1208 | 	__u8 CDID[16];		/* device id (unique w/in host context) */ |
| 1209 | 	__u8 CK[16];		/* connection key */ |
| 1210 | } __attribute__((packed)); |
| 1211 | |
| 1212 | /*-------------------------------------------------------------------------*/ |
| 1213 | |
| 1214 | /* USB 2.0 defines three speeds, here's how Linux identifies them */ |
| 1215 | |
| 1216 | enum usb_device_speed { |
| 1217 | 	USB_SPEED_UNKNOWN = 0,			/* enumerating */ |
| 1218 | 	USB_SPEED_LOW, USB_SPEED_FULL,		/* usb 1.1 */ |
| 1219 | 	USB_SPEED_HIGH,				/* usb 2.0 */ |
| 1220 | 	USB_SPEED_WIRELESS,			/* wireless (usb 2.5) */ |
| 1221 | 	USB_SPEED_SUPER,			/* usb 3.0 */ |
| 1222 | 	USB_SPEED_SUPER_PLUS,			/* usb 3.1 */ |
| 1223 | }; |
| 1224 | |
| 1225 | |
| 1226 | enum usb_device_state { |
| 1227 | 	/* NOTATTACHED isn't in the USB spec, and this state acts |
| 1228 | 	 * the same as ATTACHED ... but it's clearer this way. |
| 1229 | 	 */ |
| 1230 | 	USB_STATE_NOTATTACHED = 0, |
| 1231 | |
| 1232 | 	/* chapter 9 and authentication (wireless) device states */ |
| 1233 | 	USB_STATE_ATTACHED, |
| 1234 | 	USB_STATE_POWERED,			/* wired */ |
| 1235 | 	USB_STATE_RECONNECTING,			/* auth */ |
| 1236 | 	USB_STATE_UNAUTHENTICATED,		/* auth */ |
| 1237 | 	USB_STATE_DEFAULT,			/* limited function */ |
| 1238 | 	USB_STATE_ADDRESS, |
| 1239 | 	USB_STATE_CONFIGURED,			/* most functions */ |
| 1240 | |
| 1241 | 	USB_STATE_SUSPENDED |
| 1242 | |
| 1243 | 	/* NOTE: there are actually four different SUSPENDED |
| 1244 | 	 * states, returning to POWERED, DEFAULT, ADDRESS, or |
| 1245 | 	 * CONFIGURED respectively when SOF tokens flow again. |
| 1246 | 	 * At this level there's no difference between L1 and L2 |
| 1247 | 	 * suspend states. (L2 being original USB 1.1 suspend.) |
| 1248 | 	 */ |
| 1249 | }; |
| 1250 | |
| 1251 | enum usb3_link_state { |
| 1252 | 	USB3_LPM_U0 = 0, |
| 1253 | 	USB3_LPM_U1, |
| 1254 | 	USB3_LPM_U2, |
| 1255 | 	USB3_LPM_U3 |
| 1256 | }; |
| 1257 | |
| 1258 | /* |
| 1259 | * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1. |
| 1260 | * 0xff means the parent hub will accept transitions to U1, but will not |
| 1261 | * initiate a transition. |
| 1262 | * |
| 1263 | * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to |
| 1264 | * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved |
| 1265 | * values. |
| 1266 | * |
| 1267 | * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2. |
| 1268 | * 0xff means the parent hub will accept transitions to U2, but will not |
| 1269 | * initiate a transition. |
| 1270 | * |
| 1271 | * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to |
| 1272 | * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2 |
| 1273 | * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means |
| 1274 | * 65.024ms. |
| 1275 | */ |
| 1276 | #define USB3_LPM_DISABLED		0x0 |
| 1277 | #define USB3_LPM_U1_MAX_TIMEOUT		0x7F |
| 1278 | #define USB3_LPM_U2_MAX_TIMEOUT		0xFE |
| 1279 | #define USB3_LPM_DEVICE_INITIATED	0xFF |
| 1280 | |
| 1281 | struct usb_set_sel_req { |
| 1282 | 	__u8	u1_sel; |
| 1283 | 	__u8	u1_pel; |
| 1284 | 	__le16	u2_sel; |
| 1285 | 	__le16	u2_pel; |
| 1286 | } __attribute__ ((packed)); |
| 1287 | |
| 1288 | /* |
| 1289 | * The Set System Exit Latency control transfer provides one byte each for |
| 1290 | * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each |
| 1291 | * are two bytes long. |
| 1292 | */ |
| 1293 | #define USB3_LPM_MAX_U1_SEL_PEL		0xFF |
| 1294 | #define USB3_LPM_MAX_U2_SEL_PEL		0xFFFF |
| 1295 | |
| 1296 | /*-------------------------------------------------------------------------*/ |
| 1297 | |
| 1298 | /* |
| 1299 | * As per USB compliance update, a device that is actively drawing |
| 1300 | * more than 100mA from USB must report itself as bus-powered in |
| 1301 | * the GetStatus(DEVICE) call. |
| 1302 | * https://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34 |
| 1303 | */ |
| 1304 | #define USB_SELF_POWER_VBUS_MAX_DRAW		100 |
| 1305 | |
| 1306 | #endif /* __LINUX_USB_CH9_H */ |