Add ICCID reading/programming feature
sysmo-usim-tool still can't read or program the ICCID. This patch adds enables reading and writing EF.ICCID
This commit is contained in:
parent
14aaab262e
commit
55bb02bc62
|
@ -51,6 +51,7 @@ def helptext():
|
||||||
print " -C, --set-opc HEXSTRING ........ Set OPc value"
|
print " -C, --set-opc HEXSTRING ........ Set OPc value"
|
||||||
print " -k, --ki ....................... Show KI value"
|
print " -k, --ki ....................... Show KI value"
|
||||||
print " -K, --set-ki ................... Set KI value"
|
print " -K, --set-ki ................... Set KI value"
|
||||||
|
print " -i, --iccid .................... Show ICCID value"
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,15 +72,17 @@ def main(argv):
|
||||||
getopt_show_ki = None
|
getopt_show_ki = None
|
||||||
getopt_write_ki = None
|
getopt_write_ki = None
|
||||||
getopt_force = False
|
getopt_force = False
|
||||||
|
getopt_show_iccid = False
|
||||||
|
getopt_write_iccid = None
|
||||||
|
|
||||||
# Analyze commandline options
|
# Analyze commandline options
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(argv,
|
opts, args = getopt.getopt(argv,
|
||||||
"hva:ucmtT:lL:oO:C:kK:f",
|
"hva:ucmtT:lL:oO:C:kK:fiI:",
|
||||||
["help","verbose","adm1=","usim","classic",
|
["help","verbose","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"])
|
"ki","set-ki=","force","iccid","set-iccid="])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print " * Error: Invalid commandline options"
|
print " * Error: Invalid commandline options"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -118,6 +121,10 @@ def main(argv):
|
||||||
getopt_write_ki = asciihex_to_list(arg)
|
getopt_write_ki = asciihex_to_list(arg)
|
||||||
elif opt in ("-f", "--force"):
|
elif opt in ("-f", "--force"):
|
||||||
getopt_force = True
|
getopt_force = True
|
||||||
|
elif opt in ("-i", "--iccid"):
|
||||||
|
getopt_show_iccid = True
|
||||||
|
elif opt in ("-I", "--set-iccid"):
|
||||||
|
getopt_write_iccid = asciihex_to_list(pad_asciihex(arg))
|
||||||
|
|
||||||
|
|
||||||
if not getopt_adm1:
|
if not getopt_adm1:
|
||||||
|
@ -205,6 +212,16 @@ def main(argv):
|
||||||
sysmo_usim_show_ki_params(sim, getopt_adm1)
|
sysmo_usim_show_ki_params(sim, getopt_adm1)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
if getopt_show_iccid:
|
||||||
|
print "Reading ICCID value..."
|
||||||
|
sysmo_usim_show_iccid(sim, getopt_adm1)
|
||||||
|
print("")
|
||||||
|
|
||||||
|
if getopt_write_iccid:
|
||||||
|
print "Writing ICCID value..."
|
||||||
|
sysmo_usim_write_iccid(sim, getopt_adm1, getopt_write_iccid)
|
||||||
|
print("")
|
||||||
|
|
||||||
print "Done!"
|
print "Done!"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -358,3 +358,26 @@ def sysmo_usim_write_sim_mode(sim, adm1, usim_enabled = True):
|
||||||
sim.update_record(new_record, rec_no = 1)
|
sim.update_record(new_record, rec_no = 1)
|
||||||
|
|
||||||
|
|
||||||
|
# Show current ICCID value
|
||||||
|
def sysmo_usim_show_iccid(sim, adm1):
|
||||||
|
sysmo_usim_init(sim)
|
||||||
|
|
||||||
|
print " * Reading..."
|
||||||
|
sim.select(GSM_SIM_EF_ICCID)
|
||||||
|
res = sim.read_binary(10)
|
||||||
|
|
||||||
|
print " * Current ICCID setting:"
|
||||||
|
print " ICCID: " + hexdump(swap_nibbles(res.apdu))
|
||||||
|
|
||||||
|
|
||||||
|
# Program new ICCID value
|
||||||
|
def sysmo_usim_write_iccid(sim, adm1, iccid):
|
||||||
|
print " * New ICCID setting:"
|
||||||
|
print " ICCID: " + hexdump(iccid)
|
||||||
|
|
||||||
|
sysmo_usim_init(sim)
|
||||||
|
|
||||||
|
sim.select(GSM_SIM_EF_ICCID)
|
||||||
|
|
||||||
|
print " * Programming..."
|
||||||
|
sim.update_binary(swap_nibbles(iccid))
|
||||||
|
|
17
utils.py
17
utils.py
|
@ -48,3 +48,20 @@ def asciihex_to_list(string):
|
||||||
except:
|
except:
|
||||||
print "Warning: Invalid hex string -- ignored!"
|
print "Warning: Invalid hex string -- ignored!"
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
# Pad an ascihex string with a nibble in case it is "incomplete"
|
||||||
|
def pad_asciihex(string, padding='f'):
|
||||||
|
|
||||||
|
if len(string) % 2 != 0:
|
||||||
|
return string + padding
|
||||||
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
# Swap nibbles of each byte in an array
|
||||||
|
def swap_nibbles(array):
|
||||||
|
|
||||||
|
rc = []
|
||||||
|
for a in array:
|
||||||
|
rc.append(((a & 0xf0) >> 4) | ((a & 0x0f) << 4))
|
||||||
|
return rc
|
||||||
|
|
Loading…
Reference in New Issue