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