libusb20_desc.h revision 277847
172339Sabial/* $FreeBSD: stable/10/lib/libusb/libusb20_desc.h 277847 2015-01-28 19:49:53Z hselasky $ */
272339Sabial/*-
372339Sabial * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
472339Sabial * Copyright (c) 2007-2008 Daniel Drake.  All rights reserved.
572339Sabial * Copyright (c) 2001 Johannes Erdfelt.  All rights reserved.
672339Sabial *
772339Sabial * Redistribution and use in source and binary forms, with or without
872339Sabial * modification, are permitted provided that the following conditions
972339Sabial * are met:
1072339Sabial * 1. Redistributions of source code must retain the above copyright
1172339Sabial *    notice, this list of conditions and the following disclaimer.
1272339Sabial * 2. Redistributions in binary form must reproduce the above copyright
1372339Sabial *    notice, this list of conditions and the following disclaimer in the
1472339Sabial *    documentation and/or other materials provided with the distribution.
1572339Sabial *
1672339Sabial * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1772339Sabial * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1872339Sabial * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1972339Sabial * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2072339Sabial * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2172339Sabial * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2272339Sabial * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2372339Sabial * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2472339Sabial * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2572339Sabial * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2672339Sabial * SUCH DAMAGE.
2772339Sabial */
2872339Sabial
2972339Sabial/*
3072339Sabial * NOTE: This file contains the definition of some standard USB
3172339Sabial * structures. All structures which name ends by *DECODED use host byte
3272339Sabial * order.
3372339Sabial */
3472339Sabial
3572339Sabial/*
3672339Sabial * NOTE: This file uses a lot of macros. If you want to see what the
3772339Sabial * macros become when they are expanded then run the following
3872339Sabial * commands from your shell:
3972339Sabial *
4072339Sabial * cpp libusb20_desc.h > temp.h
4172339Sabial * indent temp.h
4272339Sabial * less temp.h
4372339Sabial */
4472339Sabial
4572339Sabial#ifndef _LIBUSB20_DESC_H_
4672339Sabial#define	_LIBUSB20_DESC_H_
4772339Sabial
4872339Sabial#ifndef LIBUSB_GLOBAL_INCLUDE_FILE
4972339Sabial#include <stdint.h>
5072339Sabial#endif
5172339Sabial
5272339Sabial#ifdef __cplusplus
5372339Sabialextern	"C" {
5472339Sabial#endif
5572339Sabial#if 0
5672339Sabial};					/* style */
5772339Sabial
5872339Sabial#endif
5972339Sabial/* basic macros */
6072339Sabial
6172339Sabial#define	LIBUSB20__NOT(...) __VA_ARGS__
6272339Sabial#define	LIBUSB20_NOT(arg) LIBUSB20__NOT(LIBUSB20_YES arg(() LIBUSB20_NO))
6372339Sabial#define	LIBUSB20_YES(...) __VA_ARGS__
6472339Sabial#define	LIBUSB20_NO(...)
6572339Sabial#define	LIBUSB20_END(...) __VA_ARGS__
6672339Sabial#define	LIBUSB20_MAX(a,b) (((a) > (b)) ? (a) : (b))
6772339Sabial#define	LIBUSB20_MIN(a,b) (((a) < (b)) ? (a) : (b))
6872339Sabial
6972339Sabial#define	LIBUSB20_ADD_BYTES(ptr,off) \
7072339Sabial  ((void *)(((const uint8_t *)(ptr)) + (off) - ((const uint8_t *)0)))
7172339Sabial
7272339Sabial/* basic message elements */
7372339Sabialenum {
7472339Sabial	LIBUSB20_ME_INT8,
7572339Sabial	LIBUSB20_ME_INT16,
7672339Sabial	LIBUSB20_ME_INT32,
7772339Sabial	LIBUSB20_ME_INT64,
7872339Sabial	LIBUSB20_ME_STRUCT,
7972339Sabial	LIBUSB20_ME_MAX,		/* used to indicate end */
8072339Sabial};
8172339Sabial
8272339Sabial/* basic message element modifiers */
8372339Sabialenum {
8472339Sabial	LIBUSB20_ME_IS_UNSIGNED = 0x00,
8572339Sabial	LIBUSB20_ME_IS_SIGNED = 0x80,
8672339Sabial	LIBUSB20_ME_MASK = 0x7F,
8772339Sabial};
8872339Sabial
8972339Sabialenum {
9072339Sabial	LIBUSB20_ME_IS_RAW,		/* structure excludes length field
9172339Sabial					 * (hardcoded value) */
9272339Sabial	LIBUSB20_ME_IS_ENCODED,		/* structure includes length field */
9372339Sabial	LIBUSB20_ME_IS_EMPTY,		/* no structure */
9472339Sabial	LIBUSB20_ME_IS_DECODED,		/* structure is recursive */
9572339Sabial};
9672339Sabial
9772339Sabial/* basic helper structures and macros */
9872339Sabial
9972339Sabial#define	LIBUSB20_ME_STRUCT_ALIGN sizeof(void *)
10072339Sabial
10172339Sabialstruct libusb20_me_struct {
10272339Sabial	void   *ptr;			/* data pointer */
10372339Sabial	uint16_t len;			/* defaults to zero */
10472339Sabial	uint16_t type;			/* defaults to LIBUSB20_ME_IS_EMPTY */
10572339Sabial} __aligned(LIBUSB20_ME_STRUCT_ALIGN);
10672339Sabial
10772339Sabialstruct libusb20_me_format {
10872339Sabial	const uint8_t *format;		/* always set */
10972339Sabial	const char *desc;		/* optionally set */
11072339Sabial	const char *fields;		/* optionally set */
11172339Sabial};
11272339Sabial
11372339Sabial#define	LIBUSB20_ME_STRUCT(n, field, arg, ismeta)		\
11472339Sabial  ismeta ( LIBUSB20_ME_STRUCT, 1, 0, )			\
11572339Sabial  LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field; )
11672339Sabial
11772339Sabial#define	LIBUSB20_ME_STRUCT_ARRAY(n, field, arg, ismeta)	\
11872339Sabial  ismeta ( LIBUSB20_ME_STRUCT , (arg) & 0xFF,		\
11972339Sabial	   ((arg) / 0x100) & 0xFF, )			\
12072339Sabial  LIBUSB20_NOT(ismeta) ( struct libusb20_me_struct field [arg]; )
12172339Sabial
12272339Sabial#define	LIBUSB20_ME_INTEGER(n, field, ismeta, un, u, bits, a, size)	\
12372339Sabial  ismeta ( LIBUSB20_ME_INT##bits |					\
12472339Sabial	   LIBUSB20_ME_IS_##un##SIGNED ,				\
12572339Sabial	   (size) & 0xFF, ((size) / 0x100) & 0xFF, )		\
12672339Sabial  LIBUSB20_NOT(ismeta) ( u##int##bits##_t				\
12772339Sabial		    __aligned((bits) / 8) field a; )
12872339Sabial
12972339Sabial#define	LIBUSB20_ME_UINT8_T(n, field, arg, ismeta) \
13072339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, , 1)
13172339Sabial
13272339Sabial#define	LIBUSB20_ME_UINT8_ARRAY_T(n, field, arg, ismeta) \
13372339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 8, [arg], arg)
13472339Sabial
13572339Sabial#define	LIBUSB20_ME_SINT8_T(n, field, arg, ismeta) \
13672339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, , 1)
13772339Sabial
13872339Sabial#define	LIBUSB20_ME_SINT8_ARRAY_T(n, field, arg, ismeta) \
13972339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 8, [arg], arg)
14072339Sabial
14172339Sabial#define	LIBUSB20_ME_UINT16_T(n, field, arg, ismeta) \
14272339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, , 1)
14372339Sabial
14472339Sabial#define	LIBUSB20_ME_UINT16_ARRAY_T(n, field, arg, ismeta) \
14572339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 16, [arg], arg)
14672339Sabial
14772339Sabial#define	LIBUSB20_ME_SINT16_T(n, field, arg, ismeta) \
14872339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, , 1)
14972339Sabial
15072339Sabial#define	LIBUSB20_ME_SINT16_ARRAY_T(n, field, arg, ismeta) \
15172339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 16, [arg], arg)
15272339Sabial
15372339Sabial#define	LIBUSB20_ME_UINT32_T(n, field, arg, ismeta) \
15472339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, , 1)
15572339Sabial
15672339Sabial#define	LIBUSB20_ME_UINT32_ARRAY_T(n, field, arg, ismeta) \
15772339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 32, [arg], arg)
15872339Sabial
15972339Sabial#define	LIBUSB20_ME_SINT32_T(n, field, arg, ismeta) \
16072339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, , 1)
16172339Sabial
16272339Sabial#define	LIBUSB20_ME_SINT32_ARRAY_T(n, field, arg, ismeta) \
16372339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 32, [arg], arg)
16472339Sabial
16572339Sabial#define	LIBUSB20_ME_UINT64_T(n, field, arg, ismeta) \
16672339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, , 1)
16772339Sabial
16872339Sabial#define	LIBUSB20_ME_UINT64_ARRAY_T(n, field, arg, ismeta) \
16972339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta, UN, u, 64, [arg], arg)
17072339Sabial
17172339Sabial#define	LIBUSB20_ME_SINT64_T(n, field, arg, ismeta) \
17272339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, , 1)
17372339Sabial
17472339Sabial#define	LIBUSB20_ME_SINT64_ARRAY_T(n, field, arg, ismeta) \
17572339Sabial  LIBUSB20_ME_INTEGER(n, field, ismeta,,, 64, [arg], arg)
17672339Sabial
17772339Sabial#define	LIBUSB20_MAKE_DECODED_FIELD(n, type, field, arg) \
17872339Sabial  LIBUSB20_ME_##type (n, field, arg, LIBUSB20_NO)
17972339Sabial
18072339Sabial#define	LIBUSB20_MAKE_STRUCT(name)			\
18172339Sabial  extern const struct libusb20_me_format			\
18272339Sabial	 name##_FORMAT[1];				\
18372339Sabial  struct name##_DECODED {				\
18472339Sabial    const struct libusb20_me_format *name##_FORMAT;	\
18572339Sabial    name (LIBUSB20_MAKE_DECODED_FIELD,)			\
18672339Sabial  }
18772339Sabial
18872339Sabial#define	LIBUSB20_MAKE_STRUCT_FORMAT(name)		\
18972339Sabial  const struct libusb20_me_format			\
19072339Sabial    name##_FORMAT[1] = {{			\
19172339Sabial      .format = LIBUSB20_MAKE_FORMAT(name),	\
19272339Sabial      .desc = #name,				\
19372339Sabial      .fields = NULL,				\
19472339Sabial  }}
19572339Sabial
19672339Sabial#define	LIBUSB20_MAKE_FORMAT_SUB(n, type, field, arg) \
19772339Sabial  LIBUSB20_ME_##type (n, field, arg, LIBUSB20_YES)
19872339Sabial
19972339Sabial#define	LIBUSB20_MAKE_FORMAT(what) (const uint8_t []) \
20072339Sabial  { what (LIBUSB20_MAKE_FORMAT_SUB, ) LIBUSB20_ME_MAX, 0, 0 }
20172339Sabial
20272339Sabial#define	LIBUSB20_INIT(what, ptr) do {		\
20372339Sabial    memset(ptr, 0, sizeof(*(ptr)));		\
20472339Sabial    (ptr)->what##_FORMAT = what##_FORMAT;	\
20572339Sabial} while (0)
20672339Sabial
20772339Sabial#define	LIBUSB20_DEVICE_DESC(m,n) \
20872339Sabial  m(n, UINT8_T, bLength, ) \
20972339Sabial  m(n, UINT8_T, bDescriptorType, ) \
21072339Sabial  m(n, UINT16_T, bcdUSB, ) \
21172339Sabial  m(n, UINT8_T, bDeviceClass, ) \
21272339Sabial  m(n, UINT8_T, bDeviceSubClass, ) \
21372339Sabial  m(n, UINT8_T, bDeviceProtocol, ) \
21472339Sabial  m(n, UINT8_T, bMaxPacketSize0, ) \
21572339Sabial  m(n, UINT16_T, idVendor, ) \
21672339Sabial  m(n, UINT16_T, idProduct, ) \
21772339Sabial  m(n, UINT16_T, bcdDevice, ) \
21872339Sabial  m(n, UINT8_T, iManufacturer, ) \
21972339Sabial  m(n, UINT8_T, iProduct, ) \
22072339Sabial  m(n, UINT8_T, iSerialNumber, ) \
22172339Sabial  m(n, UINT8_T, bNumConfigurations, ) \
22272339Sabial
22372339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_DEVICE_DESC);
22472339Sabial
22572339Sabial#define	LIBUSB20_ENDPOINT_DESC(m,n) \
22672339Sabial  m(n, UINT8_T,  bLength, ) \
22772339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
22872339Sabial  m(n, UINT8_T,  bEndpointAddress, ) \
22972339Sabial  m(n, UINT8_T,  bmAttributes, ) \
23072339Sabial  m(n, UINT16_T, wMaxPacketSize, ) \
23172339Sabial  m(n, UINT8_T,  bInterval, ) \
23272339Sabial  m(n, UINT8_T,  bRefresh, ) \
23372339Sabial  m(n, UINT8_T,  bSynchAddress, ) \
23472339Sabial
23572339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_ENDPOINT_DESC);
23672339Sabial
23772339Sabial#define	LIBUSB20_INTERFACE_DESC(m,n) \
23872339Sabial  m(n, UINT8_T,  bLength, ) \
23972339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
24072339Sabial  m(n, UINT8_T,  bInterfaceNumber, ) \
24172339Sabial  m(n, UINT8_T,  bAlternateSetting, ) \
24272339Sabial  m(n, UINT8_T,  bNumEndpoints, ) \
24372339Sabial  m(n, UINT8_T,  bInterfaceClass, ) \
24472339Sabial  m(n, UINT8_T,  bInterfaceSubClass, ) \
24572339Sabial  m(n, UINT8_T,  bInterfaceProtocol, ) \
24672339Sabial  m(n, UINT8_T,  iInterface, ) \
24772339Sabial
24872339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_INTERFACE_DESC);
24972339Sabial
25072339Sabial#define	LIBUSB20_CONFIG_DESC(m,n) \
25172339Sabial  m(n, UINT8_T,  bLength, ) \
25272339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
25372339Sabial  m(n, UINT16_T, wTotalLength, ) \
25472339Sabial  m(n, UINT8_T,  bNumInterfaces, ) \
25572339Sabial  m(n, UINT8_T,  bConfigurationValue, ) \
25672339Sabial  m(n, UINT8_T,  iConfiguration, ) \
25772339Sabial  m(n, UINT8_T,  bmAttributes, ) \
25872339Sabial  m(n, UINT8_T,  bMaxPower, ) \
25972339Sabial
26072339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_CONFIG_DESC);
26172339Sabial
26272339Sabial#define	LIBUSB20_CONTROL_SETUP(m,n) \
26372339Sabial  m(n, UINT8_T,  bmRequestType, ) \
26472339Sabial  m(n, UINT8_T,  bRequest, ) \
26572339Sabial  m(n, UINT16_T, wValue, ) \
26672339Sabial  m(n, UINT16_T, wIndex, ) \
26772339Sabial  m(n, UINT16_T, wLength, ) \
26872339Sabial
26972339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_CONTROL_SETUP);
27072339Sabial
27172339Sabial#define	LIBUSB20_SS_ENDPT_COMP_DESC(m,n) \
27272339Sabial  m(n, UINT8_T,  bLength, ) \
27372339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
27472339Sabial  m(n, UINT8_T,  bMaxBurst, ) \
27572339Sabial  m(n, UINT8_T,  bmAttributes, ) \
27672339Sabial  m(n, UINT16_T, wBytesPerInterval, ) \
27772339Sabial
27872339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_SS_ENDPT_COMP_DESC);
27972339Sabial
28072339Sabial#define	LIBUSB20_USB_20_DEVCAP_DESC(m,n) \
28172339Sabial  m(n, UINT8_T,  bLength, ) \
28272339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
28372339Sabial  m(n, UINT8_T,  bDevCapabilityType, ) \
28472339Sabial  m(n, UINT32_T, bmAttributes, ) \
28572339Sabial
28672339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC);
28772339Sabial
28872339Sabial#define	LIBUSB20_SS_USB_DEVCAP_DESC(m,n) \
28972339Sabial  m(n, UINT8_T,  bLength, ) \
29072339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
29172339Sabial  m(n, UINT8_T,  bDevCapabilityType, ) \
29272339Sabial  m(n, UINT8_T,  bmAttributes, ) \
29372339Sabial  m(n, UINT16_T, wSpeedSupported, ) \
29472339Sabial  m(n, UINT8_T,  bFunctionalitySupport, ) \
29572339Sabial  m(n, UINT8_T,  bU1DevExitLat, ) \
29672339Sabial  m(n, UINT16_T, wU2DevExitLat, ) \
29772339Sabial
29872339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);
29972339Sabial
30072339Sabial#define	LIBUSB20_BOS_DESCRIPTOR(m,n) \
30172339Sabial  m(n, UINT8_T,  bLength, ) \
30272339Sabial  m(n, UINT8_T,  bDescriptorType, ) \
30372339Sabial  m(n, UINT16_T, wTotalLength, ) \
30472339Sabial  m(n, UINT8_T,  bNumDeviceCapabilities, ) \
30572339Sabial
30672339SabialLIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);
30772339Sabial
30872339Sabial/* standard USB stuff */
30972339Sabial
31072339Sabial/** \ingroup desc
31172339Sabial * Device and/or Interface Class codes */
31272339Sabialenum libusb20_class_code {
31372339Sabial	/** In the context of a \ref LIBUSB20_DEVICE_DESC "device
31472339Sabial	 * descriptor", this bDeviceClass value indicates that each
31572339Sabial	 * interface specifies its own class information and all
31672339Sabial	 * interfaces operate independently.
31772339Sabial	 */
31872339Sabial	LIBUSB20_CLASS_PER_INTERFACE = 0,
31972339Sabial
32072339Sabial	/** Audio class */
32172339Sabial	LIBUSB20_CLASS_AUDIO = 1,
32272339Sabial
32372339Sabial	/** Communications class */
32472339Sabial	LIBUSB20_CLASS_COMM = 2,
32572339Sabial
32672339Sabial	/** Human Interface Device class */
32772339Sabial	LIBUSB20_CLASS_HID = 3,
32872339Sabial
32972339Sabial	/** Printer dclass */
33072339Sabial	LIBUSB20_CLASS_PRINTER = 7,
33172339Sabial
33272339Sabial	/** Picture transfer protocol class */
33372339Sabial	LIBUSB20_CLASS_PTP = 6,
33472339Sabial
33572339Sabial	/** Mass storage class */
33672339Sabial	LIBUSB20_CLASS_MASS_STORAGE = 8,
33772339Sabial
33872339Sabial	/** Hub class */
33972339Sabial	LIBUSB20_CLASS_HUB = 9,
34072339Sabial
34172339Sabial	/** Data class */
34272339Sabial	LIBUSB20_CLASS_DATA = 10,
34372339Sabial
34472339Sabial	/** Class is vendor-specific */
34572339Sabial	LIBUSB20_CLASS_VENDOR_SPEC = 0xff,
34672339Sabial};
34772339Sabial
34872339Sabial/** \ingroup desc
34972339Sabial * Descriptor types as defined by the USB specification. */
35072339Sabialenum libusb20_descriptor_type {
35172339Sabial	/** Device descriptor. See LIBUSB20_DEVICE_DESC. */
35272339Sabial	LIBUSB20_DT_DEVICE = 0x01,
35372339Sabial
35472339Sabial	/** Configuration descriptor. See LIBUSB20_CONFIG_DESC. */
35572339Sabial	LIBUSB20_DT_CONFIG = 0x02,
35672339Sabial
35772339Sabial	/** String descriptor */
35872339Sabial	LIBUSB20_DT_STRING = 0x03,
35972339Sabial
36072339Sabial	/** Interface descriptor. See LIBUSB20_INTERFACE_DESC. */
36172339Sabial	LIBUSB20_DT_INTERFACE = 0x04,
36272339Sabial
36372339Sabial	/** Endpoint descriptor. See LIBUSB20_ENDPOINT_DESC. */
36472339Sabial	LIBUSB20_DT_ENDPOINT = 0x05,
36572339Sabial
36672339Sabial	/** HID descriptor */
36772339Sabial	LIBUSB20_DT_HID = 0x21,
36872339Sabial
36972339Sabial	/** HID report descriptor */
37072339Sabial	LIBUSB20_DT_REPORT = 0x22,
37172339Sabial
37272339Sabial	/** Physical descriptor */
37372339Sabial	LIBUSB20_DT_PHYSICAL = 0x23,
37472339Sabial
37572339Sabial	/** Hub descriptor */
37672339Sabial	LIBUSB20_DT_HUB = 0x29,
37772339Sabial
37872339Sabial	/** Binary Object Store, BOS */
37972339Sabial	LIBUSB20_DT_BOS = 0x0f,
38072339Sabial
38172339Sabial	/** Device Capability */
38272339Sabial	LIBUSB20_DT_DEVICE_CAPABILITY = 0x10,
38372339Sabial
38472339Sabial	/** SuperSpeed endpoint companion */
38572339Sabial	LIBUSB20_DT_SS_ENDPOINT_COMPANION = 0x30,
38672339Sabial};
38772339Sabial
38872339Sabial/** \ingroup desc
389 * Device capability types as defined by the USB specification. */
390enum 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 */
416enum 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 */
430enum 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 */
446enum 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. */
496enum 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. */
514enum 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 */
535enum 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 */
556enum 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
567struct libusb20_endpoint {
568	struct LIBUSB20_ENDPOINT_DESC_DECODED desc;
569	struct libusb20_me_struct extra;
570} __aligned(sizeof(void *));
571
572struct 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
581struct 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
588uint8_t	libusb20_me_get_1(const struct libusb20_me_struct *ie, uint16_t offset);
589uint16_t libusb20_me_get_2(const struct libusb20_me_struct *ie, uint16_t offset);
590uint16_t libusb20_me_encode(void *ptr, uint16_t len, const void *pd);
591uint16_t libusb20_me_decode(const void *ptr, uint16_t len, void *pd);
592const uint8_t *libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, const uint8_t *psubdesc);
593struct 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