Skip to content

Commit

Permalink
utils.py: Add helper method to parse ePDG Identifier from hex string
Browse files Browse the repository at this point in the history
The hex string consists of contains zero or more ePDG identifier data objects.
Each ePDG Identifier TLV data object consists of tag value of '80', length, address type, identifier.

TS 31.102 version 13.4.0 Release 13. The same parsing method applies for both EF.ePDGId and EF.ePDGIdEm

Change-Id: I96fb129d178cfd7ec037989526da77899ae8d344
  • Loading branch information
herlesupreeth committed May 11, 2020
1 parent 7d77d2d commit d572ede
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pySim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,37 @@ def TLV_parser(bytelist):
else:
bytelist = bytelist[ L+2 : ]
return ret

def dec_epdgid(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.
"""

# Convert from hex str to int bytes list
epdgid_bytes = h2i(hexstr)

s = ""

# Get list of tuples containing parsed TLVs
tlvs = TLV_parser(epdgid_bytes)

for tlv in tlvs:
# tlv = (T, L, [V])
# T = Tag
# L = Length
# [V] = List of value

# Invalid Tag value scenario
if tlv[0] != 0x80:
continue

# First byte in the value has the address type
addr_type = tlv[2][0]
# TODO: Support parsing of IPv4 and IPv6
if addr_type == 0x00: #FQDN
# Skip address tye byte i.e. first byte in value list
content = tlv[2][1:]
s += "\t%s # %s\n" % (i2h(content), i2s(content))

return s

0 comments on commit d572ede

Please sign in to comment.