laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/31004 )
Change subject: cards: also program EF.AD under ADF.USIM ......................................................................
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 --- M pySim/cards.py 1 file changed, 15 insertions(+), 3 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/pySim/cards.py b/pySim/cards.py index b8a37d4..4dc20a4 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -178,7 +178,7 @@ 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 @@ 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 @@
# 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 @@
# 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 @@
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)