Change in pysim[master]: commands: do not check SW manually, use send_apdu_checksw()

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
Mon Nov 1 16:17:33 UTC 2021


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


Change subject: commands: do not check SW manually, use send_apdu_checksw()
......................................................................

commands: do not check SW manually, use send_apdu_checksw()

The transport layer provides a method send_apdu_checksw to send APDUs
and to be sure the SW is the expected one. Given that, there is no need
to verify the SW manually. The exception of send_apdu_checksw will catch
the problem and also display the SW in a human readable form.

Change-Id: I9ce556ac0b7bb21c5c5a27170c32af0152255b79
Related: OS#5275
---
M pySim/commands.py
1 file changed, 6 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/55/26055/1

diff --git a/pySim/commands.py b/pySim/commands.py
index 805fe61..dbe7e51 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -145,12 +145,9 @@
 		while chunk_offset < length:
 			chunk_len = min(255, length-chunk_offset)
 			pdu = self.cla_byte + 'b0%04x%02x' % (offset + chunk_offset, chunk_len)
-			data,sw = self._tp.send_apdu(pdu)
-			if sw == '9000':
-				total_data += data
-				chunk_offset += chunk_len
-			else:
-				raise ValueError('Failed to read (offset %d)' % (offset))
+			data, sw = self._tp.send_apdu_checksw(pdu)
+			total_data += data
+			chunk_offset += chunk_len
 		return total_data, sw
 
 	def update_binary(self, ef, data:str, offset:int=0, verify:bool=False, conserve:bool=False):
@@ -172,19 +169,14 @@
 
 		self.select_path(ef)
 		total_data = ''
-		total_sw = "9000"
 		chunk_offset = 0
 		while chunk_offset < data_length:
 			chunk_len = min(255, data_length - chunk_offset)
 			# chunk_offset is bytes, but data slicing is hex chars, so we need to multiply by 2
 			pdu = self.cla_byte + 'd6%04x%02x' % (offset + chunk_offset, chunk_len) + data[chunk_offset*2 : (chunk_offset+chunk_len)*2]
-			chunk_data, chunk_sw = self._tp.send_apdu(pdu)
-			if chunk_sw == total_sw:
-				total_data += chunk_data
-				chunk_offset += chunk_len
-			else:
-				total_sw = chunk_sw
-				raise ValueError('Failed to write chunk (chunk_offset %d, chunk_len %d)' % (chunk_offset, chunk_len))
+			chunk_data, chunk_sw = self._tp.send_apdu_checksw(pdu)
+			total_data += chunk_data
+			chunk_offset += chunk_len
 		if verify:
 			self.verify_binary(ef, data, offset)
 		return total_data, total_sw

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9ce556ac0b7bb21c5c5a27170c32af0152255b79
Gerrit-Change-Number: 26055
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/20211101/cd09ee1c/attachment.htm>


More information about the gerrit-log mailing list