diff --git a/sysmo-usim-tool.sjs1.py b/sysmo-usim-tool.sjs1.py index eb8e46c..16d44f5 100755 --- a/sysmo-usim-tool.sjs1.py +++ b/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!" diff --git a/sysmo_usimsjs1.py b/sysmo_usimsjs1.py index d569b72..09dc249 100644 --- a/sysmo_usimsjs1.py +++ b/sysmo_usimsjs1.py @@ -47,7 +47,8 @@ along with this program. If not, see . # +--[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) diff --git a/utils.py b/utils.py index b7777e0..f492778 100644 --- a/utils.py +++ b/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