From bc4894195158b12cd4bbb178c1cfbfd00d4a9d97 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 25 Oct 2020 01:12:20 +0200 Subject: [PATCH] fix smart card --- armsrc/i2c.c | 15 +++++++++------ client/src/cmdsmartcard.c | 15 ++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/armsrc/i2c.c b/armsrc/i2c.c index 7b858dd36..92737214a 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -181,7 +181,7 @@ static bool WaitSCL_L(void) { // It timeout reading response from card // Which ever comes first static bool WaitSCL_L_timeout(void) { - volatile uint32_t delay = 18000; + volatile uint32_t delay = 1800; while (delay--) { // exit on SCL LOW if (!SCL_read) @@ -219,7 +219,7 @@ static bool I2C_WaitForSim(void) { // 8051 speaks with smart card. // 1000*50*3.07 = 153.5ms // 1byte transfer == 1ms with max frame being 256bytes - if (!WaitSCL_H_delay(30 * 1000 * 50)) + if (!WaitSCL_H_delay(20 * 1000 * 50)) return false; return true; @@ -634,6 +634,9 @@ bool sc_rx_bytes(uint8_t *dest, uint8_t *destlen) { len = I2C_BufferRead(dest, *destlen, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN); + + LED_C_ON(); + if (len > 1) { break; } else if (len == 1) { @@ -667,7 +670,7 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose) { // 1byte = 1ms , max frame 256bytes. Should wait 256ms atleast just in case. if (I2C_WaitForSim() == false) return false; - + // read bytes from module uint8_t len = sizeof(card_ptr->atr); if (sc_rx_bytes(card_ptr->atr, &len) == false) @@ -706,12 +709,12 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose) { } void SmartCardAtr(void) { - smart_card_atr_t card; LED_D_ON(); set_tracing(true); I2C_Reset_EnterMainProgram(); - bool isOK = GetATR(&card, true); - reply_mix(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t)); + smart_card_atr_t card; + int res = GetATR(&card, true) ? PM3_SUCCESS : PM3_ETIMEOUT; + reply_ng(CMD_SMART_ATR, res, (uint8_t*)&card, sizeof(smart_card_atr_t)); set_tracing(false); LEDsoff(); } diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index c6b2e66e1..906a483e7 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -698,13 +698,12 @@ static int CmdSmartInfo(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_SMART_ATR, NULL, 0); PacketResponseNG resp; - if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { + if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return PM3_ETIMEOUT; } - uint8_t isok = resp.oldarg[0] & 0xFF; - if (!isok) { + if (resp.status != PM3_SUCCESS) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return PM3_ESOFT; } @@ -771,13 +770,12 @@ static int CmdSmartReader(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_SMART_ATR, NULL, 0); PacketResponseNG resp; - if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { + if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return PM3_ETIMEOUT; } - uint8_t isok = resp.oldarg[0] & 0xFF; - if (!isok) { + if (resp.status != PM3_SUCCESS) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return PM3_ESOFT; } @@ -1186,14 +1184,13 @@ bool smart_select(bool silent, smart_card_atr_t *atr) { clearCommandBuffer(); SendCommandNG(CMD_SMART_ATR, NULL, 0); PacketResponseNG resp; - if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { + if (!WaitForResponseTimeout(CMD_SMART_ATR, &resp, 2500)) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return false; } - uint8_t isok = resp.oldarg[0] & 0xFF; - if (!isok) { + if (resp.status != PM3_SUCCESS) { if (!silent) PrintAndLogEx(WARNING, "smart card select failed"); return false; }