aboutsummaryrefslogtreecommitdiffstats
path: root/pySim/transport/__init__.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-04-10 11:28:53 +0200
committerHarald Welte <laforge@osmocom.org>2021-04-10 18:41:15 +0200
commit7829d8a3579f196fc78f87e5a3de0214f22f6fb3 (patch)
treeaeaf92745088074aa06cfe02a81fd7ea149ff3c0 /pySim/transport/__init__.py
parenteb05b2f60e6ced605beb0c976cc526d2d3c63fc9 (diff)
shell: Add 'apdu_trace' settable parameter for hex-dumping APDUs
Diffstat (limited to 'pySim/transport/__init__.py')
-rw-r--r--pySim/transport/__init__.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index c176f8a..96ad974 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -25,11 +25,20 @@ from pySim.utils import sw_match
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+class ApduTracer:
+ def trace_command(self, cmd):
+ pass
+
+ def trace_response(self, cmd, sw, resp):
+ pass
+
+
class LinkBase(object):
"""Base class for link/transport to card."""
- def __init__(self, sw_interpreter=None):
+ def __init__(self, sw_interpreter=None, apdu_tracer=None):
self.sw_interpreter = sw_interpreter
+ self.apdu_tracer = apdu_tracer
def set_sw_interpreter(self, interp):
"""Set an (optional) status word interpreter."""
@@ -69,7 +78,12 @@ class LinkBase(object):
data : string (in hex) of returned data (ex. "074F4EFFFF")
sw : string (in hex) of status word (ex. "9000")
"""
- return self._send_apdu_raw(pdu)
+ if self.apdu_tracer:
+ self.apdu_tracer.trace_command(pdu)
+ (data, sw) = self._send_apdu_raw(pdu)
+ if self.apdu_tracer:
+ self.apdu_tracer.trace_response(pdu, sw, data)
+ return (data, sw)
def send_apdu(self, pdu):
"""Sends an APDU and auto fetch response data