laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/27187 )
Change subject: pySim-shell: Allow selecting of deep paths like DF.GSM/EF.IMSI
......................................................................
pySim-shell: Allow selecting of deep paths like DF.GSM/EF.IMSI
With this patch applied, users can directly enter commands like
select DF.GSM/EF.IMSI or
select ADF.USIM/DF.5GS/EF.5GAUTHKEYS
This feature doesn't have tabl completion, so it's mostly useful
for when you know what to select, or for use within scripts.
Change-Id: I681a132eb2df4b2aba4c2ccbdd21c6d5b88443e3
---
M pySim/filesystem.py
1 file changed, 16 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, approved
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index d1c3e1f..bef9005 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1411,6 +1411,22 @@
name : Name of file to select
cmd_app : Command Application State (for unregistering old file commands)
"""
+ # handling of entire paths with multiple directories/elements
+ if '/' in name:
+ prev_sel_file = self.selected_file
+ pathlist = name.split('/')
+ # treat /DF.GSM/foo like MF/DF.GSM/foo
+ if pathlist[0] == '':
+ pathlist[0] = 'MF'
+ try:
+ for p in pathlist:
+ self.select(p, cmd_app)
+ return
+ except Exception as e:
+ # if any intermediate step fails, go back to where we were
+ self.select_file(prev_sel_file, cmd_app)
+ raise e
+
sels = self.selected_file.get_selectables()
if is_hex(name):
name = name.lower()
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/27187
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I681a132eb2df4b2aba4c2ccbdd21c6d5b88443e3
Gerrit-Change-Number: 27187
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/27181 )
Change subject: ust_service_check: proper treatment of files in sub-directories
......................................................................
ust_service_check: proper treatment of files in sub-directories
We must not only consider files in the current directory (ADF.USIM)
but also in its sub-directories. This requires us to be able to
determine the path we need to traverse between the currently selected
file (EF.UST) and the respective file in some other directory,
which is implemented via CardFile.build_select_path_to().
Change-Id: I61797fefa9dafa36a8a62c11aa2cfaeecb015740
---
M pySim/filesystem.py
M pySim/ts_31_102.py
2 files changed, 71 insertions(+), 15 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index dd80071..d1c3e1f 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -115,6 +115,34 @@
ret.append(elem)
return ret
+ def fully_qualified_path_fobj(self) -> List['CardFile']:
+ """Return fully qualified path to file as list of CardFile instance references."""
+ if self.parent and self.parent != self:
+ ret = self.parent.fully_qualified_path_fobj()
+ else:
+ ret = []
+ if self:
+ ret.append(self)
+ return ret
+
+ def build_select_path_to(self, target: 'CardFile') -> Optional[List['CardFile']]:
+ """Build the relative sequence of files we need to traverse to get from us to 'target'."""
+ cur_fqpath = self.fully_qualified_path_fobj()
+ target_fqpath = target.fully_qualified_path_fobj()
+ inter_path = []
+ cur_fqpath.pop() # drop last element (currently selected file, doesn't need re-selection
+ cur_fqpath.reverse()
+ for ce in cur_fqpath:
+ inter_path.append(ce)
+ for i in range(0, len(target_fqpath)-1):
+ te = target_fqpath[i]
+ if te == ce:
+ for te2 in target_fqpath[i+1:]:
+ inter_path.append(te2)
+ # we found our common ancestor
+ return inter_path
+ return None
+
def get_mf(self) -> Optional['CardMF']:
"""Return the MF (root) of the file system."""
if self.parent == None:
@@ -1337,6 +1365,45 @@
self.selected_file = f
return select_resp
+ def _select_pre(self, cmd_app):
+ # unregister commands of old file
+ if cmd_app and self.selected_file.shell_commands:
+ for c in self.selected_file.shell_commands:
+ cmd_app.unregister_command_set(c)
+
+ def _select_post(self, cmd_app):
+ # register commands of new file
+ if cmd_app and self.selected_file.shell_commands:
+ for c in self.selected_file.shell_commands:
+ cmd_app.register_command_set(c)
+
+ def select_file(self, file: CardFile, cmd_app=None):
+ """Select a file (EF, DF, ADF, MF, ...).
+
+ Args:
+ file : CardFile [or derived class] instance
+ cmd_app : Command Application State (for unregistering old file commands)
+ """
+ # we need to find a path from our self.selected_file to the destination
+ inter_path = self.selected_file.build_select_path_to(file)
+ if not inter_path:
+ raise RuntimeError('Cannot determine path from %s to %s' % (self.selected_file, file))
+
+ self._select_pre(cmd_app)
+
+ for p in inter_path:
+ try:
+ if isinstance(p, CardADF):
+ (data, sw) = self.card.select_adf_by_aid(p.aid)
+ else:
+ (data, sw) = self.card._scc.select_file(p.fid)
+ self.selected_file = p
+ except SwMatchError as swm:
+ self._select_post(cmd_app)
+ raise(swm)
+
+ self._select_post(cmd_app)
+
def select(self, name: str, cmd_app=None):
"""Select a file (EF, DF, ADF, MF, ...).
@@ -1348,10 +1415,7 @@
if is_hex(name):
name = name.lower()
- # unregister commands of old file
- if cmd_app and self.selected_file.shell_commands:
- for c in self.selected_file.shell_commands:
- cmd_app.unregister_command_set(c)
+ self._select_pre(cmd_app)
if name in sels:
f = sels[name]
@@ -1372,11 +1436,7 @@
# store the decoded FCP for later reference
self.selected_file_fcp = select_resp
- # register commands of new file
- if cmd_app and self.selected_file.shell_commands:
- for c in self.selected_file.shell_commands:
- cmd_app.register_command_set(c)
-
+ self._select_post(cmd_app)
return select_resp
def status(self):
diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index 447ef95..7d0eb28 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -608,12 +608,8 @@
for f in files_by_service[s]:
should_exist = f.should_exist_for_services(active_services)
try:
- (data, sw) = cmd.card._scc.select_file(f.fid)
+ cmd.rs.select_file(f)
exists = True
- fcp = f.decode_select_response(data)
- # if we just selected a directory, go back
- if fcp['file_descriptor']['file_type'] == 'df':
- cmd.card._scc.select_parent_df()
except SwMatchError as e:
sw = str(e)
exists = False
@@ -625,7 +621,7 @@
cmd.perror(" ERROR: File %s is not selectable (%s) but should!" % (f, sw))
finally:
# re-select the EF.UST
- cmd.card._scc.select_file(self.fid)
+ cmd.rs.select_file(self)
return num_problems
class EF_UST(EF_UServiceTable):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/27181
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I61797fefa9dafa36a8a62c11aa2cfaeecb015740
Gerrit-Change-Number: 27181
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/27182 )
Change subject: Improve IST/UST check documentation (for the user manual)
......................................................................
Improve IST/UST check documentation (for the user manual)
Change-Id: I18093d795721f2e729eff858c8922edde9e84451
---
M pySim/ts_31_102.py
M pySim/ts_31_103.py
2 files changed, 15 insertions(+), 10 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, approved
diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index 7d0eb28..3995dfa 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -644,7 +644,12 @@
self._cmd.card.update_ust(int(arg), 0)
def do_ust_service_check(self, arg):
- """Check consistency between services of this file and files present/activated"""
+ """Check consistency between services of this file and files present/activated.
+
+ Many services determine if one or multiple files shall be present/activated or if they shall be
+ absent/deactivated. This performs a consistency check to ensure that no services are activated
+ for files that are not - and vice-versa, no files are activated for services that are not. Error
+ messages are printed for every inconsistency found."""
selected_file = self._cmd.rs.selected_file
num_problems = selected_file.ust_service_check(self._cmd)
# obtain list of currently active services
@@ -802,13 +807,6 @@
"""Deactivate a service within EF.UST"""
self._cmd.card.update_est(int(arg), 0)
- def do_est_service_check(self, arg):
- """Check consistency between services of this file and files present/activated"""
- # obtain list of currently active services
- (service_data, sw) = self._cmd.rs.read_binary_dec()
- active_services = service_data.keys()
-
-
# TS 31.102 Section 4.2.48
class EF_ACL(TransparentEF):
def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size={32, None},
diff --git a/pySim/ts_31_103.py b/pySim/ts_31_103.py
index f04f480..66124a8 100644
--- a/pySim/ts_31_103.py
+++ b/pySim/ts_31_103.py
@@ -125,9 +125,16 @@
self._cmd.card.update_ist(int(arg), 0)
def do_ist_service_check(self, arg):
- """Check consistency between services of this file and files present/activated"""
+ """Check consistency between services of this file and files present/activated.
+
+ Many services determine if one or multiple files shall be present/activated or if they shall be
+ absent/deactivated. This performs a consistency check to ensure that no services are activated
+ for files that are not - and vice-versa, no files are activated for services that are not. Error
+ messages are printed for every inconsistency found."""
selected_file = self._cmd.rs.selected_file
- selected_file.ust_service_check(self._cmd)
+ num_problems = selected_file.ust_service_check(self._cmd)
+ self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
+
# TS 31.103 Section 4.2.8
class EF_PCSCF(LinFixedEF):
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/27182
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I18093d795721f2e729eff858c8922edde9e84451
Gerrit-Change-Number: 27182
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/27177 )
Change subject: filesystem: Fix CardMF.get_app_names()
......................................................................
filesystem: Fix CardMF.get_app_names()
This function was not used and doesn't work without this patch.
Change-Id: Id3dad7d97fe29a25792d2f8f0e879666c1d9c136
---
M pySim/filesystem.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, approved
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index d52a16e..95f792a 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -384,7 +384,7 @@
def get_app_names(self):
"""Get list of completions (AID names)"""
- return [x.name for x in self.applications]
+ return list(self.applications.values())
def get_selectables(self, flags=[]) -> dict:
"""Return a dict of {'identifier': File} that is selectable from the current DF.
2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/27177
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Id3dad7d97fe29a25792d2f8f0e879666c1d9c136
Gerrit-Change-Number: 27177
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/27178 )
Change subject: ts_31_102: Add more EF.UST checks to 'ust_service_check' command
......................................................................
ts_31_102: Add more EF.UST checks to 'ust_service_check' command
* check for service dependencies listed in TS 31.102
* print number of errors encountered
Change-Id: Id47f8f2c8de299bbf91243d0c8900d22a7d35b10
---
M pySim/ts_31_102.py
1 file changed, 30 insertions(+), 3 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index 8e2d1c8..ce32b20 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -585,14 +585,20 @@
out[byte_offset] |= (bit) << bit_offset
return out
- def ust_service_check(self, cmd):
- """Check consistency between services of this file and files present/activated"""
+ def get_active_services(self, cmd):
# obtain list of currently active services
(service_data, sw) = cmd.rs.read_binary_dec()
active_services = []
for s in service_data.keys():
if service_data[s]['activated']:
active_services.append(s)
+ return active_services
+
+ def ust_service_check(self, cmd):
+ """Check consistency between services of this file and files present/activated"""
+ num_problems = 0
+ # obtain list of currently active services
+ active_services = self.get_active_services(cmd)
# iterate over all the service-constraints we know of
files_by_service = self.parent.files_by_service
try:
@@ -612,6 +618,7 @@
sw = str(e)
exists = False
if exists != should_exist:
+ num_problems += 1
if exists:
cmd.poutput(" ERROR: File %s is selectable but should not!" % f)
else:
@@ -619,6 +626,7 @@
finally:
# re-select the EF.UST
cmd.card._scc.select_file(self.fid)
+ return num_problems
class EF_UST(EF_UServiceTable):
def __init__(self, **kwargs):
@@ -642,7 +650,26 @@
def do_ust_service_check(self, arg):
"""Check consistency between services of this file and files present/activated"""
selected_file = self._cmd.rs.selected_file
- selected_file.ust_service_check(self._cmd)
+ num_problems = selected_file.ust_service_check(self._cmd)
+ # obtain list of currently active services
+ active_services = selected_file.get_active_services(self._cmd)
+ # Service n°46 can only be declared "available" if service n°45 is declared "available"
+ if 46 in active_services and not 45 in active_services:
+ self._cmd.poutput("ERROR: Service 46 available, but it requires Service 45")
+ num_problems += 1
+ # Service n°125 shall only be taken into account if Service n°124 is declared "available"
+ if 125 in active_services and not 124 in active_services:
+ self._cmd.poutput("ERROR: Service 125 is ignored as Service 124 not available")
+ num_problems += 1
+ # Service n°95, n°99 and n°115 shall not be declared "available" if an ISIM application is present on the UICC
+ non_isim_services = [95, 99, 115]
+ app_names = selected_file.get_mf().get_app_names()
+ if 'ADF.ISIM' in app_names:
+ for s in non_isim_services:
+ if s in active_services:
+ self._cmd.poutput("ERROR: Service %u shall not be available as ISIM application is present" % s)
+ num_problems += 1
+ self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
# TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC!
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/27178
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Id47f8f2c8de299bbf91243d0c8900d22a7d35b10
Gerrit-Change-Number: 27178
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged