NetBurner 3.5.6
PDF Version
usb_desc.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#ifndef __USB_DESC_H
6#define __USB_DESC_H
7#include <predef.h>
8#include <stdint.h>
9#include <basictypes.h>
10#include <usb_langid.h>
11
12enum class eDesc_t : uint8_t {
13 eDesc_Dev = 0x01, // Device Descriptor
14 eDesc_Cfg = 0x02, // Configuration Descriptor
15 eDesc_Str = 0x03, // String Descriptor
16 eDesc_Intf = 0x04, // Interface Descriptor
17 eDesc_EndPt = 0x05, // Endpoint Descriptor
18 eDesc_DevQual = 0x06, // Device Qualifier Descriptor
19 eDesc_Other_Spd_Cfg = 0x07, // Other Speed Configuration Descriptor
20 eDesc_IntfPwr = 0x08, // Interface Power Descriptor
21 eDesc_OTG = 0x09, // On-the-go Descriptor
22 eDesc_Debug = 0x0A, // Debug Descriptor
23 eDesc_IntfAssoc = 0x0B, // Interface Association Descriptor
24 eDesc_CS_Intf = 0x24, // CDC Function Interface Descriptor
25 eDesc_CS_EndPt = 0x25, // CDC Function Endpoint Descriptor
26};
27
28enum class eDevClassID_t : uint8_t {
29 eClassID_UseIntf = 0x00, // Only allowed for Device descriptor
30 eClassID_CDC = 0x02, // Communication Device Class
31 eClassID_HUB = 0x09, // USB Hub Device
32 eClassID_BillBoard = 0x11, // Billboard Device
33 eClassID_Diagnostic = 0xDC, // Diagnostic (Debug) Device
34 eClassID_Misc = 0xEF, // Miscellaneous Device
35 eClassID_Vendor = 0xFF // Vendor Defined
36};
37
38
39enum class eClassID_t : uint8_t {
40 eClassID_Audio = 0x01, // Audio Device
41 eClassID_CDC = 0x02, // Communication Device Class
42 eClassID_HID = 0x03, // Human Interface Device
43 eClassID_Physical = 0x05, // Physical Device
44 eClassID_StillImage = 0x06, // Still Imaging Device
45 eClassID_LPT = 0x07, // Printer Device
46 eClassID_MSD = 0x08, // Mass Storage Device
47 eClassID_HUB = 0x09, // USB Hub Device
48 eClassID_CDC_Data = 0x0A, // Communication Device Class, Data Interface
49 eClassID_SmartCard = 0x0B, // Smart Card Device
50 eClassID_ContentSec = 0x0C, // Content Security
51 eClassID_Video = 0x0D, // Video Device
52 eClassID_Health = 0x0F, // Personal Healthcare Device
53 eClassID_AVD = 0x10, // Audio/Visual Device
54 eClassID_BillBoard = 0x11, // Billboard Device
55 eClassID_USBC_Bridge = 0x12, // USB-C Bridge Device
56 eClassID_Diagnostic = 0xDC, // Diagnostic (Debug) Device
57 eClassID_Wireless = 0xE0, // Wireless Controller
58 eClassID_Misc = 0xEF, // Miscellaneous Device
59 eClassID_APP = 0xFE, // Application Specific
60 eClassID_Vendor = 0xFF // Vendor Defined
61};
62
63enum class eSubClass_CDC_t : uint8_t {
64 eSubClass_CDC_DLC = 0x01, // Direct Line Control Model [USBPSTN1.2]
65 eSubClass_CDC_ACM = 0x02, // Abstract Control Model [USBPSTN1.2]
66 eSubClass_CDC_PSTN = 0x03, // Telephone Control Model [USBPSTN1.2]
67 eSubClass_CDC_MC = 0x04, // Multi-Channel Control Model [USBISDN1.2]
68 eSubClass_CDC_CAPI = 0x05, // CAPI Control Model [USBISDN1.2]
69 eSubClass_CDC_Eth = 0x06, // Ethernet Networking Control Model [USBECM1.2]
70 eSubClass_CDC_ATM = 0x07, // ATM Networking Control Model [USBATM1.2]
71 eSubClass_CDC_WHS = 0x08, // Wireless Handset Control Model [USBWMC1.1]
72 eSubClass_CDC_Mgmnt = 0x09, // Device Management [USBWMC1.1]
73 eSubClass_CDC_MobDLC = 0x0A, // Mobile Direct Line Model [USBWMC1.1]
74 eSubClass_CDC_OBEX = 0x0B, // OBEX [USBWMC1.1]
75 eSubClass_CDC_EthEmu = 0x0C, // Ethernet Emulation Model [USBEEM1.0]
76 eSubClass_CDC_NetCtl = 0x0D, // Network Control Model [USBNCM1.0]
77};
78
79enum class eProto_CDC_t : uint8_t {
80 eProto_CDC_None = 0x00, // No class specific protocol required
81 eProto_CDC_V250 = 0x01, // ITU-T V.250 AT Commands: V.250 etc
82 eProto_CDC_PCCA = 0x02, // PCCA-101 AT Commands defined by PCCA-101
83 eProto_CDC_PCCA_ANX = 0x03, // PCCA-101 AT Commands defined by PCCA-101 & Annex O
84 eProto_CDC_GSM = 0x04, // GSM 7.07 AT Commands defined by GSM 07.07
85 eProto_CDC_3G = 0x05, // 3GPP 27.07 AT Commands defined by 3GPP 27.007
86 eProto_CDC_CDMA = 0x06, // C-S0017-0 AT Commands defined by TIA for CDMA
87 eProto_CDC_EthEm = 0x07, // USB EEM Ethernet Emulation Model
88 eProto_CDC_Ext = 0xFE, // External Protocol: Commands defined by
89 // Command Set Functional Descriptor
90 eProto_CDC_Vendor = 0xFF, // USB Specification Vendor-specific
91};
92
93enum class eProto_CDCData_t : uint8_t {
94 eProto_CDCData_None = 0x00, // No class specific protocol required
95 eProto_CDCDATA_NetBlock = 0x01, // Network Transfer Block [USBNCM1.0]
96 eProto_CDCDATA_ISDN_BRI = 0x30, // Physical interface protocol for ISDN BRI [I.430]
97 eProto_CDCDATA_HDLC = 0x31, // HDLC [ISO/IEC 3309-1993]
98 eProto_CDCDATA_TRN = 0x32, // Transparent
99 eProto_CDCDATA_Q921_Mgmnt = 0x50, // Management protocol for Q.921 data link protocol [Q.921M]
100 eProto_CDCDATA_Q921_Data = 0x51, // Data link protocol for Q.931 [Q.921]
101 eProto_CDCDATA_Q921_Mplx = 0x52, // TEI-multiplexor for Q.921 data link protocol [Q921TM]
102 eProto_CDCDATA_V42_Cmprss = 0x90, // Data compression procedures [V.42bis]
103 eProto_CDCDATA_EU_ISDN_Ctl = 0x91, // Euro-ISDN protocol control [Q.931/Euro- ISDN]
104 eProto_CDCDATA_V24_ISDN = 0x92, // V.24 rate adaptation to ISDN [V.120]
105 eProto_CDCDATA_CAPI_Cmd = 0x93, // CAPI Commands [CAPI2.0]
106 eProto_CDCDATA_Host_Cfg = 0xFD, // Host based driver. See note in [CDC120-20101103]
107 eProto_CDCDATA_Ext = 0xFE, // External Protocol: Protocol(s) are described
108 // by Protocol Unit Functional Descriptors
109 eProto_CDCDATA_Vendor = 0xFF, // USB Specification Vendor-specific
110};
111
112enum class eSubClass_HID_t : uint8_t {
113 eSubClass_HID_None = 0x00,
114 eSubClass_HID_Boot = 0x01, // Supports a BIOS Boot interface
115};
116
117enum class eProto_HID_t : uint8_t {
118 eProto_HID_None = 0x00,
119 eProto_HID_Keyboard = 0x01, // Keyboard device
120 eProto_HID_Mouse = 0x02, // Mouse device
121};
122
123enum class eSubClass_AVD_t : uint8_t {
124 eSubClass_AVD_Ctl = 0x01, // AVControl Interface
125 eSubClass_AVD_Video = 0x02, // AVData Video Streaming Interface
126 eSubClass_AVD_Audio = 0x03, // AVData Audio Streaming Interface
127};
128
129enum class eProtoHub_t : uint8_t {
130 eProtoHub_FS = 0x00, // Full Speed Hub
131 eProtoHub_TT = 0x01, // High Speed Hub w/ Single Transaction Translator
132 eProtoHub_MutiTT = 0x02, // High Speed Hub w/ Multiple Transaction Translators
133};
134
135enum class eCfgAttr_t : uint8_t {
136 eCfgAttr_RemoteWkup = 0x20, // Supports Remote Wakeup
137 eCfgAttr_SelfPwr = 0x40, // Device is Self Powered
138};
139
140enum class eEndPt_t : uint8_t {
141 eEndPt_Ctl = 0x00, // Control Endpoint
142 eEndPt_Iso = 0x01, // Isochronous Endpoint
143 eEndPt_Bulk = 0x02, // Bulk Transfer Endpoint
144 eEndPt_IRQ = 0x03, // Interrupt Endpoint
145
146 eEndPt_INVALID = 0xFF // Invalid enpoint/not configured
147};
148
149enum class eIsoSync_t : uint8_t {
150 eIsoSync_None = 0x00, // No synchronization
151 eIsoSync_Async = 0x01, // Fully Asynchronous
152 eIsoSync_Adapt = 0x02, // Adaptive Synchronization
153 eIsoSync_Synch = 0x03, // Fully Synchronous
154};
155
156enum class eIsoUsage_t : uint8_t {
157 eIsoUsage_Data = 0x00, // Data endpoint
158 eIsoUsage_Feedback = 0x01, // Feedback endpoint
159 eIsoUsage_Implicit = 0x02, // Implicit Feedback endpoint
160};
161
162/**** USB Descriptor Structs ****/
163
164struct usb_desc_t {
165 uint8_t bLength; // Size of descriptor in bytes
166 uint8_t bDescriptorType; // Type: <descriptor>
167 uint8_t pData[]; // Remainder of the descriptor
168};
169
170struct usb_desc_str_zero_t {
171 uint8_t bLength; // Size of descriptor in bytes
172 uint8_t bDescriptorType; // Type: STRING descriptor, equals eDesc_Str
173 eLangID_t wLangID[]; // Language codes supported by this device
174} __attribute__((packed));
175
176struct usb_desc_str_t {
177 uint8_t bLength; // Size of descriptor in bytes
178 uint8_t bDescriptorType; // Type: STRING descriptor, equals eDesc_Str
179 char16_t bString[]; // UNICODE (UTF-16) encoded string, !!!NOT NULL TERMINATED!!!
180} __attribute__((packed));
181
182/* USB Device Endpoint Descriptor */
183struct usb_endpt_t {
184 uint8_t bLength; // Size of descriptor in bytes
185 uint8_t bDescriptorType; // Type: CONFIGURATION descriptor, equals eDesc_Cfg
186 uint8_t bEndpointAddress; // The addr of the endpt on the Dev described by this descriptor
187 // Bit 3..0: Endpt Number
188 // Bit 6..4: RESERVED
189 // Bit 7: Direction, 0 = OUT endpt, 1 = IN endpt
190 uint8_t bmAttributes; // Endpoint transfer attributes
191 leuint16_t wMaxPacketSize; // Maximum packet size for this enpoint in this configuration
192 // Bit 10..0: Max packet size in bytes
193 // HS ISO/IRQ:
194 // Bit 12..11: number of additional transaction opportunities
195 // per micro-frame
196 // 0x0 = None (1 txn/microframe)
197 // 0x1 = 1 (2 txn/microframe)
198 // 0x2 = 2 (3 txn/microframe)
199 // 0x3 = RESERVED
200 uint8_t bInterval; //Interval for polling transfers. Units: Frame or Micro-frame count
201 // depending on device speed
202 // Valid ranges:
203 // FS/HS ISO: 1-16, bInterval is exponent in count (2^(bInterval-1)),
204 // i.e. bInterval of 4 means period of 8
205 // FS/LS IRQ: 1-255, bInterval is raw period
206 // HS Bulk/Ctl: 0-255, NAK rate. 0 = never NAKs,
207 // otherwise at most 1 NAK per bInterval microframes
208
210 const void *pExtra; // Pointer to extra data
211 uint16_t extraLen; // Size of extra data
212} __attribute__((packed));
213#define USB_DESC_ENDPT_SIZE (7)
214
215/* USB Interface Association Descriptor */
216/* Allows interfaces to be grouped by function */
217struct usb_intf_assoc_t {
218 uint8_t bLength; // Size of descriptor in bytes
219 uint8_t bDescriptorType; // Type: CONFIGURATION descriptor, equals eDesc_Cfg
220 uint8_t bFirstInterface; // Intf number of the First interface associated with this function
221 uint8_t bInterfaceCount; // Number of contiguous interfaces associated with this function
222 uint8_t bFunctionClass; // Class code for this function
223 uint8_t bFunctionSubClass; // Subclass code for this function
224 uint8_t bFunctionProtocol; // Protocol code for this function
225 uint8_t iFunction; // Index of the String Descriptor describing this function
226} __attribute__((packed));
227#define USB_DESC_INTF_ASSOC_SIZE (8)
228
229/* USB Interface Descriptor */
230/* A collections of endpoints used for a function */
231struct usb_intf_t {
232 uint8_t bLength; // Size of descriptor in bytes
233 uint8_t bDescriptorType; // Type: INTERFACE descriptor, equals eDesc_Intf
234 uint8_t bInterfaceNumber; // Zero-based index for this interface in this configuration
235 uint8_t bAlternateSetting; // Value used to select this alternate setting
236 uint8_t bNumEndpoints; // Number of endpoints used by this interface (excluding EP 0)
237 uint8_t bInterfaceClass; // Interface Class Code
238 uint8_t bInterfaceSubClass; // Interface SubClass Code
239 uint8_t bInterfaceProtocol; // Interface Protocol Code
240 uint8_t iInterface; // Index of String Descriptor describing this Interface
241
243 const usb_intf_t *pAltSetting; // Pointer to the next alternate setting for this interface
244 const usb_intf_assoc_t *pIntfAssoc; // Pointer to Interface Association, if first in Assoc
245 const usb_endpt_t *endpt; // Pointer to array of endpoints
246 const void *pExtra; // Pointer to extra data
247 uint16_t extraLen; // Size of extra data
248} __attribute__((packed));
249#define USB_DESC_INTF_SIZE (9)
250
251/* USB Configuration Descriptor */
252/* Logical configuration of the device as a whole */
253struct usb_cfg_t {
254 uint8_t bLength; // Size of descriptor in bytes
255 uint8_t bDescriptorType; // Type: CONFIGURATION descriptor, equals eDesc_Cfg
256 leuint16_t wTotalLength; // Total Length returned for this config:
257 // Includes combined length of *all* descriptors
258 // (cfg, intf, ep, and class- or vendor-specific)
259 uint8_t bNumInterfaces; // Number of interfaces supported by this configuration
260 uint8_t bConfigurationValue; // Argument to SetConfiguration to select this config
261 uint8_t iConfiguration; // Index of the String Descriptor describing this config
262 uint8_t bmAttributes; // Configuration Characteristics
263 uint8_t bMaxPower; // Maximum power consumption from the bus in this configuration
264 // Units: 2mA, (i.e. 50 == 100mA)
266 const usb_intf_t *intf; // Pointer to array of interfaces
267 uint16_t intfLen; // length of 'intf' array
268} __attribute__((packed));
269#define USB_DESC_CFG_SIZE (9)
270
271/* USB Other Speed Configuration Descriptor */
272/* Only relevant if the HighSpeed device has Device Qualifier */
273struct usb_other_spd_t {
274 uint8_t bLength; // Size of descriptor in bytes
275 uint8_t bDescriptorType; // Type: Other_speed_configuration descriptor, equals eDesc_Other_Spd_Cfg
276 leuint16_t wTotalLength; // Total Length returned for this config
277 // Includes combined length of *all* descriptors
278 // (cfg, intf, ep, and class- or vendor-specific)
279 uint8_t bNumInterfaces; // Number of interfaces supported by this configuration
280 uint8_t bConfigurationValue; // Argument to SetConfiguration to select this config
281 uint8_t iConfiguration; // Index of the String Descriptor describing this config
282 uint8_t bmAttributes; // Configuration Characteristics
283 uint8_t bMaxPower; // Maximum power consumption from the bus in this configuration
284 // Units: 2mA, (i.e. 50 == 100mA)
286 const usb_intf_t *intf; // Pointer to array of interfaces
287 void *pExtra; // Pointer to extra data
288 leuint16_t extraLen; // Size of extra data
289} __attribute__((packed));
290#define USB_DESC_OTHER_SPD_SIZE (9)
291
292/* USB Device Qualifier Descriptor */
293/* Per USB 2.0 Specification:
294 * The device_qualifier descriptor describes information about a high-speed
295 * capable device that would change if the device were operating at the other
296 * speed. For example, if the device is currently operating at full-speed,
297 * the device_qualifier returns information about how it would operate at
298 * high-speed and vice-versa.
299 */
300struct usb_dev_qual_t {
301 uint8_t bLength; // Size of descriptor in bytes
302 uint8_t bDescriptorType; // Type: DEVICE QUALIFIER descriptor, equals eDesc_DevQual
303 leuint16_t bcdUSB; // Binary-Coded Decimal USB Specification device is compliant to (2.10 is 0x210)
304 uint8_t bDeviceClass; // Class code for this device
305 uint8_t bDeviceSubClass; // Subclass code for tihs device
306 uint8_t bDeviceProtocol; // Protocol code for this device
307 uint8_t bMaxPacketSize0; // Maximum packet size for EP 0
308 uint8_t bNumConfigurations; // Number of possible Configurations
309 uint8_t bReserved; // Reserved for Future Use, must be Zero
310} __attribute__((packed));
311#define USB_DESC_DEV_QUALIFIER_SIZE (10)
312
313/* USB Device Descriptor */
314/* Overall description of the USB device */
315struct usb_dev_t {
316 uint8_t bLength; // Size of descriptor in bytes
317 uint8_t bDescriptorType; // Type: DEVICE descriptor, equals eDesc_Dev
318 leuint16_t bcdUSB; // Binary-Coded Decimal USB Specification device is compliant to (2.10 is 0x210)
319 uint8_t bDeviceClass; // Class code for this device
320 uint8_t bDeviceSubClass; // Subclass code for tihs device
321 uint8_t bDeviceProtocol; // Protocol code for this device
322 uint8_t bMaxPacketSize0; // Maximum packet size for EP 0
323 leuint16_t idVendor; // Vendor ID (assigned by USB-IF)
324 leuint16_t idProduct; // Product ID (assigned by the manufacturer)
325 leuint16_t bcdDevice; // Device Release number, BCD
326 uint8_t iManufacture; // Index of string descriptor describing: Manufacturer
327 uint8_t iProduct; // Index of string descriptor describing: Prouduct
328 uint8_t iSerialNumber; // Index of string descriptor describing: Serial Number
329 uint8_t bNumConfigurations; // Number of possible Configurations
330} __attribute__((packed));
331#define USB_DESC_DEVICE_SIZE (18)
332
333
334#endif /* ----- #ifndef __USB_DESC_H ----- */
335