Merge pull request #405 from kanoi/bflsc USB modify -n and --usb-dump to only show known devices or use new --usb-list-all option to see all
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
diff --git a/README b/README
index 29b3105..37b18c7 100644
--- a/README
+++ b/README
@@ -252,10 +252,11 @@ which means any devices on USB bus_number 1
This is useful if you unplug a device then plug it back in the same port,
it usually reappears with the same bus_number but a different device_address
-You can see the list of USB devices on linux with 'sudo lsusb'
-Cgminer will list the USB devices with the '--usb-dump 0' option
+You can see the list of all USB devices on linux with 'sudo lsusb'
+Cgminer will list the recognised USB devices with the '--usb-dump 0' option
The '--usb-dump N' option with a value of N greater than 0 will dump a lot
-of details about each USB device
+of details about each recognised USB device
+If you wish to see all USB devices, include the --usb-list-all option
The second version
--usb BAS:1,BFL:1,MMQ:0
diff --git a/cgminer.c b/cgminer.c
index 0e70007..39bb11a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -139,6 +139,7 @@ bool opt_worktime;
#ifdef USE_USBUTILS
char *opt_usb_select = NULL;
int opt_usbdump = -1;
+bool opt_usb_list_all;
#endif
char *opt_kernel_path;
@@ -1174,6 +1175,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--usb-dump",
set_int_0_to_10, opt_show_intval, &opt_usbdump,
opt_hidden),
+ OPT_WITHOUT_ARG("--usb-list-all",
+ opt_set_bool, &opt_usb_list_all,
+ opt_hidden),
#endif
#ifdef HAVE_OPENCL
OPT_WITH_ARG("--vectors|-v",
diff --git a/miner.h b/miner.h
index 20ef31c..cd15b40 100644
--- a/miner.h
+++ b/miner.h
@@ -781,6 +781,7 @@ extern bool opt_worktime;
#ifdef USE_USBUTILS
extern char *opt_usb_select;
extern int opt_usbdump;
+extern bool opt_usb_list_all;
#endif
#ifdef USE_BITFORCE
extern bool opt_bfl_noncerange;
diff --git a/usbutils.c b/usbutils.c
index e7567ef..151d3cd 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -411,7 +411,7 @@ static bool setgetdes(ssize_t count, libusb_device *dev, struct libusb_device_ha
return true;
}
-static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off, size_t *len, int level)
+static void usb_full(ssize_t *count, libusb_device *dev, char **buf, size_t *off, size_t *len, int level)
{
struct libusb_device_descriptor desc;
uint8_t bus_number;
@@ -427,9 +427,9 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
int err, i, j, k;
err = libusb_get_device_descriptor(dev, &desc);
- if (err) {
+ if (opt_usb_list_all && err) {
sprintf(tmp, EOL ".USB dev %d: Failed to get descriptor, err %d",
- (int)count, err);
+ (int)(++(*count)), err);
append(buf, tmp, off, len);
return;
}
@@ -437,9 +437,25 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
bus_number = libusb_get_bus_number(dev);
device_address = libusb_get_device_address(dev);
+ if (!opt_usb_list_all) {
+ bool known = false;
+
+ for (i = 0; find_dev[i].drv != DRV_LAST; i++)
+ if ((find_dev[i].idVendor == desc.idVendor) &&
+ (find_dev[i].idProduct == desc.idProduct)) {
+ known = true;
+ break;
+ }
+
+ if (!known)
+ return;
+ }
+
+ (*count)++;
+
if (level == 0) {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d ID: %04x:%04x",
- (int)count, (int)bus_number, (int)device_address,
+ (int)(*count), (int)bus_number, (int)device_address,
desc.idVendor, desc.idProduct);
} else {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d Device Descriptor:" EOL "\tLength: %d" EOL
@@ -447,7 +463,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tDeviceSubClass: %d" EOL "\tDeviceProtocol: %d" EOL "\tMaxPacketSize0: %d" EOL
"\tidVendor: %04x" EOL "\tidProduct: %04x" EOL "\tDeviceRelease: %x" EOL
"\tNumConfigurations: %d",
- (int)count, (int)bus_number, (int)device_address,
+ (int)(*count), (int)bus_number, (int)device_address,
(int)(desc.bLength), destype(desc.bDescriptorType),
desc.bcdUSB, (int)(desc.bDeviceClass), (int)(desc.bDeviceSubClass),
(int)(desc.bDeviceProtocol), (int)(desc.bMaxPacketSize0),
@@ -458,7 +474,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
err = libusb_open(dev, &handle);
if (err) {
- sprintf(tmp, EOL " ** dev %d: Failed to open, err %d", (int)count, err);
+ sprintf(tmp, EOL " ** dev %d: Failed to open, err %d", (int)(*count), err);
append(buf, tmp, off, len);
return;
}
@@ -479,17 +495,17 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
}
if (libusb_kernel_driver_active(handle, 0) == 1) {
- sprintf(tmp, EOL " * dev %d: kernel attached", (int)count);
+ sprintf(tmp, EOL " * dev %d: kernel attached", (int)(*count));
append(buf, tmp, off, len);
}
err = libusb_get_active_config_descriptor(dev, &config);
if (err) {
- if (!setgetdes(count, dev, handle, &config, 1, buf, off, len)
- && !setgetdes(count, dev, handle, &config, 0, buf, off, len)) {
+ if (!setgetdes(*count, dev, handle, &config, 1, buf, off, len)
+ && !setgetdes(*count, dev, handle, &config, 0, buf, off, len)) {
libusb_close(handle);
sprintf(tmp, EOL " ** dev %d: Failed to set config descriptor to %d or %d",
- (int)count, 1, 0);
+ (int)(*count), 1, 0);
append(buf, tmp, off, len);
return;
}
@@ -498,7 +514,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
sprintf(tmp, EOL " dev %d: Active Config:" EOL "\tDescriptorType: %s" EOL
"\tNumInterfaces: %d" EOL "\tConfigurationValue: %d" EOL
"\tAttributes: %d" EOL "\tMaxPower: %d",
- (int)count, destype(config->bDescriptorType),
+ (int)(*count), destype(config->bDescriptorType),
(int)(config->bNumInterfaces), (int)(config->iConfiguration),
(int)(config->bmAttributes), (int)(config->MaxPower));
append(buf, tmp, off, len);
@@ -511,7 +527,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tDescriptorType: %s" EOL "\tInterfaceNumber: %d" EOL
"\tNumEndpoints: %d" EOL "\tInterfaceClass: %d" EOL
"\tInterfaceSubClass: %d" EOL "\tInterfaceProtocol: %d",
- (int)count, j, destype(idesc->bDescriptorType),
+ (int)(*count), j, destype(idesc->bDescriptorType),
(int)(idesc->bInterfaceNumber),
(int)(idesc->bNumEndpoints),
(int)(idesc->bInterfaceClass),
@@ -527,7 +543,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tEndpointAddress: %s0x%x" EOL
"\tAttributes: %s" EOL "\tMaxPacketSize: %d" EOL
"\tInterval: %d" EOL "\tRefresh: %d",
- (int)count, (int)(idesc->bInterfaceNumber), k,
+ (int)(*count), (int)(idesc->bInterfaceNumber), k,
destype(epdesc->bDescriptorType),
epdir(epdesc->bEndpointAddress),
(int)(epdesc->bEndpointAddress),
@@ -549,7 +565,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
sprintf(tmp, EOL " dev %d: More Info:" EOL "\tManufacturer: '%s'" EOL
"\tProduct: '%s'" EOL "\tSerial '%s'",
- (int)count, man, prod, ser);
+ (int)(*count), man, prod, ser);
append(buf, tmp, off, len);
libusb_close(handle);
@@ -559,7 +575,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
void usb_all(int level)
{
libusb_device **list;
- ssize_t count, i;
+ ssize_t count, i, j;
char *buf;
size_t len, off;
@@ -577,15 +593,25 @@ void usb_all(int level)
buf = malloc(len+1);
sprintf(buf, "USB all: found %d devices", (int)count);
-
off = strlen(buf);
+ if (!opt_usb_list_all)
+ append(&buf, " - listing known devices", &off, &len);
+
+ j = -1;
for (i = 0; i < count; i++)
- usb_full(i, list[i], &buf, &off, &len, level);
+ usb_full(&j, list[i], &buf, &off, &len, level);
applog(LOG_WARNING, "%s", buf);
free(buf);
+
+ if (j == -1)
+ applog(LOG_WARNING, "No known USB devices");
+ else
+ applog(LOG_WARNING, "%d %sUSB devices",
+ (int)(++j), opt_usb_list_all ? BLANK : "known ");
+
}
libusb_free_device_list(list, 1);