Change in ...pysim[master]: test please ignore

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

dexter gerrit-no-reply at lists.osmocom.org
Thu Sep 12 12:05:46 UTC 2019


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/15501


Change subject: test please ignore
......................................................................

test please ignore

Change-Id: Ib757b1433c075c635fe43542103acae2167a1a15
---
M pySim/cards.py
1 file changed, 116 insertions(+), 48 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/01/15501/1

diff --git a/pySim/cards.py b/pySim/cards.py
index ec001ab..e1557c0 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -145,6 +145,107 @@
 		return sw
 
 
+class _GenericSimBase(Card):
+        """
+        A comfortable wrapper for the Card class. This class provides methods
+        that just accept just the parameter array. All further decisions,
+        parameter checking, status word checking are then done in this class.
+        """
+
+	def __check_sw(self, par, sw):
+		if sw != '9000':
+			print("Programming %s failed with code %s" % (par, sw))
+			return False
+		return True
+
+	# Safely get a parameter from the parameter array. Ensure that it
+	# exists and that it is not empty. Also ensure that it is always
+	# a string so that we know what we are working with.
+	def __get_p(self, p, p_name):
+		p_val = p.get(p_name, None)
+		if p_val == None:
+			return None
+		return str(p_val).strip()
+
+	def __get_mcc_mnc(self, p):
+		mcc = self.__get_p(p, 'mcc')
+		mnc = self.__get_p(p, 'mnc')
+
+		# If MCC is missing, try to obtain it from the IMSI
+		if mcc == None:
+			imsi = self.__get_p(p, 'imsi')
+			if imsi == None:
+				return (None, None)
+			mcc = mcc_from_imsi(imsi)
+
+		# If MNC is missing, try to obtain it from the IMSI
+		if mnc == None:
+			imsi = self.__get_p(p, 'imsi')
+			if imsi == None:
+				return (None, None)
+			mnc = mnc_from_imsi(imsi)
+		return mcc, mnc
+
+	def p_update_imsi(self, p):
+		imsi = self.__get_p(p, 'imsi')
+		if imsi != None:
+			sw = self.update_imsi(imsi)
+			return self.__check_sw('imsi',sw)
+		return False
+
+	def p_update_acc(self, p):
+		if p.get('acc'):
+			sw = self.update_acc(p['acc'])
+			return self.__check_sw('ACC',sw)
+
+	def p_update_plmnsel(self, p):
+		mcc, mnc = self.__get_mcc_mnc(p);
+		if mcc and mnc:
+			sw = self.update_plmnsel(int(mcc), int(mnc))
+			return self.__check_sw('PLMNsel',sw)
+		return False
+
+	def p_update_hplmn_act(self, p):
+		mcc, mnc = self.__get_mcc_mnc(p);
+		if mcc and mnc:
+			sw = self.update_hplmn_act(int(mcc), int(mnc))
+			return self.__check_sw('HPLMNwAcT',sw)
+		return False
+
+	def p_update_oplmn_act(self, p):
+		mcc, mnc = self.__get_mcc_mnc(p);
+		if mcc and mnc:
+			sw = self.update_oplmn_act(int(mcc), int(mnc))
+			return self.__check_sw('OPLMNwAcT',sw)
+		return False
+
+	def p_update_plmn_act(self, p):
+		mcc, mnc = self.__get_mcc_mnc(p);
+		if mcc and mnc:
+			sw = self.update_plmn_act(int(mcc), int(mnc))
+			return self.__check_sw('PLMNwAcT',sw)
+		return False
+
+	def p_update_smsp(self, p):
+		if p.get('smsp'):
+			sw = self.update_smsp(p['smsp'])
+			return self.__check_sw('SMSP',sw)
+
+	def p_update_ad(self, p):
+		mcc, mnc = self.__get_mcc_mnc(p);
+		if mcc and mnc:
+			sw = self.update_ad(int(mnc))
+			return self.__check_sw('AD',sw)
+		return False
+
+	def p_update_smsp(self, p):
+		smsp = self.__get_p(p, 'smsp')
+		if smsp:
+			sw = self.update_smsp(smsp)
+			return self.__check_sw('SMSP',sw)
+		return False
+
+
 class _MagicSimBase(Card):
 	"""
 	Theses cards uses several record based EFs to store the provider infos,
@@ -542,7 +643,7 @@
 	def erase(self):
 		return
 
-class SysmoUSIMSJS1(Card):
+class SysmoUSIMSJS1(_GenericSimBase):
 	"""
 	sysmocom sysmoUSIM-SJS1
 	"""
@@ -589,33 +690,21 @@
 			data, sw = self._scc.update_binary('00F7', content)
 
 		# write EF.IMSI
-		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
+                self.p_update_imsi(p)
 
 		# 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)
+                self.p_update_plmnsel(p)
 
                 # 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)
+                self.p_update_plmn_act(p)
 
                 # 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)
+                self.p_update_oplmn_act(p)
 
                 # 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)
+		self.p_update_ad(p)
 
-		# EF.SMSP
+		# EF.SMSP (propritary method?, why different than the others?)
 		if p.get('smsp'):
 			r = self._scc.select_file(['3f00', '7f10'])
 			data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True)
@@ -817,7 +906,7 @@
 		# write EF.IMSI
 		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
 
-class WavemobileSim(Card):
+class WavemobileSim(_GenericSimBase):
 	"""
 	WavemobileSim
 
@@ -864,46 +953,25 @@
 			print("Warning: Programming of the OPc is not implemented for this type of card.")
 
                 # EF.SMSP
-		if p.get('smsp'):
-			sw = self.update_smsp(p['smsp'])
-			if sw != '9000':
-				print("Programming SMSP failed with code %s"%sw)
+		self.p_update_smsp(p)
 
                 # EF.IMSI
-		if p.get('imsi'):
-			sw = self.update_imsi(p['imsi'])
-			if sw != '9000':
-				print("Programming IMSI failed with code %s"%sw)
+		self.p_update_imsi(p)
 
 		# EF.ACC
-		if p.get('acc'):
-			sw = self.update_acc(p['acc'])
-			if sw != '9000':
-				print("Programming ACC failed with code %s"%sw)
+		self.p_update_acc(p)
 
 		# 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)
+		self.p_update_plmnsel(p)
 
                 # 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)
+		self.p_update_plmn_act(p)
 
                 # 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)
+		self.p_update_oplmn_act(p)
 
                 # 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)
+		self.p_update_ad(p)
 
                 return None
 

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ib757b1433c075c635fe43542103acae2167a1a15
Gerrit-Change-Number: 15501
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190912/9bb3712e/attachment.htm>


More information about the gerrit-log mailing list