Browse Source

sysmo-usim-tool.sjs1: Add capability to write IMSI

We unconditionally display the IMSI but we still lack support for
writing it. Lets support writing the IMSI as well in order to be more
complete.

- Add support for writing the IMSI

Change-Id: I1b3d1e1aae953663c13e78217de2a8ec3282b969
Related: OS#3376
for/master/mnclen
Philipp Maier 3 years ago
parent
commit
4cab3bb127
  1. 13
      sysmo-usim-tool.sjs1.py
  2. 19
      sysmo_usimsjs1.py
  3. 8
      utils.py

13
sysmo-usim-tool.sjs1.py

@ -54,6 +54,7 @@ def helptext():
print " -s --seq-parameters ........... Show MILENAGE SEQ/SQN parameters"
print " -S --reset-seq-parameters...... Reset MILENAGE SEQ/SQN parameters to default"
print " -I, --set-iccid ................ Set ICCID value"
print " -J, --set-imsi ................. Set IMSI value"
print ""
@ -76,16 +77,18 @@ def main(argv):
getopt_write_iccid = None
getopt_seq_par = False
getopt_reset_seq_par = False
getopt_write_imsi = None
# Analyze commandline options
try:
opts, args = getopt.getopt(argv,
"ha:ucmtT:lL:oO:C:kK:fiI:sS",
"ha:ucmtT:lL:oO:C:kK:fiI:sSJ:",
["help","adm1=","usim","classic",
"mode","auth","set-auth=","milenage",
"set-milenage","opc","set-op=","set-opc=",
"ki","set-ki=","force","iccid","set-iccid=",
"seq-parameters", "reset-seq-parameters"])
"seq-parameters", "reset-seq-parameters",
"set-imsi"])
except getopt.GetoptError:
print " * Error: Invalid commandline options"
sys.exit(2)
@ -133,6 +136,8 @@ def main(argv):
getopt_seq_par = True
elif opt in ("-S", "--reset-sqe-parameters"):
getopt_reset_seq_par = True
elif opt in ("-J", "--set-imsi"):
getopt_write_imsi = asciihex_to_list(pad_asciihex(arg, True, '9'))
if not getopt_adm1:
@ -234,6 +239,10 @@ def main(argv):
sysmo_usim_reset_milenage_sqn_params(sim)
print("")
if getopt_write_imsi:
print "Writing IMSI value..."
sysmo_usim_write_imsi(sim, getopt_write_imsi)
print("")
print "Done!"

19
sysmo_usimsjs1.py

@ -47,7 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# +--[EF_OPC 0x00F7]
# |
# +--[EF_KI 0x00FF]
# |
# +--[EF_IMSI 0x6F07]
import sys
from card import *
@ -574,3 +575,19 @@ def sysmo_usim_write_iccid(sim, iccid):
print " * Programming..."
sim.update_binary(swap_nibbles(iccid))
# Program new IMSI value
def sysmo_usim_write_imsi(sim, imsi):
print " * New ISMI setting:"
print " IMSI: " + hexdump(imsi)
sysmo_usim_init(sim)
sim.select(GSM_SIM_DF_GSM)
sim.select(GSM_SIM_EF_IMSI)
imsi = [len(imsi)] + swap_nibbles(imsi)
print " * Programming..."
sim.update_binary(imsi)

8
utils.py

@ -51,10 +51,12 @@ def asciihex_to_list(string):
# Pad an ascihex string with a nibble in case it is "incomplete"
def pad_asciihex(string, padding='f'):
def pad_asciihex(string, front=False, padding='f'):
if len(string) % 2 != 0:
return string + padding
if front and len(string) % 2 != 0:
return padding + string
elif len(string) % 2 != 0:
return string + padding
return string

Loading…
Cancel
Save