[Spice-devel] [PATCH v6 07/10] win-usbredir: Only match USB devices by VID:PID when WinUsb used
Dmitry Fleytman
dmitry at daynix.com
Thu Feb 11 14:04:22 UTC 2016
> On 4 Feb 2016, at 23:51 PM, Jonathon Jongsma <jjongsma at redhat.com> wrote:
>
> On Thu, 2015-10-29 at 17:26 +0200, Dmitry Fleytman wrote:
>> In other cases match devices by BUS:ADDR.
>>
>> Signed-off-by: Dmitry Fleytman <dmitry at daynix.com>
>> ---
>> src/usb-device-manager.c | 78 +++++++++++++++++++++++++----------------------
>> -
>> 1 file changed, 40 insertions(+), 38 deletions(-)
>>
>> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
>> index 55533f9..dd55276 100644
>> --- a/src/usb-device-manager.c
>> +++ b/src/usb-device-manager.c
>> @@ -653,13 +653,15 @@ static gboolean
>> spice_usb_device_manager_get_udev_bus_n_address(
>>
>> *bus = *address = 0;
>>
>> -#ifndef G_OS_WIN32
>> - bus_str = g_udev_device_get_property(udev, "BUSNUM");
>> - address_str = g_udev_device_get_property(udev, "DEVNUM");
>> -#else /* Windows -- request vid:pid instead */
>> - bus_str = g_udev_device_get_property(udev, "VID");
>> - address_str = g_udev_device_get_property(udev, "PID");
>> -#endif
>> + if (manager->priv->use_usbclerk) {
>> + /* Windows WinUsb/UsbClerk -- request vid:pid instead */
>> + bus_str = g_udev_device_get_property(udev, "VID");
>> + address_str = g_udev_device_get_property(udev, "PID");
>> + } else {
>> + /* Linux or UsbDk backend on Windows*/
>> + bus_str = g_udev_device_get_property(udev, "BUSNUM");
>> + address_str = g_udev_device_get_property(udev, "DEVNUM");
>> + }
>> if (bus_str)
>> *bus = atoi(bus_str);
>> if (address_str)
>> @@ -798,13 +800,17 @@ 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 */
>> static gboolean
>> spice_usb_device_manager_device_match(SpiceUsbDeviceManager *self,
>> SpiceUsbDevice *device,
>> const int bus, const int address)
>> {
>> - return (spice_usb_device_get_busnum(device) == bus &&
>> - spice_usb_device_get_devaddr(device) == address);
>> + if (self->priv->use_usbclerk) {
>> + return (spice_usb_device_get_vid(device) == bus &&
>> + spice_usb_device_get_pid(device) == address);
>> + } else {
>> + return (spice_usb_device_get_busnum(device) == bus &&
>> + spice_usb_device_get_devaddr(device) == address);
>> + }
>> }
>>
>> #ifdef USE_GUDEV
>> @@ -812,32 +818,21 @@ static gboolean
>> spice_usb_device_manager_libdev_match(SpiceUsbDeviceManager *self,
>> libusb_device *libdev,
>> const int bus, const int address)
>> {
>> - return (libusb_get_bus_number(libdev) == bus &&
>> - libusb_get_device_address(libdev) == address);
>> -}
>> -#endif
>> -
>> -#else /* Win32 -- match functions for Windows -- match by vid:pid */
>> -static gboolean
>> -spice_usb_device_manager_device_match(SpiceUsbDeviceManager *self,
>> SpiceUsbDevice *device,
>> - const int vid, const int pid)
>> -{
>> - return (spice_usb_device_get_vid(device) == vid &&
>> - spice_usb_device_get_pid(device) == pid);
>> -}
>> + if (self->priv->use_usbclerk) {
>> + /* WinUSB -- match functions for Windows -- match by vid:pid */
>> + int vid, pid;
>>
>> -static gboolean
>> -spice_usb_device_manager_libdev_match(SpiceUsbDeviceManager *self,
>> libusb_device *libdev,
>> - const int vid, const int pid)
>> -{
>> - int vid2, pid2;
>> -
>> - if (!spice_usb_device_manager_get_libdev_vid_pid(libdev, &vid2, &pid2)) {
>> - return FALSE;
>> + if (!spice_usb_device_manager_get_libdev_vid_pid(libdev, &vid, &pid))
>> {
>> + return FALSE;
>> + }
>> + return (bus == vid && address == pid);
>> + } else {
>> + /* match functions for Linux/UsbDk -- match by bus.addr */
>> + return (libusb_get_bus_number(libdev) == bus &&
>> + libusb_get_device_address(libdev) == address);
>> }
>> - return (vid == vid2 && pid == pid2);
>> }
>> -#endif /* of Win32 -- match functions */
>> +#endif
>>
>> static SpiceUsbDevice*
>> spice_usb_device_manager_find_device(SpiceUsbDeviceManager *self,
>> @@ -1908,14 +1903,21 @@
>> spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
>> SpiceUsbDevice *device,
>> libusb_device *libdev)
>> {
>> - int vid, pid;
>> + int busnum, devaddr;
>
> indentation change
Thanks, fixed.
>
>>
>> if ((device == NULL) || (libdev == NULL))
>> - return FALSE;
>> + return FALSE;
>
> indentation change
Thanks, fixed.
>
>> +
>> + if (manager->priv->use_usbclerk) {
>> + busnum = spice_usb_device_get_vid(device);
>> + devaddr = spice_usb_device_get_pid(device);
>> + } else {
>> + busnum = spice_usb_device_get_busnum(device);
>> + devaddr = spice_usb_device_get_devaddr(device);
>> + }
>>
>> - vid = spice_usb_device_get_vid(device);
>> - pid = spice_usb_device_get_pid(device);
>> - return spice_usb_device_manager_libdev_match(manager, libdev, vid, pid);
>> + return spice_usb_device_manager_libdev_match(manager, libdev,
>> + busnum, devaddr);
>> }
>> #endif
>>
>
>
> ACK without indentation changes above
>
> Acked-by: Jonathon Jongsma <jjongsma at redhat.com <mailto:jjongsma at redhat.com>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160211/0a7a8892/attachment-0001.html>
More information about the Spice-devel
mailing list