Support programming of the MNC length value (EF.AD)

The file EF.AD contains the length of the MNC, this allows to phone to
distinguish where MCC/MNC end and where the MSIN number of the IMSI
begins. All cards are shipped with an MNC length of 2, which is fine for
the most situations, but when a MNC with 3 digits is needed the MNC
length value has to be updated. Otherwise the phone will recognize the
third digit of the MNC as part of the MSIN.

Related: OS#3850
This commit is contained in:
Philipp Maier 2019-03-21 17:05:42 +01:00
parent 3bd5054d56
commit 83760e2c22
6 changed files with 202 additions and 3 deletions

View File

@ -33,6 +33,7 @@ GSM_SIM_DF_TELECOM = [0x7F, 0x10]
GSM_SIM_DF_GSM = [0x7F, 0x20]
GSM_SIM_EF_ADN = [0x6f,0x3A]
GSM_SIM_EF_IMSI = [0x6F, 0x07]
GSM_SIM_EF_AD = [0x6f, 0xAD]
GSM_SIM_EF_ICCID = [0x2F, 0xE2]
GSM_USIM_EF_DIR = [0x2F, 0x00] # See also: 3GPP TS 31.102 Table 105

View File

@ -55,6 +55,8 @@ def helptext():
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 " -n, --mnclen ................... Show MNC length value"
print " -N, --set-mnclen ............... Set MNC length value"
print ""
@ -78,17 +80,19 @@ def main(argv):
getopt_seq_par = False
getopt_reset_seq_par = False
getopt_write_imsi = None
getopt_show_mnclen = None
getopt_write_mnclen = None
# Analyze commandline options
try:
opts, args = getopt.getopt(argv,
"ha:ucmtT:lL:oO:C:kK:fiI:sSJ:",
"ha:ucmtT:lL:oO:C:kK:fiI:sSJ:nN:",
["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",
"set-imsi"])
"set-imsi", "set-mnclen", "mnclen"])
except getopt.GetoptError:
print " * Error: Invalid commandline options"
sys.exit(2)
@ -138,6 +142,10 @@ def main(argv):
getopt_reset_seq_par = True
elif opt in ("-J", "--set-imsi"):
getopt_write_imsi = asciihex_to_list(pad_asciihex(arg, True, '9'))
elif opt in ("-n", "--mnclen"):
getopt_show_mnclen = True
elif opt in ("-N", "--set-mnclen"):
getopt_write_mnclen = asciihex_to_list(arg)
if not getopt_adm1:
@ -244,6 +252,16 @@ def main(argv):
sysmo_usim_write_imsi(sim, getopt_write_imsi)
print("")
if getopt_show_mnclen:
print "Reading MNCLEN value..."
sysmo_usim_show_mnclen(sim)
print("")
if getopt_write_mnclen:
print "Writing MNCLEN value..."
sysmo_usim_write_mnclen(sim, getopt_write_mnclen)
print("")
print "Done!"

View File

@ -591,3 +591,36 @@ def sysmo_usim_write_imsi(sim, imsi):
print " * Programming..."
sim.update_binary(imsi)
# Show current KI value
def sysmo_usim_show_mnclen(sim):
sysmo_usim_init(sim)
print " * Reading..."
sim.select(GSM_SIM_DF_GSM)
sim.select(GSM_SIM_EF_AD)
res = sim.read_binary(4)
print " * Current MNCLEN setting:"
print " MNCLEN: " + "0x%02x" % res.apdu[3]
# Program new MNCLEN value
def sysmo_usim_write_mnclen(sim, mnclen):
print " * New MNCLEN setting:"
print " MNCLEN: " + "0x" + hexdump(mnclen)
if len(mnclen) != 1:
print " * Error: mnclen value must consist of a single byte!"
return
sysmo_usim_init(sim)
sim.select(GSM_SIM_DF_GSM)
sim.select(GSM_SIM_EF_AD)
res = sim.read_binary(4)
new_ad = res.apdu[0:3] + mnclen
print " * Programming..."
sim.update_binary(new_ad)

132
tests/09_mnclen.out Normal file
View File

@ -0,0 +1,132 @@
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Writing MNCLEN value...
* New MNCLEN setting:
MNCLEN: 0x02
* Initalizing...
* Programming...
Done!
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Reading MNCLEN value...
* Initalizing...
* Reading...
* Current MNCLEN setting:
MNCLEN: 0x02
Done!
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Writing MNCLEN value...
* New MNCLEN setting:
MNCLEN: 0x03
* Initalizing...
* Programming...
Done!
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Reading MNCLEN value...
* Initalizing...
* Reading...
* Current MNCLEN setting:
MNCLEN: 0x03
Done!
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Writing MNCLEN value...
* New MNCLEN setting:
MNCLEN: 0x02
* Initalizing...
* Programming...
Done!
sysmoUSIM-SJS1 parameterization tool
Copyright (c)2017 Sysmocom s.f.m.c. GmbH
Initializing smartcard terminal...
Detected Card ICCID: 8988211320300000028
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Detected Card IMSI: 262423203000002
Reading MNCLEN value...
* Initalizing...
* Reading...
* Current MNCLEN setting:
MNCLEN: 0x02
Done!

15
tests/09_mnclen.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
. ./test-data
# set to 2 (default) + read back
$TOOL -a $ADMPIN -N 02
$TOOL -a $ADMPIN -n
# set to 3 + read back
$TOOL -a $ADMPIN -N 03
$TOOL -a $ADMPIN -n
# set to 2 (default) + read back
$TOOL -a $ADMPIN -N 02
$TOOL -a $ADMPIN -n

View File

@ -1,7 +1,7 @@
#!/bin/sh
# default: execute all tests
TESTS="01_auth.sh 02_mode_read.sh 03_mode_write.sh 04_algo.sh 05_milenage_par.sh 06_op_opc.sh 07_ki.sh 08_seq.sh"
TESTS="01_auth.sh 02_mode_read.sh 03_mode_write.sh 04_algo.sh 05_milenage_par.sh 06_op_opc.sh 07_ki.sh 08_seq.sh 09_mnclen.sh"
# if command line specifies some specific tests, execute only those
if [ $# -ge 1 ]; then