Print/Parse string representation of Algorithm Identifiers

We don't want to force the user to always open the manual every time
he uses the tool.
This commit is contained in:
Harald Welte 2017-08-16 22:38:38 +02:00
parent 72cf09e620
commit 3d7b74b3af
2 changed files with 48 additions and 8 deletions

View File

@ -169,9 +169,7 @@ def main(argv):
if getopt_write_auth:
print "Programming Authentication parameters..."
sysmo_usim_write_auth_params(sim,
int(getopt_write_auth[0]),
int(getopt_write_auth[1]))
sysmo_usim_write_auth_params(sim, getopt_write_auth[0], getopt_write_auth[1])
print("")
if getopt_show_auth:

View File

@ -227,6 +227,45 @@ def sysmo_usim_admin_auth(sim, adm1, force = False):
return rc
def sysmo_usim_algo_to_str(alg):
if alg == 1:
return 'MILENAGE'
elif alg == 3:
return 'COMP128v1'
elif alg == 4:
return 'XOR-2G'
elif alg == 5:
return 'GBA'
elif alg == 6:
return 'COMP128v2'
elif alg == 7:
return 'COMP128v3'
elif alg == 8:
return 'XOR-3G'
elif alg == 9:
return 'CIS-B'
else:
return 'INVALID'
def sysmo_usim_str_to_algo(alg):
if alg == 'MILENAGE' or alg == '1':
return 1
elif alg == 'COMP128v1' or alg == '3':
return 3
elif alg == 'XOR-2G' or alg == '4':
return 4
elif alg == 'GBA' or alg == '5':
return 5
elif alg == 'COMP128v2' or alg == '6':
return 6
elif alg == 'COMP128v3' or alg == '7':
return 7
elif alg == 'XOR-3G' or alg == '8':
return 8
elif alg == 'CIS-B' or alg == '9':
return 9
else:
raise ValueError('Unknown Algorithm %s', alg)
# Show current athentication parameters
# (Which algorithim is used for which rat?)
@ -239,15 +278,18 @@ def sysmo_usim_show_auth_params(sim):
res = sim.read_binary(0x02)
print " * Current algorithm setting:"
print " 2G: " + str(hex(res.apdu[0]))
print " 3G: " + str(hex(res.apdu[1]))
print " 2G: " + sysmo_usim_algo_to_str(res.apdu[0])
print " 3G: " + sysmo_usim_algo_to_str(res.apdu[1])
# Program new authentication parameters
def sysmo_usim_write_auth_params(sim, algo_2g, algo_3g):
def sysmo_usim_write_auth_params(sim, algo_2g_str, algo_3g_str):
algo_2g = sysmo_usim_str_to_algo(algo_2g_str)
algo_3g = sysmo_usim_str_to_algo(algo_3g_str)
print " * New algorithm setting:"
print " 2G: " + str(hex(algo_2g))
print " 3G: " + str(hex(algo_3g))
print " 2G: " + sysmo_usim_algo_to_str(algo_2g)
print " 3G: " + sysmo_usim_algo_to_str(algo_3g)
sysmo_usim_init(sim)