From f964df4eb51465d7b00ac3fcb25661e45a3e5be7 Mon Sep 17 00:00:00 2001 From: Supreeth Herle Date: Tue, 24 Mar 2020 13:15:37 +0100 Subject: [PATCH] sysmoISIM-SJA2: Add support for programming EF.ePDGSelection (ePDG Selection Information) If the EF.ePDGSelection is present, it is populated with a single entry with PLMN 1 set to Home PLMN of USIM, ePDG FQDN format set to Operator Identifier FQDN and ePDG Priority value set to 1. Change-Id: I92f3f813afa41ae497ebc0dc2ca73da810f82364 --- pySim-prog.py | 13 +++++++++++++ pySim/cards.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pySim-prog.py b/pySim-prog.py index e172d80c..93ae924a 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -150,6 +150,9 @@ def parse_options(): parser.add_option("--epdgid", dest="epdgid", help="Set Home Evolved Packet Data Gateway (ePDG) Identifier. (Only FQDN format supported)", ) + parser.add_option("--epdgSelection", dest="epdgSelection", + help="Set PLMN for ePDG Selection Information. (Only Operator Identifier FQDN format supported)", + ) parser.add_option("--read-imsi", dest="read_imsi", action="store_true", help="Read the IMSI from the CARD", default=False ) @@ -433,6 +436,15 @@ def gen_parameters(opts): pin_adm = sanitize_pin_adm(opts) + # ePDG Selection Information + if opts.epdgSelection: + if len(opts.epdgSelection) < 5 or len(opts.epdgSelection) > 6: + raise ValueError('ePDG Selection Information is not valid') + epdg_mcc = opts.epdgSelection[:3] + epdg_mnc = opts.epdgSelection[3:] + if not epdg_mcc.isdigit() or not epdg_mnc.isdigit(): + raise ValueError('PLMN for ePDG Selection must only contain decimal digits') + # Return that return { 'name' : opts.name, @@ -447,6 +459,7 @@ def gen_parameters(opts): 'pin_adm' : pin_adm, 'msisdn' : opts.msisdn, 'epdgid' : opts.epdgid, + 'epdgSelection' : opts.epdgSelection, } diff --git a/pySim/cards.py b/pySim/cards.py index 6243d4a6..dc612dfe 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -284,6 +284,16 @@ class UsimCard(Card): else: return (None, sw) + def update_ePDGSelection(self, mcc, mnc): + (res, sw) = self._scc.read_binary(EF_USIM_ADF_map['ePDGSelection'], length=None, offset=0) + if sw == '9000' and (len(mcc) == 0 or len(mnc) == 0): + # Reset contents + # 80 - Tag value + (res, sw) = self._scc.update_binary(EF_USIM_ADF_map['ePDGSelection'], rpad('', len(res))) + elif sw == '9000': + (res, sw) = self._scc.update_binary(EF_USIM_ADF_map['ePDGSelection'], enc_ePDGSelection(res, mcc, mnc)) + return sw + def read_ust(self): (res, sw) = self._scc.read_binary(EF_USIM_ADF_map['UST']) if sw == '9000': @@ -1195,6 +1205,17 @@ class SysmoISIMSJA2(UsimCard): if sw != '9000': print("Programming ePDGId failed with code %s"%sw) + # update EF.ePDGSelection in ADF.USIM + if self.file_exists(EF_USIM_ADF_map['ePDGSelection']): + if p.get('epdgSelection'): + epdg_plmn = p['epdgSelection'] + sw = self.update_ePDGSelection(epdg_plmn[:3], epdg_plmn[3:]) + else: + sw = self.update_ePDGSelection("", "") + if sw != '9000': + print("Programming ePDGSelection failed with code %s"%sw) + + return