This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/26253 )
Change subject: pySim-read: put try/catch block around select_adf_by_aid()
......................................................................
pySim-read: put try/catch block around select_adf_by_aid()
Selecting an application may fail, especially when the application does
not exist on the card.
Change-Id: Ia904a74d672cf9551fb4ee062dd606b350b64cef
---
M pySim-read.py
1 file changed, 21 insertions(+), 2 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim-read.py b/pySim-read.py
index 959a7c5..5e48116 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -34,6 +34,7 @@
from pySim.commands import SimCardCommands
from pySim.transport import init_reader, argparse_add_reader_args
+from pySim.exceptions import SwMatchError
from pySim.cards import card_detect, SimCard, UsimCard, IsimCard
from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn
from pySim.utils import format_xplmn_w_act, dec_st
@@ -44,6 +45,24 @@
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
argparse_add_reader_args(option_parser)
+def select_app(adf:str, card:SimCard):
+ """Select application by its AID"""
+ sw = 0
+ try:
+ if card._scc.cla_byte == "00":
+ data, sw = card.select_adf_by_aid(adf)
+ except SwMatchError as e:
+ if e.sw_actual == "6a82":
+ # If we can't select the file because it does not exist, we just remain silent since it means
+ # that this card just does not have an USIM application installed, which is not an error.
+ pass
+ else:
+ print("ADF." + adf + ": Can't select application -- " + str(e))
+ except Exception as e:
+ print("ADF." + adf + ": Can't select application -- " + str(e))
+
+ return sw
+
if __name__ == '__main__':
# Parse options
@@ -219,7 +238,7 @@
# Check whether we have th AID of USIM, if so select it by its AID
# EF.UST - File Id in ADF USIM : 6f38
- data, sw = card.select_adf_by_aid(adf="usim")
+ sw = select_app("USIM", card)
if sw == '9000':
# Select USIM profile
usim_card = UsimCard(scc)
@@ -269,7 +288,7 @@
print("ePDGSelection: Can't read file -- " + str(e))
# Select ISIM application by its AID
- data, sw = card.select_adf_by_aid(adf="isim")
+ sw = select_app("ISIM", card)
if sw == '9000':
# Select USIM profile
isim_card = IsimCard(scc)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26253
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia904a74d672cf9551fb4ee062dd606b350b64cef
Gerrit-Change-Number: 26253
Gerrit-PatchSet: 6
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-CC: daniel <dwillmann at sysmocom.de>
Gerrit-CC: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211124/609b28b4/attachment.htm>