From 36d774506c1be9832beb31d2be3d24f40b1adefc Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 5 Jul 2018 21:10:21 +0200 Subject: [PATCH] chg: 'sm raw' - implemented 'r' don't read reply --- armsrc/appmain.c | 2 +- client/cmdsmartcard.c | 25 +++++++++++++++---------- client/util.c | 8 +++----- common/i2c.c | 6 +++--- common/i2c.h | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index a5e38216e..a89525ad1 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1028,7 +1028,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { break; } case CMD_SMART_RAW: { - SmartCardRaw(c->arg[0], c->d.asBytes); + SmartCardRaw(c->arg[0], c->arg[1], c->d.asBytes); break; } case CMD_SMART_UPLOAD: { diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index a5d156f29..27ac7b241 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -15,7 +15,6 @@ int usage_sm_raw(void) { PrintAndLogEx(NORMAL, "Usage: sc raw [h|r|c] d <0A 0B 0C ... hex>"); PrintAndLogEx(NORMAL, " h : this help"); PrintAndLogEx(NORMAL, " r : do not read response"); - PrintAndLogEx(NORMAL, " c : calculate and append CRC"); PrintAndLogEx(NORMAL, " d : bytes to send"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); @@ -42,11 +41,16 @@ int CmdSmartRaw(const char *Cmd) { int hexlen = 0; uint8_t cmdp = 0; - bool errors = false; + bool errors = false, reply = true; uint8_t data[USB_CMD_DATA_SIZE] = {0x00}; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { + + case 'r': + reply = false; + cmdp++; + break; case 'd': { switch (param_gethex_to_eol(Cmd, cmdp+1, data, sizeof(data), &hexlen)) { case 1: @@ -73,20 +77,21 @@ int CmdSmartRaw(const char *Cmd) { //Validations if (errors || cmdp == 0 ) return usage_sm_raw(); - - UsbCommand c = {CMD_SMART_RAW, {hexlen, 0, 0}}; + UsbCommand c = {CMD_SMART_RAW, {0, hexlen, 0}}; memcpy(c.d.asBytes, data, hexlen ); clearCommandBuffer(); SendCommand(&c); - + // reading response from smart card - UsbCommand resp; - if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { - PrintAndLogEx(WARNING, "smart card response failed"); - return 1; + if ( reply ) { + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { + PrintAndLogEx(WARNING, "smart card response failed"); + return 1; + } + PrintAndLogEx(SUCCESS,"resp: %s", sprint_hex(resp.d.asBytes, resp.arg[0])); } - PrintAndLogEx(SUCCESS,"resp: %s", sprint_hex(resp.d.asBytes, resp.arg[0])); return 0;; } int CmdSmartUpgrade(const char *Cmd) { diff --git a/client/util.c b/client/util.c index e2ab9d85d..ffe55a781 100644 --- a/client/util.c +++ b/client/util.c @@ -502,8 +502,7 @@ uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base) return deflt; } -int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt) -{ +int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt) { int bg, en, i; uint32_t temp; @@ -514,7 +513,7 @@ int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt) if (en - bg + 1 != hexcnt) return 1; for(i = 0; i < hexcnt; i += 2) { - if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1; + if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1])) ) return 1; sscanf((char[]){line[bg + i], line[bg + i + 1], 0}, "%X", &temp); data[i / 2] = temp & 0xff; @@ -522,8 +521,7 @@ int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt) return 0; } -int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt) -{ +int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt) { int bg, en, i; uint32_t temp; diff --git a/common/i2c.c b/common/i2c.c index 4cb25355e..32e087920 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -525,7 +525,7 @@ void SmartCardAtr(void) { cmd_send(CMD_ACK, len, 0, 0, resp, sizeof(smart_card_atr_t)); } -void SmartCardRaw( uint64_t arg0, uint8_t *data ) { +void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) { #define ISO7618_MAX_FRAME 255 StartTicks(); I2C_Reset_EnterMainProgram(); @@ -550,12 +550,12 @@ void SmartCardRaw( uint64_t arg0, uint8_t *data ) { // start [C0 02] A0 A4 00 00 02 stop // asBytes = A0 A4 00 00 02 // arg0 = len 5 - I2C_BufferWrite(data, arg0, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN); + I2C_BufferWrite(data, arg1, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN); // read response // 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); - + out: StopTicks(); cmd_send(CMD_ACK, len, 0, 0, resp, len); diff --git a/common/i2c.h b/common/i2c.h index bb41c76f4..569110e3a 100644 --- a/common/i2c.h +++ b/common/i2c.h @@ -37,7 +37,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d // generice functions void SmartCardAtr(void); -void SmartCardRaw(uint64_t arg0, uint8_t *data); +void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data); void SmartCardUpgrade(uint64_t arg0); void I2C_print_status(void);