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

Change subject: commands.py: fix read_binary for lengths > 256
......................................................................

commands.py: fix read_binary for lengths > 256

fixed commit with commented changes

Change-Id: Ie9c61caa1412606254b44a3a24f26ad44950e73a
---
M pySim/commands.py
1 file changed, 11 insertions(+), 2 deletions(-)

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



diff --git a/pySim/commands.py b/pySim/commands.py
index e077289..7288b19 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -119,8 +119,17 @@
                        return (None, None)
                if length is None:
                        length = self.__len(r) - offset
-               pdu = self.cla_byte + 'b0%04x%02x' % (offset, (min(256, length) 
& 0xff))
-               return self._tp.send_apdu(pdu)
+               total_data = ''
+               while offset < length:
+                       chunk_len = min(255, length-offset)
+                       pdu = self.cla_byte + 'b0%04x%02x' % (offset, chunk_len)
+                       data,sw = self._tp.send_apdu(pdu)
+                       if sw == '9000':
+                               total_data += data
+                               offset += chunk_len
+                       else:
+                               raise ValueError('Failed to read (offset %d)' % 
(offset))
+               return total_data, sw

        def update_binary(self, ef, data, offset=0, verify=False):
                self.select_file(ef)

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ie9c61caa1412606254b44a3a24f26ad44950e73a
Gerrit-Change-Number: 17848
Gerrit-PatchSet: 8
Gerrit-Owner: [email protected] <[email protected]>
Gerrit-Assignee: dexter <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: [email protected] <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-CC: dexter <[email protected]>
Gerrit-CC: herlesupreeth <[email protected]>
Gerrit-MessageType: merged

Reply via email to