FreeCalypso > hg > fc-usbser-tools
annotate cp2102/decode_usb_desc.c @ 85:0787525a33e2
cp2102-decode-ee-desc program started
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 27 Sep 2023 18:43:14 +0000 |
parents | |
children | b7397959ae68 |
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 |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 if (argc != 2) { |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fprintf(stderr, "usage: %s ihex-file\n", argv[0]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 exit(1); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 read_intel_hex(argv[1]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 printf("USB device descriptor at 0x3988:\n"); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 printf(" bLength: %u", eeprom[0x388]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (eeprom[0x388] != 18) |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fputs(" (WRONG!)", stdout); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 putchar('\n'); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 printf(" bDescriptorType: 0x%02X", eeprom[0x389]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (eeprom[0x389] != 0x01) |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fputs(" (WRONG!)", stdout); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 putchar('\n'); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 printf(" bcdUSB: 0x%02X%02X\n", |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 eeprom[0x38B], eeprom[0x38A]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 printf(" bDeviceClass: 0x%02X\n", eeprom[0x38C]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 printf(" bDeviceSubClass: 0x%02X\n", eeprom[0x38D]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 printf(" bDeviceProtocol: 0x%02X\n", eeprom[0x38E]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 printf(" bMaxPacketSize0: 0x%02X\n", eeprom[0x38F]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 printf(" idVendor: 0x%02X%02X\n", |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 eeprom[0x391], eeprom[0x390]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 printf(" idProduct: 0x%02X%02X\n", |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 eeprom[0x393], eeprom[0x392]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 printf(" bcdDevice: 0x%02X%02X\n", |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 eeprom[0x395], eeprom[0x394]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 printf(" iManufacturer: %u\n", eeprom[0x396]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 printf(" iProduct: %u\n", eeprom[0x397]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 printf(" iSerialNumber: %u\n", eeprom[0x398]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 printf(" bNumConfigurations: %u\n", eeprom[0x399]); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 /* decoding of other descriptors remains to be implemented */ |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(0); |
0787525a33e2
cp2102-decode-ee-desc program started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |