]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifarecmd.c
(no commit message)
[proxmark3-svn] / armsrc / mifarecmd.c
index f18b75a08a37936484b15fe0a41542ba0b0d93b6..a0e0b01f967c4f127fd796ca5ea80e813834dce5 100644 (file)
@@ -78,11 +78,12 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
 \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
-       memcpy(ack.d.asBytes, dataoutbuf, 16);\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     memcpy(ack.d.asBytes, dataoutbuf, 16);\r
        \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,16);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
        LED_B_OFF();\r
 \r
 \r
@@ -170,17 +171,18 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
 \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
-       memcpy(ack.d.asBytes, dataoutbuf, 16 * 2);\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     memcpy(ack.d.asBytes, dataoutbuf, 16 * 2);\r
        \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
-\r
-       SpinDelay(100);\r
+  cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,32);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+//     SpinDelay(100);\r
        \r
-       memcpy(ack.d.asBytes, dataoutbuf + 16 * 2, 16 * 2);\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
-       LED_B_OFF();    \r
+//     memcpy(ack.d.asBytes, dataoutbuf + 16 * 2, 16 * 2);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,isOK,0,0,dataoutbuf+32, 32);\r
+       LED_B_OFF();\r
 \r
        // Thats it...\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
@@ -256,11 +258,12 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
 \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
        \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
-       LED_B_OFF();    \r
+  cmd_send(CMD_ACK,isOK,0,0,0,0);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+       LED_B_OFF();\r
 \r
 \r
        // Thats it...\r
@@ -301,7 +304,6 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
        nestedVector nvector[NES_MAX_INFO + 1][11];\r
        int nvectorcount[NES_MAX_INFO + 1];\r
        int ncount = 0;\r
-       UsbCommand ack = {CMD_ACK, {0, 0, 0}};\r
        struct Crypto1State mpcs = {0, 0};\r
        struct Crypto1State *pcs;\r
        pcs = &mpcs;\r
@@ -468,6 +470,8 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
 \r
+//  UsbCommand ack = {CMD_ACK, {0, 0, 0}};\r
+\r
        for (i = 0; i < NES_MAX_INFO; i++) {\r
                if (nvectorcount[i] > 10) continue;\r
                \r
@@ -475,34 +479,38 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
                        ncount = nvectorcount[i] - j;\r
                        if (ncount > 5) ncount = 5; \r
 \r
-                       ack.arg[0] = 0; // isEOF = 0\r
-                       ack.arg[1] = ncount;\r
-                       ack.arg[2] = targetBlockNo + (targetKeyType * 0x100);\r
-                       memset(ack.d.asBytes, 0x00, sizeof(ack.d.asBytes));\r
+//                     ack.arg[0] = 0; // isEOF = 0\r
+//                     ack.arg[1] = ncount;\r
+//                     ack.arg[2] = targetBlockNo + (targetKeyType * 0x100);\r
+//                     memset(ack.d.asBytes, 0x00, sizeof(ack.d.asBytes));\r
                        \r
-                       memcpy(ack.d.asBytes, &cuid, 4);\r
+      byte_t buf[48];\r
+      memset(buf, 0x00, sizeof(buf));\r
+                       memcpy(buf, &cuid, 4);\r
                        for (m = 0; m < ncount; m++) {\r
-                               memcpy(ack.d.asBytes + 8 + m * 8 + 0, &nvector[i][m + j].nt, 4);\r
-                               memcpy(ack.d.asBytes + 8 + m * 8 + 4, &nvector[i][m + j].ks1, 4);\r
+                               memcpy(buf + 8 + m * 8 + 0, &nvector[i][m + j].nt, 4);\r
+                               memcpy(buf + 8 + m * 8 + 4, &nvector[i][m + j].ks1, 4);\r
                        }\r
        \r
                        LED_B_ON();\r
-                       SpinDelay(100);\r
-                       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
-                       LED_B_OFF();    \r
+//                     SpinDelay(100);\r
+      cmd_send(CMD_ACK,0,ncount,targetBlockNo + (targetKeyType * 0x100),buf,48);\r
+//                     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+                       LED_B_OFF();\r
                }\r
        }\r
 \r
        // finalize list\r
-       ack.arg[0] = 1; // isEOF = 1\r
-       ack.arg[1] = 0;\r
-       ack.arg[2] = 0;\r
-       memset(ack.d.asBytes, 0x00, sizeof(ack.d.asBytes));\r
+//     ack.arg[0] = 1; // isEOF = 1\r
+//     ack.arg[1] = 0;\r
+//     ack.arg[2] = 0;\r
+//     memset(ack.d.asBytes, 0x00, sizeof(ack.d.asBytes));\r
        \r
        LED_B_ON();\r
-       SpinDelay(300);\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
-       LED_B_OFF();    \r
+//     SpinDelay(300);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,1,0,0,0,0);\r
+       LED_B_OFF();\r
 \r
        if (MF_DBGLEVEL >= 4)   DbpString("NESTED FINISHED");\r
 \r
@@ -575,11 +583,12 @@ void MifareChkKeys(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
 \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
-       if (isOK) memcpy(ack.d.asBytes, datain + i * 6, 6);\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     if (isOK) memcpy(ack.d.asBytes, datain + i * 6, 6);\r
        \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+    cmd_send(CMD_ACK,isOK,0,0,datain + i * 6,6);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
        LED_B_OFF();\r
 \r
   // Thats it...\r
@@ -612,12 +621,14 @@ void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
 }\r
 \r
 void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){\r
-       UsbCommand ack = {CMD_ACK, {arg0, arg1, 0}};\r
+//     UsbCommand ack = {CMD_ACK, {arg0, arg1, 0}};\r
 \r
-       emlGetMem(ack.d.asBytes, arg0, arg1); // data, block num, blocks count\r
+  byte_t buf[48];\r
+       emlGetMem(buf, arg0, arg1); // data, block num, blocks count\r
 \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,arg0,arg1,0,buf,48);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
        LED_B_OFF();\r
 }\r
 \r
@@ -790,7 +801,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
        \r
                // reset chip\r
                if (needWipe){\r
-                       ReaderTransmitShort(wupC1);\r
+      ReaderTransmitBitsPar(wupC1,7,0);\r
                        if(!ReaderReceive(receivedAnswer) || (receivedAnswer[0] != 0x0a)) {\r
                                if (MF_DBGLEVEL >= 1)   Dbprintf("wupC1 error");\r
                                break;\r
@@ -810,7 +821,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
 \r
                // write block\r
                if (workFlags & 0x02) {\r
-                       ReaderTransmitShort(wupC1);\r
+      ReaderTransmitBitsPar(wupC1,7,0);\r
                        if(!ReaderReceive(receivedAnswer) || (receivedAnswer[0] != 0x0a)) {\r
                                if (MF_DBGLEVEL >= 1)   Dbprintf("wupC1 error");\r
                                break;\r
@@ -848,15 +859,22 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                break;\r
        }\r
        \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
-       if (isOK) memcpy(ack.d.asBytes, uid, 4);\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     if (isOK) memcpy(ack.d.asBytes, uid, 4);\r
        \r
        // add trace trailer\r
-       memset(uid, 0x44, 4);\r
-       LogTrace(uid, 4, 0, 0, TRUE);\r
+       /**\r
+       *       Removed by Martin, the uid is overwritten with 0x44, \r
+       *       which can 't be intended. \r
+       *\r
+       *       memset(uid, 0x44, 4);\r
+       *       LogTrace(uid, 4, 0, 0, TRUE);\r
+       **/\r
+       \r
 \r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,isOK,0,0,uid,4);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
        LED_B_OFF();\r
 \r
        if ((workFlags & 0x10) || (!isOK)) {\r
@@ -907,7 +925,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
 \r
        while (true) {\r
                if (workFlags & 0x02) {\r
-                       ReaderTransmitShort(wupC1);\r
+      ReaderTransmitBitsPar(wupC1,7,0);\r
                        if(!ReaderReceive(receivedAnswer) || (receivedAnswer[0] != 0x0a)) {\r
                                if (MF_DBGLEVEL >= 1)   Dbprintf("wupC1 error");\r
                                break;\r
@@ -938,15 +956,20 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                break;\r
        }\r
        \r
-       UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
-       if (isOK) memcpy(ack.d.asBytes, data, 18);\r
+//     UsbCommand ack = {CMD_ACK, {isOK, 0, 0}};\r
+//     if (isOK) memcpy(ack.d.asBytes, data, 18);\r
        \r
        // add trace trailer\r
-       memset(data, 0x44, 4);\r
-       LogTrace(data, 4, 0, 0, TRUE);\r
-\r
+       /*\r
+       * Removed by Martin, this piece of overwrites the 'data' variable \r
+       * which is sent two lines down, and is obviously not correct. \r
+       * \r
+       * memset(data, 0x44, 4);\r
+       * LogTrace(data, 4, 0, 0, TRUE);\r
+       */\r
        LED_B_ON();\r
-       UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
+  cmd_send(CMD_ACK,isOK,0,0,data,18);\r
+//     UsbSendPacket((uint8_t *)&ack, sizeof(UsbCommand));\r
        LED_B_OFF();\r
 \r
        if ((workFlags & 0x10) || (!isOK)) {\r
Impressum, Datenschutz