pySim-trace: mark card reset in the trace

The trace log currently does not contain any information about card
resets. This makes the trace difficult to follow. Let's use the
CardReset object to display the ATR in the trace.

Related: OS#6094
Change-Id: Ia550a8bd2f45d2ad622cb2ac2a2905397db76bce
This commit is contained in:
Philipp Maier 2023-07-27 11:46:26 +02:00
parent 1f46f07e3c
commit 162ba3af3e
5 changed files with 18 additions and 4 deletions

View File

@ -93,6 +93,11 @@ class Tracer:
print("%02u %-16s %-35s %-8s %s %s" % (inst.lchan_nr, inst._name, inst.path_str, inst.col_id, inst.col_sw, inst.processed))
print("===============================")
def format_reset(self, apdu: CardReset):
"""Output a single decoded CardReset."""
print(apdu)
print("===============================")
def main(self):
"""Main loop of tracer: Iterates over all Apdu received from source."""
while True:
@ -101,6 +106,7 @@ class Tracer:
if isinstance(apdu, CardReset):
self.rs.reset()
self.format_reset(apdu)
continue
# ask ApduDecoder to look-up (INS,CLA) + instantiate an ApduCommand derived

View File

@ -448,4 +448,11 @@ class ApduDecoder(ApduHandler):
class CardReset:
pass
def __init__(self, atr: bytes):
self.atr = atr
def __str__(self):
if (self.atr):
return '%s(%s)' % (type(self).__name__, b2h(self.atr))
else:
return '%s' % (type(self).__name__)

View File

@ -49,7 +49,7 @@ class GsmtapApduSource(ApduSource):
return ApduCommands.parse_cmd_bytes(gsmtap_msg['body'])
elif sub_type == 'atr':
# card has been reset
return CardReset()
return CardReset(gsmtap_msg['body'])
elif sub_type in ['pps_req', 'pps_rsp']:
# simply ignore for now
pass

View File

@ -69,7 +69,7 @@ class _PysharkGsmtap(ApduSource):
return ApduCommands.parse_cmd_bytes(gsmtap_msg['body'])
elif sub_type == 'atr':
# card has been reset
return CardReset()
return CardReset(gsmtap_msg['body'])
elif sub_type in ['pps_req', 'pps_rsp']:
# simply ignore for now
pass

View File

@ -117,7 +117,8 @@ class _PysharkRspro(ApduSource):
vccPresent, resetActive, clkActive = self.get_pstatus(slot_pstatus)
if vccPresent and clkActive and not resetActive:
logger.debug("RESET")
return CardReset()
#TODO: extract ATR from RSPRO message and use it here
return CardReset(None)
else:
print("Unhandled msg type %s: %s" % (msg_type, rspro_msg))