pySim.transport: Also trace card reset events in ApduTracer

Change-Id: Ia46b65124520eb2b8015dfa3f0a135b497668b92
This commit is contained in:
Harald Welte
2024-09-07 13:09:48 +02:00
parent 241d65db12
commit 2fe9b6a3e9
6 changed files with 20 additions and 7 deletions

View File

@@ -40,12 +40,18 @@ class ApduTracer:
def trace_response(self, cmd, sw, resp):
pass
def trace_reset(self):
pass
class StdoutApduTracer(ApduTracer):
"""Minimalistic APDU tracer, printing commands to stdout."""
def trace_response(self, cmd, sw, resp):
print("-> %s %s" % (cmd[:10], cmd[10:]))
print("<- %s: %s" % (sw, resp))
def trace_reset(self):
print("-- RESET")
class ProactiveHandler(abc.ABC):
"""Abstract base class representing the interface of some code that handles
the proactive commands, as returned by the card in responses to the FETCH
@@ -117,9 +123,16 @@ class LinkBase(abc.ABC):
"""
@abc.abstractmethod
def _reset_card(self):
"""Resets the card (power down/up)
"""
def reset_card(self):
"""Resets the card (power down/up)
"""
if self.apdu_tracer:
self.apdu_tracer.trace_reset()
return self._reset_card()
def send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
"""Sends an APDU with minimal processing