from storage.device import get_device_id from trezor import io, utils # interface used for trezor wire protocol iface_wire = io.WebUSB(iface_num=0, ep_in=0x81, ep_out=0x01) if __debug__: # interface used for debug messages with trezor wire protocol iface_debug = io.WebUSB(iface_num=1, ep_in=0x82, ep_out=0x02) if not utils.BITCOIN_ONLY: # interface used for FIDO/U2F and FIDO2/WebAuthn HID transport iface_webauthn = io.HID( iface_num=2 if __debug__ else 1, ep_in=0x83 if __debug__ else 0x82, ep_out=0x03 if __debug__ else 0x02, # fmt: off report_desc=bytes([ 0x06, 0xd0, 0xf1, # USAGE_PAGE (FIDO Alliance) 0x09, 0x01, # USAGE (U2F HID Authenticator Device) 0xa1, 0x01, # COLLECTION (Application) 0x09, 0x20, # USAGE (Input Report Data) 0x15, 0x00, # LOGICAL_MINIMUM (0) 0x26, 0xff,
from trezor import io from trezor import log from trezor import loop from trezor import utils from trezor import wire from trezor import workflow from apps.common.storage import get_device_id log.level = log.DEBUG # initialize the USB stack usb_wire = io.WebUSB( iface_num=0, ep_in=0x81, ep_out=0x01, ) if __debug__: usb_debug = io.WebUSB( iface_num=1, ep_in=0x82, ep_out=0x02, ) usb_vcp = io.VCP( iface_num=2, data_iface_num=3, ep_in=0x83, ep_out=0x03, ep_cmd=0x84,
ENABLE_IFACE_WEBAUTHN = not utils.BITCOIN_ONLY # We only have 10 available USB endpoints on real HW, of which 2 are taken up by the USB descriptor. # iface_wire, iface_debug and iface_webauthn also consume 2 each, iface_vcp uses 3. # That is a grand total of 11. That means that we can't enable everything at the same time. # By default, iface_vcp is only enabled on bitcoin_only firmware, where iface_webauthn # is disabled. Implementation-wise, we check if any of the previous ifaces is disabled # in order to enable VCP. ENABLE_IFACE_VCP = __debug__ and (utils.EMULATOR or not ENABLE_IFACE_DEBUG or not ENABLE_IFACE_WEBAUTHN) # interface used for trezor wire protocol id_wire = next(_iface_iter) iface_wire = io.WebUSB( iface_num=id_wire, ep_in=0x81 + id_wire, ep_out=0x01 + id_wire, emu_port=UDP_PORT + WIRE_PORT_OFFSET, ) # XXXXXXXXXXXXXXXXXXX # # We want the following branches present only in their respective firmwares. To achieve # that, we are taking advantage of the upy compiler static optimization: when an # if-expression statically evaluates to False, the branch is excluded from the bytecode. # This works magically for the __debug__ builtin, and `utils.BITCOIN_ONLY` is replaced # by a literal True/False by us in the build step. # # Therefore, each of the following needs to include the respective static expression # so that it can be correctly excluded from the resulting build. if __debug__ and ENABLE_IFACE_DEBUG:
from trezor import io from trezor import log from trezor import loop from trezor import wire from trezor import workflow USE_WEBUSB = False log.level = log.DEBUG # initialize the USB stack if USE_WEBUSB: usb_wire = io.WebUSB( iface_num=0, ep_in=0x81, ep_out=0x01, ) else: usb_wire = io.HID( iface_num=0, ep_in=0x81, ep_out=0x01, report_desc=bytes([ 0x06, 0x00, 0xff, # USAGE_PAGE (Vendor Defined) 0x09, 0x01, # USAGE (1) 0xa1, 0x01, # COLLECTION (Application)