]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifarecmd.c
replace msleep() by thread signalling in comms.c
[proxmark3-svn] / armsrc / mifarecmd.c
index b9032c5fafc3dd9dff78f973a495648459a48abc..27b1cf1923456be7248e1065471bc0fdc5b96ad6 100644 (file)
@@ -18,7 +18,7 @@
 #include <stdint.h>\r
 \r
 #include "proxmark3.h"\r
-#include "cmd.h"\r
+#include "usb_cdc.h"\r
 #include "crapto1/crapto1.h"\r
 #include "iso14443a.h"\r
 #include "BigBuf.h"\r
@@ -111,11 +111,12 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2)   DbpString("READ BLOCK FINISHED");\r
 \r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,16);\r
        LED_B_OFF();\r
 \r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
@@ -202,9 +203,10 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
                return;\r
        }\r
 \r
-       cmd_send(CMD_ACK,1,0,0,dataout,16);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LED_D_OFF();\r
+\r
+       cmd_send(CMD_ACK,1,0,0,dataout,16);\r
        LED_A_OFF();\r
 }\r
 \r
@@ -266,12 +268,13 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2) DbpString("READ SECTOR FINISHED");\r
 \r
+       // Thats it...\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,16*NumBlocksPerSector(sectorNo));\r
        LED_B_OFF();\r
 \r
-       // Thats it...\r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
@@ -362,10 +365,11 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= MF_DBG_DEBUG) Dbprintf("Blocks read %d", countblocks);\r
 \r
-       cmd_send(CMD_ACK, 1, countblocks*4, BigBuf_max_traceLen(), 0, 0);\r
-\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LED_D_OFF();\r
+\r
+       cmd_send(CMD_ACK, 1, countblocks*4, BigBuf_max_traceLen(), 0, 0);\r
+\r
        BigBuf_free();\r
        LED_A_OFF();\r
 }\r
@@ -431,13 +435,14 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2)   DbpString("WRITE BLOCK FINISHED");\r
 \r
+       // Thats it...\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,0,0);\r
        LED_B_OFF();\r
 \r
 \r
-       // Thats it...\r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
@@ -475,8 +480,9 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2)   DbpString("WRITE BLOCK FINISHED");\r
 \r
-       cmd_send(CMD_ACK,1,0,0,0,0);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
+       cmd_send(CMD_ACK,1,0,0,0,0);\r
        LEDsoff();\r
 }\r
 */\r
@@ -544,8 +550,9 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");\r
 \r
-       cmd_send(CMD_ACK,1,0,0,0,0);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
+       cmd_send(CMD_ACK,1,0,0,0,0);\r
        LEDsoff();\r
 }\r
 \r
@@ -613,8 +620,9 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain){
                return;\r
        };\r
 \r
-       cmd_send(CMD_ACK,1,0,0,0,0);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
+       cmd_send(CMD_ACK,1,0,0,0,0);\r
        LEDsoff();\r
 }\r
 \r
@@ -743,16 +751,17 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
 \r
        crypto1_destroy(pcs);\r
 \r
+       if (field_off) {\r
+               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+               LEDsoff();\r
+       }\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK, isOK, cuid, num_nonces, buf, sizeof(buf));\r
        LED_B_OFF();\r
 \r
        if (MF_DBGLEVEL >= 3)   DbpString("AcquireEncryptedNonces finished");\r
 \r
-       if (field_off) {\r
-               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-               LEDsoff();\r
-       }\r
 }\r
 \r
 \r
@@ -978,13 +987,14 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat
        memcpy(buf+16, &target_ks[1], 4);\r
        memcpy(buf+20, &authentication_timeout, 4);\r
 \r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
+       if (MF_DBGLEVEL >= 3)   DbpString("NESTED FINISHED");\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK, isOK, 0, targetBlockNo + (targetKeyType * 0x100), buf, sizeof(buf));\r
        LED_B_OFF();\r
 \r
-       if (MF_DBGLEVEL >= 3)   DbpString("NESTED FINISHED");\r
-\r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
@@ -1352,13 +1362,14 @@ void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
                break;\r
        }\r
 \r
+       // reset fpga\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        // send USB response\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,NULL,0);\r
        LED_B_OFF();\r
 \r
-       // reset fpga\r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 \r
        return;\r
@@ -1490,14 +1501,15 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                break;\r
        }\r
 \r
+       if ((workFlags & 0x10) || (!isOK)) {\r
+               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+       }\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,uid,4);\r
        LED_B_OFF();\r
 \r
-       if ((workFlags & 0x10) || (!isOK)) {\r
-               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-               LEDsoff();\r
-       }\r
+       LEDsoff();\r
 }\r
 \r
 \r
@@ -1574,6 +1586,10 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                break;\r
        }\r
 \r
+       if ((workFlags & 0x10) || (!isOK)) {\r
+               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+       }\r
+\r
        LED_B_ON();\r
        if (workFlags & 0x20) {\r
                if (isOK)\r
@@ -1583,10 +1599,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                cmd_send(CMD_ACK,isOK,0,0,data,18);\r
        LED_B_OFF();\r
 \r
-       if ((workFlags & 0x10) || (!isOK)) {\r
-               FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-               LEDsoff();\r
-       }\r
+       LEDsoff();\r
 }\r
 \r
 void MifareCIdent(){\r
@@ -1622,11 +1635,12 @@ void MifareCIdent(){
        // From iceman1001: removed the if,  since some magic tags misbehavies and send an answer to it.\r
        mifare_classic_halt(NULL, 0);\r
 \r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,0,0);\r
        LED_B_OFF();\r
 \r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
@@ -1657,7 +1671,8 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){
        }\r
 \r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 1 FINISHED");\r
-       cmd_send(CMD_ACK,1,cuid,0,dataout, sizeof(dataout));\r
+\r
+       cmd_send(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout));\r
 }\r
 \r
 void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain){\r
@@ -1671,16 +1686,17 @@ void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain){
 \r
        isOK = mifare_desfire_des_auth2(cuid, key, dataout);\r
 \r
-       ifisOK) {\r
+       if (isOK) {\r
                if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication part2: Failed");\r
                OnError(4);\r
                return;\r
        }\r
 \r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+\r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 2 FINISHED");\r
 \r
        cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));\r
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
 \r
Impressum, Datenschutz