]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifarecmd.c
Merge branch 'master' of https://github.com/iceman1001/proxmark3
[proxmark3-svn] / armsrc / mifarecmd.c
index be25273de8d461c5dff1acc878fa95499dfa24a9..91aa7218544ee6a2d8a23e72b81e164865b967b2 100644 (file)
@@ -18,6 +18,7 @@
 #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
@@ -591,9 +592,9 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain){
 \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
@@ -897,7 +898,7 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat
                        \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
@@ -1042,7 +1043,7 @@ void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
 \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
@@ -1186,8 +1187,8 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
                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
@@ -1195,14 +1196,14 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
                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
@@ -1210,19 +1211,19 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
                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
@@ -1231,7 +1232,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
        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
@@ -1270,20 +1271,20 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
                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
@@ -1308,19 +1309,19 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain){
 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
Impressum, Datenschutz