From 9fae7350e5ea224662368f132e22a0784bd8e021 Mon Sep 17 00:00:00 2001 From: merlokk Date: Tue, 2 Oct 2018 19:57:40 +0300 Subject: [PATCH] small refactoring --- client/cmdhf14a.c | 39 +++++++++++++++++++++++++++++++++++++++ client/cmdhf14a.h | 2 ++ client/emv/cmdemv.c | 32 +------------------------------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 94eb8ff3..06a17c2f 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -136,6 +136,45 @@ int CmdHF14AList(const char *Cmd) return 0; } +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; diff --git a/client/cmdhf14a.h b/client/cmdhf14a.h index 71007f95..20ff04ee 100644 --- a/client/cmdhf14a.h +++ b/client/cmdhf14a.h @@ -14,6 +14,7 @@ #include #include +#include "mifare.h" int CmdHF14A(const char *Cmd); int CmdHF14AList(const char *Cmd); @@ -25,6 +26,7 @@ int CmdHF14ASnoop(const char *Cmd); char* getTagInfo(uint8_t uid); extern void DropField(); +extern int Hf14443_4aGetCardData(iso14a_card_select_t * card); extern int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen); #endif diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 5b7d7471..5207b8db 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -1171,40 +1171,10 @@ int CmdHFEMVScan(const char *cmd) { PrintAndLog("--> GET UID, ATS."); - UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}}; - SendCommand(&c); - - 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("E->iso14443a card select failed"); + if (Hf14443_4aGetCardData(&card)) { 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)); - } - PrintAndLog(" ATS: %s", sprint_hex(card.ats, card.ats_len)); // init applets list tree const char *al = "Applets list";