Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * This file holds USB constants and structures that are needed for
0004  * USB device APIs.  These are used by the USB device model, which is
0005  * defined in chapter 9 of the USB 2.0 specification and in the
0006  * Wireless USB 1.0 (spread around).  Linux has several APIs in C that
0007  * need these:
0008  *
0009  * - the master/host side Linux-USB kernel driver API;
0010  * - the "usbfs" user space API; and
0011  * - the Linux "gadget" slave/device/peripheral side driver API.
0012  *
0013  * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
0014  * act either as a USB master/host or as a USB slave/device.  That means
0015  * the master and slave side APIs benefit from working well together.
0016  *
0017  * There's also "Wireless USB", using low power short range radios for
0018  * peripheral interconnection but otherwise building on the USB framework.
0019  *
0020  * Note all descriptors are declared '__attribute__((packed))' so that:
0021  *
0022  * [a] they never get padded, either internally (USB spec writers
0023  *     probably handled that) or externally;
0024  *
0025  * [b] so that accessing bigger-than-a-bytes fields will never
0026  *     generate bus errors on any platform, even when the location of
0027  *     its descriptor inside a bundle isn't "naturally aligned", and
0028  *
0029  * [c] for consistency, removing all doubt even when it appears to
0030  *     someone that the two other points are non-issues for that
0031  *     particular descriptor type.
0032  */
0033 
0034 #ifndef _UAPI__LINUX_USB_CH9_H
0035 #define _UAPI__LINUX_USB_CH9_H
0036 
0037 #include <linux/types.h>    /* __u8 etc */
0038 #include <asm/byteorder.h>  /* le16_to_cpu */
0039 
0040 /*-------------------------------------------------------------------------*/
0041 
0042 /* CONTROL REQUEST SUPPORT */
0043 
0044 /*
0045  * USB directions
0046  *
0047  * This bit flag is used in endpoint descriptors' bEndpointAddress field.
0048  * It's also one of three fields in control requests bRequestType.
0049  */
0050 #define USB_DIR_OUT         0       /* to device */
0051 #define USB_DIR_IN          0x80        /* to host */
0052 
0053 /*
0054  * USB types, the second of three bRequestType fields
0055  */
0056 #define USB_TYPE_MASK           (0x03 << 5)
0057 #define USB_TYPE_STANDARD       (0x00 << 5)
0058 #define USB_TYPE_CLASS          (0x01 << 5)
0059 #define USB_TYPE_VENDOR         (0x02 << 5)
0060 #define USB_TYPE_RESERVED       (0x03 << 5)
0061 
0062 /*
0063  * USB recipients, the third of three bRequestType fields
0064  */
0065 #define USB_RECIP_MASK          0x1f
0066 #define USB_RECIP_DEVICE        0x00
0067 #define USB_RECIP_INTERFACE     0x01
0068 #define USB_RECIP_ENDPOINT      0x02
0069 #define USB_RECIP_OTHER         0x03
0070 /* From Wireless USB 1.0 */
0071 #define USB_RECIP_PORT          0x04
0072 #define USB_RECIP_RPIPE     0x05
0073 
0074 /*
0075  * Standard requests, for the bRequest field of a SETUP packet.
0076  *
0077  * These are qualified by the bRequestType field, so that for example
0078  * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
0079  * by a GET_STATUS request.
0080  */
0081 #define USB_REQ_GET_STATUS      0x00
0082 #define USB_REQ_CLEAR_FEATURE       0x01
0083 #define USB_REQ_SET_FEATURE     0x03
0084 #define USB_REQ_SET_ADDRESS     0x05
0085 #define USB_REQ_GET_DESCRIPTOR      0x06
0086 #define USB_REQ_SET_DESCRIPTOR      0x07
0087 #define USB_REQ_GET_CONFIGURATION   0x08
0088 #define USB_REQ_SET_CONFIGURATION   0x09
0089 #define USB_REQ_GET_INTERFACE       0x0A
0090 #define USB_REQ_SET_INTERFACE       0x0B
0091 #define USB_REQ_SYNCH_FRAME     0x0C
0092 #define USB_REQ_SET_SEL         0x30
0093 #define USB_REQ_SET_ISOCH_DELAY     0x31
0094 
0095 #define USB_REQ_SET_ENCRYPTION      0x0D    /* Wireless USB */
0096 #define USB_REQ_GET_ENCRYPTION      0x0E
0097 #define USB_REQ_RPIPE_ABORT     0x0E
0098 #define USB_REQ_SET_HANDSHAKE       0x0F
0099 #define USB_REQ_RPIPE_RESET     0x0F
0100 #define USB_REQ_GET_HANDSHAKE       0x10
0101 #define USB_REQ_SET_CONNECTION      0x11
0102 #define USB_REQ_SET_SECURITY_DATA   0x12
0103 #define USB_REQ_GET_SECURITY_DATA   0x13
0104 #define USB_REQ_SET_WUSB_DATA       0x14
0105 #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
0106 #define USB_REQ_LOOPBACK_DATA_READ  0x16
0107 #define USB_REQ_SET_INTERFACE_DS    0x17
0108 
0109 /* specific requests for USB Power Delivery */
0110 #define USB_REQ_GET_PARTNER_PDO     20
0111 #define USB_REQ_GET_BATTERY_STATUS  21
0112 #define USB_REQ_SET_PDO         22
0113 #define USB_REQ_GET_VDM         23
0114 #define USB_REQ_SEND_VDM        24
0115 
0116 /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command,
0117  * used by hubs to put ports into a new L1 suspend state, except that it
0118  * forgot to define its number ...
0119  */
0120 
0121 /*
0122  * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
0123  * are read as a bit array returned by USB_REQ_GET_STATUS.  (So there
0124  * are at most sixteen features of each type.)  Hubs may also support a
0125  * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
0126  */
0127 #define USB_DEVICE_SELF_POWERED     0   /* (read only) */
0128 #define USB_DEVICE_REMOTE_WAKEUP    1   /* dev may initiate wakeup */
0129 #define USB_DEVICE_TEST_MODE        2   /* (wired high speed only) */
0130 #define USB_DEVICE_BATTERY      2   /* (wireless) */
0131 #define USB_DEVICE_B_HNP_ENABLE     3   /* (otg) dev may initiate HNP */
0132 #define USB_DEVICE_WUSB_DEVICE      3   /* (wireless)*/
0133 #define USB_DEVICE_A_HNP_SUPPORT    4   /* (otg) RH port supports HNP */
0134 #define USB_DEVICE_A_ALT_HNP_SUPPORT    5   /* (otg) other RH port does */
0135 #define USB_DEVICE_DEBUG_MODE       6   /* (special devices only) */
0136 
0137 /*
0138  * Test Mode Selectors
0139  * See USB 2.0 spec Table 9-7
0140  */
0141 #define USB_TEST_J      1
0142 #define USB_TEST_K      2
0143 #define USB_TEST_SE0_NAK    3
0144 #define USB_TEST_PACKET     4
0145 #define USB_TEST_FORCE_ENABLE   5
0146 
0147 /* Status Type */
0148 #define USB_STATUS_TYPE_STANDARD    0
0149 #define USB_STATUS_TYPE_PTM     1
0150 
0151 /*
0152  * New Feature Selectors as added by USB 3.0
0153  * See USB 3.0 spec Table 9-7
0154  */
0155 #define USB_DEVICE_U1_ENABLE    48  /* dev may initiate U1 transition */
0156 #define USB_DEVICE_U2_ENABLE    49  /* dev may initiate U2 transition */
0157 #define USB_DEVICE_LTM_ENABLE   50  /* dev may send LTM */
0158 #define USB_INTRF_FUNC_SUSPEND  0   /* function suspend */
0159 
0160 #define USB_INTR_FUNC_SUSPEND_OPT_MASK  0xFF00
0161 /*
0162  * Suspend Options, Table 9-8 USB 3.0 spec
0163  */
0164 #define USB_INTRF_FUNC_SUSPEND_LP   (1 << (8 + 0))
0165 #define USB_INTRF_FUNC_SUSPEND_RW   (1 << (8 + 1))
0166 
0167 /*
0168  * Interface status, Figure 9-5 USB 3.0 spec
0169  */
0170 #define USB_INTRF_STAT_FUNC_RW_CAP     1
0171 #define USB_INTRF_STAT_FUNC_RW         2
0172 
0173 #define USB_ENDPOINT_HALT       0   /* IN/OUT will STALL */
0174 
0175 /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */
0176 #define USB_DEV_STAT_U1_ENABLED     2   /* transition into U1 state */
0177 #define USB_DEV_STAT_U2_ENABLED     3   /* transition into U2 state */
0178 #define USB_DEV_STAT_LTM_ENABLED    4   /* Latency tolerance messages */
0179 
0180 /*
0181  * Feature selectors from Table 9-8 USB Power Delivery spec
0182  */
0183 #define USB_DEVICE_BATTERY_WAKE_MASK    40
0184 #define USB_DEVICE_OS_IS_PD_AWARE   41
0185 #define USB_DEVICE_POLICY_MODE      42
0186 #define USB_PORT_PR_SWAP        43
0187 #define USB_PORT_GOTO_MIN       44
0188 #define USB_PORT_RETURN_POWER       45
0189 #define USB_PORT_ACCEPT_PD_REQUEST  46
0190 #define USB_PORT_REJECT_PD_REQUEST  47
0191 #define USB_PORT_PORT_PD_RESET      48
0192 #define USB_PORT_C_PORT_PD_CHANGE   49
0193 #define USB_PORT_CABLE_PD_RESET     50
0194 #define USB_DEVICE_CHARGING_POLICY  54
0195 
0196 /**
0197  * struct usb_ctrlrequest - SETUP data for a USB device control request
0198  * @bRequestType: matches the USB bmRequestType field
0199  * @bRequest: matches the USB bRequest field
0200  * @wValue: matches the USB wValue field (le16 byte order)
0201  * @wIndex: matches the USB wIndex field (le16 byte order)
0202  * @wLength: matches the USB wLength field (le16 byte order)
0203  *
0204  * This structure is used to send control requests to a USB device.  It matches
0205  * the different fields of the USB 2.0 Spec section 9.3, table 9-2.  See the
0206  * USB spec for a fuller description of the different fields, and what they are
0207  * used for.
0208  *
0209  * Note that the driver for any interface can issue control requests.
0210  * For most devices, interfaces don't coordinate with each other, so
0211  * such requests may be made at any time.
0212  */
0213 struct usb_ctrlrequest {
0214     __u8 bRequestType;
0215     __u8 bRequest;
0216     __le16 wValue;
0217     __le16 wIndex;
0218     __le16 wLength;
0219 } __attribute__ ((packed));
0220 
0221 /*-------------------------------------------------------------------------*/
0222 
0223 /*
0224  * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
0225  * (rarely) accepted by SET_DESCRIPTOR.
0226  *
0227  * Note that all multi-byte values here are encoded in little endian
0228  * byte order "on the wire".  Within the kernel and when exposed
0229  * through the Linux-USB APIs, they are not converted to cpu byte
0230  * order; it is the responsibility of the client code to do this.
0231  * The single exception is when device and configuration descriptors (but
0232  * not other descriptors) are read from character devices
0233  * (i.e. /dev/bus/usb/BBB/DDD);
0234  * in this case the fields are converted to host endianness by the kernel.
0235  */
0236 
0237 /*
0238  * Descriptor types ... USB 2.0 spec table 9.5
0239  */
0240 #define USB_DT_DEVICE           0x01
0241 #define USB_DT_CONFIG           0x02
0242 #define USB_DT_STRING           0x03
0243 #define USB_DT_INTERFACE        0x04
0244 #define USB_DT_ENDPOINT         0x05
0245 #define USB_DT_DEVICE_QUALIFIER     0x06
0246 #define USB_DT_OTHER_SPEED_CONFIG   0x07
0247 #define USB_DT_INTERFACE_POWER      0x08
0248 /* these are from a minor usb 2.0 revision (ECN) */
0249 #define USB_DT_OTG          0x09
0250 #define USB_DT_DEBUG            0x0a
0251 #define USB_DT_INTERFACE_ASSOCIATION    0x0b
0252 /* these are from the Wireless USB spec */
0253 #define USB_DT_SECURITY         0x0c
0254 #define USB_DT_KEY          0x0d
0255 #define USB_DT_ENCRYPTION_TYPE      0x0e
0256 #define USB_DT_BOS          0x0f
0257 #define USB_DT_DEVICE_CAPABILITY    0x10
0258 #define USB_DT_WIRELESS_ENDPOINT_COMP   0x11
0259 #define USB_DT_WIRE_ADAPTER     0x21
0260 #define USB_DT_RPIPE            0x22
0261 #define USB_DT_CS_RADIO_CONTROL     0x23
0262 /* From the T10 UAS specification */
0263 #define USB_DT_PIPE_USAGE       0x24
0264 /* From the USB 3.0 spec */
0265 #define USB_DT_SS_ENDPOINT_COMP     0x30
0266 /* From the USB 3.1 spec */
0267 #define USB_DT_SSP_ISOC_ENDPOINT_COMP   0x31
0268 
0269 /* Conventional codes for class-specific descriptors.  The convention is
0270  * defined in the USB "Common Class" Spec (3.11).  Individual class specs
0271  * are authoritative for their usage, not the "common class" writeup.
0272  */
0273 #define USB_DT_CS_DEVICE        (USB_TYPE_CLASS | USB_DT_DEVICE)
0274 #define USB_DT_CS_CONFIG        (USB_TYPE_CLASS | USB_DT_CONFIG)
0275 #define USB_DT_CS_STRING        (USB_TYPE_CLASS | USB_DT_STRING)
0276 #define USB_DT_CS_INTERFACE     (USB_TYPE_CLASS | USB_DT_INTERFACE)
0277 #define USB_DT_CS_ENDPOINT      (USB_TYPE_CLASS | USB_DT_ENDPOINT)
0278 
0279 /* All standard descriptors have these 2 fields at the beginning */
0280 struct usb_descriptor_header {
0281     __u8  bLength;
0282     __u8  bDescriptorType;
0283 } __attribute__ ((packed));
0284 
0285 
0286 /*-------------------------------------------------------------------------*/
0287 
0288 /* USB_DT_DEVICE: Device descriptor */
0289 struct usb_device_descriptor {
0290     __u8  bLength;
0291     __u8  bDescriptorType;
0292 
0293     __le16 bcdUSB;
0294     __u8  bDeviceClass;
0295     __u8  bDeviceSubClass;
0296     __u8  bDeviceProtocol;
0297     __u8  bMaxPacketSize0;
0298     __le16 idVendor;
0299     __le16 idProduct;
0300     __le16 bcdDevice;
0301     __u8  iManufacturer;
0302     __u8  iProduct;
0303     __u8  iSerialNumber;
0304     __u8  bNumConfigurations;
0305 } __attribute__ ((packed));
0306 
0307 #define USB_DT_DEVICE_SIZE      18
0308 
0309 
0310 /*
0311  * Device and/or Interface Class codes
0312  * as found in bDeviceClass or bInterfaceClass
0313  * and defined by www.usb.org documents
0314  */
0315 #define USB_CLASS_PER_INTERFACE     0   /* for DeviceClass */
0316 #define USB_CLASS_AUDIO         1
0317 #define USB_CLASS_COMM          2
0318 #define USB_CLASS_HID           3
0319 #define USB_CLASS_PHYSICAL      5
0320 #define USB_CLASS_STILL_IMAGE       6
0321 #define USB_CLASS_PRINTER       7
0322 #define USB_CLASS_MASS_STORAGE      8
0323 #define USB_CLASS_HUB           9
0324 #define USB_CLASS_CDC_DATA      0x0a
0325 #define USB_CLASS_CSCID         0x0b    /* chip+ smart card */
0326 #define USB_CLASS_CONTENT_SEC       0x0d    /* content security */
0327 #define USB_CLASS_VIDEO         0x0e
0328 #define USB_CLASS_WIRELESS_CONTROLLER   0xe0
0329 #define USB_CLASS_PERSONAL_HEALTHCARE   0x0f
0330 #define USB_CLASS_AUDIO_VIDEO       0x10
0331 #define USB_CLASS_BILLBOARD     0x11
0332 #define USB_CLASS_USB_TYPE_C_BRIDGE 0x12
0333 #define USB_CLASS_MISC          0xef
0334 #define USB_CLASS_APP_SPEC      0xfe
0335 #define USB_CLASS_VENDOR_SPEC       0xff
0336 
0337 #define USB_SUBCLASS_VENDOR_SPEC    0xff
0338 
0339 /*-------------------------------------------------------------------------*/
0340 
0341 /* USB_DT_CONFIG: Configuration descriptor information.
0342  *
0343  * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
0344  * descriptor type is different.  Highspeed-capable devices can look
0345  * different depending on what speed they're currently running.  Only
0346  * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
0347  * descriptors.
0348  */
0349 struct usb_config_descriptor {
0350     __u8  bLength;
0351     __u8  bDescriptorType;
0352 
0353     __le16 wTotalLength;
0354     __u8  bNumInterfaces;
0355     __u8  bConfigurationValue;
0356     __u8  iConfiguration;
0357     __u8  bmAttributes;
0358     __u8  bMaxPower;
0359 } __attribute__ ((packed));
0360 
0361 #define USB_DT_CONFIG_SIZE      9
0362 
0363 /* from config descriptor bmAttributes */
0364 #define USB_CONFIG_ATT_ONE      (1 << 7)    /* must be set */
0365 #define USB_CONFIG_ATT_SELFPOWER    (1 << 6)    /* self powered */
0366 #define USB_CONFIG_ATT_WAKEUP       (1 << 5)    /* can wakeup */
0367 #define USB_CONFIG_ATT_BATTERY      (1 << 4)    /* battery powered */
0368 
0369 /*-------------------------------------------------------------------------*/
0370 
0371 /* USB String descriptors can contain at most 126 characters. */
0372 #define USB_MAX_STRING_LEN  126
0373 
0374 /* USB_DT_STRING: String descriptor */
0375 struct usb_string_descriptor {
0376     __u8  bLength;
0377     __u8  bDescriptorType;
0378 
0379     __le16 wData[1];        /* UTF-16LE encoded */
0380 } __attribute__ ((packed));
0381 
0382 /* note that "string" zero is special, it holds language codes that
0383  * the device supports, not Unicode characters.
0384  */
0385 
0386 /*-------------------------------------------------------------------------*/
0387 
0388 /* USB_DT_INTERFACE: Interface descriptor */
0389 struct usb_interface_descriptor {
0390     __u8  bLength;
0391     __u8  bDescriptorType;
0392 
0393     __u8  bInterfaceNumber;
0394     __u8  bAlternateSetting;
0395     __u8  bNumEndpoints;
0396     __u8  bInterfaceClass;
0397     __u8  bInterfaceSubClass;
0398     __u8  bInterfaceProtocol;
0399     __u8  iInterface;
0400 } __attribute__ ((packed));
0401 
0402 #define USB_DT_INTERFACE_SIZE       9
0403 
0404 /*-------------------------------------------------------------------------*/
0405 
0406 /* USB_DT_ENDPOINT: Endpoint descriptor */
0407 struct usb_endpoint_descriptor {
0408     __u8  bLength;
0409     __u8  bDescriptorType;
0410 
0411     __u8  bEndpointAddress;
0412     __u8  bmAttributes;
0413     __le16 wMaxPacketSize;
0414     __u8  bInterval;
0415 
0416     /* NOTE:  these two are _only_ in audio endpoints. */
0417     /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
0418     __u8  bRefresh;
0419     __u8  bSynchAddress;
0420 } __attribute__ ((packed));
0421 
0422 #define USB_DT_ENDPOINT_SIZE        7
0423 #define USB_DT_ENDPOINT_AUDIO_SIZE  9   /* Audio extension */
0424 
0425 
0426 /*
0427  * Endpoints
0428  */
0429 #define USB_ENDPOINT_NUMBER_MASK    0x0f    /* in bEndpointAddress */
0430 #define USB_ENDPOINT_DIR_MASK       0x80
0431 
0432 #define USB_ENDPOINT_XFERTYPE_MASK  0x03    /* in bmAttributes */
0433 #define USB_ENDPOINT_XFER_CONTROL   0
0434 #define USB_ENDPOINT_XFER_ISOC      1
0435 #define USB_ENDPOINT_XFER_BULK      2
0436 #define USB_ENDPOINT_XFER_INT       3
0437 #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
0438 
0439 #define USB_ENDPOINT_MAXP_MASK  0x07ff
0440 #define USB_EP_MAXP_MULT_SHIFT  11
0441 #define USB_EP_MAXP_MULT_MASK   (3 << USB_EP_MAXP_MULT_SHIFT)
0442 #define USB_EP_MAXP_MULT(m) \
0443     (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
0444 
0445 /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
0446 #define USB_ENDPOINT_INTRTYPE       0x30
0447 #define USB_ENDPOINT_INTR_PERIODIC  (0 << 4)
0448 #define USB_ENDPOINT_INTR_NOTIFICATION  (1 << 4)
0449 
0450 #define USB_ENDPOINT_SYNCTYPE       0x0c
0451 #define USB_ENDPOINT_SYNC_NONE      (0 << 2)
0452 #define USB_ENDPOINT_SYNC_ASYNC     (1 << 2)
0453 #define USB_ENDPOINT_SYNC_ADAPTIVE  (2 << 2)
0454 #define USB_ENDPOINT_SYNC_SYNC      (3 << 2)
0455 
0456 #define USB_ENDPOINT_USAGE_MASK     0x30
0457 #define USB_ENDPOINT_USAGE_DATA     0x00
0458 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
0459 #define USB_ENDPOINT_USAGE_IMPLICIT_FB  0x20    /* Implicit feedback Data endpoint */
0460 
0461 /*-------------------------------------------------------------------------*/
0462 
0463 /**
0464  * usb_endpoint_num - get the endpoint's number
0465  * @epd: endpoint to be checked
0466  *
0467  * Returns @epd's number: 0 to 15.
0468  */
0469 static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
0470 {
0471     return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
0472 }
0473 
0474 /**
0475  * usb_endpoint_type - get the endpoint's transfer type
0476  * @epd: endpoint to be checked
0477  *
0478  * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
0479  * to @epd's transfer type.
0480  */
0481 static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
0482 {
0483     return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
0484 }
0485 
0486 /**
0487  * usb_endpoint_dir_in - check if the endpoint has IN direction
0488  * @epd: endpoint to be checked
0489  *
0490  * Returns true if the endpoint is of type IN, otherwise it returns false.
0491  */
0492 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
0493 {
0494     return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
0495 }
0496 
0497 /**
0498  * usb_endpoint_dir_out - check if the endpoint has OUT direction
0499  * @epd: endpoint to be checked
0500  *
0501  * Returns true if the endpoint is of type OUT, otherwise it returns false.
0502  */
0503 static inline int usb_endpoint_dir_out(
0504                 const struct usb_endpoint_descriptor *epd)
0505 {
0506     return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
0507 }
0508 
0509 /**
0510  * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
0511  * @epd: endpoint to be checked
0512  *
0513  * Returns true if the endpoint is of type bulk, otherwise it returns false.
0514  */
0515 static inline int usb_endpoint_xfer_bulk(
0516                 const struct usb_endpoint_descriptor *epd)
0517 {
0518     return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
0519         USB_ENDPOINT_XFER_BULK);
0520 }
0521 
0522 /**
0523  * usb_endpoint_xfer_control - check if the endpoint has control transfer type
0524  * @epd: endpoint to be checked
0525  *
0526  * Returns true if the endpoint is of type control, otherwise it returns false.
0527  */
0528 static inline int usb_endpoint_xfer_control(
0529                 const struct usb_endpoint_descriptor *epd)
0530 {
0531     return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
0532         USB_ENDPOINT_XFER_CONTROL);
0533 }
0534 
0535 /**
0536  * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
0537  * @epd: endpoint to be checked
0538  *
0539  * Returns true if the endpoint is of type interrupt, otherwise it returns
0540  * false.
0541  */
0542 static inline int usb_endpoint_xfer_int(
0543                 const struct usb_endpoint_descriptor *epd)
0544 {
0545     return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
0546         USB_ENDPOINT_XFER_INT);
0547 }
0548 
0549 /**
0550  * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
0551  * @epd: endpoint to be checked
0552  *
0553  * Returns true if the endpoint is of type isochronous, otherwise it returns
0554  * false.
0555  */
0556 static inline int usb_endpoint_xfer_isoc(
0557                 const struct usb_endpoint_descriptor *epd)
0558 {
0559     return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
0560         USB_ENDPOINT_XFER_ISOC);
0561 }
0562 
0563 /**
0564  * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
0565  * @epd: endpoint to be checked
0566  *
0567  * Returns true if the endpoint has bulk transfer type and IN direction,
0568  * otherwise it returns false.
0569  */
0570 static inline int usb_endpoint_is_bulk_in(
0571                 const struct usb_endpoint_descriptor *epd)
0572 {
0573     return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
0574 }
0575 
0576 /**
0577  * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
0578  * @epd: endpoint to be checked
0579  *
0580  * Returns true if the endpoint has bulk transfer type and OUT direction,
0581  * otherwise it returns false.
0582  */
0583 static inline int usb_endpoint_is_bulk_out(
0584                 const struct usb_endpoint_descriptor *epd)
0585 {
0586     return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
0587 }
0588 
0589 /**
0590  * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
0591  * @epd: endpoint to be checked
0592  *
0593  * Returns true if the endpoint has interrupt transfer type and IN direction,
0594  * otherwise it returns false.
0595  */
0596 static inline int usb_endpoint_is_int_in(
0597                 const struct usb_endpoint_descriptor *epd)
0598 {
0599     return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
0600 }
0601 
0602 /**
0603  * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
0604  * @epd: endpoint to be checked
0605  *
0606  * Returns true if the endpoint has interrupt transfer type and OUT direction,
0607  * otherwise it returns false.
0608  */
0609 static inline int usb_endpoint_is_int_out(
0610                 const struct usb_endpoint_descriptor *epd)
0611 {
0612     return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
0613 }
0614 
0615 /**
0616  * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
0617  * @epd: endpoint to be checked
0618  *
0619  * Returns true if the endpoint has isochronous transfer type and IN direction,
0620  * otherwise it returns false.
0621  */
0622 static inline int usb_endpoint_is_isoc_in(
0623                 const struct usb_endpoint_descriptor *epd)
0624 {
0625     return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
0626 }
0627 
0628 /**
0629  * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
0630  * @epd: endpoint to be checked
0631  *
0632  * Returns true if the endpoint has isochronous transfer type and OUT direction,
0633  * otherwise it returns false.
0634  */
0635 static inline int usb_endpoint_is_isoc_out(
0636                 const struct usb_endpoint_descriptor *epd)
0637 {
0638     return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
0639 }
0640 
0641 /**
0642  * usb_endpoint_maxp - get endpoint's max packet size
0643  * @epd: endpoint to be checked
0644  *
0645  * Returns @epd's max packet bits [10:0]
0646  */
0647 static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
0648 {
0649     return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK;
0650 }
0651 
0652 /**
0653  * usb_endpoint_maxp_mult - get endpoint's transactional opportunities
0654  * @epd: endpoint to be checked
0655  *
0656  * Return @epd's wMaxPacketSize[12:11] + 1
0657  */
0658 static inline int
0659 usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd)
0660 {
0661     int maxp = __le16_to_cpu(epd->wMaxPacketSize);
0662 
0663     return USB_EP_MAXP_MULT(maxp) + 1;
0664 }
0665 
0666 static inline int usb_endpoint_interrupt_type(
0667         const struct usb_endpoint_descriptor *epd)
0668 {
0669     return epd->bmAttributes & USB_ENDPOINT_INTRTYPE;
0670 }
0671 
0672 /*-------------------------------------------------------------------------*/
0673 
0674 /* USB_DT_SSP_ISOC_ENDPOINT_COMP: SuperSpeedPlus Isochronous Endpoint Companion
0675  * descriptor
0676  */
0677 struct usb_ssp_isoc_ep_comp_descriptor {
0678     __u8  bLength;
0679     __u8  bDescriptorType;
0680     __le16 wReseved;
0681     __le32 dwBytesPerInterval;
0682 } __attribute__ ((packed));
0683 
0684 #define USB_DT_SSP_ISOC_EP_COMP_SIZE        8
0685 
0686 /*-------------------------------------------------------------------------*/
0687 
0688 /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
0689 struct usb_ss_ep_comp_descriptor {
0690     __u8  bLength;
0691     __u8  bDescriptorType;
0692 
0693     __u8  bMaxBurst;
0694     __u8  bmAttributes;
0695     __le16 wBytesPerInterval;
0696 } __attribute__ ((packed));
0697 
0698 #define USB_DT_SS_EP_COMP_SIZE      6
0699 
0700 /* Bits 4:0 of bmAttributes if this is a bulk endpoint */
0701 static inline int
0702 usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp)
0703 {
0704     int     max_streams;
0705 
0706     if (!comp)
0707         return 0;
0708 
0709     max_streams = comp->bmAttributes & 0x1f;
0710 
0711     if (!max_streams)
0712         return 0;
0713 
0714     max_streams = 1 << max_streams;
0715 
0716     return max_streams;
0717 }
0718 
0719 /* Bits 1:0 of bmAttributes if this is an isoc endpoint */
0720 #define USB_SS_MULT(p)          (1 + ((p) & 0x3))
0721 /* Bit 7 of bmAttributes if a SSP isoc endpoint companion descriptor exists */
0722 #define USB_SS_SSP_ISOC_COMP(p)     ((p) & (1 << 7))
0723 
0724 /*-------------------------------------------------------------------------*/
0725 
0726 /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
0727 struct usb_qualifier_descriptor {
0728     __u8  bLength;
0729     __u8  bDescriptorType;
0730 
0731     __le16 bcdUSB;
0732     __u8  bDeviceClass;
0733     __u8  bDeviceSubClass;
0734     __u8  bDeviceProtocol;
0735     __u8  bMaxPacketSize0;
0736     __u8  bNumConfigurations;
0737     __u8  bRESERVED;
0738 } __attribute__ ((packed));
0739 
0740 
0741 /*-------------------------------------------------------------------------*/
0742 
0743 /* USB_DT_OTG (from OTG 1.0a supplement) */
0744 struct usb_otg_descriptor {
0745     __u8  bLength;
0746     __u8  bDescriptorType;
0747 
0748     __u8  bmAttributes; /* support for HNP, SRP, etc */
0749 } __attribute__ ((packed));
0750 
0751 /* USB_DT_OTG (from OTG 2.0 supplement) */
0752 struct usb_otg20_descriptor {
0753     __u8  bLength;
0754     __u8  bDescriptorType;
0755 
0756     __u8  bmAttributes; /* support for HNP, SRP and ADP, etc */
0757     __le16 bcdOTG;      /* OTG and EH supplement release number
0758                  * in binary-coded decimal(i.e. 2.0 is 0200H)
0759                  */
0760 } __attribute__ ((packed));
0761 
0762 /* from usb_otg_descriptor.bmAttributes */
0763 #define USB_OTG_SRP     (1 << 0)
0764 #define USB_OTG_HNP     (1 << 1)    /* swap host/device roles */
0765 #define USB_OTG_ADP     (1 << 2)    /* support ADP */
0766 
0767 #define OTG_STS_SELECTOR    0xF000      /* OTG status selector */
0768 /*-------------------------------------------------------------------------*/
0769 
0770 /* USB_DT_DEBUG:  for special highspeed devices, replacing serial console */
0771 struct usb_debug_descriptor {
0772     __u8  bLength;
0773     __u8  bDescriptorType;
0774 
0775     /* bulk endpoints with 8 byte maxpacket */
0776     __u8  bDebugInEndpoint;
0777     __u8  bDebugOutEndpoint;
0778 } __attribute__((packed));
0779 
0780 /*-------------------------------------------------------------------------*/
0781 
0782 /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
0783 struct usb_interface_assoc_descriptor {
0784     __u8  bLength;
0785     __u8  bDescriptorType;
0786 
0787     __u8  bFirstInterface;
0788     __u8  bInterfaceCount;
0789     __u8  bFunctionClass;
0790     __u8  bFunctionSubClass;
0791     __u8  bFunctionProtocol;
0792     __u8  iFunction;
0793 } __attribute__ ((packed));
0794 
0795 #define USB_DT_INTERFACE_ASSOCIATION_SIZE   8
0796 
0797 /*-------------------------------------------------------------------------*/
0798 
0799 /* USB_DT_SECURITY:  group of wireless security descriptors, including
0800  * encryption types available for setting up a CC/association.
0801  */
0802 struct usb_security_descriptor {
0803     __u8  bLength;
0804     __u8  bDescriptorType;
0805 
0806     __le16 wTotalLength;
0807     __u8  bNumEncryptionTypes;
0808 } __attribute__((packed));
0809 
0810 /*-------------------------------------------------------------------------*/
0811 
0812 /* USB_DT_KEY:  used with {GET,SET}_SECURITY_DATA; only public keys
0813  * may be retrieved.
0814  */
0815 struct usb_key_descriptor {
0816     __u8  bLength;
0817     __u8  bDescriptorType;
0818 
0819     __u8  tTKID[3];
0820     __u8  bReserved;
0821     __u8  bKeyData[];
0822 } __attribute__((packed));
0823 
0824 /*-------------------------------------------------------------------------*/
0825 
0826 /* USB_DT_ENCRYPTION_TYPE:  bundled in DT_SECURITY groups */
0827 struct usb_encryption_descriptor {
0828     __u8  bLength;
0829     __u8  bDescriptorType;
0830 
0831     __u8  bEncryptionType;
0832 #define USB_ENC_TYPE_UNSECURE       0
0833 #define USB_ENC_TYPE_WIRED      1   /* non-wireless mode */
0834 #define USB_ENC_TYPE_CCM_1      2   /* aes128/cbc session */
0835 #define USB_ENC_TYPE_RSA_1      3   /* rsa3072/sha1 auth */
0836     __u8  bEncryptionValue;     /* use in SET_ENCRYPTION */
0837     __u8  bAuthKeyIndex;
0838 } __attribute__((packed));
0839 
0840 
0841 /*-------------------------------------------------------------------------*/
0842 
0843 /* USB_DT_BOS:  group of device-level capabilities */
0844 struct usb_bos_descriptor {
0845     __u8  bLength;
0846     __u8  bDescriptorType;
0847 
0848     __le16 wTotalLength;
0849     __u8  bNumDeviceCaps;
0850 } __attribute__((packed));
0851 
0852 #define USB_DT_BOS_SIZE     5
0853 /*-------------------------------------------------------------------------*/
0854 
0855 /* USB_DT_DEVICE_CAPABILITY:  grouped with BOS */
0856 struct usb_dev_cap_header {
0857     __u8  bLength;
0858     __u8  bDescriptorType;
0859     __u8  bDevCapabilityType;
0860 } __attribute__((packed));
0861 
0862 #define USB_CAP_TYPE_WIRELESS_USB   1
0863 
0864 struct usb_wireless_cap_descriptor {    /* Ultra Wide Band */
0865     __u8  bLength;
0866     __u8  bDescriptorType;
0867     __u8  bDevCapabilityType;
0868 
0869     __u8  bmAttributes;
0870 #define USB_WIRELESS_P2P_DRD        (1 << 1)
0871 #define USB_WIRELESS_BEACON_MASK    (3 << 2)
0872 #define USB_WIRELESS_BEACON_SELF    (1 << 2)
0873 #define USB_WIRELESS_BEACON_DIRECTED    (2 << 2)
0874 #define USB_WIRELESS_BEACON_NONE    (3 << 2)
0875     __le16 wPHYRates;   /* bit rates, Mbps */
0876 #define USB_WIRELESS_PHY_53     (1 << 0)    /* always set */
0877 #define USB_WIRELESS_PHY_80     (1 << 1)
0878 #define USB_WIRELESS_PHY_107        (1 << 2)    /* always set */
0879 #define USB_WIRELESS_PHY_160        (1 << 3)
0880 #define USB_WIRELESS_PHY_200        (1 << 4)    /* always set */
0881 #define USB_WIRELESS_PHY_320        (1 << 5)
0882 #define USB_WIRELESS_PHY_400        (1 << 6)
0883 #define USB_WIRELESS_PHY_480        (1 << 7)
0884     __u8  bmTFITXPowerInfo; /* TFI power levels */
0885     __u8  bmFFITXPowerInfo; /* FFI power levels */
0886     __le16 bmBandGroup;
0887     __u8  bReserved;
0888 } __attribute__((packed));
0889 
0890 #define USB_DT_USB_WIRELESS_CAP_SIZE    11
0891 
0892 /* USB 2.0 Extension descriptor */
0893 #define USB_CAP_TYPE_EXT        2
0894 
0895 struct usb_ext_cap_descriptor {     /* Link Power Management */
0896     __u8  bLength;
0897     __u8  bDescriptorType;
0898     __u8  bDevCapabilityType;
0899     __le32 bmAttributes;
0900 #define USB_LPM_SUPPORT         (1 << 1)    /* supports LPM */
0901 #define USB_BESL_SUPPORT        (1 << 2)    /* supports BESL */
0902 #define USB_BESL_BASELINE_VALID     (1 << 3)    /* Baseline BESL valid*/
0903 #define USB_BESL_DEEP_VALID     (1 << 4)    /* Deep BESL valid */
0904 #define USB_SET_BESL_BASELINE(p)    (((p) & 0xf) << 8)
0905 #define USB_SET_BESL_DEEP(p)        (((p) & 0xf) << 12)
0906 #define USB_GET_BESL_BASELINE(p)    (((p) & (0xf << 8)) >> 8)
0907 #define USB_GET_BESL_DEEP(p)        (((p) & (0xf << 12)) >> 12)
0908 } __attribute__((packed));
0909 
0910 #define USB_DT_USB_EXT_CAP_SIZE 7
0911 
0912 /*
0913  * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB
0914  * specific device level capabilities
0915  */
0916 #define     USB_SS_CAP_TYPE     3
0917 struct usb_ss_cap_descriptor {      /* Link Power Management */
0918     __u8  bLength;
0919     __u8  bDescriptorType;
0920     __u8  bDevCapabilityType;
0921     __u8  bmAttributes;
0922 #define USB_LTM_SUPPORT         (1 << 1) /* supports LTM */
0923     __le16 wSpeedSupported;
0924 #define USB_LOW_SPEED_OPERATION     (1)  /* Low speed operation */
0925 #define USB_FULL_SPEED_OPERATION    (1 << 1) /* Full speed operation */
0926 #define USB_HIGH_SPEED_OPERATION    (1 << 2) /* High speed operation */
0927 #define USB_5GBPS_OPERATION     (1 << 3) /* Operation at 5Gbps */
0928     __u8  bFunctionalitySupport;
0929     __u8  bU1devExitLat;
0930     __le16 bU2DevExitLat;
0931 } __attribute__((packed));
0932 
0933 #define USB_DT_USB_SS_CAP_SIZE  10
0934 
0935 /*
0936  * Container ID Capability descriptor: Defines the instance unique ID used to
0937  * identify the instance across all operating modes
0938  */
0939 #define CONTAINER_ID_TYPE   4
0940 struct usb_ss_container_id_descriptor {
0941     __u8  bLength;
0942     __u8  bDescriptorType;
0943     __u8  bDevCapabilityType;
0944     __u8  bReserved;
0945     __u8  ContainerID[16]; /* 128-bit number */
0946 } __attribute__((packed));
0947 
0948 #define USB_DT_USB_SS_CONTN_ID_SIZE 20
0949 
0950 /*
0951  * SuperSpeed Plus USB Capability descriptor: Defines the set of
0952  * SuperSpeed Plus USB specific device level capabilities
0953  */
0954 #define USB_SSP_CAP_TYPE    0xa
0955 struct usb_ssp_cap_descriptor {
0956     __u8  bLength;
0957     __u8  bDescriptorType;
0958     __u8  bDevCapabilityType;
0959     __u8  bReserved;
0960     __le32 bmAttributes;
0961 #define USB_SSP_SUBLINK_SPEED_ATTRIBS   (0x1f << 0) /* sublink speed entries */
0962 #define USB_SSP_SUBLINK_SPEED_IDS   (0xf << 5)  /* speed ID entries */
0963     __le16  wFunctionalitySupport;
0964 #define USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID  (0xf)
0965 #define USB_SSP_MIN_RX_LANE_COUNT       (0xf << 8)
0966 #define USB_SSP_MIN_TX_LANE_COUNT       (0xf << 12)
0967     __le16 wReserved;
0968     __le32 bmSublinkSpeedAttr[1]; /* list of sublink speed attrib entries */
0969 #define USB_SSP_SUBLINK_SPEED_SSID  (0xf)       /* sublink speed ID */
0970 #define USB_SSP_SUBLINK_SPEED_LSE   (0x3 << 4)  /* Lanespeed exponent */
0971 #define USB_SSP_SUBLINK_SPEED_LSE_BPS       0
0972 #define USB_SSP_SUBLINK_SPEED_LSE_KBPS      1
0973 #define USB_SSP_SUBLINK_SPEED_LSE_MBPS      2
0974 #define USB_SSP_SUBLINK_SPEED_LSE_GBPS      3
0975 
0976 #define USB_SSP_SUBLINK_SPEED_ST    (0x3 << 6)  /* Sublink type */
0977 #define USB_SSP_SUBLINK_SPEED_ST_SYM_RX     0
0978 #define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX    1
0979 #define USB_SSP_SUBLINK_SPEED_ST_SYM_TX     2
0980 #define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX    3
0981 
0982 #define USB_SSP_SUBLINK_SPEED_RSVD  (0x3f << 8) /* Reserved */
0983 #define USB_SSP_SUBLINK_SPEED_LP    (0x3 << 14) /* Link protocol */
0984 #define USB_SSP_SUBLINK_SPEED_LP_SS     0
0985 #define USB_SSP_SUBLINK_SPEED_LP_SSP        1
0986 
0987 #define USB_SSP_SUBLINK_SPEED_LSM   (0xff << 16)    /* Lanespeed mantissa */
0988 } __attribute__((packed));
0989 
0990 /*
0991  * USB Power Delivery Capability Descriptor:
0992  * Defines capabilities for PD
0993  */
0994 /* Defines the various PD Capabilities of this device */
0995 #define USB_PD_POWER_DELIVERY_CAPABILITY    0x06
0996 /* Provides information on each battery supported by the device */
0997 #define USB_PD_BATTERY_INFO_CAPABILITY      0x07
0998 /* The Consumer characteristics of a Port on the device */
0999 #define USB_PD_PD_CONSUMER_PORT_CAPABILITY  0x08
1000 /* The provider characteristics of a Port on the device */
1001 #define USB_PD_PD_PROVIDER_PORT_CAPABILITY  0x09
1002 
1003 struct usb_pd_cap_descriptor {
1004     __u8  bLength;
1005     __u8  bDescriptorType;
1006     __u8  bDevCapabilityType; /* set to USB_PD_POWER_DELIVERY_CAPABILITY */
1007     __u8  bReserved;
1008     __le32 bmAttributes;
1009 #define USB_PD_CAP_BATTERY_CHARGING (1 << 1) /* supports Battery Charging specification */
1010 #define USB_PD_CAP_USB_PD       (1 << 2) /* supports USB Power Delivery specification */
1011 #define USB_PD_CAP_PROVIDER     (1 << 3) /* can provide power */
1012 #define USB_PD_CAP_CONSUMER     (1 << 4) /* can consume power */
1013 #define USB_PD_CAP_CHARGING_POLICY  (1 << 5) /* supports CHARGING_POLICY feature */
1014 #define USB_PD_CAP_TYPE_C_CURRENT   (1 << 6) /* supports power capabilities defined in the USB Type-C Specification */
1015 
1016 #define USB_PD_CAP_PWR_AC       (1 << 8)
1017 #define USB_PD_CAP_PWR_BAT      (1 << 9)
1018 #define USB_PD_CAP_PWR_USE_V_BUS    (1 << 14)
1019 
1020     __le16 bmProviderPorts; /* Bit zero refers to the UFP of the device */
1021     __le16 bmConsumerPorts;
1022     __le16 bcdBCVersion;
1023     __le16 bcdPDVersion;
1024     __le16 bcdUSBTypeCVersion;
1025 } __attribute__((packed));
1026 
1027 struct usb_pd_cap_battery_info_descriptor {
1028     __u8 bLength;
1029     __u8 bDescriptorType;
1030     __u8 bDevCapabilityType;
1031     /* Index of string descriptor shall contain the user friendly name for this battery */
1032     __u8 iBattery;
1033     /* Index of string descriptor shall contain the Serial Number String for this battery */
1034     __u8 iSerial;
1035     __u8 iManufacturer;
1036     __u8 bBatteryId; /* uniquely identifies this battery in status Messages */
1037     __u8 bReserved;
1038     /*
1039      * Shall contain the Battery Charge value above which this
1040      * battery is considered to be fully charged but not necessarily
1041      * “topped off.”
1042      */
1043     __le32 dwChargedThreshold; /* in mWh */
1044     /*
1045      * Shall contain the minimum charge level of this battery such
1046      * that above this threshold, a device can be assured of being
1047      * able to power up successfully (see Battery Charging 1.2).
1048      */
1049     __le32 dwWeakThreshold; /* in mWh */
1050     __le32 dwBatteryDesignCapacity; /* in mWh */
1051     __le32 dwBatteryLastFullchargeCapacity; /* in mWh */
1052 } __attribute__((packed));
1053 
1054 struct usb_pd_cap_consumer_port_descriptor {
1055     __u8 bLength;
1056     __u8 bDescriptorType;
1057     __u8 bDevCapabilityType;
1058     __u8 bReserved;
1059     __u8 bmCapabilities;
1060 /* port will oerate under: */
1061 #define USB_PD_CAP_CONSUMER_BC      (1 << 0) /* BC */
1062 #define USB_PD_CAP_CONSUMER_PD      (1 << 1) /* PD */
1063 #define USB_PD_CAP_CONSUMER_TYPE_C  (1 << 2) /* USB Type-C Current */
1064     __le16 wMinVoltage; /* in 50mV units */
1065     __le16 wMaxVoltage; /* in 50mV units */
1066     __u16 wReserved;
1067     __le32 dwMaxOperatingPower; /* in 10 mW - operating at steady state */
1068     __le32 dwMaxPeakPower; /* in 10mW units - operating at peak power */
1069     __le32 dwMaxPeakPowerTime; /* in 100ms units - duration of peak */
1070 #define USB_PD_CAP_CONSUMER_UNKNOWN_PEAK_POWER_TIME 0xffff
1071 } __attribute__((packed));
1072 
1073 struct usb_pd_cap_provider_port_descriptor {
1074     __u8 bLength;
1075     __u8 bDescriptorType;
1076     __u8 bDevCapabilityType;
1077     __u8 bReserved1;
1078     __u8 bmCapabilities;
1079 /* port will oerate under: */
1080 #define USB_PD_CAP_PROVIDER_BC      (1 << 0) /* BC */
1081 #define USB_PD_CAP_PROVIDER_PD      (1 << 1) /* PD */
1082 #define USB_PD_CAP_PROVIDER_TYPE_C  (1 << 2) /* USB Type-C Current */
1083     __u8 bNumOfPDObjects;
1084     __u8 bReserved2;
1085     __le32 wPowerDataObject[];
1086 } __attribute__((packed));
1087 
1088 /*
1089  * Precision time measurement capability descriptor: advertised by devices and
1090  * hubs that support PTM
1091  */
1092 #define USB_PTM_CAP_TYPE    0xb
1093 struct usb_ptm_cap_descriptor {
1094     __u8  bLength;
1095     __u8  bDescriptorType;
1096     __u8  bDevCapabilityType;
1097 } __attribute__((packed));
1098 
1099 #define USB_DT_USB_PTM_ID_SIZE      3
1100 /*
1101  * The size of the descriptor for the Sublink Speed Attribute Count
1102  * (SSAC) specified in bmAttributes[4:0]. SSAC is zero-based
1103  */
1104 #define USB_DT_USB_SSP_CAP_SIZE(ssac)   (12 + (ssac + 1) * 4)
1105 
1106 /*-------------------------------------------------------------------------*/
1107 
1108 /* USB_DT_WIRELESS_ENDPOINT_COMP:  companion descriptor associated with
1109  * each endpoint descriptor for a wireless device
1110  */
1111 struct usb_wireless_ep_comp_descriptor {
1112     __u8  bLength;
1113     __u8  bDescriptorType;
1114 
1115     __u8  bMaxBurst;
1116     __u8  bMaxSequence;
1117     __le16 wMaxStreamDelay;
1118     __le16 wOverTheAirPacketSize;
1119     __u8  bOverTheAirInterval;
1120     __u8  bmCompAttributes;
1121 #define USB_ENDPOINT_SWITCH_MASK    0x03    /* in bmCompAttributes */
1122 #define USB_ENDPOINT_SWITCH_NO      0
1123 #define USB_ENDPOINT_SWITCH_SWITCH  1
1124 #define USB_ENDPOINT_SWITCH_SCALE   2
1125 } __attribute__((packed));
1126 
1127 /*-------------------------------------------------------------------------*/
1128 
1129 /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
1130  * host and a device for connection set up, mutual authentication, and
1131  * exchanging short lived session keys.  The handshake depends on a CC.
1132  */
1133 struct usb_handshake {
1134     __u8 bMessageNumber;
1135     __u8 bStatus;
1136     __u8 tTKID[3];
1137     __u8 bReserved;
1138     __u8 CDID[16];
1139     __u8 nonce[16];
1140     __u8 MIC[8];
1141 } __attribute__((packed));
1142 
1143 /*-------------------------------------------------------------------------*/
1144 
1145 /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
1146  * A CC may also be set up using non-wireless secure channels (including
1147  * wired USB!), and some devices may support CCs with multiple hosts.
1148  */
1149 struct usb_connection_context {
1150     __u8 CHID[16];      /* persistent host id */
1151     __u8 CDID[16];      /* device id (unique w/in host context) */
1152     __u8 CK[16];        /* connection key */
1153 } __attribute__((packed));
1154 
1155 /*-------------------------------------------------------------------------*/
1156 
1157 /* USB 2.0 defines three speeds, here's how Linux identifies them */
1158 
1159 enum usb_device_speed {
1160     USB_SPEED_UNKNOWN = 0,          /* enumerating */
1161     USB_SPEED_LOW, USB_SPEED_FULL,      /* usb 1.1 */
1162     USB_SPEED_HIGH,             /* usb 2.0 */
1163     USB_SPEED_WIRELESS,         /* wireless (usb 2.5) */
1164     USB_SPEED_SUPER,            /* usb 3.0 */
1165     USB_SPEED_SUPER_PLUS,           /* usb 3.1 */
1166 };
1167 
1168 
1169 enum usb_device_state {
1170     /* NOTATTACHED isn't in the USB spec, and this state acts
1171      * the same as ATTACHED ... but it's clearer this way.
1172      */
1173     USB_STATE_NOTATTACHED = 0,
1174 
1175     /* chapter 9 and authentication (wireless) device states */
1176     USB_STATE_ATTACHED,
1177     USB_STATE_POWERED,          /* wired */
1178     USB_STATE_RECONNECTING,         /* auth */
1179     USB_STATE_UNAUTHENTICATED,      /* auth */
1180     USB_STATE_DEFAULT,          /* limited function */
1181     USB_STATE_ADDRESS,
1182     USB_STATE_CONFIGURED,           /* most functions */
1183 
1184     USB_STATE_SUSPENDED
1185 
1186     /* NOTE:  there are actually four different SUSPENDED
1187      * states, returning to POWERED, DEFAULT, ADDRESS, or
1188      * CONFIGURED respectively when SOF tokens flow again.
1189      * At this level there's no difference between L1 and L2
1190      * suspend states.  (L2 being original USB 1.1 suspend.)
1191      */
1192 };
1193 
1194 enum usb3_link_state {
1195     USB3_LPM_U0 = 0,
1196     USB3_LPM_U1,
1197     USB3_LPM_U2,
1198     USB3_LPM_U3
1199 };
1200 
1201 /*
1202  * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1.
1203  * 0xff means the parent hub will accept transitions to U1, but will not
1204  * initiate a transition.
1205  *
1206  * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to
1207  * U1 after that many microseconds.  Timeouts of 0x80 to 0xFE are reserved
1208  * values.
1209  *
1210  * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2.
1211  * 0xff means the parent hub will accept transitions to U2, but will not
1212  * initiate a transition.
1213  *
1214  * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to
1215  * U2 after N*256 microseconds.  Therefore a U2 timeout value of 0x1 means a U2
1216  * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means
1217  * 65.024ms.
1218  */
1219 #define USB3_LPM_DISABLED       0x0
1220 #define USB3_LPM_U1_MAX_TIMEOUT     0x7F
1221 #define USB3_LPM_U2_MAX_TIMEOUT     0xFE
1222 #define USB3_LPM_DEVICE_INITIATED   0xFF
1223 
1224 struct usb_set_sel_req {
1225     __u8    u1_sel;
1226     __u8    u1_pel;
1227     __le16  u2_sel;
1228     __le16  u2_pel;
1229 } __attribute__ ((packed));
1230 
1231 /*
1232  * The Set System Exit Latency control transfer provides one byte each for
1233  * U1 SEL and U1 PEL, so the max exit latency is 0xFF.  U2 SEL and U2 PEL each
1234  * are two bytes long.
1235  */
1236 #define USB3_LPM_MAX_U1_SEL_PEL     0xFF
1237 #define USB3_LPM_MAX_U2_SEL_PEL     0xFFFF
1238 
1239 /*-------------------------------------------------------------------------*/
1240 
1241 /*
1242  * As per USB compliance update, a device that is actively drawing
1243  * more than 100mA from USB must report itself as bus-powered in
1244  * the GetStatus(DEVICE) call.
1245  * https://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34
1246  */
1247 #define USB_SELF_POWER_VBUS_MAX_DRAW        100
1248 
1249 #endif /* _UAPI__LINUX_USB_CH9_H */