From f5ff1b896e12ad1584e07bd23b32aa77573bdb65 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 24 Jul 2022 12:19:57 +0200 Subject: [PATCH] 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 --- pySim/filesystem.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index 886a48dd..a3d1122d 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()