static GSList *scan(GSList *options) { struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; struct sr_config *src; const struct dso_profile *prof; GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; int devcnt, ret, i, j; const char *conn; drvc = di->priv; devcnt = 0; devices = 0; conn = NULL; for (l = options; l; l = l->next) { src = l->data; if (src->key == SR_CONF_CONN) { conn = g_variant_get_string(src->data, NULL); break; } } if (conn) conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn); else conn_devices = NULL; /* Find all Hantek DSO devices and upload firmware to all of them. */ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { if (conn) { usb = NULL; for (l = conn_devices; l; l = l->next) { usb = l->data; if (usb->bus == libusb_get_bus_number(devlist[i]) && usb->address == libusb_get_device_address(devlist[i])) break; } if (!l) /* This device matched none of the ones that * matched the conn specification. */ continue; } if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { sr_err("Failed to get device descriptor: %s.", libusb_error_name(ret)); continue; } prof = NULL; for (j = 0; dev_profiles[j].orig_vid; j++) { if (des.idVendor == dev_profiles[j].orig_vid && des.idProduct == dev_profiles[j].orig_pid) { /* Device matches the pre-firmware profile. */ prof = &dev_profiles[j]; sr_dbg("Found a %s %s.", prof->vendor, prof->model); sdi = dso_dev_new(devcnt, prof); devices = g_slist_append(devices, sdi); devc = sdi->priv; if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, prof->firmware) == SR_OK) /* Remember when the firmware on this device was updated */ devc->fw_updated = g_get_monotonic_time(); else sr_err("Firmware upload failed for " "device %d.", devcnt); /* Dummy USB address of 0xff will get overwritten later. */ sdi->conn = sr_usb_dev_inst_new( libusb_get_bus_number(devlist[i]), 0xff, NULL); devcnt++; break; } else if (des.idVendor == dev_profiles[j].fw_vid && des.idProduct == dev_profiles[j].fw_pid) { /* Device matches the post-firmware profile. */ prof = &dev_profiles[j]; sr_dbg("Found a %s %s.", prof->vendor, prof->model); sdi = dso_dev_new(devcnt, prof); sdi->status = SR_ST_INACTIVE; devices = g_slist_append(devices, sdi); devc = sdi->priv; sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new( libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); devcnt++; break; } } if (!prof) /* not a supported VID/PID */ continue; } libusb_free_device_list(devlist, 1); return devices; }
static GSList *hw_scan(GSList *options) { struct sr_dev_inst *sdi; const struct dso_profile *prof; struct drv_context *drvc; struct dev_context *devc; GSList *devices; struct libusb_device_descriptor des; libusb_device **devlist; int devcnt, ret, i, j; (void)options; drvc = di->priv; drvc->instances = NULL; devcnt = 0; devices = 0; clear_instances(); /* Find all Hantek DSO devices and upload firmware to all of them. */ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { sr_err("Failed to get device descriptor: %s.", libusb_error_name(ret)); continue; } prof = NULL; for (j = 0; dev_profiles[j].orig_vid; j++) { if (des.idVendor == dev_profiles[j].orig_vid && des.idProduct == dev_profiles[j].orig_pid) { /* Device matches the pre-firmware profile. */ prof = &dev_profiles[j]; sr_dbg("Found a %s %s.", prof->vendor, prof->model); sdi = dso_dev_new(devcnt, prof); devices = g_slist_append(devices, sdi); devc = sdi->priv; if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, prof->firmware) == SR_OK) /* Remember when the firmware on this device was updated */ devc->fw_updated = g_get_monotonic_time(); else sr_err("Firmware upload failed for " "device %d.", devcnt); /* Dummy USB address of 0xff will get overwritten later. */ devc->usb = sr_usb_dev_inst_new( libusb_get_bus_number(devlist[i]), 0xff, NULL); devcnt++; break; } else if (des.idVendor == dev_profiles[j].fw_vid && des.idProduct == dev_profiles[j].fw_pid) { /* Device matches the post-firmware profile. */ prof = &dev_profiles[j]; sr_dbg("Found a %s %s.", prof->vendor, prof->model); sdi = dso_dev_new(devcnt, prof); sdi->status = SR_ST_INACTIVE; devices = g_slist_append(devices, sdi); devc = sdi->priv; devc->usb = sr_usb_dev_inst_new( libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); devcnt++; break; } } if (!prof) /* not a supported VID/PID */ continue; } libusb_free_device_list(devlist, 1); return devices; }