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