+ devc->usbdev = dev;
+ devc->desc = desc;
+
+ vendor = g_malloc(32);
+ model = g_malloc(32);
+ serial_num = g_malloc(32);
+ rv = ftdi_usb_get_strings(devc->ftdic, dev, vendor, 32,
+ model, 32, serial_num, 32);
+ switch (rv) {
+ case 0:
+ break;
+ case -9:
+ sr_dbg("The device lacks a serial number.");
+ g_free(serial_num);
+ serial_num = NULL;
+ break;
+ default:
+ sr_err("Failed to get the FTDI strings: %d", rv);
+ goto err_free_strings;
+ }
+ sr_dbg("Found an FTDI device: %s.", model);
+
+ /* Register the device with libsigrok. */
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->vendor = vendor;
+ sdi->model = model;
+ sdi->serial_num = serial_num;
+ sdi->driver = di;
+ sdi->priv = devc;
+
+ for (char *const *chan = &(desc->channel_names[0]); *chan; chan++)
+ sr_channel_new(sdi, chan - &(desc->channel_names[0]),
+ SR_CHANNEL_LOGIC, TRUE, *chan);
+
+ *devices = g_slist_append(*devices, sdi);
+ drvc->instances = g_slist_append(drvc->instances, sdi);
+ return;
+
+err_free_strings:
+ g_free(vendor);
+ g_free(model);
+ g_free(serial_num);
+ ftdi_free(devc->ftdic);
+err_free_data_buf:
+ g_free(devc->data_buf);
+ g_free(devc);
+}
+
+static GSList *scan_all(struct sr_dev_driver *di, GSList *options)
+{
+ GSList *devices;
+ struct ftdi_device_list *devlist = 0;
+ struct ftdi_device_list *curdev;
+ struct ftdi_context *ftdic;
+ int ret;
+
+ (void)options;
+
+ devices = NULL;
+
+ /* Allocate memory for the FTDI context (ftdic) and initialize it. */
+ ftdic = ftdi_new();
+ if (!ftdic) {
+ sr_err("Failed to initialize libftdi.");
+ return NULL;
+ }
+
+ ret = ftdi_usb_find_all(ftdic, &devlist, 0, 0);