- /* Check for LA8 and/or LA16 devices with various VID/PIDs. */
- for (i = 0; i < ARRAY_SIZE(vid_pid); i++) {
- ret = ftdi_usb_open_desc(ftdic, vid_pid[i].vid,
- vid_pid[i].pid, vid_pid[i].iproduct, NULL);
- /* Show errors other than "device not found". */
- if (ret < 0 && ret != -3)
- sr_dbg("Error finding/opening device (%d): %s.",
- ret, ftdi_get_error_string(ftdic));
- if (ret < 0)
- continue; /* No device found, or not usable. */
-
- sr_dbg("Found %s device (%04x:%04x).",
- vid_pid[i].iproduct, vid_pid[i].vid, vid_pid[i].pid);
-
- if ((ret = add_device(i, vid_pid[i].model, &devices)) < 0)
+ devices = NULL;
+ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
+
+ for (i = 0; devlist[i]; i++) {
+ if (conn) {
+ for (l = conn_devices; l; l = l->next) {
+ usb = l->data;
+ if (usb->bus == libusb_get_bus_number(devlist[i])
+ && usb->address == libusb_get_device_address(devlist[i]))
+ break;
+ }
+ if (!l)
+ /* This device matched none of the ones that
+ * matched the conn specification. */
+ continue;
+ }
+
+ libusb_get_device_descriptor(devlist[i], &des);
+
+ if ((ret = libusb_open(devlist[i], &hdl)) < 0)
+ continue;
+
+ if (des.iProduct == 0) {
+ product[0] = '\0';
+ } else if ((ret = libusb_get_string_descriptor_ascii(hdl,
+ des.iProduct, (unsigned char *)product,
+ sizeof(product))) < 0) {
+ sr_warn("Failed to get product string descriptor: %s.",
+ libusb_error_name(ret));
+ continue;
+ }
+
+ if (des.iSerialNumber == 0) {
+ serial_num[0] = '\0';
+ } else if ((ret = libusb_get_string_descriptor_ascii(hdl,
+ des.iSerialNumber, (unsigned char *)serial_num,
+ sizeof(serial_num))) < 0) {
+ sr_warn("Failed to get serial number string descriptor: %s.",
+ libusb_error_name(ret));
+ continue;
+ }
+
+ usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
+
+ libusb_close(hdl);
+
+ if (!strcmp(product, "ChronoVu LA8")) {
+ model = 0;
+ } else if (!strcmp(product, "ChronoVu LA16")) {
+ model = 1;
+ } else {
+ sr_spew("Unknown iProduct string '%s'.", product);
+ continue;
+ }
+
+ sr_dbg("Found %s (%04x:%04x, %d.%d, %s).",
+ product, des.idVendor, des.idProduct,
+ libusb_get_bus_number(devlist[i]),
+ libusb_get_device_address(devlist[i]), connection_id);
+
+ if ((ret = add_device(model, &des, serial_num, connection_id,
+ devlist[i], &devices)) < 0) {