[Nut-upsdev] USB Device match

Edgar Fuß ef at math.uni-bonn.de
Wed Dec 21 20:01:19 GMT 2022


> the attached patch
Sorry, forgot to attach.
-------------- next part --------------
--- drivers/libusb1.c.orig	2022-12-21 20:34:49.234885584 +0100
+++ drivers/libusb1.c	2022-12-21 20:37:12.563000417 +0100
@@ -151,7 +151,7 @@ static int nut_libusb_open(libusb_device
 	struct libusb_config_descriptor *conf_desc = NULL;
 	const struct libusb_interface_descriptor *if_desc;
 	libusb_device_handle *udev;
-	uint8_t bus;
+	uint8_t bus, port;
 	int ret, res;
 	unsigned char buf[20];
 	const unsigned char *p;
@@ -227,6 +227,17 @@ static int nut_libusb_open(libusb_device
 			fatal_with_errno(EXIT_FAILURE, "Out of memory");
 		}
 		sprintf(curDevice->Bus, "%03d", bus);
+		port = libusb_get_port_number(device);
+		curDevice->Device = (char *)malloc(4);
+		if (curDevice->Device == NULL) {
+			libusb_free_device_list(devlist, 1);
+			fatal_with_errno(EXIT_FAILURE, "Out of memory");
+		}
+#if 0
+		sprintf(curDevice->Device, "%03d", port);
+#else
+		sprintf(curDevice->Device, "%03d", devnum);
+#endif
 		curDevice->VendorID = dev_desc.idVendor;
 		curDevice->ProductID = dev_desc.idProduct;
 		curDevice->bcdDevice = dev_desc.bcdDevice;


More information about the Nut-upsdev mailing list