+ if (bus > 64) {
+ sr_err("invalid bus");
+ return NULL;
+ }
+
+ if (addr > 127) {
+ sr_err("invalid address");
+ return NULL;
+ }
+
+ /* Looks like a valid USB device specification, but is it connected? */
+ devices = NULL;
+ libusb_get_device_list(genericdmm_usb_context, &devlist);
+ for (i = 0; devlist[i]; i++) {
+ if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
+ sr_err("genericdmm: failed to get device descriptor: %d", err);
+ continue;
+ }
+
+ if (vid + pid && (des.idVendor != vid || des.idProduct != pid))
+ /* VID/PID specified, but no match. */
+ continue;
+
+ if (bus + addr && (
+ libusb_get_bus_number(devlist[i]) != bus
+ || libusb_get_device_address(devlist[i]) != addr))
+ /* Bus/address specified, but no match. */
+ continue;
+
+ /* Found one. */
+ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
+ sr_err("genericdmm: devc malloc failed.");
+ return 0;
+ }
+
+ devcnt = g_slist_length(drvc->instances);
+ if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
+ NULL, NULL, NULL))) {
+ sr_err("genericdmm: sr_dev_inst_new returned NULL.");
+ return NULL;
+ }
+ sdi->priv = devc;
+ if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
+ return NULL;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ devc->usb = sr_usb_dev_inst_new(
+ libusb_get_bus_number(devlist[i]),
+ libusb_get_device_address(devlist[i]), NULL);
+ devices = g_slist_append(devices, sdi);
+ }
+ libusb_free_device_list(devlist, 1);
+
+ return devices;