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
This commit is contained in:
Philipp Maier 2018-08-08 10:49:26 +02:00
parent 5144c904e6
commit 4cab3bb127
3 changed files with 34 additions and 6 deletions

View File

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

View File

@ -47,7 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# +--[EF_OPC 0x00F7] # +--[EF_OPC 0x00F7]
# | # |
# +--[EF_KI 0x00FF] # +--[EF_KI 0x00FF]
# |
# +--[EF_IMSI 0x6F07]
import sys import sys
from card import * from card import *
@ -574,3 +575,19 @@ def sysmo_usim_write_iccid(sim, iccid):
print " * Programming..." print " * Programming..."
sim.update_binary(swap_nibbles(iccid)) 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)

View File

@ -51,10 +51,12 @@ def asciihex_to_list(string):
# Pad an ascihex string with a nibble in case it is "incomplete" # 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: if front and len(string) % 2 != 0:
return string + padding return padding + string
elif len(string) % 2 != 0:
return string + padding
return string return string