2016-12-08 07:18:12 -08:00
|
|
|
from trezor.wire import register, protobuf_workflow
|
2016-11-14 13:13:32 -08:00
|
|
|
from trezor.messages.wire_types import \
|
|
|
|
DebugLinkDecision, DebugLinkGetState, DebugLinkStop, \
|
|
|
|
DebugLinkMemoryRead, DebugLinkMemoryWrite, DebugLinkFlashErase
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-11-14 13:13:32 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkDecision(session_id, msg):
|
2016-11-15 04:48:52 -08:00
|
|
|
from trezor.ui.confirm import CONFIRMED, CANCELLED
|
2016-12-17 04:20:57 -08:00
|
|
|
from apps.common.confirm import signal
|
2016-11-25 06:42:33 -08:00
|
|
|
signal.send(CONFIRMED if msg.yes_no else CANCELLED)
|
2016-11-14 13:13:32 -08:00
|
|
|
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkGetState(session_id, msg):
|
2016-11-14 13:13:32 -08:00
|
|
|
from trezor.messages.DebugLinkState import DebugLinkState
|
2016-12-17 04:20:57 -08:00
|
|
|
from apps.common import storage, request_pin
|
2017-01-24 05:13:07 -08:00
|
|
|
from apps.management import reset_device
|
2016-11-16 05:23:28 -08:00
|
|
|
|
|
|
|
if request_pin.matrix:
|
|
|
|
matrix = ''.join([str(d) for d in request_pin.matrix.digits])
|
|
|
|
else:
|
|
|
|
matrix = None
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2017-01-24 05:13:07 -08:00
|
|
|
m = DebugLinkState()
|
|
|
|
m.pin = storage.config_get(storage.PIN).decode()
|
|
|
|
m.mnemonic = storage.config_get(storage.MNEMONIC).decode()
|
|
|
|
m.passphrase_protection = storage.is_protected_by_passphrase()
|
|
|
|
m.matrix = matrix
|
|
|
|
m.reset_entropy = reset_device.internal_entropy
|
|
|
|
m.reset_word = reset_device.current_word
|
2016-11-16 05:23:28 -08:00
|
|
|
|
2016-11-15 02:50:45 -08:00
|
|
|
# TODO: handle other fields:
|
2016-11-14 13:13:32 -08:00
|
|
|
# f.recovery_fake_word = recovery_get_fake_word()
|
|
|
|
# f.recovery_word_pos = recovery_get_word_pos()
|
|
|
|
# f.node = storage.get_node()
|
2016-11-15 02:50:45 -08:00
|
|
|
|
|
|
|
return m
|
|
|
|
|
2016-11-14 13:13:32 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkStop(session_id, msg):
|
2016-11-14 13:13:32 -08:00
|
|
|
pass
|
|
|
|
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkMemoryRead(session_id, msg):
|
2017-05-15 14:10:03 -07:00
|
|
|
from trezor.messages.DebugLinkMemory import DebugLinkMemory
|
|
|
|
from uctypes import bytes_at
|
|
|
|
m = DebugLinkMemory()
|
|
|
|
m.memory = bytes_at(msg.address, msg.length)
|
|
|
|
return m
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-11-14 13:13:32 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkMemoryWrite(session_id, msg):
|
2017-05-15 14:10:03 -07:00
|
|
|
from uctypes import bytearray_at
|
|
|
|
l = len(msg.memory)
|
|
|
|
data = bytearray_at(msg.address, l)
|
|
|
|
data[0:l] = msg.memory
|
2016-11-14 13:13:32 -08:00
|
|
|
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-12-08 07:18:12 -08:00
|
|
|
async def dispatch_DebugLinkFlashErase(session_id, msg):
|
2016-11-14 13:13:32 -08:00
|
|
|
# TODO: erase(msg.sector)
|
|
|
|
pass
|
|
|
|
|
2016-11-15 02:50:45 -08:00
|
|
|
|
2016-11-14 13:13:32 -08:00
|
|
|
def boot():
|
2016-12-08 07:18:12 -08:00
|
|
|
register(DebugLinkDecision, protobuf_workflow, dispatch_DebugLinkDecision)
|
|
|
|
register(DebugLinkGetState, protobuf_workflow, dispatch_DebugLinkGetState)
|
|
|
|
register(DebugLinkStop, protobuf_workflow, dispatch_DebugLinkStop)
|
|
|
|
register(DebugLinkMemoryRead, protobuf_workflow, dispatch_DebugLinkMemoryRead)
|
|
|
|
register(DebugLinkMemoryWrite, protobuf_workflow, dispatch_DebugLinkMemoryWrite)
|
|
|
|
register(DebugLinkFlashErase, protobuf_workflow, dispatch_DebugLinkFlashErase)
|