1 | /*
|
---|
2 | * Copyright (c) 2010 Vojtech Horky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libusb usb
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief Standard USB descriptors.
|
---|
34 | */
|
---|
35 | #ifndef LIBUSB_DESCRIPTOR_H_
|
---|
36 | #define LIBUSB_DESCRIPTOR_H_
|
---|
37 |
|
---|
38 | #include <ipc/ipc.h>
|
---|
39 | #include <async.h>
|
---|
40 |
|
---|
41 | /** Descriptor type. */
|
---|
42 | typedef enum {
|
---|
43 | USB_DESCTYPE_DEVICE = 1,
|
---|
44 | USB_DESCTYPE_CONFIGURATION = 2,
|
---|
45 | USB_DESCTYPE_STRING = 3,
|
---|
46 | USB_DESCTYPE_INTERFACE = 4,
|
---|
47 | USB_DESCTYPE_ENDPOINT = 5
|
---|
48 | } usb_descriptor_type_t;
|
---|
49 |
|
---|
50 | /** Standard USB device descriptor.
|
---|
51 | */
|
---|
52 | typedef struct {
|
---|
53 | /** Size of this descriptor in bytes. */
|
---|
54 | uint8_t length;
|
---|
55 | /** Descriptor type (USB_DESCTYPE_DEVICE). */
|
---|
56 | uint8_t descriptor_type;
|
---|
57 | /** USB specification release number.
|
---|
58 | * The number shall be coded as binary-coded decimal (BCD).
|
---|
59 | */
|
---|
60 | uint16_t usb_spec_version;
|
---|
61 | /** Device class. */
|
---|
62 | uint8_t device_class;
|
---|
63 | /** Device sub-class. */
|
---|
64 | uint8_t device_subclass;
|
---|
65 | /** Device protocol. */
|
---|
66 | uint8_t device_protocol;
|
---|
67 | /** Maximum packet size for endpoint zero.
|
---|
68 | * Valid values are only 8, 16, 32, 64).
|
---|
69 | */
|
---|
70 | uint8_t max_packet_size;
|
---|
71 | /** Vendor ID. */
|
---|
72 | uint16_t vendor_id;
|
---|
73 | /** Product ID. */
|
---|
74 | uint16_t product_id;
|
---|
75 | /** Device release number (in BCD). */
|
---|
76 | uint16_t device_version;
|
---|
77 | /** Manufacturer descriptor index. */
|
---|
78 | uint8_t str_manufacturer;
|
---|
79 | /** Product descriptor index. */
|
---|
80 | uint8_t str_product;
|
---|
81 | /** Device serial number desriptor index. */
|
---|
82 | uint8_t str_serial_number;
|
---|
83 | /** Number of possible configurations. */
|
---|
84 | uint8_t configuration_count;
|
---|
85 | } __attribute__ ((packed)) usb_standard_device_descriptor_t;
|
---|
86 |
|
---|
87 | /** Standard USB configuration descriptor.
|
---|
88 | */
|
---|
89 | typedef struct {
|
---|
90 | /** Size of this descriptor in bytes. */
|
---|
91 | uint8_t length;
|
---|
92 | /** Descriptor type (USB_DESCTYPE_CONFIGURATION). */
|
---|
93 | uint8_t descriptor_type;
|
---|
94 | /** Total length of all data of this configuration.
|
---|
95 | * This includes the combined length of all descriptors
|
---|
96 | * (configuration, interface, endpoint, class-specific and
|
---|
97 | * vendor-specific) valid for this configuration.
|
---|
98 | */
|
---|
99 | uint16_t total_length;
|
---|
100 | /** Number of possible interfaces under this configuration. */
|
---|
101 | uint8_t interface_count;
|
---|
102 | /** Configuration value used when setting this configuration. */
|
---|
103 | uint8_t configuration_number;
|
---|
104 | /** String descriptor describing this configuration. */
|
---|
105 | uint8_t str_configuration;
|
---|
106 | /** Attribute bitmap. */
|
---|
107 | uint8_t attributes;
|
---|
108 | /** Maximum power consumption from the USB under this configuration.
|
---|
109 | * Expressed in 2mA unit (e.g. 50 ~ 100mA).
|
---|
110 | */
|
---|
111 | uint8_t max_power;
|
---|
112 | } __attribute__ ((packed)) usb_standard_configuration_descriptor_t;
|
---|
113 |
|
---|
114 | /** Standard USB interface descriptor.
|
---|
115 | */
|
---|
116 | typedef struct {
|
---|
117 | /** Size of this descriptor in bytes. */
|
---|
118 | uint8_t length;
|
---|
119 | /** Descriptor type (USB_DESCTYPE_INTERFACE). */
|
---|
120 | uint8_t descriptor_type;
|
---|
121 | /** Number of interface.
|
---|
122 | * Zero-based index into array of interfaces for current configuration.
|
---|
123 | */
|
---|
124 | uint8_t interface_number;
|
---|
125 | /** Alternate setting for value in interface_number. */
|
---|
126 | uint8_t alternate_setting;
|
---|
127 | /** Number of endpoints used by this interface.
|
---|
128 | * This number must exclude usage of endpoint zero
|
---|
129 | * (default control pipe).
|
---|
130 | */
|
---|
131 | uint8_t endpoint_count;
|
---|
132 | /** Class code. */
|
---|
133 | uint8_t interface_class;
|
---|
134 | /** Subclass code. */
|
---|
135 | uint8_t interface_subclass;
|
---|
136 | /** Protocol code. */
|
---|
137 | uint8_t interface_protocol;
|
---|
138 | /** String descriptor describing this interface. */
|
---|
139 | uint8_t str_interface;
|
---|
140 | } __attribute__ ((packed)) usb_standard_interface_descriptor_t;
|
---|
141 |
|
---|
142 | /** Standard USB endpoint descriptor.
|
---|
143 | */
|
---|
144 | typedef struct {
|
---|
145 | /** Size of this descriptor in bytes. */
|
---|
146 | uint8_t length;
|
---|
147 | /** Descriptor type (USB_DESCTYPE_ENDPOINT). */
|
---|
148 | uint8_t descriptor_type;
|
---|
149 | /** Endpoint address together with data flow direction. */
|
---|
150 | uint8_t endpoint_address;
|
---|
151 | /** Endpoint attributes.
|
---|
152 | * Includes transfer type (usb_transfer_type_t).
|
---|
153 | */
|
---|
154 | uint8_t attributes;
|
---|
155 | /** Maximum packet size. */
|
---|
156 | uint16_t max_packet_size;
|
---|
157 | /** Polling interval in milliseconds.
|
---|
158 | * Ignored for bulk and control endpoints.
|
---|
159 | * Isochronous endpoints must use value 1.
|
---|
160 | * Interrupt endpoints any value from 1 to 255.
|
---|
161 | */
|
---|
162 | uint8_t poll_interval;
|
---|
163 | } __attribute__ ((packed)) usb_standard_endpoint_descriptor_t;
|
---|
164 |
|
---|
165 |
|
---|
166 | /* TODO: string descriptors. */
|
---|
167 |
|
---|
168 | #endif
|
---|
169 | /**
|
---|
170 | * @}
|
---|
171 | */
|
---|