xref: /freebsd/lib/libusb/libusb20_desc.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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_CONFIG_DESC(m,n) \
252   m(n, UINT8_T,  bLength, ) \
253   m(n, UINT8_T,  bDescriptorType, ) \
254   m(n, UINT16_T, wTotalLength, ) \
255   m(n, UINT8_T,  bNumInterfaces, ) \
256   m(n, UINT8_T,  bConfigurationValue, ) \
257   m(n, UINT8_T,  iConfiguration, ) \
258   m(n, UINT8_T,  bmAttributes, ) \
259   m(n, UINT8_T,  bMaxPower, ) \
260 
261 LIBUSB20_MAKE_STRUCT(LIBUSB20_CONFIG_DESC);
262 
263 #define	LIBUSB20_CONTROL_SETUP(m,n) \
264   m(n, UINT8_T,  bmRequestType, ) \
265   m(n, UINT8_T,  bRequest, ) \
266   m(n, UINT16_T, wValue, ) \
267   m(n, UINT16_T, wIndex, ) \
268   m(n, UINT16_T, wLength, ) \
269 
270 LIBUSB20_MAKE_STRUCT(LIBUSB20_CONTROL_SETUP);
271 
272 #define	LIBUSB20_SS_ENDPT_COMP_DESC(m,n) \
273   m(n, UINT8_T,  bLength, ) \
274   m(n, UINT8_T,  bDescriptorType, ) \
275   m(n, UINT8_T,  bMaxBurst, ) \
276   m(n, UINT8_T,  bmAttributes, ) \
277   m(n, UINT16_T, wBytesPerInterval, ) \
278 
279 LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_ENDPT_COMP_DESC);
280 
281 #define	LIBUSB20_USB_20_DEVCAP_DESC(m,n) \
282   m(n, UINT8_T,  bLength, ) \
283   m(n, UINT8_T,  bDescriptorType, ) \
284   m(n, UINT8_T,  bDevCapabilityType, ) \
285   m(n, UINT32_T, bmAttributes, ) \
286 
287 LIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC);
288 
289 #define	LIBUSB20_SS_USB_DEVCAP_DESC(m,n) \
290   m(n, UINT8_T,  bLength, ) \
291   m(n, UINT8_T,  bDescriptorType, ) \
292   m(n, UINT8_T,  bDevCapabilityType, ) \
293   m(n, UINT8_T,  bmAttributes, ) \
294   m(n, UINT16_T, wSpeedSupported, ) \
295   m(n, UINT8_T,  bFunctionalitySupport, ) \
296   m(n, UINT8_T,  bU1DevExitLat, ) \
297   m(n, UINT16_T, wU2DevExitLat, ) \
298 
299 LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);
300 
301 #define	LIBUSB20_BOS_DESCRIPTOR(m,n) \
302   m(n, UINT8_T,  bLength, ) \
303   m(n, UINT8_T,  bDescriptorType, ) \
304   m(n, UINT16_T, wTotalLength, ) \
305   m(n, UINT8_T,  bNumDeviceCapabilities, ) \
306 
307 LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);
308 
309 /* standard USB stuff */
310 
311 /** \ingroup desc
312  * Device and/or Interface Class codes */
313 enum libusb20_class_code {
314 	/** In the context of a \ref LIBUSB20_DEVICE_DESC "device
315 	 * descriptor", this bDeviceClass value indicates that each
316 	 * interface specifies its own class information and all
317 	 * interfaces operate independently.
318 	 */
319 	LIBUSB20_CLASS_PER_INTERFACE = 0,
320 
321 	/** Audio class */
322 	LIBUSB20_CLASS_AUDIO = 1,
323 
324 	/** Communications class */
325 	LIBUSB20_CLASS_COMM = 2,
326 
327 	/** Human Interface Device class */
328 	LIBUSB20_CLASS_HID = 3,
329 
330 	/** Printer dclass */
331 	LIBUSB20_CLASS_PRINTER = 7,
332 
333 	/** Picture transfer protocol class */
334 	LIBUSB20_CLASS_PTP = 6,
335 
336 	/** Mass storage class */
337 	LIBUSB20_CLASS_MASS_STORAGE = 8,
338 
339 	/** Hub class */
340 	LIBUSB20_CLASS_HUB = 9,
341 
342 	/** Data class */
343 	LIBUSB20_CLASS_DATA = 10,
344 
345 	/** Class is vendor-specific */
346 	LIBUSB20_CLASS_VENDOR_SPEC = 0xff,
347 };
348 
349 /** \ingroup desc
350  * Descriptor types as defined by the USB specification. */
351 enum libusb20_descriptor_type {
352 	/** Device descriptor. See LIBUSB20_DEVICE_DESC. */
353 	LIBUSB20_DT_DEVICE = 0x01,
354 
355 	/** Configuration descriptor. See LIBUSB20_CONFIG_DESC. */
356 	LIBUSB20_DT_CONFIG = 0x02,
357 
358 	/** String descriptor */
359 	LIBUSB20_DT_STRING = 0x03,
360 
361 	/** Interface descriptor. See LIBUSB20_INTERFACE_DESC. */
362 	LIBUSB20_DT_INTERFACE = 0x04,
363 
364 	/** Endpoint descriptor. See LIBUSB20_ENDPOINT_DESC. */
365 	LIBUSB20_DT_ENDPOINT = 0x05,
366 
367 	/** HID descriptor */
368 	LIBUSB20_DT_HID = 0x21,
369 
370 	/** HID report descriptor */
371 	LIBUSB20_DT_REPORT = 0x22,
372 
373 	/** Physical descriptor */
374 	LIBUSB20_DT_PHYSICAL = 0x23,
375 
376 	/** Hub descriptor */
377 	LIBUSB20_DT_HUB = 0x29,
378 
379 	/** Binary Object Store, BOS */
380 	LIBUSB20_DT_BOS = 0x0f,
381 
382 	/** Device Capability */
383 	LIBUSB20_DT_DEVICE_CAPABILITY = 0x10,
384 
385 	/** SuperSpeed endpoint companion */
386 	LIBUSB20_DT_SS_ENDPOINT_COMPANION = 0x30,
387 };
388 
389 /** \ingroup desc
390  * Device capability types as defined by the USB specification. */
391 enum libusb20_device_capability_type {
392 	LIBUSB20_WIRELESS_USB_DEVICE_CAPABILITY = 0x1,
393 	LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY = 0x2,
394 	LIBUSB20_SS_USB_DEVICE_CAPABILITY = 0x3,
395 	LIBUSB20_CONTAINER_ID_DEVICE_CAPABILITY = 0x4,
396 };
397 
398 /* Descriptor sizes per descriptor type */
399 #define	LIBUSB20_DT_DEVICE_SIZE			18
400 #define	LIBUSB20_DT_CONFIG_SIZE			9
401 #define	LIBUSB20_DT_INTERFACE_SIZE		9
402 #define	LIBUSB20_DT_ENDPOINT_SIZE		7
403 #define	LIBUSB20_DT_ENDPOINT_AUDIO_SIZE		9	/* Audio extension */
404 #define	LIBUSB20_DT_HUB_NONVAR_SIZE		7
405 #define	LIBUSB20_DT_SS_ENDPOINT_COMPANION_SIZE	6
406 #define	LIBUSB20_DT_BOS_SIZE		5
407 #define	LIBUSB20_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE	7
408 #define	LIBUSB20_SS_USB_DEVICE_CAPABILITY_SIZE	10
409 
410 #define	LIBUSB20_ENDPOINT_ADDRESS_MASK	0x0f	/* in bEndpointAddress */
411 #define	LIBUSB20_ENDPOINT_DIR_MASK	0x80
412 
413 /** \ingroup desc
414  * Endpoint direction. Values for bit 7 of the
415  * \ref LIBUSB20_ENDPOINT_DESC::bEndpointAddress "endpoint address" scheme.
416  */
417 enum libusb20_endpoint_direction {
418 	/** In: device-to-host */
419 	LIBUSB20_ENDPOINT_IN = 0x80,
420 
421 	/** Out: host-to-device */
422 	LIBUSB20_ENDPOINT_OUT = 0x00,
423 };
424 
425 #define	LIBUSB20_TRANSFER_TYPE_MASK	0x03	/* in bmAttributes */
426 
427 /** \ingroup desc
428  * Endpoint transfer type. Values for bits 0:1 of the
429  * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "endpoint attributes" field.
430  */
431 enum libusb20_transfer_type {
432 	/** Control endpoint */
433 	LIBUSB20_TRANSFER_TYPE_CONTROL = 0,
434 
435 	/** Isochronous endpoint */
436 	LIBUSB20_TRANSFER_TYPE_ISOCHRONOUS = 1,
437 
438 	/** Bulk endpoint */
439 	LIBUSB20_TRANSFER_TYPE_BULK = 2,
440 
441 	/** Interrupt endpoint */
442 	LIBUSB20_TRANSFER_TYPE_INTERRUPT = 3,
443 };
444 
445 /** \ingroup misc
446  * Standard requests, as defined in table 9-3 of the USB2 specifications */
447 enum libusb20_standard_request {
448 	/** Request status of the specific recipient */
449 	LIBUSB20_REQUEST_GET_STATUS = 0x00,
450 
451 	/** Clear or disable a specific feature */
452 	LIBUSB20_REQUEST_CLEAR_FEATURE = 0x01,
453 
454 	/* 0x02 is reserved */
455 
456 	/** Set or enable a specific feature */
457 	LIBUSB20_REQUEST_SET_FEATURE = 0x03,
458 
459 	/* 0x04 is reserved */
460 
461 	/** Set device address for all future accesses */
462 	LIBUSB20_REQUEST_SET_ADDRESS = 0x05,
463 
464 	/** Get the specified descriptor */
465 	LIBUSB20_REQUEST_GET_DESCRIPTOR = 0x06,
466 
467 	/** Used to update existing descriptors or add new descriptors */
468 	LIBUSB20_REQUEST_SET_DESCRIPTOR = 0x07,
469 
470 	/** Get the current device configuration value */
471 	LIBUSB20_REQUEST_GET_CONFIGURATION = 0x08,
472 
473 	/** Set device configuration */
474 	LIBUSB20_REQUEST_SET_CONFIGURATION = 0x09,
475 
476 	/** Return the selected alternate setting for the specified
477 	 * interface */
478 	LIBUSB20_REQUEST_GET_INTERFACE = 0x0A,
479 
480 	/** Select an alternate interface for the specified interface */
481 	LIBUSB20_REQUEST_SET_INTERFACE = 0x0B,
482 
483 	/** Set then report an endpoint's synchronization frame */
484 	LIBUSB20_REQUEST_SYNCH_FRAME = 0x0C,
485 
486 	/** Set U1 and U2 system exit latency */
487 	LIBUSB20_REQUEST_SET_SEL = 0x30,
488 
489 	/** Set isochronous delay */
490 	LIBUSB20_REQUEST_SET_ISOCH_DELAY = 0x31,
491 };
492 
493 /** \ingroup misc
494  * Request type bits of the
495  * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in
496  * control transfers. */
497 enum libusb20_request_type {
498 	/** Standard */
499 	LIBUSB20_REQUEST_TYPE_STANDARD = (0x00 << 5),
500 
501 	/** Class */
502 	LIBUSB20_REQUEST_TYPE_CLASS = (0x01 << 5),
503 
504 	/** Vendor */
505 	LIBUSB20_REQUEST_TYPE_VENDOR = (0x02 << 5),
506 
507 	/** Reserved */
508 	LIBUSB20_REQUEST_TYPE_RESERVED = (0x03 << 5),
509 };
510 
511 /** \ingroup misc
512  * Recipient bits of the
513  * \ref libusb20_control_setup::bmRequestType "bmRequestType" field in
514  * control transfers. Values 4 through 31 are reserved. */
515 enum libusb20_request_recipient {
516 	/** Device */
517 	LIBUSB20_RECIPIENT_DEVICE = 0x00,
518 
519 	/** Interface */
520 	LIBUSB20_RECIPIENT_INTERFACE = 0x01,
521 
522 	/** Endpoint */
523 	LIBUSB20_RECIPIENT_ENDPOINT = 0x02,
524 
525 	/** Other */
526 	LIBUSB20_RECIPIENT_OTHER = 0x03,
527 };
528 
529 #define	LIBUSB20_ISO_SYNC_TYPE_MASK		0x0C
530 
531 /** \ingroup desc
532  * Synchronization type for isochronous endpoints. Values for bits 2:3
533  * of the \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes"
534  * field in LIBUSB20_ENDPOINT_DESC.
535  */
536 enum libusb20_iso_sync_type {
537 	/** No synchronization */
538 	LIBUSB20_ISO_SYNC_TYPE_NONE = 0,
539 
540 	/** Asynchronous */
541 	LIBUSB20_ISO_SYNC_TYPE_ASYNC = 1,
542 
543 	/** Adaptive */
544 	LIBUSB20_ISO_SYNC_TYPE_ADAPTIVE = 2,
545 
546 	/** Synchronous */
547 	LIBUSB20_ISO_SYNC_TYPE_SYNC = 3,
548 };
549 
550 #define	LIBUSB20_ISO_USAGE_TYPE_MASK 0x30
551 
552 /** \ingroup desc
553  * Usage type for isochronous endpoints. Values for bits 4:5 of the
554  * \ref LIBUSB20_ENDPOINT_DESC::bmAttributes "bmAttributes" field in
555  * LIBUSB20_ENDPOINT_DESC.
556  */
557 enum libusb20_iso_usage_type {
558 	/** Data endpoint */
559 	LIBUSB20_ISO_USAGE_TYPE_DATA = 0,
560 
561 	/** Feedback endpoint */
562 	LIBUSB20_ISO_USAGE_TYPE_FEEDBACK = 1,
563 
564 	/** Implicit feedback Data endpoint */
565 	LIBUSB20_ISO_USAGE_TYPE_IMPLICIT = 2,
566 };
567 
568 struct libusb20_endpoint {
569 	struct LIBUSB20_ENDPOINT_DESC_DECODED desc;
570 	struct libusb20_me_struct extra;
571 } __aligned(sizeof(void *));
572 
573 struct libusb20_interface {
574 	struct LIBUSB20_INTERFACE_DESC_DECODED desc;
575 	struct libusb20_me_struct extra;
576 	struct libusb20_interface *altsetting;
577 	struct libusb20_endpoint *endpoints;
578 	uint8_t	num_altsetting;
579 	uint8_t	num_endpoints;
580 } __aligned(sizeof(void *));
581 
582 struct libusb20_config {
583 	struct LIBUSB20_CONFIG_DESC_DECODED desc;
584 	struct libusb20_me_struct extra;
585 	struct libusb20_interface *interface;
586 	uint8_t	num_interface;
587 } __aligned(sizeof(void *));
588 
589 uint8_t	libusb20_me_get_1(const struct libusb20_me_struct *ie, uint16_t offset);
590 uint16_t libusb20_me_get_2(const struct libusb20_me_struct *ie, uint16_t offset);
591 uint16_t libusb20_me_encode(void *ptr, uint16_t len, const void *pd);
592 uint16_t libusb20_me_decode(const void *ptr, uint16_t len, void *pd);
593 const uint8_t *libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, const uint8_t *psubdesc);
594 struct libusb20_config *libusb20_parse_config_desc(const void *config_desc);
595 
596 #if 0
597 {					/* style */
598 #endif
599 #ifdef __cplusplus
600 }
601 
602 #endif
603 
604 #endif					/* _LIBUSB20_DESC_H_ */
605