From 79f43dda3d0700ef2cc4e3e06595a8f207a866bf Mon Sep 17 00:00:00 2001 From: Supreeth Herle Date: Wed, 25 Mar 2020 11:43:19 +0100 Subject: [PATCH] sysmoISIM-SJA2: Add support for programming IMS Home Network Domain Name As per 3GPP TS 31.103, this EF (DOMAIN) can found under ADF.ISIM at File Id 6f03. The Home Network Domain Name, i.e. FQDN shall be encoded to an octet string according to UTF-8 encoding rules as specified in IETF RFC 3629 [27]. The tag value of the Home Network Domain Name TLV data object shall be '80'. Example: ./pySim-prog.py -p 0 -x 001 -y 01 -s 8988211900000000004 -i 001011234567895 -k 8baf473f2f8fd09487cccbd7097c6862 --op 11111111111111111111111111111111 -o 8E27B6AF0E692E750F32667A3B14605D -a 85524953 -n isim.test --msisdn 0598765432100 --epdgid epdg.epc.mnc001.mcc001.pub.3gppnetwork.org --pcscf pcscf.testims.org --ims-hdomain testims.org Change-Id: I3c823203aee88734ae423e4ad73da1027a4eaeed --- pySim-prog.py | 4 ++++ pySim/cards.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/pySim-prog.py b/pySim-prog.py index 7ad57e64..f2780159 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -156,6 +156,9 @@ def parse_options(): parser.add_option("--pcscf", dest="pcscf", help="Set Proxy Call Session Control Function (P-CSCF) Address. (Only FQDN format supported)", ) + parser.add_option("--ims-hdomain", dest="ims_hdomain", + help="Set IMS Home Network Domain Name in FQDN format", + ) parser.add_option("--read-imsi", dest="read_imsi", action="store_true", help="Read the IMSI from the CARD", default=False ) @@ -464,6 +467,7 @@ def gen_parameters(opts): 'epdgid' : opts.epdgid, 'epdgSelection' : opts.epdgSelection, 'pcscf' : opts.pcscf, + 'ims_hdomain': opts.ims_hdomain, } diff --git a/pySim/cards.py b/pySim/cards.py index 42460fe3..7e479162 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -28,6 +28,7 @@ from pySim.ts_31_102 import EF_USIM_ADF_map from pySim.ts_31_103 import EF_ISIM_ADF_map from pySim.utils import * from smartcard.util import toBytes +from pytlv.TLV import * class Card(object): @@ -346,6 +347,23 @@ class IsimCard(Card): else: return (None, sw) + def update_domain(self, domain=None, mcc=None, mnc=None): + hex_str = "" + if domain: + hex_str = s2h(domain) + elif mcc and mnc: + # MCC and MNC always has 3 digits in domain form + plmn_str = 'mnc' + lpad(mnc, 3, "0") + '.mcc' + lpad(mcc, 3, "0") + hex_str = s2h('ims.' + plmn_str + '.3gppnetwork.org') + + # Build TLV + tlv = TLV(['80']) + content = tlv.build({'80': hex_str}) + + bin_size_bytes = self._scc.binary_size(EF_ISIM_ADF_map['DOMAIN']) + data, sw = self._scc.update_binary(EF_ISIM_ADF_map['DOMAIN'], rpad(content, bin_size_bytes*2)) + return sw + class _MagicSimBase(Card): """ @@ -1238,6 +1256,16 @@ class SysmoISIMSJA2(UsimCard, IsimCard): print("Programming P-CSCF failed with code %s"%sw) + # update EF.DOMAIN in ADF.ISIM + if self.file_exists(EF_ISIM_ADF_map['DOMAIN']): + if p.get('ims_hdomain'): + sw = self.update_domain(domain=p['ims_hdomain']) + else: + sw = self.update_domain() + + if sw != '9000': + print("Programming Home Network Domain Name failed with code %s"%sw) + if '9000' == self.select_adf_by_aid(): # update EF-USIM_AUTH_KEY in ADF.USIM if p.get('ki'):