1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00

debuglink: fix debuglink for V2

This commit is contained in:
Jan Pochyla 2016-11-15 13:46:00 +01:00
parent c12bfc4add
commit 737200c7ef
2 changed files with 8 additions and 0 deletions

View File

@ -15,11 +15,13 @@ def pprint(msg):
class DebugLink(object):
def __init__(self, transport, pin_func=pin_info, button_func=button_press):
self.transport = transport
self.transport.session_begin()
self.pin_func = pin_func
self.button_func = button_func
def close(self):
self.transport.session_end()
self.transport.close()
def _call(self, msg, nowait=False):

View File

@ -156,6 +156,9 @@ class TransportV1(Transport):
class TransportV2(Transport):
def write(self, msg):
if not self.session_id:
raise Exception('Missing session_id for v2 transport')
data = bytearray(msg.SerializeToString())
# Convert to unsigned in python2
@ -185,6 +188,9 @@ class TransportV2(Transport):
first = False
def _read(self):
if not self.session_id:
raise Exception('Missing session_id for v2 transport')
chunk = self._read_chunk()
(session_id, msg_type, datalen, data) = self.parse_first(chunk)
payloadlen = datalen + 4 # For the checksum