laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/28768 )


Change subject: filesystem: We can select not just immediate parent DF but all 
ancestors
......................................................................

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
---
M pySim/filesystem.py
1 file changed, 14 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/68/28768/1

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 886a48d..513532e 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -194,6 +194,19 @@
             sels.update({self.name: self})
         return sels

+    def _get_parent_selectables(self, alias: str = None, flags=[]) -> 
Dict[str, 'CardFile']:
+        sels = {}
+        if not self.parent or self.parent == self:
+            return sels
+        # add our immediate 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 +223,7 @@
             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()

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28768
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ic9037aa9a13af6fb0c2c22b673aa4afa78575b49
Gerrit-Change-Number: 28768
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to