Bjoern Riemer has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/26959 )


Change subject: implement shell command to update PLMN in IMSI
......................................................................

implement shell command to update PLMN in IMSI

Add file specific command `update_imsi_plmn` to EF_IMSI to replace
the mcc and mnc part of the imsi for use in bulk_script(s)

Change-Id: I9662ff074acf9dc974ae4c78edac44db286e98fc
---
M pySim/ts_51_011.py
1 file changed, 24 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/26959/1

diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 847ed98..96941b2 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -470,10 +470,34 @@
 class EF_IMSI(TransparentEF):
     def __init__(self, fid='6f07', sfid=None, name='EF.IMSI', desc='IMSI', 
size={9,9}):
         super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
+        # add those commands to the general commands of a TransparentEF
+        self.shell_commands += [self.AddlShellCommands(self)]
     def _decode_hex(self, raw_hex):
         return {'imsi': dec_imsi(raw_hex)}
     def _encode_hex(self, abstract):
         return enc_imsi(abstract['imsi'])
+    @with_default_category('File-Specific Commands')
+    class AddlShellCommands(CommandSet):
+        def __init__(self,ef:TransparentEF):
+            super().__init__()
+            self._ef=ef
+
+        def do_update_imsi_plmn(self, arg: string):
+            """Change the plmn part of the IMSI"""
+            plmn = arg.strip()
+            if len(plmn) == 5:
+                (data, sw) = self._cmd.rs.read_binary_dec()
+                if sw == '9000' and len(data['imsi']) == 15:
+                    imsi = data['imsi']
+                    msin = imsi[5:]
+                    (data, sw) = self._cmd.rs.update_binary_dec({'imsi': 
plmn+msin})
+                    if sw == '9000' and data:
+                        
self._cmd.poutput_json(self._cmd.rs.selected_file.decode_hex(data))
+                else:
+                    raise ValueError("invalid imsi")
+            else:
+                raise ValueError("PLMN has wrong length (xxxyy)")
+

 # TS 51.011 Section 10.3.4
 class EF_PLMNsel(TransRecEF):

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9662ff074acf9dc974ae4c78edac44db286e98fc
Gerrit-Change-Number: 26959
Gerrit-PatchSet: 1
Gerrit-Owner: Bjoern Riemer <[email protected]>
Gerrit-MessageType: newchange

Reply via email to