2018-02-27 02:05:15 +00:00
|
|
|
import boot # noqa: F401
|
2017-10-24 11:59:09 +00:00
|
|
|
|
2017-08-14 09:08:47 +00:00
|
|
|
from trezor import io
|
2017-08-16 13:02:03 +00:00
|
|
|
from trezor import log
|
|
|
|
from trezor import loop
|
2018-02-23 18:08:34 +00:00
|
|
|
from trezor import utils
|
2016-09-21 12:21:18 +00:00
|
|
|
from trezor import wire
|
2017-08-16 13:02:03 +00:00
|
|
|
from trezor import workflow
|
|
|
|
|
2018-02-07 13:59:09 +00:00
|
|
|
from apps.common.storage import get_device_id
|
|
|
|
|
2017-08-16 13:02:03 +00:00
|
|
|
log.level = log.DEBUG
|
2016-04-28 21:48:27 +00:00
|
|
|
|
2017-08-15 13:09:09 +00:00
|
|
|
# initialize the USB stack
|
2018-01-20 22:11:21 +00:00
|
|
|
|
2018-02-03 15:13:25 +00:00
|
|
|
usb_wire = io.WebUSB(
|
|
|
|
iface_num=0,
|
|
|
|
ep_in=0x81,
|
|
|
|
ep_out=0x01,
|
|
|
|
)
|
2018-01-20 22:11:21 +00:00
|
|
|
|
|
|
|
if __debug__:
|
2018-02-03 15:13:25 +00:00
|
|
|
usb_debug = io.WebUSB(
|
2018-02-09 15:45:36 +00:00
|
|
|
iface_num=1,
|
|
|
|
ep_in=0x82,
|
|
|
|
ep_out=0x02,
|
2018-02-03 15:13:25 +00:00
|
|
|
)
|
2018-01-20 22:11:21 +00:00
|
|
|
usb_vcp = io.VCP(
|
2018-02-09 15:45:36 +00:00
|
|
|
iface_num=2,
|
|
|
|
data_iface_num=3,
|
2018-02-07 15:04:44 +00:00
|
|
|
ep_in=0x83,
|
|
|
|
ep_out=0x03,
|
|
|
|
ep_cmd=0x84,
|
2018-01-20 22:11:21 +00:00
|
|
|
)
|
2018-02-09 15:45:36 +00:00
|
|
|
else:
|
|
|
|
usb_u2f = io.HID(
|
|
|
|
iface_num=1,
|
|
|
|
ep_in=0x82,
|
|
|
|
ep_out=0x02,
|
|
|
|
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, 0x00, # LOGICAL_MAXIMUM (255)
|
|
|
|
0x75, 0x08, # REPORT_SIZE (8)
|
|
|
|
0x95, 0x40, # REPORT_COUNT (64)
|
|
|
|
0x81, 0x02, # INPUT (Data,Var,Abs)
|
|
|
|
0x09, 0x21, # USAGE (Output Report Data)
|
|
|
|
0x15, 0x00, # LOGICAL_MINIMUM (0)
|
|
|
|
0x26, 0xff, 0x00, # LOGICAL_MAXIMUM (255)
|
|
|
|
0x75, 0x08, # REPORT_SIZE (8)
|
|
|
|
0x95, 0x40, # REPORT_COUNT (64)
|
|
|
|
0x91, 0x02, # OUTPUT (Data,Var,Abs)
|
|
|
|
0xc0, # END_COLLECTION
|
|
|
|
]),
|
|
|
|
)
|
2018-01-20 22:11:21 +00:00
|
|
|
|
2017-08-14 09:08:47 +00:00
|
|
|
usb = io.USB(
|
2017-04-21 14:06:22 +00:00
|
|
|
vendor_id=0x1209,
|
|
|
|
product_id=0x53C1,
|
2018-01-20 21:04:41 +00:00
|
|
|
release_num=0x0200,
|
2017-08-14 09:08:47 +00:00
|
|
|
manufacturer="SatoshiLabs",
|
|
|
|
product="TREZOR",
|
2018-02-07 13:59:09 +00:00
|
|
|
serial_number=get_device_id(),
|
2018-01-20 21:04:41 +00:00
|
|
|
interface="TREZOR Interface",
|
2017-08-14 09:08:47 +00:00
|
|
|
)
|
2018-01-20 22:11:21 +00:00
|
|
|
|
2017-08-14 09:08:47 +00:00
|
|
|
usb.add(usb_wire)
|
2017-10-30 16:34:21 +00:00
|
|
|
if __debug__:
|
|
|
|
usb.add(usb_debug)
|
2018-01-20 22:11:21 +00:00
|
|
|
usb.add(usb_vcp)
|
2018-02-09 15:45:36 +00:00
|
|
|
else:
|
|
|
|
usb.add(usb_u2f)
|
2016-10-11 10:33:02 +00:00
|
|
|
|
2017-08-15 13:09:09 +00:00
|
|
|
# load applications
|
|
|
|
from apps import homescreen
|
|
|
|
from apps import management
|
|
|
|
from apps import wallet
|
|
|
|
from apps import ethereum
|
2018-02-09 15:45:36 +00:00
|
|
|
if __debug__:
|
|
|
|
from apps import debug
|
|
|
|
else:
|
|
|
|
from apps import fido_u2f
|
2017-08-15 13:09:09 +00:00
|
|
|
|
|
|
|
# boot applications
|
|
|
|
homescreen.boot()
|
|
|
|
management.boot()
|
|
|
|
wallet.boot()
|
|
|
|
ethereum.boot()
|
2018-02-09 15:45:36 +00:00
|
|
|
if __debug__:
|
|
|
|
debug.boot()
|
|
|
|
else:
|
|
|
|
fido_u2f.boot(usb_u2f)
|
2017-08-15 13:09:09 +00:00
|
|
|
|
2017-08-21 11:22:44 +00:00
|
|
|
# initialize the wire codec and start the USB
|
2017-08-15 13:09:09 +00:00
|
|
|
wire.setup(usb_wire)
|
2017-10-30 16:34:21 +00:00
|
|
|
if __debug__:
|
|
|
|
wire.setup(usb_debug)
|
2017-08-21 11:22:44 +00:00
|
|
|
usb.open()
|
2016-09-21 12:21:18 +00:00
|
|
|
|
2018-02-23 19:35:05 +00:00
|
|
|
utils.set_mode_unprivileged()
|
2018-02-23 18:08:34 +00:00
|
|
|
|
2017-08-15 13:09:09 +00:00
|
|
|
# load default homescreen
|
2018-02-27 15:35:21 +00:00
|
|
|
from apps.homescreen.homescreen import homescreen
|
2016-04-28 21:48:27 +00:00
|
|
|
|
2017-08-15 13:09:09 +00:00
|
|
|
# run main even loop and specify which screen is default
|
2018-02-27 15:35:21 +00:00
|
|
|
workflow.startdefault(homescreen)
|
2017-08-21 11:22:44 +00:00
|
|
|
loop.run()
|