]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/i2c.c
uart_posix.c rework
[proxmark3-svn] / armsrc / i2c.c
index 0560d306b508d1c6fb648da9ed75761c7e666371..3d16b42cea10783cfc27fb7b9b646ffdf58f0a70 100644 (file)
@@ -18,6 +18,7 @@
 #include "mifareutil.h" // for MF_DBGLEVEL
 #include "BigBuf.h"
 #include "apps.h"
+#include "usb_cdc.h"
 
 #ifdef WITH_SMARTCARD
 #include "smartcard.h"
@@ -257,10 +258,11 @@ static void I2C_Reset_EnterBootloader(void) {
        WaitMS(10);
 }
 
-// Wait max 300ms or until SCL goes LOW.
+// Wait max 1800ms or until SCL goes LOW.
+// It timeout reading response from card
 // Which ever comes first
-static bool WaitSCL_L_300ms(void) {
-       volatile uint16_t delay = 310;
+bool WaitSCL_L_timeout(void){
+       volatile uint16_t delay = 1800;
        while ( delay-- ) {
                // exit on SCL LOW
                if (!SCL_read)
@@ -272,8 +274,8 @@ static bool WaitSCL_L_300ms(void) {
 }
 
 static bool I2C_WaitForSim() {
-       // variable delay here.
-       if (!WaitSCL_L_300ms())
+       // wait for data from card
+       if (!WaitSCL_L_timeout())
                return false;
 
        // 8051 speaks with smart card.
@@ -656,28 +658,6 @@ static bool GetATR(smart_card_atr_t *card_ptr) {
        if ( !sc_rx_bytes(card_ptr->atr, &len) )                
                return false;
 
-       uint8_t pos_td = 1;
-       if ( (card_ptr->atr[1] & 0x10) == 0x10) pos_td++;
-       if ( (card_ptr->atr[1] & 0x20) == 0x20) pos_td++;
-       if ( (card_ptr->atr[1] & 0x40) == 0x40) pos_td++;
-       
-       // T0 indicate presence T=0 vs T=1.  T=1 has checksum TCK
-       if ( (card_ptr->atr[1] & 0x80) == 0x80) {
-               
-               pos_td++;
-       
-               // 1 == T1 ,  presence of checksum TCK
-               if ( (card_ptr->atr[pos_td] & 0x01) == 0x01) {
-                       uint8_t chksum = 0;
-                       // xor property.  will be zero when xored with chksum.
-                       for (uint8_t i = 1; i < len; ++i)
-                               chksum ^= card_ptr->atr[i];
-                       if ( chksum ) {
-                               if ( MF_DBGLEVEL > 2) DbpString("Wrong ATR checksum");
-                       }
-               }
-       }
-
        card_ptr->atr_len = len;
        LogTrace(card_ptr->atr, card_ptr->atr_len, 0, 0, NULL, false);
 
Impressum, Datenschutz