as in #447. hf 14a reader may start and end acting as reader

This commit is contained in:
merlokk 2017-10-31 18:56:48 +02:00
commit 2662dbaa42

View file

@ -134,9 +134,46 @@ int CmdHF14AList(const char *Cmd)
} }
int CmdHF14AReader(const char *Cmd) { int CmdHF14AReader(const char *Cmd) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}}; uint32_t cm = ISO14A_CONNECT;
bool disconnectAfter = false;
int cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
PrintAndLog("Usage: hf 14a reader [d] [3]");
PrintAndLog(" d drop the signal field after command executed");
PrintAndLog(" x just drop the signal field");
PrintAndLog(" 3 ISO14443-3 select only (skip RATS)");
return 0;
case '3':
cm |= ISO14A_NO_RATS;
break;
case 'd':
case 'D':
disconnectAfter = true;
break;
case 'x':
case 'X':
disconnectAfter = true;
cm = cm - ISO14A_CONNECT;
break;
default:
PrintAndLog("Unknown command.");
return 1;
}
cmdp++;
}
if (!disconnectAfter)
cm |= ISO14A_NO_DISCONNECT;
UsbCommand c = {CMD_READER_ISO_14443a, {cm, 0, 0}};
SendCommand(&c); SendCommand(&c);
if (ISO14A_CONNECT & cm) {
UsbCommand resp; UsbCommand resp;
WaitForResponse(CMD_ACK,&resp); WaitForResponse(CMD_ACK,&resp);
@ -162,7 +199,10 @@ int CmdHF14AReader(const char *Cmd) {
if(card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes if(card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
PrintAndLog(" ATS : %s", sprint_hex(card.ats, card.ats_len)); PrintAndLog(" ATS : %s", sprint_hex(card.ats, card.ats_len));
} }
PrintAndLog("For more info execute command `hf 14a info`"); PrintAndLog("Card is selected. You can now start sending commands");
} else {
PrintAndLog("Field dropped.");
}
return 0; return 0;
} }
@ -788,7 +828,7 @@ static command_t CommandTable[] =
{ {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"list", CmdHF14AList, 0, "[Deprecated] List ISO 14443a history"}, {"list", CmdHF14AList, 0, "[Deprecated] List ISO 14443a history"},
{"reader", CmdHF14AReader, 0, "Act like an ISO14443 Type A reader"}, {"reader", CmdHF14AReader, 0, "Start acting like an ISO14443 Type A reader"},
{"info", CmdHF14AInfo, 0, "Reads card and shows information about it"}, {"info", CmdHF14AInfo, 0, "Reads card and shows information about it"},
{"cuids", CmdHF14ACUIDs, 0, "<n> Collect n>0 ISO14443 Type A UIDs in one go"}, {"cuids", CmdHF14ACUIDs, 0, "<n> Collect n>0 ISO14443 Type A UIDs in one go"},
{"sim", CmdHF14ASim, 0, "<UID> -- Simulate ISO 14443a tag"}, {"sim", CmdHF14ASim, 0, "<UID> -- Simulate ISO 14443a tag"},