trezor-core/src/apps/debug/__init__.py

70 lines
2.3 KiB
Python
Raw Normal View History

2016-12-08 07:18:12 -08:00
from trezor.wire import register, protobuf_workflow
from trezor.messages.wire_types import \
DebugLinkDecision, DebugLinkGetState, DebugLinkStop, \
DebugLinkMemoryRead, DebugLinkMemoryWrite, DebugLinkFlashErase
2016-11-15 02:50:45 -08:00
2016-12-08 07:18:12 -08:00
async def dispatch_DebugLinkDecision(session_id, msg):
from trezor.ui.confirm import CONFIRMED, CANCELLED
2016-12-17 04:20:57 -08:00
from apps.common.confirm import signal
signal.send(CONFIRMED if msg.yes_no else CANCELLED)
2016-11-15 02:50:45 -08:00
2016-12-08 07:18:12 -08:00
async def dispatch_DebugLinkGetState(session_id, msg):
from trezor.messages.DebugLinkState import DebugLinkState
2016-12-17 04:20:57 -08:00
from apps.common import storage, request_pin
from apps.management import reset_device
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
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-15 02:50:45 -08:00
# TODO: handle other fields:
# 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-12-08 07:18:12 -08:00
async def dispatch_DebugLinkStop(session_id, msg):
pass
2016-11-15 02:50:45 -08:00
2016-12-08 07:18:12 -08:00
async def dispatch_DebugLinkMemoryRead(session_id, msg):
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-12-08 07:18:12 -08:00
async def dispatch_DebugLinkMemoryWrite(session_id, msg):
from uctypes import bytearray_at
l = len(msg.memory)
data = bytearray_at(msg.address, l)
data[0:l] = msg.memory
2016-11-15 02:50:45 -08:00
2016-12-08 07:18:12 -08:00
async def dispatch_DebugLinkFlashErase(session_id, msg):
# TODO: erase(msg.sector)
pass
2016-11-15 02:50:45 -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)