<p>andrew-ma has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/25114">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Allow update_binary function to write more than 255 bytes<br><br>The T0 protocol (selected in transport/pcsc.py) does not support extended APDU, so 255 bytes is the maximum number of bytes that can be transmitted at a time.  We can divide large data into 255 byte chunks.  The read_binary function already has code to read more than 255 bytes, so we can just adapt it to the update_binary function.<br><br>Change-Id: Icc240d5c8c04198640eb118565ea99f10ba27466<br>---<br>M pySim/commands.py<br>1 file changed, 15 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/14/25114/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/commands.py b/pySim/commands.py</span><br><span>index 76b7cd5..9657162 100644</span><br><span>--- a/pySim/commands.py</span><br><span>+++ b/pySim/commands.py</span><br><span>@@ -170,11 +170,23 @@</span><br><span>                               return None, sw</span><br><span> </span><br><span>          self.select_path(ef)</span><br><span style="color: hsl(0, 100%, 40%);">-            pdu = self.cla_byte + 'd6%04x%02x' % (offset, data_length) + data</span><br><span style="color: hsl(0, 100%, 40%);">-               res = self._tp.send_apdu_checksw(pdu)</span><br><span style="color: hsl(120, 100%, 40%);">+         total_data = ''</span><br><span style="color: hsl(120, 100%, 40%);">+               total_sw = "9000"</span><br><span style="color: hsl(120, 100%, 40%);">+           chunk_offset = offset</span><br><span style="color: hsl(120, 100%, 40%);">+         while chunk_offset < data_length:</span><br><span style="color: hsl(120, 100%, 40%);">+                  chunk_len = min(255, data_length - chunk_offset)</span><br><span style="color: hsl(120, 100%, 40%);">+                      # chunk_offset is bytes, but data slicing is hex chars, so we need to multiply by 2</span><br><span style="color: hsl(120, 100%, 40%);">+                   pdu = self.cla_byte + 'd6%04x%02x' % (chunk_offset, chunk_len) + data[chunk_offset*2 : (chunk_offset+chunk_len)*2]</span><br><span style="color: hsl(120, 100%, 40%);">+                    chunk_data, chunk_sw = self._tp.send_apdu(pdu)</span><br><span style="color: hsl(120, 100%, 40%);">+                        if chunk_sw == total_sw:</span><br><span style="color: hsl(120, 100%, 40%);">+                              total_data += chunk_data</span><br><span style="color: hsl(120, 100%, 40%);">+                              chunk_offset += chunk_len</span><br><span style="color: hsl(120, 100%, 40%);">+                     else:</span><br><span style="color: hsl(120, 100%, 40%);">+                         total_sw = chunk_sw</span><br><span style="color: hsl(120, 100%, 40%);">+                           raise ValueError('Failed to write chunk (chunk_offset %d, chunk_len %d)' % (chunk_offset, chunk_len))</span><br><span>                if verify:</span><br><span>                   self.verify_binary(ef, data, offset)</span><br><span style="color: hsl(0, 100%, 40%);">-            return res</span><br><span style="color: hsl(120, 100%, 40%);">+            return total_data, total_sw</span><br><span> </span><br><span>      def verify_binary(self, ef, data:str, offset:int=0):</span><br><span>                 """Verify contents of transparent EF.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/25114">change 25114</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/25114"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Icc240d5c8c04198640eb118565ea99f10ba27466 </div>
<div style="display:none"> Gerrit-Change-Number: 25114 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: andrew-ma <andrewm098@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>