cmsis-dap: refactor HID PID/VID check loop 28/2328/2
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 2 Oct 2014 20:47:22 +0000 (21:47 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Thu, 16 Oct 2014 12:30:45 +0000 (12:30 +0000)
In preparation for adding serial number support.

Change-Id: I3c9fb411b79d54a4d2de067039255436ba6708c7
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/2328
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/jtag/drivers/cmsis_dap_usb.c

index 3e62ce9c87cf8e05e993bf25b585565ae316877a..fd8c82e01deacc07c54bdce711d6f0c6eb523ed1 100644 (file)
@@ -163,14 +163,16 @@ static int cmsis_dap_usb_open(void)
        struct hid_device_info *devs, *cur_dev;
        unsigned short target_vid, target_pid;
 
        struct hid_device_info *devs, *cur_dev;
        unsigned short target_vid, target_pid;
 
+       bool found = false;
+
        target_vid = 0;
        target_pid = 0;
 
        /*
        target_vid = 0;
        target_pid = 0;
 
        /*
-       The CMSIS-DAP specification stipulates:
-       "The Product String must contain "CMSIS-DAP" somewhere in the string. This is used by the
-       debuggers to idenify a CMSIS-DAP compliant Debug Unit that is connected to a host computer."
-       */
+        * The CMSIS-DAP specification stipulates:
+        * "The Product String must contain "CMSIS-DAP" somewhere in the string. This is used by the
+        * debuggers to identify a CMSIS-DAP compliant Debug Unit that is connected to a host computer."
+        */
        devs = hid_enumerate(0x0, 0x0);
        cur_dev = devs;
        while (NULL != cur_dev) {
        devs = hid_enumerate(0x0, 0x0);
        cur_dev = devs;
        while (NULL != cur_dev) {
@@ -179,23 +181,27 @@ static int cmsis_dap_usb_open(void)
                                LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
                                          cur_dev->vendor_id, cur_dev->product_id);
                        } else {
                                LOG_DEBUG("Cannot read product string of device 0x%x:0x%x",
                                          cur_dev->vendor_id, cur_dev->product_id);
                        } else {
-                               if (wcsstr(cur_dev->product_string, L"CMSIS-DAP"))
-                                       /*
-                                       if the user hasn't specified VID:PID *and*
-                                       product string contains "CMSIS-DAP", pick it
-                                       */
-                                       break;
+                               if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) {
+                                       /* if the user hasn't specified VID:PID *and*
+                                        * product string contains "CMSIS-DAP", pick it
+                                        */
+                                       found = true;
+                               }
                        }
                } else {
                        }
                } else {
-                       /*
-                       otherwise, exhaustively compare against all VID:PID in list
-                       */
+                       /* otherwise, exhaustively compare against all VID:PID in list */
                        for (i = 0; cmsis_dap_vid[i] || cmsis_dap_pid[i]; i++) {
                                if ((cmsis_dap_vid[i] == cur_dev->vendor_id) && (cmsis_dap_pid[i] == cur_dev->product_id))
                        for (i = 0; cmsis_dap_vid[i] || cmsis_dap_pid[i]; i++) {
                                if ((cmsis_dap_vid[i] == cur_dev->vendor_id) && (cmsis_dap_pid[i] == cur_dev->product_id))
-                                       break;
+                                       found = true;
                        }
                        }
+
                        if (cmsis_dap_vid[i] || cmsis_dap_pid[i])
                        if (cmsis_dap_vid[i] || cmsis_dap_pid[i])
-                               break;
+                               found = true;
+               }
+
+               if (found) {
+                       /* we have found an adapter, so exit further checks */
+                       break;
                }
 
                cur_dev = cur_dev->next;
                }
 
                cur_dev = cur_dev->next;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)