mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
Added padding to HID messages
This commit is contained in:
parent
813fb233a1
commit
682578f1ad
@ -22,7 +22,7 @@ class HidTransport(Transport):
|
|||||||
self.hid = None
|
self.hid = None
|
||||||
self.buffer = ''
|
self.buffer = ''
|
||||||
super(HidTransport, self).__init__(device, *args, **kwargs)
|
super(HidTransport, self).__init__(device, *args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enumerate(cls):
|
def enumerate(cls):
|
||||||
devices = []
|
devices = []
|
||||||
@ -35,7 +35,7 @@ class HidTransport(Transport):
|
|||||||
devices.append("0x%04x:0x%04x:%s" % (vendor_id, product_id, serial_number))
|
devices.append("0x%04x:0x%04x:%s" % (vendor_id, product_id, serial_number))
|
||||||
|
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
self.buffer = ''
|
self.buffer = ''
|
||||||
path = self.device.split(':')
|
path = self.device.split(':')
|
||||||
@ -53,13 +53,10 @@ 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:]
|
||||||
|
Loading…
Reference in New Issue
Block a user