thegecko / webusb

Node.js implementation of the WebUSB Specification
https://thegecko.github.io/webusb/
MIT License
183 stars 27 forks source link

Duplicate filtering functions don't agreee #74

Closed pelikhan closed 3 years ago

pelikhan commented 3 years ago

We have a device that requires this code path to match.

https://github.com/thegecko/webusb/blob/0a3f33156129f9e042ede361aab69164b0a00588/src/usb.ts#L173

But the device pre-filter does not have this code path.

https://github.com/thegecko/webusb/blob/0a3f33156129f9e042ede361aab69164b0a00588/src/adapter.ts#L256

Should both filter be merged?

thegecko commented 3 years ago

Hmm, the usb.ts case follows the WebUSB specification correctly AFAICT.

The filter in the adapter is different and was used to find allowedDevices already selected. This bit is quite difficult as recognising a device as the same between plugs is hard (the unique address on the bus can change and other IDs such as SerialNumber and vid/pid are either optional or not unique).

My approach was to use a filter, but it's far from ideal, perhaps it should be swapped to storing a hash of known data.

This aside, I can see the same filter is being used here:

https://github.com/thegecko/webusb/blob/0a3f33156129f9e042ede361aab69164b0a00588/src/usb.ts#L291

And it probably shouldn't, hence the issue you are seeing!

thegecko commented 3 years ago

@pelikhan Does deleting these lines fix your issue?

https://github.com/thegecko/webusb/blob/0a3f33156129f9e042ede361aab69164b0a00588/src/adapter.ts#L255-L262

pelikhan commented 3 years ago

it goes through but then i get LIBUSB_ERROR_NOT_FOUND so my setup does not seem to be ok :( :( :(, but at least it finds a device.

pelikhan commented 3 years ago

Thanks’