Change in pysim[master]: pySim-shell: Add open_channel + close_channel commands

laforge gerrit-no-reply at lists.osmocom.org
Sat Apr 10 16:41:30 UTC 2021


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


Change subject: pySim-shell: Add open_channel + close_channel commands
......................................................................

pySim-shell: Add open_channel + close_channel commands

Change-Id: I53d9d7f7720eb5f10956bff74ea7ba9fd3b3bd19
---
M docs/shell.rst
M pySim-shell.py
M pySim/commands.py
3 files changed, 38 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/08/23708/1

diff --git a/docs/shell.rst b/docs/shell.rst
index f2ddba1..30938fe 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -129,6 +129,18 @@
 ~~~~~~~~~~~~~
 Activate the currently selected file.  This used to be called REHABILITATE in TS 11.11.
 
+open_channel
+~~~~~~~~~~~~
+.. argparse::
+   :module: pySim-shell
+   :func: Iso7816Commands.open_chan_parser
+
+close_channel
+~~~~~~~~~~~~~
+.. argparse::
+   :module: pySim-shell
+   :func: Iso7816Commands.close_chan_parser
+
 
 pySim commands
 --------------
diff --git a/pySim-shell.py b/pySim-shell.py
index b2ccb9a..132733d 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -413,6 +413,23 @@
 		fid = self._cmd.rs.selected_file.fid
 		(data, sw) = self._cmd.card._scc.activate_file(fid)
 
+	open_chan_parser = argparse.ArgumentParser()
+	open_chan_parser.add_argument('chan_nr', type=int, default=0, help='Channel Number')
+
+	@cmd2.with_argparser(open_chan_parser)
+	def do_open_channel(self, opts):
+		"""Open a logical channel."""
+		(data, sw) = self._cmd.card._scc.manage_channel(mode='open', lchan_nr=opts.chan_nr)
+
+	close_chan_parser = argparse.ArgumentParser()
+	close_chan_parser.add_argument('chan_nr', type=int, default=0, help='Channel Number')
+
+	@cmd2.with_argparser(close_chan_parser)
+	def do_close_channel(self, opts):
+		"""Close a logical channel."""
+		(data, sw) = self._cmd.card._scc.manage_channel(mode='close', lchan_nr=opts.chan_nr)
+
+
 def parse_options():
 
 	parser = OptionParser(usage="usage: %prog [options]")
diff --git a/pySim/commands.py b/pySim/commands.py
index 2894d31..33aec12 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -304,6 +304,15 @@
 		"""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)
 
+	def manage_channel(self, mode='open', lchan_nr=0):
+		"""Execute MANAGE CHANNEL command as per TS 102 221 Section 11.1.17."""
+		if mode == 'close':
+			p1 = 0x80
+		else:
+			p1 = 0x00
+		pdu = self.cla_byte + '70%02x%02x00' % (p1, lchan_nr)
+		return self._tp.send_apdu_checksw(pdu)
+
 	def reset_card(self):
 		"""Physically reset the card"""
 		return self._tp.reset_card()

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I53d9d7f7720eb5f10956bff74ea7ba9fd3b3bd19
Gerrit-Change-Number: 23708
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/20210410/57ed8074/attachment.htm>


More information about the gerrit-log mailing list