laforge has uploaded this change for review.

View Change

transport: Implement treatment of 62xx and 63xx warning/error responses

TS 102 221 specifies that (in case of a class 4 command) and as SW
62xx or 63xx, we should send a GET RESPONSE just like in the 61xx
case in order to get the respective response.

As we don't really know if it's a case1/2/3/4 command in the
pySim.transport, let's always send the GET RESPONSE in case SW 62xx or
63xx are received. It shouldn't hurt - in the worst case there's no
response available...

Change-Id: Ibb1398194a16fc1f1f9bc46af6c66fb6575240cd
---
M pySim/transport/__init__.py
1 file changed, 23 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/52/37452/1
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index dd06af8..bc630e9 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -130,6 +130,7 @@
data : string (in hex) of returned data (ex. "074F4EFFFF")
sw : string (in hex) of status word (ex. "9000")
"""
+ prev_pdu = pdu
data, sw = self.send_apdu_raw(pdu)

# When we have sent the first APDU, the SW may indicate that there are response bytes
@@ -137,15 +138,17 @@
# xx is the number of response bytes available.
# See also:
if sw is not None:
- while ((sw[0:2] == '9f') or (sw[0:2] == '61')):
+ while (sw[0:2] in ['9f', '61', '62', '63']):
# SW1=9F: 3GPP TS 51.011 9.4.1, Responses to commands which are correctly executed
# SW1=61: ISO/IEC 7816-4, Table 5 — General meaning of the interindustry values of SW1-SW2
+ # SW1=62: ETSI TS 102 221 7.3.1.1.4 Clause 4b): 62xx, 63xx, 9xxx != 9000
pdu_gr = pdu[0:2] + 'c00000' + sw[2:4]
+ prev_pdu = pdu_gr
d, sw = self.send_apdu_raw(pdu_gr)
data += d
if sw[0:2] == '6c':
# SW1=6C: ETSI TS 102 221 Table 7.1: Procedure byte coding
- pdu_gr = pdu[0:8] + sw[2:4]
+ pdu_gr = prev_pdu[0:8] + sw[2:4]
data, sw = self.send_apdu_raw(pdu_gr)

return data, sw

To view, visit change 37452. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ibb1398194a16fc1f1f9bc46af6c66fb6575240cd
Gerrit-Change-Number: 37452
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange