diff options
author | Bjoern Riemer <bjoern.riemer@fokus.fraunhofer.de> | 2021-12-17 15:16:35 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2022-01-31 11:55:12 +0000 |
commit | e91405e04edb8d08be4c91aa700cf8e179fe0794 (patch) | |
tree | 054854d4584b1e2f4f1abb0a0cc17bd85eca95d2 | |
parent | 9c93cec32ab812a8de8377a93d4c7b8f83b49301 (diff) |
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
-rw-r--r-- | pySim/ts_51_011.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py index 0f7e737..a4e3507 100644 --- a/pySim/ts_51_011.py +++ b/pySim/ts_51_011.py @@ -470,10 +470,34 @@ class EF_LP(TransRecEF): 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: str): + """Change the plmn part of the IMSI""" + plmn = arg.strip() + if len(plmn) == 5 or len(plmn) == 6: + (data, sw) = self._cmd.rs.read_binary_dec() + if sw == '9000' and len(data['imsi'])-len(plmn) == 10: + imsi = data['imsi'] + msin = imsi[len(plmn):] + (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("PLMN length does not match IMSI length") + else: + raise ValueError("PLMN has wrong length!") + # TS 51.011 Section 10.3.4 class EF_PLMNsel(TransRecEF): |