diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index c19d06091..b662efdae 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -294,6 +294,37 @@ int hf14a_getversion_data(iso14a_card_select_t *card, uint64_t select_status, ve return res; } +// Build and send a single CMD_HF_ISO14443A_READER frame. +// `datalen` is how many bytes travel in the frame +// `len` / `lenbits` are what the device is told to transmit +// They are the same for almost every caller, see SendIso14aReader() below. +void SendIso14aReaderEx(uint32_t flags, const uint8_t *data, uint16_t datalen, uint16_t len, + uint16_t lenbits, uint32_t timeout, uint32_t wait_us) { + + if (datalen > (PM3_CMD_DATA_SIZE - sizeof(iso14a_raw_cmd_t))) { + PrintAndLogEx(WARNING, "Sending " _RED_("%u") " bytes of payload is too much, abort", datalen); + return; + } + + uint8_t buf[PM3_CMD_DATA_SIZE] = {0}; + iso14a_raw_cmd_t *payload = (iso14a_raw_cmd_t *)buf; + payload->flags = flags; + payload->timeout = timeout; + payload->wait_us = wait_us; + payload->len = len; + payload->lenbits = lenbits; + + if (datalen && data) { + memcpy(payload->data, data, datalen); + } + + SendCommandNG(CMD_HF_ISO14443A_READER, buf, ISO14A_RAW_LEN(datalen)); +} + +void SendIso14aReader(uint32_t flags, const uint8_t *data, uint16_t len) { + SendIso14aReaderEx(flags, data, len, len, 0, 0, 0); +} + static int CmdHF14AList(const char *Cmd) { return CmdTraceListAlias(Cmd, "hf 14a", "14a -c"); } @@ -618,7 +649,7 @@ static const char *get_uid_type(iso14a_card_select_t *card) { int Hf14443_4aGetCardData(iso14a_card_select_t *card) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); @@ -725,7 +756,7 @@ static int CmdHF14AReader(const char *Cmd) { int res = PM3_SUCCESS; do { clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, cm, 0, 0, NULL, 0); + SendIso14aReader(cm, NULL, 0); if ((cm & ISO14A_CONNECT) == ISO14A_CONNECT) { PacketResponseNG resp; @@ -880,7 +911,7 @@ static int CmdHF14ACUIDs(const char *Cmd) { } // execute anticollision procedure - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { @@ -1170,7 +1201,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav int min = MIN((PM3_CMD_DATA_SIZE - 2), (datainlen & 0x1FF)); memcpy(&data[2], datain, min); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | cmdc, (datainlen & 0xFFFF) + 2, 0, data, min + 2); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | cmdc, data, min + 2); uint8_t *recv; PacketResponseNG resp; @@ -1208,7 +1239,8 @@ resend: // WARNING for users of this function: // This NO_DISCONNECT flag will NOT save you. If you run your commands with LeaveSignalOn set to false, they will still fail if a card asks for WTX. // Better keep the flag on and do a DropField(); at the end. - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_DISCONNECT | cmdc, 5, 0, recv, min); // 2b frame +1b "data" + 2b crc. Hardcode length to 5 and reply to response + // 2b frame + 1b "data" + 2b crc. Hardcode length to 5 and reply to response + SendIso14aReader(ISO14A_RAW | ISO14A_NO_DISCONNECT | cmdc, recv, 5); goto resend; } // OBS @@ -1255,9 +1287,11 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card // Anticollision + SELECT card PacketResponseNG resp; if (polling_parameters != NULL) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_USE_CUSTOM_POLLING, 0, 0, (uint8_t *)polling_parameters, sizeof(iso14a_polling_parameters_t)); + SendIso14aReaderEx(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_USE_CUSTOM_POLLING + , (uint8_t *)polling_parameters, sizeof(iso14a_polling_parameters_t) + , 0, 0, 0, 0); } else { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); } if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) { @@ -1286,7 +1320,7 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision // get ATS uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; @@ -1387,9 +1421,9 @@ static int CmdExchangeAPDU(bool chainingin, const uint8_t *datain, int datainlen // here length PM3_CMD_DATA_SIZE=512 // timeout must be authomatically set by "get ATS" if (datain) { - SendCommandMIX(CMD_HF_ISO14443A_READER, cmdc, (datainlen & 0x1FF), 0, datain, (datainlen & 0x1FF)); + SendIso14aReader(cmdc, datain, (datainlen & 0x1FF)); } else { - SendCommandMIX(CMD_HF_ISO14443A_READER, cmdc, 0, 0, NULL, 0); + SendIso14aReader(cmdc, NULL, 0); } PacketResponseNG resp; @@ -2736,7 +2770,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -2784,7 +2818,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { if (select_status == 2) { uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT; @@ -2953,7 +2987,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { // reconnect for further tests clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); DropField(); diff --git a/client/src/cmdhf14a.h b/client/src/cmdhf14a.h index 74e8a6685..162537a69 100644 --- a/client/src/cmdhf14a.h +++ b/client/src/cmdhf14a.h @@ -66,6 +66,10 @@ typedef enum { MTNTAG = 8192, } nxp_mifare_type_t; +void SendIso14aReaderEx(uint32_t flags, const uint8_t *data, uint16_t datalen, uint16_t len, + uint16_t lenbits, uint32_t timeout, uint32_t wait_us); +void SendIso14aReader(uint32_t flags, const uint8_t *data, uint16_t len); + int CmdHF14A(const char *Cmd); int CmdHF14ASniff(const char *Cmd); // used by hf topaz sniff int CmdHF14ASim(const char *Cmd); // used by hf mfu sim diff --git a/client/src/cmdhffudan.c b/client/src/cmdhffudan.c index 18cd0b258..a0f2ff98f 100644 --- a/client/src/cmdhffudan.c +++ b/client/src/cmdhffudan.c @@ -111,7 +111,7 @@ static int fudan_get_type(iso14a_card_select_t *card, bool verbose) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -310,7 +310,7 @@ static int CmdHFFudanDump(const char *Cmd) { clearCommandBuffer(); PacketResponseNG resp; - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, sizeof(cmd) | ((uint32_t)(numbits << 16)), argtimeout, cmd, sizeof(cmd)); + SendIso14aReaderEx(flags, cmd, sizeof(cmd), sizeof(cmd), numbits, argtimeout, 0); if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (resp.status == PM3_SUCCESS) { diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index dcc947cf3..2e7f1f6c4 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -32,6 +32,7 @@ #include "common.h" #include "commonutil.h" #include "cmdparser.h" +#include "cmdhf14a.h" #include "cliparser.h" #include "comms.h" #include "ui.h" @@ -1045,7 +1046,7 @@ static int hfgal_write_classic_card(GallagherCredentials_t *creds, uint8_t cred_ clearCommandBuffer(); // Select card to get UID - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(ERR, "Card select timeout"); @@ -1174,7 +1175,7 @@ static int hfgal_read_classic_card(uint8_t *site_key, bool verbose, bool quiet) GallagherCredentials_t creds = {0}; // Select card - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { if (!quiet) { diff --git a/client/src/cmdhfict.c b/client/src/cmdhfict.c index 7c749d5d2..8d9610ba4 100644 --- a/client/src/cmdhfict.c +++ b/client/src/cmdhfict.c @@ -403,7 +403,7 @@ static int ict_select_card(iso14a_card_select_t *card) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { return PM3_ESOFT; diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index fc4e925bf..c0cf07502 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -103,32 +103,25 @@ static int CmdHelp(const char *Cmd); static void lto_switch_off_field(void) { SetISODEPState(ISODEP_INACTIVE); - SendCommandMIX(CMD_HF_ISO14443A_READER, 0, 0, 0, NULL, 0); + SendIso14aReader(0, NULL, 0); } static void lto_switch_on_field(void) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, NULL, 0); } // send a raw LTO-CM command, returns the length of the response (0 in case of error) static int lto_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response, uint16_t *response_len, bool addcrc, bool is7bits, bool verbose) { - uint64_t arg0 = ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS; - uint32_t arg1; + uint32_t flags = ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS; if (addcrc) { - arg0 |= ISO14A_APPEND_CRC; + flags |= ISO14A_APPEND_CRC; } - if (is7bits) { - arg1 = 7 << 16; - } else { - arg1 = 0; - } + uint16_t lenbits = (is7bits) ? 7 : 0; - arg1 |= len; - - SendCommandMIX(CMD_HF_ISO14443A_READER, arg0, arg1, 0, cmd, len); + SendIso14aReaderEx(flags, cmd, len, len, lenbits, 0, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 2ebc9a608..60bce788f 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -376,7 +376,7 @@ int mfc_ev1_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, in int mf_read_uid(uint8_t *uid, int *uidlen, int *nxptype) { clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select failed"); @@ -393,7 +393,7 @@ int mf_read_uid(uint8_t *uid, int *uidlen, int *nxptype) { if (select_status == 2) { uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT; @@ -914,7 +914,7 @@ static int mfc_read_tag(iso14a_card_select_t *card, uint8_t *carddata, uint8_t n // Select card to get UID/UIDLEN/ATQA/SAK information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -3088,7 +3088,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Select card to get UID/UIDLEN/ATQA/SAK information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -3112,7 +3112,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (select_status == 2) { uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT; @@ -6352,7 +6352,7 @@ static int CmdHF14AMfCSave(const char *Cmd) { // Select card to get UID/UIDLEN information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -6502,7 +6502,7 @@ static int CmdHF14AMfCView(const char *Cmd) { // Select card to get UID/UIDLEN information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -7399,7 +7399,7 @@ int CmdHFMFNDEFFormat(const char *Cmd) { // Select card to get UID/UIDLEN/ATQA/SAK information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -8138,7 +8138,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) { uint8_t data[] = {0xAA, 0xA8, 0x00, i}; uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, sizeof(data), 0, data, sizeof(data)); + SendIso14aReader(flags, data, sizeof(data)); if (WaitForResponseTimeout(CMD_ACK, NULL, 1500) == false) { break; } @@ -8169,7 +8169,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) { uint8_t data[] = {0x30, i}; uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, sizeof(data), 0, data, sizeof(data)); + SendIso14aReader(flags, data, sizeof(data)); if (WaitForResponseTimeout(CMD_ACK, NULL, 1500) == false) { break; } @@ -9395,7 +9395,7 @@ static int CmdHF14AGen4Save(const char *Cmd) { // Select card to get UID/UIDLEN information clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -11227,7 +11227,7 @@ static int CmdHF14AMfInfo(const char *Cmd) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -11250,7 +11250,7 @@ static int CmdHF14AMfInfo(const char *Cmd) { if (select_status == 2) { uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT; @@ -11795,7 +11795,7 @@ static int CmdHF14AMfISEN(const char *Cmd) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 64fa8e85c..e38f58ae7 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -1808,7 +1808,7 @@ static int CmdHF14aDesChk(const char *Cmd) { if ((jsonnamelen > 0) && result) { DropField(); // MIFARE DESFire info - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index b6775b191..d9efca13f 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -126,7 +126,7 @@ static int mfp_read_card_id(iso14a_card_select_t *card, int *nxptype) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select failed"); @@ -288,7 +288,7 @@ static int CmdHFMFPInfo(const char *Cmd) { PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); // Mifare Plus info - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); diff --git a/client/src/cmdhfmfsen.c b/client/src/cmdhfmfsen.c index fdba947c4..41f65e574 100644 --- a/client/src/cmdhfmfsen.c +++ b/client/src/cmdhfmfsen.c @@ -656,7 +656,7 @@ static int fm11_collect_nonces_ex(const uint8_t *key, uint32_t flags, uint8_t fi } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "iso14443a card select timeout"); @@ -2757,7 +2757,7 @@ static int fm11_select_mifare_classic(iso14a_card_select_t *card_out) { } clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -2778,7 +2778,7 @@ static int fm11_select_mifare_classic(iso14a_card_select_t *card_out) { if (select_status == 2) { uint8_t rats[] = { 0xE0, 0x80 }; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); DropField(); diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 681e50739..a8e403318 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -338,7 +338,7 @@ int ul_read_uid(uint8_t *uid) { } // read uid from tag clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); @@ -367,7 +367,7 @@ int ul_read_uid(uint8_t *uid) { static void ul_switch_on_field(void) { clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, NULL, 0); } static int ul_send_cmd_raw(const uint8_t *cmd, uint8_t cmdlen, uint8_t *response, uint16_t responseLength, bool schann) { @@ -377,7 +377,7 @@ static int ul_send_cmd_raw(const uint8_t *cmd, uint8_t cmdlen, uint8_t *response if (schann) { param |= ISO14A_APPEND_CMAC; } - SendCommandMIX(CMD_HF_ISO14443A_READER, param, cmdlen, 0, cmd, cmdlen); + SendIso14aReader(param, cmd, cmdlen); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { return PM3_ETIMEOUT; @@ -442,7 +442,7 @@ static bool ul_select_rats(iso14a_card_select_t *card) { if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision // get ATS uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats)); if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(WARNING, "command execution time out"); return false; @@ -496,7 +496,7 @@ static int ulc_requestAuthentication(uint8_t *nonce, uint16_t nonceLength) { } int mfuc_test_authentication_support(void) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); @@ -802,7 +802,7 @@ static long long unsigned int ul_fudan_check(void) { uint8_t cmd[4] = {ISO14443A_CMD_READBLOCK, 0x00, 0x02, 0xa7}; // wrong crc on purpose, should be 0xa8 clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 4, 0, cmd, sizeof(cmd)); + SendIso14aReader(ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, cmd, sizeof(cmd)); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { return MFU_TT_UL_ERROR; @@ -2009,7 +2009,7 @@ static int mfulc_fingerprint(void) { return PM3_ESOFT; } uint8_t cmd0[] = {0xAF}; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS, sizeof(cmd0), 0, cmd0, sizeof(cmd0)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS, cmd0, sizeof(cmd0)); if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if ((resp.oldarg[0] == 11) && (resp.data.asBytes[0] == 0x00)) { PrintAndLogEx(SUCCESS, _GREEN_("Lab401 Ultralight-C compatible UID modifiable")); @@ -2026,7 +2026,7 @@ static int mfulc_fingerprint(void) { return PM3_ESOFT; } uint8_t cmd1[] = {0x1A, 0x2F}; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS, sizeof(cmd1), 0, cmd1, sizeof(cmd1)); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS, cmd1, sizeof(cmd1)); if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if ((resp.oldarg[0] == 11) && (resp.data.asBytes[0] == 0xAF)) { PrintAndLogEx(SUCCESS, _GREEN_("Feiju FJ8010")); @@ -2043,7 +2043,7 @@ static int mfulc_fingerprint(void) { return PM3_ESOFT; } uint8_t cmd2[] = {0x1A}; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_RATS, sizeof(cmd2), 0, cmd2, sizeof(cmd2)); + SendIso14aReader(ISO14A_RAW | ISO14A_NO_RATS, cmd2, sizeof(cmd2)); if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if ((resp.oldarg[0] == 11) && (resp.data.asBytes[0] == 0xAF)) { uint8_t response[11] = {0}; @@ -2067,10 +2067,12 @@ static int mfulc_fingerprint(void) { // GT23SC4489 uint8_t cmd3a[] = {0x26}; uint8_t cmd3b[] = {0x30}; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT, 7 << 16, 0, cmd3a, sizeof(cmd3a)); + // 7 bit REQA, so lenbits carries it and len stays 0 + SendIso14aReaderEx(ISO14A_RAW | ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT + , cmd3a, sizeof(cmd3a), 0, 7, 0, 0); if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if (resp.oldarg[0] == 2) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_SELECT, sizeof(cmd3b), 0, cmd3b, sizeof(cmd3b)); + SendIso14aReader(ISO14A_RAW | ISO14A_NO_SELECT, cmd3b, sizeof(cmd3b)); if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if (resp.oldarg[0] == 18) { if ((resp.data.asBytes[0] == 0x04) && (resp.data.asBytes[6] == 0x15) && (resp.data.asBytes[7] == 0x89)) { @@ -6117,7 +6119,7 @@ static int CmdHF14AMfUKeyGen(const char *Cmd) { if (read_tag) { // read uid from tag clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); diff --git a/client/src/cmdhfsaflok.c b/client/src/cmdhfsaflok.c index 61219d771..4f622920d 100644 --- a/client/src/cmdhfsaflok.c +++ b/client/src/cmdhfsaflok.c @@ -24,6 +24,7 @@ #include #include "cliparser.h" #include "cmdparser.h" +#include "cmdhf14a.h" #include "comms.h" #include "ui.h" #include "util.h" @@ -1241,7 +1242,7 @@ static void saflok_encode( // perhaps by creating a struct to avoid having to pass a length parameter. static int saflok_read_sector(int sector, uint8_t *secdata) { clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select failed"); diff --git a/client/src/cmdhfst25ta.c b/client/src/cmdhfst25ta.c index 76c32d154..3ee01316e 100644 --- a/client/src/cmdhfst25ta.c +++ b/client/src/cmdhfst25ta.c @@ -42,7 +42,7 @@ static int CmdHelp(const char *Cmd); static bool st25ta_select(iso14a_card_select_t *card) { clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { PrintAndLogEx(DEBUG, "iso14443a card select timeout"); diff --git a/client/src/cmdhftopaz.c b/client/src/cmdhftopaz.c index f6d4ea76b..d50775a4d 100644 --- a/client/src/cmdhftopaz.c +++ b/client/src/cmdhftopaz.c @@ -41,17 +41,17 @@ static topaz_tag_t topaz_tag; static void topaz_switch_on_field(void) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, NULL, 0); } static void topaz_switch_off_field(void) { SetISODEPState(ISODEP_INACTIVE); - SendCommandMIX(CMD_HF_ISO14443A_READER, 0, 0, 0, NULL, 0); + SendIso14aReader(0, NULL, 0); } // send a raw topaz command, returns the length of the response (0 in case of error) static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response, uint16_t *response_len, bool verbose) { - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, len, 0, cmd, len); + SendIso14aReader(ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, cmd, len); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { if (verbose) PrintAndLogEx(WARNING, "timeout while waiting for reply"); diff --git a/client/src/cmdhfwaveshare.c b/client/src/cmdhfwaveshare.c index a22202ada..57ae53de0 100644 --- a/client/src/cmdhfwaveshare.c +++ b/client/src/cmdhfwaveshare.c @@ -23,6 +23,7 @@ #include #include "comms.h" #include "cmdparser.h" +#include "cmdhf14a.h" #include "ui.h" #include "util.h" #include "fileutils.h" @@ -135,7 +136,7 @@ static int transceive_blocking(uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf while (1) { PacketResponseNG resp; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, txBufLen, 0, txBuf, txBufLen); + SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, txBuf, txBufLen); rxBuf[0] = 1; if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { if (resp.oldarg[0] > rxBufLen) { @@ -249,7 +250,7 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) { uint16_t actrxlen[20]; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(ERR, "No tag found"); diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index c348fd3a9..aac662f14 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -3313,7 +3313,7 @@ int DesfireISOAppendRecord(DesfireContext_t *dctx, uint8_t fileid, uint8_t *data int DesfireGetCardUID(DesfireContext_t *ctx) { iso14a_card_select_t card = {0}; - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE, 0, 0, NULL, 0); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); diff --git a/client/src/mifare/gen4.c b/client/src/mifare/gen4.c index 9a9fa3e17..ed4b8fbc0 100644 --- a/client/src/mifare/gen4.c +++ b/client/src/mifare/gen4.c @@ -60,7 +60,7 @@ static int mfG4ExCommand(uint8_t cmd, uint8_t *pwd, uint8_t *data, size_t datale int resplen = 0; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_NO_RATS | ISO14A_APPEND_CRC, 6 + datalen, 0, (uint8_t *)&payload, 6 + datalen); + SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_NO_RATS | ISO14A_APPEND_CRC, (uint8_t *)&payload, 6 + datalen); PacketResponseNG resp; if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index 6d6d174fd..f0ffa8a90 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -1404,7 +1404,7 @@ int detect_classic_prng(void) { uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, sizeof(cmd), 0, cmd, sizeof(cmd)); + SendIso14aReader(flags, cmd, sizeof(cmd)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT; @@ -1444,7 +1444,7 @@ int detect_classic_auth(uint8_t key_type) { uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS; clearCommandBuffer(); - SendCommandMIX(CMD_HF_ISO14443A_READER, flags, sizeof(cmd), 0, cmd, sizeof(cmd)); + SendIso14aReader(flags, cmd, sizeof(cmd)); if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); return PM3_ETIMEOUT;