diff --git a/.usbredir.metadata b/.usbredir.metadata new file mode 100644 index 0000000..4389e0e --- /dev/null +++ b/.usbredir.metadata @@ -0,0 +1 @@ +5f931b9c05fc7cefa68bd05f59d28b201661777e SOURCES/usbredir-0.6.tar.bz2 diff --git a/README.md b/README.md deleted file mode 100644 index 0e7897f..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -The master branch has no content - -Look at the c7 branch if you are working with CentOS-7, or the c4/c5/c6 branch for CentOS-4, 5 or 6 - -If you find this file in a distro specific branch, it means that no content has been checked in yet diff --git a/SOURCES/0001-usbredirserver-Allow-connections-from-both-ipv6-and-.patch b/SOURCES/0001-usbredirserver-Allow-connections-from-both-ipv6-and-.patch new file mode 100644 index 0000000..0ccfd06 --- /dev/null +++ b/SOURCES/0001-usbredirserver-Allow-connections-from-both-ipv6-and-.patch @@ -0,0 +1,88 @@ +From c7e8bfe7f88ea11b31ebe115a629fb1cc903f7bc Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 7 May 2013 15:29:09 +0200 +Subject: [PATCH 1/3] usbredirserver: Allow connections from both ipv6 and ipv4 + +The while loop over the getaddrinfo result would bind to the ipv4 addr and +then stop, causing usbredirserver to not accept connections on ipv6. + +Instead bind explicitly to ipv6 with in6addr_any, which accepts connections +from both. + +Signed-off-by: Hans de Goede +--- + usbredirserver/usbredirserver.c | 42 +++++++++++++++++------------------------ + 1 file changed, 17 insertions(+), 25 deletions(-) + +diff --git a/usbredirserver/usbredirserver.c b/usbredirserver/usbredirserver.c +index 7e063a8..c45a27c 100644 +--- a/usbredirserver/usbredirserver.c ++++ b/usbredirserver/usbredirserver.c +@@ -196,9 +196,9 @@ int main(int argc, char *argv[]) + int usbaddr = -1; + int usbvendor = -1; + int usbproduct = -1; +- struct addrinfo *r, *res, hints; ++ int on = 1; ++ struct sockaddr_in6 serveraddr; + struct sigaction act; +- char port_str[16]; + libusb_device_handle *handle = NULL; + + while ((o = getopt_long(argc, argv, "hp:v:", longopts, NULL)) != -1) { +@@ -271,37 +271,29 @@ int main(int argc, char *argv[]) + + libusb_set_debug(ctx, verbose); + +- memset(&hints, 0, sizeof(hints)); +- hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV | AI_PASSIVE; +- hints.ai_family = AF_UNSPEC; +- hints.ai_socktype = SOCK_STREAM; +- hints.ai_protocol = IPPROTO_TCP; +- +- sprintf(port_str, "%d", port); +- if (getaddrinfo(NULL, port_str, &hints, &res) != 0) { +- perror("getaddrinfo"); ++ server_fd = socket(AF_INET6, SOCK_STREAM, 0); ++ if (server_fd == -1) { ++ perror("Error creating ipv6 socket"); + exit(1); + } + +- for (r = res; r != NULL; r = r->ai_next) { +- server_fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); +- if (server_fd == -1) +- continue; +- +- if (bind(server_fd, r->ai_addr, r->ai_addrlen) == 0) +- break; +- +- close(server_fd); ++ if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) { ++ perror("Error setsockopt(SO_REUSEADDR) failed"); ++ exit(1); + } +- freeaddrinfo(res); +- +- if (r == NULL) { +- fprintf(stderr, "Could not bind to port: %s\n", port_str); ++ ++ memset(&serveraddr, 0, sizeof(serveraddr)); ++ serveraddr.sin6_family = AF_INET6; ++ serveraddr.sin6_port = htons(port); ++ serveraddr.sin6_addr = in6addr_any; ++ ++ if (bind(server_fd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) { ++ fprintf(stderr, "Error binding port %d: %s\n", port, strerror(errno)); + exit(1); + } + + if (listen(server_fd, 1)) { +- perror("listen"); ++ perror("Error listening"); + exit(1); + } + +-- +1.8.2.1 + diff --git a/SOURCES/0002-usbredirserver-testclient-Error-check-fcntl-calls.patch b/SOURCES/0002-usbredirserver-testclient-Error-check-fcntl-calls.patch new file mode 100644 index 0000000..2501a35 --- /dev/null +++ b/SOURCES/0002-usbredirserver-testclient-Error-check-fcntl-calls.patch @@ -0,0 +1,78 @@ +From 65b99a49dc4d5d4cf16ba880d3377196e96f1bc5 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Mon, 13 May 2013 09:59:32 +0200 +Subject: [PATCH 2/3] usbredirserver/testclient: Error check fcntl calls + +Signed-off-by: Hans de Goede +--- + usbredirserver/usbredirserver.c | 14 +++++++++++--- + usbredirtestclient/usbredirtestclient.c | 14 ++++++++++++-- + 2 files changed, 23 insertions(+), 5 deletions(-) + +diff --git a/usbredirserver/usbredirserver.c b/usbredirserver/usbredirserver.c +index c45a27c..d2765c6 100644 +--- a/usbredirserver/usbredirserver.c ++++ b/usbredirserver/usbredirserver.c +@@ -189,7 +189,7 @@ static void quit_handler(int sig) + + int main(int argc, char *argv[]) + { +- int o, server_fd = -1; ++ int o, flags, server_fd = -1; + char *endptr, *delim; + int port = 4000; + int usbbus = -1; +@@ -307,8 +307,16 @@ int main(int argc, char *argv[]) + break; + } + +- fcntl(client_fd, F_SETFL, +- (long)fcntl(client_fd, F_GETFL) | O_NONBLOCK); ++ flags = fcntl(client_fd, F_GETFL); ++ if (flags == -1) { ++ perror("fcntl F_GETFL"); ++ break; ++ } ++ flags = fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); ++ if (flags == -1) { ++ perror("fcntl F_SETFL O_NONBLOCK"); ++ break; ++ } + + /* Try to find the specified usb device */ + if (usbvendor != -1) { +diff --git a/usbredirtestclient/usbredirtestclient.c b/usbredirtestclient/usbredirtestclient.c +index a9123da..42b16dc 100644 +--- a/usbredirtestclient/usbredirtestclient.c ++++ b/usbredirtestclient/usbredirtestclient.c +@@ -189,7 +189,7 @@ static void quit_handler(int sig) + + int main(int argc, char *argv[]) + { +- int o; ++ int o, flags; + char *endptr, *server; + struct addrinfo *r, *res, hints; + struct sigaction act; +@@ -265,7 +265,17 @@ int main(int argc, char *argv[]) + exit(1); + } + +- fcntl(client_fd, F_SETFL, (long)fcntl(client_fd, F_GETFL) | O_NONBLOCK); ++ flags = fcntl(client_fd, F_GETFL); ++ if (flags == -1) { ++ perror("fcntl F_GETFL"); ++ exit(1); ++ } ++ flags = fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); ++ if (flags == -1) { ++ perror("fcntl F_SETFL O_NONBLOCK"); ++ exit(1); ++ } ++ + parser = usbredirparser_create(); + if (!parser) { + exit(1); +-- +1.8.2.1 + diff --git a/SOURCES/0003-usbredirhost-Fix-coverity-sign_extension-warning.patch b/SOURCES/0003-usbredirhost-Fix-coverity-sign_extension-warning.patch new file mode 100644 index 0000000..aecc9cc --- /dev/null +++ b/SOURCES/0003-usbredirhost-Fix-coverity-sign_extension-warning.patch @@ -0,0 +1,32 @@ +From 3f85be6da588d17f272a4b3c9b34bbfb7510f1e7 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Mon, 13 May 2013 10:30:30 +0200 +Subject: [PATCH 3/3] usbredirhost: Fix coverity sign_extension warning + +Coverity does not like uint8_t * int being casted to an uint64_t, change +the int to an unsigned int to make it happy. + +Note that the int in question can never be > 255, so this is not a real issue. + +Signed-off-by: Hans de Goede +--- + usbredirhost/usbredirhost.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c +index da3ef90..09745c2 100644 +--- a/usbredirhost/usbredirhost.c ++++ b/usbredirhost/usbredirhost.c +@@ -1041,7 +1041,8 @@ static int usbredirhost_submit_stream_transfer_unlocked( + static int usbredirhost_start_stream_unlocked(struct usbredirhost *host, + uint8_t ep) + { +- int i, status, count = host->endpoint[EP2I(ep)].transfer_count; ++ unsigned int i, count = host->endpoint[EP2I(ep)].transfer_count; ++ int status; + + /* For out endpoints 1/2 the transfers are a buffer for usb-guest data */ + if (!(ep & LIBUSB_ENDPOINT_IN)) { +-- +1.8.2.1 + diff --git a/SOURCES/0004-usbredirhost-Use-libusb_set_auto_detach_kernel_drive.patch b/SOURCES/0004-usbredirhost-Use-libusb_set_auto_detach_kernel_drive.patch new file mode 100644 index 0000000..01b4242 --- /dev/null +++ b/SOURCES/0004-usbredirhost-Use-libusb_set_auto_detach_kernel_drive.patch @@ -0,0 +1,57 @@ +From 050f32a35898c8ac8ac47322f21f0ec4928aa065 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +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 +--- + 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 + diff --git a/SOURCES/0005-usbredirparser-Update-header-len-inside-the-usbredir.patch b/SOURCES/0005-usbredirparser-Update-header-len-inside-the-usbredir.patch new file mode 100644 index 0000000..1081ccf --- /dev/null +++ b/SOURCES/0005-usbredirparser-Update-header-len-inside-the-usbredir.patch @@ -0,0 +1,33 @@ +From 931a41c1c92410639a0e76e6fdd07482f06e4578 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +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 +--- + 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 + diff --git a/SPECS/usbredir.spec b/SPECS/usbredir.spec new file mode 100644 index 0000000..f0936ff --- /dev/null +++ b/SPECS/usbredir.spec @@ -0,0 +1,146 @@ +Name: usbredir +Version: 0.6 +Release: 5%{?dist} +Summary: USB network redirection protocol libraries +Group: System Environment/Libraries +License: LGPLv2+ +URL: http://spice-space.org/page/UsbRedir +Source0: http://spice-space.org/download/%{name}/%{name}-%{version}.tar.bz2 +# Some patches from upstream git (drop at next rebase) +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 +The usbredir libraries allow USB devices to be used on remote and/or virtual +hosts over TCP. The following libraries are provided: + +usbredirparser: +A library containing the parser for the usbredir protocol + +usbredirhost: +A library implementing the USB host side of a usbredir connection. +All that an application wishing to implement a USB host needs to do is: +* Provide a libusb device handle for the device +* Provide write and read callbacks for the actual transport of usbredir data +* Monitor for usbredir and libusb read/write events and call their handlers + + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries +Requires: %{name}%{?_isa} = %{version}-%{release} + +%description devel +The %{name}-devel package contains libraries and header files for +developing applications that use %{name}. + + +%package server +Summary: Simple USB host TCP server +Group: System Environment/Daemons +License: GPLv2+ +Requires: %{name}%{?_isa} = %{version}-%{release} + +%description server +A simple USB host TCP server, using libusbredirhost. + + +%prep +%setup -q +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 +%patch4 -p1 +%patch5 -p1 + + +%build +%configure --disable-static +make %{?_smp_mflags} V=1 + + +%install +%make_install +rm $RPM_BUILD_ROOT%{_libdir}/libusbredir*.la + + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + + +%files +%doc ChangeLog COPYING.LIB README TODO +%{_libdir}/libusbredir*.so.* + +%files devel +%doc usb-redirection-protocol.txt README.multi-thread +%{_includedir}/usbredir*.h +%{_libdir}/libusbredir*.so +%{_libdir}/pkgconfig/libusbredir*.pc + +%files server +%doc COPYING +%{_sbindir}/usbredirserver +%{_mandir}/man1/usbredirserver.1* + + +%changelog +* Tue Sep 10 2013 Hans de Goede - 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 - 0.6-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild + +* Mon May 13 2013 Hans de Goede - 0.6-3 +- Fix usbredirserver not listening for ipv6 connections (rhbz#957470) +- Fix a few (harmless) coverity warnings + +* Fri Feb 15 2013 Fedora Release Engineering - 0.6-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild + +* Thu Dec 13 2012 Hans de Goede - 0.6-1 +- Update to upstream 0.6 release + +* Tue Sep 25 2012 Hans de Goede - 0.5.2-1 +- Update to upstream 0.5.2 release + +* Wed Sep 19 2012 Hans de Goede - 0.5.1-1 +- Update to upstream 0.5.1 release + +* Fri Sep 7 2012 Hans de Goede - 0.5-1 +- Update to upstream 0.5 release + +* Mon Jul 30 2012 Hans de Goede - 0.4.3-3 +- Add 2 fixes from upstream fixing issues with some bulk devices (rhbz#842358) + +* Sun Jul 22 2012 Fedora Release Engineering - 0.4.3-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Mon Apr 2 2012 Hans de Goede - 0.4.3-1 +- Update to upstream 0.4.3 release + +* Tue Mar 6 2012 Hans de Goede - 0.4.2-1 +- Update to upstream 0.4.2 release + +* Sat Feb 25 2012 Hans de Goede - 0.4.1-1 +- Update to upstream 0.4.1 release + +* Thu Feb 23 2012 Hans de Goede - 0.4-1 +- Update to upstream 0.4 release + +* Thu Jan 12 2012 Hans de Goede - 0.3.3-1 +- Update to upstream 0.3.3 release + +* Tue Jan 3 2012 Hans de Goede 0.3.2-1 +- Update to upstream 0.3.2 release + +* Wed Aug 24 2011 Hans de Goede 0.3.1-1 +- Update to upstream 0.3.1 release + +* Thu Jul 14 2011 Hans de Goede 0.3-1 +- Initial Fedora package