Change in pysim[master]: Re-purpose helper method to be used for parsing Address TLV Object in...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

herlesupreeth gerrit-no-reply at lists.osmocom.org
Wed Dec 23 08:09:31 UTC 2020


herlesupreeth has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/21852 )


Change subject: Re-purpose helper method to be used for parsing Address TLV Object in general
......................................................................

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
---
M pySim-read.py
M pySim/cards.py
M pySim/utils.py
3 files changed, 14 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/52/21852/1

diff --git a/pySim-read.py b/pySim-read.py
index 2be34bd..c8b1a5d 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -35,7 +35,7 @@
 from pySim.commands import SimCardCommands
 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 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
 
 def parse_options():
diff --git a/pySim/cards.py b/pySim/cards.py
index 7e37271..dd0eaa6 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -267,12 +267,12 @@
 	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 ebc2a95..a6c6be9 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -500,19 +500,19 @@
 
 	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 @@
 		# 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 @@
 
 	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

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/21852
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ifd8a240f6b5c7736e58a8151295c30ec5b32ed5f
Gerrit-Change-Number: 21852
Gerrit-PatchSet: 1
Gerrit-Owner: herlesupreeth <herlesupreeth at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201223/5347f0e1/attachment.htm>


More information about the gerrit-log mailing list