1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62#ifndef __USBDESCRIPTORS_H__
63#define __USBDESCRIPTORS_H__
64
65#include <asm/types.h>
66
67
68
69
70
71
72
73
74
75#define CLASS_BCD_VERSION 0x0110
76
77
78#define COMMUNICATIONS_DEVICE_CLASS 0x02
79
80
81#define COMMUNICATIONS_INTERFACE_CLASS_CONTROL 0x02
82#define COMMUNICATIONS_INTERFACE_CLASS_DATA 0x0A
83#define COMMUNICATIONS_INTERFACE_CLASS_VENDOR 0x0FF
84
85
86#define COMMUNICATIONS_NO_SUBCLASS 0x00
87#define COMMUNICATIONS_DLCM_SUBCLASS 0x01
88#define COMMUNICATIONS_ACM_SUBCLASS 0x02
89#define COMMUNICATIONS_TCM_SUBCLASS 0x03
90#define COMMUNICATIONS_MCCM_SUBCLASS 0x04
91#define COMMUNICATIONS_CCM_SUBCLASS 0x05
92#define COMMUNICATIONS_ENCM_SUBCLASS 0x06
93#define COMMUNICATIONS_ANCM_SUBCLASS 0x07
94
95
96#define COMMUNICATIONS_WHCM_SUBCLASS 0x08
97#define COMMUNICATIONS_DMM_SUBCLASS 0x09
98#define COMMUNICATIONS_MDLM_SUBCLASS 0x0a
99#define COMMUNICATIONS_OBEX_SUBCLASS 0x0b
100
101
102#define COMMUNICATIONS_NO_PROTOCOL 0x00
103#define COMMUNICATIONS_V25TER_PROTOCOL 0x01
104
105
106#define DATA_INTERFACE_CLASS 0x0a
107
108
109#define DATA_INTERFACE_SUBCLASS_NONE 0x00
110
111
112#define DATA_INTERFACE_PROTOCOL_NONE 0x00
113
114
115
116#define CS_INTERFACE 0x24
117#define CS_ENDPOINT 0x25
118
119
120
121
122
123
124
125
126#define USB_ST_HEADER 0x00
127#define USB_ST_CMF 0x01
128#define USB_ST_ACMF 0x02
129#define USB_ST_DLMF 0x03
130#define USB_ST_TRF 0x04
131#define USB_ST_TCLF 0x05
132#define USB_ST_UF 0x06
133#define USB_ST_CSF 0x07
134#define USB_ST_TOMF 0x08
135#define USB_ST_USBTF 0x09
136#define USB_ST_NCT 0x0a
137#define USB_ST_PUF 0x0b
138#define USB_ST_EUF 0x0c
139#define USB_ST_MCMF 0x0d
140#define USB_ST_CCMF 0x0e
141#define USB_ST_ENF 0x0f
142#define USB_ST_ATMNF 0x10
143
144#define USB_ST_WHCM 0x11
145#define USB_ST_MDLM 0x12
146#define USB_ST_MDLMD 0x13
147#define USB_ST_DMM 0x14
148#define USB_ST_OBEX 0x15
149#define USB_ST_CS 0x16
150#define USB_ST_CSD 0x17
151#define USB_ST_TCM 0x18
152
153
154
155
156
157
158
159
160
161
162
163#define OUT 0x00
164#define IN 0x80
165
166#define CONTROL 0x00
167#define ISOCHRONOUS 0x01
168#define BULK 0x02
169#define INTERRUPT 0x03
170
171
172
173
174#define BMATTRIBUTE_RESERVED 0x80
175#define BMATTRIBUTE_SELF_POWERED 0x40
176
177
178
179
180
181struct usb_endpoint_descriptor {
182 u8 bLength;
183 u8 bDescriptorType;
184 u8 bEndpointAddress;
185 u8 bmAttributes;
186 u16 wMaxPacketSize;
187 u8 bInterval;
188} __attribute__ ((packed));
189
190struct usb_interface_descriptor {
191 u8 bLength;
192 u8 bDescriptorType;
193 u8 bInterfaceNumber;
194 u8 bAlternateSetting;
195 u8 bNumEndpoints;
196 u8 bInterfaceClass;
197 u8 bInterfaceSubClass;
198 u8 bInterfaceProtocol;
199 u8 iInterface;
200} __attribute__ ((packed));
201
202struct usb_configuration_descriptor {
203 u8 bLength;
204 u8 bDescriptorType;
205 u16 wTotalLength;
206 u8 bNumInterfaces;
207 u8 bConfigurationValue;
208 u8 iConfiguration;
209 u8 bmAttributes;
210 u8 bMaxPower;
211} __attribute__ ((packed));
212
213struct usb_device_descriptor {
214 u8 bLength;
215 u8 bDescriptorType;
216 u16 bcdUSB;
217 u8 bDeviceClass;
218 u8 bDeviceSubClass;
219 u8 bDeviceProtocol;
220 u8 bMaxPacketSize0;
221 u16 idVendor;
222 u16 idProduct;
223 u16 bcdDevice;
224 u8 iManufacturer;
225 u8 iProduct;
226 u8 iSerialNumber;
227 u8 bNumConfigurations;
228} __attribute__ ((packed));
229
230#if defined(CONFIG_USBD_HS)
231struct usb_qualifier_descriptor {
232 u8 bLength;
233 u8 bDescriptorType;
234
235 u16 bcdUSB;
236 u8 bDeviceClass;
237 u8 bDeviceSubClass;
238 u8 bDeviceProtocol;
239 u8 bMaxPacketSize0;
240 u8 bNumConfigurations;
241 u8 breserved;
242} __attribute__ ((packed));
243#endif
244
245struct usb_string_descriptor {
246 u8 bLength;
247 u8 bDescriptorType;
248 u16 wData[0];
249} __attribute__ ((packed));
250
251struct usb_generic_descriptor {
252 u8 bLength;
253 u8 bDescriptorType;
254 u8 bDescriptorSubtype;
255} __attribute__ ((packed));
256
257
258
259
260
261
262
263
264struct usb_class_function_descriptor {
265 u8 bFunctionLength;
266 u8 bDescriptorType;
267 u8 bDescriptorSubtype;
268} __attribute__ ((packed));
269
270struct usb_class_function_descriptor_generic {
271 u8 bFunctionLength;
272 u8 bDescriptorType;
273 u8 bDescriptorSubtype;
274 u8 bmCapabilities;
275} __attribute__ ((packed));
276
277struct usb_class_header_function_descriptor {
278 u8 bFunctionLength;
279 u8 bDescriptorType;
280 u8 bDescriptorSubtype;
281 u16 bcdCDC;
282} __attribute__ ((packed));
283
284struct usb_class_call_management_descriptor {
285 u8 bFunctionLength;
286 u8 bDescriptorType;
287 u8 bDescriptorSubtype;
288 u8 bmCapabilities;
289 u8 bDataInterface;
290} __attribute__ ((packed));
291
292struct usb_class_abstract_control_descriptor {
293 u8 bFunctionLength;
294 u8 bDescriptorType;
295 u8 bDescriptorSubtype;
296 u8 bmCapabilities;
297} __attribute__ ((packed));
298
299struct usb_class_direct_line_descriptor {
300 u8 bFunctionLength;
301 u8 bDescriptorType;
302 u8 bDescriptorSubtype;
303} __attribute__ ((packed));
304
305struct usb_class_telephone_ringer_descriptor {
306 u8 bFunctionLength;
307 u8 bDescriptorType;
308 u8 bDescriptorSubtype;
309 u8 bRingerVolSeps;
310 u8 bNumRingerPatterns;
311} __attribute__ ((packed));
312
313struct usb_class_telephone_call_descriptor {
314 u8 bFunctionLength;
315 u8 bDescriptorType;
316 u8 bDescriptorSubtype;
317 u8 bmCapabilities;
318} __attribute__ ((packed));
319
320struct usb_class_union_function_descriptor {
321 u8 bFunctionLength;
322 u8 bDescriptorType;
323 u8 bDescriptorSubtype;
324 u8 bMasterInterface;
325
326 u8 bSlaveInterface0;
327} __attribute__ ((packed));
328
329struct usb_class_country_selection_descriptor {
330 u8 bFunctionLength;
331 u8 bDescriptorType;
332 u8 bDescriptorSubtype;
333 u8 iCountryCodeRelDate;
334 u16 wCountryCode0[0];
335} __attribute__ ((packed));
336
337
338struct usb_class_telephone_operational_descriptor {
339 u8 bFunctionLength;
340 u8 bDescriptorType;
341 u8 bDescriptorSubtype;
342 u8 bmCapabilities;
343} __attribute__ ((packed));
344
345
346struct usb_class_usb_terminal_descriptor {
347 u8 bFunctionLength;
348 u8 bDescriptorType;
349 u8 bDescriptorSubtype;
350 u8 bEntityId;
351 u8 bInterfaceNo;
352 u8 bOutInterfaceNo;
353 u8 bmOptions;
354 u8 bChild0[0];
355} __attribute__ ((packed));
356
357struct usb_class_network_channel_descriptor {
358 u8 bFunctionLength;
359 u8 bDescriptorType;
360 u8 bDescriptorSubtype;
361 u8 bEntityId;
362 u8 iName;
363 u8 bChannelIndex;
364 u8 bPhysicalInterface;
365} __attribute__ ((packed));
366
367struct usb_class_protocol_unit_function_descriptor {
368 u8 bFunctionLength;
369 u8 bDescriptorType;
370 u8 bDescriptorSubtype;
371 u8 bEntityId;
372 u8 bProtocol;
373 u8 bChild0[0];
374} __attribute__ ((packed));
375
376struct usb_class_extension_unit_descriptor {
377 u8 bFunctionLength;
378 u8 bDescriptorType;
379 u8 bDescriptorSubtype;
380 u8 bEntityId;
381 u8 bExtensionCode;
382 u8 iName;
383 u8 bChild0[0];
384} __attribute__ ((packed));
385
386struct usb_class_multi_channel_descriptor {
387 u8 bFunctionLength;
388 u8 bDescriptorType;
389 u8 bDescriptorSubtype;
390 u8 bmCapabilities;
391} __attribute__ ((packed));
392
393struct usb_class_capi_control_descriptor {
394 u8 bFunctionLength;
395 u8 bDescriptorType;
396 u8 bDescriptorSubtype;
397 u8 bmCapabilities;
398} __attribute__ ((packed));
399
400struct usb_class_ethernet_networking_descriptor {
401 u8 bFunctionLength;
402 u8 bDescriptorType;
403 u8 bDescriptorSubtype;
404 u8 iMACAddress;
405 u32 bmEthernetStatistics;
406 u16 wMaxSegmentSize;
407 u16 wNumberMCFilters;
408 u8 bNumberPowerFilters;
409} __attribute__ ((packed));
410
411struct usb_class_atm_networking_descriptor {
412 u8 bFunctionLength;
413 u8 bDescriptorType;
414 u8 bDescriptorSubtype;
415 u8 iEndSystermIdentifier;
416 u8 bmDataCapabilities;
417 u8 bmATMDeviceStatistics;
418 u16 wType2MaxSegmentSize;
419 u16 wType3MaxSegmentSize;
420 u16 wMaxVC;
421} __attribute__ ((packed));
422
423
424struct usb_class_mdlm_descriptor {
425 u8 bFunctionLength;
426 u8 bDescriptorType;
427 u8 bDescriptorSubtype;
428 u16 bcdVersion;
429 u8 bGUID[16];
430} __attribute__ ((packed));
431
432struct usb_class_mdlmd_descriptor {
433 u8 bFunctionLength;
434 u8 bDescriptorType;
435 u8 bDescriptorSubtype;
436 u8 bGuidDescriptorType;
437 u8 bDetailData[0];
438
439} __attribute__ ((packed));
440
441
442
443
444
445
446
447struct usb_class_hid_descriptor {
448 u8 bLength;
449 u8 bDescriptorType;
450 u16 bcdCDC;
451 u8 bCountryCode;
452 u8 bNumDescriptors;
453 u8 bDescriptorType0;
454 u16 wDescriptorLength0;
455
456} __attribute__((packed));
457
458struct usb_class_report_descriptor {
459 u8 bLength;
460 u8 bDescriptorType;
461 u16 wLength;
462 u8 bData[0];
463} __attribute__((packed));
464
465
466
467
468
469struct usb_descriptor {
470 union {
471 struct usb_generic_descriptor generic;
472 struct usb_endpoint_descriptor endpoint;
473 struct usb_interface_descriptor interface;
474 struct usb_configuration_descriptor configuration;
475 struct usb_device_descriptor device;
476 struct usb_string_descriptor string;
477 } descriptor;
478
479} __attribute__ ((packed));
480
481struct usb_class_descriptor {
482 union {
483 struct usb_class_function_descriptor function;
484 struct usb_class_function_descriptor_generic generic;
485 struct usb_class_header_function_descriptor header_function;
486 struct usb_class_call_management_descriptor call_management;
487 struct usb_class_abstract_control_descriptor abstract_control;
488 struct usb_class_direct_line_descriptor direct_line;
489 struct usb_class_telephone_ringer_descriptor telephone_ringer;
490 struct usb_class_telephone_operational_descriptor telephone_operational;
491 struct usb_class_telephone_call_descriptor telephone_call;
492 struct usb_class_union_function_descriptor union_function;
493 struct usb_class_country_selection_descriptor country_selection;
494 struct usb_class_usb_terminal_descriptor usb_terminal;
495 struct usb_class_network_channel_descriptor network_channel;
496 struct usb_class_extension_unit_descriptor extension_unit;
497 struct usb_class_multi_channel_descriptor multi_channel;
498 struct usb_class_capi_control_descriptor capi_control;
499 struct usb_class_ethernet_networking_descriptor ethernet_networking;
500 struct usb_class_atm_networking_descriptor atm_networking;
501 struct usb_class_mdlm_descriptor mobile_direct;
502 struct usb_class_mdlmd_descriptor mobile_direct_detail;
503 struct usb_class_hid_descriptor hid;
504 } descriptor;
505
506} __attribute__ ((packed));
507
508#ifdef DEBUG
509static inline void print_device_descriptor(struct usb_device_descriptor *d)
510{
511 serial_printf("usb device descriptor \n");
512 serial_printf("\tbLength %2.2x\n", d->bLength);
513 serial_printf("\tbDescriptorType %2.2x\n", d->bDescriptorType);
514 serial_printf("\tbcdUSB %4.4x\n", d->bcdUSB);
515 serial_printf("\tbDeviceClass %2.2x\n", d->bDeviceClass);
516 serial_printf("\tbDeviceSubClass %2.2x\n", d->bDeviceSubClass);
517 serial_printf("\tbDeviceProtocol %2.2x\n", d->bDeviceProtocol);
518 serial_printf("\tbMaxPacketSize0 %2.2x\n", d->bMaxPacketSize0);
519 serial_printf("\tidVendor %4.4x\n", d->idVendor);
520 serial_printf("\tidProduct %4.4x\n", d->idProduct);
521 serial_printf("\tbcdDevice %4.4x\n", d->bcdDevice);
522 serial_printf("\tiManufacturer %2.2x\n", d->iManufacturer);
523 serial_printf("\tiProduct %2.2x\n", d->iProduct);
524 serial_printf("\tiSerialNumber %2.2x\n", d->iSerialNumber);
525 serial_printf("\tbNumConfigurations %2.2x\n", d->bNumConfigurations);
526}
527
528#else
529
530
531#define print_device_descriptor(d)
532
533#endif
534#endif
535