diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index f7750ffd3..617a703e4 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -758,20 +758,16 @@ int CmdHF14AAPDU(const char *cmd) { while(param_getchar(cmd, cmdp) != 0x00) { char c = param_getchar(cmd, cmdp); if ((c == '-') && (param_getlength(cmd, cmdp) == 2)) - switch (param_getchar_indx(cmd, 1, cmdp)) { + switch (tolower(param_getchar_indx(cmd, 1, cmdp))) { case 'h': - case 'H': return usage_hf_14a_apdu(); case 's': - case 'S': activateField = true; break; case 'k': - case 'K': leaveSignalON = true; break; case 't': - case 'T': decodeTLV = true; break; default: diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 55ed00312..24789bedd 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -17,6 +17,7 @@ int usage_sm_raw(void) { PrintAndLogEx(NORMAL, " r : do not read response"); PrintAndLogEx(NORMAL, " a : active signal field ON without select"); PrintAndLogEx(NORMAL, " s : active signal field ON with select"); + PrintAndLogEx(NORMAL, " t : executes TLV decoder if it possible"); PrintAndLogEx(NORMAL, " d : bytes to send"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); @@ -67,7 +68,7 @@ int CmdSmartRaw(const char *Cmd) { bool active = false; bool active_select = false; uint8_t cmdp = 0; - bool errors = false, reply = true; + bool errors = false, reply = true, decodeTLV = false; uint8_t data[USB_CMD_DATA_SIZE] = {0x00}; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -85,6 +86,10 @@ int CmdSmartRaw(const char *Cmd) { active_select = true; cmdp++; break; + case 't': + decodeTLV = true; + cmdp++; + break; case 'd': { switch (param_gethex_to_eol(Cmd, cmdp+1, data, sizeof(data), &hexlen)) { case 1: @@ -135,19 +140,27 @@ int CmdSmartRaw(const char *Cmd) { PrintAndLogEx(WARNING, "smart card response failed"); return 1; } - uint32_t len = resp.arg[0]; + uint32_t datalen = resp.arg[0]; - if ( !len ) { + if ( !datalen ) { PrintAndLogEx(WARNING, "smart card response failed"); return 1; } - PrintAndLogEx(INFO, "received %i bytes", len); + PrintAndLogEx(INFO, "received %i bytes", datalen); - if (!len) + if (!datalen) return 1; - PrintAndLogEx(SUCCESS, "%s", sprint_hex(resp.d.asBytes, len) ); + uint8_t *data = resp.d.asBytes; + + // TLV decoder + if (decodeTLV && datalen > 4) { + PrintAndLogEx(SUCCESS, "APDU response: %02x %02x - %s", data[datalen - 2], data[datalen - 1], GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1])); + TLVPrintFromBuffer(data, datalen - 2); + } else { + PrintAndLogEx(SUCCESS, "%s", sprint_hex(data, datalen)); + } } return 0; } diff --git a/client/cmdsmartcard.h b/client/cmdsmartcard.h index b21f30984..1c7b5d3f8 100644 --- a/client/cmdsmartcard.h +++ b/client/cmdsmartcard.h @@ -22,6 +22,8 @@ #include "util.h" #include "loclass/fileutils.h" // saveFile #include "cmdmain.h" // getfromdevice +#include "emv/emvcore.h" // decodeTVL +#include "emv/apduinfo.h" // APDUcode description extern int CmdSmartcard(const char *Cmd); diff --git a/common/i2c.c b/common/i2c.c index ac884ca22..a3ede5730 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -154,13 +154,14 @@ bool I2C_Start(void) { } bool I2C_WaitForSim() { - // variable delay here. + // variable delay here. if (!WaitSCL_L_300ms()) return false; // 8051 speaks with smart card. // 1000*50*3.07 = 153.5ms - if (!WaitSCL_H_delay(1000*50) ) + // 1byte transfer == 1ms + if (!WaitSCL_H_delay(2000*50) ) return false; return true; @@ -526,7 +527,7 @@ void I2C_print_status(void) { I2C_Reset_EnterMainProgram(); uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN); if ( len > 0 ) - Dbprintf(" version. ................v%x.%02x", resp[0], resp[1]); + Dbprintf(" version.................v%x.%02x", resp[0], resp[1]); else DbpString(" version.................FAILED"); }