xref: /freebsd/lib/libusb/libusb20_desc.h (revision ae489991d1c0b550ead309abc1eade3b185e7499)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5  * Copyright (c) 2007-2008 Daniel Drake.  All rights reserved.
6  * Copyright (c) 2001 Johannes Erdfelt.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /*
31  * NOTE: This file contains the definition of some standard USB
32  * structures. All structures which name ends by *DECODED use host byte
33  * order.
34  */
35 
36 /*
37  * NOTE: This file uses a lot of macros. If you want to see what the
38  * macros become when they are expanded then run the following
39  * commands from your shell:
40  *
41  * cpp libusb20_desc.h > temp.h
42  * indent temp.h
43  * less temp.h
44  */
45 
46 #ifndef _LIBUSB20_DESC_H_
47 #define	_LIBUSB20_DESC_H_
48 
49 #ifndef LIBUSB_GLOBAL_INCLUDE_FILE
50 #include <stdint.h>
51 #endif
52 
53 #ifdef __cplusplus
54 extern	"C" {
55 #endif
56 #if 0
57 };					/* style */
58 
59 #endif
60 /* basic macros */
61 
62 #define	LIBUSB20__NOT(...) __VA_ARGS__
63 #define	LIBUSB20_NOT(arg) LIBUSB20__NOT(LIBUSB20_YES arg(() LIBUSB20_NO))
64 #define	LIBUSB20_YES(...) __VA_ARGS__
65 #define	LIBUSB20_NO(...)
66 #define	LIBUSB20_END(...) __VA_ARGS__
67 #define	LIBUSB20_MAX(a,b) (((a) > (b)) ? (a) : (b))
68 #define	LIBUSB20_MIN(a,b) (((a) < (b)) ? (a) : (b))
69 
70 #define	LIBUSB20_ADD_BYTES(ptr,off) \
71   ((void *)(((const uint8_t *)(ptr)) + (off) - ((const uint8_t *)0)))
72 
73 /* basic message elements */
74 enum {
75 	LIBUSB20_ME_INT8,
76 	LIBUSB20_ME_INT16,
77 	LIBUSB20_ME_INT32,
78 	LIBUSB20_ME_INT64,
79 	LIBUSB20_ME_STRUCT,
80 	LIBUSB20_ME_MAX,		/* used to indicate end */
81 };
82 
83 /* basic message element modifiers */
84 enum {
85 	LIBUSB20_ME_IS_UNSIGNED = 0x00,
86 	LIBUSB20_ME_IS_SIGNED = 0x80,
87 	LIBUSB20_ME_MASK = 0x7F,
88 };
89 
90 enum {
91 	LIBUSB20_ME_IS_RAW,		/* structure excludes length field
92 					 * (hardcoded value) */
93 	LIBUSB20_ME_IS_ENCODED,		/* structure includes length field */
94 	LIBUSB20_ME_IS_EMPTY,		/* no structure */
95 	LIBUSB20_ME_IS_DECODED,		/* structure is recursive */
96 };
97 
98 /* basic helper structures and macros */
99 
100 #define	LIBUSB20_ME_STRUCT_ALIGN sizeof(void *)
101 
102 struct libusb20_me_struct {
103 	void   *ptr;			/* data pointer */
104 	uint16_t len;			/* defaults to zero */
105 	uint16_t type;			/* defaults to LIBUSB20_ME_IS_EMPTY */
106 } __aligned(LIBUSB20_ME_STRUCT_ALIGN);
107 
108 struct libusb20_me_format {
109 	const uint8_t *format;		/* always set */
110 	const char *desc;		/* optionally set */
111 	const char *fields;		/* optionally set */
112 };
113 
114 #define	LIBUSB20_ME_STRUCT(n, field, arg, ismeta)		\
115   ismeta ( LIBUSB20_ME_STRUCT, 1, 0, )			\
116   LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field; )
117 
118 #define	LIBUSB20_ME_STRUCT_ARRAY(n, field, arg, ismeta)	\
119   ismeta ( LIBUSB20_ME_STRUCT , (arg) & 0xFF,		\
120 	   ((arg) / 0x100) & 0xFF, )			\
121   LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field [arg]; )
122 
123 #define	LIBUSB20_ME_INTEGER(n, field, ismeta, un, u, bits, a, size)	\
124   ismeta ( LIBUSB20_ME_INT##bits |					\
125 	   LIBUSB20_ME_IS_##un##SIGNED ,				\
126 	   (size) & 0xFF, ((size) / 0x100) & 0xFF, )		\
127   LIBUSB20_NOT(ismeta) ( u##int##bits##_t				\
128 		    __aligned((bits) / 8) field a; )
129 
130 #define	LIBUSB20_ME_UINT8_T(n, field, arg, ismeta) \
131   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, , 1)
132 
133 #define	LIBUSB20_ME_UINT8_ARRAY_T(n, field, arg, ismeta) \
134   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, [arg], arg)
135 
136 #define	LIBUSB20_ME_SINT8_T(n, field, arg, ismeta) \
137   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, , 1)
138 
139 #define	LIBUSB20_ME_SINT8_ARRAY_T(n, field, arg, ismeta) \
140   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, [arg], arg)
141 
142 #define	LIBUSB20_ME_UINT16_T(n, field, arg, ismeta) \
143   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, , 1)
144 
145 #define	LIBUSB20_ME_UINT16_ARRAY_T(n, field, arg, ismeta) \
146   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, [arg], arg)
147 
148 #define	LIBUSB20_ME_SINT16_T(n, field, arg, ismeta) \
149   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, , 1)
150 
151 #define	LIBUSB20_ME_SINT16_ARRAY_T(n, field, arg, ismeta) \
152   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, [arg], arg)
153 
154 #define	LIBUSB20_ME_UINT32_T(n, field, arg, ismeta) \
155   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, , 1)
156 
157 #define	LIBUSB20_ME_UINT32_ARRAY_T(n, field, arg, ismeta) \
158   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, [arg], arg)
159 
160 #define	LIBUSB20_ME_SINT32_T(n, field, arg, ismeta) \
161   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, , 1)
162 
163 #define	LIBUSB20_ME_SINT32_ARRAY_T(n, field, arg, ismeta) \
164   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, [arg], arg)
165 
166 #define	LIBUSB20_ME_UINT64_T(n, field, arg, ismeta) \
167   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, , 1)
168 
169 #define	LIBUSB20_ME_UINT64_ARRAY_T(n, field, arg, ismeta) \
170   LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, [arg], arg)
171 
172 #define	LIBUSB20_ME_SINT64_T(n, field, arg, ismeta) \
173   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, , 1)
174 
175 #define	LIBUSB20_ME_SINT64_ARRAY_T(n, field, arg, ismeta) \
176   LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, [arg], arg)
177 
178 #define	LIBUSB20_MAKE_DECODED_FIELD(n, type, field, arg) \
179   LIBUSB20_ME_##type (n, field, arg, LIBUSB20_NO)
180 
181 #define	LIBUSB20_MAKE_STRUCT(name)			\
182   extern const struct libusb20_me_format			\
183 	 name##_FORMAT[1];				\
184   struct name##_DECODED {				\
185     const struct libusb20_me_format *name##_FORMAT;	\
186     name (LIBUSB20_MAKE_DECODED_FIELD,)			\
187   }
188 
189 #define	LIBUSB20_MAKE_STRUCT_FORMAT(name)		\
190   const struct libusb20_me_format			\
191     name##_FORMAT[1] = {{			\
192       .format = LIBUSB20_MAKE_FORMAT(name),	\
193       .desc = #name,				\
194       .fields = NULL,				\
195   }}
196 
197 #define	LIBUSB20_MAKE_FORMAT_SUB(n, type, field, arg) \
198   LIBUSB20_ME_##type (n, field, arg, LIBUSB20_YES)
199 
200 #define	LIBUSB20_MAKE_FORMAT(what) (const uint8_t []) \
201   { what (LIBUSB20_MAKE_FORMAT_SUB, ) LIBUSB20_ME_MAX, 0, 0 }
202 
203 #define	LIBUSB20_INIT(what, ptr) do {		\
204     memset(ptr, 0, sizeof(*(ptr)));		\
205     (ptr)->what##_FORMAT = what##_FORMAT;	\
206 } while (0)
207 
208 #define	LIBUSB20_DEVICE_DESC(m,n) \
209   m(n, UINT8_T, bLength, ) \
210   m(n, UINT8_T, bDescriptorType, ) \
211   m(n, UINT16_T, bcdUSB, ) \
212   m(n, UINT8_T, bDeviceClass, ) \
213   m(n, UINT8_T, bDeviceSubClass, ) \
214   m(n, UINT8_T, bDeviceProtocol, ) \
215   m(n, UINT8_T, bMaxPacketSize0, ) \
216   m(n, UINT16_T, idVendor, ) \
217   m(n, UINT16_T, idProduct, ) \
218   m(n, UINT16_T, bcdDevice, ) \
219   m(n, UINT8_T, iManufacturer, ) \
220   m(n, UINT8_T, iProduct, ) \
221   m(n, UINT8_T, iSerialNumber, ) \
222   m(n, UINT8_T, bNumConfigurations, ) \
223 
224 LIBUSB20_MAKE_STRUCT(LIBUSB20_DEVICE_DESC);
225 
226 #define	LIBUSB20_ENDPOINT_DESC(m,n) \
227   m(n, UINT8_T,  bLength, ) \
228   m(n, UINT8_T,  bDescriptorType, ) \
229   m(n, UINT8_T,  bEndpointAddress, ) \
230   m(n, UINT8_T,  bmAttributes, ) \
231   m(n, UINT16_T, wMaxPacketSize, ) \
232   m(n, UINT8_T,  bInterval, ) \
233   m(n, UINT8_T,  bRefresh, ) \
234   m(n, UINT8_T,  bSynchAddress, ) \
235 
236 LIBUSB20_MAKE_STRUCT(LIBUSB20_ENDPOINT_DESC);
237 
238 #define	LIBUSB20_INTERFACE_DESC(m,n) \
239   m(n, UINT8_T,  bLength, ) \
240   m(n, UINT8_T,  bDescriptorType, ) \
241   m(n, UINT8_T,  bInterfaceNumber, ) \
242   m(n, UINT8_T,  bAlternateSetting, ) \
243   m(n, UINT8_T,  bNumEndpoints, ) \
244   m(n, UINT8_T,  bInterfaceClass, ) \
245   m(n, UINT8_T,  bInterfaceSubClass, ) \
246   m(n, UINT8_T,  bInterfaceProtocol, ) \
247   m(n, UINT8_T,  iInterface, ) \
248 
249 LIBUSB20_MAKE_STRUCT(LIBUSB20_INTERFACE_DESC);
250 
251 #define	LIBUSB20_INTERFACE_ASSOCIATION_DESC(m,n) \
252   m(n, UINT8_T,  bLength, ) \
253   m(n, UINT8_T,  bDescriptorType, ) \
254   m(n, UINT8_T,  bFirstInterface, ) \
255   m(n, UINT8_T,  bInterfaceCount, ) \
256   m(n, UINT8_T,  bFunctionClass, ) \
257   m(n, UINT8_T,  bFunctionSubClass, ) \
258   m(n, UINT8_T,  bFunctionProtocol, ) \
259   m(n, UINT8_T,  iFunction, ) \
260 
261 LIBUSB20_MAKE_STRUCT(LIBUSB20_INTERFACE_ASSOCIATION_DESC);
262 
263 #define	LIBUSB20_CONFIG_DESC(m,n) \
264   m(n, UINT8_T,  bLength, ) \
265   m(n, UINT8_T,  bDescriptorType, ) \
266   m(n, UINT16_T, wTotalLength, ) \
267   m(n, UINT8_T,  bNumInterfaces, ) \
268   m(n, UINT8_T,  bConfigurationValue, ) \
269   m(n, UINT8_T,  iConfiguration, ) \
270   m(n, UINT8_T,  bmAttributes, ) \
271   m(n, UINT8_T,  bMaxPower, ) \
272 
273 LIBUSB20_MAKE_STRUCT(LIBUSB20_CONFIG_DESC);
274 
275 #define	LIBUSB20_CONTROL_SETUP(m,n) \
276   m(n, UINT8_T,  bmRequestType, ) \
277   m(n, UINT8_T,  bRequest, ) \
278   m(n, UINT16_T, wValue, ) \
279   m(n, UINT16_T, wIndex, ) \
280   m(n, UINT16_T, wLength, ) \
281 
282 LIBUSB20_MAKE_STRUCT(LIBUSB20_CONTROL_SETUP);
283 
284 #define	LIBUSB20_SS_ENDPT_COMP_DESC(m,n) \
285   m(n, UINT8_T,  bLength, ) \
286   m(n, UINT8_T,  bDescriptorType, ) \
287   m(n, UINT8_T,  bMaxBurst, ) \
288   m(n, UINT8_T,  bmAttributes, ) \
289   m(n, UINT16_T, wBytesPerInterval, ) \
290 
291 LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_ENDPT_COMP_DESC);
292 
293 #define	LIBUSB20_USB_20_DEVCAP_DESC(m,n) \
294   m(n, UINT8_T,  bLength, ) \
295   m(n, UINT8_T,  bDescriptorType, ) \
296   m(n, UINT8_T,  bDevCapabilityType, ) \
297   m(n, UINT32_T, bmAttributes, ) \
298 
299 LIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC);
300 
301 #define	LIBUSB20_SS_USB_DEVCAP_DESC(m,n) \
302   m(n, UINT8_T,  bLength, ) \
303   m(n, UINT8_T,  bDescriptorType, ) \
304   m(n, UINT8_T,  bDevCapabilityType, ) \
305   m(n, UINT8_T,  bmAttributes, ) \
306   m(n, UINT16_T, wSpeedSupported, ) \
307   m(n, UINT8_T,  bFunctionalitySupport, ) \
308   m(n, UINT8_T,  bU1DevExitLat, ) \
309   m(n, UINT16_T, wU2DevExitLat, ) \
310 
311 LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);
312 
313 #ifndef bNumDeviceCapabilities
314 #define bNumDeviceCapabilities bNumDeviceCaps
315 #endif
316 
317 #define	LIBUSB20_BOS_DESCRIPTOR(m,n) \
318   m(n, UINT8_T,  bLength, ) \
319   m(n, UINT8_T,  bDescriptorType, ) \
320   m(n, UINT16_T, wTotalLength, ) \
321   m(n, UINT8_T,  bNumDeviceCaps, ) \
322 
323 LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);
324 
325 /* standard USB stuff */
326 
327 /** \ingroup desc
328  * Device and/or Interface Class codes */
329 enum libusb20_class_code {
330 	/** In the context of a \ref LIBUSB20_DEVICE_DESC "device
331 	 * descriptor", this bDeviceClass value indicates that each
332 	 * interface specifies its own class information and all
333 	 * interfaces operate independently.
334 	 */
335 	LIBUSB20_CLASS_PER_INTERFACE = 0,
336 
337 	/** Audio class */
338 	LIBUSB20_CLASS_AUDIO = 1,
339 
340 	/** Communications class */
341 	LIBUSB20_CLASS_COMM = 2,
342 
343 	/** Human Interface Device class */
344 	LIBUSB20_CLASS_HID = 3,
345 
346 	/** Printer dclass */
347 	LIBUSB20_CLASS_PRINTER = 7,
348 
349 	/** Picture transfer protocol class */
350 	LIBUSB20_CLASS_PTP = 6,
351 
352 	/** Mass storage class */
353 	LIBUSB20_CLASS_MASS_STORAGE = 8,
354 
355 	/** Hub class */
356 	LIBUSB20_CLASS_HUB = 9,
357 
358 	/** Data class */
359 	LIBUSB20_CLASS_DATA = 10,
360 
361 	/** Class is vendor-specific */
362 	LIBUSB20_CLASS_VENDOR_SPEC = 0xff,
363 };
364 
365 /** \ingroup desc
366  * Descriptor types as defined by the USB specification. */
367 enum libusb20_descriptor_type {
368 	/** Device descriptor. See LIBUSB20_DEVICE_DESC. */
369 	LIBUSB20_DT_DEVICE = 0x01,
370 
371 	/** Configuration descriptor. See LIBUSB20_CONFIG_DESC. */
372 	LIBUSB20_DT_CONFIG = 0x02,
373 
374 	/** String descriptor */
375 	LIBUSB20_DT_STRING = 0x03,
376 
377 	/** Interface descriptor. See LIBUSB20_INTERFACE_DESC. */
378 	LIBUSB20_DT_INTERFACE = 0x04,
379 
380 	/** Endpoint descriptor. See LIBUSB20_ENDPOINT_DESC. */
381 	LIBUSB20_DT_ENDPOINT = 0x05,
382 
383 	/** Interface Association descriptor. See
384 	   LIBUSB20_INTERFACE_ASSOCIATION_DESC. */
385 	LIBUSB20_DT_INTERFACE_ASSOCIATION = 0x0b,
386 
387 	/** HID descriptor */
388 	LIBUSB20_DT_HID = 0x21,
389 
390 	/** HID report descriptor */
391 	LIBUSB20_DT_REPORT = 0x22,
392 
393 	/** Physical descriptor */
394 	LIBUSB20_DT_PHYSICAL = 0x23,
395 
396 	/** Hub descriptor */
397 	LIBUSB20_DT_HUB = 0x29,
398 
399 	/** Binary Object Store, BOS */
400 	LIBUSB20_DT_BOS = 0x0f,
401 
402 	/** Device Capability */
403 	LIBUSB20_DT_DEVICE_CAPABILITY = 0x10,
404 
405 	/** SuperSpeed endpoint companion */
406 	LIBUSB20_DT_SS_ENDPOINT_COMPANION = 0x30,
407 };
408 
409 /** \ingroup desc
410  * Device capability types as defined by the USB specification. */
411 enum libusb20_device_capability_type {
412 	LIBUSB20_WIRELESS_USB_DEVICE_CAPABILITY = 0x1,
413 	LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY = 0x2,
414 	LIBUSB20_SS_USB_DEVICE_CAPABILITY = 0x3,
415 	LIBUSB20_CONTAINER_ID_DEVICE_CAPABILITY = 0x4,
416 };
417 
418 /* Descriptor sizes per descriptor type */
419 #define	LIBUSB20_DT_DEVICE_SIZE			18
420 #define	LIBUSB20_DT_CONFIG_SIZE			9
421 #define	LIBUSB20_DT_INTERFACE_SIZE		9
422 #define	LIBUSB20_DT_ENDPOINT_SIZE		7
423 #define	LIBUSB20_DT_ENDPOINT_AUDIO_SIZE		9	/* Audio extension */
424 #define	LIBUSB20_DT_HUB_NONVAR_SIZE		7
425 #define	LIBUSB20_DT_SS_ENDPOINT_COMPANION_SIZE	6
426 #define	LIBUSB20_DT_BOS_SIZE		5
427 #define	LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE	7
428 #define	LIBUSB20_SS_USB_DEVICE_CAPABILITY_SIZE	10
429 
430 #define	LIBUSB20_ENDPOINT_ADDRESS_MASK	0x0f	/* in bEndpointAddress */
431 #define	LIBUSB20_ENDPOINT_DIR_MASK	0x80
432 
433 /** \ingroup desc
434  * Endpoint direction. Values for bit 7 of the
435  * \ref LIBUSB20_ENDPOINT_DESC::bEndpointAddress "endpoint address" scheme.
436  */
437 enum libusb20_endpoint_direction {
438 	/** In: device-to-host */
439 	LIBUSB20_ENDPOINT_IN = 0x80,
440 
441 	/** Out: host-to-device */
442 	LIBUSB20_ENDPOINT_OUT = 0x00,
443 };
444 
445 #define	LIBUSB20_TRANSFER_TYPE_MASK	0x03	/* in bmAttributes */
446 
447 /** \ingroup desc
448  * Endpoint transfer type. Values for bits 0:1 of the
449  * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "endpoint attributes" field.
450  */
451 enum libusb20_transfer_type {
452 	/** Control endpoint */
453 	LIBUSB20_TRANSFER_TYPE_CONTROL = 0,
454 
455 	/** Isochronous endpoint */
456 	LIBUSB20_TRANSFER_TYPE_ISOCHRONOUS = 1,
457 
458 	/** Bulk endpoint */
459 	LIBUSB20_TRANSFER_TYPE_BULK = 2,
460 
461 	/** Interrupt endpoint */
462 	LIBUSB20_TRANSFER_TYPE_INTERRUPT = 3,
463 };
464 
465 /** \ingroup misc
466  * Standard requests, as defined in table 9-3 of the USB2 specifications */
467 enum libusb20_standard_request {
468 	/** Request status of the specific recipient */
469 	LIBUSB20_REQUEST_GET_STATUS = 0x00,
470 
471 	/** Clear or disable a specific feature */
472 	LIBUSB20_REQUEST_CLEAR_FEATURE = 0x01,
473 
474 	/* 0x02 is reserved */
475 
476 	/** Set or enable a specific feature */
477 	LIBUSB20_REQUEST_SET_FEATURE = 0x03,
478 
479 	/* 0x04 is reserved */
480 
481 	/** Set device address for all future accesses */
482 	LIBUSB20_REQUEST_SET_ADDRESS = 0x05,
483 
484 	/** Get the specified descriptor */
485 	LIBUSB20_REQUEST_GET_DESCRIPTOR = 0x06,
486 
487 	/** Used to update existing descriptors or add new descriptors */
488 	LIBUSB20_REQUEST_SET_DESCRIPTOR = 0x07,
489 
490 	/** Get the current device configuration value */
491 	LIBUSB20_REQUEST_GET_CONFIGURATION = 0x08,
492 
493 	/** Set device configuration */
494 	LIBUSB20_REQUEST_SET_CONFIGURATION = 0x09,
495 
496 	/** Return the selected alternate setting for the specified
497 	 * interface */
498 	LIBUSB20_REQUEST_GET_INTERFACE = 0x0A,
499 
500 	/** Select an alternate interface for the specified interface */
501 	LIBUSB20_REQUEST_SET_INTERFACE = 0x0B,
502 
503 	/** Set then report an endpoint's synchronization frame */
504 	LIBUSB20_REQUEST_SYNCH_FRAME = 0x0C,
505 
506 	/** Set U1 and U2 system exit latency */
507 	LIBUSB20_REQUEST_SET_SEL = 0x30,
508 
509 	/** Set isochronous delay */
510 	LIBUSB20_REQUEST_SET_ISOCH_DELAY = 0x31,
511 };
512 
513 /** \ingroup misc
514  * Request type bits of the
515  * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in
516  * control transfers. */
517 enum libusb20_request_type {
518 	/** Standard */
519 	LIBUSB20_REQUEST_TYPE_STANDARD = (0x00 << 5),
520 
521 	/** Class */
522 	LIBUSB20_REQUEST_TYPE_CLASS = (0x01 << 5),
523 
524 	/** Vendor */
525 	LIBUSB20_REQUEST_TYPE_VENDOR = (0x02 << 5),
526 
527 	/** Reserved */
528 	LIBUSB20_REQUEST_TYPE_RESERVED = (0x03 << 5),
529 };
530 
531 /** \ingroup misc
532  * Recipient bits of the
533  * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in
534  * control transfers. Values 4 through 31 are reserved. */
535 enum libusb20_request_recipient {
536 	/** Device */
537 	LIBUSB20_RECIPIENT_DEVICE = 0x00,
538 
539 	/** Interface */
540 	LIBUSB20_RECIPIENT_INTERFACE = 0x01,
541 
542 	/** Endpoint */
543 	LIBUSB20_RECIPIENT_ENDPOINT = 0x02,
544 
545 	/** Other */
546 	LIBUSB20_RECIPIENT_OTHER = 0x03,
547 };
548 
549 #define	LIBUSB20_ISO_SYNC_TYPE_MASK		0x0C
550 
551 /** \ingroup desc
552  * Synchronization type for isochronous endpoints. Values for bits 2:3
553  * of the \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes"
554  * field in LIBUSB20_ENDPOINT_DESC.
555  */
556 enum libusb20_iso_sync_type {
557 	/** No synchronization */
558 	LIBUSB20_ISO_SYNC_TYPE_NONE = 0,
559 
560 	/** Asynchronous */
561 	LIBUSB20_ISO_SYNC_TYPE_ASYNC = 1,
562 
563 	/** Adaptive */
564 	LIBUSB20_ISO_SYNC_TYPE_ADAPTIVE = 2,
565 
566 	/** Synchronous */
567 	LIBUSB20_ISO_SYNC_TYPE_SYNC = 3,
568 };
569 
570 #define	LIBUSB20_ISO_USAGE_TYPE_MASK 0x30
571 
572 /** \ingroup desc
573  * Usage type for isochronous endpoints. Values for bits 4:5 of the
574  * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes" field in
575  * LIBUSB20_ENDPOINT_DESC.
576  */
577 enum libusb20_iso_usage_type {
578 	/** Data endpoint */
579 	LIBUSB20_ISO_USAGE_TYPE_DATA = 0,
580 
581 	/** Feedback endpoint */
582 	LIBUSB20_ISO_USAGE_TYPE_FEEDBACK = 1,
583 
584 	/** Implicit feedback Data endpoint */
585 	LIBUSB20_ISO_USAGE_TYPE_IMPLICIT = 2,
586 };
587 
588 struct libusb20_endpoint {
589 	struct LIBUSB20_ENDPOINT_DESC_DECODED desc;
590 	struct libusb20_me_struct extra;
591 } __aligned(sizeof(void *));
592 
593 struct libusb20_interface {
594 	struct LIBUSB20_INTERFACE_DESC_DECODED desc;
595 	struct libusb20_me_struct extra;
596 	struct libusb20_interface *altsetting;
597 	struct libusb20_endpoint *endpoints;
598 	uint8_t	num_altsetting;
599 	uint8_t	num_endpoints;
600 } __aligned(sizeof(void *));
601 
602 struct libusb20_iad_desc {
603 	struct LIBUSB20_INTERFACE_ASSOCIATION_DESC_DECODED desc;
604 	struct libusb20_me_struct extra;
605 } __aligned(sizeof(void *));
606 
607 struct libusb20_config {
608 	struct LIBUSB20_CONFIG_DESC_DECODED desc;
609 	struct libusb20_me_struct extra;
610 	struct libusb20_interface *interface;
611 	uint8_t	num_interface;
612 	struct libusb20_iad_desc *iad_desc;
613 	int niad;
614 } __aligned(sizeof(void *));
615 
616 uint8_t	libusb20_me_get_1(const struct libusb20_me_struct *ie, uint16_t offset);
617 uint16_t libusb20_me_get_2(const struct libusb20_me_struct *ie, uint16_t offset);
618 uint16_t libusb20_me_encode(void *ptr, uint16_t len, const void *pd);
619 uint16_t libusb20_me_decode(const void *ptr, uint16_t len, void *pd);
620 const uint8_t *libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, const uint8_t *psubdesc);
621 struct libusb20_config *libusb20_parse_config_desc(const void *config_desc);
622 
623 #if 0
624 {					/* style */
625 #endif
626 #ifdef __cplusplus
627 }
628 
629 #endif
630 
631 #endif					/* _LIBUSB20_DESC_H_ */
632