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


Change subject: WIP: pySim-shell: support TS 102 220 administrative commands
......................................................................

WIP: pySim-shell: support TS 102 220 administrative commands

Change-Id: I5b1ffb1334afa18d62beb642268066a30deb7ea6
---
M pySim-shell.py
M pySim/commands.py
M pySim/filesystem.py
3 files changed, 66 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/26/27126/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 8e8a1a6..0a2e5b0 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -169,6 +169,7 @@
                        self._onchange_conserve_write('conserve_write', False, 
self.conserve_write)
                        self._onchange_apdu_trace('apdu_trace', False, 
self.apdu_trace)
                        self.register_command_set(Iso7816Commands())
+                       self.register_command_set(Ts102221Commands())
                        self.register_command_set(PySimCommands())
                        self.iccid, sw = self.card.read_iccid()
                        rs.select('MF', self)
@@ -624,6 +625,51 @@
                else:
                        raise ValueError("error: cannot authenticate, no 
adm-pin!")

+@with_default_category('TS 102 222 Commands')
+class Ts102221Commands(CommandSet):
+       """Administrative commands for telecommunication aplpications."""
+       def __init__(self):
+               super().__init__()
+
+       def do_delete_file(self, opts):
+               """Delete the specified file. DANGEROUS!"""
+               path = opts.arg_list[0]
+               f = self._cmd.rs.get_file_for_selectable(path)
+               (data, sw) = self._cmd.card._scc.delete_file(f.fid)
+
+       def complete_delete_file(self, text, line, begidx, endidx) -> List[str]:
+               """Command Line tab completion for DELETE FILE"""
+               index_dict = { 1: 
self._cmd.rs.selected_file.get_selectable_names() }
+               return self._cmd.index_based_complete(text, line, begidx, 
endidx, index_dict=index_dict)
+
+       def do_terminate_df(self, opts):
+               """Terminate the specified DF. DANGEROUS!"""
+               path = opts.arg_list[0]
+               f = self._cmd.rs.get_file_for_selectable(path)
+               (data, sw) = self._cmd.card._scc.terminate_df(f.fid)
+
+       def complete_terminate_df(self, text, line, begidx, endidx) -> 
List[str]:
+               """Command Line tab completion for TERMINATE DF"""
+               index_dict = { 1: 
self._cmd.rs.selected_file.get_selectable_names() }
+               return self._cmd.index_based_complete(text, line, begidx, 
endidx, index_dict=index_dict)
+
+       def do_terminate_ef(self, opts):
+               """Terminate the specified EF. DANGEROUS!"""
+               path = opts.arg_list[0]
+               f = self._cmd.rs.get_file_for_selectable(path)
+               (data, sw) = self._cmd.card._scc.terminate_ef(f.fid)
+
+       def complete_terminate_ef(self, text, line, begidx, endidx) -> 
List[str]:
+               """Command Line tab completion for TERMINATE EF"""
+               index_dict = { 1: 
self._cmd.rs.selected_file.get_selectable_names() }
+               return self._cmd.index_based_complete(text, line, begidx, 
endidx, index_dict=index_dict)
+
+       def do_terminate_card_usage(self, opts):
+               """Terminate the Card. SUPER DANGEROUS!"""
+               (data, sw) = self._cmd.card._scc.terminate_card_usage()
+
+
+
 @with_default_category('ISO7816 Commands')
 class Iso7816Commands(CommandSet):
        def __init__(self):
diff --git a/pySim/commands.py b/pySim/commands.py
index 674e184..9dc273c 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -431,6 +431,22 @@
                """
                return self._tp.send_apdu_checksw(self.cla_byte + '44000002' + 
fid)

+       def delete_file(self, fid):
+               """Execute DELETE FILE command as per TS 102 222 Section 6.4"""
+               return self._tp.send_apdu_checksw(self.cla_byte + 'e4000002' + 
fid)
+
+       def terminate_df(self, fid):
+               """Execute TERMINATE DF command as per TS 102 222 Section 6.7"""
+               return self._tp.send_apdu_checksw(self.cla_byte + 'e6000002' + 
fid)
+
+       def terminate_ef(self, fid):
+               """Execute TERMINATE EF command as per TS 102 222 Section 6.8"""
+               return self._tp.send_apdu_checksw(self.cla_byte + 'e8000002' + 
fid)
+
+       def terminate_card_usage(self):
+               """Execute TERMINATE CARD USAGE command as per TS 102 222 
Section 6.9"""
+               return self._tp.send_apdu_checksw(self.cla_byte + 'fe000000')
+
        def manage_channel(self, mode='open', lchan_nr=0):
                """Execute MANAGE CHANNEL command as per TS 102 221 Section 
11.1.17.

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 7100b21..d9c7475 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1265,6 +1265,10 @@
         (data, sw) = self.card._scc.status()
         return self.selected_file.decode_select_response(data)

+    def get_file_for_selectable(self, name:str):
+        sels = self.selected_file.get_selectables()
+        return sels[name]
+
     def activate_file(self, name:str):
         """Request ACTIVATE FILE of specified file."""
         sels = self.selected_file.get_selectables()

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

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

Reply via email to