blob: c1121fbd83b3ab2b8704625596dce677d8574638 [file] [log] [blame]
Elliott Hughes180edef2023-11-02 00:08:05 +00001/*
2 * This file is auto-generated. Modifications will be lost.
3 *
4 * See https://android.googlesource.com/platform/bionic/+/master/libc/kernel/
5 * for more information.
6 */
Ben Cheng655a7c02013-10-16 16:09:24 -07007#ifndef _UAPI__LINUX_USB_CH9_H
8#define _UAPI__LINUX_USB_CH9_H
9#include <linux/types.h>
10#include <asm/byteorder.h>
Ben Cheng655a7c02013-10-16 16:09:24 -070011#define USB_DIR_OUT 0
12#define USB_DIR_IN 0x80
13#define USB_TYPE_MASK (0x03 << 5)
14#define USB_TYPE_STANDARD (0x00 << 5)
Ben Cheng655a7c02013-10-16 16:09:24 -070015#define USB_TYPE_CLASS (0x01 << 5)
16#define USB_TYPE_VENDOR (0x02 << 5)
17#define USB_TYPE_RESERVED (0x03 << 5)
18#define USB_RECIP_MASK 0x1f
Ben Cheng655a7c02013-10-16 16:09:24 -070019#define USB_RECIP_DEVICE 0x00
20#define USB_RECIP_INTERFACE 0x01
21#define USB_RECIP_ENDPOINT 0x02
22#define USB_RECIP_OTHER 0x03
Ben Cheng655a7c02013-10-16 16:09:24 -070023#define USB_RECIP_PORT 0x04
24#define USB_RECIP_RPIPE 0x05
25#define USB_REQ_GET_STATUS 0x00
26#define USB_REQ_CLEAR_FEATURE 0x01
Ben Cheng655a7c02013-10-16 16:09:24 -070027#define USB_REQ_SET_FEATURE 0x03
28#define USB_REQ_SET_ADDRESS 0x05
29#define USB_REQ_GET_DESCRIPTOR 0x06
30#define USB_REQ_SET_DESCRIPTOR 0x07
Ben Cheng655a7c02013-10-16 16:09:24 -070031#define USB_REQ_GET_CONFIGURATION 0x08
32#define USB_REQ_SET_CONFIGURATION 0x09
33#define USB_REQ_GET_INTERFACE 0x0A
34#define USB_REQ_SET_INTERFACE 0x0B
Ben Cheng655a7c02013-10-16 16:09:24 -070035#define USB_REQ_SYNCH_FRAME 0x0C
36#define USB_REQ_SET_SEL 0x30
37#define USB_REQ_SET_ISOCH_DELAY 0x31
38#define USB_REQ_SET_ENCRYPTION 0x0D
Ben Cheng655a7c02013-10-16 16:09:24 -070039#define USB_REQ_GET_ENCRYPTION 0x0E
40#define USB_REQ_RPIPE_ABORT 0x0E
41#define USB_REQ_SET_HANDSHAKE 0x0F
42#define USB_REQ_RPIPE_RESET 0x0F
Ben Cheng655a7c02013-10-16 16:09:24 -070043#define USB_REQ_GET_HANDSHAKE 0x10
44#define USB_REQ_SET_CONNECTION 0x11
45#define USB_REQ_SET_SECURITY_DATA 0x12
46#define USB_REQ_GET_SECURITY_DATA 0x13
Ben Cheng655a7c02013-10-16 16:09:24 -070047#define USB_REQ_SET_WUSB_DATA 0x14
48#define USB_REQ_LOOPBACK_DATA_WRITE 0x15
49#define USB_REQ_LOOPBACK_DATA_READ 0x16
50#define USB_REQ_SET_INTERFACE_DS 0x17
Christopher Ferris106b3a82016-08-24 12:15:38 -070051#define USB_REQ_GET_PARTNER_PDO 20
52#define USB_REQ_GET_BATTERY_STATUS 21
53#define USB_REQ_SET_PDO 22
54#define USB_REQ_GET_VDM 23
Christopher Ferris106b3a82016-08-24 12:15:38 -070055#define USB_REQ_SEND_VDM 24
Ben Cheng655a7c02013-10-16 16:09:24 -070056#define USB_DEVICE_SELF_POWERED 0
57#define USB_DEVICE_REMOTE_WAKEUP 1
58#define USB_DEVICE_TEST_MODE 2
Christopher Ferris106b3a82016-08-24 12:15:38 -070059#define USB_DEVICE_BATTERY 2
Ben Cheng655a7c02013-10-16 16:09:24 -070060#define USB_DEVICE_B_HNP_ENABLE 3
61#define USB_DEVICE_WUSB_DEVICE 3
62#define USB_DEVICE_A_HNP_SUPPORT 4
Christopher Ferris106b3a82016-08-24 12:15:38 -070063#define USB_DEVICE_A_ALT_HNP_SUPPORT 5
Ben Cheng655a7c02013-10-16 16:09:24 -070064#define USB_DEVICE_DEBUG_MODE 6
Christopher Ferris25c18d42020-10-14 17:42:58 -070065#define USB_TEST_J 1
66#define USB_TEST_K 2
67#define USB_TEST_SE0_NAK 3
68#define USB_TEST_PACKET 4
69#define USB_TEST_FORCE_ENABLE 5
Christopher Ferris934ec942018-01-31 15:29:16 -080070#define USB_STATUS_TYPE_STANDARD 0
71#define USB_STATUS_TYPE_PTM 1
Ben Cheng655a7c02013-10-16 16:09:24 -070072#define USB_DEVICE_U1_ENABLE 48
Christopher Ferris106b3a82016-08-24 12:15:38 -070073#define USB_DEVICE_U2_ENABLE 49
Ben Cheng655a7c02013-10-16 16:09:24 -070074#define USB_DEVICE_LTM_ENABLE 50
75#define USB_INTRF_FUNC_SUSPEND 0
76#define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
Christopher Ferris106b3a82016-08-24 12:15:38 -070077#define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
Ben Cheng655a7c02013-10-16 16:09:24 -070078#define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))
79#define USB_INTRF_STAT_FUNC_RW_CAP 1
80#define USB_INTRF_STAT_FUNC_RW 2
Christopher Ferris106b3a82016-08-24 12:15:38 -070081#define USB_ENDPOINT_HALT 0
Ben Cheng655a7c02013-10-16 16:09:24 -070082#define USB_DEV_STAT_U1_ENABLED 2
83#define USB_DEV_STAT_U2_ENABLED 3
84#define USB_DEV_STAT_LTM_ENABLED 4
Christopher Ferris106b3a82016-08-24 12:15:38 -070085#define USB_DEVICE_BATTERY_WAKE_MASK 40
86#define USB_DEVICE_OS_IS_PD_AWARE 41
87#define USB_DEVICE_POLICY_MODE 42
88#define USB_PORT_PR_SWAP 43
Christopher Ferris106b3a82016-08-24 12:15:38 -070089#define USB_PORT_GOTO_MIN 44
90#define USB_PORT_RETURN_POWER 45
91#define USB_PORT_ACCEPT_PD_REQUEST 46
92#define USB_PORT_REJECT_PD_REQUEST 47
Christopher Ferris106b3a82016-08-24 12:15:38 -070093#define USB_PORT_PORT_PD_RESET 48
94#define USB_PORT_C_PORT_PD_CHANGE 49
95#define USB_PORT_CABLE_PD_RESET 50
96#define USB_DEVICE_CHARGING_POLICY 54
Christopher Ferris106b3a82016-08-24 12:15:38 -070097struct usb_ctrlrequest {
Tao Baod7db5942015-01-28 10:07:51 -080098 __u8 bRequestType;
99 __u8 bRequest;
100 __le16 wValue;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700101 __le16 wIndex;
Tao Baod7db5942015-01-28 10:07:51 -0800102 __le16 wLength;
103} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700104#define USB_DT_DEVICE 0x01
Christopher Ferris106b3a82016-08-24 12:15:38 -0700105#define USB_DT_CONFIG 0x02
Ben Cheng655a7c02013-10-16 16:09:24 -0700106#define USB_DT_STRING 0x03
107#define USB_DT_INTERFACE 0x04
108#define USB_DT_ENDPOINT 0x05
Christopher Ferris106b3a82016-08-24 12:15:38 -0700109#define USB_DT_DEVICE_QUALIFIER 0x06
Ben Cheng655a7c02013-10-16 16:09:24 -0700110#define USB_DT_OTHER_SPEED_CONFIG 0x07
111#define USB_DT_INTERFACE_POWER 0x08
112#define USB_DT_OTG 0x09
Christopher Ferris106b3a82016-08-24 12:15:38 -0700113#define USB_DT_DEBUG 0x0a
Ben Cheng655a7c02013-10-16 16:09:24 -0700114#define USB_DT_INTERFACE_ASSOCIATION 0x0b
115#define USB_DT_SECURITY 0x0c
116#define USB_DT_KEY 0x0d
Christopher Ferris106b3a82016-08-24 12:15:38 -0700117#define USB_DT_ENCRYPTION_TYPE 0x0e
Ben Cheng655a7c02013-10-16 16:09:24 -0700118#define USB_DT_BOS 0x0f
119#define USB_DT_DEVICE_CAPABILITY 0x10
120#define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
Christopher Ferris106b3a82016-08-24 12:15:38 -0700121#define USB_DT_WIRE_ADAPTER 0x21
Christopher Ferris65552ba2024-11-20 17:55:06 +0000122#define USB_DT_DFU_FUNCTIONAL 0x21
Ben Cheng655a7c02013-10-16 16:09:24 -0700123#define USB_DT_RPIPE 0x22
124#define USB_DT_CS_RADIO_CONTROL 0x23
125#define USB_DT_PIPE_USAGE 0x24
Christopher Ferris106b3a82016-08-24 12:15:38 -0700126#define USB_DT_SS_ENDPOINT_COMP 0x30
127#define USB_DT_SSP_ISOC_ENDPOINT_COMP 0x31
Ben Cheng655a7c02013-10-16 16:09:24 -0700128#define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE)
129#define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG)
130#define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING)
131#define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE)
Ben Cheng655a7c02013-10-16 16:09:24 -0700132#define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT)
133struct usb_descriptor_header {
Tao Baod7db5942015-01-28 10:07:51 -0800134 __u8 bLength;
135 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800136} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700137struct usb_device_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800138 __u8 bLength;
139 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800140 __le16 bcdUSB;
141 __u8 bDeviceClass;
142 __u8 bDeviceSubClass;
143 __u8 bDeviceProtocol;
Tao Baod7db5942015-01-28 10:07:51 -0800144 __u8 bMaxPacketSize0;
145 __le16 idVendor;
146 __le16 idProduct;
147 __le16 bcdDevice;
Tao Baod7db5942015-01-28 10:07:51 -0800148 __u8 iManufacturer;
149 __u8 iProduct;
150 __u8 iSerialNumber;
151 __u8 bNumConfigurations;
Tao Baod7db5942015-01-28 10:07:51 -0800152} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700153#define USB_DT_DEVICE_SIZE 18
154#define USB_CLASS_PER_INTERFACE 0
155#define USB_CLASS_AUDIO 1
Ben Cheng655a7c02013-10-16 16:09:24 -0700156#define USB_CLASS_COMM 2
157#define USB_CLASS_HID 3
158#define USB_CLASS_PHYSICAL 5
159#define USB_CLASS_STILL_IMAGE 6
Ben Cheng655a7c02013-10-16 16:09:24 -0700160#define USB_CLASS_PRINTER 7
161#define USB_CLASS_MASS_STORAGE 8
162#define USB_CLASS_HUB 9
163#define USB_CLASS_CDC_DATA 0x0a
Ben Cheng655a7c02013-10-16 16:09:24 -0700164#define USB_CLASS_CSCID 0x0b
165#define USB_CLASS_CONTENT_SEC 0x0d
166#define USB_CLASS_VIDEO 0x0e
167#define USB_CLASS_WIRELESS_CONTROLLER 0xe0
Christopher Ferris25c18d42020-10-14 17:42:58 -0700168#define USB_CLASS_PERSONAL_HEALTHCARE 0x0f
169#define USB_CLASS_AUDIO_VIDEO 0x10
170#define USB_CLASS_BILLBOARD 0x11
171#define USB_CLASS_USB_TYPE_C_BRIDGE 0x12
Ben Cheng655a7c02013-10-16 16:09:24 -0700172#define USB_CLASS_MISC 0xef
173#define USB_CLASS_APP_SPEC 0xfe
Christopher Ferris65552ba2024-11-20 17:55:06 +0000174#define USB_SUBCLASS_DFU 0x01
Ben Cheng655a7c02013-10-16 16:09:24 -0700175#define USB_CLASS_VENDOR_SPEC 0xff
176#define USB_SUBCLASS_VENDOR_SPEC 0xff
Ben Cheng655a7c02013-10-16 16:09:24 -0700177struct usb_config_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800178 __u8 bLength;
179 __u8 bDescriptorType;
180 __le16 wTotalLength;
Tao Baod7db5942015-01-28 10:07:51 -0800181 __u8 bNumInterfaces;
182 __u8 bConfigurationValue;
183 __u8 iConfiguration;
184 __u8 bmAttributes;
Tao Baod7db5942015-01-28 10:07:51 -0800185 __u8 bMaxPower;
186} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700187#define USB_DT_CONFIG_SIZE 9
188#define USB_CONFIG_ATT_ONE (1 << 7)
Ben Cheng655a7c02013-10-16 16:09:24 -0700189#define USB_CONFIG_ATT_SELFPOWER (1 << 6)
190#define USB_CONFIG_ATT_WAKEUP (1 << 5)
191#define USB_CONFIG_ATT_BATTERY (1 << 4)
Christopher Ferris25c18d42020-10-14 17:42:58 -0700192#define USB_MAX_STRING_LEN 126
Ben Cheng655a7c02013-10-16 16:09:24 -0700193struct usb_string_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800194 __u8 bLength;
195 __u8 bDescriptorType;
Christopher Ferris8666d042023-09-06 14:55:31 -0700196 union {
197 __le16 legacy_padding;
198 __DECLARE_FLEX_ARRAY(__le16, wData);
199 };
Tao Baod7db5942015-01-28 10:07:51 -0800200} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700201struct usb_interface_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800202 __u8 bLength;
203 __u8 bDescriptorType;
204 __u8 bInterfaceNumber;
Tao Baod7db5942015-01-28 10:07:51 -0800205 __u8 bAlternateSetting;
206 __u8 bNumEndpoints;
207 __u8 bInterfaceClass;
208 __u8 bInterfaceSubClass;
Tao Baod7db5942015-01-28 10:07:51 -0800209 __u8 bInterfaceProtocol;
210 __u8 iInterface;
211} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700212#define USB_DT_INTERFACE_SIZE 9
Ben Cheng655a7c02013-10-16 16:09:24 -0700213struct usb_endpoint_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800214 __u8 bLength;
215 __u8 bDescriptorType;
216 __u8 bEndpointAddress;
Tao Baod7db5942015-01-28 10:07:51 -0800217 __u8 bmAttributes;
218 __le16 wMaxPacketSize;
219 __u8 bInterval;
220 __u8 bRefresh;
Tao Baod7db5942015-01-28 10:07:51 -0800221 __u8 bSynchAddress;
222} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700223#define USB_DT_ENDPOINT_SIZE 7
224#define USB_DT_ENDPOINT_AUDIO_SIZE 9
Ben Cheng655a7c02013-10-16 16:09:24 -0700225#define USB_ENDPOINT_NUMBER_MASK 0x0f
226#define USB_ENDPOINT_DIR_MASK 0x80
227#define USB_ENDPOINT_XFERTYPE_MASK 0x03
228#define USB_ENDPOINT_XFER_CONTROL 0
Ben Cheng655a7c02013-10-16 16:09:24 -0700229#define USB_ENDPOINT_XFER_ISOC 1
230#define USB_ENDPOINT_XFER_BULK 2
231#define USB_ENDPOINT_XFER_INT 3
232#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
Christopher Ferris48af7cb2017-02-21 12:35:09 -0800233#define USB_ENDPOINT_MAXP_MASK 0x07ff
234#define USB_EP_MAXP_MULT_SHIFT 11
Christopher Ferris48af7cb2017-02-21 12:35:09 -0800235#define USB_EP_MAXP_MULT_MASK (3 << USB_EP_MAXP_MULT_SHIFT)
236#define USB_EP_MAXP_MULT(m) (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
Ben Cheng655a7c02013-10-16 16:09:24 -0700237#define USB_ENDPOINT_INTRTYPE 0x30
238#define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
239#define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4)
240#define USB_ENDPOINT_SYNCTYPE 0x0c
Ben Cheng655a7c02013-10-16 16:09:24 -0700241#define USB_ENDPOINT_SYNC_NONE (0 << 2)
242#define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
243#define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
244#define USB_ENDPOINT_SYNC_SYNC (3 << 2)
Ben Cheng655a7c02013-10-16 16:09:24 -0700245#define USB_ENDPOINT_USAGE_MASK 0x30
246#define USB_ENDPOINT_USAGE_DATA 0x00
247#define USB_ENDPOINT_USAGE_FEEDBACK 0x10
248#define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20
Christopher Ferris106b3a82016-08-24 12:15:38 -0700249struct usb_ssp_isoc_ep_comp_descriptor {
250 __u8 bLength;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700251 __u8 bDescriptorType;
252 __le16 wReseved;
253 __le32 dwBytesPerInterval;
254} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700255#define USB_DT_SSP_ISOC_EP_COMP_SIZE 8
Ben Cheng655a7c02013-10-16 16:09:24 -0700256struct usb_ss_ep_comp_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800257 __u8 bLength;
258 __u8 bDescriptorType;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700259 __u8 bMaxBurst;
Tao Baod7db5942015-01-28 10:07:51 -0800260 __u8 bmAttributes;
261 __le16 wBytesPerInterval;
262} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700263#define USB_DT_SS_EP_COMP_SIZE 6
Ben Cheng655a7c02013-10-16 16:09:24 -0700264#define USB_SS_MULT(p) (1 + ((p) & 0x3))
Christopher Ferris106b3a82016-08-24 12:15:38 -0700265#define USB_SS_SSP_ISOC_COMP(p) ((p) & (1 << 7))
Ben Cheng655a7c02013-10-16 16:09:24 -0700266struct usb_qualifier_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800267 __u8 bLength;
268 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800269 __le16 bcdUSB;
270 __u8 bDeviceClass;
271 __u8 bDeviceSubClass;
272 __u8 bDeviceProtocol;
Tao Baod7db5942015-01-28 10:07:51 -0800273 __u8 bMaxPacketSize0;
274 __u8 bNumConfigurations;
275 __u8 bRESERVED;
276} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700277struct usb_otg_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800278 __u8 bLength;
279 __u8 bDescriptorType;
280 __u8 bmAttributes;
Tao Baod7db5942015-01-28 10:07:51 -0800281} __attribute__((packed));
Christopher Ferris05d08e92016-02-04 13:16:38 -0800282struct usb_otg20_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800283 __u8 bLength;
284 __u8 bDescriptorType;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800285 __u8 bmAttributes;
286 __le16 bcdOTG;
287} __attribute__((packed));
288#define USB_OTG_SRP (1 << 0)
Christopher Ferris05d08e92016-02-04 13:16:38 -0800289#define USB_OTG_HNP (1 << 1)
290#define USB_OTG_ADP (1 << 2)
Christopher Ferris7f4c8372024-06-03 14:22:19 -0700291#define USB_OTG_RSP (1 << 3)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700292#define OTG_STS_SELECTOR 0xF000
Christopher Ferris05d08e92016-02-04 13:16:38 -0800293struct usb_debug_descriptor {
294 __u8 bLength;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800295 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800296 __u8 bDebugInEndpoint;
297 __u8 bDebugOutEndpoint;
Ben Cheng655a7c02013-10-16 16:09:24 -0700298} __attribute__((packed));
299struct usb_interface_assoc_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800300 __u8 bLength;
301 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800302 __u8 bFirstInterface;
303 __u8 bInterfaceCount;
304 __u8 bFunctionClass;
305 __u8 bFunctionSubClass;
Tao Baod7db5942015-01-28 10:07:51 -0800306 __u8 bFunctionProtocol;
307 __u8 iFunction;
308} __attribute__((packed));
Christopher Ferris1308ad32017-11-14 17:32:13 -0800309#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
Ben Cheng655a7c02013-10-16 16:09:24 -0700310struct usb_security_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800311 __u8 bLength;
312 __u8 bDescriptorType;
313 __le16 wTotalLength;
314 __u8 bNumEncryptionTypes;
Ben Cheng655a7c02013-10-16 16:09:24 -0700315} __attribute__((packed));
316struct usb_key_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800317 __u8 bLength;
318 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800319 __u8 tTKID[3];
320 __u8 bReserved;
Christopher Ferris7447a1c2022-10-04 18:24:44 -0700321 __u8 bKeyData[];
Ben Cheng655a7c02013-10-16 16:09:24 -0700322} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700323struct usb_encryption_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800324 __u8 bLength;
325 __u8 bDescriptorType;
326 __u8 bEncryptionType;
Ben Cheng655a7c02013-10-16 16:09:24 -0700327#define USB_ENC_TYPE_UNSECURE 0
328#define USB_ENC_TYPE_WIRED 1
329#define USB_ENC_TYPE_CCM_1 2
330#define USB_ENC_TYPE_RSA_1 3
Tao Baod7db5942015-01-28 10:07:51 -0800331 __u8 bEncryptionValue;
332 __u8 bAuthKeyIndex;
Ben Cheng655a7c02013-10-16 16:09:24 -0700333} __attribute__((packed));
334struct usb_bos_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800335 __u8 bLength;
336 __u8 bDescriptorType;
337 __le16 wTotalLength;
338 __u8 bNumDeviceCaps;
Ben Cheng655a7c02013-10-16 16:09:24 -0700339} __attribute__((packed));
340#define USB_DT_BOS_SIZE 5
341struct usb_dev_cap_header {
Tao Baod7db5942015-01-28 10:07:51 -0800342 __u8 bLength;
Tao Baod7db5942015-01-28 10:07:51 -0800343 __u8 bDescriptorType;
344 __u8 bDevCapabilityType;
Ben Cheng655a7c02013-10-16 16:09:24 -0700345} __attribute__((packed));
346#define USB_CAP_TYPE_WIRELESS_USB 1
Ben Cheng655a7c02013-10-16 16:09:24 -0700347struct usb_wireless_cap_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800348 __u8 bLength;
349 __u8 bDescriptorType;
350 __u8 bDevCapabilityType;
Tao Baod7db5942015-01-28 10:07:51 -0800351 __u8 bmAttributes;
Ben Cheng655a7c02013-10-16 16:09:24 -0700352#define USB_WIRELESS_P2P_DRD (1 << 1)
353#define USB_WIRELESS_BEACON_MASK (3 << 2)
354#define USB_WIRELESS_BEACON_SELF (1 << 2)
Ben Cheng655a7c02013-10-16 16:09:24 -0700355#define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
356#define USB_WIRELESS_BEACON_NONE (3 << 2)
Tao Baod7db5942015-01-28 10:07:51 -0800357 __le16 wPHYRates;
Ben Cheng655a7c02013-10-16 16:09:24 -0700358#define USB_WIRELESS_PHY_53 (1 << 0)
Ben Cheng655a7c02013-10-16 16:09:24 -0700359#define USB_WIRELESS_PHY_80 (1 << 1)
360#define USB_WIRELESS_PHY_107 (1 << 2)
361#define USB_WIRELESS_PHY_160 (1 << 3)
362#define USB_WIRELESS_PHY_200 (1 << 4)
Ben Cheng655a7c02013-10-16 16:09:24 -0700363#define USB_WIRELESS_PHY_320 (1 << 5)
364#define USB_WIRELESS_PHY_400 (1 << 6)
365#define USB_WIRELESS_PHY_480 (1 << 7)
Tao Baod7db5942015-01-28 10:07:51 -0800366 __u8 bmTFITXPowerInfo;
Tao Baod7db5942015-01-28 10:07:51 -0800367 __u8 bmFFITXPowerInfo;
368 __le16 bmBandGroup;
369 __u8 bReserved;
Ben Cheng655a7c02013-10-16 16:09:24 -0700370} __attribute__((packed));
Christopher Ferris934ec942018-01-31 15:29:16 -0800371#define USB_DT_USB_WIRELESS_CAP_SIZE 11
Ben Cheng655a7c02013-10-16 16:09:24 -0700372#define USB_CAP_TYPE_EXT 2
373struct usb_ext_cap_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800374 __u8 bLength;
375 __u8 bDescriptorType;
Tao Baod7db5942015-01-28 10:07:51 -0800376 __u8 bDevCapabilityType;
377 __le32 bmAttributes;
Ben Cheng655a7c02013-10-16 16:09:24 -0700378#define USB_LPM_SUPPORT (1 << 1)
379#define USB_BESL_SUPPORT (1 << 2)
Ben Cheng655a7c02013-10-16 16:09:24 -0700380#define USB_BESL_BASELINE_VALID (1 << 3)
381#define USB_BESL_DEEP_VALID (1 << 4)
Christopher Ferris9584fa42019-12-09 15:36:13 -0800382#define USB_SET_BESL_BASELINE(p) (((p) & 0xf) << 8)
383#define USB_SET_BESL_DEEP(p) (((p) & 0xf) << 12)
Ben Cheng655a7c02013-10-16 16:09:24 -0700384#define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8)
385#define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12)
Ben Cheng655a7c02013-10-16 16:09:24 -0700386} __attribute__((packed));
387#define USB_DT_USB_EXT_CAP_SIZE 7
388#define USB_SS_CAP_TYPE 3
389struct usb_ss_cap_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800390 __u8 bLength;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700391 __u8 bDescriptorType;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700392 __u8 bDevCapabilityType;
393 __u8 bmAttributes;
394#define USB_LTM_SUPPORT (1 << 1)
395 __le16 wSpeedSupported;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700396#define USB_LOW_SPEED_OPERATION (1)
397#define USB_FULL_SPEED_OPERATION (1 << 1)
398#define USB_HIGH_SPEED_OPERATION (1 << 2)
399#define USB_5GBPS_OPERATION (1 << 3)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700400 __u8 bFunctionalitySupport;
401 __u8 bU1devExitLat;
402 __le16 bU2DevExitLat;
403} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700404#define USB_DT_USB_SS_CAP_SIZE 10
405#define CONTAINER_ID_TYPE 4
406struct usb_ss_container_id_descriptor {
407 __u8 bLength;
Tao Baod7db5942015-01-28 10:07:51 -0800408 __u8 bDescriptorType;
409 __u8 bDevCapabilityType;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700410 __u8 bReserved;
411 __u8 ContainerID[16];
Ben Cheng655a7c02013-10-16 16:09:24 -0700412} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700413#define USB_DT_USB_SS_CONTN_ID_SIZE 20
Christopher Ferrisb7cef6d2023-05-09 19:04:15 +0000414#define USB_PLAT_DEV_CAP_TYPE 5
415struct usb_plat_dev_cap_descriptor {
416 __u8 bLength;
417 __u8 bDescriptorType;
418 __u8 bDevCapabilityType;
419 __u8 bReserved;
420 __u8 UUID[16];
421 __u8 CapabilityData[];
422} __attribute__((packed));
423#define USB_DT_USB_PLAT_DEV_CAP_SIZE(capability_data_size) (20 + capability_data_size)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700424#define USB_SSP_CAP_TYPE 0xa
425struct usb_ssp_cap_descriptor {
Christopher Ferris05d08e92016-02-04 13:16:38 -0800426 __u8 bLength;
427 __u8 bDescriptorType;
428 __u8 bDevCapabilityType;
429 __u8 bReserved;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700430 __le32 bmAttributes;
431#define USB_SSP_SUBLINK_SPEED_ATTRIBS (0x1f << 0)
432#define USB_SSP_SUBLINK_SPEED_IDS (0xf << 5)
433 __le16 wFunctionalitySupport;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700434#define USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID (0xf)
435#define USB_SSP_MIN_RX_LANE_COUNT (0xf << 8)
436#define USB_SSP_MIN_TX_LANE_COUNT (0xf << 12)
437 __le16 wReserved;
Christopher Ferris8666d042023-09-06 14:55:31 -0700438 union {
439 __le32 legacy_padding;
440 __DECLARE_FLEX_ARRAY(__le32, bmSublinkSpeedAttr);
441 };
Christopher Ferris106b3a82016-08-24 12:15:38 -0700442#define USB_SSP_SUBLINK_SPEED_SSID (0xf)
443#define USB_SSP_SUBLINK_SPEED_LSE (0x3 << 4)
Christopher Ferrisa9750ed2021-05-03 14:02:49 -0700444#define USB_SSP_SUBLINK_SPEED_LSE_BPS 0
445#define USB_SSP_SUBLINK_SPEED_LSE_KBPS 1
446#define USB_SSP_SUBLINK_SPEED_LSE_MBPS 2
447#define USB_SSP_SUBLINK_SPEED_LSE_GBPS 3
Christopher Ferris106b3a82016-08-24 12:15:38 -0700448#define USB_SSP_SUBLINK_SPEED_ST (0x3 << 6)
Christopher Ferrisa9750ed2021-05-03 14:02:49 -0700449#define USB_SSP_SUBLINK_SPEED_ST_SYM_RX 0
450#define USB_SSP_SUBLINK_SPEED_ST_ASYM_RX 1
451#define USB_SSP_SUBLINK_SPEED_ST_SYM_TX 2
452#define USB_SSP_SUBLINK_SPEED_ST_ASYM_TX 3
Christopher Ferris106b3a82016-08-24 12:15:38 -0700453#define USB_SSP_SUBLINK_SPEED_RSVD (0x3f << 8)
454#define USB_SSP_SUBLINK_SPEED_LP (0x3 << 14)
Christopher Ferrisa9750ed2021-05-03 14:02:49 -0700455#define USB_SSP_SUBLINK_SPEED_LP_SS 0
456#define USB_SSP_SUBLINK_SPEED_LP_SSP 1
Christopher Ferris106b3a82016-08-24 12:15:38 -0700457#define USB_SSP_SUBLINK_SPEED_LSM (0xff << 16)
458} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700459#define USB_PD_POWER_DELIVERY_CAPABILITY 0x06
460#define USB_PD_BATTERY_INFO_CAPABILITY 0x07
461#define USB_PD_PD_CONSUMER_PORT_CAPABILITY 0x08
462#define USB_PD_PD_PROVIDER_PORT_CAPABILITY 0x09
Christopher Ferris106b3a82016-08-24 12:15:38 -0700463struct usb_pd_cap_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800464 __u8 bLength;
465 __u8 bDescriptorType;
466 __u8 bDevCapabilityType;
Tao Baod7db5942015-01-28 10:07:51 -0800467 __u8 bReserved;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800468 __le32 bmAttributes;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700469#define USB_PD_CAP_BATTERY_CHARGING (1 << 1)
470#define USB_PD_CAP_USB_PD (1 << 2)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700471#define USB_PD_CAP_PROVIDER (1 << 3)
472#define USB_PD_CAP_CONSUMER (1 << 4)
473#define USB_PD_CAP_CHARGING_POLICY (1 << 5)
474#define USB_PD_CAP_TYPE_C_CURRENT (1 << 6)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700475#define USB_PD_CAP_PWR_AC (1 << 8)
476#define USB_PD_CAP_PWR_BAT (1 << 9)
477#define USB_PD_CAP_PWR_USE_V_BUS (1 << 14)
478 __le16 bmProviderPorts;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700479 __le16 bmConsumerPorts;
480 __le16 bcdBCVersion;
481 __le16 bcdPDVersion;
482 __le16 bcdUSBTypeCVersion;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800483} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700484struct usb_pd_cap_battery_info_descriptor {
Tao Baod7db5942015-01-28 10:07:51 -0800485 __u8 bLength;
486 __u8 bDescriptorType;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700487 __u8 bDevCapabilityType;
488 __u8 iBattery;
489 __u8 iSerial;
490 __u8 iManufacturer;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700491 __u8 bBatteryId;
492 __u8 bReserved;
493 __le32 dwChargedThreshold;
494 __le32 dwWeakThreshold;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700495 __le32 dwBatteryDesignCapacity;
496 __le32 dwBatteryLastFullchargeCapacity;
497} __attribute__((packed));
498struct usb_pd_cap_consumer_port_descriptor {
Christopher Ferris106b3a82016-08-24 12:15:38 -0700499 __u8 bLength;
500 __u8 bDescriptorType;
501 __u8 bDevCapabilityType;
502 __u8 bReserved;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700503 __u8 bmCapabilities;
504#define USB_PD_CAP_CONSUMER_BC (1 << 0)
505#define USB_PD_CAP_CONSUMER_PD (1 << 1)
506#define USB_PD_CAP_CONSUMER_TYPE_C (1 << 2)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700507 __le16 wMinVoltage;
508 __le16 wMaxVoltage;
509 __u16 wReserved;
510 __le32 dwMaxOperatingPower;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700511 __le32 dwMaxPeakPower;
512 __le32 dwMaxPeakPowerTime;
513#define USB_PD_CAP_CONSUMER_UNKNOWN_PEAK_POWER_TIME 0xffff
514} __attribute__((packed));
Christopher Ferris106b3a82016-08-24 12:15:38 -0700515struct usb_pd_cap_provider_port_descriptor {
516 __u8 bLength;
517 __u8 bDescriptorType;
518 __u8 bDevCapabilityType;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700519 __u8 bReserved1;
520 __u8 bmCapabilities;
521#define USB_PD_CAP_PROVIDER_BC (1 << 0)
522#define USB_PD_CAP_PROVIDER_PD (1 << 1)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700523#define USB_PD_CAP_PROVIDER_TYPE_C (1 << 2)
524 __u8 bNumOfPDObjects;
525 __u8 bReserved2;
526 __le32 wPowerDataObject[];
Christopher Ferris106b3a82016-08-24 12:15:38 -0700527} __attribute__((packed));
528#define USB_PTM_CAP_TYPE 0xb
529struct usb_ptm_cap_descriptor {
530 __u8 bLength;
Christopher Ferris106b3a82016-08-24 12:15:38 -0700531 __u8 bDescriptorType;
532 __u8 bDevCapabilityType;
533} __attribute__((packed));
Christopher Ferris934ec942018-01-31 15:29:16 -0800534#define USB_DT_USB_PTM_ID_SIZE 3
Christopher Ferris76a1d452018-06-27 14:12:29 -0700535#define USB_DT_USB_SSP_CAP_SIZE(ssac) (12 + (ssac + 1) * 4)
Christopher Ferris106b3a82016-08-24 12:15:38 -0700536struct usb_wireless_ep_comp_descriptor {
537 __u8 bLength;
538 __u8 bDescriptorType;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800539 __u8 bMaxBurst;
Tao Baod7db5942015-01-28 10:07:51 -0800540 __u8 bMaxSequence;
541 __le16 wMaxStreamDelay;
542 __le16 wOverTheAirPacketSize;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800543 __u8 bOverTheAirInterval;
Tao Baod7db5942015-01-28 10:07:51 -0800544 __u8 bmCompAttributes;
Ben Cheng655a7c02013-10-16 16:09:24 -0700545#define USB_ENDPOINT_SWITCH_MASK 0x03
546#define USB_ENDPOINT_SWITCH_NO 0
Christopher Ferris05d08e92016-02-04 13:16:38 -0800547#define USB_ENDPOINT_SWITCH_SWITCH 1
Ben Cheng655a7c02013-10-16 16:09:24 -0700548#define USB_ENDPOINT_SWITCH_SCALE 2
549} __attribute__((packed));
550struct usb_handshake {
Christopher Ferris05d08e92016-02-04 13:16:38 -0800551 __u8 bMessageNumber;
Tao Baod7db5942015-01-28 10:07:51 -0800552 __u8 bStatus;
553 __u8 tTKID[3];
554 __u8 bReserved;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800555 __u8 CDID[16];
Tao Baod7db5942015-01-28 10:07:51 -0800556 __u8 nonce[16];
557 __u8 MIC[8];
Ben Cheng655a7c02013-10-16 16:09:24 -0700558} __attribute__((packed));
Christopher Ferris05d08e92016-02-04 13:16:38 -0800559struct usb_connection_context {
Tao Baod7db5942015-01-28 10:07:51 -0800560 __u8 CHID[16];
561 __u8 CDID[16];
562 __u8 CK[16];
Christopher Ferris05d08e92016-02-04 13:16:38 -0800563} __attribute__((packed));
Ben Cheng655a7c02013-10-16 16:09:24 -0700564enum usb_device_speed {
Tao Baod7db5942015-01-28 10:07:51 -0800565 USB_SPEED_UNKNOWN = 0,
566 USB_SPEED_LOW,
Christopher Ferris05d08e92016-02-04 13:16:38 -0800567 USB_SPEED_FULL,
Tao Baod7db5942015-01-28 10:07:51 -0800568 USB_SPEED_HIGH,
569 USB_SPEED_WIRELESS,
570 USB_SPEED_SUPER,
Christopher Ferris106b3a82016-08-24 12:15:38 -0700571 USB_SPEED_SUPER_PLUS,
Christopher Ferris05d08e92016-02-04 13:16:38 -0800572};
Ben Cheng655a7c02013-10-16 16:09:24 -0700573enum usb_device_state {
Tao Baod7db5942015-01-28 10:07:51 -0800574 USB_STATE_NOTATTACHED = 0,
575 USB_STATE_ATTACHED,
Christopher Ferris05d08e92016-02-04 13:16:38 -0800576 USB_STATE_POWERED,
Tao Baod7db5942015-01-28 10:07:51 -0800577 USB_STATE_RECONNECTING,
578 USB_STATE_UNAUTHENTICATED,
579 USB_STATE_DEFAULT,
Christopher Ferris05d08e92016-02-04 13:16:38 -0800580 USB_STATE_ADDRESS,
Tao Baod7db5942015-01-28 10:07:51 -0800581 USB_STATE_CONFIGURED,
582 USB_STATE_SUSPENDED
Ben Cheng655a7c02013-10-16 16:09:24 -0700583};
Christopher Ferris05d08e92016-02-04 13:16:38 -0800584enum usb3_link_state {
Tao Baod7db5942015-01-28 10:07:51 -0800585 USB3_LPM_U0 = 0,
586 USB3_LPM_U1,
587 USB3_LPM_U2,
Christopher Ferris05d08e92016-02-04 13:16:38 -0800588 USB3_LPM_U3
Ben Cheng655a7c02013-10-16 16:09:24 -0700589};
Ben Cheng655a7c02013-10-16 16:09:24 -0700590#define USB3_LPM_DISABLED 0x0
591#define USB3_LPM_U1_MAX_TIMEOUT 0x7F
Christopher Ferris05d08e92016-02-04 13:16:38 -0800592#define USB3_LPM_U2_MAX_TIMEOUT 0xFE
Ben Cheng655a7c02013-10-16 16:09:24 -0700593#define USB3_LPM_DEVICE_INITIATED 0xFF
Ben Cheng655a7c02013-10-16 16:09:24 -0700594struct usb_set_sel_req {
Tao Baod7db5942015-01-28 10:07:51 -0800595 __u8 u1_sel;
Christopher Ferris05d08e92016-02-04 13:16:38 -0800596 __u8 u1_pel;
Tao Baod7db5942015-01-28 10:07:51 -0800597 __le16 u2_sel;
598 __le16 u2_pel;
599} __attribute__((packed));
Christopher Ferris05d08e92016-02-04 13:16:38 -0800600#define USB3_LPM_MAX_U1_SEL_PEL 0xFF
Tao Baod7db5942015-01-28 10:07:51 -0800601#define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF
Ben Cheng655a7c02013-10-16 16:09:24 -0700602#define USB_SELF_POWER_VBUS_MAX_DRAW 100
603#endif