ports/sysutils/nut/files/patch-drivers_libusb.c
Cy Schubert 311484254a Nut USB drivers report a "permission error" without visible reasons
for the error even though permissions are OK (or the driver is run
as root).

Nut uses libusb-0.1 API, assuming return cods of < 0. FreeBSD provides
a libusb-0.1 wrapper howerver it uses libusb-1.0 error codes (which
are negative). This set of patches "teaches" nut libusb-1.0 error codes
as produced by FreeBSD.

Network UPS Tools (networkupstools.org) has a project to use libusb-1.0.
This commit is a stopgap fix until our upline implments lubusb-1.0
support in nut.

PR:		223117
Submitted by:	lev
2017-10-20 01:09:12 +00:00

65 lines
2.2 KiB
C

--- drivers/libusb.c.orig 2015-12-29 12:08:34 UTC
+++ drivers/libusb.c
@@ -428,26 +428,21 @@ static int libusb_strerror(const int ret, const char *
switch(ret)
{
- case -EBUSY: /* Device or resource busy */
- case -EPERM: /* Operation not permitted */
- case -ENODEV: /* No such device */
- case -EACCES: /* Permission denied */
- case -EIO: /* I/O error */
- case -ENXIO: /* No such device or address */
- case -ENOENT: /* No such file or directory */
- case -EPIPE: /* Broken pipe */
- case -ENOSYS: /* Function not implemented */
+ case LIBUSB_ERROR_BUSY: /* Device or resource busy */
+ case LIBUSB_ERROR_NO_DEVICE: /* No such device */
+ case LIBUSB_ERROR_ACCESS: /* Permission denied */
+ case LIBUSB_ERROR_IO: /* I/O error */
+ case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
+ case LIBUSB_ERROR_PIPE: /* Broken pipe */
+ case LIBUSB_ERROR_NOT_SUPPORTED: /* Function not implemented */
upslogx(LOG_DEBUG, "%s: %s", desc, usb_strerror());
return ret;
- case -ETIMEDOUT: /* Connection timed out */
+ case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */
upsdebugx(2, "%s: Connection timed out", desc);
return 0;
- case -EOVERFLOW: /* Value too large for defined data type */
-#ifdef EPROTO
- case -EPROTO: /* Protocol error */
-#endif
+ case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */
upsdebugx(2, "%s: %s", desc, usb_strerror());
return 0;
@@ -478,7 +473,7 @@ static int libusb_get_report(usb_dev_handle *udev, int
0, raw_buf, ReportSize, USB_TIMEOUT);
/* Ignore "protocol stall" (for unsupported request) on control endpoint */
- if (ret == -EPIPE) {
+ if (ret == LIBUSB_ERROR_PIPE) {
return 0;
}
@@ -500,7 +495,7 @@ static int libusb_set_report(usb_dev_handle *udev, int
0, raw_buf, ReportSize, USB_TIMEOUT);
/* Ignore "protocol stall" (for unsupported request) on control endpoint */
- if (ret == -EPIPE) {
+ if (ret == LIBUSB_ERROR_PIPE) {
return 0;
}
@@ -532,7 +527,7 @@ static int libusb_get_interrupt(usb_dev_handle *udev,
ret = usb_interrupt_read(udev, 0x81, (char *)buf, bufsize, timeout);
/* Clear stall condition */
- if (ret == -EPIPE) {
+ if (ret == LIBUSB_ERROR_PIPE) {
ret = usb_clear_halt(udev, 0x81);
}