[Spice-devel] win: usb: use port_number instead of device_address

Submitted by Uri Lublin on March 6, 2013, 11:27 p.m.

Details

Message ID 1362612477-22434-1-git-send-email-uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin March 6, 2013, 11:27 p.m.
It seems that device_address is not consistent and port_number is for Windows.
For example the device_address may change when the WinUSB driver is
installed.
This seems to happen more for Win7 clients.

USB devices are being redir'ed by their bus_number and device_address.
When the device_address before/after installing the WinUSB driver is not
the same, the "before" device will not be found, and an error message
will appear. The "after" device may or may not be redir'ed.

Note that win-usb-dev.h is compiled only for Windows machine.

Fixes rhbz#842816
---

1. Although a bit hacky and maybe confusing, this patch is least intrusive,
and does not require ifdefs etc.
If you think it's too much, please let me know and I'll make another patch.
One thing I thought of is to redir based on vid:pid instead of bus.addr for windows clients.

2. I did not reproduced the bug exactly as explained in its description.

---
 gtk/win-usb-dev.h | 1 +
 1 file changed, 1 insertion(+)

Patch hide | download patch | download mbox

diff --git a/gtk/win-usb-dev.h b/gtk/win-usb-dev.h
index b5c4fce..5cd6ef5 100644
--- a/gtk/win-usb-dev.h
+++ b/gtk/win-usb-dev.h
@@ -107,4 +107,5 @@  typedef enum

 G_END_DECLS

+#define libusb_get_device_address(dev) libusb_get_port_number(dev)
 #endif /* __WIN_USB_DEV_H__ */

Comments

Hi,

On 03/07/2013 12:27 AM, Uri Lublin wrote:
> It seems that device_address is not consistent and port_number is for Windows.
> For example the device_address may change when the WinUSB driver is
> installed.
> This seems to happen more for Win7 clients.
>
> USB devices are being redir'ed by their bus_number and device_address.
> When the device_address before/after installing the WinUSB driver is not
> the same, the "before" device will not be found, and an error message
> will appear. The "after" device may or may not be redir'ed.
>
> Note that win-usb-dev.h is compiled only for Windows machine.
>
> Fixes rhbz#842816

I believe this needs more testing before it can be applied. the port-number
typically is the number of the hub port, so 2 devices, 1 in the first port of
the root-hub, and one in the 1st port of another hub could / should have the
same port-number.

Can you please get 2 external usb-hubs (preferable 2 identical ones) and then
check what the port-numbers are for a device plugged into the 1st port of each
hub?

Regards,

Hans


> ---
>
> 1. Although a bit hacky and maybe confusing, this patch is least intrusive,
> and does not require ifdefs etc.
> If you think it's too much, please let me know and I'll make another patch.
> One thing I thought of is to redir based on vid:pid instead of bus.addr for windows clients.
>
> 2. I did not reproduced the bug exactly as explained in its description.
>
> ---
>   gtk/win-usb-dev.h | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/gtk/win-usb-dev.h b/gtk/win-usb-dev.h
> index b5c4fce..5cd6ef5 100644
> --- a/gtk/win-usb-dev.h
> +++ b/gtk/win-usb-dev.h
> @@ -107,4 +107,5 @@ typedef enum
>
>   G_END_DECLS
>
> +#define libusb_get_device_address(dev) libusb_get_port_number(dev)
>   #endif /* __WIN_USB_DEV_H__ */
>
On 03/07/2013 11:02 AM, Hans de Goede wrote:
> Hi,
>
> On 03/07/2013 12:27 AM, Uri Lublin wrote:
>> It seems that device_address is not consistent and port_number is for 
>> Windows.
>> For example the device_address may change when the WinUSB driver is
>> installed.
>> This seems to happen more for Win7 clients.
>>
>> USB devices are being redir'ed by their bus_number and device_address.
>> When the device_address before/after installing the WinUSB driver is not
>> the same, the "before" device will not be found, and an error message
>> will appear. The "after" device may or may not be redir'ed.
>>
>> Note that win-usb-dev.h is compiled only for Windows machine.
>>
>> Fixes rhbz#842816
>
> I believe this needs more testing before it can be applied. the 
> port-number
> typically is the number of the hub port, so 2 devices, 1 in the first 
> port of
> the root-hub, and one in the 1st port of another hub could / should 
> have the
> same port-number.
>
> Can you please get 2 external usb-hubs (preferable 2 identical ones) 
> and then
> check what the port-numbers are for a device plugged into the 1st port 
> of each
> hub?

Hi Hans,

Indeed, more testing with 2 external usb-hubs show that two different
devices each inserted into port 1 of two chained external usb-hubs
may get the same (bus_number, slot_number) pair.
(In chained external usb-hubs I mean that the second is connected to
a port of the first which is connected to the computer)

Thanks,
     Uri.
Hi,

On 03/07/2013 12:37 PM, Uri Lublin wrote:
> On 03/07/2013 11:02 AM, Hans de Goede wrote:
>> Hi,
>>
>> On 03/07/2013 12:27 AM, Uri Lublin wrote:
>>> It seems that device_address is not consistent and port_number is for Windows.
>>> For example the device_address may change when the WinUSB driver is
>>> installed.
>>> This seems to happen more for Win7 clients.
>>>
>>> USB devices are being redir'ed by their bus_number and device_address.
>>> When the device_address before/after installing the WinUSB driver is not
>>> the same, the "before" device will not be found, and an error message
>>> will appear. The "after" device may or may not be redir'ed.
>>>
>>> Note that win-usb-dev.h is compiled only for Windows machine.
>>>
>>> Fixes rhbz#842816
>>
>> I believe this needs more testing before it can be applied. the port-number
>> typically is the number of the hub port, so 2 devices, 1 in the first port of
>> the root-hub, and one in the 1st port of another hub could / should have the
>> same port-number.
>>
>> Can you please get 2 external usb-hubs (preferable 2 identical ones) and then
>> check what the port-numbers are for a device plugged into the 1st port of each
>> hub?
>
> Hi Hans,
>
> Indeed, more testing with 2 external usb-hubs show that two different
> devices each inserted into port 1 of two chained external usb-hubs
> may get the same (bus_number, slot_number) pair.
> (In chained external usb-hubs I mean that the second is connected to
> a port of the first which is connected to the computer)

:(

I already was afraid of that. An alternative (which is only available in
libusbx unfortunately) is libusb_get_port_path:
http://libusbx.sourceforge.net/api-1.0/group__dev.html#ga83a600e076b07b4eb7b594651ffe440c

But even when using that, there is another problem, what if the
user unplugs the device, and then replugs another device into the same
port? We need to be able to see the new device as truely a new
device in this case ... So I think we need to do some more thinking on
this and somehow comeup with a creative solution.

Regards,

Hans