+int Hf14443_4aGetCardData(iso14a_card_select_t * card) {
+ UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
+ SendCommand(&c);
+
+ UsbCommand resp;
+ WaitForResponse(CMD_ACK,&resp);
+
+ memcpy(card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
+
+ uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
+
+ if(select_status == 0) {
+ PrintAndLog("E->iso14443a card select failed");
+ return 1;
+ }
+
+ if(select_status == 2) {
+ PrintAndLog("E->Card doesn't support iso14443-4 mode");
+ return 1;
+ }
+
+ if(select_status == 3) {
+ PrintAndLog("E->Card doesn't support standard iso14443-3 anticollision");
+ PrintAndLog("\tATQA : %02x %02x", card->atqa[1], card->atqa[0]);
+ return 1;
+ }
+
+ PrintAndLog(" UID: %s", sprint_hex(card->uid, card->uidlen));
+ PrintAndLog("ATQA: %02x %02x", card->atqa[1], card->atqa[0]);
+ PrintAndLog(" SAK: %02x [%" PRIu64 "]", card->sak, resp.arg[0]);
+ if(card->ats_len < 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
+ PrintAndLog("E-> Error ATS length(%d) : %s", card->ats_len, sprint_hex(card->ats, card->ats_len));
+ return 1;
+ }
+ PrintAndLog(" ATS: %s", sprint_hex(card->ats, card->ats_len));
+
+ return 0;
+}
+
+int CmdHF14AReader(const char *Cmd) {
+ uint32_t cm = ISO14A_CONNECT;
+ bool leaveSignalON = false;
+
+ CLIParserInit("hf 14a reader", "Executes ISO1443A anticollision-select group of commands.", NULL);
+ void* argtable[] = {
+ arg_param_begin,
+ arg_lit0("kK", "keep", "keep the field active after command executed"),
+ arg_lit0("xX", "drop", "just drop the signal field"),
+ arg_lit0("3", NULL, "ISO14443-3 select only (skip RATS)"),
+ arg_param_end
+ };
+ if (CLIParserParseString(Cmd, argtable, arg_getsize(argtable), true)){
+ CLIParserFree();
+ return 0;
+ }
+
+ leaveSignalON = arg_get_lit(1);
+ if (arg_get_lit(2)) {
+ cm = cm - ISO14A_CONNECT;
+ }
+ if (arg_get_lit(3)) {
+ cm |= ISO14A_NO_RATS;
+ }
+
+ CLIParserFree();
+
+ if (leaveSignalON)
+ cm |= ISO14A_NO_DISCONNECT;
+
+ UsbCommand c = {CMD_READER_ISO_14443a, {cm, 0, 0}};
+ SendCommand(&c);
+
+ if (ISO14A_CONNECT & cm) {
+ UsbCommand resp;
+ WaitForResponse(CMD_ACK,&resp);
+
+ iso14a_card_select_t card;
+ memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
+
+ uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
+
+ if(select_status == 0) {
+ PrintAndLog("iso14443a card select failed");
+ return 1;
+ }
+
+ if(select_status == 3) {
+ PrintAndLog("Card doesn't support standard iso14443-3 anticollision");
+ PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
+ return 1;
+ }
+
+ PrintAndLog(" UID : %s", sprint_hex(card.uid, card.uidlen));
+ PrintAndLog("ATQA : %02x %02x", card.atqa[1], card.atqa[0]);
+ PrintAndLog(" SAK : %02x [%" PRIu64 "]", card.sak, resp.arg[0]);
+ 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));
+ }
+ if (leaveSignalON) {
+ PrintAndLog("Card is selected. You can now start sending commands");
+ }
+ }
+
+ if (!leaveSignalON) {
+ PrintAndLog("Field dropped.");
+ }
+
+ return 0;
+}
+
+int CmdHF14AInfo(const char *Cmd)