changeset 90:3bde280f0986

cp2102-decode-ee-desc: decode string descriptor 0
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 27 Sep 2023 20:15:57 +0000
parents cddf60418f98
children f4a7ac90cf39
files cp2102/decode_usb_desc.c
diffstat 1 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cp2102/decode_usb_desc.c	Wed Sep 27 20:00:56 2023 +0000
+++ b/cp2102/decode_usb_desc.c	Wed Sep 27 20:15:57 2023 +0000
@@ -95,6 +95,33 @@
 	printf("  bInterval:        %u\n", desc[6]);
 }
 
+static void
+print_string_desc_0(desc)
+	u_char *desc;
+{
+	printf("  bLength:         %u", desc[0]);
+	if (desc[0] > 8)
+		fputs(" (too long!)", stdout);
+	else if (desc[0] < 2)
+		fputs(" (too short!)", stdout);
+	else if (desc[0] & 1)
+		fputs(" (odd bogon!)", stdout);
+	putchar('\n');
+	printf("  bDescriptorType: 0x%02X", desc[1]);
+	if (desc[1] != 0x03)
+		fputs(" (WRONG!)", stdout);
+	putchar('\n');
+	if (desc[0] < 4)
+		return;
+	printf("  wLANGID[0]:      0x%04X\n", desc[2] | (desc[3] << 8));
+	if (desc[0] < 6)
+		return;
+	printf("  wLANGID[1]:      0x%04X\n", desc[4] | (desc[5] << 8));
+	if (desc[0] < 8)
+		return;
+	printf("  wLANGID[2]:      0x%04X\n", desc[6] | (desc[7] << 8));
+}
+
 main(argc, argv)
 	char **argv;
 {
@@ -113,6 +140,8 @@
 	print_endpoint_desc(eeprom + 0x3AC);
 	printf("USB endpoint descriptor at 0x39B3:\n");
 	print_endpoint_desc(eeprom + 0x3B3);
-	/* decoding of string descriptors remains to be implemented */
+	printf("USB string descriptor 0 at 0x3800:\n");
+	print_string_desc_0(eeprom + 0x200);
+	/* decoding of other string descriptors remains to be implemented */
 	exit(0);
 }