Use a unique usb_list function displaying only pertinent information when listing usb devices from the menu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
diff --git a/cgminer.c b/cgminer.c
index 6491a26..43d894b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5334,7 +5334,7 @@ retry:
hotplug_time = selected;
goto retry;
} else if (!strncasecmp(&input, "l", 1)) {
- usb_all(0);
+ usb_list();
goto retry;
} else
clear_logwin();
diff --git a/usbutils.c b/usbutils.c
index 21bc653..c7b378d 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1274,6 +1274,80 @@ static bool is_in_use(libusb_device *dev)
return is_in_use_bd(libusb_get_bus_number(dev), libusb_get_device_address(dev));
}
+static bool how_in_use(uint8_t bus_number, uint8_t device_address, bool *blacklisted)
+{
+ bool ret;
+ mutex_lock(&cgusb_lock);
+ ret = _in_use(in_use_head, bus_number, device_address);
+ if (!ret) {
+ if (_in_use(blacklist_head, bus_number, device_address))
+ *blacklisted = true;
+ }
+ mutex_unlock(&cgusb_lock);
+
+ return ret;
+}
+
+void usb_list(void)
+{
+ struct libusb_device_descriptor desc;
+ struct libusb_device_handle *handle;
+ uint8_t bus_number;
+ uint8_t device_address;
+ libusb_device **list;
+ ssize_t count, i, j;
+ int err, total = 0;
+
+ count = libusb_get_device_list(NULL, &list);
+ if (count < 0) {
+ applog(LOG_ERR, "USB list: failed, err:(%d) %s", (int)count, libusb_error_name((int)count));
+ return;
+ }
+ if (count == 0) {
+ applog(LOG_WARNING, "USB list: found no devices");
+ return;
+ }
+ for (i = 0; i < count; i++) {
+ bool known = false, blacklisted = false, active;
+ unsigned char manuf[256], prod[256];
+ libusb_device *dev = list[i];
+
+ err = libusb_get_device_descriptor(dev, &desc);
+ if (err) {
+ applog(LOG_WARNING, "USB list: Failed to get descriptor %d", (int)i);
+ break;
+ }
+
+ bus_number = libusb_get_bus_number(dev);
+ device_address = libusb_get_device_address(dev);
+
+ for (j = 0; find_dev[j].drv != DRIVER_MAX; j++) {
+ if ((find_dev[j].idVendor == desc.idVendor) &&
+ (find_dev[j].idProduct == desc.idProduct)) {
+ known = true;
+ break;
+ }
+ }
+ if (!known)
+ continue;
+
+ err = libusb_open(dev, &handle);
+ if (err) {
+ applog(LOG_WARNING, "USB list: Failed to open %d", (int)i);
+ break;
+ }
+ libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, manuf, 255);
+ libusb_get_string_descriptor_ascii(handle, desc.iProduct, prod, 255);
+ total++;
+ active = how_in_use(bus_number, device_address, &blacklisted);
+ applog(LOG_WARNING, "Bus %u Device %u ID: %04x:%04x %s %s %sactive %s",
+ bus_number, device_address, desc.idVendor, desc.idProduct,
+ manuf, prod, active ? "" : "in", blacklisted ? "blacklisted" : "");
+ }
+ libusb_free_device_list(list, 1);
+ applog(LOG_WARNING, "%d total known USB device%s", total, total > 1 ? "s": "");
+}
+
static void add_in_use(uint8_t bus_number, uint8_t device_address, bool blacklist)
{
struct usb_in_use_list *in_use_tmp, **head;
diff --git a/usbutils.h b/usbutils.h
index c92d64d..14c5605 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -418,6 +418,7 @@ struct cgpu_info;
bool async_usb_transfers(void);
void cancel_usb_transfers(void);
void usb_all(int level);
+void usb_list(void);
const char *usb_cmdname(enum usb_cmds cmd);
void usb_applog(struct cgpu_info *cgpu, enum usb_cmds cmd, char *msg, int amount, int err);
void blacklist_cgpu(struct cgpu_info *cgpu);