Skip to contentSkip to conversation

Retrieve the correct TD byte when checking an ATR.

PATCH In review Jeremy White 2 participants 3 messages Jan 19, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Retrieve the correct TD byte when checking an ATR.

A physical smartcard with an ATR of
3B 95 95 40 FF AE 01 0E 00 00
was parsed incorrectly.

The '40' should have been the second TD; instead
the FF is used, incorrectly.

---
 hw/usb/ccid-card-passthru.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/ccid-card-passthru.c +1 -1
index 10f1d30..2ae3b81 100644
@@ -168,8 +168,8 @@ static int check_atr(PassthruState *card, uint8_t *data, int len)
             opt_bytes++;
         }
         if (td & 0x8) {
-            opt_bytes++;
             td = data[opt_bytes + 2] >> 4;
+            opt_bytes++;
         }
     }
     if (len < 2 + historical_length + opt_bytes) {
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jeremy White

A physical smartcard with an ATR of
3B 95 95 40 FF AE 01 0E 00 00
was parsed incorrectly.

The '40' should have been the second TD; instead
the FF is used, incorrectly.

The second TD? There is only one here, T0 = 0x95 & 0xf0 >> 4 = b1001

Quoted 21 lines
---
 hw/usb/ccid-card-passthru.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/ccid-card-passthru.c +1 -2
index 10f1d30..2ae3b81 100644
@@ -168,8 +168,8 @@ static int check_atr(PassthruState *card, uint8_t *data, int len)
             opt_bytes++;
         }
         if (td & 0x8) {
-            opt_bytes++;
             td = data[opt_bytes + 2] >> 4;
+            opt_bytes++;
         }
     }
     if (len < 2 + historical_length + opt_bytes) {
--
Quoted 3 lines

1.7.10.4

That looks correct, opt_bytes before incrementing points to the current TD.

Signature · 1 line
Marc-André Lureau
#2 lore raw
Quoted 4 lines
Quoted 2 lines

The '40' should have been the second TD; instead
the FF is used, incorrectly.

The second TD? There is only one here, T0 = 0x95 & 0xf0 >> 4 = b1001

Yes, sorry, I should not have capitalized TD in my comment. The code uses the variable 'td' to hold the upper 4 bits of T0, and then, if present, the upper 4 bits of TD1. So what is read imprecisely is the upper 4 bits of TD1.

I don't know qemu patch protocol; that seems like a very minor detail in the comment; does it justify a resubmit?

Quoted 30 lines
Quoted 22 lines
---
 hw/usb/ccid-card-passthru.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/ccid-card-passthru.c +1 -2
index 10f1d30..2ae3b81 100644
@@ -168,8 +168,8 @@ static int check_atr(PassthruState *card, uint8_t *data, int len)
             opt_bytes++;
         }
         if (td & 0x8) {
-            opt_bytes++;
             td = data[opt_bytes + 2] >> 4;
+            opt_bytes++;
         }
     }
     if (len < 2 + historical_length + opt_bytes) {
--
Quoted 3 lines

1.7.10.4

That looks correct, opt_bytes before incrementing points to the current TD.