+static int open_usb(struct sr_dev_inst *sdi)
+{
+ libusb_device **devlist;
+ struct libusb_device_descriptor des;
+ struct dev_context *devc;
+ int ret, tmp, cnt, i;
+
+ devc = sdi->priv;
+
+ if (sdi->status == SR_ST_ACTIVE)
+ /* already in use */
+ return SR_ERR;
+
+ cnt = libusb_get_device_list(genericdmm_usb_context, &devlist);
+ if (cnt < 0) {
+ sr_err("genericdmm: Failed to retrieve device list (%d)", cnt);
+ return SR_ERR;
+ }
+
+ ret = SR_ERR;
+ for (i = 0; i < cnt; i++) {
+ if ((tmp = libusb_get_device_descriptor(devlist[i], &des))) {
+ sr_err("genericdmm: Failed to get device descriptor: %d.", tmp);
+ continue;
+ }
+
+ if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
+ || libusb_get_device_address(devlist[i]) != devc->usb->address)
+ /* this is not the one */
+ continue;
+
+ if ((tmp = libusb_open(devlist[i], &devc->usb->devhdl))) {
+ sr_err("genericdmm: Failed to open device: %d.", tmp);
+ break;
+ }
+
+ sr_info("genericdmm: Opened device %s on %d.%d ", devc->profile->modelid,
+ devc->usb->bus, devc->usb->address);
+ ret = SR_OK;
+ break;
+ }
+ libusb_free_device_list(devlist, 1);
+
+ return ret;
+}
+