- struct zp *zp;
- unsigned int i;
- int err;
-
- /* Note: sdi is non-NULL, the caller already checked this. */
-
- if (!(zp = (*sdi)->priv)) {
- sr_err("zp: %s: (*sdi)->priv was NULL", __func__);
- return -1;
- }
-
- if ((err = libusb_get_device_descriptor(dev, des))) {
- sr_warn("failed to get device descriptor: %d", err);
- return -1;
- }
-
- if (des->idVendor != USB_VENDOR)
- return 0;
-
- if (libusb_get_bus_number(dev) == (*sdi)->usb->bus
- && libusb_get_device_address(dev) == (*sdi)->usb->address) {
-
- for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
- if (!(des->idProduct == zeroplus_models[i].pid))
- continue;
-
- sr_info("Found PID=%04X (%s)", des->idProduct,
- zeroplus_models[i].model_name);
- zp->num_channels = zeroplus_models[i].channels;
- zp->memory_size = zeroplus_models[i].sample_depth * 1024;
- break;
- }
-
- if (zp->num_channels == 0) {
- sr_warn("Unknown ZeroPlus device %04X", des->idProduct);
- return -2;
- }
-
- /* Found it. */
- if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
- (*sdi)->status = SR_ST_ACTIVE;
- sr_info("opened device %d on %d.%d interface %d",
- (*sdi)->index, (*sdi)->usb->bus,
- (*sdi)->usb->address, USB_INTERFACE);
- } else {
- sr_warn("failed to open device: %d", err);
- *sdi = NULL;
- }
- }
-
- return 0;
-}
-
-static struct sr_device_instance *zp_open_device(int device_index)
-{
- struct sr_device_instance *sdi;
- libusb_device **devlist;
- struct libusb_device_descriptor des;
- int err, i;
-
- if (!(sdi = sr_get_device_instance(device_instances, device_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. */
- err = 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_device(struct sr_device_instance *sdi)
-{
- if (!sdi->usb->devhdl)
- return;
-
- sr_info("closing device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
- libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
- libusb_close(sdi->usb->devhdl);
- sdi->usb->devhdl = NULL;
- sdi->status = SR_ST_INACTIVE;
-}
-
-static int configure_probes(struct sr_device_instance *sdi, GSList *probes)
-{
- struct zp *zp;
- struct sr_probe *probe;
- GSList *l;