diff options
author | Supreeth Herle <herlesupreeth@gmail.com> | 2020-03-24 16:15:02 +0100 |
---|---|---|
committer | herlesupreeth <herlesupreeth@gmail.com> | 2021-01-05 10:06:19 +0100 |
commit | 3b342c2f14789ac6203292beb9fc6eec58f4a552 (patch) | |
tree | c541fab6b2f98cb268707e8910f0ed5bef6037cc /pySim | |
parent | acc222f9f082983b642c60120fd941e34638d81a (diff) |
Re-purpose helper method to be used for parsing Address TLV Object in general
The Address TLV object is used in EF.P-CSCF Address, EF.ePDGId and EF.ePDGIdEm.
See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.8, 4.2.102 and 4.2.104.
Address TLV Object format
Tag (1 Byte) - '80'
Length (1 Byte)
Address Type (1 Byte) - '00' (FQDN), '01' (IPv4), '02' (IPv6)
Address (Address Length Bytes)
Change-Id: Ifd8a240f6b5c7736e58a8151295c30ec5b32ed5f
Diffstat (limited to 'pySim')
-rw-r--r-- | pySim/cards.py | 4 | ||||
-rw-r--r-- | pySim/utils.py | 21 |
2 files changed, 13 insertions, 12 deletions
diff --git a/pySim/cards.py b/pySim/cards.py index 1036717..1662fc5 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -267,12 +267,12 @@ class UsimCard(Card): def read_epdgid(self): (res, sw) = self._scc.read_binary(EF_USIM_ADF_map['ePDGId']) if sw == '9000': - return (dec_epdgid(res), sw) + return (dec_addr_tlv(res), sw) else: return (None, sw) def update_epdgid(self, epdgid): - epdgid_tlv = enc_epdgid(epdgid) + epdgid_tlv = enc_addr_tlv(epdgid) data, sw = self._scc.update_binary( EF_USIM_ADF_map['ePDGId'], epdgid_tlv) return sw diff --git a/pySim/utils.py b/pySim/utils.py index cdb2926..38cc580 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -500,19 +500,19 @@ def enc_st(st, service, state=1): return s -def dec_epdgid(hexstr): +def dec_addr_tlv(hexstr): """ - Decode ePDG Id to get EF.ePDGId or EF.ePDGIdEm. - See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.102 and 4.2.104. + Decode hex string to get EF.P-CSCF Address or EF.ePDGId or EF.ePDGIdEm. + See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.8, 4.2.102 and 4.2.104. """ # Convert from hex str to int bytes list - epdgid_bytes = h2i(hexstr) + addr_tlv_bytes = h2i(hexstr) s = "" # Get list of tuples containing parsed TLVs - tlvs = TLV_parser(epdgid_bytes) + tlvs = TLV_parser(addr_tlv_bytes) for tlv in tlvs: # tlv = (T, L, [V]) @@ -531,6 +531,7 @@ def dec_epdgid(hexstr): # First byte in the value has the address type addr_type = tlv[2][0] # TODO: Support parsing of IPv4 and IPv6 + # Address Type: 0x00 (FQDN), 0x01 (IPv4), 0x02 (IPv6), other (Reserved) if addr_type == 0x00: #FQDN # Skip address tye byte i.e. first byte in value list content = tlv[2][1:] @@ -538,20 +539,20 @@ def dec_epdgid(hexstr): return s -def enc_epdgid(epdg_addr, addr_type='00'): +def enc_addr_tlv(addr, addr_type='00'): """ - Encode ePDG Id so it can be stored to EF.ePDGId or EF.ePDGIdEm. - See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.102 and 4.2.104. + Encode address TLV object used in EF.P-CSCF Address, EF.ePDGId and EF.ePDGIdEm. + See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.8, 4.2.102 and 4.2.104. Default values: - - addr_type: 00 - FQDN format of ePDG Address + - addr_type: 00 - FQDN format of Address """ s = "" # TODO: Encoding of IPv4 and IPv6 address if addr_type == '00': - hex_str = s2h(epdg_addr) + hex_str = s2h(addr) s += '80' + ('%02x' % ((len(hex_str)//2)+1)) + '00' + hex_str return s |