summaryrefslogtreecommitdiff
path: root/libusb/os
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-09-11 13:06:38 +0200
committerHans de Goede <hdegoede@redhat.com>2014-04-22 14:31:35 +0200
commit0504375ea965dd25f00d4828a19c329b7e7525d4 (patch)
treee207b92c7e777046288be44de2c344b51068906e /libusb/os
parentc59d574b211bedcab951b2f19de58bb03a04d671 (diff)
downloadlibusb-0504375ea965dd25f00d4828a19c329b7e7525d4.tar.gz
Add API for allocating / freeing usb3 bulk streams + Linux implementation
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'libusb/os')
-rw-r--r--libusb/os/linux_usbfs.c53
-rw-r--r--libusb/os/linux_usbfs.h8
-rw-r--r--libusb/os/netbsd_usb.c3
-rw-r--r--libusb/os/openbsd_usb.c3
-rw-r--r--libusb/os/wince_usb.c3
-rw-r--r--libusb/os/windows_usb.c3
6 files changed, 73 insertions, 0 deletions
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 5ad6129..2f6b4af 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -1495,6 +1495,56 @@ out:
return ret;
}
+static int do_streams_ioctl(struct libusb_device_handle *handle, long req,
+ uint32_t num_streams, unsigned char *endpoints, int num_endpoints)
+{
+ int r, fd = _device_handle_priv(handle)->fd;
+ struct usbfs_streams *streams;
+
+ if (num_endpoints > 30) /* Max 15 in + 15 out eps */
+ return LIBUSB_ERROR_INVALID_PARAM;
+
+ streams = malloc(sizeof(struct usbfs_streams) + num_endpoints);
+ if (!streams)
+ return LIBUSB_ERROR_NO_MEM;
+
+ streams->num_streams = num_streams;
+ streams->num_eps = num_endpoints;
+ memcpy(streams->eps, endpoints, num_endpoints);
+
+ r = ioctl(fd, req, streams);
+
+ free(streams);
+
+ if (r < 0) {
+ if (errno == ENOTTY)
+ return LIBUSB_ERROR_NOT_SUPPORTED;
+ else if (errno == EINVAL)
+ return LIBUSB_ERROR_INVALID_PARAM;
+ else if (errno == ENODEV)
+ return LIBUSB_ERROR_NO_DEVICE;
+
+ usbi_err(HANDLE_CTX(handle),
+ "streams-ioctl failed error %d errno %d", r, errno);
+ return LIBUSB_ERROR_OTHER;
+ }
+ return r;
+}
+
+static int op_alloc_streams(struct libusb_device_handle *handle,
+ uint32_t num_streams, unsigned char *endpoints, int num_endpoints)
+{
+ return do_streams_ioctl(handle, IOCTL_USBFS_ALLOC_STREAMS,
+ num_streams, endpoints, num_endpoints);
+}
+
+static int op_free_streams(struct libusb_device_handle *handle,
+ unsigned char *endpoints, int num_endpoints)
+{
+ return do_streams_ioctl(handle, IOCTL_USBFS_FREE_STREAMS, 0,
+ endpoints, num_endpoints);
+}
+
static int op_kernel_driver_active(struct libusb_device_handle *handle,
int interface)
{
@@ -2596,6 +2646,9 @@ const struct usbi_os_backend linux_usbfs_backend = {
.clear_halt = op_clear_halt,
.reset_device = op_reset_device,
+ .alloc_streams = op_alloc_streams,
+ .free_streams = op_free_streams,
+
.kernel_driver_active = op_kernel_driver_active,
.detach_kernel_driver = op_detach_kernel_driver,
.attach_kernel_driver = op_attach_kernel_driver,
diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
index 1f5b191..de5186f 100644
--- a/libusb/os/linux_usbfs.h
+++ b/libusb/os/linux_usbfs.h
@@ -132,6 +132,12 @@ struct usbfs_disconnect_claim {
char driver[USBFS_MAXDRIVERNAME + 1];
};
+struct usbfs_streams {
+ unsigned int num_streams; /* Not used by USBDEVFS_FREE_STREAMS */
+ unsigned int num_eps;
+ unsigned char eps[0];
+};
+
#define IOCTL_USBFS_CONTROL _IOWR('U', 0, struct usbfs_ctrltransfer)
#define IOCTL_USBFS_BULK _IOWR('U', 2, struct usbfs_bulktransfer)
#define IOCTL_USBFS_RESETEP _IOR('U', 3, unsigned int)
@@ -155,6 +161,8 @@ struct usbfs_disconnect_claim {
#define IOCTL_USBFS_RELEASE_PORT _IOR('U', 25, unsigned int)
#define IOCTL_USBFS_GET_CAPABILITIES _IOR('U', 26, __u32)
#define IOCTL_USBFS_DISCONNECT_CLAIM _IOR('U', 27, struct usbfs_disconnect_claim)
+#define IOCTL_USBFS_ALLOC_STREAMS _IOR('U', 28, struct usbfs_streams)
+#define IOCTL_USBFS_FREE_STREAMS _IOR('U', 29, struct usbfs_streams)
extern usbi_mutex_static_t linux_hotplug_lock;
diff --git a/libusb/os/netbsd_usb.c b/libusb/os/netbsd_usb.c
index d43eea3..988d3c0 100644
--- a/libusb/os/netbsd_usb.c
+++ b/libusb/os/netbsd_usb.c
@@ -112,6 +112,9 @@ const struct usbi_os_backend netbsd_backend = {
netbsd_clear_halt,
netbsd_reset_device,
+ NULL, /* alloc_streams */
+ NULL, /* free_streams */
+
NULL, /* kernel_driver_active() */
NULL, /* detach_kernel_driver() */
NULL, /* attach_kernel_driver() */
diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c
index ef0b27b..d56c1af 100644
--- a/libusb/os/openbsd_usb.c
+++ b/libusb/os/openbsd_usb.c
@@ -115,6 +115,9 @@ const struct usbi_os_backend openbsd_backend = {
obsd_clear_halt,
obsd_reset_device,
+ NULL, /* alloc_streams */
+ NULL, /* free_streams */
+
NULL, /* kernel_driver_active() */
NULL, /* detach_kernel_driver() */
NULL, /* attach_kernel_driver() */
diff --git a/libusb/os/wince_usb.c b/libusb/os/wince_usb.c
index c48d27d..656b1de 100644
--- a/libusb/os/wince_usb.c
+++ b/libusb/os/wince_usb.c
@@ -1005,6 +1005,9 @@ const struct usbi_os_backend wince_backend = {
wince_clear_halt,
wince_reset_device,
+ NULL, /* alloc_streams */
+ NULL, /* free_streams */
+
wince_kernel_driver_active,
wince_detach_kernel_driver,
wince_attach_kernel_driver,
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index e130bc9..1a25d37 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -2317,6 +2317,9 @@ const struct usbi_os_backend windows_backend = {
windows_clear_halt,
windows_reset_device,
+ NULL, /* alloc_streams */
+ NULL, /* free_streams */
+
windows_kernel_driver_active,
windows_detach_kernel_driver,
windows_attach_kernel_driver,