add cmds to read/write KI

This commit is contained in:
Neels Hofmeyr 2017-03-05 01:00:13 +01:00
parent 2c11efcdf6
commit 8b8ccfcba4
2 changed files with 51 additions and 2 deletions

View File

@ -49,6 +49,8 @@ def helptext():
print " -o, --opc ...................... Show OP/c configuration"
print " -O, --set-op HEXSTRING ......... Set OP value"
print " -C, --set-opc HEXSTRING ........ Set OPc value"
print " -k, --ki ....................... Show KI value"
print " -K, --set-ki ................... Set KI value"
print ""
@ -66,14 +68,17 @@ def main(argv):
getopt_show_opc = False
getopt_write_op = None
getopt_write_opc = None
getopt_show_ki = None
getopt_write_ki = None
# Analyze commandline options
try:
opts, args = getopt.getopt(argv,
"hva:ucmtT:lL:oO:C:",
"hva:ucmtT:lL:oO:C:kK:",
["help","verbose","adm1=","usim","classic",
"mode","auth","set-auth=","milenage",
"set-milenage","opc","set-op=","set-opc="])
"set-milenage","opc","set-op=","set-opc=",
"ki","set-ki="])
except getopt.GetoptError:
print " * Error: Invalid commandline options"
sys.exit(2)
@ -106,6 +111,10 @@ def main(argv):
getopt_write_op = asciihex_to_list(arg)
elif opt in ("-C", "--set-opc"):
getopt_write_opc = asciihex_to_list(arg)
elif opt in ("-k", "--ki"):
getopt_show_ki = True
elif opt in ("-K", "--set-ki"):
getopt_write_ki = asciihex_to_list(arg)
if not getopt_adm1:
@ -173,6 +182,17 @@ def main(argv):
sysmo_usim_show_opc_params(sim, getopt_adm1)
print("")
if getopt_write_ki:
print "Writing KI value..."
sysmo_usim_write_ki_params(sim,
getopt_adm1, getopt_write_ki)
print("")
if getopt_show_ki:
print "Reading KI value..."
sysmo_usim_show_ki_params(sim, getopt_adm1)
print("")
print "Done!"

View File

@ -269,6 +269,35 @@ def sysmo_usim_write_opc_params(sim, adm1, select, op):
sim.update_binary([select] + op)
# Show current KI value
def sysmo_usim_show_ki_params(sim, adm1):
sysmo_usim_init(sim)
sysmo_usim_admin_auth(sim, adm1)
print " * Reading..."
sim.select(GSM_SIM_DF_GSM)
sim.select(SYSMO_USIMSJS1_EF_KI)
res = sim.read_binary(16)
print " * Current KI setting:"
print " KI: " + hexdump(res.apdu)
# Program new KI value
def sysmo_usim_write_ki_params(sim, adm1, ki):
print " * New KI setting:"
print " KI: " + hexdump(ki)
sysmo_usim_init(sim)
sysmo_usim_admin_auth(sim, adm1)
sim.select(GSM_SIM_DF_GSM)
sim.select(SYSMO_USIMSJS1_EF_KI)
print " * Programming..."
sim.update_binary(ki)
# Show the enable status of the USIM application (app is enabled or disabled?)
def sysmo_usim_show_usim_status(sim, adm1):
sysmo_usim_init(sim)