\r
#include "mifarecmd.h"\r
\r
-#include "apps.h"\r
#include "util.h"\r
#include "parity.h"\r
#include "crc.h"\r
+#include "fpgaloader.h"\r
+\r
+#define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation)\r
+#define HARDNESTED_PRE_AUTHENTICATION_LEADTIME 400 // some (non standard) cards need a pause after select before they are ready for first authentication \r
\r
// the block number for the ISO14443-4 PCB\r
static uint8_t pcb_blocknum = 0;\r
}\r
\r
if (slow) {\r
- timeout = GetCountSspClk() + PRE_AUTHENTICATION_LEADTIME;\r
+ timeout = GetCountSspClk() + HARDNESTED_PRE_AUTHENTICATION_LEADTIME;\r
while(GetCountSspClk() < timeout);\r
}\r
\r
continue;\r
}\r
\r
- // send a dummy byte as reader response in order to trigger the cards authentication timeout\r
- uint8_t dummy_answer = 0;\r
- ReaderTransmit(&dummy_answer, 1, NULL);\r
- timeout = GetCountSspClk() + AUTHENTICATION_TIMEOUT;\r
+ // send an incomplete dummy response in order to trigger the card's authentication failure timeout\r
+ uint8_t dummy_answer[1] = {0};\r
+ ReaderTransmit(dummy_answer, 1, NULL);\r
\r
+ timeout = GetCountSspClk() + HARDNESTED_AUTHENTICATION_TIMEOUT;\r
+ \r
num_nonces++;\r
if (num_nonces % 2) {\r
memcpy(buf+i, receivedAnswer, 4);\r
if (blockN >= 128 && blockN <= 256) {\r
return ((blockN & 0x0F) == 0x0F);\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){\r
\r
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
+ \r
+ LED_A_ON();\r
+ LED_B_OFF();\r
+ LED_C_OFF();\r
+ iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
+\r
+ clear_trace();\r
+ set_tracing(true); \r
\r
ReaderTransmitBitsPar(wupC1,7,0, NULL);\r
if(ReaderReceive(receivedAnswer, receivedAnswerPar) && (receivedAnswer[0] == 0x0a)) {\r
\r
// From iceman1001: removed the if, since some magic tags misbehavies and send an answer to it.\r
mifare_classic_halt(NULL, 0);\r
-\r
+ \r
+ LED_B_ON();\r
cmd_send(CMD_ACK,isOK,0,0,0,0);\r
+ LED_B_OFF();\r
+\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+ LEDsoff(); \r
}\r
\r
//\r