FreeCalypso > hg > fc-usbser-tools
annotate cp2102/decode_usb_desc.c @ 104:866eae65dbea
LICENSE: same as other FreeCalypso tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 29 Sep 2023 18:20:04 +0000 |
parents | f4a7ac90cf39 |
children |
rev | line source |
---|---|
85
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a CP2102 EEPROM image from an Intel HEX file |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * and decodes the USB descriptors portion thereof. |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "cp210x_defs.h" |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char eeprom[SIZE_EEPROM]; |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
87
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
13 static void |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
14 print_device_desc(desc) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
15 u_char *desc; |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
16 { |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
17 printf(" bLength: %u", desc[0]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
18 if (desc[0] != 18) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
19 fputs(" (WRONG!)", stdout); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
20 putchar('\n'); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
21 printf(" bDescriptorType: 0x%02X", desc[1]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
22 if (desc[1] != 0x01) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
23 fputs(" (WRONG!)", stdout); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
24 putchar('\n'); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
25 printf(" bcdUSB: 0x%02X%02X\n", desc[3], desc[2]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
26 printf(" bDeviceClass: 0x%02X\n", desc[4]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
27 printf(" bDeviceSubClass: 0x%02X\n", desc[5]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
28 printf(" bDeviceProtocol: 0x%02X\n", desc[6]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
29 printf(" bMaxPacketSize0: %u\n", desc[7]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
30 printf(" idVendor: 0x%02X%02X\n", desc[9], desc[8]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
31 printf(" idProduct: 0x%02X%02X\n", desc[11], desc[10]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
32 printf(" bcdDevice: 0x%02X%02X\n", desc[13], desc[12]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
33 printf(" iManufacturer: %u\n", desc[14]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
34 printf(" iProduct: %u\n", desc[15]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
35 printf(" iSerialNumber: %u\n", desc[16]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
36 printf(" bNumConfigurations: %u\n", desc[17]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
37 } |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
38 |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
39 static void |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
40 print_config_desc(desc) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
41 u_char *desc; |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
42 { |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
43 printf(" bLength: %u", desc[0]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
44 if (desc[0] != 9) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
45 fputs(" (WRONG!)", stdout); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
46 putchar('\n'); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
47 printf(" bDescriptorType: 0x%02X", desc[1]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
48 if (desc[1] != 0x02) |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
49 fputs(" (WRONG!)", stdout); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
50 putchar('\n'); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
51 printf(" wTotalLength: %u\n", desc[2] | (desc[3] << 8)); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
52 printf(" bNumInterfaces: %u\n", desc[4]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
53 printf(" bConfigurationValue: 0x%02X\n", desc[5]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
54 printf(" iConfiguration: %u\n", desc[6]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
55 printf(" bmAttributes: 0x%02X\n", desc[7]); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
56 printf(" bMaxPower: 0x%02X (%u mA)\n", desc[8], desc[8] * 2); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
57 } |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
58 |
88
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
59 static void |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
60 print_interf_desc(desc) |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
61 u_char *desc; |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
62 { |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
63 printf(" bLength: %u", desc[0]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
64 if (desc[0] != 9) |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
65 fputs(" (WRONG!)", stdout); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
66 putchar('\n'); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
67 printf(" bDescriptorType: 0x%02X", desc[1]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
68 if (desc[1] != 0x04) |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
69 fputs(" (WRONG!)", stdout); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
70 putchar('\n'); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
71 printf(" bInterfaceNumber: %u\n", desc[2]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
72 printf(" bAlternateSetting: 0x%02X\n", desc[3]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
73 printf(" bNumEndpoints: %u\n", desc[4]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
74 printf(" bInterfaceClass: 0x%02X\n", desc[5]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
75 printf(" bInterfaceSubClass: 0x%02X\n", desc[6]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
76 printf(" bInterfaceProtocol: 0x%02X\n", desc[7]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
77 printf(" iInterface: %u\n", desc[8]); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
78 } |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
79 |
89
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
80 static void |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
81 print_endpoint_desc(desc) |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
82 u_char *desc; |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
83 { |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
84 printf(" bLength: %u", desc[0]); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
85 if (desc[0] != 7) |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
86 fputs(" (WRONG!)", stdout); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
87 putchar('\n'); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
88 printf(" bDescriptorType: 0x%02X", desc[1]); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
89 if (desc[1] != 0x05) |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
90 fputs(" (WRONG!)", stdout); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
91 putchar('\n'); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
92 printf(" bEndpointAddress: 0x%02X\n", desc[2]); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
93 printf(" bmAttributes: 0x%02X\n", desc[3]); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
94 printf(" wMaxPacketSize: %u\n", desc[4] | (desc[5] << 8)); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
95 printf(" bInterval: %u\n", desc[6]); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
96 } |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
97 |
90
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
98 static void |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
99 print_string_desc_0(desc) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
100 u_char *desc; |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
101 { |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
102 printf(" bLength: %u", desc[0]); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
103 if (desc[0] > 8) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
104 fputs(" (too long!)", stdout); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
105 else if (desc[0] < 2) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
106 fputs(" (too short!)", stdout); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
107 else if (desc[0] & 1) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
108 fputs(" (odd bogon!)", stdout); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
109 putchar('\n'); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
110 printf(" bDescriptorType: 0x%02X", desc[1]); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
111 if (desc[1] != 0x03) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
112 fputs(" (WRONG!)", stdout); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
113 putchar('\n'); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
114 if (desc[0] < 4) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
115 return; |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
116 printf(" wLANGID[0]: 0x%04X\n", desc[2] | (desc[3] << 8)); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
117 if (desc[0] < 6) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
118 return; |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
119 printf(" wLANGID[1]: 0x%04X\n", desc[4] | (desc[5] << 8)); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
120 if (desc[0] < 8) |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
121 return; |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
122 printf(" wLANGID[2]: 0x%04X\n", desc[6] | (desc[7] << 8)); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
123 } |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
124 |
91
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
125 static void |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
126 print_string_desc(headline, desc, maxlen) |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
127 char *headline; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
128 u_char *desc; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
129 unsigned maxlen; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
130 { |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
131 u_char *sp, *endp; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
132 unsigned uni; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
133 |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
134 if (desc[0] < 2 || desc[0] > maxlen || desc[0] & 1 || desc[1] != 0x03) { |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
135 printf("%s INVALID\n", headline); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
136 return; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
137 } |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
138 printf("%s \"", headline); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
139 endp = desc + desc[0]; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
140 for (sp = desc + 2; sp < endp; sp += 2) { |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
141 uni = sp[0] | (sp[1] << 8); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
142 if (uni < 0x20 || uni > 0x7E) { |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
143 printf("\\u%04X", uni); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
144 continue; |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
145 } |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
146 if (uni == '"' || uni == '\\') |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
147 putchar('\\'); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
148 putchar(uni); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
149 } |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
150 putchar('"'); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
151 putchar('\n'); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
152 } |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
153 |
85
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 main(argc, argv) |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 char **argv; |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 { |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (argc != 2) { |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 fprintf(stderr, "usage: %s ihex-file\n", argv[0]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 exit(1); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 read_intel_hex(argv[1]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 printf("USB device descriptor at 0x3988:\n"); |
87
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
163 print_device_desc(eeprom + 0x388); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
164 printf("USB configuration descriptor at 0x399A:\n"); |
4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
165 print_config_desc(eeprom + 0x39A); |
88
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
166 printf("USB interface descriptor at 0x39A3:\n"); |
ea7b411aad27
cp2102-decode-ee-desc: decode interface descriptor
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
167 print_interf_desc(eeprom + 0x3A3); |
89
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
168 printf("USB endpoint descriptor at 0x39AC:\n"); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
169 print_endpoint_desc(eeprom + 0x3AC); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
170 printf("USB endpoint descriptor at 0x39B3:\n"); |
cddf60418f98
cp2102-decode-ee-desc: decode endpoint descriptors
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
171 print_endpoint_desc(eeprom + 0x3B3); |
90
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
172 printf("USB string descriptor 0 at 0x3800:\n"); |
3bde280f0986
cp2102-decode-ee-desc: decode string descriptor 0
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
173 print_string_desc_0(eeprom + 0x200); |
91
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
174 print_string_desc("Manuf string: ", eeprom + 0x3C3, 60); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
175 print_string_desc("Product string:", eeprom + 0x208, 254); |
f4a7ac90cf39
cp2102-decode-ee-desc: decode textual ID strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
176 print_string_desc("Serial# string:", eeprom + 0x307, 128); |
85
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 exit(0); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |