Change in pysim[master]: commands.py: rename select_file() to select_path()

laforge gerrit-no-reply at lists.osmocom.org
Wed Mar 3 07:38:46 UTC 2021


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

Change subject: commands.py: rename select_file() to select_path()
......................................................................

commands.py: rename select_file() to select_path()

In reality, the function is not a simple avstraction around the SELECT
command, but it iterates over a list/path and selects at each element.

Change-Id: I63e01155de4ae47aeed8500708c0eb6580c7b8d1
---
M pySim/cards.py
M pySim/commands.py
2 files changed, 37 insertions(+), 37 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  dexter: Looks good to me, but someone else must approve



diff --git a/pySim/cards.py b/pySim/cards.py
index dd8fe8b..61d2624 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -44,7 +44,7 @@
 		return
 
 	def file_exists(self, fid):
-		res_arr = self._scc.try_select_file(fid)
+		res_arr = self._scc.try_select_path(fid)
 		for res in res_arr:
 			if res[1] != '9000':
 				return False
@@ -477,7 +477,7 @@
 		"""
 		f = self._files['name']
 
-		r = self._scc.select_file(['3f00', '7f4d', f[0]])
+		r = self._scc.select_path(['3f00', '7f4d', f[0]])
 		rec_len = int(r[-1][28:30], 16)
 		tlen = int(r[-1][4:8],16)
 		rec_cnt = (tlen / rec_len) - 1
@@ -489,7 +489,7 @@
 
 	def program(self, p):
 		# Go to dir
-		self._scc.select_file(['3f00', '7f4d'])
+		self._scc.select_path(['3f00', '7f4d'])
 
 		# Home PLMN in PLMN_Sel format
 		hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -533,7 +533,7 @@
 			# FIXME
 
 		# Write PLMN_Sel forcefully as well
-		r = self._scc.select_file(['3f00', '7f20', '6f30'])
+		r = self._scc.select_path(['3f00', '7f20', '6f30'])
 		tl = int(r[-1][4:8], 16)
 
 		hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -607,7 +607,7 @@
 		and entry size
 		"""
 
-		r = self._scc.select_file(['3f00', '000c'])
+		r = self._scc.select_path(['3f00', '000c'])
 		rec_len = int(r[-1][28:30], 16)
 		tlen = int(r[-1][4:8],16)
 		rec_cnt = (tlen / rec_len) - 1
@@ -619,7 +619,7 @@
 
 	def program(self, p):
 		# Home PLMN
-		r = self._scc.select_file(['3f00', '7f20', '6f30'])
+		r = self._scc.select_path(['3f00', '7f20', '6f30'])
 		tl = int(r[-1][4:8], 16)
 
 		hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -674,11 +674,11 @@
 		self._scc.verify_chv(5, pin)
 
 		# EF.ICCID
-		r = self._scc.select_file(['3f00', '2fe2'])
+		r = self._scc.select_path(['3f00', '2fe2'])
 		data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
 
 		# EF.IMSI
-		r = self._scc.select_file(['3f00', '7f20', '6f07'])
+		r = self._scc.select_path(['3f00', '7f20', '6f07'])
 		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
 
 		# EF.ACC
@@ -687,7 +687,7 @@
 
 		# EF.SMSP
 		if p.get('smsp'):
-			r = self._scc.select_file(['3f00', '7f10', '6f42'])
+			r = self._scc.select_path(['3f00', '7f10', '6f42'])
 			data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
 
 		# Set the Ki using proprietary command
@@ -695,13 +695,13 @@
 		data, sw = self._scc._tp.send_apdu(pdu)
 
 		# EF.HPLMN
-		r = self._scc.select_file(['3f00', '7f20', '6f30'])
+		r = self._scc.select_path(['3f00', '7f20', '6f30'])
 		size = int(r[-1][4:8], 16)
 		hplmn = enc_plmn(p['mcc'], p['mnc'])
 		self._scc.update_binary('6f30', hplmn + 'ff' * (size-3))
 
 		# EF.SPN (Service Provider Name)
-		r = self._scc.select_file(['3f00', '7f20', '6f30'])
+		r = self._scc.select_path(['3f00', '7f20', '6f30'])
 		size = int(r[-1][4:8], 16)
 		# FIXME
 
@@ -772,7 +772,7 @@
 	def program(self, p):
 
 		# select MF
-		r = self._scc.select_file(['3f00'])
+		r = self._scc.select_path(['3f00'])
 
 		# authenticate as SUPER ADM using default key
 		self._scc.verify_chv(0x0b, h2b("3838383838383838"))
@@ -798,7 +798,7 @@
 		data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
 
 		# select DF_GSM
-		r = self._scc.select_file(['7f20'])
+		r = self._scc.select_path(['7f20'])
 
 		# write EF.IMSI
 		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
@@ -808,7 +808,7 @@
 			data, sw = self._scc.update_binary('6f78', lpad(p['acc'], 4))
 
 		# get size and write EF.HPLMN
-		r = self._scc.select_file(['6f30'])
+		r = self._scc.select_path(['6f30'])
 		size = int(r[-1][4:8], 16)
 		hplmn = enc_plmn(p['mcc'], p['mnc'])
 		self._scc.update_binary('6f30', hplmn + 'ff' * (size-3))
@@ -820,7 +820,7 @@
 		data, sw = self._scc.update_binary('0001', p['ki'], 3)
 
 		# select DF_TELECOM
-		r = self._scc.select_file(['3f00', '7f10'])
+		r = self._scc.select_path(['3f00', '7f10'])
 
 		# write EF.SMSP
 		if p.get('smsp'):
@@ -862,13 +862,13 @@
 		self.verify_adm(h2b(p['pin_adm']))
 
 		# select MF
-		r = self._scc.select_file(['3f00'])
+		r = self._scc.select_path(['3f00'])
 
 		# write EF.ICCID
 		data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
 
 		# select DF_GSM
-		r = self._scc.select_file(['7f20'])
+		r = self._scc.select_path(['7f20'])
 
 		# set Ki in proprietary file
 		data, sw = self._scc.update_binary('00FF', p['ki'])
@@ -921,7 +921,7 @@
 
 		# EF.SMSP
 		if p.get('smsp'):
-			r = self._scc.select_file(['3f00', '7f10'])
+			r = self._scc.select_path(['3f00', '7f10'])
 			data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True)
 
 		# EF.MSISDN
@@ -932,7 +932,7 @@
 			msisdn = enc_msisdn(p['msisdn'])
 			data = 'ff' * 20 + msisdn + 'ff' * 2
 
-			r = self._scc.select_file(['3f00', '7f10'])
+			r = self._scc.select_path(['3f00', '7f10'])
 			data, sw = self._scc.update_record('6F40', 1, data, force_len=True)
 
 
@@ -1106,12 +1106,12 @@
 		self._scc.verify_chv(0x0A, h2b(p['pin_adm']))
 
 		# select MF
-		r = self._scc.select_file(['3f00'])
+		r = self._scc.select_path(['3f00'])
 
 		# write EF.ICCID
 		data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
 
-		r = self._scc.select_file(['7ff0'])
+		r = self._scc.select_path(['7ff0'])
 
 		# set Ki in proprietary file
 		data, sw = self._scc.update_binary('FF02', p['ki'])
@@ -1120,7 +1120,7 @@
 		data, sw = self._scc.update_binary('FF01', p['opc'])
 
 		# select DF_GSM
-		r = self._scc.select_file(['7f20'])
+		r = self._scc.select_path(['7f20'])
 
 		# write EF.IMSI
 		data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
@@ -1269,7 +1269,7 @@
 			print("Warning: Programming of the ICCID is not implemented for this type of card.")
 
 		# select DF_GSM
-		self._scc.select_file(['7f20'])
+		self._scc.select_path(['7f20'])
 
 		# write EF.IMSI
 		if p.get('imsi'):
@@ -1307,7 +1307,7 @@
 
 		# EF.SMSP
 		if p.get('smsp'):
-			r = self._scc.select_file(['3f00', '7f10'])
+			r = self._scc.select_path(['3f00', '7f10'])
 			data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True)
 
 		# EF.MSISDN
@@ -1318,7 +1318,7 @@
 			msisdn = enc_msisdn(p['msisdn'])
 			content = 'ff' * 20 + msisdn + 'ff' * 2
 
-			r = self._scc.select_file(['3f00', '7f10'])
+			r = self._scc.select_path(['3f00', '7f10'])
 			data, sw = self._scc.update_record('6F40', 1, content, force_len=True)
 
 		# EF.ACC
@@ -1332,8 +1332,8 @@
 
 		# update EF-SIM_AUTH_KEY (and EF-USIM_AUTH_KEY_2G, which is
 		# hard linked to EF-USIM_AUTH_KEY)
-		self._scc.select_file(['3f00'])
-		self._scc.select_file(['a515'])
+		self._scc.select_path(['3f00'])
+		self._scc.select_path(['a515'])
 		if p.get('ki'):
 			self._scc.update_binary('6f20', p['ki'], 1)
 		if p.get('opc'):
diff --git a/pySim/commands.py b/pySim/commands.py
index 327de57..d6159ea 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -99,7 +99,7 @@
 	def sel_ctrl(self, value):
 		self._sel_ctrl = value
 
-	def try_select_file(self, dir_list):
+	def try_select_path(self, dir_list):
 		rv = []
 		if type(dir_list) is not list:
 			dir_list = [dir_list]
@@ -110,7 +110,7 @@
 				return rv
 		return rv
 
-	def select_file(self, dir_list):
+	def select_path(self, dir_list):
 		rv = []
 		if type(dir_list) is not list:
 			dir_list = [dir_list]
@@ -124,7 +124,7 @@
 		return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid)
 
 	def read_binary(self, ef, length=None, offset=0):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		if len(r[-1]) == 0:
 			return (None, None)
 		if length is None:
@@ -142,7 +142,7 @@
 		return total_data, sw
 
 	def update_binary(self, ef, data, offset=0, verify=False):
-		self.select_file(ef)
+		self.select_path(ef)
 		pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data) // 2) + data
 		res = self._tp.send_apdu_checksw(pdu)
 		if verify:
@@ -155,13 +155,13 @@
 			raise ValueError('Binary verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
 
 	def read_record(self, ef, rec_no):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		rec_length = self.__record_len(r)
 		pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length)
 		return self._tp.send_apdu(pdu)
 
 	def update_record(self, ef, rec_no, data, force_len=False, verify=False):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		if not force_len:
 			rec_length = self.__record_len(r)
 			if (len(data) // 2 != rec_length):
@@ -180,21 +180,21 @@
 			raise ValueError('Record verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
 
 	def record_size(self, ef):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		return self.__record_len(r)
 
 	def record_count(self, ef):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		return self.__len(r) // self.__record_len(r)
 
 	def binary_size(self, ef):
-		r = self.select_file(ef)
+		r = self.select_path(ef)
 		return self.__len(r)
 
 	def run_gsm(self, rand):
 		if len(rand) != 32:
 			raise ValueError('Invalid rand')
-		self.select_file(['3f00', '7f20'])
+		self.select_path(['3f00', '7f20'])
 		return self._tp.send_apdu(self.cla_byte + '88000010' + rand)
 
 	def reset_card(self):

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I63e01155de4ae47aeed8500708c0eb6580c7b8d1
Gerrit-Change-Number: 23172
Gerrit-PatchSet: 8
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210303/503f3189/attachment.htm>


More information about the gerrit-log mailing list