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


Change subject: ts_102_222: Implement support for RESIZE FILE for an EF
......................................................................

ts_102_222: Implement support for RESIZE FILE for an EF

This adds pySim-shell support for the RESIZE FILE command in order
to change the size of linear fixed or transparent EF.

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



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/15/31715/1

diff --git a/docs/shell.rst b/docs/shell.rst
index c1f37af..9ffbac3 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -650,6 +650,12 @@
    :module: pySim.ts_102_222
    :func: Ts102222Commands.createdf_parser

+resize_ef
+~~~~~~~~~
+.. argparse::
+   :module: pySim.ts_102_222
+   :func: Ts102222Commands.resize_ef_parser
+

 ARA-M commands
 --------------
diff --git a/pySim/commands.py b/pySim/commands.py
index fa0458a..d123e67 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -457,6 +457,10 @@
         """Execute CREEATE FILE command as per TS 102 222 Section 6.3"""
         return self._tp.send_apdu_checksw(self.cla_byte + 'e00000%02x%s' % 
(len(payload)//2, payload))

+    def resize_file(self, payload: Hexstr):
+        """Execute RESIZE FILE command as per TS 102 222 Section 6.10"""
+        return self._tp.send_apdu_checksw('80d40000%02x%s' % (len(payload)//2, 
payload))
+
     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)
diff --git a/pySim/ts_102_222.py b/pySim/ts_102_222.py
index 4843c77..c377cad 100644
--- a/pySim/ts_102_222.py
+++ b/pySim/ts_102_222.py
@@ -206,3 +206,20 @@
         (data, sw) = self._cmd.card._scc.create_file(b2h(fcp.to_tlv()))
         # the newly-created file is automatically selected but our runtime 
state knows nothing of it
         self._cmd.lchan.select_file(self._cmd.lchan.selected_file)
+
+    resize_ef_parser = argparse.ArgumentParser()
+    resize_ef_parser.add_argument('FILE_ID', type=str, help='File Identifier 
as 4-character hex string')
+    resize_ef_parser._action_groups.pop()
+    resize_ef_required = resize_ef_parser.add_argument_group('required 
arguments')
+    resize_ef_required.add_argument('--file-size', required=True, type=int, 
help='Size of file in octets')
+
+    @cmd2.with_argparser(resize_ef_parser)
+    def do_resize_ef(self, opts):
+        """Resize an existing EF below the currently selected DF.  Requires 
related privileges."""
+
+        ies = [FileIdentifier(decoded=opts.FILE_ID),
+               FileSize(decoded=opts.file_size)]
+        fcp = FcpTemplate(children=ies)
+        (data, sw) = self._cmd.card._scc.resize_file(b2h(fcp.to_tlv()))
+        # the resized file is automatically selected but our runtime state 
knows nothing of it
+        self._cmd.lchan.select_file(self._cmd.lchan.selected_file)

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

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

Reply via email to