FreeCalypso > hg > fc-usbser-tools
comparison cp2102/decode_usb_desc.c @ 87:4393e1b4b245
cp2102-decode-ee-desc: decode config descriptor
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 27 Sep 2023 19:15:29 +0000 |
parents | b7397959ae68 |
children | ea7b411aad27 |
comparison
equal
deleted
inserted
replaced
86:b7397959ae68 | 87:4393e1b4b245 |
---|---|
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include "cp210x_defs.h" | 9 #include "cp210x_defs.h" |
10 | 10 |
11 u_char eeprom[SIZE_EEPROM]; | 11 u_char eeprom[SIZE_EEPROM]; |
12 | 12 |
13 static void | |
14 print_device_desc(desc) | |
15 u_char *desc; | |
16 { | |
17 printf(" bLength: %u", desc[0]); | |
18 if (desc[0] != 18) | |
19 fputs(" (WRONG!)", stdout); | |
20 putchar('\n'); | |
21 printf(" bDescriptorType: 0x%02X", desc[1]); | |
22 if (desc[1] != 0x01) | |
23 fputs(" (WRONG!)", stdout); | |
24 putchar('\n'); | |
25 printf(" bcdUSB: 0x%02X%02X\n", desc[3], desc[2]); | |
26 printf(" bDeviceClass: 0x%02X\n", desc[4]); | |
27 printf(" bDeviceSubClass: 0x%02X\n", desc[5]); | |
28 printf(" bDeviceProtocol: 0x%02X\n", desc[6]); | |
29 printf(" bMaxPacketSize0: %u\n", desc[7]); | |
30 printf(" idVendor: 0x%02X%02X\n", desc[9], desc[8]); | |
31 printf(" idProduct: 0x%02X%02X\n", desc[11], desc[10]); | |
32 printf(" bcdDevice: 0x%02X%02X\n", desc[13], desc[12]); | |
33 printf(" iManufacturer: %u\n", desc[14]); | |
34 printf(" iProduct: %u\n", desc[15]); | |
35 printf(" iSerialNumber: %u\n", desc[16]); | |
36 printf(" bNumConfigurations: %u\n", desc[17]); | |
37 } | |
38 | |
39 static void | |
40 print_config_desc(desc) | |
41 u_char *desc; | |
42 { | |
43 printf(" bLength: %u", desc[0]); | |
44 if (desc[0] != 9) | |
45 fputs(" (WRONG!)", stdout); | |
46 putchar('\n'); | |
47 printf(" bDescriptorType: 0x%02X", desc[1]); | |
48 if (desc[1] != 0x02) | |
49 fputs(" (WRONG!)", stdout); | |
50 putchar('\n'); | |
51 printf(" wTotalLength: %u\n", desc[2] | (desc[3] << 8)); | |
52 printf(" bNumInterfaces: %u\n", desc[4]); | |
53 printf(" bConfigurationValue: 0x%02X\n", desc[5]); | |
54 printf(" iConfiguration: %u\n", desc[6]); | |
55 printf(" bmAttributes: 0x%02X\n", desc[7]); | |
56 printf(" bMaxPower: 0x%02X (%u mA)\n", desc[8], desc[8] * 2); | |
57 } | |
58 | |
13 main(argc, argv) | 59 main(argc, argv) |
14 char **argv; | 60 char **argv; |
15 { | 61 { |
16 if (argc != 2) { | 62 if (argc != 2) { |
17 fprintf(stderr, "usage: %s ihex-file\n", argv[0]); | 63 fprintf(stderr, "usage: %s ihex-file\n", argv[0]); |
18 exit(1); | 64 exit(1); |
19 } | 65 } |
20 read_intel_hex(argv[1]); | 66 read_intel_hex(argv[1]); |
21 printf("USB device descriptor at 0x3988:\n"); | 67 printf("USB device descriptor at 0x3988:\n"); |
22 printf(" bLength: %u", eeprom[0x388]); | 68 print_device_desc(eeprom + 0x388); |
23 if (eeprom[0x388] != 18) | 69 printf("USB configuration descriptor at 0x399A:\n"); |
24 fputs(" (WRONG!)", stdout); | 70 print_config_desc(eeprom + 0x39A); |
25 putchar('\n'); | |
26 printf(" bDescriptorType: 0x%02X", eeprom[0x389]); | |
27 if (eeprom[0x389] != 0x01) | |
28 fputs(" (WRONG!)", stdout); | |
29 putchar('\n'); | |
30 printf(" bcdUSB: 0x%02X%02X\n", | |
31 eeprom[0x38B], eeprom[0x38A]); | |
32 printf(" bDeviceClass: 0x%02X\n", eeprom[0x38C]); | |
33 printf(" bDeviceSubClass: 0x%02X\n", eeprom[0x38D]); | |
34 printf(" bDeviceProtocol: 0x%02X\n", eeprom[0x38E]); | |
35 printf(" bMaxPacketSize0: %u\n", eeprom[0x38F]); | |
36 printf(" idVendor: 0x%02X%02X\n", | |
37 eeprom[0x391], eeprom[0x390]); | |
38 printf(" idProduct: 0x%02X%02X\n", | |
39 eeprom[0x393], eeprom[0x392]); | |
40 printf(" bcdDevice: 0x%02X%02X\n", | |
41 eeprom[0x395], eeprom[0x394]); | |
42 printf(" iManufacturer: %u\n", eeprom[0x396]); | |
43 printf(" iProduct: %u\n", eeprom[0x397]); | |
44 printf(" iSerialNumber: %u\n", eeprom[0x398]); | |
45 printf(" bNumConfigurations: %u\n", eeprom[0x399]); | |
46 /* decoding of other descriptors remains to be implemented */ | 71 /* decoding of other descriptors remains to be implemented */ |
47 exit(0); | 72 exit(0); |
48 } | 73 } |