mirror of https://gerrit.osmocom.org/pysim
pySim-shell: add ADF.ISIM / ADF.USIM dynamically
currently ADF.ISIM and ADF.USIM are always added regardless if there is a matching application on the card or not. Lets check what applications are actually installed and add ADF.ISIM and ADF.USIM dynamically. Change-Id: I42ee23375f98e6322708c1c4db6d65e1425feecd Related: OS#4963
This commit is contained in:
parent
eb72fa461d
commit
1e896f3d8c
|
@ -58,8 +58,6 @@ class PysimApp(cmd2.Cmd):
|
||||||
self.card = card
|
self.card = card
|
||||||
self.rs = rs
|
self.rs = rs
|
||||||
self.py_locals = { 'card': self.card, 'rs' : self.rs }
|
self.py_locals = { 'card': self.card, 'rs' : self.rs }
|
||||||
self.card.read_aids()
|
|
||||||
self.poutput('AIDs on card: %s' % (self.card._aids))
|
|
||||||
self.numeric_path = False
|
self.numeric_path = False
|
||||||
self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names',
|
self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names',
|
||||||
onchange_cb=self._onchange_numeric_path))
|
onchange_cb=self._onchange_numeric_path))
|
||||||
|
@ -254,13 +252,14 @@ if __name__ == '__main__':
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
profile = CardProfileUICC()
|
profile = CardProfileUICC()
|
||||||
|
profile.add_application(ADF_USIM())
|
||||||
|
profile.add_application(ADF_ISIM())
|
||||||
|
|
||||||
rs = RuntimeState(card, profile)
|
rs = RuntimeState(card, profile)
|
||||||
|
|
||||||
# FIXME: do this dynamically
|
# FIXME: do this dynamically
|
||||||
rs.mf.add_file(DF_TELECOM())
|
rs.mf.add_file(DF_TELECOM())
|
||||||
rs.mf.add_file(DF_GSM())
|
rs.mf.add_file(DF_GSM())
|
||||||
rs.mf.add_application(ADF_USIM())
|
|
||||||
rs.mf.add_application(ADF_ISIM())
|
|
||||||
|
|
||||||
app = PysimApp(card, rs)
|
app = PysimApp(card, rs)
|
||||||
rs.select('MF', app)
|
rs.select('MF', app)
|
||||||
|
|
|
@ -207,6 +207,7 @@ class Card(object):
|
||||||
|
|
||||||
# Fetch all the AIDs present on UICC
|
# Fetch all the AIDs present on UICC
|
||||||
def read_aids(self):
|
def read_aids(self):
|
||||||
|
self._aids = []
|
||||||
try:
|
try:
|
||||||
# Find out how many records the EF.DIR has
|
# Find out how many records the EF.DIR has
|
||||||
# and store all the AIDs in the UICC
|
# and store all the AIDs in the UICC
|
||||||
|
@ -218,6 +219,8 @@ class Card(object):
|
||||||
self._aids.append(rec[0][8:8 + int(rec[0][6:8], 16) * 2])
|
self._aids.append(rec[0][8:8 + int(rec[0][6:8], 16) * 2])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Can't read AIDs from SIM -- %s" % (str(e),))
|
print("Can't read AIDs from SIM -- %s" % (str(e),))
|
||||||
|
self._aids = []
|
||||||
|
return self._aids
|
||||||
|
|
||||||
# Select ADF.U/ISIM in the Card using its full AID
|
# Select ADF.U/ISIM in the Card using its full AID
|
||||||
def select_adf_by_aid(self, adf="usim"):
|
def select_adf_by_aid(self, adf="usim"):
|
||||||
|
|
|
@ -550,11 +550,33 @@ class RuntimeState(object):
|
||||||
self.selected_file = self.mf
|
self.selected_file = self.mf
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
# add applications + MF-files from profile
|
# add applications + MF-files from profile
|
||||||
for a in self.profile.applications:
|
apps = self._match_applications()
|
||||||
|
for a in apps:
|
||||||
self.mf.add_application(a)
|
self.mf.add_application(a)
|
||||||
for f in self.profile.files_in_mf:
|
for f in self.profile.files_in_mf:
|
||||||
self.mf.add_file(f)
|
self.mf.add_file(f)
|
||||||
|
|
||||||
|
def _match_applications(self):
|
||||||
|
"""match the applications from the profile with applications on the card"""
|
||||||
|
apps_profile = self.profile.applications
|
||||||
|
aids_card = self.card.read_aids()
|
||||||
|
apps_taken = []
|
||||||
|
if aids_card:
|
||||||
|
aids_taken = []
|
||||||
|
print("AIDs on card:")
|
||||||
|
for a in aids_card:
|
||||||
|
for f in apps_profile:
|
||||||
|
if f.aid in a:
|
||||||
|
print(" %s: %s" % (f.name, a))
|
||||||
|
aids_taken.append(a)
|
||||||
|
apps_taken.append(f)
|
||||||
|
aids_unknown = set(aids_card) - set(aids_taken)
|
||||||
|
for a in aids_unknown:
|
||||||
|
print(" unknown: %s" % a)
|
||||||
|
else:
|
||||||
|
print("error: could not determine card applications")
|
||||||
|
return apps_taken
|
||||||
|
|
||||||
def get_cwd(self):
|
def get_cwd(self):
|
||||||
"""Obtain the current working directory."""
|
"""Obtain the current working directory."""
|
||||||
if isinstance(self.selected_file, CardDF):
|
if isinstance(self.selected_file, CardDF):
|
||||||
|
|
Loading…
Reference in New Issue