Change in pysim[master]: shell: Fix activate_file + deactivate_file commands

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Tue May 25 20:23:10 UTC 2021


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


Change subject: shell: Fix activate_file + deactivate_file commands
......................................................................

shell: Fix activate_file + deactivate_file commands

We cannot re-activate a deactivated file after we have selected somethng
else, as SELECT will fail on the deactivated file.  Hence, the
deactivate_file command needs to be used with a file name as argument.

Change-Id: Ief4d2bf8ea90497a8f25d1986aeea935c615f9bb
---
M pySim-shell.py
M pySim/commands.py
M pySim/filesystem.py
3 files changed, 18 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/05/24405/1

diff --git a/pySim-shell.py b/pySim-shell.py
index edd8112..59bfa28 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -419,13 +419,17 @@
 
 	def do_deactivate_file(self, opts):
 		"""Deactivate the current EF"""
-		fid = self._cmd.rs.selected_file.fid
-		(data, sw) = self._cmd.card._scc.deactivate_file(fid)
+		(data, sw) = self._cmd.card._scc.deactivate_file()
 
 	def do_activate_file(self, opts):
-		"""Activate the current EF"""
-		fid = self._cmd.rs.selected_file.fid
-		(data, sw) = self._cmd.card._scc.activate_file(fid)
+		"""Activate the specified EF"""
+		path = opts.arg_list[0]
+		(data, sw) = self._cmd.rs.activate_file(path)
+
+	def complete_activate_file(self, text, line, begidx, endidx) -> List[str]:
+		"""Command Line tab completion for ACTIVATE 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)
 
 	open_chan_parser = argparse.ArgumentParser()
 	open_chan_parser.add_argument('chan_nr', type=int, default=0, help='Channel Number')
diff --git a/pySim/commands.py b/pySim/commands.py
index 4640fe1..1fbea16 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -367,9 +367,9 @@
 		"""Execute DECATIVATE FILE command as per TS 102 221 Section 11.1.14."""
 		return self._tp.send_apdu_constr_checksw(self.cla_byte, '04', '00', '00', None, None, None)
 
-	def activate_file(self):
+	def activate_file(self, fid):
 		"""Execute ACTIVATE FILE command as per TS 102 221 Section 11.1.15."""
-		return self._tp.send_apdu_constr_checksw(self.cla_byte, '44', '00', '00', None, None, None)
+		return self._tp.send_apdu_checksw(self.cla_byte + '44000002' + fid)
 
 	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 aaf333b..8c45ba1 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1150,6 +1150,13 @@
         (data, sw) = self.card._scc.status()
         return self.selected_file.decode_select_response(data)
 
+    def activate_file(self, name:str):
+        """Request ACTIVATE FILE of specified file."""
+        sels = self.selected_file.get_selectables()
+        f = sels[name]
+        data, sw = self.card._scc.activate_file(f.fid)
+        return data, sw
+
     def read_binary(self, length:int=None, offset:int=0):
         """Read [part of] a transparent EF binary data.
 

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ief4d2bf8ea90497a8f25d1986aeea935c615f9bb
Gerrit-Change-Number: 24405
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210525/585e0fb3/attachment.htm>


More information about the gerrit-log mailing list