cards: also program EF.AD under ADF.USIM

DF.GSM and ADF.USIM have an EF.AD with nearly the same contents. Usually
there is one file physically present and the other is just a link.
Apparantly this is not always the case for sysmo-ismi-sja2 cards, so
lets program EF.AD in both locations.

Change-Id: Ic9dd4acc8d9a72acbb7376ddf3e2128125d4a8f5
Related: OS#5830
This commit is contained in:
Philipp Maier 2023-01-17 14:26:56 +01:00
parent de0cf1648c
commit 284ac104af
1 changed files with 15 additions and 3 deletions

View File

@ -178,7 +178,7 @@ class SimCard:
data, sw = self._scc.update_record(EF['SMSP'], 1, rpad(smsp, 84))
return sw
def update_ad(self, mnc=None, opmode=None, ofm=None):
def update_ad(self, mnc=None, opmode=None, ofm=None, path=EF['AD']):
"""
Update Administrative Data (AD)
@ -191,6 +191,7 @@ class SimCard:
mnc (str): MNC of IMSI
opmode (Hex-str, 1 Byte): MS Operation Mode
ofm (Hex-str, 1 Byte): Operational Feature Monitor (OFM) aka Ciphering Indicator
path (optional list with file path e.g. ['3f00', '7f20', '6fad'])
Returns:
str: Return code of write operation
@ -200,7 +201,7 @@ class SimCard:
# read from card
raw_hex_data, sw = self._scc.read_binary(
EF['AD'], length=None, offset=0)
path, length=None, offset=0)
abstract_data = ad.decode_hex(raw_hex_data)
# perform updates
@ -223,7 +224,7 @@ class SimCard:
# write to card
raw_hex_data = ad.encode_hex(abstract_data)
data, sw = self._scc.update_binary(EF['AD'], raw_hex_data)
data, sw = self._scc.update_binary(path, raw_hex_data)
return sw
def read_spn(self):
@ -1576,6 +1577,17 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
data, sw = self.select_adf_by_aid(adf="usim")
if sw == '9000':
# EF.AD in ADF.USIM
if (p.get('mcc') and p.get('mnc')) or p.get('opmode'):
if p.get('mcc') and p.get('mnc'):
mnc = p['mnc']
else:
mnc = None
sw = self.update_ad(mnc=mnc, opmode=p.get('opmode'),
path=EF_USIM_ADF_map['AD'])
if sw != '9000':
print("Programming AD failed with code %s" % sw)
# update EF-USIM_AUTH_KEY in ADF.USIM
if p.get('ki'):
self._scc.update_binary('af20', p['ki'], 1)