freebsd-ports/devel/libusb/files/patch-bsd.c
Pav Lucistnik 87caa7a6af - Fix a runtime failure. While usb_control_msg is supposed to return the
actual number of bytes received, the FreeBSD version returns the receiving
  buffer size instead.  Applications inspecting the returned length for error
  checking will fail.  My patch is based on this excerpt from FreeBSDs
  /usr/src/sys/dev/usb/usb.h.

PR:		ports/128549
Submitted by:	ladan (maintainer)
2008-11-14 09:52:21 +00:00

44 lines
1.4 KiB
C

--- bsd.c.orig 2006-03-04 03:52:46.000000000 +0100
+++ bsd.c 2008-11-03 00:08:15.000000000 +0100
@@ -408,7 +408,7 @@
/* Ensure the endpoint address is correct */
ep |= USB_ENDPOINT_IN;
- fd = ensure_ep_open(dev, ep, O_RDONLY);
+ fd = ensure_ep_open(dev, ep, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
if (usb_debug >= 2) {
#ifdef __FreeBSD_kernel__
@@ -477,7 +477,7 @@
USB_ERROR_STR(-errno, "error sending control message: %s",
strerror(errno));
- return UGETW(req.ucr_request.wLength);
+ return req.ucr_actlen;
}
int usb_os_find_busses(struct usb_bus **busses)
@@ -623,9 +623,21 @@
int usb_clear_halt(usb_dev_handle *dev, unsigned int ep)
{
- /* Not yet done, because I haven't needed it. */
+ int ret;
+ struct usb_ctl_request ctl_req;
+
+ ctl_req.ucr_addr = 0; // Not used for this type of request
+ ctl_req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
+ ctl_req.ucr_request.bRequest = UR_CLEAR_FEATURE;
+ USETW(ctl_req.ucr_request.wValue, UF_ENDPOINT_HALT);
+ USETW(ctl_req.ucr_request.wIndex, ep);
+ USETW(ctl_req.ucr_request.wLength, 0);
+ ctl_req.ucr_flags = 0;
+
+ if ((ret = ioctl(dev->fd, USB_DO_REQUEST, &ctl_req)) < 0)
+ USB_ERROR_STR(-errno, "clear_halt: failed for %d", ep);
- USB_ERROR_STR(-ENOSYS, "usb_clear_halt called, unimplemented on BSD");
+ return ret;
}
int usb_reset(usb_dev_handle *dev)