1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

Added padding to HID messages

This commit is contained in:
slush 2013-09-09 15:37:39 +02:00
parent 813fb233a1
commit 682578f1ad

View File

@ -54,12 +54,9 @@ class HidTransport(Transport):
def _write(self, msg): def _write(self, msg):
msg = bytearray(msg) msg = bytearray(msg)
while len(msg): while len(msg):
to_send = min(63, len(msg)) # Report ID, data padded to 62 bytes
self.hid.write([63,] + list(msg[:63]) + [0]*(63-len(msg[0:63])))
#print [to_send,] + list(msg[:to_send]) msg = msg[63:]
self.hid.write([to_send,] + list(msg[:to_send]))
msg = msg[to_send:]
def _read(self): def _read(self):
(msg_type, datalen) = self._read_headers(FakeRead(self._raw_read)) (msg_type, datalen) = self._read_headers(FakeRead(self._raw_read))
@ -68,14 +65,15 @@ class HidTransport(Transport):
def _raw_read(self, length): def _raw_read(self, length):
while len(self.buffer) < length: while len(self.buffer) < length:
data = self.hid.read(64) data = self.hid.read(64)
report_id = data[0] report_id = data[0]
if report_id > 63: if report_id > 63:
# Command report # Command report
raise Exception("Not implemented") raise Exception("Not implemented")
# Payload received # Payload received, skip the report ID
self.buffer += str(bytearray(data[1:report_id+1])) self.buffer += str(bytearray(data[1:64]))
ret = self.buffer[:length] ret = self.buffer[:length]
self.buffer = self.buffer[length:] self.buffer = self.buffer[length:]