cezanne / usbip-win

USB/IP for Windows
GNU General Public License v3.0
1.98k stars 350 forks source link

Wrong device is selected when trying to bind it #183

Closed SvenLuebke closed 3 years ago

SvenLuebke commented 4 years ago

Dear @cezanne!

First of all thank you very much for your good work creating and improving the Windows port of USB/IP !!

80% of my devices seemed to be bindable with usbip.exe, but I got some error messages for the rest: I tried to get a USB serial device working

C:\Apps\USB\usbip_debug>usbip.exe list -l
 - busid 1-11 (138a:0090)
   Validity Sensors, Inc. : unknown product (138a:0090)
 - busid 1-130 (8087:0a2b)
   Intel Corp. : unknown product (8087:0a2b)
 - busid 1-196 (058f:9540)
   Alcor Micro Corp. : AU9540 Smartcard Reader (058f:9540)
 - busid 1-191 (045e:076c)
   Microsoft Corp. : Comfort Mouse 4500 (045e:076c)
 - busid 1-219 (1a86:7523)
   QinHeng Electronics : HL-340 USB-Serial adapter (1a86:7523)

and although I got the error 0, it wasn't binded:

C:\Apps\USB\usbip-win\Debug\x64>usbip.exe bind -b 1-219
usbip: error: failed to update driver: errorcode: 0
usbip: error: bind_device: error binding device on busid 1-219: err: 0

I added some more debug messages and saw, that it's correctly found in walker_bind(), as it stops searching for other devcies:

usbip: info: walker_bind():47 devno: 219 ; pdevno: 219 ; hardwareid: USB\VID_1A86&PID_7523&REV_0254
usbip: info: walker_attach():216 ; devno: 099 ; hardwareid: USB\VID_10C4&PID_EA60&REV_0100
usbip: info: walker_attach():223 ; friendlyname: Silicon Labs CP210x USB to UART Bridge (COM4)

In walker_attach() the application now searches for all installed USB devices and the list goes on until:

usbip: info: walker_attach():216 ; devno: 220 ; hardwareid: USB\VID_8564&PID_1000&REV_1100
usbip: info: walker_attach():229 ; devicedesc: USB Mass Storage Device
usbip: info: walker_attach():216 ; devno: 219 ; hardwareid: USB\VID_152D&PID_2329&REV_0100
usbip: info: walker_attach():229 ; devicedesc: USB Mass Storage Device
usbip: info: get_dev_property():31 ; devicedesc: USB Mass Storage Device
usbip: info: get_dev_property:36 hardwareid: USB\VID_152D&PID_2329&REV_0100

As you can see above devno: 219 is found and the application continues with this device. But the VID and PID changed completely! According to the debug messages it printed, I assume that it looks through a list with all devices which were attached to the PC. Even these ones, which are currently NOT attached. And for some reason, it finds this device number 219 there as well. So I checked the code further and found traverse_usbdevs() which gets parameter "FALSE" for even not present devices. With the changes of https://github.com/cezanne/usbip-win/pull/182/commits/a81ab69937f0d972e270ddac493c3b8a7b890db8 I can now bind AND unbind ALL of my devices. Probably this is not a final fix, but at least it's working on my side.

Best regards, Sven Lübke

cezanne commented 4 years ago

@SvenLuebke : One byte-length device number is prone to incur a collision such as your devno 219. Your fix looks a good solution to this limitation. I'll review your PR and try to merge. Thanks 👍