self.out_ann = self.register(srd.OUTPUT_ANN)
def output_tx_bytes(self):
- if len(self.bytes) < 1: # Ignore wakeup.
+ b = self.bytes
+ if len(b) < 1: # Ignore wakeup.
return
- self.waddr = self.bytes[0][2]
- self.display_waddr(self.bytes[0])
+ self.waddr = b[0][2]
+ self.display_waddr(b[0])
if self.waddr == WORD_ADDR_COMMAND:
- count = self.bytes[1][2]
- self.display_count(self.bytes[1])
- if len(self.bytes) - 1 != count:
- self.display_warning(self.bytes[0][0], self.bytes[-1][1],
+ count = b[1][2]
+ self.display_count(b[1])
+ if len(b) - 1 != count:
+ self.display_warning(b[0][0], b[-1][1],
'Invalid frame length: Got {}, expecting {} '.format(
- len(self.bytes) - 1, count))
+ len(b) - 1, count))
return
- self.opcode = self.bytes[2][2]
- self.display_opcode(self.bytes[2])
- self.display_param1(self.bytes[3])
- self.display_param2([self.bytes[4], self.bytes[5]])
- self.display_data(self.bytes[6:-2])
- self.display_crc([self.bytes[-2], self.bytes[-1]])
+ self.opcode = b[2][2]
+ self.display_opcode(b[2])
+ self.display_param1(b[3])
+ self.display_param2([b[4], b[5]])
+ self.display_data(b[6:-2])
+ self.display_crc([b[-2], b[-1]])
def output_rx_bytes(self):
- count = self.bytes[0][2]
- self.display_count(self.bytes[0])
+ b = self.bytes
+ count = b[0][2]
+ self.display_count(b[0])
if self.waddr == WORD_ADDR_RESET:
- self.display_data([self.bytes[1]])
- self.display_crc([self.bytes[2], self.bytes[3]])
- self.display_status(self.bytes[0][0], self.bytes[-1][1], self.bytes[1][2])
+ self.display_data([b[1]])
+ self.display_crc([b[2], b[3]])
+ self.display_status(b[0][0], b[-1][1], b[1][2])
elif self.waddr == WORD_ADDR_COMMAND:
if count == 4: # Status / Error.
- self.display_data([self.bytes[1]])
- self.display_crc([self.bytes[2], self.bytes[3]])
- self.display_status(self.bytes[0][0], self.bytes[-1][1], self.bytes[1][2])
+ self.display_data([b[1]])
+ self.display_crc([b[2], b[3]])
+ self.display_status(b[0][0], b[-1][1], b[1][2])
else:
- self.display_data(self.bytes[1:-2])
- self.display_crc([self.bytes[-2], self.bytes[-1]])
+ self.display_data(b[1:-2])
+ self.display_crc([b[-2], b[-1]])
def display_waddr(self, data):
self.put(data[0], data[1], self.out_ann, [0, ['Word addr: %s' % WORD_ADDR[data[2]]]])
self.put(data[0], data[1], self.out_ann, [2, ['Opcode: %s' % OPCODES[data[2]]]])
def display_param1(self, data):
- if (self.opcode == OPCODE_CHECK_MAC) or (self.opcode == OPCODE_DEV_REV) or \
- (self.opcode == OPCODE_HMAC) or (self.opcode == OPCODE_MAC) or \
- (self.opcode == OPCODE_NONCE) or (self.opcode == OPCODE_RANDOM) or \
- (self.opcode == OPCODE_SHA):
+ op = self.opcode
+ if op in (OPCODE_CHECK_MAC, OPCODE_DEV_REV, OPCODE_HMAC, \
+ OPCODE_MAC, OPCODE_NONCE, OPCODE_RANDOM, OPCODE_SHA):
self.put(data[0], data[1], self.out_ann, [3, ['Mode: %02X' % data[2]]])
- elif self.opcode == OPCODE_DERIVE_KEY:
+ elif op == OPCODE_DERIVE_KEY:
self.put(data[0], data[1], self.out_ann, [3, ['Random: %s' % data[2]]])
- elif self.opcode == OPCODE_GEN_DIG:
+ elif op == OPCODE_GEN_DIG:
self.put(data[0], data[1], self.out_ann, [3, ['Zone: %s' % ZONES[data[2]]]])
- elif self.opcode == OPCODE_LOCK:
+ elif op == OPCODE_LOCK:
self.put(data[0], data[1], self.out_ann, [3, ['Zone: {}, Summary: {}'.format(
'DATA/OTP' if data[2] else 'CONFIG',
'Ignored' if data[2] & 0x80 else 'Used')]])
- elif self.opcode == OPCODE_PAUSE:
+ elif op == OPCODE_PAUSE:
self.put(data[0], data[1], self.out_ann, [3, ['Selector: %02X' % data[2]]])
- elif self.opcode == OPCODE_READ:
+ elif op == OPCODE_READ:
self.put(data[0], data[1], self.out_ann, [3, ['Zone: {}, Length: {}'.format(ZONES[data[2] & 0x03],
'32 bytes' if data[2] & 0x90 else '4 bytes')]])
- elif self.opcode == OPCODE_WRITE:
+ elif op == OPCODE_WRITE:
self.put(data[0], data[1], self.out_ann, [3, ['Zone: {}, Encrypted: {}, Length: {}'.format(ZONES[data[2] & 0x03],
'Yes' if data[2] & 0x40 else 'No', '32 bytes' if data[2] & 0x90 else '4 bytes')]])
else:
self.put(data[0], data[1], self.out_ann, [3, ['Param1: %02X' % data[2]]])
def display_param2(self, data):
- if self.opcode == OPCODE_DERIVE_KEY:
+ op = self.opcode
+ if op == OPCODE_DERIVE_KEY:
self.put(data[0][0], data[1][1], self.out_ann, [4, ['TargetKey: {:02x} {:02x}'.format(data[1][2], data[0][2])]])
- elif (self.opcode == OPCODE_NONCE) or (self.opcode == OPCODE_PAUSE) or (self.opcode == OPCODE_RANDOM):
+ elif op in (OPCODE_NONCE, OPCODE_PAUSE, OPCODE_RANDOM):
self.put(data[0][0], data[1][1], self.out_ann, [4, ['Zero: {:02x} {:02x}'.format(data[1][2], data[0][2])]])
- elif (self.opcode == OPCODE_HMAC) or (self.opcode == OPCODE_MAC) or \
- (self.opcode == OPCODE_CHECK_MAC) or (self.opcode == OPCODE_GEN_DIG):
+ elif op in (OPCODE_HMAC, OPCODE_MAC, OPCODE_CHECK_MAC, OPCODE_GEN_DIG):
self.put(data[0][0], data[1][1], self.out_ann, [4, ['SlotID: {:02x} {:02x}'.format(data[1][2], data[0][2])]])
- elif self.opcode == OPCODE_LOCK:
+ elif op == OPCODE_LOCK:
self.put(data[0][0], data[1][1], self.out_ann, [4, ['Summary: {:02x} {:02x}'.format(data[1][2], data[0][2])]])
- elif (self.opcode == OPCODE_READ) or (self.opcode == OPCODE_WRITE):
+ elif op in (OPCODE_READ, OPCODE_WRITE):
self.put(data[0][0], data[1][1], self.out_ann, [4, ['Address: {:02x} {:02x}'.format(data[1][2], data[0][2])]])
- elif self.opcode == OPCODE_UPDATE_EXTRA:
+ elif op == OPCODE_UPDATE_EXTRA:
self.put(data[0][0], data[1][1], self.out_ann, [4, ['NewValue: {:02x}'.format(data[0][2])]])
else:
self.put(data[0][0], data[1][1], self.out_ann, [4, ['-']])
def display_data(self, data):
if len(data) == 0:
return
- if self.opcode == OPCODE_CHECK_MAC:
+ op = self.opcode
+ if op == OPCODE_CHECK_MAC:
self.put(data[0][0], data[31][1], self.out_ann, [5, ['ClientChal: %s' % ' '.join(format(i[2], '02x') for i in data[0:31])]])
self.put(data[32][0], data[63][1], self.out_ann, [5, ['ClientResp: %s' % ' '.join(format(i[2], '02x') for i in data[32:63])]])
self.put(data[64][0], data[76][1], self.out_ann, [5, ['OtherData: %s' % ' '.join(format(i[2], '02x') for i in data[64:76])]])
- elif self.opcode == OPCODE_DERIVE_KEY:
+ elif op == OPCODE_DERIVE_KEY:
self.put(data[0][0], data[31][1], self.out_ann, [5, ['MAC: %s' % ' '.join(format(i[2], '02x') for i in data)]])
- elif self.opcode == OPCODE_GEN_DIG:
+ elif op == OPCODE_GEN_DIG:
self.put(data[0][0], data[3][1], self.out_ann, [5, ['OtherData: %s' % ' '.join(format(i[2], '02x') for i in data)]])
- elif self.opcode == OPCODE_MAC:
+ elif op == OPCODE_MAC:
self.put(data[0][0], data[31][1], self.out_ann, [5, ['Challenge: %s' % ' '.join(format(i[2], '02x') for i in data)]])
- elif self.opcode == OPCODE_WRITE:
+ elif op == OPCODE_WRITE:
if len(data) > 32: # Value + MAC.
self.put(data[0][0], data[-31][1], self.out_ann, [5, ['Value: %s' % ' '.join(format(i[2], '02x') for i in data)]])
self.put(data[-32][0], data[-1][1], self.out_ann, [5, ['MAC: %s' % ' '.join(format(i[2], '02x') for i in data)]])