1b1995d
From f04315d9210f22e5d7317f1cfb3c076fb93b3c08 Mon Sep 17 00:00:00 2001
1b1995d
From: Hans de Goede <hdegoede@redhat.com>
1b1995d
Date: Sun, 19 Feb 2012 09:58:03 +0100
1b1995d
Subject: [PATCH 123/140] usb-redir: Let the usb-host know about our device
1b1995d
 filtering
1b1995d
1b1995d
libusbredirparser-0.3.4 adds 2 new packets which allows us to notify
1b1995d
the usb-host:
1b1995d
-about the usb device filter we have (if any), so that it knows not the even
1b1995d
 try to redirect certain devices
1b1995d
-when we reject a device based on filtering (in case it tries anyways)
1b1995d
1b1995d
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1b1995d
---
1b1995d
 configure   |    2 +-
1b1995d
 usb-redir.c |   20 ++++++++++++++++++++
1b1995d
 2 files changed, 21 insertions(+), 1 deletion(-)
1b1995d
1b1995d
diff --git a/configure b/configure
1b1995d
index c7e37df..a4848a4 100755
1b1995d
--- a/configure
1b1995d
+++ b/configure
1b1995d
@@ -2541,7 +2541,7 @@ fi
1b1995d
 
1b1995d
 # check for usbredirparser for usb network redirection support
1b1995d
 if test "$usb_redir" != "no" ; then
1b1995d
-    if $pkg_config --atleast-version=0.3.3 libusbredirparser >/dev/null 2>&1 ; then
1b1995d
+    if $pkg_config --atleast-version=0.3.4 libusbredirparser >/dev/null 2>&1 ; then
1b1995d
         usb_redir="yes"
1b1995d
         usb_redir_cflags=$($pkg_config --cflags libusbredirparser 2>/dev/null)
1b1995d
         usb_redir_libs=$($pkg_config --libs libusbredirparser 2>/dev/null)
1b1995d
diff --git a/usb-redir.c b/usb-redir.c
1b1995d
index fe3b0a3..d10d8de 100644
1b1995d
--- a/usb-redir.c
1b1995d
+++ b/usb-redir.c
1b1995d
@@ -106,6 +106,7 @@ struct AsyncURB {
1b1995d
     QTAILQ_ENTRY(AsyncURB)next;
1b1995d
 };
1b1995d
 
1b1995d
+static void usbredir_hello(void *priv, struct usb_redir_hello_header *h);
1b1995d
 static void usbredir_device_connect(void *priv,
1b1995d
     struct usb_redir_device_connect_header *device_connect);
1b1995d
 static void usbredir_device_disconnect(void *priv);
1b1995d
@@ -812,6 +813,7 @@ static void usbredir_open_close_bh(void *opaque)
1b1995d
         dev->parser->log_func = usbredir_log;
1b1995d
         dev->parser->read_func = usbredir_read;
1b1995d
         dev->parser->write_func = usbredir_write;
1b1995d
+        dev->parser->hello_func = usbredir_hello;
1b1995d
         dev->parser->device_connect_func = usbredir_device_connect;
1b1995d
         dev->parser->device_disconnect_func = usbredir_device_disconnect;
1b1995d
         dev->parser->interface_info_func = usbredir_interface_info;
1b1995d
@@ -830,6 +832,7 @@ static void usbredir_open_close_bh(void *opaque)
1b1995d
         dev->read_buf_size = 0;
1b1995d
 
1b1995d
         usbredirparser_caps_set_cap(caps, usb_redir_cap_connect_device_version);
1b1995d
+        usbredirparser_caps_set_cap(caps, usb_redir_cap_filter);
1b1995d
         usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE, 0);
1b1995d
         usbredirparser_do_write(dev->parser);
1b1995d
     }
1b1995d
@@ -1018,6 +1021,10 @@ static int usbredir_check_filter(USBRedirDevice *dev)
1b1995d
 
1b1995d
 error:
1b1995d
     usbredir_device_disconnect(dev);
1b1995d
+    if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter)) {
1b1995d
+        usbredirparser_send_filter_reject(dev->parser);
1b1995d
+        usbredirparser_do_write(dev->parser);
1b1995d
+    }
1b1995d
     return -1;
1b1995d
 }
1b1995d
 
1b1995d
@@ -1043,6 +1050,19 @@ static int usbredir_handle_status(USBRedirDevice *dev,
1b1995d
     }
1b1995d
 }
1b1995d
 
1b1995d
+static void usbredir_hello(void *priv, struct usb_redir_hello_header *h)
1b1995d
+{
1b1995d
+    USBRedirDevice *dev = priv;
1b1995d
+
1b1995d
+    /* Try to send the filter info now that we've the usb-host's caps */
1b1995d
+    if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter) &&
1b1995d
+            dev->filter_rules) {
1b1995d
+        usbredirparser_send_filter_filter(dev->parser, dev->filter_rules,
1b1995d
+                                          dev->filter_rules_count);
1b1995d
+        usbredirparser_do_write(dev->parser);
1b1995d
+    }
1b1995d
+}
1b1995d
+
1b1995d
 static void usbredir_device_connect(void *priv,
1b1995d
     struct usb_redir_device_connect_header *device_connect)
1b1995d
 {
1b1995d
-- 
1b1995d
1.7.9.3
1b1995d