From b60ab51f9bae81722562107f504dd953d8c8fdaf Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Mon, 4 Sep 2017 17:30:07 +0200 Subject: [PATCH] transport_hid: more strict interface detection --- trezorlib/transport_hid.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/trezorlib/transport_hid.py b/trezorlib/transport_hid.py index ef3bf13bbc..f42c8b8ef8 100644 --- a/trezorlib/transport_hid.py +++ b/trezorlib/transport_hid.py @@ -53,11 +53,18 @@ class HidTransport(Transport): @staticmethod def enumerate(debug=False): - return [ - HidTransport(dev) for dev in hid.enumerate(0, 0) - if ((is_trezor1(dev) or is_trezor2(dev) or is_trezor2_bl(dev)) and - (is_debug(dev) == debug)) - ] + devices = [] + for dev in hid.enumerate(0, 0): + if not (is_trezor1(dev) or is_trezor2(dev) or is_trezor2_bl(dev)): + continue + if debug: + if not is_debuglink(dev): + continue + else: + if not is_wirelink(dev): + continue + devices.append(HidTransport(dev)) + return devices @staticmethod def find_by_path(path=None): @@ -148,5 +155,9 @@ def is_trezor2_bl(dev): return (dev['vendor_id'], dev['product_id']) == DEV_TREZOR2_BL -def is_debug(dev): - return (dev['usage_page'] == 0xFF01 or dev['interface_number'] == 1) +def is_wirelink(dev): + return (dev['usage_page'] == 0xFF00 or dev['interface_number'] == 0) + + +def is_debuglink(dev): + return (dev['usage_page'] == 0xFF01 or dev['interface_number'] == 1) \ No newline at end of file