- if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) {
- /* We have a list of sr_usb_dev_inst matching the connection
- * string. Wrap them in sr_dev_inst and we're done. */
- for (l = usb_devices; l; l = l->next) {
- sdi = g_malloc0(sizeof(struct sr_dev_inst));
- sdi->status = SR_ST_INACTIVE;
- sdi->vendor = g_strdup(VENDOR);
- sdi->model = g_strdup(MODEL);
- sdi->inst_type = SR_INST_USB;
- sdi->conn = l->data;
- for (i = 0; i < ARRAY_SIZE(channel_names); i++)
- sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
- channel_names[i]);
- devc = g_malloc0(sizeof(struct dev_context));
- sdi->priv = devc;
- devc->limit_samples = 0;
- devc->data_source = DEFAULT_DATA_SOURCE;
- devices = g_slist_append(devices, sdi);
- }
- g_slist_free(usb_devices);
- } else
- g_slist_free_full(usb_devices, g_free);
-
- return std_scan_complete(di, devices);
-}
-
-static int dev_open(struct sr_dev_inst *sdi)
-{
- struct sr_dev_driver *di = sdi->driver;
- struct drv_context *drvc = di->context;
- struct sr_usb_dev_inst *usb;
- int ret;
-
- usb = sdi->conn;
-
- if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK)
- return SR_ERR;
-
-/*
- * The libusb 1.0.9 Darwin backend is broken: it can report a kernel
- * driver being active, but detaching it always returns an error.
- */
-#if !defined(__APPLE__)
- if (libusb_kernel_driver_active(usb->devhdl, USB_INTERFACE) == 1) {
- if ((ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE)) < 0) {
- sr_err("failed to detach kernel driver: %s",
- libusb_error_name(ret));
- return SR_ERR;
- }
- }
-#endif
-
- if ((ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION))) {
- sr_err("Failed to set configuration: %s.", libusb_error_name(ret));
- return SR_ERR;