#include "parity.h"\r
#include "crc.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
// Deselect card by sending a s-block. the crc is precalced for speed\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 response in order to trigger the cards authentication failure timeout\r
- uint8_t dummy_answer[8] = {0};\r
- ReaderTransmit(dummy_answer, 8, NULL);\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
i += 9;\r
}\r
\r
+ // wait for the card to become ready again\r
+ while(GetCountSspClk() < timeout);\r
+\r
}\r
\r
LED_C_OFF();\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