- struct context *ctx;
- unsigned int i;
- int ret;
-
- /* Note: sdi is non-NULL, the caller already checked this. */
-
- if (!(ctx = (*sdi)->priv)) {
- sr_err("zp: %s: (*sdi)->priv was NULL", __func__);
- return -1;
- }
-
- if ((ret = libusb_get_device_descriptor(dev, des))) {
- sr_err("zp: failed to get device descriptor: %d", ret);
- return -1;
- }
-
- if (des->idVendor != USB_VENDOR)
- return 0;
-
- if (libusb_get_bus_number(dev) == ctx->usb->bus
- && libusb_get_device_address(dev) == ctx->usb->address) {
-
- for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
- if (!(des->idProduct == zeroplus_models[i].pid))
- continue;
-
- sr_info("zp: Found ZEROPLUS device 0x%04x (%s)",
- des->idProduct, zeroplus_models[i].model_name);
- ctx->num_channels = zeroplus_models[i].channels;
- ctx->memory_size = zeroplus_models[i].sample_depth * 1024;
- break;
- }
-
- if (ctx->num_channels == 0) {
- sr_err("zp: Unknown ZEROPLUS device 0x%04x",
- des->idProduct);
- return -2;
- }
-
- /* Found it. */
- if (!(ret = libusb_open(dev, &(ctx->usb->devhdl)))) {
- (*sdi)->status = SR_ST_ACTIVE;
- sr_info("zp: opened device %d on %d.%d interface %d",
- (*sdi)->index, ctx->usb->bus,
- ctx->usb->address, USB_INTERFACE);
- } else {
- sr_err("zp: failed to open device: %d", ret);
- *sdi = NULL;
- }
- }
-
- return 0;
-}
-
-static struct sr_dev_inst *zp_open_dev(int dev_index)
-{
- struct sr_dev_inst *sdi;
- libusb_device **devlist;
- struct libusb_device_descriptor des;
- int i;
-
- if (!(sdi = sr_dev_inst_get(zdi->instances, dev_index)))
- return NULL;
-
- libusb_get_device_list(usb_context, &devlist);
- if (sdi->status == SR_ST_INACTIVE) {
- /* Find the device by vendor, product, bus and address. */
- libusb_get_device_list(usb_context, &devlist);
- for (i = 0; devlist[i]; i++) {
- /* TODO: Error handling. */
- opendev4(&sdi, devlist[i], &des);
- }
- } else {
- /* Status must be SR_ST_ACTIVE, i.e. already in use... */
- sdi = NULL;
- }
- libusb_free_device_list(devlist, 1);
-
- if (sdi && sdi->status != SR_ST_ACTIVE)
- sdi = NULL;
-
- return sdi;
-}
-
-static void close_dev(struct sr_dev_inst *sdi)
-{
- struct context *ctx;
-
- if (!(ctx = sdi->priv)) {
- sr_err("zp: %s: sdi->priv was NULL", __func__);
- return; /* FIXME */
- }
-
- if (!ctx->usb->devhdl)
- return;
-
- sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
- ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
- libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
- libusb_reset_device(ctx->usb->devhdl);
- libusb_close(ctx->usb->devhdl);
- ctx->usb->devhdl = NULL;
- /* TODO: Call libusb_exit() here or only in hw_cleanup()? */
- sdi->status = SR_ST_INACTIVE;
-}
-
-static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes)
-{
- struct context *ctx;