trezor / cython-hidapi

:snake: Python wrapper for the HIDAPI
Other
285 stars 110 forks source link

hid.enumerate changed behaviour from 0.14.0 to 0.14.0post2 #181

Closed jremmet closed 2 months ago

jremmet commented 2 months ago

We install hidapi via pip and run into a changed result of hid.enumerate() under linux:

0.14.0

pprint([d for d in hid.enumerate() if d['vendor_id'] == 1240])
 {'interface_number': 2,
  'manufacturer_string': 'Phytec Messtechnik GmbH',
  'path': b'1-5.3.3.4:1.2',
  'product_id': 221,
  'product_string': 'DH-013.A0',
  'release_number': 256,
  'serial_number': '',
  'usage': 0,
  'usage_page': 0,
  'vendor_id': 1240}

hid.device().open_path(b'1-5.3.3.4:1.2')

0.14.0post2

pprint([d for d in hid.enumerate() if d['vendor_id'] == 1240])
 {'bus_type': 1,
  'interface_number': 2,
  'manufacturer_string': 'Phytec Messtechnik GmbH',
  'path': b'/dev/hidraw5',
  'product_id': 221,
  'product_string': 'DH-013.A0',
  'release_number': 256,
  'serial_number': '',
  'usage': 1,
  'usage_page': 65280,
  'vendor_id': 1240},

>>> hid.device().open_path(b'/dev/hidraw5')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "hidraw.pyx", line 158, in hid.device.open_path
OSError: open failed
>>> hid.device().open_path(b'1-5.3.3.4:1.2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "hidraw.pyx", line 158, in hid.device.open_path
OSError: open failed

The chip is a branded MCP2221. Linux kernel driver hid_mcp2221 is blacklisted

I stumbled over this: test_venv3/lib/python3.10/site-packages/hidapi-0.14.0.dist-info/RECORD:hidapi.libs/libusb-1-150b88da.0.so.0.1.0,sha256=0F1IdhpGybnMo2ZCKSF4EyTehIy023YNTgl2lKz2R2g,118537 which is missing in hidapi-0.14.0.post2 Not sure if this means that its without libusb suport. (Which should be there from: https://github.com/trezor/cython-hidapi/commit/690824080c360c60276e4da0f873bd3df223a502 ad far as I understand)

prusnak commented 2 months ago

do you have user access to read /dev/hidraw5? (run ls -l /dev/hidraw5)

i think you need to adapt your udev rules or run as root

jremmet commented 2 months ago

Thanks, after altering the udev rules the mcp2111 works again. Does this mean the default for the wheels are switched to hidraw interface?

prusnak commented 2 months ago

Does this mean the default for the wheels are switched to hidraw interface?

Yes

bearsh commented 2 months ago

Does this mean the default for the wheels are switched to hidraw interface?

Yes

@prusnak is this mentioned somewhere? I assume this will break many applications... maybe #166 should then be updated...

prusnak commented 2 months ago

@prusnak is this mentioned somewhere? I assume this will break many applications...

maybe #166 should then be updated...

How exactly should the change break applications?

bearsh commented 2 months ago

well she this bug.

when the default hid backend changes, the user/application needs to e.g. adjust the udev rules. furthermore path completely changes, so if the application relies on it, it will most probably fail.