mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
chg: enable/disable hf fpga tracing
This commit is contained in:
parent
d78b308470
commit
eb9f67635b
3 changed files with 76 additions and 7 deletions
|
@ -552,8 +552,6 @@ RAMFUNC int ManchesterDecoding_Thinfilm(uint8_t bit) {
|
||||||
return false; // not finished yet, need more data
|
return false; // not finished yet, need more data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// Finally, a `sniffer' for ISO 14443 Type A
|
// Finally, a `sniffer' for ISO 14443 Type A
|
||||||
// Both sides of communication!
|
// Both sides of communication!
|
||||||
|
@ -717,6 +715,8 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||||
}
|
}
|
||||||
} // end main loop
|
} // end main loop
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) {
|
if (DBGLEVEL >= DBG_ERROR) {
|
||||||
Dbprintf("maxDataLen=%d, Uart.state=%x, Uart.len=%d", maxDataLen, Uart.state, Uart.len);
|
Dbprintf("maxDataLen=%d, Uart.state=%x, Uart.len=%d", maxDataLen, Uart.state, Uart.len);
|
||||||
Dbprintf("traceLen=" _YELLOW_("%d")", Uart.output[0]="_YELLOW_("%08x"), BigBuf_get_traceLen(), (uint32_t)Uart.output[0]);
|
Dbprintf("traceLen=" _YELLOW_("%d")", Uart.output[0]="_YELLOW_("%08x"), BigBuf_get_traceLen(), (uint32_t)Uart.output[0]);
|
||||||
|
@ -2646,6 +2646,8 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||||
if (!(param & ISO14A_NO_SELECT)) {
|
if (!(param & ISO14A_NO_SELECT)) {
|
||||||
iso14a_card_select_t *card = (iso14a_card_select_t *)buf;
|
iso14a_card_select_t *card = (iso14a_card_select_t *)buf;
|
||||||
arg0 = iso14443a_select_card(NULL, card, NULL, true, 0, param & ISO14A_NO_RATS);
|
arg0 = iso14443a_select_card(NULL, card, NULL, true, 0, param & ISO14A_NO_RATS);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
reply_mix(CMD_ACK, arg0, card->uidlen, 0, buf, sizeof(iso14a_card_select_t));
|
reply_mix(CMD_ACK, arg0, card->uidlen, 0, buf, sizeof(iso14a_card_select_t));
|
||||||
if (arg0 == 0)
|
if (arg0 == 0)
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
@ -2658,6 +2660,8 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||||
if ((param & ISO14A_APDU)) {
|
if ((param & ISO14A_APDU)) {
|
||||||
uint8_t res;
|
uint8_t res;
|
||||||
arg0 = iso14_apdu(cmd, len, (param & ISO14A_SEND_CHAINING), buf, &res);
|
arg0 = iso14_apdu(cmd, len, (param & ISO14A_SEND_CHAINING), buf, &res);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
reply_old(CMD_ACK, arg0, res, 0, buf, sizeof(buf));
|
reply_old(CMD_ACK, arg0, res, 0, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2702,6 +2706,8 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arg0 = ReaderReceive(buf, par);
|
arg0 = ReaderReceive(buf, par);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
reply_old(CMD_ACK, arg0, 0, 0, buf, sizeof(buf));
|
reply_old(CMD_ACK, arg0, 0, 0, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3013,6 +3019,8 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Number of sent auth requests: %u", i);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Number of sent auth requests: %u", i);
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int32_t isOK;
|
int32_t isOK;
|
||||||
uint8_t cuid[4];
|
uint8_t cuid[4];
|
||||||
|
@ -3270,6 +3278,7 @@ void DetectNACKbug(void) {
|
||||||
|
|
||||||
// num_nacks = number of nacks recieved. should be only 1. if not its a clone card which always sends NACK (parity == 0) ?
|
// num_nacks = number of nacks recieved. should be only 1. if not its a clone card which always sends NACK (parity == 0) ?
|
||||||
// i = number of authentications sent. Not always 256, since we are trying to sync but close to it.
|
// i = number of authentications sent. Not always 256, since we are trying to sync but close to it.
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
uint8_t *data = BigBuf_malloc(4);
|
uint8_t *data = BigBuf_malloc(4);
|
||||||
data[0] = isOK;
|
data[0] = isOK;
|
||||||
|
|
|
@ -1165,6 +1165,9 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r
|
||||||
CodeAndTransmit14443bAsReader(message_frame, message_length + 4); //no
|
CodeAndTransmit14443bAsReader(message_frame, message_length + 4); //no
|
||||||
// get response
|
// get response
|
||||||
GetTagSamplesFor14443bDemod(); //no
|
GetTagSamplesFor14443bDemod(); //no
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (Demod.len < 3)
|
if (Demod.len < 3)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -1191,6 +1194,7 @@ uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||||
|
|
||||||
CodeAndTransmit14443bAsReader(init_srx, sizeof(init_srx));
|
CodeAndTransmit14443bAsReader(init_srx, sizeof(init_srx));
|
||||||
GetTagSamplesFor14443bDemod(); //no
|
GetTagSamplesFor14443bDemod(); //no
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (Demod.len == 0)
|
if (Demod.len == 0)
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1204,6 +1208,7 @@ uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||||
|
|
||||||
CodeAndTransmit14443bAsReader(select_srx, sizeof(select_srx));
|
CodeAndTransmit14443bAsReader(select_srx, sizeof(select_srx));
|
||||||
GetTagSamplesFor14443bDemod(); //no
|
GetTagSamplesFor14443bDemod(); //no
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (Demod.len != 3)
|
if (Demod.len != 3)
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1222,6 +1227,7 @@ uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||||
AddCrc14B(select_srx, 1);
|
AddCrc14B(select_srx, 1);
|
||||||
CodeAndTransmit14443bAsReader(select_srx, 3); // Only first three bytes for this one
|
CodeAndTransmit14443bAsReader(select_srx, 3); // Only first three bytes for this one
|
||||||
GetTagSamplesFor14443bDemod(); //no
|
GetTagSamplesFor14443bDemod(); //no
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (Demod.len != 10)
|
if (Demod.len != 10)
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -1253,6 +1259,7 @@ uint8_t iso14443b_select_card(iso14b_card_select_t *card) {
|
||||||
// first, wake up the tag
|
// first, wake up the tag
|
||||||
CodeAndTransmit14443bAsReader(wupb, sizeof(wupb));
|
CodeAndTransmit14443bAsReader(wupb, sizeof(wupb));
|
||||||
GetTagSamplesFor14443bDemod(); //select_card
|
GetTagSamplesFor14443bDemod(); //select_card
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
// ATQB too short?
|
// ATQB too short?
|
||||||
if (Demod.len < 14)
|
if (Demod.len < 14)
|
||||||
|
@ -1277,6 +1284,7 @@ uint8_t iso14443b_select_card(iso14b_card_select_t *card) {
|
||||||
|
|
||||||
CodeAndTransmit14443bAsReader(attrib, sizeof(attrib));
|
CodeAndTransmit14443bAsReader(attrib, sizeof(attrib));
|
||||||
GetTagSamplesFor14443bDemod();//select_card
|
GetTagSamplesFor14443bDemod();//select_card
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
// Answer to ATTRIB too short?
|
// Answer to ATTRIB too short?
|
||||||
if (Demod.len < 3)
|
if (Demod.len < 3)
|
||||||
|
@ -1353,6 +1361,7 @@ static bool ReadSTBlock(uint8_t block) {
|
||||||
AddCrc14B(cmd, 2);
|
AddCrc14B(cmd, 2);
|
||||||
CodeAndTransmit14443bAsReader(cmd, sizeof(cmd));
|
CodeAndTransmit14443bAsReader(cmd, sizeof(cmd));
|
||||||
GetTagSamplesFor14443bDemod();
|
GetTagSamplesFor14443bDemod();
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
// Check if we got an answer from the tag
|
// Check if we got an answer from the tag
|
||||||
if (Demod.len != 6) {
|
if (Demod.len != 6) {
|
||||||
|
@ -1602,7 +1611,7 @@ void SendRawCommand14443B_Ex(PacketCommandNG *c) {
|
||||||
if ((param & ISO14B_SELECT_STD) == ISO14B_SELECT_STD) {
|
if ((param & ISO14B_SELECT_STD) == ISO14B_SELECT_STD) {
|
||||||
iso14b_card_select_t *card = (iso14b_card_select_t *)buf;
|
iso14b_card_select_t *card = (iso14b_card_select_t *)buf;
|
||||||
status = iso14443b_select_card(card);
|
status = iso14443b_select_card(card);
|
||||||
reply_old(CMD_ACK, status, sendlen, 0, buf, sendlen);
|
reply_mix(CMD_ACK, status, sendlen, 0, buf, sendlen);
|
||||||
// 0: OK 2: attrib fail, 3:crc fail,
|
// 0: OK 2: attrib fail, 3:crc fail,
|
||||||
if (status > 0) goto out;
|
if (status > 0) goto out;
|
||||||
}
|
}
|
||||||
|
@ -1610,14 +1619,14 @@ void SendRawCommand14443B_Ex(PacketCommandNG *c) {
|
||||||
if ((param & ISO14B_SELECT_SR) == ISO14B_SELECT_SR) {
|
if ((param & ISO14B_SELECT_SR) == ISO14B_SELECT_SR) {
|
||||||
iso14b_card_select_t *card = (iso14b_card_select_t *)buf;
|
iso14b_card_select_t *card = (iso14b_card_select_t *)buf;
|
||||||
status = iso14443b_select_srx_card(card);
|
status = iso14443b_select_srx_card(card);
|
||||||
reply_old(CMD_ACK, status, sendlen, 0, buf, sendlen);
|
reply_mix(CMD_ACK, status, sendlen, 0, buf, sendlen);
|
||||||
// 0: OK 2: demod fail, 3:crc fail,
|
// 0: OK 2: demod fail, 3:crc fail,
|
||||||
if (status > 0) goto out;
|
if (status > 0) goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((param & ISO14B_APDU) == ISO14B_APDU) {
|
if ((param & ISO14B_APDU) == ISO14B_APDU) {
|
||||||
status = iso14443b_apdu(cmd, len, buf);
|
status = iso14443b_apdu(cmd, len, buf);
|
||||||
reply_old(CMD_ACK, status, status, 0, buf, status);
|
reply_mix(CMD_ACK, status, status, 0, buf, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((param & ISO14B_RAW) == ISO14B_RAW) {
|
if ((param & ISO14B_RAW) == ISO14B_RAW) {
|
||||||
|
@ -1628,6 +1637,7 @@ void SendRawCommand14443B_Ex(PacketCommandNG *c) {
|
||||||
|
|
||||||
CodeAndTransmit14443bAsReader(cmd, len); // raw
|
CodeAndTransmit14443bAsReader(cmd, len); // raw
|
||||||
GetTagSamplesFor14443bDemod(); // raw
|
GetTagSamplesFor14443bDemod(); // raw
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
sendlen = MIN(Demod.len, PM3_CMD_DATA_SIZE);
|
sendlen = MIN(Demod.len, PM3_CMD_DATA_SIZE);
|
||||||
status = (Demod.len > 0) ? 0 : 1;
|
status = (Demod.len > 0) ? 0 : 1;
|
||||||
|
|
|
@ -435,7 +435,6 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*MIFARE 1K simulate.
|
*MIFARE 1K simulate.
|
||||||
*
|
*
|
||||||
|
@ -547,16 +546,19 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FpgaEnableTracing();
|
||||||
//Now, get data
|
//Now, get data
|
||||||
int res = EmGetCmd(receivedCmd, &receivedCmd_len, receivedCmd_par);
|
int res = EmGetCmd(receivedCmd, &receivedCmd_len, receivedCmd_par);
|
||||||
|
|
||||||
if (res == 2) { //Field is off!
|
if (res == 2) { //Field is off!
|
||||||
|
FpgaDisableTracing();
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
cardSTATE = MFEMUL_NOFIELD;
|
cardSTATE = MFEMUL_NOFIELD;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("cardSTATE = MFEMUL_NOFIELD");
|
Dbprintf("cardSTATE = MFEMUL_NOFIELD");
|
||||||
continue;
|
continue;
|
||||||
} else if (res == 1) { // button pressed
|
} else if (res == 1) { // button pressed
|
||||||
|
FpgaDisableTracing();
|
||||||
button_pushed = true;
|
button_pushed = true;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("Button pressed");
|
Dbprintf("Button pressed");
|
||||||
|
@ -570,6 +572,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);");
|
Dbprintf("EmSendPrecompiledCmd(&responses[ATQA]);");
|
||||||
EmSendPrecompiledCmd(&responses[ATQA]);
|
EmSendPrecompiledCmd(&responses[ATQA]);
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
// init crypto block
|
// init crypto block
|
||||||
crypto1_deinit(pcs);
|
crypto1_deinit(pcs);
|
||||||
cardAUTHKEY = AUTHKEYNONE;
|
cardAUTHKEY = AUTHKEYNONE;
|
||||||
|
@ -637,6 +641,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// Incoming SELECT ALL for any cascade level
|
// Incoming SELECT ALL for any cascade level
|
||||||
if (receivedCmd_len == 2 && receivedCmd[1] == 0x20) {
|
if (receivedCmd_len == 2 && receivedCmd[1] == 0x20) {
|
||||||
EmSendPrecompiledCmd(&responses[uid_index]);
|
EmSendPrecompiledCmd(&responses[uid_index]);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ALL - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -648,6 +654,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
(uid_len == 7 && uid_index == UIDBCC2) ||
|
(uid_len == 7 && uid_index == UIDBCC2) ||
|
||||||
(uid_len == 10 && uid_index == UIDBCC3);
|
(uid_len == 10 && uid_index == UIDBCC3);
|
||||||
EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]);
|
EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]);
|
||||||
if (cl_finished) {
|
if (cl_finished) {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
|
@ -670,6 +678,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) {
|
if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) {
|
||||||
// response missing part of UID via relative array index
|
// response missing part of UID via relative array index
|
||||||
EmSendPrecompiledCmd(&responses[uid_index + receivedCmd_len - 2]);
|
EmSendPrecompiledCmd(&responses[uid_index + receivedCmd_len - 2]);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT ANTICOLLISION - EmSendPrecompiledCmd(%02x)", &responses[uid_index]);
|
||||||
} else {
|
} else {
|
||||||
// IDLE, not our UID or split-byte frame anti-collision (not supports)
|
// IDLE, not our UID or split-byte frame anti-collision (not supports)
|
||||||
|
@ -710,6 +720,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) { // all commands must have a valid CRC
|
if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) { // all commands must have a valid CRC
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] All commands must have a valid CRC %02X (%d)", receivedCmd_dec, receivedCmd_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -725,6 +737,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// if authenticating to a block that shouldn't exist - as long as we are not doing the reader attack
|
// if authenticating to a block that shouldn't exist - as long as we are not doing the reader attack
|
||||||
if (((flags & FLAG_NR_AR_ATTACK) != FLAG_NR_AR_ATTACK)) {
|
if (((flags & FLAG_NR_AR_ATTACK) != FLAG_NR_AR_ATTACK)) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -754,6 +768,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
crypto1_word(pcs, cuid ^ nonce, 0);
|
crypto1_word(pcs, cuid ^ nonce, 0);
|
||||||
// rAUTH_NT contains prepared nonce for authenticate
|
// rAUTH_NT contains prepared nonce for authenticate
|
||||||
EmSendCmd(rAUTH_NT, sizeof(rAUTH_NT));
|
EmSendCmd(rAUTH_NT, sizeof(rAUTH_NT));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_NT, cuid);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader authenticating for block %d (0x%02x) with key %c - nonce: %02X - ciud: %02X", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B', rAUTH_NT, cuid);
|
||||||
} else {
|
} else {
|
||||||
// nested authentication
|
// nested authentication
|
||||||
|
@ -765,6 +781,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// we need calculate parity bits for non-encrypted sequence
|
// we need calculate parity bits for non-encrypted sequence
|
||||||
mf_crypto1_encryptEx(pcs, rAUTH_NT, rAUTH_NT_keystream, response, 4, response_par);
|
mf_crypto1_encryptEx(pcs, rAUTH_NT, rAUTH_NT_keystream, response, 4, response_par);
|
||||||
EmSendCmdPar(response, 4, response_par);
|
EmSendCmdPar(response, 4, response_par);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B');
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Reader doing nested authentication for block %d (0x%02x) with key %c", receivedCmd_dec[1], receivedCmd_dec[1], (cardAUTHKEY == 0) ? 'A' : 'B');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,12 +795,14 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// BUT... ACK --> NACK
|
// BUT... ACK --> NACK
|
||||||
if (receivedCmd_len == 1 && receivedCmd_dec[0] == CARD_ACK) {
|
if (receivedCmd_len == 1 && receivedCmd_dec[0] == CARD_ACK) {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rule 12 of 7.5.3. in ISO 14443-4. R(NAK) --> R(ACK)
|
// rule 12 of 7.5.3. in ISO 14443-4. R(NAK) --> R(ACK)
|
||||||
if (receivedCmd_len == 1 && receivedCmd_dec[0] == CARD_NACK_NA) {
|
if (receivedCmd_len == 1 && receivedCmd_dec[0] == CARD_NACK_NA) {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_ACK) : CARD_ACK);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_ACK) : CARD_ACK);
|
||||||
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,6 +816,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
// all other commands must be encrypted (authenticated)
|
// all other commands must be encrypted (authenticated)
|
||||||
if (!encrypted_data) {
|
if (!encrypted_data) {
|
||||||
EmSend4bit(CARD_NACK_NA);
|
EmSend4bit(CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)");
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Commands must be encrypted (authenticated)");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -805,6 +827,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
/*
|
/*
|
||||||
if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK) {
|
if (receivedCmd_dec[1] > MIFARE_4K_MAXBLOCK) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -812,6 +835,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
if (MifareBlockToSector(receivedCmd_dec[1]) != cardAUTHSC) {
|
if (MifareBlockToSector(receivedCmd_dec[1]) != cardAUTHSC) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -867,6 +892,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
AddCrc14A(response, 16);
|
AddCrc14A(response, 16);
|
||||||
mf_crypto1_encrypt(pcs, response, MAX_MIFARE_FRAME_SIZE, response_par);
|
mf_crypto1_encrypt(pcs, response, MAX_MIFARE_FRAME_SIZE, response_par);
|
||||||
EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par);
|
EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_WORK - EmSendCmdPar] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
Dbprintf("[MFEMUL_WORK - EmSendCmdPar] Data Block[%d]: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", blockNo,
|
||||||
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
response[0], response[1], response[2], response[3], response[4], response[5], response[6],
|
||||||
|
@ -888,6 +915,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
blockNo = receivedCmd_dec[1];
|
blockNo = receivedCmd_dec[1];
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo);
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RECV 0xA0 write block %d (%02x)", blockNo, blockNo);
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardWRBL = blockNo;
|
cardWRBL = blockNo;
|
||||||
cardSTATE = MFEMUL_WRITEBL2;
|
cardSTATE = MFEMUL_WRITEBL2;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2");
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] cardSTATE = MFEMUL_WRITEBL2");
|
||||||
|
@ -901,9 +930,11 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (emlCheckValBl(blockNo)) {
|
if (emlCheckValBl(blockNo)) {
|
||||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking");
|
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate on block, but emlCheckValBl failed, nacking");
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
||||||
|
FpgaDisableTracing();
|
||||||
cardWRBL = blockNo;
|
cardWRBL = blockNo;
|
||||||
|
|
||||||
// INC
|
// INC
|
||||||
|
@ -936,6 +967,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
else
|
else
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,12 +991,15 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
memcpy(response, rats, rats_len);
|
memcpy(response, rats, rats_len);
|
||||||
mf_crypto1_encrypt(pcs, response, rats_len, response_par);
|
mf_crypto1_encrypt(pcs, response, rats_len, response_par);
|
||||||
EmSendCmdPar(response, rats_len, response_par);
|
EmSendCmdPar(response, rats_len, response_par);
|
||||||
|
FpgaDisableTracing();
|
||||||
} else
|
} else
|
||||||
EmSendCmd(rats, rats_len);
|
EmSendCmd(rats, rats_len);
|
||||||
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
||||||
} else {
|
} else {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
||||||
}
|
}
|
||||||
|
@ -980,10 +1016,14 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
EmSendCmdPar(response, receivedCmd_len, response_par);
|
EmSendCmdPar(response, receivedCmd_len, response_par);
|
||||||
} else
|
} else
|
||||||
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
||||||
|
|
||||||
|
FpgaDisableTracing();
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
||||||
} else {
|
} else {
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
||||||
}
|
}
|
||||||
|
@ -994,6 +1034,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
if (DBGLEVEL >= DBG_EXTENDED)
|
if (DBGLEVEL >= DBG_EXTENDED)
|
||||||
Dbprintf("Received command not allowed, nacking");
|
Dbprintf("Received command not allowed, nacking");
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
|
FpgaDisableTracing();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1101,6 +1142,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
num_to_bytes(ans, 4, response);
|
num_to_bytes(ans, 4, response);
|
||||||
mf_crypto1_encrypt(pcs, response, 4, response_par);
|
mf_crypto1_encrypt(pcs, response, 4, response_par);
|
||||||
EmSendCmdPar(response, 4, response_par);
|
EmSendCmdPar(response, 4, response_par);
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||||
Dbprintf("[MFEMUL_AUTH1] AUTH COMPLETED for sector %d with key %c. time=%d",
|
Dbprintf("[MFEMUL_AUTH1] AUTH COMPLETED for sector %d with key %c. time=%d",
|
||||||
|
@ -1138,6 +1180,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
}
|
}
|
||||||
emlSetMem(receivedCmd_dec, cardWRBL, 1);
|
emlSetMem(receivedCmd_dec, cardWRBL, 1);
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK)); // always ACK?
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK)); // always ACK?
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardSTATE = MFEMUL_WORK;
|
cardSTATE = MFEMUL_WORK;
|
||||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK");
|
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WRITEBL2] cardSTATE = MFEMUL_WORK");
|
||||||
break;
|
break;
|
||||||
|
@ -1155,6 +1199,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
||||||
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1174,6 +1220,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
||||||
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1190,6 +1238,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t *)&ans);
|
||||||
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
|
||||||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||||
|
FpgaDisableTracing();
|
||||||
|
|
||||||
cardSTATE_TO_IDLE();
|
cardSTATE_TO_IDLE();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1245,7 +1295,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
||||||
|
|
||||||
if ((flags & FLAG_INTERACTIVE) == FLAG_INTERACTIVE) { // Interactive mode flag, means we need to send ACK
|
if ((flags & FLAG_INTERACTIVE) == FLAG_INTERACTIVE) { // Interactive mode flag, means we need to send ACK
|
||||||
//Send the collected ar_nr in the response
|
//Send the collected ar_nr in the response
|
||||||
reply_old(CMD_ACK, CMD_HF_MIFARE_SIMULATE, button_pushed, 0, &ar_nr_resp, sizeof(ar_nr_resp));
|
reply_mix(CMD_ACK, CMD_HF_MIFARE_SIMULATE, button_pushed, 0, &ar_nr_resp, sizeof(ar_nr_resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue