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