From 88ea96e5e54118b4e7087d5725ce7e311768db18 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 16 Jan 2014 08:11:19 +0000 Subject: [PATCH] Move the descriptor checks up from dfu_init() into the FLIP protocol implementation. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1266 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 7 +++++++ dfu.c | 42 ------------------------------------------ flip1.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ flip2.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f543c44..139758ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-01-16 Joerg Wunsch + + * dfu.c (dfu_init): Move the descriptor checks up into the + FLIP protocol implementation. + * flip2.c (flip2_initialize): (Dito.) + * flip1.c (flip1_initialize): (Dito.) + 2014-01-16 Joerg Wunsch * flip2.c: Rename from flip.c diff --git a/dfu.c b/dfu.c index 10248b55..f35cdd3b 100644 --- a/dfu.c +++ b/dfu.c @@ -236,48 +236,6 @@ int dfu_init(struct dfu_dev *dfu, unsigned short vid, unsigned short pid) memcpy(&dfu->endp_desc, found->config->interface->altsetting->endpoint, sizeof(dfu->endp_desc)); - /* Check if descriptor values are what we expect. */ - - if (dfu->dev_desc.idVendor != vid) - fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", - progname, dfu->dev_desc.idVendor, vid); - - if (pid != 0 && dfu->dev_desc.idProduct != pid) - fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", - progname, dfu->dev_desc.idProduct, pid); - - if (dfu->dev_desc.bNumConfigurations != 1) - fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", - progname, (int) dfu->dev_desc.bNumConfigurations); - - if (dfu->conf_desc.bNumInterfaces != 1) - fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", - progname, (int) dfu->conf_desc.bNumInterfaces); - - if (dfu->dev_desc.bDeviceClass != 0) - fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 0)\n", - progname, (int) dfu->dev_desc.bDeviceClass); - - if (dfu->dev_desc.bDeviceSubClass != 0) - fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n", - progname, (int) dfu->dev_desc.bDeviceSubClass); - - if (dfu->dev_desc.bDeviceProtocol != 0) - fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", - progname, (int) dfu->dev_desc.bDeviceProtocol); - - if (dfu->intf_desc.bInterfaceClass != 0xFF) - fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n", - progname, (int) dfu->intf_desc.bInterfaceClass); - - if (dfu->intf_desc.bInterfaceSubClass != 0) - fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", - progname, (int) dfu->intf_desc.bInterfaceSubClass); - - if (dfu->intf_desc.bInterfaceProtocol != 0) - fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", - progname, (int) dfu->intf_desc.bInterfaceProtocol); - /* Get strings. */ dfu->manf_str = get_usb_string(dfu->dev_handle, diff --git a/flip1.c b/flip1.c index 11ca29c3..b4c53007 100644 --- a/flip1.c +++ b/flip1.c @@ -162,6 +162,7 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part) { unsigned short vid, pid; int result; + struct dfu_dev *dfu = FLIP1(pgm)->dfu; /* A note about return values. Negative return values from this function are * interpreted as failure by main(), from where this function is called. @@ -199,6 +200,56 @@ int flip1_initialize(PROGRAMMER* pgm, AVRPART *part) if (result != 0) goto flip1_initialize_fail; + /* Check if descriptor values are what we expect. */ + + if (dfu->dev_desc.idVendor != vid) + fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", + progname, dfu->dev_desc.idVendor, vid); + + if (pid != 0 && dfu->dev_desc.idProduct != pid) + fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", + progname, dfu->dev_desc.idProduct, pid); + + if (dfu->dev_desc.bNumConfigurations != 1) + fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", + progname, (int) dfu->dev_desc.bNumConfigurations); + + if (dfu->conf_desc.bNumInterfaces != 1) + fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", + progname, (int) dfu->conf_desc.bNumInterfaces); + + if (dfu->dev_desc.bDeviceClass != 254) + fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 254)\n", + progname, (int) dfu->dev_desc.bDeviceClass); + + if (dfu->dev_desc.bDeviceSubClass != 1) + fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 1)\n", + progname, (int) dfu->dev_desc.bDeviceSubClass); + + if (dfu->dev_desc.bDeviceProtocol != 0) + fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", + progname, (int) dfu->dev_desc.bDeviceProtocol); + + /* + * doc7618 claims an interface class of FEh and a subclas 01h. + * However, as of today (2014-01-16), all values in the interface + * descriptor (except of bLength and bDescriptorType) are actually + * 0. So rather don't check these. + */ + if (0) { + if (dfu->intf_desc.bInterfaceClass != 254) + fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 254)\n", + progname, (int) dfu->intf_desc.bInterfaceClass); + + if (dfu->intf_desc.bInterfaceSubClass != 1) + fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 1)\n", + progname, (int) dfu->intf_desc.bInterfaceSubClass); + + if (dfu->intf_desc.bInterfaceProtocol != 0) + fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", + progname, (int) dfu->intf_desc.bInterfaceProtocol); + } + #if 0 result = flip1_read_memory(FLIP1(pgm)->dfu, FLIP1_MEM_UNIT_SIGNATURE, 0, FLIP1(pgm)->part_sig, 4); diff --git a/flip2.c b/flip2.c index d49ece93..4bbeefe5 100644 --- a/flip2.c +++ b/flip2.c @@ -210,6 +210,7 @@ int flip2_initialize(PROGRAMMER* pgm, AVRPART *part) { unsigned short vid, pid; int result; + struct dfu_dev *dfu = FLIP2(pgm)->dfu; /* A note about return values. Negative return values from this function are * interpreted as failure by main(), from where this function is called. @@ -242,11 +243,53 @@ int flip2_initialize(PROGRAMMER* pgm, AVRPART *part) return -1; } - result = dfu_init(FLIP2(pgm)->dfu, vid, pid); + result = dfu_init(dfu, vid, pid); if (result != 0) goto flip2_initialize_fail; + /* Check if descriptor values are what we expect. */ + + if (dfu->dev_desc.idVendor != vid) + fprintf( stderr, "%s: Warning: USB idVendor = 0x%04X (expected 0x%04X)\n", + progname, dfu->dev_desc.idVendor, vid); + + if (pid != 0 && dfu->dev_desc.idProduct != pid) + fprintf( stderr, "%s: Warning: USB idProduct = 0x%04X (expected 0x%04X)\n", + progname, dfu->dev_desc.idProduct, pid); + + if (dfu->dev_desc.bNumConfigurations != 1) + fprintf( stderr, "%s: Warning: USB bNumConfigurations = %d (expected 1)\n", + progname, (int) dfu->dev_desc.bNumConfigurations); + + if (dfu->conf_desc.bNumInterfaces != 1) + fprintf( stderr, "%s: Warning: USB bNumInterfaces = %d (expected 1)\n", + progname, (int) dfu->conf_desc.bNumInterfaces); + + if (dfu->dev_desc.bDeviceClass != 0) + fprintf( stderr, "%s: Warning: USB bDeviceClass = %d (expected 0)\n", + progname, (int) dfu->dev_desc.bDeviceClass); + + if (dfu->dev_desc.bDeviceSubClass != 0) + fprintf( stderr, "%s: Warning: USB bDeviceSubClass = %d (expected 0)\n", + progname, (int) dfu->dev_desc.bDeviceSubClass); + + if (dfu->dev_desc.bDeviceProtocol != 0) + fprintf( stderr, "%s: Warning: USB bDeviceProtocol = %d (expected 0)\n", + progname, (int) dfu->dev_desc.bDeviceProtocol); + + if (dfu->intf_desc.bInterfaceClass != 0xFF) + fprintf( stderr, "%s: Warning: USB bInterfaceClass = %d (expected 255)\n", + progname, (int) dfu->intf_desc.bInterfaceClass); + + if (dfu->intf_desc.bInterfaceSubClass != 0) + fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", + progname, (int) dfu->intf_desc.bInterfaceSubClass); + + if (dfu->intf_desc.bInterfaceProtocol != 0) + fprintf( stderr, "%s: Warning: USB bInterfaceSubClass = %d (expected 0)\n", + progname, (int) dfu->intf_desc.bInterfaceProtocol); + result = flip2_read_memory(FLIP2(pgm)->dfu, FLIP2_MEM_UNIT_SIGNATURE, 0, FLIP2(pgm)->part_sig, 4);