[PATCH 2/5] windows: fix device matching for non-WinUSB configurations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Pavel Gurvich <pavel@xxxxxxxxxx>

Match USB devices by bus addresses instead of VID/PID.
This makes system distinguish between similar devices plugged into
different USB ports.

Signed-off-by: Pavel Gurvich <pavel@xxxxxxxxxx>
Signed-off-by: Dmitry Fleytman <dmitry@xxxxxxxxxx>
---
 gtk/usb-device-manager.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index e1f03e2..7739337 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -668,10 +668,10 @@ static gboolean spice_usb_device_manager_get_udev_bus_n_address(
 
     *bus = *address = 0;
 
-#ifndef G_OS_WIN32
+#ifndef USE_WINUSB
     bus_str = g_udev_device_get_property(udev, "BUSNUM");
     address_str = g_udev_device_get_property(udev, "DEVNUM");
-#else /* Windows -- request vid:pid instead */
+#else /* WinUSB -- request vid:pid instead */
     bus_str = g_udev_device_get_property(udev, "VID");
     address_str = g_udev_device_get_property(udev, "PID");
 #endif
@@ -811,7 +811,7 @@ static void spice_usb_device_manager_auto_connect_cb(GObject      *gobject,
     spice_usb_device_unref(device);
 }
 
-#ifndef G_OS_WIN32 /* match functions for Linux -- match by bus.addr */
+#ifndef USE_WINUSB /* match functions for non-WinUSB -- match by bus.addr */
 static gboolean
 spice_usb_device_manager_device_match(SpiceUsbDevice *device,
                                       const int bus, const int address)
@@ -830,7 +830,7 @@ spice_usb_device_manager_libdev_match(libusb_device *libdev,
 }
 #endif
 
-#else /* Win32 -- match functions for Windows -- match by vid:pid */
+#else /* WinUSB -- match functions for WinUSB -- match by vid:pid */
 static gboolean
 spice_usb_device_manager_device_match(SpiceUsbDevice *device,
                                       const int vid, const int pid)
@@ -1861,6 +1861,7 @@ spice_usb_device_equal_libdev(SpiceUsbDevice *device,
     return info->libdev == libdev;
 }
 #else /* Windows -- compare vid:pid of device and libdev */
+#ifdef USE_WINUSB
 static gboolean
 spice_usb_device_equal_libdev(SpiceUsbDevice *device,
                               libusb_device  *libdev)
@@ -1879,7 +1880,26 @@ spice_usb_device_equal_libdev(SpiceUsbDevice *device,
 
     return ((vid1 == vid2) && (pid1 == pid2));
 }
-#endif
+#else /* non-WinUSB -- compare bus:port of device and libdev */
+static gboolean
+spice_usb_device_equal_libdev(SpiceUsbDevice *device,
+                              libusb_device  *libdev)
+{
+    int busnum1, devaddr1, busnum2, devaddr2;
+
+    if ((device == NULL) || (libdev == NULL))
+        return FALSE;
+
+    busnum1 = spice_usb_device_get_busnum(device);
+    devaddr1 = spice_usb_device_get_devaddr(device);
+
+    busnum2 = libusb_get_bus_number(libdev);
+    devaddr2 = libusb_get_device_address(libdev);
+
+    return ((busnum1 == busnum2) && (devaddr1 == devaddr2));
+}
+#endif /* end of USE_WINUSB*/
+#endif /* end of G_OS_WIN32*/
 
 /*
  * Caller must libusb_unref_device the libusb_device returned by this function.
@@ -1906,9 +1926,14 @@ spice_usb_device_manager_device_to_libdev(SpiceUsbDeviceManager *self,
     g_return_val_if_fail(self->priv != NULL, NULL);
     g_return_val_if_fail(self->priv->context != NULL, NULL);
 
-    /* On windows we match by vid / pid, since the address may change */
+#ifdef USE_WINUSB
+    /* For WinUSB we match by vid / pid, since the address may change */
     bus  = spice_usb_device_get_vid(device);
     addr = spice_usb_device_get_pid(device);
+#else
+    bus  = spice_usb_device_get_busnum(device);
+    addr = spice_usb_device_get_devaddr(device);
+#endif
 
     libusb_get_device_list(self->priv->context, &devlist);
     if (!devlist)
-- 
2.1.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]