+static int opendev2(int device_index, struct sigrok_device_instance **sdi,
+ libusb_device *dev, struct libusb_device_descriptor *des,
+ int *skip)
+{
+ int err;
+
+ if ((err = libusb_get_device_descriptor(dev, des))) {
+ g_warning("failed to get device descriptor: %d", err);
+ return -1;
+ }
+
+ if (des->idVendor != USB_VENDOR || des->idProduct != USB_PRODUCT)
+ return 0;
+
+ if (*skip != device_index) {
+ /* Skip devices of this type that aren't the one we want. */
+ *skip += 1;
+ return 0;
+ }
+
+ /*
+ * Should check the bus here, since we know that already. But what are
+ * we going to do if it doesn't match after the right number of skips?
+ */
+ if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
+ (*sdi)->usb->address = libusb_get_device_address(dev);
+ (*sdi)->status = ST_ACTIVE;
+ g_message("opened device %d on %d.%d interface %d",
+ (*sdi)->index, (*sdi)->usb->bus,
+ (*sdi)->usb->address, USB_INTERFACE);
+ } else {
+ g_warning("failed to open device: %d", err);
+ *sdi = NULL;
+ }
+
+ return 0;
+}
+
+static int opendev3(struct sigrok_device_instance **sdi, libusb_device *dev,
+ struct libusb_device_descriptor *des)
+{
+ int err;
+
+ if ((err = libusb_get_device_descriptor(dev, des))) {
+ g_warning("failed to get device descriptor: %d", err);
+ return -1;
+ }
+
+ if (des->idVendor != USB_VENDOR || des->idProduct != USB_PRODUCT)
+ return 0;
+
+ if (libusb_get_bus_number(dev) == (*sdi)->usb->bus
+ && libusb_get_device_address(dev) == (*sdi)->usb->address) {
+ /* Found it. */
+ if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
+ (*sdi)->status = ST_ACTIVE;
+ g_message("opened device %d on %d.%d interface %d",
+ (*sdi)->index, (*sdi)->usb->bus,
+ (*sdi)->usb->address, USB_INTERFACE);
+ } else {
+ g_warning("failed to open device: %d", err);
+ *sdi = NULL;
+ }
+ }
+
+ return 0;
+}
+