chg: 'sc list' - hooked up list command (runs 'trace list 7816' )

chg: 'sc reader' - added 's' silent parameter
chg: 'sc info' - added 's' silent parameter
This commit is contained in:
Chris 2018-07-08 11:19:26 +02:00
parent ef318b56ec
commit f9ba0e59fa
2 changed files with 63 additions and 33 deletions

View file

@ -191,12 +191,11 @@ int CmdHF14AList(const char *Cmd) {
}
int CmdHF14AReader(const char *Cmd) {
bool silent = false;
uint32_t cm = ISO14A_CONNECT;
bool disconnectAfter = true;
bool disconnectAfter = true, silent = false;
int cmdp = 0;
while (param_getchar(Cmd, cmdp) != 0x00) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h':
@ -217,7 +216,6 @@ int CmdHF14AReader(const char *Cmd) {
PrintAndLogEx(WARNING, "Unknown command.");
return 1;
}
cmdp++;
}
@ -225,7 +223,6 @@ int CmdHF14AReader(const char *Cmd) {
cm |= ISO14A_NO_DISCONNECT;
UsbCommand c = {CMD_READER_ISO_14443a, {cm, 0, 0}};
clearCommandBuffer();
SendCommand(&c);

View file

@ -211,38 +211,68 @@ int CmdSmartUpgrade(const char *Cmd) {
}
int CmdSmartInfo(const char *Cmd){
uint8_t cmdp = 0;
bool errors = false;
bool errors = false, silent = false;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h': return usage_sm_info();
case 's':
silent = true;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
cmdp++;
}
//Validations
if (errors || cmdp == 0 ) return usage_sm_info();
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
UsbCommand resp;
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2500) ) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return 1;
}
uint8_t isok = resp.arg[0] & 0xFF;
if (!isok) {
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return 1;
}
smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
// print header
PrintAndLogEx(INFO, "\n--- Smartcard Information ---------");
PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, sizeof(card.atr_len)));
PrintAndLogEx(INFO, "\n todo - look up ATR ");
return 0;
}
int CmdSmartReader(const char *Cmd){
uint8_t cmdp = 0;
bool errors = false;
bool errors = false, silent = false;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h': return usage_sm_reader();
case 's':
silent = true;
break;
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
cmdp++;
}
//Validations
@ -253,27 +283,30 @@ int CmdSmartReader(const char *Cmd){
SendCommand(&c);
UsbCommand resp;
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2500) ) {
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return 1;
}
uint8_t isok = resp.arg[0] & 0xFF;
if (!isok) {
PrintAndLogEx(FAILED, "failed to get ATR");
if (!silent) PrintAndLogEx(WARNING, "smart card select failed");
return 1;
}
smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
smart_card_atr_t *card = (smart_card_atr_t *)resp.d.asBytes;
PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card.atr, sizeof(card.atr_len)));
return 0;
}
// print header
PrintAndLogEx(INFO, "\n--- Smartcard Information ---------");
PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(INFO, "ATR : %s", sprint_hex(card->atr, sizeof(card->atr_len)));
int CmdSmartList(const char *Cmd) {
CmdTraceList("7816");
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
{"list", CmdSmartList, 0, "List ISO 7816 history"},
{"info", CmdSmartInfo, 1, "Tag information [rdv40]"},
{"reader", CmdSmartReader, 1, "Act like an IS07816 reader [rdv40]"},
{"raw", CmdSmartRaw, 1, "Send raw hex data to tag [rdv40]"},