aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2022-07-24 12:19:57 +0200
committerHarald Welte <laforge@osmocom.org>2022-07-25 14:25:11 +0200
commitf5ff1b896e12ad1584e07bd23b32aa77573bdb65 (patch)
tree214522bbf47dad2a31141b716e6e606fcf88e8b7
parent8e9c844130f5746dd149ba1a91d8eae07d4ef8d0 (diff)
filesystem: We can select not just immediate parent DF but all ancestors
I didn't check the specs, but at least experience with real-world cards (and modems) shows that it's not just permitted to select the immediate parent DF, but all ancestors of the currently selected file. So adjust the get_selectables() method to not just return the immediate parent, but to recurse all the way up and report the FID of any ancestor DF. Change-Id: Ic9037aa9a13af6fb0c2c22b673aa4afa78575b49
-rw-r--r--pySim/filesystem.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 886a48d..a3d1122 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -194,6 +194,21 @@ class CardFile:
sels.update({self.name: self})
return sels
+ def _get_parent_selectables(self, alias: Optional[str] = None, flags=[]) -> Dict[str, 'CardFile']:
+ sels = {}
+ if not self.parent or self.parent == self:
+ return sels
+ # add our immediate parent
+ if alias:
+ sels.update({alias: self.parent})
+ if self.parent.fid and (flags == [] or 'FIDS' in flags):
+ sels.update({self.parent.fid: self.parent})
+ if self.parent.name and (flags == [] or 'FNAMES' in flags):
+ sels.update({self.parent.name: self.parent})
+ # recurse to parents of our parent, but without any alias
+ sels.update(self.parent._get_parent_selectables(None, flags))
+ return sels
+
def get_selectables(self, flags=[]) -> Dict[str, 'CardFile']:
"""Return a dict of {'identifier': File} that is selectable from the current file.
@@ -210,8 +225,7 @@ class CardFile:
sels = self._get_self_selectables('.', flags)
# we can always select our parent
if flags == [] or 'PARENT' in flags:
- if self.parent:
- sels = self.parent._get_self_selectables('..', flags)
+ sels.update(self._get_parent_selectables('..', flags))
# if we have a MF, we can always select its applications
if flags == [] or 'MF' in flags:
mf = self.get_mf()