mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-30 23:00:10 +03:00
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
This commit is contained in:
committed by
herlesupreeth
parent
acc222f9f0
commit
3b342c2f14
@@ -35,7 +35,7 @@ from pySim.ts_31_103 import EF_IST_map
|
|||||||
from pySim.commands import SimCardCommands
|
from pySim.commands import SimCardCommands
|
||||||
from pySim.cards import card_detect, Card
|
from pySim.cards import card_detect, Card
|
||||||
from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn
|
from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn
|
||||||
from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, init_reader, dec_epdgid
|
from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, init_reader, dec_addr_tlv
|
||||||
from pySim.utils import h2s, format_ePDGSelection
|
from pySim.utils import h2s, format_ePDGSelection
|
||||||
|
|
||||||
def parse_options():
|
def parse_options():
|
||||||
|
|||||||
@@ -267,12 +267,12 @@ class UsimCard(Card):
|
|||||||
def read_epdgid(self):
|
def read_epdgid(self):
|
||||||
(res, sw) = self._scc.read_binary(EF_USIM_ADF_map['ePDGId'])
|
(res, sw) = self._scc.read_binary(EF_USIM_ADF_map['ePDGId'])
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
return (dec_epdgid(res), sw)
|
return (dec_addr_tlv(res), sw)
|
||||||
else:
|
else:
|
||||||
return (None, sw)
|
return (None, sw)
|
||||||
|
|
||||||
def update_epdgid(self, epdgid):
|
def update_epdgid(self, epdgid):
|
||||||
epdgid_tlv = enc_epdgid(epdgid)
|
epdgid_tlv = enc_addr_tlv(epdgid)
|
||||||
data, sw = self._scc.update_binary(
|
data, sw = self._scc.update_binary(
|
||||||
EF_USIM_ADF_map['ePDGId'], epdgid_tlv)
|
EF_USIM_ADF_map['ePDGId'], epdgid_tlv)
|
||||||
return sw
|
return sw
|
||||||
|
|||||||
@@ -500,19 +500,19 @@ def enc_st(st, service, state=1):
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def dec_epdgid(hexstr):
|
def dec_addr_tlv(hexstr):
|
||||||
"""
|
"""
|
||||||
Decode ePDG Id to get EF.ePDGId or EF.ePDGIdEm.
|
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.102 and 4.2.104.
|
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
|
# Convert from hex str to int bytes list
|
||||||
epdgid_bytes = h2i(hexstr)
|
addr_tlv_bytes = h2i(hexstr)
|
||||||
|
|
||||||
s = ""
|
s = ""
|
||||||
|
|
||||||
# Get list of tuples containing parsed TLVs
|
# Get list of tuples containing parsed TLVs
|
||||||
tlvs = TLV_parser(epdgid_bytes)
|
tlvs = TLV_parser(addr_tlv_bytes)
|
||||||
|
|
||||||
for tlv in tlvs:
|
for tlv in tlvs:
|
||||||
# tlv = (T, L, [V])
|
# tlv = (T, L, [V])
|
||||||
@@ -531,6 +531,7 @@ def dec_epdgid(hexstr):
|
|||||||
# First byte in the value has the address type
|
# First byte in the value has the address type
|
||||||
addr_type = tlv[2][0]
|
addr_type = tlv[2][0]
|
||||||
# TODO: Support parsing of IPv4 and IPv6
|
# TODO: Support parsing of IPv4 and IPv6
|
||||||
|
# Address Type: 0x00 (FQDN), 0x01 (IPv4), 0x02 (IPv6), other (Reserved)
|
||||||
if addr_type == 0x00: #FQDN
|
if addr_type == 0x00: #FQDN
|
||||||
# Skip address tye byte i.e. first byte in value list
|
# Skip address tye byte i.e. first byte in value list
|
||||||
content = tlv[2][1:]
|
content = tlv[2][1:]
|
||||||
@@ -538,20 +539,20 @@ def dec_epdgid(hexstr):
|
|||||||
|
|
||||||
return s
|
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.
|
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.102 and 4.2.104.
|
See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.8, 4.2.102 and 4.2.104.
|
||||||
|
|
||||||
Default values:
|
Default values:
|
||||||
- addr_type: 00 - FQDN format of ePDG Address
|
- addr_type: 00 - FQDN format of Address
|
||||||
"""
|
"""
|
||||||
|
|
||||||
s = ""
|
s = ""
|
||||||
|
|
||||||
# TODO: Encoding of IPv4 and IPv6 address
|
# TODO: Encoding of IPv4 and IPv6 address
|
||||||
if addr_type == '00':
|
if addr_type == '00':
|
||||||
hex_str = s2h(epdg_addr)
|
hex_str = s2h(addr)
|
||||||
s += '80' + ('%02x' % ((len(hex_str)//2)+1)) + '00' + hex_str
|
s += '80' + ('%02x' % ((len(hex_str)//2)+1)) + '00' + hex_str
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|||||||
Reference in New Issue
Block a user