Use the new libusb autodetach kernel driver functionality

- Fix a usbredirparser bug which causes tcp/ip redir to not work (rhbz#1005015)
This commit is contained in:
Hans de Goede 2013-09-10 11:04:40 +02:00
parent 4c830f3c43
commit 750c3bc245
3 changed files with 99 additions and 1 deletions

View File

@ -0,0 +1,57 @@
From 050f32a35898c8ac8ac47322f21f0ec4928aa065 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Fri, 14 Jun 2013 09:56:20 +0200
Subject: [PATCH 4/8] usbredirhost: Use libusb_set_auto_detach_kernel_driver
when available
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
usbredirhost/usbredirhost.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c
index 09745c2..0335b37 100644
--- a/usbredirhost/usbredirhost.c
+++ b/usbredirhost/usbredirhost.c
@@ -499,9 +499,13 @@ static int usbredirhost_claim(struct usbredirhost *host, int initial_claim)
memset(host->alt_setting, 0, MAX_INTERFACES);
host->claimed = 1;
+#if LIBUSBX_API_VERSION >= 0x01000102
+ libusb_set_auto_detach_kernel_driver(host->handle, 1);
+#endif
for (i = 0; host->config && i < host->config->bNumInterfaces; i++) {
n = host->config->interface[i].altsetting[0].bInterfaceNumber;
+#if LIBUSBX_API_VERSION < 0x01000102
r = libusb_detach_kernel_driver(host->handle, n);
if (r < 0 && r != LIBUSB_ERROR_NOT_FOUND
&& r != LIBUSB_ERROR_NOT_SUPPORTED) {
@@ -509,6 +513,7 @@ static int usbredirhost_claim(struct usbredirhost *host, int initial_claim)
n, host->config->bConfigurationValue, libusb_error_name(r));
return libusb_status_or_error_to_redir_status(host, r);
}
+#endif
r = libusb_claim_interface(host->handle, n);
if (r < 0) {
@@ -534,6 +539,16 @@ static void usbredirhost_release(struct usbredirhost *host, int attach_drivers)
if (!host->claimed)
return;
+#if LIBUSBX_API_VERSION >= 0x01000102
+ /* We want to always do the attach ourselves because:
+ 1) For compound interfaces such as usb-audio we must first release all
+ interfaces before we can attach the driver;
+ 2) When releasing interfaces before calling libusb_set_configuration,
+ we don't want the kernel driver to get attached (our attach_drivers
+ parameter is 0 in this case). */
+ libusb_set_auto_detach_kernel_driver(host->handle, 0);
+#endif
+
for (i = 0; host->config && i < host->config->bNumInterfaces; i++) {
n = host->config->interface[i].altsetting[0].bInterfaceNumber;
--
1.8.3.1

View File

@ -0,0 +1,33 @@
From 931a41c1c92410639a0e76e6fdd07482f06e4578 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 5 Sep 2013 16:25:13 +0200
Subject: [PATCH 5/5] usbredirparser: Update header-len inside the
usbredirparser_do_read loop
If we process the hello packet with the 64 bit id capability bit in the same
loop as other packets (because they were send quickly after one each other),
then we end up reading 48 bytes for the header of the next packets processed
in the same loop, while we should read 64 bytes for them, causing the
sender and receiver to get out of sync.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
usbredirparser/usbredirparser.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/usbredirparser/usbredirparser.c b/usbredirparser/usbredirparser.c
index b60d3f4..b50ddec 100644
--- a/usbredirparser/usbredirparser.c
+++ b/usbredirparser/usbredirparser.c
@@ -1011,6 +1011,8 @@ int usbredirparser_do_read(struct usbredirparser *parser_pub)
parser->data = NULL;
if (!r)
return -2;
+ /* header len may change if this was an hello packet */
+ header_len = usbredirparser_get_header_len(parser_pub);
}
}
}
--
1.8.3.1

View File

@ -1,6 +1,6 @@
Name: usbredir
Version: 0.6
Release: 4%{?dist}
Release: 5%{?dist}
Summary: USB network redirection protocol libraries
Group: System Environment/Libraries
License: LGPLv2+
@ -10,6 +10,8 @@ Source0: http://spice-space.org/download/%{name}/%{name}-%{version}.tar.b
Patch1: 0001-usbredirserver-Allow-connections-from-both-ipv6-and-.patch
Patch2: 0002-usbredirserver-testclient-Error-check-fcntl-calls.patch
Patch3: 0003-usbredirhost-Fix-coverity-sign_extension-warning.patch
Patch4: 0004-usbredirhost-Use-libusb_set_auto_detach_kernel_drive.patch
Patch5: 0005-usbredirparser-Update-header-len-inside-the-usbredir.patch
BuildRequires: libusb1-devel >= 1.0.9
%description
@ -52,6 +54,8 @@ A simple USB host TCP server, using libusbredirhost.
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%build
@ -85,6 +89,10 @@ rm $RPM_BUILD_ROOT%{_libdir}/libusbredir*.la
%changelog
* Tue Sep 10 2013 Hans de Goede <hdegoede@redhat.com> - 0.6-5
- Use the new libusb autodetach kernel driver functionality
- Fix a usbredirparser bug which causes tcp/ip redir to not work (rhbz#1005015)
* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.6-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild