]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifareutil.c
FIX: a compilation error for a static method in CmdHF14A.h
[proxmark3-svn] / armsrc / mifareutil.c
index dcea901d98766f0d02704afd73ed8c647fe3a07b..84f77a351c70c8124c865e7502562cf95dfedfcd 100644 (file)
@@ -94,8 +94,8 @@ int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint
        ReaderTransmit(dcmd, sizeof(dcmd), NULL);
        int len = ReaderReceive(answer, answer_parity);
        if(!len) {
-                if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");
-                return 2;
+        if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");
+        return 2;
     }\r
        return len;\r
 }\r
@@ -433,7 +433,6 @@ int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
        // variables
        uint16_t len;     
        uint8_t par[3] = {0}; // enough for 18 parity bits
-       
        uint8_t d_block[18];
        uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
        uint8_t* receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
@@ -466,7 +465,6 @@ int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
 int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
 {
     uint16_t len;
-\r
        uint8_t d_block[8];
        uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
        uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
@@ -625,3 +623,91 @@ void emlClearMem(void) {
        emlSetMem((uint8_t *)uid, 0, 1);\r
        return;\r
 }\r
+\r
+//\r
+//DESFIRE\r
+//\r
+int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing)\r
+{\r
+    uint8_t dcmd[5] = {0x00};\r
+    dcmd[0] = cmd;\r
+    memcpy(dcmd+1,data,2);\r
+       AppendCrc14443a(dcmd, 3);\r
+       \r
+       ReaderTransmit(dcmd, sizeof(dcmd), NULL);\r
+       int len = ReaderReceive(answer, answer_parity);\r
+       if(!len) {\r
+               if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");\r
+                       return 2;\r
+    }\r
+       return len;\r
+}\r
+\r
+int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer,uint8_t *answer_parity, uint32_t *timing)\r
+{\r
+    uint8_t dcmd[20] = {0x00};\r
+    dcmd[0] = cmd;\r
+    memcpy(dcmd+1,data,17);\r
+       AppendCrc14443a(dcmd, 18);\r
+\r
+       ReaderTransmit(dcmd, sizeof(dcmd), NULL);\r
+       int len = ReaderReceive(answer, answer_parity);\r
+       if(!len){\r
+        if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");\r
+                       return 2;\r
+    }\r
+       return len;\r
+}\r
+\r
+int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData){\r
+       // variables\r
+       int len;\r
+       //           load key, keynumber\r
+       uint8_t data[2]={0x0a, 0x00};\r
+       uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
+       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
+       \r
+       // command MIFARE_CLASSIC_READBLOCK\r
+       len = mifare_sendcmd_special(NULL, 1, 0x02, data, receivedAnswer,receivedAnswerPar,NULL);\r
+       if (len == 1) {\r
+               if (MF_DBGLEVEL >= 1)   Dbprintf("Cmd Error: %02x", receivedAnswer[0]);\r
+               return 1;\r
+       }\r
+       \r
+       if (len == 12) {\r
+               if (MF_DBGLEVEL >= 1)   Dbprintf("Auth1 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",\r
+                 receivedAnswer[0],receivedAnswer[1],receivedAnswer[2],receivedAnswer[3],receivedAnswer[4],\r
+                 receivedAnswer[5],receivedAnswer[6],receivedAnswer[7],receivedAnswer[8],receivedAnswer[9],\r
+                 receivedAnswer[10],receivedAnswer[11]);\r
+               memcpy(blockData, receivedAnswer, 12);\r
+               return 0;\r
+       }\r
+       return 1;\r
+}\r
+\r
+int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData){\r
+       // variables\r
+       int len;\r
+       uint8_t data[17]={0xaf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       memcpy(data+1,key,16);\r
+       \r
+       uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
+       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
+       \r
+       // command MIFARE_CLASSIC_READBLOCK\r
+       len = mifare_sendcmd_special2(NULL, 1, 0x03, data, receivedAnswer, receivedAnswerPar ,NULL);\r
+       \r
+       if ((receivedAnswer[0] == 0x03)&&(receivedAnswer[1] == 0xae)) {\r
+               if (MF_DBGLEVEL >= 1)   Dbprintf("Auth Error: %02x %02x", receivedAnswer[0], receivedAnswer[1]);\r
+               return 1;\r
+       }\r
+       if (len == 12){\r
+               if (MF_DBGLEVEL >= 1)   Dbprintf("Auth2 Resp: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",\r
+                 receivedAnswer[0],receivedAnswer[1],receivedAnswer[2],receivedAnswer[3],receivedAnswer[4],\r
+                 receivedAnswer[5],receivedAnswer[6],receivedAnswer[7],receivedAnswer[8],receivedAnswer[9],\r
+                 receivedAnswer[10],receivedAnswer[11]);\r
+               memcpy(blockData, receivedAnswer, 12);\r
+               return 0;\r
+       }\r
+       return 1;\r
+}
\ No newline at end of file
Impressum, Datenschutz