dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33960 )
Change subject: pySim-trace: mark card reset in the trace ......................................................................
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 --- M pySim-trace.py M pySim/apdu/__init__.py M pySim/apdu_source/gsmtap.py M pySim/apdu_source/pyshark_gsmtap.py M pySim/apdu_source/pyshark_rspro.py 5 files changed, 32 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/60/33960/1
diff --git a/pySim-trace.py b/pySim-trace.py index 453ee43..c93a339 100755 --- a/pySim-trace.py +++ b/pySim-trace.py @@ -93,6 +93,11 @@ 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 + processed ApduCommand.""" + print(apdu) + print("===============================") + def main(self): """Main loop of tracer: Iterates over all Apdu received from source.""" while True: @@ -101,6 +106,7 @@
if isinstance(apdu, CardReset): self.rs.reset() + self.format_reset(apdu) continue
# ask ApduDecoder to look-up (INS,CLA) + instantiate an ApduCommand derived diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py index cc0f701..b884e23 100644 --- a/pySim/apdu/__init__.py +++ b/pySim/apdu/__init__.py @@ -448,4 +448,11 @@
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__) diff --git a/pySim/apdu_source/gsmtap.py b/pySim/apdu_source/gsmtap.py index fe450e2..aaf97ad 100644 --- a/pySim/apdu_source/gsmtap.py +++ b/pySim/apdu_source/gsmtap.py @@ -49,7 +49,7 @@ 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 diff --git a/pySim/apdu_source/pyshark_gsmtap.py b/pySim/apdu_source/pyshark_gsmtap.py index 8ea9ae7..aa7b624 100644 --- a/pySim/apdu_source/pyshark_gsmtap.py +++ b/pySim/apdu_source/pyshark_gsmtap.py @@ -69,7 +69,7 @@ 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 diff --git a/pySim/apdu_source/pyshark_rspro.py b/pySim/apdu_source/pyshark_rspro.py index 499e9ff..8c614ff 100644 --- a/pySim/apdu_source/pyshark_rspro.py +++ b/pySim/apdu_source/pyshark_rspro.py @@ -117,7 +117,8 @@ 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))