OLD/MIX convert to NG: Phase C
This commit is contained in:
1 parent
bbc8cc25b2
commit
1a3f64960a
20 files changed
+300
-179
No files matched your search
+33
-26
@@ -3787,15 +3787,16 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u
|
||||
return len;
|
||||
}
|
||||
|
||||
static void reply_iso14a_raw(iso14a_raw_resp_t *response, uint8_t *respbuf, uint16_t len) {
|
||||
response->len = len;
|
||||
response->sel = 0;
|
||||
reply_ng(CMD_HF_ISO14443A_READER, PM3_SUCCESS, respbuf, ISO14A_RESP_LEN(len));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read an ISO 14443a tag. Send out commands and store answers.
|
||||
//-----------------------------------------------------------------------------
|
||||
// NG callers send one iso14a_raw_cmd_t. OLD/MIX callers still pack:
|
||||
// arg0 iso_14a flags
|
||||
// arg1 high :: number of bits, if you want to send 7bits etc
|
||||
// low :: len of commandbytes
|
||||
// arg2 high :: wait_us, low :: timeout
|
||||
// d.asBytes command bytes to send
|
||||
// Callers send one iso14a_raw_cmd_t and get back one iso14a_raw_resp_t.
|
||||
void ReaderIso14443a(PacketCommandNG *c) {
|
||||
|
||||
iso14a_command_t param;
|
||||
@@ -3825,18 +3826,17 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
cmd = payload->data;
|
||||
|
||||
} else {
|
||||
// OLD/MIX callers, still the majority. See doc/new_frame_format.md
|
||||
param = c->oldarg[0];
|
||||
len = c->oldarg[1] & 0xffff;
|
||||
lenbits = c->oldarg[1] >> 16;
|
||||
timeout = c->oldarg[2] & 0xffffffff;
|
||||
wait_us = c->oldarg[2] >> 32;
|
||||
cmd = c->data.asBytes;
|
||||
// every caller is NG now, OLD/MIX frames are no longer accepted
|
||||
reply_ng(CMD_HF_ISO14443A_READER, PM3_EINVARG, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t arg0;
|
||||
|
||||
uint8_t buf[PM3_CMD_DATA_SIZE_MIX] = {0x00};
|
||||
// the reply frame is built in place: `buf` is its data[] area
|
||||
uint8_t respbuf[PM3_CMD_DATA_SIZE] = {0x00};
|
||||
iso14a_raw_resp_t *response = (iso14a_raw_resp_t *)respbuf;
|
||||
uint8_t *buf = response->data;
|
||||
|
||||
if ((param & ISO14A_CONNECT) == ISO14A_CONNECT) {
|
||||
iso14_pcb_blocknum = 0;
|
||||
@@ -3878,7 +3878,9 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
crypto1_deinit(&crypto1_state);
|
||||
}
|
||||
|
||||
reply_mix(CMD_ACK, arg0, card->uidlen, 0, buf, sizeof(iso14a_card_select_t));
|
||||
response->len = sizeof(iso14a_card_select_t);
|
||||
response->sel = arg0;
|
||||
reply_ng(CMD_HF_ISO14443A_READER, PM3_SUCCESS, respbuf, ISO14A_RESP_LEN(sizeof(iso14a_card_select_t)));
|
||||
if (arg0 == 0) {
|
||||
goto OUT;
|
||||
}
|
||||
@@ -3906,11 +3908,13 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
len,
|
||||
((param & ISO14A_SEND_CHAINING) == ISO14A_SEND_CHAINING),
|
||||
buf,
|
||||
sizeof(buf),
|
||||
ISO14A_RESP_MAXLEN,
|
||||
&res
|
||||
);
|
||||
|
||||
reply_mix(CMD_ACK, arg0, res, 0, buf, sizeof(buf));
|
||||
response->len = arg0;
|
||||
response->sel = res;
|
||||
reply_ng(CMD_HF_ISO14443A_READER, PM3_SUCCESS, respbuf, ISO14A_RESP_LEN(arg0));
|
||||
}
|
||||
|
||||
if ((param & ISO14A_RAW) == ISO14A_RAW) {
|
||||
@@ -3928,7 +3932,10 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
if (g_dbglevel >= DBG_INFO) Dbprintf("Auth succeeded");
|
||||
res = 0x0a;
|
||||
}
|
||||
reply_mix(CMD_ACK, 1, 0, 0, &res, 1);
|
||||
response->len = 1;
|
||||
response->sel = 0;
|
||||
response->data[0] = res;
|
||||
reply_ng(CMD_HF_ISO14443A_READER, PM3_SUCCESS, respbuf, ISO14A_RESP_LEN(1));
|
||||
goto CMD_DONE;
|
||||
}
|
||||
}
|
||||
@@ -4023,17 +4030,17 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
// tearoff occurred
|
||||
if (tearoff_hook() == PM3_ETEAROFF) {
|
||||
FpgaDisableTracing();
|
||||
reply_mix(CMD_ACK, 0, 0, 0, NULL, 0);
|
||||
reply_iso14a_raw(response, respbuf, 0);
|
||||
} else {
|
||||
arg0 = ReaderReceive(buf, sizeof(buf), parity_array);
|
||||
arg0 = ReaderReceive(buf, ISO14A_RESP_MAXLEN, parity_array);
|
||||
FpgaDisableTracing();
|
||||
reply_mix(CMD_ACK, arg0, 0, 0, buf, sizeof(buf));
|
||||
reply_iso14a_raw(response, respbuf, arg0);
|
||||
}
|
||||
|
||||
} else {
|
||||
arg0 = ReaderReceive(buf, sizeof(buf), parity_array);
|
||||
arg0 = ReaderReceive(buf, ISO14A_RESP_MAXLEN, parity_array);
|
||||
FpgaDisableTracing();
|
||||
reply_mix(CMD_ACK, arg0, 0, 0, buf, sizeof(buf));
|
||||
reply_iso14a_raw(response, respbuf, arg0);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -4041,9 +4048,9 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
// tearoff occurred
|
||||
if (tearoff_hook() == PM3_ETEAROFF) {
|
||||
FpgaDisableTracing();
|
||||
reply_mix(CMD_ACK, 0, 0, 0, NULL, 0);
|
||||
reply_iso14a_raw(response, respbuf, 0);
|
||||
} else {
|
||||
arg0 = ReaderReceive(buf, sizeof(buf), parity_array);
|
||||
arg0 = ReaderReceive(buf, ISO14A_RESP_MAXLEN, parity_array);
|
||||
|
||||
if ((param & ISO14A_CRYPTO1MODE) == ISO14A_CRYPTO1MODE) {
|
||||
mf_crypto1_decrypt(&crypto1_state, buf, arg0);
|
||||
@@ -4053,7 +4060,7 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
increase_session_counter();
|
||||
}
|
||||
FpgaDisableTracing();
|
||||
reply_mix(CMD_ACK, arg0, 0, 0, buf, sizeof(buf));
|
||||
reply_iso14a_raw(response, respbuf, arg0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
-33
@@ -321,6 +321,39 @@ void SendIso14aReaderEx(uint32_t flags, const uint8_t *data, uint16_t datalen, u
|
||||
SendCommandNG(CMD_HF_ISO14443A_READER, buf, ISO14A_RAW_LEN(datalen));
|
||||
}
|
||||
|
||||
// Receive the reply to a CMD_HF_ISO14443A_READER frame.
|
||||
// `len` gets the payload size, 0 meaning the card did not answer
|
||||
// `sel` gets the select status on a CONNECT, or the APDU res byte
|
||||
// Either may be NULL. On success resp->data.asBytes holds the payload itself,
|
||||
// so callers read it exactly as they did with the old CMD_ACK reply.
|
||||
bool WaitForIso14aReply(PacketResponseNG *resp, uint32_t timeout_ms, uint16_t *len, uint8_t *sel) {
|
||||
|
||||
PacketResponseNG local;
|
||||
PacketResponseNG *r = (resp) ? resp : &local;
|
||||
|
||||
if (WaitForResponseTimeout(CMD_HF_ISO14443A_READER, r, timeout_ms) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (r->status != PM3_SUCCESS || r->length < sizeof(iso14a_raw_resp_t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const iso14a_raw_resp_t *payload = (const iso14a_raw_resp_t *)r->data.asBytes;
|
||||
|
||||
if (len) {
|
||||
*len = payload->len;
|
||||
}
|
||||
if (sel) {
|
||||
*sel = payload->sel;
|
||||
}
|
||||
|
||||
// shift the payload down so data.asBytes[0] is the first response byte
|
||||
r->length -= sizeof(iso14a_raw_resp_t);
|
||||
memmove(r->data.asBytes, r->data.asBytes + sizeof(iso14a_raw_resp_t), r->length);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SendIso14aReader(uint32_t flags, const uint8_t *data, uint16_t len) {
|
||||
SendIso14aReaderEx(flags, data, len, len, 0, 0, 0);
|
||||
}
|
||||
@@ -651,14 +684,15 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) {
|
||||
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_687 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_687) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
uint64_t select_status = sel_687; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "iso14443a card select failed");
|
||||
@@ -683,7 +717,7 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) {
|
||||
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card->uid, card->uidlen));
|
||||
PrintAndLogEx(SUCCESS, "ATQA: %02X %02X", card->atqa[1], card->atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: %02X [%" PRIu64 "]", card->sak, resp.oldarg[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: %02X [%u]", card->sak, select_status);
|
||||
|
||||
// a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||
if (card->ats_len < 3) {
|
||||
@@ -760,7 +794,8 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||
|
||||
if ((cm & ISO14A_CONNECT) == ISO14A_CONNECT) {
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_797 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_797) == false) {
|
||||
DropField();
|
||||
res = PM3_ESOFT;
|
||||
goto plot;
|
||||
@@ -775,7 +810,7 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_797;
|
||||
|
||||
found = (select_status != 0);
|
||||
|
||||
@@ -806,7 +841,7 @@ static int CmdHF14AReader(const char *Cmd) {
|
||||
|
||||
if (!(silent && continuous)) {
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card.sak, sel_797);
|
||||
|
||||
if (card.ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||
if (card.ats_len == card.ats[0] + 2)
|
||||
@@ -914,7 +949,8 @@ static int CmdHF14ACUIDs(const char *Cmd) {
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_952 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_952) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -922,7 +958,7 @@ static int CmdHF14ACUIDs(const char *Cmd) {
|
||||
iso14a_card_select_t *card = (iso14a_card_select_t *) resp.data.asBytes;
|
||||
|
||||
// check if command failed
|
||||
if (resp.oldarg[0] == 0) {
|
||||
if (sel_952 == 0) {
|
||||
PrintAndLogEx(WARNING, "card select failed.");
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "%s", sprint_hex_inrow(card->uid, card->uidlen));
|
||||
@@ -1206,9 +1242,10 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
|
||||
uint8_t *recv;
|
||||
PacketResponseNG resp;
|
||||
resend:
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 7000)) {
|
||||
uint16_t rlen_1245 = 0;
|
||||
if (WaitForIso14aReply(&resp, 7000, &rlen_1245, NULL)) {
|
||||
recv = resp.data.asBytes;
|
||||
int iLen = resp.oldarg[0];
|
||||
int iLen = rlen_1245;
|
||||
|
||||
if (iLen == 0) {
|
||||
if (silentMode == false) {
|
||||
@@ -1294,21 +1331,22 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
}
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
uint8_t sel_1334 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2000, NULL, &sel_1334) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// check result
|
||||
if (resp.oldarg[0] == 0) {
|
||||
if (sel_1334 == 0) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(WARNING, "No ISO14443-A Card in field");
|
||||
}
|
||||
return PM3_ECARDEXCHANGE;
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) {
|
||||
PrintAndLogEx(WARNING, "Card not in iso14443-4, res=%" PRId64 ".", resp.oldarg[0]);
|
||||
if (sel_1334 != 1 && sel_1334 != 2) {
|
||||
PrintAndLogEx(WARNING, "Card not in iso14443-4, res=%d.", sel_1334);
|
||||
return PM3_ECARDEXCHANGE;
|
||||
}
|
||||
|
||||
@@ -1317,16 +1355,17 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card
|
||||
memcpy(card, vcard, sizeof(iso14a_card_select_t));
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
if (sel_1334 == 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
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t rlen_1362 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen_1362, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] == 0) { // ats_len
|
||||
if (rlen_1362 == 0) { // ats_len
|
||||
if (verbose) {
|
||||
PrintAndLogEx(FAILED, "Can't get ATS");
|
||||
}
|
||||
@@ -1334,7 +1373,7 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card
|
||||
}
|
||||
|
||||
// get frame length from ATS in data field
|
||||
if (resp.oldarg[0] > 1) {
|
||||
if (rlen_1362 > 1) {
|
||||
uint8_t fsci = resp.data.asBytes[1] & 0x0f;
|
||||
if (fsci < ARRAYLEN(atsFSC)) {
|
||||
gs_frame_len = atsFSC[fsci];
|
||||
@@ -1342,7 +1381,7 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card
|
||||
}
|
||||
|
||||
if (card) {
|
||||
card->ats_len = resp.oldarg[0];
|
||||
card->ats_len = rlen_1362;
|
||||
memcpy(card->ats, resp.data.asBytes, card->ats_len);
|
||||
}
|
||||
} else {
|
||||
@@ -1428,14 +1467,16 @@ static int CmdExchangeAPDU(bool chainingin, const uint8_t *datain, int datainlen
|
||||
|
||||
PacketResponseNG resp;
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, timeout) == false) {
|
||||
uint16_t rlen_1470 = 0;
|
||||
uint8_t apdu_res = 0;
|
||||
if (WaitForIso14aReply(&resp, timeout, &rlen_1470, &apdu_res) == false) {
|
||||
PrintAndLogEx(DEBUG, "ERR: APDU: Reply timeout");
|
||||
return PM3_EAPDU_FAIL;
|
||||
}
|
||||
|
||||
const uint8_t *recv = resp.data.asBytes;
|
||||
int iLen = resp.oldarg[0];
|
||||
uint8_t res = resp.oldarg[1];
|
||||
int iLen = rlen_1470;
|
||||
uint8_t res = apdu_res;
|
||||
|
||||
int dlen = iLen - 2;
|
||||
if (dlen < 0) {
|
||||
@@ -1857,11 +1898,12 @@ static int CmdHF14ACmdRaw(const char *Cmd) {
|
||||
|
||||
static int waitCmd(bool i_select, uint32_t timeout, bool verbose) {
|
||||
PacketResponseNG resp;
|
||||
uint16_t rlen = 0;
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, timeout + 1500)) {
|
||||
uint16_t len = (resp.oldarg[0] & 0xFFFF);
|
||||
if (WaitForIso14aReply(&resp, timeout + 1500, &rlen, NULL)) {
|
||||
uint16_t len = rlen;
|
||||
if (i_select) {
|
||||
len = (resp.oldarg[1] & 0xFFFF);
|
||||
len = ((const iso14a_card_select_t *)resp.data.asBytes)->uidlen;
|
||||
if (len) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "Card selected. UID[%u]:", len);
|
||||
@@ -2772,7 +2814,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_2815 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_2815) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -2788,7 +2831,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
3: proprietary Anticollision
|
||||
4: OK, SAK = no ATS but RATS possible (tested below)
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_2815;
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
@@ -2819,13 +2862,14 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint16_t rlen_2863 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, &rlen_2863, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]);
|
||||
card.ats_len = resp.oldarg[0]; // note: ats_len includes CRC Bytes
|
||||
memcpy(card.ats, resp.data.asBytes, rlen_2863);
|
||||
card.ats_len = rlen_2863; // note: ats_len includes CRC Bytes
|
||||
if (card.ats_len > 3) {
|
||||
select_status = 4;
|
||||
}
|
||||
@@ -2847,7 +2891,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
PrintAndLogEx(INFO, "---------- " _CYAN_("ISO14443-A Information") " ----------");
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s") " %s", sprint_hex(card.uid, card.uidlen), get_uid_type(&card));
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, select_status);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card.sak, select_status);
|
||||
if (version_hw_available) {
|
||||
PrintAndLogEx(DEBUG, "GetV: " _GREEN_("%s"), sprint_hex((uint8_t *)&version_hw, sizeof(version_hw)));
|
||||
}
|
||||
@@ -2988,7 +3032,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
// reconnect for further tests
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_3033 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_3033) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -2996,7 +3041,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS
|
||||
select_status = sel_3033; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS
|
||||
|
||||
if (select_status == 0) {
|
||||
DropField();
|
||||
|
||||
@@ -69,6 +69,7 @@ typedef enum {
|
||||
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);
|
||||
bool WaitForIso14aReply(PacketResponseNG *resp, uint32_t timeout_ms, uint16_t *len, uint8_t *sel);
|
||||
|
||||
int CmdHF14A(const char *Cmd);
|
||||
int CmdHF14ASniff(const char *Cmd); // used by hf topaz sniff
|
||||
|
||||
@@ -113,7 +113,8 @@ static int fudan_get_type(iso14a_card_select_t *card, bool verbose) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_116 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_116) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -126,7 +127,7 @@ static int fudan_get_type(iso14a_card_select_t *card, bool verbose) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_116;
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
@@ -146,7 +147,7 @@ static int fudan_get_type(iso14a_card_select_t *card, bool verbose) {
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card->uid, card->uidlen));
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card->atqa[1], card->atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card->sak, select_status);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card->sak, select_status);
|
||||
|
||||
if (card->ats_len >= 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes
|
||||
if (card->ats_len == card->ats[0] + 2)
|
||||
@@ -312,7 +313,7 @@ static int CmdHFFudanDump(const char *Cmd) {
|
||||
PacketResponseNG resp;
|
||||
SendIso14aReaderEx(flags, cmd, sizeof(cmd), sizeof(cmd), numbits, argtimeout, 0);
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, NULL)) {
|
||||
if (resp.status == PM3_SUCCESS) {
|
||||
uint8_t *data = resp.data.asBytes;
|
||||
memcpy(carddata + (b * MAX_FUDAN_BLOCK_SIZE), data, MAX_FUDAN_BLOCK_SIZE);
|
||||
|
||||
@@ -1048,7 +1048,8 @@ static int hfgal_write_classic_card(GallagherCredentials_t *creds, uint8_t cred_
|
||||
// Select card to get UID
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_1051 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_1051) == false) {
|
||||
PrintAndLogEx(ERR, "Card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -1056,7 +1057,7 @@ static int hfgal_write_classic_card(GallagherCredentials_t *creds, uint8_t cred_
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_1051;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "Card select failed");
|
||||
return PM3_EFAILED;
|
||||
@@ -1177,7 +1178,8 @@ static int hfgal_read_classic_card(uint8_t *site_key, bool verbose, bool quiet)
|
||||
// Select card
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_1181 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_1181) == false) {
|
||||
if (!quiet) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
}
|
||||
@@ -1193,7 +1195,7 @@ static int hfgal_read_classic_card(uint8_t *site_key, bool verbose, bool quiet)
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_1181;
|
||||
|
||||
if (select_status == 0) {
|
||||
if (!quiet) {
|
||||
|
||||
@@ -405,7 +405,8 @@ static int ict_select_card(iso14a_card_select_t *card) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_408 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_408) == false) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
@@ -415,7 +416,7 @@ static int ict_select_card(iso14a_card_select_t *card) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_408;
|
||||
if (select_status == 0) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
@@ -124,18 +124,19 @@ static int lto_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response, uint16
|
||||
SendIso14aReaderEx(flags, cmd, len, len, lenbits, 0, 0);
|
||||
PacketResponseNG resp;
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t rlen_127 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen_127, NULL) == false) {
|
||||
if (verbose) PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] == *response_len) {
|
||||
*response_len = resp.oldarg[0];
|
||||
if (rlen_127 == *response_len) {
|
||||
*response_len = rlen_127;
|
||||
if (*response_len > 0) {
|
||||
memcpy(response, resp.data.asBytes, *response_len);
|
||||
}
|
||||
} else {
|
||||
if (verbose) PrintAndLogEx(WARNING, "Wrong response length (%d != %" PRIu64 ")", *response_len, resp.oldarg[0]);
|
||||
if (verbose) PrintAndLogEx(WARNING, "Wrong response length (%d != %u)", *response_len, rlen_127);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
|
||||
+51
-35
@@ -378,7 +378,8 @@ int mf_read_uid(uint8_t *uid, int *uidlen, int *nxptype) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_381 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_381) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
return PM3_ERFTRANS;
|
||||
@@ -387,20 +388,21 @@ int mf_read_uid(uint8_t *uid, int *uidlen, int *nxptype) {
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_381;
|
||||
|
||||
// try to request ATS even if tag claims not to support it. If yes => 4
|
||||
if (select_status == 2) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint16_t rlen_398 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, &rlen_398, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]);
|
||||
card.ats_len = resp.oldarg[0]; // note: ats_len includes CRC Bytes
|
||||
memcpy(card.ats, resp.data.asBytes, rlen_398);
|
||||
card.ats_len = rlen_398; // note: ats_len includes CRC Bytes
|
||||
if (card.ats_len > 3) {
|
||||
select_status = 4;
|
||||
}
|
||||
@@ -916,12 +918,13 @@ static int mfc_read_tag(iso14a_card_select_t *card, uint8_t *carddata, uint8_t n
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_921 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_921) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_921;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
return PM3_ESOFT;
|
||||
@@ -3090,13 +3093,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_3096 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_3096) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_3096;
|
||||
if (select_status == 0) {
|
||||
// iso14443a card select failed
|
||||
PrintAndLogEx(FAILED, "No tag detected or other tag communication error");
|
||||
@@ -3113,13 +3117,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint16_t rlen_3120 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, &rlen_3120, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]);
|
||||
card.ats_len = resp.oldarg[0]; // note: ats_len includes CRC Bytes
|
||||
memcpy(card.ats, resp.data.asBytes, rlen_3120);
|
||||
card.ats_len = rlen_3120; // note: ats_len includes CRC Bytes
|
||||
if (card.ats_len > 3) {
|
||||
select_status = 4;
|
||||
}
|
||||
@@ -6354,7 +6359,8 @@ static int CmdHF14AMfCSave(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_6362 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_6362) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -6365,7 +6371,7 @@ static int CmdHF14AMfCSave(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_6362;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
return PM3_SUCCESS;
|
||||
@@ -6504,7 +6510,8 @@ static int CmdHF14AMfCView(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_6513 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_6513) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -6515,7 +6522,7 @@ static int CmdHF14AMfCView(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_6513;
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
@@ -7401,12 +7408,13 @@ int CmdHFMFNDEFFormat(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_7411 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_7411) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_7411;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
return PM3_SUCCESS;
|
||||
@@ -8139,16 +8147,18 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
|
||||
uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS;
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(flags, data, sizeof(data));
|
||||
if (WaitForResponseTimeout(CMD_ACK, NULL, 1500) == false) {
|
||||
// CONNECT + RAW, so the device answers twice: select first, then the raw exchange
|
||||
if (WaitForIso14aReply(NULL, 1500, NULL, NULL) == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t len = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &len, NULL) == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t len = resp.oldarg[0] & 0xFFFF;
|
||||
len &= 0xFFFF;
|
||||
if (len != 20) {
|
||||
break; // Not trace data
|
||||
}
|
||||
@@ -8170,16 +8180,18 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
|
||||
uint32_t flags = ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_RATS;
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(flags, data, sizeof(data));
|
||||
if (WaitForResponseTimeout(CMD_ACK, NULL, 1500) == false) {
|
||||
// CONNECT + RAW, so the device answers twice: select first, then the raw exchange
|
||||
if (WaitForIso14aReply(NULL, 1500, NULL, NULL) == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t len = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &len, NULL) == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t len = resp.oldarg[0] & 0xFFFF;
|
||||
len &= 0xFFFF;
|
||||
if (len != 18) {
|
||||
break; // Not trace data
|
||||
}
|
||||
@@ -9397,7 +9409,8 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_9410 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_9410) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -9408,7 +9421,7 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_9410;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
return PM3_SUCCESS;
|
||||
@@ -11229,7 +11242,8 @@ static int CmdHF14AMfInfo(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_11243 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_11243) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -11244,20 +11258,21 @@ static int CmdHF14AMfInfo(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_11243;
|
||||
|
||||
// try to request ATS even if tag claims not to support it. If yes => 4
|
||||
if (select_status == 2) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint16_t rlen_11266 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, &rlen_11266, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]);
|
||||
card.ats_len = resp.oldarg[0]; // note: ats_len includes CRC Bytes
|
||||
memcpy(card.ats, resp.data.asBytes, rlen_11266);
|
||||
card.ats_len = rlen_11266; // note: ats_len includes CRC Bytes
|
||||
if (card.ats_len > 3) {
|
||||
select_status = 4;
|
||||
}
|
||||
@@ -11281,7 +11296,7 @@ static int CmdHF14AMfInfo(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("ISO14443-a Information") " -----------------------------");
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card.sak, select_status);
|
||||
|
||||
|
||||
uint8_t ats_hist_pos = 0;
|
||||
@@ -11797,7 +11812,8 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_11813 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_11813) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
return 0;
|
||||
}
|
||||
@@ -11811,7 +11827,7 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
2: OK, no ATS
|
||||
3: proprietary Anticollision
|
||||
*/
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_11813;
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
@@ -11888,7 +11904,7 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("ISO14443-a Information") " -----------------------------");
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card.sak, select_status);
|
||||
|
||||
// if (setDeviceDebugLevel(DBG_DEBUG, false) != PM3_SUCCESS) {
|
||||
if (setDeviceDebugLevel(DBG_EXTENDED, false) != PM3_SUCCESS) {
|
||||
|
||||
@@ -1810,7 +1810,8 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
// MIFARE DESFire info
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_1813 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_1813) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -1818,7 +1819,7 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
uint64_t select_status = sel_1813; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
|
||||
uint8_t data[10 + 1 + 2 + 1 + 256 + (4 * 0xE * (24 + 1))] = {0};
|
||||
uint8_t atslen = 0;
|
||||
|
||||
@@ -128,13 +128,14 @@ static int mfp_read_card_id(iso14a_card_select_t *card, int *nxptype) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_131 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_131) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
|
||||
uint64_t select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK with ATS, 2: OK no ATS, 3: proprietary
|
||||
uint64_t select_status = sel_131; // 0: couldn't read, 1: OK with ATS, 2: OK no ATS, 3: proprietary
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "No card present or card not responding");
|
||||
DropField();
|
||||
@@ -290,7 +291,8 @@ static int CmdHFMFPInfo(const char *Cmd) {
|
||||
// Mifare Plus info
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
uint8_t sel_294 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2000, NULL, &sel_294) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return false;
|
||||
@@ -299,7 +301,7 @@ static int CmdHFMFPInfo(const char *Cmd) {
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
uint64_t select_status = sel_294; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
|
||||
bool Version4BUID = false;
|
||||
bool supportVersion = false;
|
||||
|
||||
+10
-7
@@ -658,11 +658,12 @@ static int fm11_collect_nonces_ex(const uint8_t *key, uint32_t flags, uint8_t fi
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_661 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_661) == false) {
|
||||
PrintAndLogEx(WARNING, "iso14443a card select timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
if (resp.oldarg[0] == 0) {
|
||||
if (sel_661 == 0) {
|
||||
PrintAndLogEx(WARNING, "iso14443a card select failed");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -2759,13 +2760,14 @@ static int fm11_select_mifare_classic(iso14a_card_select_t *card_out) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t sel_2763 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_2763) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_2763;
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(FAILED, "No tag detected or other tag communication error");
|
||||
PrintAndLogEx(HINT, "Hint: Try some distance or position of the card");
|
||||
@@ -2779,14 +2781,15 @@ static int fm11_select_mifare_classic(iso14a_card_select_t *card_out) {
|
||||
uint8_t rats[] = { 0xE0, 0x80 };
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint16_t rlen_2784 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, &rlen_2784, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(card.ats, resp.data.asBytes, resp.oldarg[0]);
|
||||
card.ats_len = resp.oldarg[0];
|
||||
memcpy(card.ats, resp.data.asBytes, rlen_2784);
|
||||
card.ats_len = rlen_2784;
|
||||
if (card.ats_len > 3) {
|
||||
select_status = 4;
|
||||
}
|
||||
|
||||
+38
-27
@@ -340,14 +340,15 @@ int ul_read_uid(uint8_t *uid) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_343 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_343) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_343;
|
||||
// 0: couldn't read
|
||||
// 1: OK with ATS
|
||||
// 2: OK, no ATS
|
||||
@@ -379,15 +380,16 @@ static int ul_send_cmd_raw(const uint8_t *cmd, uint8_t cmdlen, uint8_t *response
|
||||
}
|
||||
SendIso14aReader(param, cmd, cmdlen);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t rlen_383 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen_383, NULL) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if ((resp.oldarg[0] == 0) && responseLength) {
|
||||
if ((rlen_383 == 0) && responseLength) {
|
||||
return PM3_EWRONGANSWER;
|
||||
}
|
||||
|
||||
uint16_t resplen = (resp.oldarg[0] < responseLength) ? resp.oldarg[0] : responseLength;
|
||||
uint16_t resplen = (rlen_383 < responseLength) ? rlen_383 : responseLength;
|
||||
memcpy(response, resp.data.asBytes, resplen);
|
||||
return resplen;
|
||||
}
|
||||
@@ -397,13 +399,13 @@ static bool ul_select(iso14a_card_select_t *card) {
|
||||
ul_switch_on_field();
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
if (WaitForIso14aReply(&resp, 2000, NULL, NULL) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return false;
|
||||
} else {
|
||||
|
||||
uint16_t len = (resp.oldarg[1] & 0xFFFF);
|
||||
uint16_t len = ((const iso14a_card_select_t *)resp.data.asBytes)->uidlen;
|
||||
if (len == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
@@ -422,13 +424,15 @@ static bool ul_select_rats(iso14a_card_select_t *card) {
|
||||
ul_switch_on_field();
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint8_t select_status = 0;
|
||||
uint16_t ats_len = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &select_status) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return false;
|
||||
} else {
|
||||
|
||||
uint16_t len = (resp.oldarg[1] & 0xFFFF);
|
||||
uint16_t len = ((const iso14a_card_select_t *)resp.data.asBytes)->uidlen;
|
||||
if (len == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
@@ -439,18 +443,18 @@ static bool ul_select_rats(iso14a_card_select_t *card) {
|
||||
memcpy(card, resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
|
||||
if (select_status == 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
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, rats, sizeof(rats));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
if (WaitForIso14aReply(&resp, 1500, &ats_len, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (card) {
|
||||
card->ats_len = resp.oldarg[0];
|
||||
card->ats_len = ats_len;
|
||||
memcpy(card->ats, resp.data.asBytes, card->ats_len);
|
||||
}
|
||||
|
||||
@@ -498,7 +502,7 @@ static int ulc_requestAuthentication(uint8_t *nonce, uint16_t nonceLength) {
|
||||
int mfuc_test_authentication_support(void) {
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, NULL) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -804,10 +808,11 @@ static long long unsigned int ul_fudan_check(void) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, cmd, sizeof(cmd));
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t rlen_810 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen_810, NULL) == false) {
|
||||
return MFU_TT_UL_ERROR;
|
||||
}
|
||||
if (resp.oldarg[0] != 1) {
|
||||
if (rlen_810 != 1) {
|
||||
return MFU_TT_UL_ERROR;
|
||||
}
|
||||
|
||||
@@ -2010,8 +2015,9 @@ static int mfulc_fingerprint(void) {
|
||||
}
|
||||
uint8_t cmd0[] = {0xAF};
|
||||
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)) {
|
||||
uint16_t rlen_2017 = 0;
|
||||
if (WaitForIso14aReply(&resp, 500, &rlen_2017, NULL)) {
|
||||
if ((rlen_2017 == 11) && (resp.data.asBytes[0] == 0x00)) {
|
||||
PrintAndLogEx(SUCCESS, _GREEN_("Lab401 Ultralight-C compatible UID modifiable"));
|
||||
DropField();
|
||||
return PM3_SUCCESS;
|
||||
@@ -2027,8 +2033,9 @@ static int mfulc_fingerprint(void) {
|
||||
}
|
||||
uint8_t cmd1[] = {0x1A, 0x2F};
|
||||
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)) {
|
||||
uint16_t rlen_2035 = 0;
|
||||
if (WaitForIso14aReply(&resp, 500, &rlen_2035, NULL)) {
|
||||
if ((rlen_2035 == 11) && (resp.data.asBytes[0] == 0xAF)) {
|
||||
PrintAndLogEx(SUCCESS, _GREEN_("Feiju FJ8010"));
|
||||
DropField();
|
||||
return PM3_SUCCESS;
|
||||
@@ -2044,8 +2051,9 @@ static int mfulc_fingerprint(void) {
|
||||
}
|
||||
uint8_t cmd2[] = {0x1A};
|
||||
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)) {
|
||||
uint16_t rlen_2053 = 0;
|
||||
if (WaitForIso14aReply(&resp, 500, &rlen_2053, NULL)) {
|
||||
if ((rlen_2053 == 11) && (resp.data.asBytes[0] == 0xAF)) {
|
||||
uint8_t response[11] = {0};
|
||||
memcpy(response, resp.data.asBytes, 9);
|
||||
compute_crc(CRC_14443_A, response, 9, response + 9, response + 10);
|
||||
@@ -2070,11 +2078,13 @@ static int mfulc_fingerprint(void) {
|
||||
// 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) {
|
||||
uint16_t rlen_2080 = 0;
|
||||
if (WaitForIso14aReply(&resp, 500, &rlen_2080, NULL)) {
|
||||
if (rlen_2080 == 2) {
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_NO_SELECT, cmd3b, sizeof(cmd3b));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 500)) {
|
||||
if (resp.oldarg[0] == 18) {
|
||||
uint16_t rlen_2084 = 0;
|
||||
if (WaitForIso14aReply(&resp, 500, &rlen_2084, NULL)) {
|
||||
if (rlen_2084 == 18) {
|
||||
if ((resp.data.asBytes[0] == 0x04) && (resp.data.asBytes[6] == 0x15) && (resp.data.asBytes[7] == 0x89)) {
|
||||
PrintAndLogEx(SUCCESS, _GREEN_("GT23SC4489"));
|
||||
} else {
|
||||
@@ -6121,7 +6131,8 @@ static int CmdHF14AMfUKeyGen(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_RATS, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_6133 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_6133) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -6129,7 +6140,7 @@ static int CmdHF14AMfUKeyGen(const char *Cmd) {
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_6133;
|
||||
// 0: couldn't read,
|
||||
// 1: OK, with ATS
|
||||
// 2: OK, no ATS
|
||||
|
||||
@@ -1244,7 +1244,7 @@ static int saflok_read_sector(int sector, uint8_t *secdata) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, NULL) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
return PM3_ERFTRANS;
|
||||
|
||||
@@ -44,13 +44,13 @@ static bool st25ta_select(iso14a_card_select_t *card) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, NULL) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return false;
|
||||
} else {
|
||||
|
||||
uint16_t len = (resp.oldarg[1] & 0xFFFF);
|
||||
uint16_t len = ((const iso14a_card_select_t *)resp.data.asBytes)->uidlen;
|
||||
if (len == 0) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select failed");
|
||||
DropField();
|
||||
|
||||
@@ -53,20 +53,21 @@ static void topaz_switch_off_field(void) {
|
||||
static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response, uint16_t *response_len, bool verbose) {
|
||||
SendIso14aReader(ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, cmd, len);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
uint16_t rlen_56 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen_56, NULL) == false) {
|
||||
if (verbose) PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.oldarg[0] == *response_len) {
|
||||
*response_len = resp.oldarg[0];
|
||||
if (rlen_56 == *response_len) {
|
||||
*response_len = rlen_56;
|
||||
|
||||
PrintAndLogEx(DEBUG, "%s", sprint_hex(resp.data.asBytes, *response_len));
|
||||
if (*response_len > 0) {
|
||||
memcpy(response, resp.data.asBytes, *response_len);
|
||||
}
|
||||
} else {
|
||||
if (verbose) PrintAndLogEx(WARNING, "Wrong response length (%d != %" PRIu64 ")", *response_len, resp.oldarg[0]);
|
||||
if (verbose) PrintAndLogEx(WARNING, "Wrong response length (%d != %u)", *response_len, rlen_56);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
|
||||
@@ -138,15 +138,16 @@ static int transceive_blocking(uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf
|
||||
PacketResponseNG resp;
|
||||
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) {
|
||||
PrintAndLogEx(WARNING, "Received %"PRIu64 " bytes, rxBuf too small (%u)", resp.oldarg[0], rxBufLen);
|
||||
uint16_t rlen_141 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2000, &rlen_141, NULL)) {
|
||||
if (rlen_141 > rxBufLen) {
|
||||
PrintAndLogEx(WARNING, "Received %"PRIu64 " bytes, rxBuf too small (%u)", rlen_141, rxBufLen);
|
||||
memcpy(rxBuf, resp.data.asBytes, rxBufLen);
|
||||
*actLen = rxBufLen;
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
memcpy(rxBuf, resp.data.asBytes, resp.oldarg[0]);
|
||||
*actLen = resp.oldarg[0];
|
||||
memcpy(rxBuf, resp.data.asBytes, rlen_141);
|
||||
*actLen = rlen_141;
|
||||
}
|
||||
|
||||
if ((retransmit) && (rxBuf[0] != 0 || rxBuf[1] != 0)) {
|
||||
@@ -252,7 +253,8 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) {
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE | ISO14A_NO_DISCONNECT, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_256 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_256) == false) {
|
||||
PrintAndLogEx(ERR, "No tag found");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -261,7 +263,7 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) {
|
||||
iso14a_card_select_t card;
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_256;
|
||||
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "Tag select error");
|
||||
|
||||
@@ -3315,13 +3315,14 @@ int DesfireGetCardUID(DesfireContext_t *ctx) {
|
||||
|
||||
SendIso14aReader(ISO14A_CONNECT | ISO14A_CLEARTRACE, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
uint8_t sel_3318 = 0;
|
||||
if (WaitForIso14aReply(&resp, 2500, NULL, &sel_3318) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
|
||||
uint64_t select_status = resp.oldarg[0];
|
||||
uint64_t select_status = sel_3318;
|
||||
|
||||
if (select_status == 0 || select_status == 2 || select_status == 3) {
|
||||
return PM3_ESOFT;
|
||||
|
||||
@@ -63,8 +63,9 @@ static int mfG4ExCommand(uint8_t cmd, uint8_t *pwd, uint8_t *data, size_t datale
|
||||
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)) {
|
||||
if (resp.oldarg[0] != 2) {
|
||||
uint8_t sel_66 = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, NULL, &sel_66)) {
|
||||
if (sel_66 != 2) {
|
||||
if (verbose) PrintAndLogEx(ERR, "No card in the field.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -74,15 +75,17 @@ static int mfG4ExCommand(uint8_t cmd, uint8_t *pwd, uint8_t *data, size_t datale
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
|
||||
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
|
||||
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%u]"), card.sak, sel_66);
|
||||
}
|
||||
} else {
|
||||
if (verbose) PrintAndLogEx(ERR, "No card in the field.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||
resplen = resp.oldarg[0];
|
||||
// CONNECT + RAW, so the device answers twice: select above, raw exchange here
|
||||
uint16_t rlen = 0;
|
||||
if (WaitForIso14aReply(&resp, 1500, &rlen, NULL)) {
|
||||
resplen = rlen;
|
||||
|
||||
if (!resplen) {
|
||||
if (verbose) PrintAndLogEx(ERR, "No card response.");
|
||||
|
||||
@@ -1405,28 +1405,32 @@ int detect_classic_prng(void) {
|
||||
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(flags, cmd, sizeof(cmd));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
|
||||
// CONNECT + RAW, so the device answers twice: select first, then the raw exchange
|
||||
uint8_t select_status = 0;
|
||||
if (WaitForIso14aReply(&resp, 2000, NULL, &select_status) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// if select tag failed.
|
||||
if (resp.oldarg[0] == 0) {
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "error: selecting tag failed, can't detect prng\n");
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
if (WaitForResponseTimeout(CMD_ACK, &respA, 2500) == false) {
|
||||
uint16_t rlen = 0;
|
||||
if (WaitForIso14aReply(&respA, 2500, &rlen, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// check respA
|
||||
if (respA.oldarg[0] != 4) {
|
||||
PrintAndLogEx(ERR, "PRNG data error: Wrong length: %"PRIu64, respA.oldarg[0]);
|
||||
if (rlen != 4) {
|
||||
PrintAndLogEx(ERR, "PRNG data error: Wrong length: %u", rlen);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint32_t nonce = bytes_to_num(respA.data.asBytes, respA.oldarg[0]);
|
||||
uint32_t nonce = bytes_to_num(respA.data.asBytes, rlen);
|
||||
return validate_prng_nonce(nonce);
|
||||
}
|
||||
|
||||
@@ -1445,23 +1449,27 @@ int detect_classic_auth(uint8_t key_type) {
|
||||
|
||||
clearCommandBuffer();
|
||||
SendIso14aReader(flags, cmd, sizeof(cmd));
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
|
||||
|
||||
// CONNECT + RAW, so the device answers twice: select first, then the raw exchange
|
||||
uint8_t select_status = 0;
|
||||
if (WaitForIso14aReply(&resp, 2000, NULL, &select_status) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// if select tag failed.
|
||||
if (resp.oldarg[0] == 0) {
|
||||
if (select_status == 0) {
|
||||
PrintAndLogEx(ERR, "error: selecting tag failed, can't detect nonce\n");
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
if (WaitForResponseTimeout(CMD_ACK, &respA, 2500) == false) {
|
||||
uint16_t rlen = 0;
|
||||
if (WaitForIso14aReply(&respA, 2500, &rlen, NULL) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// check respA for a nonce
|
||||
return respA.oldarg[0] == 4;
|
||||
return (rlen == 4);
|
||||
}
|
||||
|
||||
/* Detect Mifare Classic NACK bug
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define _MIFARE_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h" // PM3_CMD_DATA_SIZE
|
||||
|
||||
// These are also used to construct AUTH commands (60+x)
|
||||
#define MF_KEY_A 0
|
||||
@@ -127,6 +128,20 @@ typedef struct {
|
||||
|
||||
#define ISO14A_RAW_LEN(x) (sizeof(iso14a_raw_cmd_t) + (x))
|
||||
|
||||
// Reply to CMD_HF_ISO14443A_READER.
|
||||
// Replaces the anonymous CMD_ACK this command used to answer with:
|
||||
// arg0 = select status on a CONNECT, otherwise the response length
|
||||
// arg1 = uidlen on a CONNECT (also in the card struct), or the APDU res byte
|
||||
typedef struct {
|
||||
uint16_t len; // bytes in data[]
|
||||
uint8_t sel; // select status on CONNECT, APDU res byte, else 0
|
||||
uint8_t rfu;
|
||||
uint8_t data[];
|
||||
} PACKED iso14a_raw_resp_t;
|
||||
|
||||
#define ISO14A_RESP_LEN(x) (sizeof(iso14a_raw_resp_t) + (x))
|
||||
#define ISO14A_RESP_MAXLEN (PM3_CMD_DATA_SIZE - sizeof(iso14a_raw_resp_t))
|
||||
|
||||
typedef struct {
|
||||
uint8_t *response;
|
||||
uint8_t *modulation;
|
||||
|
||||
Reference in new issue
Block a user