From b49eea563702ada952fb61e44ea179f852d61539 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 8 Jul 2018 12:03:35 +0200 Subject: [PATCH] chg: 'sc raw' -i2c correct lenght? chg: 'sc upgrade' - warning message chg: 'sc reader' - print right amount of bytes --- client/cmdsmartcard.c | 12 ++++++++---- common/i2c.c | 16 ++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 283021603..207a8e951 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -101,13 +101,16 @@ int CmdSmartRaw(const char *Cmd) { PrintAndLogEx(WARNING, "smart card response failed"); return 1; } - PrintAndLogEx(SUCCESS,"isOK %d | resp: %s",resp.arg[0], sprint_hex(resp.d.asBytes, resp.arg[1])); + PrintAndLogEx(SUCCESS,"isOK %d | resp: %s", resp.arg[0], sprint_hex(resp.d.asBytes, resp.arg[1])); } return 0; } int CmdSmartUpgrade(const char *Cmd) { + PrintAndLogEx(WARNING, "WARNING - Smartcard socket firmware upgrade."); + PrintAndLogEx(WARNING, "A dangerous command, do wrong and you will brick the smart card socket"); + FILE *f; char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; @@ -135,7 +138,7 @@ int CmdSmartUpgrade(const char *Cmd) { //Validations if (errors || cmdp == 0 ) return usage_sm_upgrade(); - + // load file f = fopen(filename, "rb"); if ( !f ){ @@ -252,7 +255,7 @@ int CmdSmartInfo(const char *Cmd){ // print header PrintAndLogEx(INFO, "\n--- Smartcard Information ---------"); PrintAndLogEx(INFO, "-------------------------------------------------------------"); - PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, sizeof(card.atr_len))); + PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, card.atr_len)); PrintAndLogEx(INFO, "\n todo - look up ATR "); return 0; } @@ -295,7 +298,8 @@ int CmdSmartReader(const char *Cmd){ smart_card_atr_t card; memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t)); - PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, sizeof(card.atr_len))); + PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, card.atr_len)); + return 0; } diff --git a/common/i2c.c b/common/i2c.c index 06b76a9b6..ba40a8e3b 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -556,7 +556,7 @@ bool GetATR(smart_card_atr_t *card_ptr) { // remove length byte from the read bytes. if ( card_ptr ) - card_ptr->atr_len = (len == 0) ? 0 : len - 1; + card_ptr->atr_len = (len == 0) ? 0 : len--; LogTrace(card_ptr->atr, card_ptr->atr_len, 0, 0, NULL, false); return true; @@ -564,17 +564,11 @@ bool GetATR(smart_card_atr_t *card_ptr) { void SmartCardAtr(void) { smart_card_atr_t card; - LED_D_ON(); clear_trace(); set_tracing(true); - I2C_Reset_EnterMainProgram(); - bool isOK = GetATR( &card ); - if ( isOK ) - Dbhexdump(card.atr_len, card.atr, false); - cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t)); LED_D_OFF(); } @@ -589,10 +583,9 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) { I2C_Reset_EnterMainProgram(); uint8_t len = 0; - uint8_t *resp = BigBuf_malloc(ISO7618_MAX_FRAME); + uint8_t *resp = BigBuf_malloc(ISO7618_MAX_FRAME); smart_card_atr_t card; - bool isOK = GetATR( &card ); if ( !isOK ) goto out; @@ -603,7 +596,7 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) { // Send raw bytes // start [C0 02] A0 A4 00 00 02 stop // asBytes = A0 A4 00 00 02 - // arg0 = len 5 + // arg1 = len 5 I2C_BufferWrite(data, arg1, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN); //wait for sim card to answer. @@ -615,6 +608,9 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) { // start [C0 03 start C1 len aa bb cc stop] len = I2C_BufferRead(resp, ISO7618_MAX_FRAME, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN); + // remove length byte from the read bytes. + if ( len > 0 ) len--; + // log answer LogTrace(resp, len, 0, 0, NULL, false); out: