Change in pysim[master]: utils.py: Add helper method to encode Service Table

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/.

laforge gerrit-no-reply at lists.osmocom.org
Sun Sep 20 09:49:22 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/20171 )

Change subject: utils.py: Add helper method to encode Service Table
......................................................................

utils.py: Add helper method to encode Service Table

This method helps in encoding of Service Tables in EF.SST, EF.UST, EF.EST, EF.IST.
Takes original hex string of EF.SST, EF.UST, EF.EST, EF.IST, Service number,
Service to be enabled or disable flag as input and outputs the modified Service Table.

Change-Id: I0c97317d5a17aa0df720659d021b5cbf7d30edcc
---
M pySim/utils.py
1 file changed, 43 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/pySim/utils.py b/pySim/utils.py
index dc14d58..d0d6cb5 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -460,6 +460,49 @@
 			bytelist = bytelist[ L+2 : ]
 	return ret
 
+def enc_st(st, service, state=1):
+	"""
+	Encodes the EF S/U/IST/EST and returns the updated Service Table
+
+	Parameters:
+		st - Current value of SIM/USIM/ISIM Service Table
+		service - Service Number to encode as activated/de-activated
+		state - 1 mean activate, 0 means de-activate
+
+	Returns:
+		s - Modified value of SIM/USIM/ISIM Service Table
+
+	Default values:
+		- state: 1 - Sets the particular Service bit to 1
+	"""
+	st_bytes = [st[i:i+2] for i in range(0, len(st), 2) ]
+
+	s = ""
+	# Check whether the requested service is present in each byte
+	for i in range(0, len(st_bytes)):
+		# Byte i contains info about Services num (8i+1) to num (8i+8)
+		if service in range((8*i) + 1, (8*i) + 9):
+			byte = int(st_bytes[i], 16)
+			# Services in each byte are in order MSB to LSB
+			# MSB - Service (8i+8)
+			# LSB - Service (8i+1)
+			mod_byte = 0x00
+			# Copy bit by bit contents of byte to mod_byte with modified bit
+			# for requested service
+			for j in range(1, 9):
+				mod_byte = mod_byte >> 1
+				if service == (8*i) + j:
+					mod_byte = state == 1 and mod_byte|0x80 or mod_byte&0x7f
+				else:
+					mod_byte = byte&0x01 == 0x01 and mod_byte|0x80 or mod_byte&0x7f
+				byte = byte >> 1
+
+			s += ('%02x' % (mod_byte))
+		else:
+			s += st_bytes[i]
+
+	return s
+
 def dec_epdgid(hexstr):
 	"""
 	Decode ePDG Id to get EF.ePDGId or EF.ePDGIdEm.

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I0c97317d5a17aa0df720659d021b5cbf7d30edcc
Gerrit-Change-Number: 20171
Gerrit-PatchSet: 4
Gerrit-Owner: herlesupreeth <herlesupreeth at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: herlesupreeth <herlesupreeth at gmail.com>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200920/2465fbca/attachment.htm>


More information about the gerrit-log mailing list