chg: 'sc raw' -i2c correct lenght?

chg: 'sc upgrade' - warning message
chg: 'sc reader' - print right amount of bytes
This commit is contained in:
Chris 2018-07-08 12:03:35 +02:00
commit b49eea5637
2 changed files with 14 additions and 14 deletions

View file

@ -101,13 +101,16 @@ int CmdSmartRaw(const char *Cmd) {
PrintAndLogEx(WARNING, "smart card response failed"); PrintAndLogEx(WARNING, "smart card response failed");
return 1; 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; return 0;
} }
int CmdSmartUpgrade(const char *Cmd) { 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; FILE *f;
char filename[FILE_PATH_SIZE] = {0}; char filename[FILE_PATH_SIZE] = {0};
uint8_t cmdp = 0; uint8_t cmdp = 0;
@ -252,7 +255,7 @@ int CmdSmartInfo(const char *Cmd){
// print header // print header
PrintAndLogEx(INFO, "\n--- Smartcard Information ---------"); PrintAndLogEx(INFO, "\n--- Smartcard Information ---------");
PrintAndLogEx(INFO, "-------------------------------------------------------------"); 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 "); PrintAndLogEx(INFO, "\n todo - look up ATR ");
return 0; return 0;
} }
@ -295,7 +298,8 @@ int CmdSmartReader(const char *Cmd){
smart_card_atr_t card; smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t)); 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; return 0;
} }

View file

@ -556,7 +556,7 @@ bool GetATR(smart_card_atr_t *card_ptr) {
// remove length byte from the read bytes. // remove length byte from the read bytes.
if ( card_ptr ) 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); LogTrace(card_ptr->atr, card_ptr->atr_len, 0, 0, NULL, false);
return true; return true;
@ -564,17 +564,11 @@ bool GetATR(smart_card_atr_t *card_ptr) {
void SmartCardAtr(void) { void SmartCardAtr(void) {
smart_card_atr_t card; smart_card_atr_t card;
LED_D_ON(); LED_D_ON();
clear_trace(); clear_trace();
set_tracing(true); set_tracing(true);
I2C_Reset_EnterMainProgram(); I2C_Reset_EnterMainProgram();
bool isOK = GetATR( &card ); 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)); cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
LED_D_OFF(); LED_D_OFF();
} }
@ -589,10 +583,9 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
I2C_Reset_EnterMainProgram(); I2C_Reset_EnterMainProgram();
uint8_t len = 0; 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; smart_card_atr_t card;
bool isOK = GetATR( &card ); bool isOK = GetATR( &card );
if ( !isOK ) if ( !isOK )
goto out; goto out;
@ -603,7 +596,7 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
// Send raw bytes // Send raw bytes
// start [C0 02] A0 A4 00 00 02 stop // start [C0 02] A0 A4 00 00 02 stop
// asBytes = A0 A4 00 00 02 // asBytes = A0 A4 00 00 02
// arg0 = len 5 // arg1 = len 5
I2C_BufferWrite(data, arg1, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN); I2C_BufferWrite(data, arg1, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
//wait for sim card to answer. //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] // 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); 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 // log answer
LogTrace(resp, len, 0, 0, NULL, false); LogTrace(resp, len, 0, 0, NULL, false);
out: out: