Change in pysim[master]: shell: Add 'reset' command to reset the card

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
Mon May 3 21:26:36 UTC 2021


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


Change subject: shell: Add 'reset' command to reset the card
......................................................................

shell: Add 'reset' command to reset the card

At some points during an interactive session or a script one may want
to reset the card.

Change-Id: I992eb3e0ed52f7941a5fb44f28a42e22ebd49301
---
M docs/shell.rst
M pySim-shell.py
M pySim/filesystem.py
3 files changed, 24 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/09/24109/1

diff --git a/docs/shell.rst b/docs/shell.rst
index 5170999..08fd376 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -193,6 +193,12 @@
 FIXME
 
 
+reset
+~~~~~
+
+Perform card reset and display the card ATR.
+
+
 Linear Fixed EF commands
 ------------------------
 
diff --git a/pySim-shell.py b/pySim-shell.py
index 5b5768a..bbfe7e9 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -313,6 +313,12 @@
 		elif context['DF_SKIP']:
 			raise RuntimeError("unable to export %i dedicated files(s)" % context['ERR'])
 
+	def do_reset(self, opts):
+		"""Reset the Card."""
+		atr = self._cmd.rs.reset(self._cmd)
+		self._cmd.poutput('Card ATR: %s' % atr)
+		self._cmd.update_prompt()
+
 
 @with_default_category('ISO7816 Commands')
 class Iso7816Commands(CommandSet):
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index b3e28ef..780da26 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -34,7 +34,7 @@
 
 from typing import cast, Optional, Iterable, List, Any, Dict, Tuple
 
-from pySim.utils import sw_match, h2b, b2h, is_hex, auto_int, bertlv_parse_one
+from pySim.utils import sw_match, h2b, b2h, i2h, is_hex, auto_int, bertlv_parse_one, Hexstr
 from pySim.construct import filter_dict
 from pySim.exceptions import *
 from pySim.jsonpath import js_path_find, js_path_modify
@@ -1020,6 +1020,17 @@
             print("error: could not determine card applications")
         return apps_taken
 
+    def reset(self, cmd_app=None) -> Hexstr:
+        """Perform physical card reset and obtain ATR.
+        Args:
+            cmd_app : Command Application State (for unregistering old file commands)
+        """
+        self.card._scc._tp.reset_card()
+        atr = i2h(self.card._scc._tp.get_atr())
+        # select MF to reset internal state and to verify card really works
+        self.select('MF', cmd_app)
+        return atr
+
     def get_cwd(self) -> CardDF:
         """Obtain the current working directory.
 

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I992eb3e0ed52f7941a5fb44f28a42e22ebd49301
Gerrit-Change-Number: 24109
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/20210503/56b33be4/attachment.htm>


More information about the gerrit-log mailing list