diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cp2102/decode_usb_desc.c	Wed Sep 27 18:43:14 2023 +0000
@@ -0,0 +1,48 @@
+/*
+ * This program reads a CP2102 EEPROM image from an Intel HEX file
+ * and decodes the USB descriptors portion thereof.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "cp210x_defs.h"
+
+u_char eeprom[SIZE_EEPROM];
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s ihex-file\n", argv[0]);
+		exit(1);
+	}
+	read_intel_hex(argv[1]);
+	printf("USB device descriptor at 0x3988:\n");
+	printf("  bLength:            %u", eeprom[0x388]);
+	if (eeprom[0x388] != 18)
+		fputs(" (WRONG!)", stdout);
+	putchar('\n');
+	printf("  bDescriptorType:    0x%02X", eeprom[0x389]);
+	if (eeprom[0x389] != 0x01)
+		fputs(" (WRONG!)", stdout);
+	putchar('\n');
+	printf("  bcdUSB:             0x%02X%02X\n",
+		eeprom[0x38B], eeprom[0x38A]);
+	printf("  bDeviceClass:       0x%02X\n", eeprom[0x38C]);
+	printf("  bDeviceSubClass:    0x%02X\n", eeprom[0x38D]);
+	printf("  bDeviceProtocol:    0x%02X\n", eeprom[0x38E]);
+	printf("  bMaxPacketSize0:    0x%02X\n", eeprom[0x38F]);
+	printf("  idVendor:           0x%02X%02X\n",
+		eeprom[0x391], eeprom[0x390]);
+	printf("  idProduct:          0x%02X%02X\n",
+		eeprom[0x393], eeprom[0x392]);
+	printf("  bcdDevice:          0x%02X%02X\n",
+		eeprom[0x395], eeprom[0x394]);
+	printf("  iManufacturer:      %u\n", eeprom[0x396]);
+	printf("  iProduct:           %u\n", eeprom[0x397]);
+	printf("  iSerialNumber:      %u\n", eeprom[0x398]);
+	printf("  bNumConfigurations: %u\n", eeprom[0x399]);
+	/* decoding of other descriptors remains to be implemented */
+	exit(0);
+}