xref: /rk3399_rockchip-uboot/include/linux/usb/ch9.h (revision 23cd138503f90ff6af109c0096727ba641942614)
1*23cd1385SRemy Bohmer /*
2*23cd1385SRemy Bohmer  * This file holds USB constants and structures that are needed for
3*23cd1385SRemy Bohmer  * USB device APIs.  These are used by the USB device model, which is
4*23cd1385SRemy Bohmer  * defined in chapter 9 of the USB 2.0 specification and in the
5*23cd1385SRemy Bohmer  * Wireless USB 1.0 (spread around).  Linux has several APIs in C that
6*23cd1385SRemy Bohmer  * need these:
7*23cd1385SRemy Bohmer  *
8*23cd1385SRemy Bohmer  * - the master/host side Linux-USB kernel driver API;
9*23cd1385SRemy Bohmer  * - the "usbfs" user space API; and
10*23cd1385SRemy Bohmer  * - the Linux "gadget" slave/device/peripheral side driver API.
11*23cd1385SRemy Bohmer  *
12*23cd1385SRemy Bohmer  * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
13*23cd1385SRemy Bohmer  * act either as a USB master/host or as a USB slave/device.  That means
14*23cd1385SRemy Bohmer  * the master and slave side APIs benefit from working well together.
15*23cd1385SRemy Bohmer  *
16*23cd1385SRemy Bohmer  * There's also "Wireless USB", using low power short range radios for
17*23cd1385SRemy Bohmer  * peripheral interconnection but otherwise building on the USB framework.
18*23cd1385SRemy Bohmer  *
19*23cd1385SRemy Bohmer  * Note all descriptors are declared '__attribute__((packed))' so that:
20*23cd1385SRemy Bohmer  *
21*23cd1385SRemy Bohmer  * [a] they never get padded, either internally (USB spec writers
22*23cd1385SRemy Bohmer  *     probably handled that) or externally;
23*23cd1385SRemy Bohmer  *
24*23cd1385SRemy Bohmer  * [b] so that accessing bigger-than-a-bytes fields will never
25*23cd1385SRemy Bohmer  *     generate bus errors on any platform, even when the location of
26*23cd1385SRemy Bohmer  *     its descriptor inside a bundle isn't "naturally aligned", and
27*23cd1385SRemy Bohmer  *
28*23cd1385SRemy Bohmer  * [c] for consistency, removing all doubt even when it appears to
29*23cd1385SRemy Bohmer  *     someone that the two other points are non-issues for that
30*23cd1385SRemy Bohmer  *     particular descriptor type.
31*23cd1385SRemy Bohmer  *
32*23cd1385SRemy Bohmer  * Ported to U-boot by: Thomas Smits <ts.smits@gmail.com> and
33*23cd1385SRemy Bohmer  *                      Remy Bohmer <linux@bohmer.net>
34*23cd1385SRemy Bohmer  */
35*23cd1385SRemy Bohmer 
36*23cd1385SRemy Bohmer #ifndef __LINUX_USB_CH9_H
37*23cd1385SRemy Bohmer #define __LINUX_USB_CH9_H
38*23cd1385SRemy Bohmer 
39*23cd1385SRemy Bohmer #include <linux/types.h>	/* __u8 etc */
40*23cd1385SRemy Bohmer 
41*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
42*23cd1385SRemy Bohmer 
43*23cd1385SRemy Bohmer /* CONTROL REQUEST SUPPORT */
44*23cd1385SRemy Bohmer 
45*23cd1385SRemy Bohmer /*
46*23cd1385SRemy Bohmer  * USB directions
47*23cd1385SRemy Bohmer  *
48*23cd1385SRemy Bohmer  * This bit flag is used in endpoint descriptors' bEndpointAddress field.
49*23cd1385SRemy Bohmer  * It's also one of three fields in control requests bRequestType.
50*23cd1385SRemy Bohmer  */
51*23cd1385SRemy Bohmer #define USB_DIR_OUT			0		/* to device */
52*23cd1385SRemy Bohmer #define USB_DIR_IN			0x80		/* to host */
53*23cd1385SRemy Bohmer 
54*23cd1385SRemy Bohmer /*
55*23cd1385SRemy Bohmer  * USB types, the second of three bRequestType fields
56*23cd1385SRemy Bohmer  */
57*23cd1385SRemy Bohmer #define USB_TYPE_MASK			(0x03 << 5)
58*23cd1385SRemy Bohmer #define USB_TYPE_STANDARD		(0x00 << 5)
59*23cd1385SRemy Bohmer #define USB_TYPE_CLASS			(0x01 << 5)
60*23cd1385SRemy Bohmer #define USB_TYPE_VENDOR			(0x02 << 5)
61*23cd1385SRemy Bohmer #define USB_TYPE_RESERVED		(0x03 << 5)
62*23cd1385SRemy Bohmer 
63*23cd1385SRemy Bohmer /*
64*23cd1385SRemy Bohmer  * USB recipients, the third of three bRequestType fields
65*23cd1385SRemy Bohmer  */
66*23cd1385SRemy Bohmer #define USB_RECIP_MASK			0x1f
67*23cd1385SRemy Bohmer #define USB_RECIP_DEVICE		0x00
68*23cd1385SRemy Bohmer #define USB_RECIP_INTERFACE		0x01
69*23cd1385SRemy Bohmer #define USB_RECIP_ENDPOINT		0x02
70*23cd1385SRemy Bohmer #define USB_RECIP_OTHER			0x03
71*23cd1385SRemy Bohmer /* From Wireless USB 1.0 */
72*23cd1385SRemy Bohmer #define USB_RECIP_PORT 			0x04
73*23cd1385SRemy Bohmer #define USB_RECIP_RPIPE 		0x05
74*23cd1385SRemy Bohmer 
75*23cd1385SRemy Bohmer /*
76*23cd1385SRemy Bohmer  * Standard requests, for the bRequest field of a SETUP packet.
77*23cd1385SRemy Bohmer  *
78*23cd1385SRemy Bohmer  * These are qualified by the bRequestType field, so that for example
79*23cd1385SRemy Bohmer  * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
80*23cd1385SRemy Bohmer  * by a GET_STATUS request.
81*23cd1385SRemy Bohmer  */
82*23cd1385SRemy Bohmer #define USB_REQ_GET_STATUS		0x00
83*23cd1385SRemy Bohmer #define USB_REQ_CLEAR_FEATURE		0x01
84*23cd1385SRemy Bohmer #define USB_REQ_SET_FEATURE		0x03
85*23cd1385SRemy Bohmer #define USB_REQ_SET_ADDRESS		0x05
86*23cd1385SRemy Bohmer #define USB_REQ_GET_DESCRIPTOR		0x06
87*23cd1385SRemy Bohmer #define USB_REQ_SET_DESCRIPTOR		0x07
88*23cd1385SRemy Bohmer #define USB_REQ_GET_CONFIGURATION	0x08
89*23cd1385SRemy Bohmer #define USB_REQ_SET_CONFIGURATION	0x09
90*23cd1385SRemy Bohmer #define USB_REQ_GET_INTERFACE		0x0A
91*23cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE		0x0B
92*23cd1385SRemy Bohmer #define USB_REQ_SYNCH_FRAME		0x0C
93*23cd1385SRemy Bohmer 
94*23cd1385SRemy Bohmer #define USB_REQ_SET_ENCRYPTION		0x0D	/* Wireless USB */
95*23cd1385SRemy Bohmer #define USB_REQ_GET_ENCRYPTION		0x0E
96*23cd1385SRemy Bohmer #define USB_REQ_RPIPE_ABORT		0x0E
97*23cd1385SRemy Bohmer #define USB_REQ_SET_HANDSHAKE		0x0F
98*23cd1385SRemy Bohmer #define USB_REQ_RPIPE_RESET		0x0F
99*23cd1385SRemy Bohmer #define USB_REQ_GET_HANDSHAKE		0x10
100*23cd1385SRemy Bohmer #define USB_REQ_SET_CONNECTION		0x11
101*23cd1385SRemy Bohmer #define USB_REQ_SET_SECURITY_DATA	0x12
102*23cd1385SRemy Bohmer #define USB_REQ_GET_SECURITY_DATA	0x13
103*23cd1385SRemy Bohmer #define USB_REQ_SET_WUSB_DATA		0x14
104*23cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_WRITE	0x15
105*23cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_READ	0x16
106*23cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE_DS	0x17
107*23cd1385SRemy Bohmer 
108*23cd1385SRemy Bohmer /*
109*23cd1385SRemy Bohmer  * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
110*23cd1385SRemy Bohmer  * are read as a bit array returned by USB_REQ_GET_STATUS.  (So there
111*23cd1385SRemy Bohmer  * are at most sixteen features of each type.)
112*23cd1385SRemy Bohmer  */
113*23cd1385SRemy Bohmer #define USB_DEVICE_SELF_POWERED		0	/* (read only) */
114*23cd1385SRemy Bohmer #define USB_DEVICE_REMOTE_WAKEUP	1	/* dev may initiate wakeup */
115*23cd1385SRemy Bohmer #define USB_DEVICE_TEST_MODE		2	/* (wired high speed only) */
116*23cd1385SRemy Bohmer #define USB_DEVICE_BATTERY		2	/* (wireless) */
117*23cd1385SRemy Bohmer #define USB_DEVICE_B_HNP_ENABLE		3	/* (otg) dev may initiate HNP */
118*23cd1385SRemy Bohmer #define USB_DEVICE_WUSB_DEVICE		3	/* (wireless)*/
119*23cd1385SRemy Bohmer #define USB_DEVICE_A_HNP_SUPPORT	4	/* (otg) RH port supports HNP */
120*23cd1385SRemy Bohmer #define USB_DEVICE_A_ALT_HNP_SUPPORT	5	/* (otg) other RH port does */
121*23cd1385SRemy Bohmer #define USB_DEVICE_DEBUG_MODE		6	/* (special devices only) */
122*23cd1385SRemy Bohmer 
123*23cd1385SRemy Bohmer #define USB_ENDPOINT_HALT		0	/* IN/OUT will STALL */
124*23cd1385SRemy Bohmer 
125*23cd1385SRemy Bohmer 
126*23cd1385SRemy Bohmer /**
127*23cd1385SRemy Bohmer  * struct usb_ctrlrequest - SETUP data for a USB device control request
128*23cd1385SRemy Bohmer  * @bRequestType: matches the USB bmRequestType field
129*23cd1385SRemy Bohmer  * @bRequest: matches the USB bRequest field
130*23cd1385SRemy Bohmer  * @wValue: matches the USB wValue field (le16 byte order)
131*23cd1385SRemy Bohmer  * @wIndex: matches the USB wIndex field (le16 byte order)
132*23cd1385SRemy Bohmer  * @wLength: matches the USB wLength field (le16 byte order)
133*23cd1385SRemy Bohmer  *
134*23cd1385SRemy Bohmer  * This structure is used to send control requests to a USB device.  It matches
135*23cd1385SRemy Bohmer  * the different fields of the USB 2.0 Spec section 9.3, table 9-2.  See the
136*23cd1385SRemy Bohmer  * USB spec for a fuller description of the different fields, and what they are
137*23cd1385SRemy Bohmer  * used for.
138*23cd1385SRemy Bohmer  *
139*23cd1385SRemy Bohmer  * Note that the driver for any interface can issue control requests.
140*23cd1385SRemy Bohmer  * For most devices, interfaces don't coordinate with each other, so
141*23cd1385SRemy Bohmer  * such requests may be made at any time.
142*23cd1385SRemy Bohmer  */
143*23cd1385SRemy Bohmer #if defined(__BIG_ENDIAN) || defined(__ARMEB__)
144*23cd1385SRemy Bohmer #error (functionality not verified for big endian targets, todo...)
145*23cd1385SRemy Bohmer #endif
146*23cd1385SRemy Bohmer 
147*23cd1385SRemy Bohmer struct usb_ctrlrequest {
148*23cd1385SRemy Bohmer 	__u8 bRequestType;
149*23cd1385SRemy Bohmer 	__u8 bRequest;
150*23cd1385SRemy Bohmer 	__le16 wValue;
151*23cd1385SRemy Bohmer 	__le16 wIndex;
152*23cd1385SRemy Bohmer 	__le16 wLength;
153*23cd1385SRemy Bohmer } __attribute__ ((packed));
154*23cd1385SRemy Bohmer 
155*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
156*23cd1385SRemy Bohmer 
157*23cd1385SRemy Bohmer /*
158*23cd1385SRemy Bohmer  * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
159*23cd1385SRemy Bohmer  * (rarely) accepted by SET_DESCRIPTOR.
160*23cd1385SRemy Bohmer  *
161*23cd1385SRemy Bohmer  * Note that all multi-byte values here are encoded in little endian
162*23cd1385SRemy Bohmer  * byte order "on the wire".  But when exposed through Linux-USB APIs,
163*23cd1385SRemy Bohmer  * they've been converted to cpu byte order.
164*23cd1385SRemy Bohmer  */
165*23cd1385SRemy Bohmer 
166*23cd1385SRemy Bohmer /*
167*23cd1385SRemy Bohmer  * Descriptor types ... USB 2.0 spec table 9.5
168*23cd1385SRemy Bohmer  */
169*23cd1385SRemy Bohmer #define USB_DT_DEVICE			0x01
170*23cd1385SRemy Bohmer #define USB_DT_CONFIG			0x02
171*23cd1385SRemy Bohmer #define USB_DT_STRING			0x03
172*23cd1385SRemy Bohmer #define USB_DT_INTERFACE		0x04
173*23cd1385SRemy Bohmer #define USB_DT_ENDPOINT			0x05
174*23cd1385SRemy Bohmer #define USB_DT_DEVICE_QUALIFIER		0x06
175*23cd1385SRemy Bohmer #define USB_DT_OTHER_SPEED_CONFIG	0x07
176*23cd1385SRemy Bohmer #define USB_DT_INTERFACE_POWER		0x08
177*23cd1385SRemy Bohmer /* these are from a minor usb 2.0 revision (ECN) */
178*23cd1385SRemy Bohmer #define USB_DT_OTG			0x09
179*23cd1385SRemy Bohmer #define USB_DT_DEBUG			0x0a
180*23cd1385SRemy Bohmer #define USB_DT_INTERFACE_ASSOCIATION	0x0b
181*23cd1385SRemy Bohmer /* these are from the Wireless USB spec */
182*23cd1385SRemy Bohmer #define USB_DT_SECURITY			0x0c
183*23cd1385SRemy Bohmer #define USB_DT_KEY			0x0d
184*23cd1385SRemy Bohmer #define USB_DT_ENCRYPTION_TYPE		0x0e
185*23cd1385SRemy Bohmer #define USB_DT_BOS			0x0f
186*23cd1385SRemy Bohmer #define USB_DT_DEVICE_CAPABILITY	0x10
187*23cd1385SRemy Bohmer #define USB_DT_WIRELESS_ENDPOINT_COMP	0x11
188*23cd1385SRemy Bohmer #define USB_DT_WIRE_ADAPTER		0x21
189*23cd1385SRemy Bohmer #define USB_DT_RPIPE			0x22
190*23cd1385SRemy Bohmer 
191*23cd1385SRemy Bohmer /* Conventional codes for class-specific descriptors.  The convention is
192*23cd1385SRemy Bohmer  * defined in the USB "Common Class" Spec (3.11).  Individual class specs
193*23cd1385SRemy Bohmer  * are authoritative for their usage, not the "common class" writeup.
194*23cd1385SRemy Bohmer  */
195*23cd1385SRemy Bohmer #define USB_DT_CS_DEVICE		(USB_TYPE_CLASS | USB_DT_DEVICE)
196*23cd1385SRemy Bohmer #define USB_DT_CS_CONFIG		(USB_TYPE_CLASS | USB_DT_CONFIG)
197*23cd1385SRemy Bohmer #define USB_DT_CS_STRING		(USB_TYPE_CLASS | USB_DT_STRING)
198*23cd1385SRemy Bohmer #define USB_DT_CS_INTERFACE		(USB_TYPE_CLASS | USB_DT_INTERFACE)
199*23cd1385SRemy Bohmer #define USB_DT_CS_ENDPOINT		(USB_TYPE_CLASS | USB_DT_ENDPOINT)
200*23cd1385SRemy Bohmer 
201*23cd1385SRemy Bohmer /* All standard descriptors have these 2 fields at the beginning */
202*23cd1385SRemy Bohmer struct usb_descriptor_header {
203*23cd1385SRemy Bohmer 	__u8  bLength;
204*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
205*23cd1385SRemy Bohmer } __attribute__ ((packed));
206*23cd1385SRemy Bohmer 
207*23cd1385SRemy Bohmer 
208*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
209*23cd1385SRemy Bohmer 
210*23cd1385SRemy Bohmer /* USB_DT_DEVICE: Device descriptor */
211*23cd1385SRemy Bohmer struct usb_device_descriptor {
212*23cd1385SRemy Bohmer 	__u8  bLength;
213*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
214*23cd1385SRemy Bohmer 
215*23cd1385SRemy Bohmer 	__le16 bcdUSB;
216*23cd1385SRemy Bohmer 	__u8  bDeviceClass;
217*23cd1385SRemy Bohmer 	__u8  bDeviceSubClass;
218*23cd1385SRemy Bohmer 	__u8  bDeviceProtocol;
219*23cd1385SRemy Bohmer 	__u8  bMaxPacketSize0;
220*23cd1385SRemy Bohmer 	__le16 idVendor;
221*23cd1385SRemy Bohmer 	__le16 idProduct;
222*23cd1385SRemy Bohmer 	__le16 bcdDevice;
223*23cd1385SRemy Bohmer 	__u8  iManufacturer;
224*23cd1385SRemy Bohmer 	__u8  iProduct;
225*23cd1385SRemy Bohmer 	__u8  iSerialNumber;
226*23cd1385SRemy Bohmer 	__u8  bNumConfigurations;
227*23cd1385SRemy Bohmer } __attribute__ ((packed));
228*23cd1385SRemy Bohmer 
229*23cd1385SRemy Bohmer #define USB_DT_DEVICE_SIZE		18
230*23cd1385SRemy Bohmer 
231*23cd1385SRemy Bohmer 
232*23cd1385SRemy Bohmer /*
233*23cd1385SRemy Bohmer  * Device and/or Interface Class codes
234*23cd1385SRemy Bohmer  * as found in bDeviceClass or bInterfaceClass
235*23cd1385SRemy Bohmer  * and defined by www.usb.org documents
236*23cd1385SRemy Bohmer  */
237*23cd1385SRemy Bohmer #define USB_CLASS_PER_INTERFACE		0	/* for DeviceClass */
238*23cd1385SRemy Bohmer #define USB_CLASS_AUDIO			1
239*23cd1385SRemy Bohmer #define USB_CLASS_COMM			2
240*23cd1385SRemy Bohmer #define USB_CLASS_HID			3
241*23cd1385SRemy Bohmer #define USB_CLASS_PHYSICAL		5
242*23cd1385SRemy Bohmer #define USB_CLASS_STILL_IMAGE		6
243*23cd1385SRemy Bohmer #define USB_CLASS_PRINTER		7
244*23cd1385SRemy Bohmer #define USB_CLASS_MASS_STORAGE		8
245*23cd1385SRemy Bohmer #define USB_CLASS_HUB			9
246*23cd1385SRemy Bohmer #define USB_CLASS_CDC_DATA		0x0a
247*23cd1385SRemy Bohmer #define USB_CLASS_CSCID			0x0b	/* chip+ smart card */
248*23cd1385SRemy Bohmer #define USB_CLASS_CONTENT_SEC		0x0d	/* content security */
249*23cd1385SRemy Bohmer #define USB_CLASS_VIDEO			0x0e
250*23cd1385SRemy Bohmer #define USB_CLASS_WIRELESS_CONTROLLER	0xe0
251*23cd1385SRemy Bohmer #define USB_CLASS_MISC			0xef
252*23cd1385SRemy Bohmer #define USB_CLASS_APP_SPEC		0xfe
253*23cd1385SRemy Bohmer #define USB_CLASS_VENDOR_SPEC		0xff
254*23cd1385SRemy Bohmer 
255*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
256*23cd1385SRemy Bohmer 
257*23cd1385SRemy Bohmer /* USB_DT_CONFIG: Configuration descriptor information.
258*23cd1385SRemy Bohmer  *
259*23cd1385SRemy Bohmer  * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
260*23cd1385SRemy Bohmer  * descriptor type is different.  Highspeed-capable devices can look
261*23cd1385SRemy Bohmer  * different depending on what speed they're currently running.  Only
262*23cd1385SRemy Bohmer  * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
263*23cd1385SRemy Bohmer  * descriptors.
264*23cd1385SRemy Bohmer  */
265*23cd1385SRemy Bohmer struct usb_config_descriptor {
266*23cd1385SRemy Bohmer 	__u8  bLength;
267*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
268*23cd1385SRemy Bohmer 
269*23cd1385SRemy Bohmer 	__le16 wTotalLength;
270*23cd1385SRemy Bohmer 	__u8  bNumInterfaces;
271*23cd1385SRemy Bohmer 	__u8  bConfigurationValue;
272*23cd1385SRemy Bohmer 	__u8  iConfiguration;
273*23cd1385SRemy Bohmer 	__u8  bmAttributes;
274*23cd1385SRemy Bohmer 	__u8  bMaxPower;
275*23cd1385SRemy Bohmer } __attribute__ ((packed));
276*23cd1385SRemy Bohmer 
277*23cd1385SRemy Bohmer #define USB_DT_CONFIG_SIZE		9
278*23cd1385SRemy Bohmer 
279*23cd1385SRemy Bohmer /* from config descriptor bmAttributes */
280*23cd1385SRemy Bohmer #define USB_CONFIG_ATT_ONE		(1 << 7)	/* must be set */
281*23cd1385SRemy Bohmer #define USB_CONFIG_ATT_SELFPOWER	(1 << 6)	/* self powered */
282*23cd1385SRemy Bohmer #define USB_CONFIG_ATT_WAKEUP		(1 << 5)	/* can wakeup */
283*23cd1385SRemy Bohmer #define USB_CONFIG_ATT_BATTERY		(1 << 4)	/* battery powered */
284*23cd1385SRemy Bohmer 
285*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
286*23cd1385SRemy Bohmer 
287*23cd1385SRemy Bohmer /* USB_DT_STRING: String descriptor */
288*23cd1385SRemy Bohmer struct usb_string_descriptor {
289*23cd1385SRemy Bohmer 	__u8  bLength;
290*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
291*23cd1385SRemy Bohmer 
292*23cd1385SRemy Bohmer 	__le16 wData[1];		/* UTF-16LE encoded */
293*23cd1385SRemy Bohmer } __attribute__ ((packed));
294*23cd1385SRemy Bohmer 
295*23cd1385SRemy Bohmer /* note that "string" zero is special, it holds language codes that
296*23cd1385SRemy Bohmer  * the device supports, not Unicode characters.
297*23cd1385SRemy Bohmer  */
298*23cd1385SRemy Bohmer 
299*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
300*23cd1385SRemy Bohmer 
301*23cd1385SRemy Bohmer /* USB_DT_INTERFACE: Interface descriptor */
302*23cd1385SRemy Bohmer struct usb_interface_descriptor {
303*23cd1385SRemy Bohmer 	__u8  bLength;
304*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
305*23cd1385SRemy Bohmer 
306*23cd1385SRemy Bohmer 	__u8  bInterfaceNumber;
307*23cd1385SRemy Bohmer 	__u8  bAlternateSetting;
308*23cd1385SRemy Bohmer 	__u8  bNumEndpoints;
309*23cd1385SRemy Bohmer 	__u8  bInterfaceClass;
310*23cd1385SRemy Bohmer 	__u8  bInterfaceSubClass;
311*23cd1385SRemy Bohmer 	__u8  bInterfaceProtocol;
312*23cd1385SRemy Bohmer 	__u8  iInterface;
313*23cd1385SRemy Bohmer } __attribute__ ((packed));
314*23cd1385SRemy Bohmer 
315*23cd1385SRemy Bohmer #define USB_DT_INTERFACE_SIZE		9
316*23cd1385SRemy Bohmer 
317*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
318*23cd1385SRemy Bohmer 
319*23cd1385SRemy Bohmer /* USB_DT_ENDPOINT: Endpoint descriptor */
320*23cd1385SRemy Bohmer struct usb_endpoint_descriptor {
321*23cd1385SRemy Bohmer 	__u8  bLength;
322*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
323*23cd1385SRemy Bohmer 
324*23cd1385SRemy Bohmer 	__u8  bEndpointAddress;
325*23cd1385SRemy Bohmer 	__u8  bmAttributes;
326*23cd1385SRemy Bohmer 	__le16 wMaxPacketSize;
327*23cd1385SRemy Bohmer 	__u8  bInterval;
328*23cd1385SRemy Bohmer 
329*23cd1385SRemy Bohmer 	/* NOTE:  these two are _only_ in audio endpoints. */
330*23cd1385SRemy Bohmer 	/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
331*23cd1385SRemy Bohmer 	__u8  bRefresh;
332*23cd1385SRemy Bohmer 	__u8  bSynchAddress;
333*23cd1385SRemy Bohmer } __attribute__ ((packed));
334*23cd1385SRemy Bohmer 
335*23cd1385SRemy Bohmer #define USB_DT_ENDPOINT_SIZE		7
336*23cd1385SRemy Bohmer #define USB_DT_ENDPOINT_AUDIO_SIZE	9	/* Audio extension */
337*23cd1385SRemy Bohmer 
338*23cd1385SRemy Bohmer 
339*23cd1385SRemy Bohmer /*
340*23cd1385SRemy Bohmer  * Endpoints
341*23cd1385SRemy Bohmer  */
342*23cd1385SRemy Bohmer #define USB_ENDPOINT_NUMBER_MASK	0x0f	/* in bEndpointAddress */
343*23cd1385SRemy Bohmer #define USB_ENDPOINT_DIR_MASK		0x80
344*23cd1385SRemy Bohmer 
345*23cd1385SRemy Bohmer #define USB_ENDPOINT_XFERTYPE_MASK	0x03	/* in bmAttributes */
346*23cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_CONTROL	0
347*23cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_ISOC		1
348*23cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_BULK		2
349*23cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_INT		3
350*23cd1385SRemy Bohmer #define USB_ENDPOINT_MAX_ADJUSTABLE	0x80
351*23cd1385SRemy Bohmer 
352*23cd1385SRemy Bohmer 
353*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
354*23cd1385SRemy Bohmer 
355*23cd1385SRemy Bohmer /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
356*23cd1385SRemy Bohmer struct usb_qualifier_descriptor {
357*23cd1385SRemy Bohmer 	__u8  bLength;
358*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
359*23cd1385SRemy Bohmer 
360*23cd1385SRemy Bohmer 	__le16 bcdUSB;
361*23cd1385SRemy Bohmer 	__u8  bDeviceClass;
362*23cd1385SRemy Bohmer 	__u8  bDeviceSubClass;
363*23cd1385SRemy Bohmer 	__u8  bDeviceProtocol;
364*23cd1385SRemy Bohmer 	__u8  bMaxPacketSize0;
365*23cd1385SRemy Bohmer 	__u8  bNumConfigurations;
366*23cd1385SRemy Bohmer 	__u8  bRESERVED;
367*23cd1385SRemy Bohmer } __attribute__ ((packed));
368*23cd1385SRemy Bohmer 
369*23cd1385SRemy Bohmer 
370*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
371*23cd1385SRemy Bohmer 
372*23cd1385SRemy Bohmer /* USB_DT_OTG (from OTG 1.0a supplement) */
373*23cd1385SRemy Bohmer struct usb_otg_descriptor {
374*23cd1385SRemy Bohmer 	__u8  bLength;
375*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
376*23cd1385SRemy Bohmer 
377*23cd1385SRemy Bohmer 	__u8  bmAttributes;	/* support for HNP, SRP, etc */
378*23cd1385SRemy Bohmer } __attribute__ ((packed));
379*23cd1385SRemy Bohmer 
380*23cd1385SRemy Bohmer /* from usb_otg_descriptor.bmAttributes */
381*23cd1385SRemy Bohmer #define USB_OTG_SRP		(1 << 0)
382*23cd1385SRemy Bohmer #define USB_OTG_HNP		(1 << 1)	/* swap host/device roles */
383*23cd1385SRemy Bohmer 
384*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
385*23cd1385SRemy Bohmer 
386*23cd1385SRemy Bohmer /* USB_DT_DEBUG:  for special highspeed devices, replacing serial console */
387*23cd1385SRemy Bohmer struct usb_debug_descriptor {
388*23cd1385SRemy Bohmer 	__u8  bLength;
389*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
390*23cd1385SRemy Bohmer 
391*23cd1385SRemy Bohmer 	/* bulk endpoints with 8 byte maxpacket */
392*23cd1385SRemy Bohmer 	__u8  bDebugInEndpoint;
393*23cd1385SRemy Bohmer 	__u8  bDebugOutEndpoint;
394*23cd1385SRemy Bohmer } __attribute__((packed));
395*23cd1385SRemy Bohmer 
396*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
397*23cd1385SRemy Bohmer 
398*23cd1385SRemy Bohmer /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
399*23cd1385SRemy Bohmer struct usb_interface_assoc_descriptor {
400*23cd1385SRemy Bohmer 	__u8  bLength;
401*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
402*23cd1385SRemy Bohmer 
403*23cd1385SRemy Bohmer 	__u8  bFirstInterface;
404*23cd1385SRemy Bohmer 	__u8  bInterfaceCount;
405*23cd1385SRemy Bohmer 	__u8  bFunctionClass;
406*23cd1385SRemy Bohmer 	__u8  bFunctionSubClass;
407*23cd1385SRemy Bohmer 	__u8  bFunctionProtocol;
408*23cd1385SRemy Bohmer 	__u8  iFunction;
409*23cd1385SRemy Bohmer } __attribute__ ((packed));
410*23cd1385SRemy Bohmer 
411*23cd1385SRemy Bohmer 
412*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
413*23cd1385SRemy Bohmer 
414*23cd1385SRemy Bohmer /* USB_DT_SECURITY:  group of wireless security descriptors, including
415*23cd1385SRemy Bohmer  * encryption types available for setting up a CC/association.
416*23cd1385SRemy Bohmer  */
417*23cd1385SRemy Bohmer struct usb_security_descriptor {
418*23cd1385SRemy Bohmer 	__u8  bLength;
419*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
420*23cd1385SRemy Bohmer 
421*23cd1385SRemy Bohmer 	__le16 wTotalLength;
422*23cd1385SRemy Bohmer 	__u8  bNumEncryptionTypes;
423*23cd1385SRemy Bohmer } __attribute__((packed));
424*23cd1385SRemy Bohmer 
425*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
426*23cd1385SRemy Bohmer 
427*23cd1385SRemy Bohmer /* USB_DT_KEY:  used with {GET,SET}_SECURITY_DATA; only public keys
428*23cd1385SRemy Bohmer  * may be retrieved.
429*23cd1385SRemy Bohmer  */
430*23cd1385SRemy Bohmer struct usb_key_descriptor {
431*23cd1385SRemy Bohmer 	__u8  bLength;
432*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
433*23cd1385SRemy Bohmer 
434*23cd1385SRemy Bohmer 	__u8  tTKID[3];
435*23cd1385SRemy Bohmer 	__u8  bReserved;
436*23cd1385SRemy Bohmer 	__u8  bKeyData[0];
437*23cd1385SRemy Bohmer } __attribute__((packed));
438*23cd1385SRemy Bohmer 
439*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
440*23cd1385SRemy Bohmer 
441*23cd1385SRemy Bohmer /* USB_DT_ENCRYPTION_TYPE:  bundled in DT_SECURITY groups */
442*23cd1385SRemy Bohmer struct usb_encryption_descriptor {
443*23cd1385SRemy Bohmer 	__u8  bLength;
444*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
445*23cd1385SRemy Bohmer 
446*23cd1385SRemy Bohmer 	__u8  bEncryptionType;
447*23cd1385SRemy Bohmer #define	USB_ENC_TYPE_UNSECURE		0
448*23cd1385SRemy Bohmer #define	USB_ENC_TYPE_WIRED		1	/* non-wireless mode */
449*23cd1385SRemy Bohmer #define	USB_ENC_TYPE_CCM_1		2	/* aes128/cbc session */
450*23cd1385SRemy Bohmer #define	USB_ENC_TYPE_RSA_1		3	/* rsa3072/sha1 auth */
451*23cd1385SRemy Bohmer 	__u8  bEncryptionValue;		/* use in SET_ENCRYPTION */
452*23cd1385SRemy Bohmer 	__u8  bAuthKeyIndex;
453*23cd1385SRemy Bohmer } __attribute__((packed));
454*23cd1385SRemy Bohmer 
455*23cd1385SRemy Bohmer 
456*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
457*23cd1385SRemy Bohmer 
458*23cd1385SRemy Bohmer /* USB_DT_BOS:  group of wireless capabilities */
459*23cd1385SRemy Bohmer struct usb_bos_descriptor {
460*23cd1385SRemy Bohmer 	__u8  bLength;
461*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
462*23cd1385SRemy Bohmer 
463*23cd1385SRemy Bohmer 	__le16 wTotalLength;
464*23cd1385SRemy Bohmer 	__u8  bNumDeviceCaps;
465*23cd1385SRemy Bohmer } __attribute__((packed));
466*23cd1385SRemy Bohmer 
467*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
468*23cd1385SRemy Bohmer 
469*23cd1385SRemy Bohmer /* USB_DT_DEVICE_CAPABILITY:  grouped with BOS */
470*23cd1385SRemy Bohmer struct usb_dev_cap_header {
471*23cd1385SRemy Bohmer 	__u8  bLength;
472*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
473*23cd1385SRemy Bohmer 	__u8  bDevCapabilityType;
474*23cd1385SRemy Bohmer } __attribute__((packed));
475*23cd1385SRemy Bohmer 
476*23cd1385SRemy Bohmer #define	USB_CAP_TYPE_WIRELESS_USB	1
477*23cd1385SRemy Bohmer 
478*23cd1385SRemy Bohmer struct usb_wireless_cap_descriptor {	/* Ultra Wide Band */
479*23cd1385SRemy Bohmer 	__u8  bLength;
480*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
481*23cd1385SRemy Bohmer 	__u8  bDevCapabilityType;
482*23cd1385SRemy Bohmer 
483*23cd1385SRemy Bohmer 	__u8  bmAttributes;
484*23cd1385SRemy Bohmer #define	USB_WIRELESS_P2P_DRD		(1 << 1)
485*23cd1385SRemy Bohmer #define	USB_WIRELESS_BEACON_MASK	(3 << 2)
486*23cd1385SRemy Bohmer #define	USB_WIRELESS_BEACON_SELF	(1 << 2)
487*23cd1385SRemy Bohmer #define	USB_WIRELESS_BEACON_DIRECTED	(2 << 2)
488*23cd1385SRemy Bohmer #define	USB_WIRELESS_BEACON_NONE	(3 << 2)
489*23cd1385SRemy Bohmer 	__le16 wPHYRates;	/* bit rates, Mbps */
490*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_53		(1 << 0)	/* always set */
491*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_80		(1 << 1)
492*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_107		(1 << 2)	/* always set */
493*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_160		(1 << 3)
494*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_200		(1 << 4)	/* always set */
495*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_320		(1 << 5)
496*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_400		(1 << 6)
497*23cd1385SRemy Bohmer #define	USB_WIRELESS_PHY_480		(1 << 7)
498*23cd1385SRemy Bohmer 	__u8  bmTFITXPowerInfo;	/* TFI power levels */
499*23cd1385SRemy Bohmer 	__u8  bmFFITXPowerInfo;	/* FFI power levels */
500*23cd1385SRemy Bohmer 	__le16 bmBandGroup;
501*23cd1385SRemy Bohmer 	__u8  bReserved;
502*23cd1385SRemy Bohmer } __attribute__((packed));
503*23cd1385SRemy Bohmer 
504*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
505*23cd1385SRemy Bohmer 
506*23cd1385SRemy Bohmer /* USB_DT_WIRELESS_ENDPOINT_COMP:  companion descriptor associated with
507*23cd1385SRemy Bohmer  * each endpoint descriptor for a wireless device
508*23cd1385SRemy Bohmer  */
509*23cd1385SRemy Bohmer struct usb_wireless_ep_comp_descriptor {
510*23cd1385SRemy Bohmer 	__u8  bLength;
511*23cd1385SRemy Bohmer 	__u8  bDescriptorType;
512*23cd1385SRemy Bohmer 
513*23cd1385SRemy Bohmer 	__u8  bMaxBurst;
514*23cd1385SRemy Bohmer 	__u8  bMaxSequence;
515*23cd1385SRemy Bohmer 	__le16 wMaxStreamDelay;
516*23cd1385SRemy Bohmer 	__le16 wOverTheAirPacketSize;
517*23cd1385SRemy Bohmer 	__u8  bOverTheAirInterval;
518*23cd1385SRemy Bohmer 	__u8  bmCompAttributes;
519*23cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_MASK	0x03	/* in bmCompAttributes */
520*23cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_NO		0
521*23cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SWITCH	1
522*23cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SCALE	2
523*23cd1385SRemy Bohmer } __attribute__((packed));
524*23cd1385SRemy Bohmer 
525*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
526*23cd1385SRemy Bohmer 
527*23cd1385SRemy Bohmer /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
528*23cd1385SRemy Bohmer  * host and a device for connection set up, mutual authentication, and
529*23cd1385SRemy Bohmer  * exchanging short lived session keys.  The handshake depends on a CC.
530*23cd1385SRemy Bohmer  */
531*23cd1385SRemy Bohmer struct usb_handshake {
532*23cd1385SRemy Bohmer 	__u8 bMessageNumber;
533*23cd1385SRemy Bohmer 	__u8 bStatus;
534*23cd1385SRemy Bohmer 	__u8 tTKID[3];
535*23cd1385SRemy Bohmer 	__u8 bReserved;
536*23cd1385SRemy Bohmer 	__u8 CDID[16];
537*23cd1385SRemy Bohmer 	__u8 nonce[16];
538*23cd1385SRemy Bohmer 	__u8 MIC[8];
539*23cd1385SRemy Bohmer } __attribute__((packed));
540*23cd1385SRemy Bohmer 
541*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
542*23cd1385SRemy Bohmer 
543*23cd1385SRemy Bohmer /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
544*23cd1385SRemy Bohmer  * A CC may also be set up using non-wireless secure channels (including
545*23cd1385SRemy Bohmer  * wired USB!), and some devices may support CCs with multiple hosts.
546*23cd1385SRemy Bohmer  */
547*23cd1385SRemy Bohmer struct usb_connection_context {
548*23cd1385SRemy Bohmer 	__u8 CHID[16];		/* persistent host id */
549*23cd1385SRemy Bohmer 	__u8 CDID[16];		/* device id (unique w/in host context) */
550*23cd1385SRemy Bohmer 	__u8 CK[16];		/* connection key */
551*23cd1385SRemy Bohmer } __attribute__((packed));
552*23cd1385SRemy Bohmer 
553*23cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
554*23cd1385SRemy Bohmer 
555*23cd1385SRemy Bohmer /* USB 2.0 defines three speeds, here's how Linux identifies them */
556*23cd1385SRemy Bohmer 
557*23cd1385SRemy Bohmer enum usb_device_speed {
558*23cd1385SRemy Bohmer 	USB_SPEED_UNKNOWN = 0,			/* enumerating */
559*23cd1385SRemy Bohmer 	USB_SPEED_LOW, USB_SPEED_FULL,		/* usb 1.1 */
560*23cd1385SRemy Bohmer 	USB_SPEED_HIGH,				/* usb 2.0 */
561*23cd1385SRemy Bohmer 	USB_SPEED_VARIABLE,			/* wireless (usb 2.5) */
562*23cd1385SRemy Bohmer };
563*23cd1385SRemy Bohmer 
564*23cd1385SRemy Bohmer enum usb_device_state {
565*23cd1385SRemy Bohmer 	/* NOTATTACHED isn't in the USB spec, and this state acts
566*23cd1385SRemy Bohmer 	 * the same as ATTACHED ... but it's clearer this way.
567*23cd1385SRemy Bohmer 	 */
568*23cd1385SRemy Bohmer 	USB_STATE_NOTATTACHED = 0,
569*23cd1385SRemy Bohmer 
570*23cd1385SRemy Bohmer 	/* chapter 9 and authentication (wireless) device states */
571*23cd1385SRemy Bohmer 	USB_STATE_ATTACHED,
572*23cd1385SRemy Bohmer 	USB_STATE_POWERED,			/* wired */
573*23cd1385SRemy Bohmer 	USB_STATE_UNAUTHENTICATED,		/* auth */
574*23cd1385SRemy Bohmer 	USB_STATE_RECONNECTING,			/* auth */
575*23cd1385SRemy Bohmer 	USB_STATE_DEFAULT,			/* limited function */
576*23cd1385SRemy Bohmer 	USB_STATE_ADDRESS,
577*23cd1385SRemy Bohmer 	USB_STATE_CONFIGURED,			/* most functions */
578*23cd1385SRemy Bohmer 
579*23cd1385SRemy Bohmer 	USB_STATE_SUSPENDED
580*23cd1385SRemy Bohmer 
581*23cd1385SRemy Bohmer 	/* NOTE:  there are actually four different SUSPENDED
582*23cd1385SRemy Bohmer 	 * states, returning to POWERED, DEFAULT, ADDRESS, or
583*23cd1385SRemy Bohmer 	 * CONFIGURED respectively when SOF tokens flow again.
584*23cd1385SRemy Bohmer 	 */
585*23cd1385SRemy Bohmer };
586*23cd1385SRemy Bohmer 
587*23cd1385SRemy Bohmer #endif	/* __LINUX_USB_CH9_H */
588