+static int vsllink_tap_execute(void)
+{
+ return vsllink_jtag_execute();
+}
+
+/****************************************************************************
+ * VSLLink USB low-level functions */
+
+static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
+ char *string, char *buff, uint16_t buf_size)
+{
+ int len;
+ uint8_t alloced = 0;
+ uint8_t ret = 1;
+
+ if (NULL == buff) {
+ buf_size = 256;
+ buff = malloc(buf_size);
+ if (NULL == buff) {
+ ret = 0;
+ goto free_and_return;
+ }
+ alloced = 1;
+ }
+
+ strcpy(buff, "");
+ len = usb_get_string_simple(usb, stringidx, buff, buf_size);
+ if ((len < 0) || ((size_t)len != strlen(buff))) {
+ ret = 0;
+ goto free_and_return;
+ }
+
+ buff[len] = '\0';
+ if ((string != NULL) && strcmp(buff, string)) {
+ ret = 0;
+ goto free_and_return;
+ }
+
+free_and_return:
+ if (alloced && (buff != NULL)) {
+ free(buff);
+ buff = NULL;
+ }
+ return ret;
+}
+
+static usb_dev_handle *find_usb_device(uint16_t VID, uint16_t PID, uint8_t interface,
+ char *serialstring, char *productstring)
+{
+ usb_dev_handle *dev_handle = NULL;
+ struct usb_bus *busses;
+ struct usb_bus *bus;
+ struct usb_device *dev;
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+ busses = usb_get_busses();
+
+ for (bus = busses; bus; bus = bus->next) {
+ for (dev = bus->devices; dev; dev = dev->next) {
+ if ((dev->descriptor.idVendor == VID)
+ && (dev->descriptor.idProduct == PID)) {
+ dev_handle = usb_open(dev);
+ if (NULL == dev_handle) {
+ LOG_ERROR("failed to open %04X:%04X, %s", VID, PID,
+ usb_strerror());
+ continue;
+ }
+
+ /* check description string */
+ if ((productstring != NULL && !usb_check_string(dev_handle,
+ dev->descriptor.iProduct, productstring, NULL, 0))
+ || (serialstring != NULL && !usb_check_string(dev_handle,
+ dev->descriptor.iSerialNumber, serialstring, NULL, 0))) {
+ usb_close(dev_handle);
+ dev_handle = NULL;
+ continue;
+ }
+
+ if (usb_claim_interface(dev_handle, interface) != 0) {
+ LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE,
+ "claim interface", usb_strerror());
+ usb_close(dev_handle);
+ dev_handle = NULL;
+ continue;
+ }
+
+ if (dev_handle != NULL)
+ return dev_handle;
+ }
+ }
+ }
+
+ return dev_handle;
+}