mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-30 00:48:54 +03:00
transport: Pass status word interpreter to exception handler
Prior to this patch, any SwMatchError raised within the 'transport' would not be interpreted. EXCEPTION of type 'SwMatchError' occurred with message: 'SW match failed! Expected 9000 and got 6982.' vs (now) EXCEPTION of type 'SwMatchError' occurred with message: 'SW match failed! Expected 9000 and got 6982: Command not allowed - Security status not satisfied' Change-Id: I08b7f2b6bd422f7f2f36094bc8a29b187ff882a6
This commit is contained in:
@@ -433,6 +433,8 @@ if __name__ == '__main__':
|
|||||||
profile.add_application(CardApplicationISIM)
|
profile.add_application(CardApplicationISIM)
|
||||||
|
|
||||||
rs = RuntimeState(card, profile)
|
rs = RuntimeState(card, profile)
|
||||||
|
# inform the transport that we can do context-specific SW interpretation
|
||||||
|
sl.set_sw_interpreter(rs)
|
||||||
|
|
||||||
# FIXME: do this dynamically
|
# FIXME: do this dynamically
|
||||||
rs.mf.add_file(DF_TELECOM())
|
rs.mf.add_file(DF_TELECOM())
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ from pySim.utils import sw_match
|
|||||||
class LinkBase(object):
|
class LinkBase(object):
|
||||||
"""Base class for link/transport to card."""
|
"""Base class for link/transport to card."""
|
||||||
|
|
||||||
|
sw_interpreter = None
|
||||||
|
|
||||||
|
def set_sw_interpreter(self, interp):
|
||||||
|
"""Set an (optional) status word interpreter."""
|
||||||
|
self.sw_interpreter = interp
|
||||||
|
|
||||||
def wait_for_card(self, timeout:int=None, newcardonly:bool=False):
|
def wait_for_card(self, timeout:int=None, newcardonly:bool=False):
|
||||||
"""Wait for a card and connect to it
|
"""Wait for a card and connect to it
|
||||||
|
|
||||||
@@ -103,7 +109,7 @@ class LinkBase(object):
|
|||||||
rv = self.send_apdu(pdu)
|
rv = self.send_apdu(pdu)
|
||||||
|
|
||||||
if not sw_match(rv[1], sw):
|
if not sw_match(rv[1], sw):
|
||||||
raise SwMatchError(rv[1], sw.lower())
|
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def init_reader(opts) -> Optional[LinkBase]:
|
def init_reader(opts) -> Optional[LinkBase]:
|
||||||
|
|||||||
Reference in New Issue
Block a user