Change in pysim[master]: Fixed messy indentation and added ability to write HPLMN_ACT in Sysmo...

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
Mon Jan 20 12:18:00 UTC 2020


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


Change subject: Fixed messy indentation and added ability to write HPLMN_ACT in Sysmocom Card
......................................................................

Fixed messy indentation and added ability to write HPLMN_ACT in Sysmocom Card

Change-Id: I35848059d6082c379246c8d695cb094c20780d15
---
M pySim/cards.py
1 file changed, 60 insertions(+), 52 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/16945/1

diff --git a/pySim/cards.py b/pySim/cards.py
index 5d4d4f3..ff9c9b1 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -76,8 +76,10 @@
 		access_tech = 'FFFF' # All technologues selected, even Reserved for Future Use ones
 		"""
 		# get size and write EF.HPLMNwAcT
-		r = self._scc.select_file(EF['HPLMNwAcT'])
-		size = int(r[-1][4:8], 16)
+		#r = self._scc.select_file(EF['HPLMNwAcT'])
+		#size = int(r[-1][4:8], 16)
+		data = self._scc.read_binary(EF['HPLMNwAcT'], length=None, offset=0)
+		size = len(data[0])/2
 		hplmn = enc_plmn(mcc, mnc)
 		content = hplmn + access_tech
 		data, sw = self._scc.update_binary(EF['HPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
@@ -85,11 +87,11 @@
 
 	def update_oplmn_act(self, mcc, mnc, access_tech='FFFF'):
 		"""
-                See note in update_hplmn_act()
+				See note in update_hplmn_act()
 		"""
 		# get size and write EF.OPLMNwAcT
-	        data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
-                size = len(data[0])/2
+		data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
+		size = len(data[0])/2
 		hplmn = enc_plmn(mcc, mnc)
 		content = hplmn + access_tech
 		data, sw = self._scc.update_binary(EF['OPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
@@ -97,19 +99,19 @@
 
 	def update_plmn_act(self, mcc, mnc, access_tech='FFFF'):
 		"""
-                See note in update_hplmn_act()
+				See note in update_hplmn_act()
 		"""
 		# get size and write EF.PLMNwAcT
-	        data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
-                size = len(data[0])/2
+		data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
+		size = len(data[0])/2
 		hplmn = enc_plmn(mcc, mnc)
 		content = hplmn + access_tech
 		data, sw = self._scc.update_binary(EF['PLMNwAcT'], content + 'ffffff0000' * (size/5-1))
 		return sw
 
-        def update_plmnsel(self, mcc, mnc):
-	        data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
-                size = len(data[0])/2
+	def update_plmnsel(self, mcc, mnc):
+		data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
+		size = len(data[0])/2
 		hplmn = enc_plmn(mcc, mnc)
 		data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
 		return sw
@@ -119,16 +121,16 @@
 		return sw
 
 	def update_ad(self, mnc):
-                #See also: 3GPP TS 31.102, chapter 4.2.18
-                mnclen = len(str(mnc))
-                if mnclen == 1:
-                        mnclen = 2
-                if mnclen > 3:
+		#See also: 3GPP TS 31.102, chapter 4.2.18
+		mnclen = len(str(mnc))
+		if mnclen == 1:
+				mnclen = 2
+		if mnclen > 3:
 			raise RuntimeError('unable to calculate proper mnclen')
 
-	        data = self._scc.read_binary(EF['AD'], length=None, offset=0)
-                size = len(data[0])/2
-                content = data[0][0:6] + "%02X" % mnclen
+		data = self._scc.read_binary(EF['AD'], length=None, offset=0)
+		size = len(data[0])/2
+		content = data[0][0:6] + "%02X" % mnclen
 		data, sw = self._scc.update_binary(EF['AD'], content)
 		return sw
 
@@ -151,7 +153,7 @@
 	each possible provider uses a specific record number in each EF. The
 	indexes used are ( where N is the number of providers supported ) :
 	 - [2 .. N+1] for the operator name
-     - [1 .. N] for the programable EFs
+	 - [1 .. N] for the programable EFs
 
 	* 3f00/7f4d/8f0c : Operator Name
 
@@ -425,7 +427,7 @@
 	"""
 	name = 'sysmosim-gr1'
 
-        @classmethod
+	@classmethod
 	def autodetect(kls, scc):
 		try:
 			# Look for ATR
@@ -593,25 +595,31 @@
 		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
 
 		# EF.PLMNsel
-                if p.get('mcc') and p.get('mnc'):
-                        sw = self.update_plmnsel(p['mcc'], p['mnc'])
-                        if sw != '9000':
-				print("Programming PLMNsel failed with code %s"%sw)
+		if p.get('mcc') and p.get('mnc'):
+			sw = self.update_plmnsel(p['mcc'], p['mnc'])
+			if sw != '9000':
+				rint("Programming PLMNsel failed with code %s"%sw)
 
-                # EF.PLMNwAcT
-                if p.get('mcc') and p.get('mnc'):
+		# EF.PLMNwAcT
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_plmn_act(p['mcc'], p['mnc'])
 			if sw != '9000':
 				print("Programming PLMNwAcT failed with code %s"%sw)
 
-                # EF.OPLMNwAcT
-                if p.get('mcc') and p.get('mnc'):
+		# EF.OPLMNwAcT
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_oplmn_act(p['mcc'], p['mnc'])
 			if sw != '9000':
 				print("Programming OPLMNwAcT failed with code %s"%sw)
 
-                # EF.AD
-                if p.get('mcc') and p.get('mnc'):
+		# EF.HPLMNwAcT
+		if p.get('mcc') and p.get('mnc'):
+			sw = self.update_hplmn_act(p['mcc'], p['mnc'])
+			if sw != '9000':
+				print("Programming HPLMNwAcT failed with code %s"%sw)
+
+		# EF.AD
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_ad(p['mnc'])
 			if sw != '9000':
 				print("Programming AD failed with code %s"%sw)
@@ -848,28 +856,28 @@
 		if sw != '9000':
 			raise RuntimeError('Failed to authenticate with ADM key %s'%(p['pin_adm'],))
 
-                # EF.ICCID
-                # TODO: Add programming of the ICCID
-                if p.get('iccid'):
+		# EF.ICCID
+		# TODO: Add programming of the ICCID
+		if p.get('iccid'):
 			print("Warning: Programming of the ICCID is not implemented for this type of card.")
 
-                # KI (Presumably a propritary file)
-                # TODO: Add programming of KI
-                if p.get('ki'):
+		# KI (Presumably a propritary file)
+		# TODO: Add programming of KI
+		if p.get('ki'):
 			print("Warning: Programming of the KI is not implemented for this type of card.")
 
-                # OPc (Presumably a propritary file)
-                # TODO: Add programming of OPc
-                if p.get('opc'):
+		# OPc (Presumably a propritary file)
+		# TODO: Add programming of OPc
+		if p.get('opc'):
 			print("Warning: Programming of the OPc is not implemented for this type of card.")
 
-                # EF.SMSP
+		# EF.SMSP
 		if p.get('smsp'):
 			sw = self.update_smsp(p['smsp'])
 			if sw != '9000':
 				print("Programming SMSP failed with code %s"%sw)
 
-                # EF.IMSI
+				# EF.IMSI
 		if p.get('imsi'):
 			sw = self.update_imsi(p['imsi'])
 			if sw != '9000':
@@ -882,30 +890,30 @@
 				print("Programming ACC failed with code %s"%sw)
 
 		# EF.PLMNsel
-                if p.get('mcc') and p.get('mnc'):
-                        sw = self.update_plmnsel(p['mcc'], p['mnc'])
-                        if sw != '9000':
+		if p.get('mcc') and p.get('mnc'):
+			sw = self.update_plmnsel(p['mcc'], p['mnc'])
+			if sw != '9000':
 				print("Programming PLMNsel failed with code %s"%sw)
 
-                # EF.PLMNwAcT
-                if p.get('mcc') and p.get('mnc'):
+		# EF.PLMNwAcT
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_plmn_act(p['mcc'], p['mnc'])
 			if sw != '9000':
 				print("Programming PLMNwAcT failed with code %s"%sw)
 
-                # EF.OPLMNwAcT
-                if p.get('mcc') and p.get('mnc'):
+		# EF.OPLMNwAcT
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_oplmn_act(p['mcc'], p['mnc'])
 			if sw != '9000':
 				print("Programming OPLMNwAcT failed with code %s"%sw)
 
-                # EF.AD
-                if p.get('mcc') and p.get('mnc'):
+		# EF.AD
+		if p.get('mcc') and p.get('mnc'):
 			sw = self.update_ad(p['mnc'])
 			if sw != '9000':
 				print("Programming AD failed with code %s"%sw)
 
-                return None
+				return None
 
 	def erase(self):
 		return

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I35848059d6082c379246c8d695cb094c20780d15
Gerrit-Change-Number: 16945
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/20200120/25bf2efd/attachment.htm>


More information about the gerrit-log mailing list