laforge has submitted this change. (
https://gerrit.osmocom.org/c/pysim/+/38055?usp=email
)
Change subject: pySim.transport: Also trace card reset events in ApduTracer
......................................................................
pySim.transport: Also trace card reset events in ApduTracer
Change-Id: Ia46b65124520eb2b8015dfa3f0a135b497668b92
---
M pySim-trace.py
M pySim/transport/__init__.py
M pySim/transport/calypso.py
M pySim/transport/modem_atcmd.py
M pySim/transport/pcsc.py
M pySim/transport/serial.py
6 files changed, 20 insertions(+), 7 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim-trace.py b/pySim-trace.py
index 3652b3a..46d4c40 100755
--- a/pySim-trace.py
+++ b/pySim-trace.py
@@ -65,7 +65,7 @@
def disconnect(self):
pass
- def reset_card(self):
+ def _reset_card(self):
return 1
def get_atr(self):
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 856e86e..9482528 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -40,12 +40,18 @@
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 @@
"""
@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
diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py
index d8e5b89..9462939 100644
--- a/pySim/transport/calypso.py
+++ b/pySim/transport/calypso.py
@@ -109,7 +109,7 @@
rsp = self.sock.recv(exp_len)
return rsp
- def reset_card(self):
+ def _reset_card(self):
# Request FULL reset
req_msg = L1CTLMessageReset()
self.sock.send(req_msg.gen_msg())
diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py
index 882cb65..8970f7d 100644
--- a/pySim/transport/modem_atcmd.py
+++ b/pySim/transport/modem_atcmd.py
@@ -125,7 +125,7 @@
return
raise ReaderError('Interface \'%s\' does not respond to
\'AT\' command' % self._device)
- def reset_card(self):
+ def _reset_card(self):
# Reset the modem, just to be sure
if self.send_at_cmd('ATZ') != [b'OK']:
raise ReaderError('Failed to reset the modem')
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index 7843f7f..207cf6c 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -97,7 +97,7 @@
def disconnect(self):
self._con.disconnect()
- def reset_card(self):
+ def _reset_card(self):
self.disconnect()
self.connect()
return 1
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index e155226..04b4ab7 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -101,15 +101,15 @@
def disconnect(self):
pass # Nothing to do really ...
- def reset_card(self):
- rv = self._reset_card()
+ def _reset_card(self):
+ rv = self.__reset_card()
if rv == 0:
raise NoCardError()
if rv < 0:
raise ProtocolError()
return rv
- def _reset_card(self):
+ def __reset_card(self):
self._atr = None
rst_meth_map = {
'rts': self._sl.setRTS,
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/38055?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia46b65124520eb2b8015dfa3f0a135b497668b92
Gerrit-Change-Number: 38055
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: dexter <pmaier(a)sysmocom.de>