From 4c5ce0b16afe3b7ca88c39282147926bc15dff41 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 9 Dec 2020 17:33:47 +0100 Subject: [PATCH] Hosted: Handle devices w/o serial number, e.g. GigaDevices GD-Link ARM/CMSIS-DAP --- src/platforms/hosted/bmp_libusb.c | 20 +++++++++++++------- src/platforms/hosted/cmsis_dap.c | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index 30abda8d..e24bdda6 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -98,12 +98,19 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) char serial[64]; char manufacturer[128]; char product[128]; - bmp_type_t type = BMP_TYPE_NONE; + bmp_type_t type; bool access_problems = false; char *active_cable = NULL; bool ftdi_unknown = false; rescan: + type = BMP_TYPE_NONE; found_debuggers = 0; + serial[0] = 0; + manufacturer[0] = 0; + product[0] = 0; + access_problems = false; + active_cable = NULL; + ftdi_unknown = false; for (int i = 0; devs[i]; i++) { libusb_device *dev = devs[i]; int res = libusb_get_device_descriptor(dev, &desc); @@ -130,12 +137,8 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) res = libusb_get_string_descriptor_ascii( handle, desc.iSerialNumber, (uint8_t*)serial, sizeof(serial)); - if (res <= 0) { - /* This can fail for many devices. Continue silent!*/ - libusb_close(handle); - continue; - } - if (cl_opts->opt_serial && !strstr(serial, cl_opts->opt_serial)) { + if (cl_opts->opt_serial && ((res <= 0) || + !strstr(serial, cl_opts->opt_serial))) { libusb_close(handle); continue; } @@ -154,6 +157,9 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) libusb_close(handle); continue; } + } else { + libusb_close(handle); + continue; } libusb_close(handle); if (cl_opts->opt_ident_string) { diff --git a/src/platforms/hosted/cmsis_dap.c b/src/platforms/hosted/cmsis_dap.c index 8abd9d7e..c1e9668f 100644 --- a/src/platforms/hosted/cmsis_dap.c +++ b/src/platforms/hosted/cmsis_dap.c @@ -56,18 +56,18 @@ int dap_init(bmp_info_t *info) if (hid_init()) return -1; int size = strlen(info->serial); - wchar_t serial[size + 1], *wc = serial; + wchar_t serial[64] = {0}, *wc = serial; for (int i = 0; i < size; i++) *wc++ = info->serial[i]; *wc = 0; - /* Blacklist devices that do not wirk with 513 byte report length + /* Blacklist devices that do not work with 513 byte report length * FIXME: Find a solution to decipher from the device. */ if ((info->vid == 0x1fc9) && (info->pid == 0x0132)) { DEBUG_WARN("Blacklist\n"); report_size = 64 + 1; } - handle = hid_open(info->vid, info->pid, serial); + handle = hid_open(info->vid, info->pid, (serial[0]) ? serial : NULL); if (!handle) return -1; dap_disconnect();