#include "util.h"\r
#include "crc.h"\r
#include "protocols.h"\r
+#include "parity.h"\r
\r
//-----------------------------------------------------------------------------\r
// Select, Authenticate, Read a MIFARE tag. \r
\r
// Return 1 if the nonce is invalid else return 0\r
int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity) {\r
- return ((oddparity((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity((NtEnc >> 24) & 0xFF) ^ BIT(Ks1,16))) & \\r
- (oddparity((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity((NtEnc >> 16) & 0xFF) ^ BIT(Ks1,8))) & \\r
- (oddparity((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity((NtEnc >> 8) & 0xFF) ^ BIT(Ks1,0)))) ? 1 : 0;\r
+ return ((oddparity8((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity8((NtEnc >> 24) & 0xFF) ^ BIT(Ks1,16))) & \\r
+ (oddparity8((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity8((NtEnc >> 16) & 0xFF) ^ BIT(Ks1,8))) & \\r
+ (oddparity8((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity8((NtEnc >> 8) & 0xFF) ^ BIT(Ks1,0)))) ? 1 : 0;\r
}\r
\r
\r
\r
// Parity validity check\r
for (j = 0; j < 4; j++) {\r
- par_array[j] = (oddparity(receivedAnswer[j]) != ((par[0] >> (7-j)) & 0x01));\r
+ par_array[j] = (oddparity8(receivedAnswer[j]) != ((par[0] >> (7-j)) & 0x01));\r
}\r
\r
ncount = 0;\r
\r
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){\r
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);\r
- //emlSetMem(datain, arg0, arg1); // data, block num, blocks count \r
+ if (arg2==0) arg2 = 16; // backwards compat... default bytewidth\r
emlSetMem_xt(datain, arg0, arg1, arg2); // data, block num, blocks count, block byte width\r
}\r
\r
if(!iso14443a_select_card(uid, NULL, &cuid, true, 0)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Can't select card");\r
OnErrorMagic(MAGIC_UID);\r
- };\r
- };\r
+ }\r
+ }\r
\r
// wipe tag, fill it with zeros\r
if (workFlags & MAGIC_WIPE){\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");\r
OnErrorMagic(MAGIC_WIPE);\r
- };\r
+ }\r
\r
ReaderTransmit(wipeC, sizeof(wipeC), NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wipeC error");\r
OnErrorMagic(MAGIC_WIPE);\r
- };\r
- }; \r
+ }\r
+ } \r
\r
// write block\r
if (workFlags & MAGIC_WUPC) {\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");\r
OnErrorMagic(MAGIC_WUPC);\r
- };\r
+ }\r
\r
ReaderTransmit(wupC2, sizeof(wupC2), NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC2 error");\r
OnErrorMagic(MAGIC_WUPC);\r
- };\r
+ }\r
}\r
\r
if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_WRITEBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send command error");\r
OnErrorMagic(4);\r
- };\r
+ }\r
\r
memcpy(data, datain, 16);\r
AppendCrc14443a(data, 16);\r
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("write block send data error");\r
OnErrorMagic(0);\r
- }; \r
+ } \r
\r
if (workFlags & MAGIC_OFF) \r
mifare_classic_halt_ex(NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC1 error");\r
OnErrorMagic(MAGIC_WUPC);\r
- };\r
+ }\r
\r
ReaderTransmit(wupC2, sizeof(wupC2), NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("wupC2 error");\r
OnErrorMagic(MAGIC_WUPC);\r
- };\r
+ }\r
}\r
\r
// read block \r
if ((mifare_sendcmd_short(NULL, 0, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 18)) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("read block send command error");\r
OnErrorMagic(0);\r
- };\r
+ }\r
\r
memcpy(data, receivedAnswer, sizeof(data));\r
\r
void MifareCIdent(){\r
\r
// variables\r
- byte_t isOK = 1; \r
+ bool isOK = true; \r
uint8_t receivedAnswer[1];\r
uint8_t receivedAnswerPar[1];\r
\r
ReaderTransmitBitsPar(wupC1,7,0, NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
- isOK = 0;\r
- };\r
+ isOK = false;\r
+ }\r
\r
ReaderTransmit(wupC2, sizeof(wupC2), NULL);\r
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {\r
- isOK = 0;\r
- };\r
+ isOK = false;\r
+ }\r
\r
// removed the if, since some magic tags misbehavies and send an answer to it.\r
mifare_classic_halt(NULL, 0);\r