diff options
author | Supreeth Herle <herlesupreeth@gmail.com> | 2020-03-25 14:25:38 +0100 |
---|---|---|
committer | herlesupreeth <herlesupreeth@gmail.com> | 2021-01-05 11:46:41 +0100 |
commit | 654eca72c992e9a75affc9ee2f2c488bc09693e2 (patch) | |
tree | 9e80627466337548404d6fe526c1742ef9776c5d | |
parent | 4779034f9e95714cf8b6f8a692ede344983feaa4 (diff) |
utils.py: Support IPv4 encoding for Address TLV object present in EF.ePDGId and EF.ePDGIdEm
Change-Id: Id46a44257d09c98ad5e0b7558e25e2bc52b23978
-rw-r--r-- | pySim/utils.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/pySim/utils.py b/pySim/utils.py index c5a38d8..782cb8b 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -550,10 +550,19 @@ def enc_addr_tlv(addr, addr_type='00'): s = "" - # TODO: Encoding of IPv4 and IPv6 address - if addr_type == '00': + # TODO: Encoding of IPv6 address + if addr_type == '00': #FQDN hex_str = s2h(addr) s += '80' + ('%02x' % ((len(hex_str)//2)+1)) + '00' + hex_str + elif addr_type == '01': #IPv4 + ipv4_list = addr.split('.') + ipv4_str = "" + for i in ipv4_list: + ipv4_str += ('%02x' % (int(i))) + + # Unused bytes shall be set to 'ff'. i.e 4th Octet after Address Type is not used + # IPv4 Address is in octet 5 to octet 8 of the TLV data object + s += '80' + ('%02x' % ((len(ipv4_str)//2)+2)) + '01' + 'ff' + ipv4_str return s |