laforge has submitted this change. (
https://gerrit.osmocom.org/c/pysim/+/39863?usp=email
)
Change subject: saip-tool: add commandline option to edit mandatory services list
......................................................................
saip-tool: add commandline option to edit mandatory services list
Change-Id: I120b98d4b0942c26674bc1365c5711101ec95235
---
M contrib/saip-tool.py
M pySim/esim/saip/__init__.py
2 files changed, 36 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/contrib/saip-tool.py b/contrib/saip-tool.py
index 927db1f..9fc111c 100755
--- a/contrib/saip-tool.py
+++ b/contrib/saip-tool.py
@@ -101,6 +101,12 @@
parser_rappi.add_argument('--aid', required=True, help='Load package
AID')
parser_rappi.add_argument('--inst-aid', required=True, help='Instance
AID')
+esrv_flag_choices = [t.name for t in
asn1.types['ServicesList'].type.root_members]
+parser_esrv = subparsers.add_parser('edit-mand-srv-list', help='Add/Remove
service flag from/to mandatory services list')
+parser_esrv.add_argument('--output-file', required=True, help='Output file
name')
+parser_esrv.add_argument('--add-flag', default=[], choices=esrv_flag_choices,
action='append', help='Add flag to mandatory services list')
+parser_esrv.add_argument('--remove-flag', default=[], choices=esrv_flag_choices,
action='append', help='Remove flag from mandatory services list')
+
parser_info = subparsers.add_parser('tree', help='Display the filesystem
tree')
def write_pes(pes: ProfileElementSequence, output_file:str):
@@ -418,6 +424,25 @@
return
print("Load Package AID: %s not found in PE Sequence" % opts.aid)
+def do_edit_mand_srv_list(pes: ProfileElementSequence, opts):
+ header = pes.pe_by_type.get('header', [])[0]
+
+ for s in opts.add_flag:
+ print("Adding service '%s' to mandatory services list..." % s)
+ header.mandatory_service_add(s)
+ for s in opts.remove_flag:
+ if s in header.decoded['eUICC-Mandatory-services'].keys():
+ print("Removing service '%s' from mandatory services
list..." % s)
+ header.mandatory_service_remove(s)
+ else:
+ print("Service '%s' not present in mandatory services list,
cannot remove!" % s)
+
+ print("The following services are now set mandatory:")
+ for s in header.decoded['eUICC-Mandatory-services'].keys():
+ print("\t%s" % s)
+
+ write_pes(pes, opts.output_file)
+
def do_tree(pes:ProfileElementSequence, opts):
pes.mf.print_tree()
@@ -458,5 +483,7 @@
do_add_app_inst(pes, opts)
elif opts.command == 'remove-app-inst':
do_remove_app_inst(pes, opts)
+ elif opts.command == 'edit-mand-srv-list':
+ do_edit_mand_srv_list(pes, opts)
elif opts.command == 'tree':
do_tree(pes, opts)
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 9ccf134..21f44ef 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -1411,6 +1411,15 @@
if profile_type:
self.decoded['profileType'] = profile_type
+ def mandatory_service_add(self, service_name):
+ self.decoded['eUICC-Mandatory-services'][service_name] = None
+
+ def mandatory_service_remove(self, service_name):
+ if service_name in self.decoded['eUICC-Mandatory-services'].keys():
+ del self.decoded['eUICC-Mandatory-services'][service_name]
+ else:
+ raise ValueError("service not in eUICC-Mandatory-services list, cannot
remove")
+
class ProfileElementEnd(ProfileElement):
type = 'end'
def __init__(self, decoded: Optional[dict] = None, **kwargs):
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/39863?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I120b98d4b0942c26674bc1365c5711101ec95235
Gerrit-Change-Number: 39863
Gerrit-PatchSet: 5
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>