+/* Create a new device instance for a libusb device if it is a SysClk LWLA
+ * device and also matches the connection specification.
+ */
+static struct sr_dev_inst *dev_inst_new_matching(GSList *conn_matches,
+ libusb_device *dev)
+{
+ GSList *node;
+ struct sr_usb_dev_inst *usb;
+ const struct model_info *model;
+ struct sr_dev_inst *sdi;
+ struct libusb_device_descriptor des;
+ int bus, address, ret;
+ unsigned int vid, pid;
+
+ bus = libusb_get_bus_number(dev);
+ address = libusb_get_device_address(dev);
+
+ for (node = conn_matches; node != NULL; node = node->next) {
+ usb = node->data;
+ if (usb && usb->bus == bus && usb->address == address)
+ break; /* found */
+ }
+ if (conn_matches && !node)
+ return NULL; /* no match */
+
+ ret = libusb_get_device_descriptor(dev, &des);
+ if (ret != 0) {
+ sr_err("Failed to get USB device descriptor: %s.",
+ libusb_error_name(ret));
+ return NULL;
+ }
+ vid = des.idVendor;
+ pid = des.idProduct;
+
+ /* Create sigrok device instance. */
+ if (vid == USB_VID_SYSCLK && pid == USB_PID_LWLA1016) {
+ model = &lwla1016_info;
+ } else if (vid == USB_VID_SYSCLK && pid == USB_PID_LWLA1034) {
+ model = &lwla1034_info;
+ } else {
+ if (conn_matches)
+ sr_warn("USB device %d.%d (%04x:%04x) is not a"
+ " SysClk LWLA.", bus, address, vid, pid);
+ return NULL;
+ }
+ sdi = dev_inst_new(model);
+
+ sdi->inst_type = SR_INST_USB;
+ sdi->conn = sr_usb_dev_inst_new(bus, address, NULL);
+
+ return sdi;
+}
+