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