# HG changeset patch # User Mychaela Falconia # Date 1695847590 0 # Node ID f4a7ac90cf3901d4b16c756d7b2ca95c7ba6ebc3 # Parent 3bde280f0986b4f741c43adebd283bcfddd0ff66 cp2102-decode-ee-desc: decode textual ID strings diff -r 3bde280f0986 -r f4a7ac90cf39 cp2102/decode_usb_desc.c --- a/cp2102/decode_usb_desc.c Wed Sep 27 20:15:57 2023 +0000 +++ b/cp2102/decode_usb_desc.c Wed Sep 27 20:46:30 2023 +0000 @@ -122,6 +122,35 @@ printf(" wLANGID[2]: 0x%04X\n", desc[6] | (desc[7] << 8)); } +static void +print_string_desc(headline, desc, maxlen) + char *headline; + u_char *desc; + unsigned maxlen; +{ + u_char *sp, *endp; + unsigned uni; + + if (desc[0] < 2 || desc[0] > maxlen || desc[0] & 1 || desc[1] != 0x03) { + printf("%s INVALID\n", headline); + return; + } + printf("%s \"", headline); + endp = desc + desc[0]; + for (sp = desc + 2; sp < endp; sp += 2) { + uni = sp[0] | (sp[1] << 8); + if (uni < 0x20 || uni > 0x7E) { + printf("\\u%04X", uni); + continue; + } + if (uni == '"' || uni == '\\') + putchar('\\'); + putchar(uni); + } + putchar('"'); + putchar('\n'); +} + main(argc, argv) char **argv; { @@ -142,6 +171,8 @@ print_endpoint_desc(eeprom + 0x3B3); printf("USB string descriptor 0 at 0x3800:\n"); print_string_desc_0(eeprom + 0x200); - /* decoding of other string descriptors remains to be implemented */ + print_string_desc("Manuf string: ", eeprom + 0x3C3, 60); + print_string_desc("Product string:", eeprom + 0x208, 254); + print_string_desc("Serial# string:", eeprom + 0x307, 128); exit(0); }