mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 06:13:27 -07:00
add smartcard to menu + make get atr work
sc is now functioning as far as my limited knowledge takes me
This commit is contained in:
parent
419ffeacc1
commit
68e93fa639
6 changed files with 71 additions and 42 deletions
|
@ -30,6 +30,10 @@
|
||||||
#ifdef WITH_LCD
|
#ifdef WITH_LCD
|
||||||
#include "LCD.h"
|
#include "LCD.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WITH_SMARTCARD
|
||||||
|
#include "i2c.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Craig Young - 14a stand-alone code
|
// Craig Young - 14a stand-alone code
|
||||||
#ifdef WITH_ISO14443a
|
#ifdef WITH_ISO14443a
|
||||||
|
@ -1253,6 +1257,35 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||||
HfSnoop(c->arg[0], c->arg[1]);
|
HfSnoop(c->arg[0], c->arg[1]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WITH_SMARTCARD
|
||||||
|
case CMD_SMART_ATR: {
|
||||||
|
SmartCardAtr();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SMART_SETBAUD:{
|
||||||
|
SmartCardSetBaud(c->arg[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SMART_SETCLOCK:{
|
||||||
|
SmartCardSetClock(c->arg[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SMART_RAW: {
|
||||||
|
SmartCardRaw(c->arg[0], c->arg[1], c->d.asBytes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SMART_UPLOAD: {
|
||||||
|
// upload file from client
|
||||||
|
uint8_t *mem = BigBuf_get_addr();
|
||||||
|
memcpy( mem + c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
|
||||||
|
cmd_send(CMD_ACK,1,0,0,0,0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SMART_UPGRADE: {
|
||||||
|
SmartCardUpgrade(c->arg[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case CMD_BUFF_CLEAR:
|
case CMD_BUFF_CLEAR:
|
||||||
BigBuf_Clear();
|
BigBuf_Clear();
|
||||||
|
|
18
armsrc/i2c.c
18
armsrc/i2c.c
|
@ -259,7 +259,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||||
do {
|
do {
|
||||||
if (!I2C_Start())
|
if (!I2C_Start())
|
||||||
return false;
|
return false;
|
||||||
|
//[C0]
|
||||||
I2C_SendByte(device_address & 0xFE);
|
I2C_SendByte(device_address & 0xFE);
|
||||||
if (!I2C_WaitAck())
|
if (!I2C_WaitAck())
|
||||||
break;
|
break;
|
||||||
|
@ -545,6 +545,8 @@ bool GetATR(smart_card_atr_t *card_ptr) {
|
||||||
// Send ATR
|
// Send ATR
|
||||||
// start [C0 01] stop start C1 len aa bb cc stop]
|
// start [C0 01] stop start C1 len aa bb cc stop]
|
||||||
I2C_WriteCmd(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN);
|
I2C_WriteCmd(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN);
|
||||||
|
uint8_t cmd[1] = {1};
|
||||||
|
LogTrace(cmd, 1, 0, 0, NULL, true);
|
||||||
|
|
||||||
//wait for sim card to answer.
|
//wait for sim card to answer.
|
||||||
if (!I2C_WaitForSim())
|
if (!I2C_WaitForSim())
|
||||||
|
@ -556,10 +558,24 @@ bool GetATR(smart_card_atr_t *card_ptr) {
|
||||||
if ( len == 0 )
|
if ( len == 0 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// for some reason we only get first byte of atr, if that is so, send dummy command to retrieve the rest of the atr
|
||||||
|
if (len == 1) {
|
||||||
|
|
||||||
|
uint8_t data[1] = {0};
|
||||||
|
I2C_BufferWrite(data, len, I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
|
||||||
|
|
||||||
|
if ( !I2C_WaitForSim() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
uint8_t len2 = I2C_BufferRead(card_ptr->atr + len, sizeof(card_ptr->atr) - len, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN);
|
||||||
|
len = len + len2;
|
||||||
|
}
|
||||||
|
|
||||||
if ( card_ptr ) {
|
if ( card_ptr ) {
|
||||||
card_ptr->atr_len = len;
|
card_ptr->atr_len = 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "util_posix.h"
|
#include "util_posix.h"
|
||||||
#include "cmdscript.h"
|
#include "cmdscript.h"
|
||||||
|
#ifdef WITH_SMARTCARD
|
||||||
|
#include "cmdsmartcard.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
static int CmdQuit(const char *Cmd);
|
static int CmdQuit(const char *Cmd);
|
||||||
|
@ -39,6 +41,9 @@ static command_t CommandTable[] =
|
||||||
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
|
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
|
||||||
{"hw", CmdHW, 1, "{ Hardware commands... }"},
|
{"hw", CmdHW, 1, "{ Hardware commands... }"},
|
||||||
{"lf", CmdLF, 1, "{ Low Frequency commands... }"},
|
{"lf", CmdLF, 1, "{ Low Frequency commands... }"},
|
||||||
|
#ifdef WITH_SMARTCARD
|
||||||
|
{"sc", CmdSmartcard,1,"{ Smartcard commands... }"},
|
||||||
|
#endif
|
||||||
{"script",CmdScript,1, "{ Scripting commands }"},
|
{"script",CmdScript,1, "{ Scripting commands }"},
|
||||||
{"quit", CmdQuit, 1, "Exit program"},
|
{"quit", CmdQuit, 1, "Exit program"},
|
||||||
{"exit", CmdQuit, 1, "Exit program"},
|
{"exit", CmdQuit, 1, "Exit program"},
|
||||||
|
|
|
@ -372,7 +372,6 @@ 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));
|
||||||
|
|
||||||
PrintAndLog("ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
PrintAndLog("ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +509,6 @@ uint16_t printScTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace)
|
||||||
}
|
}
|
||||||
|
|
||||||
parity_len = (data_len-1)/8 + 1;
|
parity_len = (data_len-1)/8 + 1;
|
||||||
PrintAndLog("TODO REMOVE ME: parlen=%u",parity_len);
|
|
||||||
if (tracepos + data_len + parity_len > traceLen) {
|
if (tracepos + data_len + parity_len > traceLen) {
|
||||||
return traceLen;
|
return traceLen;
|
||||||
}
|
}
|
||||||
|
@ -562,49 +560,26 @@ uint16_t printScTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace)
|
||||||
int ScTraceList(const char *Cmd) {
|
int ScTraceList(const char *Cmd) {
|
||||||
bool loadFromFile = false;
|
bool loadFromFile = false;
|
||||||
bool saveToFile = false;
|
bool saveToFile = false;
|
||||||
char param1 = '\0';
|
char type[5] = {0};
|
||||||
char param2 = '\0';
|
|
||||||
char type[40] = {0};
|
|
||||||
char filename[FILE_PATH_SIZE] = {0};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
|
|
||||||
// parse command line
|
// parse command line
|
||||||
int tlen = param_getstr(Cmd, 0, type, sizeof(type));
|
param_getstr(Cmd, 0, type, sizeof(type));
|
||||||
if (param_getlength(Cmd, 1) == 1) {
|
param_getstr(Cmd, 1, filename, sizeof(filename));
|
||||||
param1 = param_getchar(Cmd, 1);
|
|
||||||
} else {
|
|
||||||
param_getstr(Cmd, 1, filename, sizeof(filename));
|
|
||||||
}
|
|
||||||
if (param_getlength(Cmd, 2) == 1) {
|
|
||||||
param2 = param_getchar(Cmd, 2);
|
|
||||||
} else if (strlen(filename) == 0) {
|
|
||||||
param_getstr(Cmd, 2, filename, sizeof(filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate param1
|
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
if(type[0] == 'h') {
|
||||||
if(tlen == 0) {
|
|
||||||
errors = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(param1 == 'h'
|
|
||||||
|| (param1 != 0 && param1 != 'l')
|
|
||||||
|| (param2 != 0 && param2 != 'l')) {
|
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!errors) {
|
if(!errors) {
|
||||||
if (strcmp(type, "save") == 0) {
|
if (strcmp(type, "s") == 0) {
|
||||||
saveToFile = true;
|
saveToFile = true;
|
||||||
} else {
|
} else if (strcmp(type,"l") == 0) {
|
||||||
errors = true;
|
loadFromFile = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param1 == 'l' || param2 == 'l') {
|
|
||||||
loadFromFile = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((loadFromFile || saveToFile) && strlen(filename) == 0) {
|
if ((loadFromFile || saveToFile) && strlen(filename) == 0) {
|
||||||
errors = true;
|
errors = true;
|
||||||
}
|
}
|
||||||
|
@ -616,9 +591,9 @@ int ScTraceList(const char *Cmd) {
|
||||||
if (errors) {
|
if (errors) {
|
||||||
PrintAndLog("List or save protocol data.");
|
PrintAndLog("List or save protocol data.");
|
||||||
PrintAndLog("Usage: sc list [l <filename>]");
|
PrintAndLog("Usage: sc list [l <filename>]");
|
||||||
PrintAndLog(" sc list save <filename>");
|
PrintAndLog(" sc list [s <filename>]");
|
||||||
PrintAndLog(" l - load data from file instead of trace buffer");
|
PrintAndLog(" l - load data from file instead of trace buffer");
|
||||||
PrintAndLog(" save - save data to file");
|
PrintAndLog(" s - save data to file");
|
||||||
PrintAndLog("");
|
PrintAndLog("");
|
||||||
PrintAndLog("example: sc list");
|
PrintAndLog("example: sc list");
|
||||||
PrintAndLog("example: sc list save myCardTrace.trc");
|
PrintAndLog("example: sc list save myCardTrace.trc");
|
||||||
|
@ -626,7 +601,6 @@ int ScTraceList(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t *trace;
|
uint8_t *trace;
|
||||||
uint32_t tracepos = 0;
|
uint32_t tracepos = 0;
|
||||||
uint32_t traceLen = 0;
|
uint32_t traceLen = 0;
|
||||||
|
@ -692,8 +666,8 @@ int ScTraceList(const char *Cmd) {
|
||||||
PrintAndLog("");
|
PrintAndLog("");
|
||||||
PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");
|
PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");
|
||||||
PrintAndLog("");
|
PrintAndLog("");
|
||||||
PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |");
|
PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |");
|
||||||
PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
|
PrintAndLog("------------|------------|-----|-------------------------------------------------------------------------|-----|--------------------|");
|
||||||
|
|
||||||
while(tracepos < traceLen)
|
while(tracepos < traceLen)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@ APP_CFLAGS += -DWITH_ISO14443a_StandAlone \
|
||||||
-DWITH_GUI
|
-DWITH_GUI
|
||||||
#END
|
#END
|
||||||
|
|
||||||
|
|
||||||
### Standalone modes:
|
### Standalone modes:
|
||||||
#-DWITH_ISO14443a_StandAlone
|
#-DWITH_ISO14443a_StandAlone
|
||||||
#-DWITH_LF_StandAlone
|
#-DWITH_LF_StandAlone
|
||||||
|
@ -39,4 +40,4 @@ APP_CFLAGS += -DWITH_ISO14443a_StandAlone \
|
||||||
#-DWITH_GUI \ include QT GUI/Graph support in build
|
#-DWITH_GUI \ include QT GUI/Graph support in build
|
||||||
#-DWITH_LCD \ include LCD support in build (experimental?)
|
#-DWITH_LCD \ include LCD support in build (experimental?)
|
||||||
|
|
||||||
#marshmellow NOTE: tested GUI, and smartcard removal only...
|
#marshmellow NOTE: tested GUI, and SMARTCARD removal only...
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
//
|
//
|
||||||
// NOTES:
|
// NOTES:
|
||||||
// LF Demod functions are placed here to allow the flexability to use client or
|
// LF Demod functions are placed here to allow the flexability to use client or
|
||||||
// device side. Most BUT NOT ALL of these functions are currenlty safe for
|
// device side. Most BUT NOT ALL of these functions are currently safe for
|
||||||
// device side use currently. (DetectST for example...)
|
// device side use. (DetectST for example...)
|
||||||
//
|
//
|
||||||
// There are likely many improvements to the code that could be made, please
|
// There are likely many improvements to the code that could be made, please
|
||||||
// make suggestions...
|
// make suggestions...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue