]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifarecmd.c
FIX; the "L" optional parameter for swapping endianess on used authentication key...
[proxmark3-svn] / armsrc / mifarecmd.c
index 45d034380f78defa1331c2d6e9d3564ed1ef74bd..03e15b3b52e9ce8d29bd38bb33c87ad598b9d011 100644 (file)
@@ -249,17 +249,26 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 // datain = KEY bytes\r
 void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)\r
 {\r
+       // free eventually allocated BigBuf memory\r
+       BigBuf_free();\r
+       // clear trace\r
+       clear_trace();\r
+\r
        // params\r
        uint8_t blockNo = arg0;\r
        uint16_t blocks = arg1;\r
        bool useKey = (arg2 == 1); //UL_C\r
        bool usePwd = (arg2 == 2); //UL_EV1/NTAG\r
        uint32_t countblocks = 0;\r
-       uint8_t *dataout = BigBuf_get_addr();\r
+       uint8_t *dataout = BigBuf_malloc(CARD_MEMORY_SIZE);\r
+       if (dataout == NULL){\r
+               Dbprintf("out of memory");\r
+               OnError(1);\r
+               return;\r
+       }\r
 \r
        LEDsoff();\r
        LED_A_ON(); \r
-       clear_trace();\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
        int len = iso14443a_select_card(NULL, NULL, NULL);\r
@@ -293,7 +302,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
        }\r
        \r
        for (int i = 0; i < blocks; i++){\r
-               if ((i*4) + 4 > BigBuf_get_traceLen()) {\r
+               if ((i*4) + 4 > CARD_MEMORY_SIZE) {\r
                        Dbprintf("Data exceeds buffer!!");\r
                        break;\r
                }\r
@@ -440,12 +449,20 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t *datain)
        LEDsoff();\r
 }\r
 \r
-void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)\r
+// Arg0   : Block to write to.\r
+// Arg1   : 0 = use no authentication.\r
+//          1 = use 0x1A authentication.\r
+//          2 = use 0x1B authentication.\r
+// datain : 4 first bytes is data to be written.\r
+//        : 4/16 next bytes is authentication key.\r
+void MifareUWriteBlock_Special(uint8_t arg0, uint8_t arg1, uint8_t *datain)\r
 {\r
        uint8_t blockNo = arg0;\r
+       bool useKey = (arg1 == 1); //UL_C\r
+       bool usePwd = (arg1 == 2); //UL_EV1/NTAG\r
        byte_t blockdata[4] = {0x00};\r
        \r
-       memcpy(blockdata, datain,4);\r
+       memcpy(blockdata, datain, 4);\r
        \r
        LEDsoff();\r
        LED_A_ON();\r
@@ -458,6 +475,28 @@ void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)
                return;\r
        };\r
 \r
+       // UL-C authentication\r
+       if ( useKey ) {\r
+               uint8_t key[16] = {0x00};       \r
+               memcpy(key, datain+4, sizeof(key) );\r
+\r
+               if ( !mifare_ultra_auth(key) ) {\r
+                       OnError(1);\r
+                       return;                 \r
+               }\r
+       }\r
+       \r
+       // UL-EV1 / NTAG authentication\r
+       if (usePwd) { \r
+               uint8_t pwd[4] = {0x00};\r
+               memcpy(pwd, datain+4, 4);\r
+               uint8_t pack[4] = {0,0,0,0};\r
+               if (!mifare_ul_ev1_auth(pwd, pack)) {\r
+                       OnError(1);\r
+                       return;                 \r
+               }\r
+       }\r
+       \r
        if(mifare_ultra_special_writeblock(blockNo, blockdata)) {\r
                if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");\r
                OnError(0);\r
Impressum, Datenschutz