dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37643?usp=email )


Change subject: ara_m: add export support for the ARA-M application
......................................................................

ara_m: add export support for the ARA-M application

This patch adds an export method to the CardApplicationARAM class.
This method reads the ARA-M configuration and transforms it into
executeable command lines, which can be executed as a script later
to restore an ARA-M configuration.

Related: OS#6092
Change-Id: I811cb9d25cb8ee194b4ead5fb2cabf1fdc0c1c43
---
M pySim/ara_m.py
1 file changed, 86 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/43/37643/1

diff --git a/pySim/ara_m.py b/pySim/ara_m.py
index c283cf0..c327e13 100644
--- a/pySim/ara_m.py
+++ b/pySim/ara_m.py
@@ -415,3 +415,74 @@
 class CardApplicationARAM(CardApplication):
     def __init__(self):
         super().__init__('ARA-M', adf=ADF_ARAM(), sw=sw_aram)
+
+    @staticmethod
+    def export(as_json: bool, lchan):
+
+        # TODO: Add JSON output as soon as aram_store_ref_ar_do is able to 
process input in JSON format.
+        if as_json:
+            raise NotImplementedError("res_do encoder not yet implemented. 
Patches welcome.")
+
+        export_str = ""
+        export_str += "aram_delete_all\n"
+
+        res_do = ADF_ARAM.get_all(lchan.scc._tp)
+        if res_do:
+            for res_do_dict in res_do.to_dict():
+                if 'response_all_ref_ar_do' in res_do_dict and 
res_do_dict['response_all_ref_ar_do']:
+                    for ref_ar_do_list in 
res_do_dict['response_all_ref_ar_do']:
+                        ref_do_list = None
+                        ar_do_list = None
+                        if 'ref_ar_do' in ref_ar_do_list:
+                            for ref_ar_do in ref_ar_do_list['ref_ar_do']:
+                                if 'ref_do' in ref_ar_do:
+                                    ref_do_list = ref_ar_do['ref_do']
+                                if 'ar_do' in ref_ar_do:
+                                    ar_do_list = ref_ar_do['ar_do']
+
+                        if ref_do_list and ar_do_list:
+                            aid_ref_do = None
+                            dev_app_id_ref_do = None
+                            apdu_ar_do = None
+                            nfc_ar_do = None
+                            perm_ar_do = None
+                            pkg_ref_do = None
+                            for ref_do in ref_do_list:
+                                if 'aid_ref_do' in ref_do:
+                                    aid_ref_do = ref_do['aid_ref_do']
+                                if 'dev_app_id_ref_do' in ref_do:
+                                    dev_app_id_ref_do = 
ref_do['dev_app_id_ref_do']
+                                if 'pkg_ref_do' in ref_do:
+                                    pkg_ref_do = ref_do['pkg_ref_do']
+                            for ar_do in ar_do_list:
+                                if 'apdu_ar_do' in ar_do:
+                                    apdu_ar_do = ar_do['apdu_ar_do']
+                                if 'nfc_ar_do' in ar_do:
+                                    nfc_ar_do = ar_do['nfc_ar_do']
+                                if 'perm_ar_do' in ar_do:
+                                    perm_ar_do = ar_do['perm_ar_do']
+
+                            # Write command-line
+                            export_str += "aram_store_ref_ar_do"
+                            if aid_ref_do:
+                                export_str += (" --aid %s" % aid_ref_do)
+                            else:
+                                export_str += " --aid-empty"
+                            if dev_app_id_ref_do:
+                                export_str += (" --device-app-id %s" % 
dev_app_id_ref_do)
+                            if apdu_ar_do and 'generic_access_rule' in 
apdu_ar_do:
+                                export_str += (" --apdu-%s" % 
apdu_ar_do['generic_access_rule'])
+                            elif apdu_ar_do and 'apdu_filter' in apdu_ar_do:
+                                export_str += (" --apdu-filter ")
+                                for apdu_filter in apdu_ar_do['apdu_filter']:
+                                    export_str += apdu_filter['header']
+                                    export_str += apdu_filter['mask']
+                            if nfc_ar_do and 'nfc_event_access_rule' in 
nfc_ar_do:
+                                export_str += (" --nfc-%s" % 
nfc_ar_do['nfc_event_access_rule'])
+                            if perm_ar_do:
+                                export_str += (" --android-permissions %s" % 
perm_ar_do['permissions'])
+                            if pkg_ref_do:
+                                export_str += (" --pkg-ref %s" % 
pkg_ref_do['package_name_string'])
+                            export_str += "\n"
+
+        return export_str.strip()

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37643?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I811cb9d25cb8ee194b4ead5fb2cabf1fdc0c1c43
Gerrit-Change-Number: 37643
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>
Gerrit-MessageType: newchange

Reply via email to