usbutils allow call of usb_all() from other code
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
diff --git a/usbutils.c b/usbutils.c
index 93d918c..e7567ef 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)
+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;
@@ -437,7 +437,7 @@ 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_usbdump == 0) {
+ if (level == 0) {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d ID: %04x:%04x",
(int)count, (int)bus_number, (int)device_address,
desc.idVendor, desc.idProduct);
@@ -471,7 +471,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
if (err < 0)
sprintf((char *)prod, "** err(%d)", err);
- if (opt_usbdump == 0) {
+ if (level == 0) {
libusb_close(handle);
sprintf(tmp, EOL " Manufacturer: '%s'" EOL " Product: '%s'", man, prod);
append(buf, tmp, off, len);
@@ -556,7 +556,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
}
// Function to dump all USB devices
-static void usb_all()
+void usb_all(int level)
{
libusb_device **list;
ssize_t count, i;
@@ -581,7 +581,7 @@ static void usb_all()
off = strlen(buf);
for (i = 0; i < count; i++)
- usb_full(i, list[i], &buf, &off, &len);
+ usb_full(i, list[i], &buf, &off, &len, level);
applog(LOG_WARNING, "%s", buf);
@@ -599,7 +599,7 @@ static void cgusb_check_init()
// N.B. environment LIBUSB_DEBUG also sets libusb_set_debug()
if (opt_usbdump >= 0) {
libusb_set_debug(NULL, opt_usbdump);
- usb_all();
+ usb_all(opt_usbdump);
}
usb_commands = malloc(sizeof(*usb_commands) * C_MAX);
diff --git a/usbutils.h b/usbutils.h
index 8a364c9..de79312 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -129,6 +129,7 @@ enum usb_cmds {
struct device_drv;
struct cgpu_info;
+void usb_all(int level);
void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));