aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-shell.py
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2021-11-08 16:12:03 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2021-11-19 13:21:32 +0100
commita028c7d7aaa30c7c8da6987f9c19d17b3d1a2ddb (patch)
tree6be21ea2737635b8b267c4f855e4eb1766e131e4 /pySim-shell.py
parent055b80aa5cebda5ec8207bf14cc9024e0618fd7b (diff)
pySim-shell: add method to match card profile to card
UICC and old SIM cards can be difficult to tell apart without prior knowledge of the card. The ATR won't tell if the card is UICC or not. The only remaining option is to try out if the card is able to handle UICC APDUs. The same is true for 2G SIM cards. It is not guranteed that every UICC card will have 2G functionality. Lets add functionality to match a profile to the currently plugged card by actively probing it. Lets also add another profile to distinguish between UICC-only cards and UICC cards that include SIM functionality. Change-Id: If090d32551145f75c644657b90085a3ef5bfa691 Related: OS#5274
Diffstat (limited to 'pySim-shell.py')
-rwxr-xr-xpySim-shell.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index 128c0ea..0519ec4 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -45,8 +45,10 @@ from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex, box
from pySim.card_handler import CardHandler, CardHandlerAuto
from pySim.filesystem import CardMF, RuntimeState, CardDF, CardADF, CardModel
+from pySim.profile import CardProfile
from pySim.ts_51_011 import CardProfileSIM, DF_TELECOM, DF_GSM
from pySim.ts_102_221 import CardProfileUICC
+from pySim.ts_102_221 import CardProfileUICCSIM
from pySim.ts_31_102 import CardApplicationUSIM
from pySim.ts_31_103 import CardApplicationISIM
from pySim.ara_m import CardApplicationARAM
@@ -80,19 +82,32 @@ def init_card(sl):
card = card_detect("auto", scc)
if card is None:
- print("Could not detect card type!")
+ print("Warning: Could not detect card type - assuming a generic card type...")
+ card = SimCard(scc)
+
+ profile = CardProfile.pick(scc)
+ if profile is None:
+ print("Unsupported card type!")
return None, None
+ print("Info: Card is of type: %s" % str(profile))
+
+ # FIXME: This shouln't be here, the profile should add the applications,
+ # however, we cannot simply put his into ts_102_221.py since we would
+ # have to e.g. import CardApplicationUSIM from ts_31_102.py, which already
+ # imports from ts_102_221.py. This means we will end up with a circular
+ # import, which needs to be resolved first.
+ if isinstance(profile, CardProfileUICC):
+ profile.add_application(CardApplicationUSIM())
+ profile.add_application(CardApplicationISIM())
+ profile.add_application(CardApplicationARAM())
+
# Create runtime state with card profile
- profile = CardProfileUICC()
- profile.add_application(CardApplicationUSIM())
- profile.add_application(CardApplicationISIM())
- profile.add_application(CardApplicationARAM())
rs = RuntimeState(card, profile)
- # FIXME: do this dynamically
- rs.mf.add_file(DF_TELECOM())
- rs.mf.add_file(DF_GSM())
+ # FIXME: This is an GSM-R related file, it needs to be added throughout,
+ # the profile. At the moment we add it for all cards, this won't hurt,
+ # but regular SIM and UICC will not have it and fail to select it.
rs.mf.add_file(DF_EIRENE())
CardModel.apply_matching_models(scc, rs)