laforge has uploaded this change for review.
pySim.transport: Add mechanism for handling for CAT/USAT proactive cmds
This introduces an optional argument to the LinkBase class constructor,
where the application can pass an instance of a ProactiveHandler derived
class in order to handle the proactive commands that the LinkBase is
automatically fetching whenever the card indicates so.
Change-Id: I844504e2fc1b27ce4fc7ede20b2307e698baa0f6
---
M pySim/transport/__init__.py
1 file changed, 15 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/63/28963/1
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 9364b07..bc18b5a 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -9,11 +9,11 @@
from pySim.exceptions import *
from pySim.construct import filter_dict
-from pySim.utils import sw_match, b2h, h2b, i2h
+from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr
#
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
-# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
+# Copyright (C) 2021-2022 Harald Welte <laforge@osmocom.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -37,13 +37,22 @@
def trace_response(self, cmd, sw, resp):
pass
+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
+ command."""
+ @abc.abstractmethod
+ def receive_fetch(payload: Hexstr):
+ pass
class LinkBase(abc.ABC):
"""Base class for link/transport to card."""
- def __init__(self, sw_interpreter=None, apdu_tracer=None):
+ def __init__(self, sw_interpreter=None, apdu_tracer=None,
+ proactive_handler: Optional[ProactiveHandler]=None):
self.sw_interpreter = sw_interpreter
self.apdu_tracer = apdu_tracer
+ self.proactive_handler = proactive_handler
@abc.abstractmethod
def _send_apdu_raw(self, pdu: str) -> Tuple[str, str]:
@@ -137,10 +146,12 @@
"""
rv = self.send_apdu(pdu)
- if sw == '9000' and sw_match(rv[1], '91xx'):
+ while sw == '9000' and sw_match(rv[1], '91xx'):
# proactive sim as per TS 102 221 Setion 7.4.2
rv = self.send_apdu_checksw('80120000' + rv[1][2:], sw)
print("FETCH: %s", rv[0])
+ if self.proactive_handler:
+ self.proactive_handler.receive_fetch(rv[0])
if not sw_match(rv[1], sw):
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
return rv
To view, visit change 28963. To unsubscribe, or for help writing mail filters, visit settings.