From d70ac226186de5503b2adc9de117d2818d307867 Mon Sep 17 00:00:00 2001 From: Tobias Engel Date: Mon, 29 May 2023 21:20:59 +0200 Subject: [PATCH] modem_atcmd: raise ProtocolError instead of ReaderError on CME ERROR Also accept ProtocolError in addition to SwMatchError in filesystem.py when probing for applications Change-Id: I82b50408328f8eaaee5c9e311c4620d20f930642 --- pySim/filesystem.py | 2 +- pySim/transport/modem_atcmd.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index ce1882b3..b5d0ccd2 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -1352,7 +1352,7 @@ class RuntimeState: if sw == "9000": print(" %s: %s" % (f.name, f.aid)) apps_taken.append(f) - except SwMatchError: + except (SwMatchError, ProtocolError): pass return apps_taken diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index a373d685..ea50bc9d 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -148,8 +148,9 @@ class ModemATCommandLink(LinkBase): log.debug('Sending command: %s', cmd) # Send AT+CSIM command to the modem - # TODO: also handle +CME ERROR: rsp = self.send_at_cmd(cmd) + if rsp[-1].startswith(b'+CME ERROR:'): + raise ProtocolError('AT+CSIM failed with: %s' % str(rsp)) if len(rsp) != 2 or rsp[-1] != b'OK': raise ReaderError('APDU transfer failed: %s' % str(rsp)) rsp = rsp[0] # Get rid of b'OK'