]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: rename the HF MFU * commands.
authoriceman1001 <iceman@iuse.se>
Tue, 6 Jan 2015 16:43:31 +0000 (17:43 +0100)
committericeman1001 <iceman@iuse.se>
Tue, 6 Jan 2015 16:43:31 +0000 (17:43 +0100)
ADD: added a HF MFU INFO  commmand, where you can see some tag info. Used to be in the readcard command.
FIX: minor code clean up for ultralight & desfire commands in armsrc/mifarecmd.c, armsrc/mifaredesfire.c, armsrc/mifareutil.c
CHG: Lowered the default MF_DBGLEVEL, it set to MF_DBG_ERROR.
CHG: lowered a testing value for timeout in cmdhf14a.c

armsrc/mifarecmd.c
armsrc/mifaredesfire.c
armsrc/mifareutil.c
client/cmdhf14a.c
client/cmdhfmf.c
client/cmdhfmfu.c
client/cmdhfmfu.h

index fc480a38dc3289acbd892327d4b73a7405431b1e..d2497977df350e48940fb6de07ec1b823cebe19b 100644 (file)
@@ -90,8 +90,8 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 void MifareUC_Auth1(uint8_t arg0, uint8_t *datain){\r
        // variables\r
        byte_t isOK = 0;\r
-       byte_t dataoutbuf[16];\r
-       uint8_t uid[10];\r
+       byte_t dataoutbuf[16] = {0x00};\r
+       uint8_t uid[10] = {0x00};\r
        uint32_t cuid;\r
     \r
        // clear trace\r
@@ -116,18 +116,15 @@ void MifareUC_Auth1(uint8_t arg0, uint8_t *datain){
     \r
        LED_B_ON();\r
     cmd_send(CMD_ACK,isOK,cuid,0,dataoutbuf,11);\r
-       LED_B_OFF();\r
          \r
-       // Thats it...\r
        LEDsoff();\r
 }\r
 void MifareUC_Auth2(uint32_t arg0, uint8_t *datain){\r
-       // params\r
+\r
        uint32_t cuid = arg0;\r
-       uint8_t key[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
-       // variables\r
+       uint8_t key[16] = {0x00};\r
        byte_t isOK = 0;\r
-       byte_t dataoutbuf[16];\r
+       byte_t dataoutbuf[16] = {0x00};\r
     \r
        memcpy(key, datain, 16);\r
     \r
@@ -138,11 +135,11 @@ void MifareUC_Auth2(uint32_t arg0, uint8_t *datain){
        if(mifare_ultra_auth2(cuid, key, dataoutbuf)){\r
            if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part2: Fail...");    \r
        }\r
-       isOK=1;\r
+       isOK = 1;\r
        if (MF_DBGLEVEL >= 2)   DbpString("AUTH 2 FINISHED");\r
     \r
        LED_B_ON();\r
-        cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,11);\r
+       cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,11);\r
        LED_B_OFF();\r
     \r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
@@ -156,8 +153,8 @@ void MifareUReadBlock(uint8_t arg0,uint8_t *datain)
        \r
        // variables\r
        byte_t isOK = 0;\r
-       byte_t dataoutbuf[16];\r
-       uint8_t uid[10];\r
+       byte_t dataoutbuf[16] = {0x00};\r
+       uint8_t uid[10] = {0x00};\r
        uint32_t cuid;\r
     \r
        // clear trace\r
@@ -269,57 +266,62 @@ void MifareUReadCard(uint8_t arg0, int arg1, uint8_t *datain)
 {\r
        // params\r
        uint8_t sectorNo = arg0;\r
-       int Pages=arg1;\r
-       int count_Pages=0;\r
-       // variables\r
-       byte_t isOK = 0;\r
-       byte_t dataoutbuf[176];\r
-       uint8_t uid[10];\r
+       int Pages = arg1;\r
+       int count_Pages = 0;\r
+       byte_t dataoutbuf[176] = {0x00};;\r
+       uint8_t uid[10] = {0x00};\r
        uint32_t cuid;\r
 \r
-       // clear trace\r
        iso14a_clear_trace();\r
-\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
        LED_A_ON();\r
        LED_B_OFF();\r
        LED_C_OFF();\r
-       Dbprintf("Pages %d",Pages);\r
-        while (true) {\r
-                if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
-                if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
-                        break;\r
-                };\r
-               for(int sec=0;sec<Pages;sec++){\r
-                    if(mifare_ultra_readblock(cuid, sectorNo * 4 + sec, dataoutbuf + 4 * sec)) {\r
-                    if (MF_DBGLEVEL >= 1)   Dbprintf("Read block %d error",sec);\r
-                        break;\r
-                    }else{\r
-                     count_Pages++;\r
-                    };\r
-                }\r
-                if(mifare_ultra_halt(cuid)) {\r
-                if (MF_DBGLEVEL >= 1)   Dbprintf("Halt error");\r
-                        break;\r
-                };\r
-\r
-                isOK = 1;\r
-                break;\r
-        }\r
-       Dbprintf("Pages read %d",count_Pages);\r
-       if (MF_DBGLEVEL >= 2) DbpString("READ CARD FINISHED");\r
-\r
-        LED_B_ON();\r
-       if (Pages==16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,64);\r
-       if (Pages==44 && count_Pages==16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,64);\r
-       if (Pages==44 && count_Pages>16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,176);\r
-        LED_B_OFF();\r
+       \r
+       if (MF_DBGLEVEL >= MF_DBG_ALL) \r
+               Dbprintf("Pages %d",Pages);\r
+       \r
+       if (!iso14443a_select_card(uid, NULL, &cuid)) {\r
+               if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+                       Dbprintf("Can't select card");\r
+               OnError();\r
+               return;\r
+       }\r
+       \r
+       for (int i = 0; i < Pages; i++){\r
+               if (mifare_ultra_readblock(cuid, sectorNo * 4 + i, dataoutbuf + 4 * i)) {\r
+                       if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+                               Dbprintf("Read block %d error",i);\r
+                       OnError();\r
+                       return;\r
+               } else {\r
+                       count_Pages++;\r
+               }\r
+       }\r
+               \r
+       if (mifare_ultra_halt(cuid)) {\r
+               if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+                       Dbprintf("Halt error");\r
+               OnError();\r
+               return;\r
+       }\r
+       \r
+       if (MF_DBGLEVEL >= MF_DBG_ALL) {\r
+               Dbprintf("Pages read %d",count_Pages);\r
+               DbpString("Read card finished");\r
+       }\r
 \r
-       // Thats it...\r
+       int len = 16*4; //64 bytes\r
+       \r
+       // Read a UL-C\r
+       if (Pages == 44 && count_Pages > 16) \r
+               len = 176;\r
+\r
+       cmd_send(CMD_ACK, 1, 0, 0, dataoutbuf, len);\r
+       \r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
-\r
 }\r
 \r
 \r
@@ -397,76 +399,65 @@ void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
 \r
 void MifareUWriteBlock(uint8_t arg0, uint8_t *datain)\r
 {\r
-        // params\r
-        uint8_t blockNo = arg0;\r
-        byte_t blockdata[16];\r
+       // params\r
+       uint8_t blockNo = arg0;\r
+       byte_t blockdata[16] = {0x00};\r
 \r
-        memset(blockdata,'\0',16);\r
-        memcpy(blockdata, datain,16);\r
-        \r
-        // variables\r
-        byte_t isOK = 0;\r
-        uint8_t uid[10];\r
-        uint32_t cuid;\r
+       memcpy(blockdata, datain, 16);\r
+       \r
+       // variables\r
+       byte_t isOK = 0;\r
+       uint8_t uid[10] = {0x00};\r
+       uint32_t cuid;\r
 \r
-        // clear trace\r
-        iso14a_clear_trace();\r
+       iso14a_clear_trace();\r
+       iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
-               iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
+       LED_A_ON();\r
+       LED_B_OFF();\r
+       LED_C_OFF();\r
 \r
-        LED_A_ON();\r
-        LED_B_OFF();\r
-        LED_C_OFF();\r
-\r
-        while (true) {\r
-                if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
-                        if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
-                        break;\r
-                };\r
-\r
-                if(mifare_ultra_writeblock(cuid, blockNo, blockdata)) {\r
-                        if (MF_DBGLEVEL >= 1)   Dbprintf("Write block error");\r
-                        break;\r
-                };\r
-\r
-                if(mifare_ultra_halt(cuid)) {\r
-                        if (MF_DBGLEVEL >= 1)   Dbprintf("Halt error");\r
-                        break;\r
-                };\r
-                \r
-                isOK = 1;\r
-                break;\r
-        }\r
-        \r
-        if (MF_DBGLEVEL >= 2)   DbpString("WRITE BLOCK FINISHED");\r
+       while (true) {\r
+               if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
+                               if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
+                               break;\r
+               };\r
 \r
-        LED_B_ON();\r
-               cmd_send(CMD_ACK,isOK,0,0,0,0);\r
-        LED_B_OFF();\r
+               if(mifare_ultra_writeblock(cuid, blockNo, blockdata)) {\r
+                               if (MF_DBGLEVEL >= 1)   Dbprintf("Write block error");\r
+                               break;\r
+               };\r
 \r
+               if(mifare_ultra_halt(cuid)) {\r
+                               if (MF_DBGLEVEL >= 1)   Dbprintf("Halt error");\r
+                               break;\r
+               };\r
+               \r
+               isOK = 1;\r
+               break;\r
+       }\r
+        \r
+       if (MF_DBGLEVEL >= 2)   DbpString("WRITE BLOCK FINISHED");\r
 \r
-        // Thats it...\r
-        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-        LEDsoff();\r
-//  iso14a_set_tracing(TRUE);\r
+       cmd_send(CMD_ACK,isOK,0,0,0,0);\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+       LEDsoff();\r
 }\r
 \r
 void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)\r
 {\r
        // params\r
        uint8_t blockNo = arg0;\r
-       byte_t blockdata[4];\r
+       byte_t blockdata[4] = {0x00};\r
        \r
        memcpy(blockdata, datain,4);\r
 \r
        // variables\r
        byte_t isOK = 0;\r
-       uint8_t uid[10];\r
+       uint8_t uid[10] = {0x00};\r
        uint32_t cuid;\r
 \r
-       // clear trace\r
        iso14a_clear_trace();\r
-\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
        LED_A_ON();\r
@@ -495,11 +486,7 @@ void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)
 \r
        if (MF_DBGLEVEL >= 2)   DbpString("WRITE BLOCK FINISHED");\r
 \r
-       LED_B_ON();\r
        cmd_send(CMD_ACK,isOK,0,0,0,0);\r
-       LED_B_OFF();\r
-\r
-       // Thats it...\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }\r
@@ -1152,71 +1139,54 @@ void MifareCIdent(){
 void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){\r
        // variables\r
        byte_t isOK = 0;\r
-       byte_t dataoutbuf[16];\r
-       uint8_t uid[10];\r
+       byte_t dataout[11] = {0x00};\r
+       uint8_t uid[10] = {0x00};\r
        uint32_t cuid;\r
     \r
-       // clear trace\r
        iso14a_clear_trace();\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
-    \r
-       LED_A_ON();\r
-       LED_B_OFF();\r
-       LED_C_OFF();\r
-       \r
 \r
        if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
           if (MF_DBGLEVEL >= 1)        Dbprintf("Can't select card, something went wrong before auth");\r
        };\r
 \r
-       if(mifare_desfire_des_auth1(cuid, dataoutbuf)){\r
-         if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part1: Fail.");    \r
+       if(mifare_desfire_des_auth1(cuid, dataout)){\r
+         if (MF_DBGLEVEL >= 1) \r
+               Dbprintf("Authentication part1: Fail."); \r
        }\r
 \r
-       isOK=1;\r
-       if (MF_DBGLEVEL >= 2)   DbpString("AUTH 1 FINISHED");\r
+       isOK = 1;\r
+       if (MF_DBGLEVEL >= 2) DbpString("AUTH 1 FINISHED");\r
     \r
-       LED_B_ON();\r
-        cmd_send(CMD_ACK,isOK,cuid,0,dataoutbuf,11);\r
-       LED_B_OFF();\r
-         \r
-       // Thats it...\r
-       //FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
-       LEDsoff();\r
+    cmd_send(CMD_ACK,isOK,cuid,0,dataout, sizeof(dataout));\r
 }\r
 \r
 void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain){\r
-       // params\r
+\r
        uint32_t cuid = arg0;\r
-       uint8_t key[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
-       // variables\r
+       uint8_t key[16] = {0x00};\r
        byte_t isOK = 0;\r
-       byte_t dataoutbuf[16];\r
+       byte_t dataout[12] = {0x00};\r
     \r
        memcpy(key, datain, 16);\r
-       // clear trace\r
-       //iso14a_clear_trace();\r
-       //iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
-    \r
+   \r
        LED_A_ON();\r
        LED_B_OFF();\r
        LED_C_OFF();\r
-\r
-//     Dbprintf("Sending %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",\r
-//              key[0],key[1],key[2],key[3],key[4],key[5],key[6],key[7],key[8],\r
-//              key[9],key[10],key[11],key[12],key[13],key[14],key[15]);\r
        \r
-       if(mifare_desfire_des_auth2(cuid, key, dataoutbuf)){\r
-           if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part2: Fail...");    \r
+       isOK = mifare_desfire_des_auth2(cuid, key, dataout);\r
+       \r
+       if(isOK){\r
+               if (MF_DBGLEVEL >= 2) \r
+                       DbpString("AUTH 2 FINISHED");\r
+               cmd_send(CMD_ACK,isOK,0,0,dataout,sizeof(dataout));\r
        }\r
-       isOK=1;\r
-       if (MF_DBGLEVEL >= 2)   DbpString("AUTH 2 FINISHED");\r
-    \r
-       LED_B_ON();\r
-        cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,12);\r
-       LED_B_OFF();\r
-    \r
-    // Thats it...\r
+       else {\r
+           if (MF_DBGLEVEL >= 2) \r
+                       Dbprintf("Authentication part2: Failed");  \r
+               OnError();\r
+       }\r
+\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 }
\ No newline at end of file
index 155538cb45a9a0612811d89158face468a59a293..e064c33aa45068e5924075d4b1cbcddcfec9988a 100644 (file)
@@ -18,13 +18,9 @@ static  uint8_t deselect_cmd[] = {0xc2,0xe0,0xb4};
 //static uint8_t __res[MAX_FRAME_SIZE];
 
 bool InitDesfireCard(){
-
-       // Make sure it is off.
-//     FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-//     SpinDelay(300);
        
-       byte_t cardbuf[USB_CMD_DATA_SIZE];
-       memset(cardbuf,0,sizeof(cardbuf));
+       byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
+
        iso14a_card_select_t *card = (iso14a_card_select_t*)cardbuf;
        
        iso14a_set_tracing(TRUE);
@@ -99,13 +95,9 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain){
 void MifareDesfireGetInformation(){
                
        int len = 0;
-       uint8_t resp[USB_CMD_DATA_SIZE];
-       uint8_t dataout[USB_CMD_DATA_SIZE];
-       byte_t cardbuf[USB_CMD_DATA_SIZE];
-       
-       memset(resp,0,sizeof(resp));
-       memset(dataout,0, sizeof(dataout));
-       memset(cardbuf,0,sizeof(cardbuf));
+       uint8_t resp[USB_CMD_DATA_SIZE] = {0x00};
+       uint8_t dataout[USB_CMD_DATA_SIZE] = {0x00};
+       byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
        
        /*
                1 = PCB                                 1
@@ -191,7 +183,6 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
        //uint8_t new_key_data8[8]  = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
        //uint8_t new_key_data16[16]  = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
 
-       //uint8_t* bigbuffer = get_bigbufptr_recvrespbuf();
        uint8_t resp[256] = {0x00};
        uint8_t IV[16] = {0x00};
 
@@ -219,7 +210,7 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
         case 1:{
             if (algo == 1) {
 
-            uint8_t keybytes[8];
+            uint8_t keybytes[8] = {0x00};
             uint8_t RndA[8] = {0x00};
             uint8_t RndB[8] = {0x00};
             
@@ -268,7 +259,6 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
             
             for (int x = 0; x < 8; x++) {
                 decRndB[x] = decRndB[x] ^ encRndA[x];
-
             }
             
             des_dec(&encRndB, &decRndB, key->data);
@@ -366,14 +356,14 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno,  uint8_t *datain
                case 3:{
                
                        //defaultkey
-                       uint8_t keybytes[16];
+                       uint8_t keybytes[16] = {0x00};
                        if (datain[1] == 0xff){
                                memcpy(keybytes,PICC_MASTER_KEY16,16); 
                        } else{
                                memcpy(keybytes, datain+1, datalen);
                        }
                        
-                       struct desfire_key defaultkey = {0};
+                       struct desfire_key defaultkey = {0x00};
                        desfirekey_t key = &defaultkey;
                        Desfire_aes_key_new( keybytes, key);
                
index 84f77a351c70c8124c865e7502562cf95dfedfcd..d51da21ccb9a08f57d9ebb0d01c821df497611df 100644 (file)
@@ -19,7 +19,7 @@
 #include "crapto1.h"\r
 #include "mifareutil.h"\r
 \r
-int MF_DBGLEVEL = MF_DBG_ALL;\r
+int MF_DBGLEVEL = MF_DBG_ERROR;\r
 \r
 // memory management\r
 uint8_t* get_bigbufptr_recvrespbuf(void) {\r
@@ -511,7 +511,7 @@ int mifare_ultra_halt(uint32_t uid)
                if (MF_DBGLEVEL >= 1)   Dbprintf("halt error. response len: %x", len);
                return 1;
        }
-    
+\r
        return 0;
 }
 
@@ -638,7 +638,7 @@ int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cm
        int len = ReaderReceive(answer, answer_parity);\r
        if(!len) {\r
                if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");\r
-                       return 2;\r
+                       return 1;\r
     }\r
        return len;\r
 }\r
@@ -654,7 +654,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c
        int len = ReaderReceive(answer, answer_parity);\r
        if(!len){\r
         if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");\r
-                       return 2;\r
+                       return 1;\r
     }\r
        return len;\r
 }\r
@@ -662,7 +662,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c
 int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData){\r
        // variables\r
        int len;\r
-       //           load key, keynumber\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
@@ -688,7 +688,8 @@ int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData){
 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
+       uint8_t data[17] = {0x00};\r
+       data[0] = 0xAF;\r
        memcpy(data+1,key,16);\r
        \r
        uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
@@ -697,7 +698,7 @@ int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData){
        // 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 ((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
index 4f0ffde61e3d0af175a53b5e639145a0573919a9..12fb10ed455ed59aabc9da606055b5b11397ca12 100644 (file)
@@ -649,7 +649,7 @@ static void waitCmd(uint8_t iSelect)
     UsbCommand resp;
     char *hexout;
 
-    if (WaitForResponseTimeout(CMD_ACK,&resp,10000)) {
+    if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
         recv = resp.d.asBytes;
         uint8_t iLen = iSelect ? resp.arg[1] : resp.arg[0];
         PrintAndLog("received %i octets",iLen);
index 49928c9aef2d4ddf508fd82851a9b511bec70743..6939f653cc7469bd529f70926ecbcfb801eba9c1 100644 (file)
@@ -1983,9 +1983,6 @@ static command_t CommandTable[] =
   {"help",             CmdHelp,                                1, "This help"},\r
   {"dbg",              CmdHF14AMfDbg,                  0, "Set default debug mode"},\r
   {"rdbl",             CmdHF14AMfRdBl,                 0, "Read MIFARE classic block"},\r
-  //{"urdbl",              CmdHF14AMfURdBl,                 0, "Read MIFARE Ultralight block"},\r
-  //{"urdcard",           CmdHF14AMfURdCard,               0,"Read MIFARE Ultralight Card"},\r
-  //{"uwrbl",          CmdHF14AMfUWrBl,                0,"Write MIFARE Ultralight block"},\r
   {"rdsc",             CmdHF14AMfRdSc,                 0, "Read MIFARE classic sector"},\r
   {"dump",             CmdHF14AMfDump,                 0, "Dump MIFARE classic tag to binary file"},\r
   {"restore",  CmdHF14AMfRestore,              0, "Restore MIFARE classic binary file to BLANK tag"},\r
@@ -2003,9 +2000,9 @@ static command_t CommandTable[] =
   {"ecfill",   CmdHF14AMfECFill,               0, "Fill simulator memory with help of keys from simulator"},\r
   {"ekeyprn",  CmdHF14AMfEKeyPrn,              0, "Print keys from simulator memory"},\r
   {"csetuid",  CmdHF14AMfCSetUID,              0, "Set UID for magic Chinese card"},\r
-  {"csetblk",  CmdHF14AMfCSetBlk,              0, "Write block into magic Chinese card"},\r
-  {"cgetblk",  CmdHF14AMfCGetBlk,              0, "Read block from magic Chinese card"},\r
-  {"cgetsc",   CmdHF14AMfCGetSc,               0, "Read sector from magic Chinese card"},\r
+  {"csetblk",  CmdHF14AMfCSetBlk,              0, "Write block - Magic Chinese card"},\r
+  {"cgetblk",  CmdHF14AMfCGetBlk,              0, "Read block - Magic Chinese card"},\r
+  {"cgetsc",   CmdHF14AMfCGetSc,               0, "Read sector - Magic Chinese card"},\r
   {"cload",            CmdHF14AMfCLoad,                0, "Load dump into magic Chinese card"},\r
   {"csave",            CmdHF14AMfCSave,                0, "Save dump from magic Chinese card into file or emulator"},\r
   {NULL, NULL, 0, NULL}\r
index 52b7ad14c46b46f9e06f3f618cc1cf014380a912..e9a12083ec3a39fa0f666c9a7371ebc976e1b1dc 100644 (file)
@@ -20,6 +20,57 @@ uint8_t key5_ones_data[16] = { 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
 
 static int CmdHelp(const char *Cmd);
 
+int CmdHF14AMfUInfo(const char *Cmd){
+
+    uint8_t datatemp[7] = {0x00};
+    uint8_t isOK  = 0;
+    uint8_t *data = NULL;
+
+    UsbCommand c = {CMD_MIFAREU_READCARD, {0, 4}};
+    SendCommand(&c);
+    UsbCommand resp;
+
+    if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
+        isOK  = resp.arg[0] & 0xff;
+        data  = resp.d.asBytes;
+
+        if (!isOK) {
+                       PrintAndLog("Error reading from tag");
+                       return -1;
+               }
+       } else {
+               PrintAndLog("Command execute timed out");
+               return -1;
+       }
+       
+       // UID
+       memcpy( datatemp, data,3);
+       memcpy( datatemp+3, data+4, 4);
+       PrintAndLog("        UID :%s ", sprint_hex(datatemp, 7));
+       // BBC
+       // CT (cascade tag byte) 0x88 xor SN0 xor SN1 xor SN2 
+       int crc0 = 0x88 ^ data[0] ^ data[1] ^data[2];
+       if ( data[3] == crc0 )
+               PrintAndLog("       BCC0 :%02x - Ok", data[3]);
+       else
+               PrintAndLog("       BCC0 :%02x - crc should be %02x", data[3], crc0);
+               
+       int crc1 = data[4] ^ data[5] ^ data[6] ^data[7];
+       if ( data[8] == crc1 )
+               PrintAndLog("       BCC1 :%02x - Ok", data[8]);
+       else
+               PrintAndLog("       BCC1 :%02x - crc should be %02x", data[8], crc1 );
+       
+       PrintAndLog("   Internal :%s ", sprint_hex(data + 9, 1));
+       
+       memcpy(datatemp, data+10, 2);
+       PrintAndLog("       Lock :%s - %s", sprint_hex(datatemp, 2),printBits( 2, &datatemp) );
+       PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4));
+       PrintAndLog("");
+
+       return 0;
+}
+
 //
 //  Mifare Ultralight Write Single Block
 //
@@ -172,19 +223,18 @@ int CmdHF14AMfURdBl(const char *Cmd){
 int CmdHF14AMfURdCard(const char *Cmd){
     int i;
     uint8_t BlockNo = 0;
-    int pages=16;
-    uint8_t *lockbytes_t=NULL;
-    uint8_t lockbytes[2]={0x00};
-    bool bit[16]={0x00};
-    bool dump=false;
-    uint8_t datatemp[7]= {0x00};
-        
+    int pages = 16;
+    uint8_t *lockbytes_t = NULL;
+    uint8_t lockbytes[2] = {0x00};
+    bool bit[16] = {0x00};
+    bool dump = false;
+    uint8_t datatemp[7] = {0x00};        
     uint8_t isOK  = 0;
     uint8_t * data  = NULL;
     FILE *fout = NULL;
 
     if (strchr(Cmd,'x') != 0){
-        dump=true;
+        dump = true;
         if ((fout = fopen("dump_ultralight_data.bin","wb")) == NULL) { 
             PrintAndLog("Could not create file name dumpdata.bin");
             return 1;  
@@ -201,36 +251,6 @@ int CmdHF14AMfURdCard(const char *Cmd){
         data  = resp.d.asBytes;
         PrintAndLog("isOk:%02x", isOK);
         if (isOK) {
-               
-                       // UID
-                       memcpy( datatemp, data,3);
-                       memcpy( datatemp+3, data+4, 4);
-                       PrintAndLog("        UID :%s ", sprint_hex(datatemp, 7));
-                       // BBC
-                       // CT (cascade tag byte) 0x88 xor SN0 xor SN1 xor SN2 
-                       int crc0 = 0x88 ^ data[0] ^ data[1] ^data[2];
-                       if ( data[3] == crc0 ) {
-                               PrintAndLog("       BCC0 :%02x - Ok", data[3]);
-                       }
-                       else{
-                               PrintAndLog("       BCC0 :%02x - crc should be %02x", data[3], crc0);
-                       }
-                       
-                       int crc1 = data[4] ^ data[5] ^ data[6] ^data[7];
-                       if ( data[8] == crc1 ){
-                               PrintAndLog("       BCC1 :%02x - Ok", data[8]);
-                               }
-                       else{
-                               PrintAndLog("       BCC1 :%02x - crc should be %02x", data[8], crc1 );
-                       }
-                       
-                       PrintAndLog("   Internal :%s ", sprint_hex(data + 9, 1));
-                       
-                       memcpy(datatemp, data+10, 2);
-                       PrintAndLog("       Lock :%s - %s", sprint_hex(datatemp, 2),printBits( 2, &datatemp) );
-                       
-                       PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4));
-                       PrintAndLog("");
                        
             for (i = 0; i < pages; i++) {
                 switch(i){
@@ -320,7 +340,7 @@ int CmdHF14AMfURdCard(const char *Cmd){
             }
                }
     } else {                
-        PrintAndLog("Command1 execute timeout");
+        PrintAndLog("Command execute timeout");
     }
     if (dump) fclose(fout);
     return 0;
@@ -1131,17 +1151,18 @@ int CmdHF14AMfUCWrBl(const char *Cmd){
 //------------------------------------
 static command_t CommandTable[] =
 {
-    {"help",    CmdHelp,                   1,"This help"},
-    {"dbg",     CmdHF14AMfDbg,         0,"Set default debug mode"},
-    {"urdbl",   CmdHF14AMfURdBl,    0,"Read MIFARE Ultralight block"},
-    {"urdcard", CmdHF14AMfURdCard,  0,"Read MIFARE Ultralight Card"},
-    {"udump",   CmdHF14AMfUDump,       0,"Dump MIFARE Ultralight tag to binary file"},
-    {"uwrbl",   CmdHF14AMfUWrBl,       0,"Write MIFARE Ultralight block"},
-    {"ucrdbl",  CmdHF14AMfUCRdBl,   0,"Read MIFARE Ultralight C block"},
-    {"ucrdcard",CmdHF14AMfUCRdCard, 0,"Read MIFARE Ultralight C Card"},
-    {"ucdump",  CmdHF14AMfUCDump,      0,"Dump MIFARE Ultralight C tag to binary file"},
-    {"ucwrbl",  CmdHF14AMfUCWrBl,      0,"Write MIFARE Ultralight C block"},
-    {"auth",    CmdHF14AMfucAuth,      0,"Ultralight C Authentication"},
+    {"help",   CmdHelp,                        1,"This help"},
+    {"dbg",            CmdHF14AMfDbg,          0,"Set default debug mode"},
+       {"info",        CmdHF14AMfUInfo,        0,"Taginfo"},
+    {"rdbl",   CmdHF14AMfURdBl,        0,"Read block - MIFARE Ultralight"},
+    {"rdcard", CmdHF14AMfURdCard,      0,"Read card - MIFARE Ultralight"},
+    {"dump",   CmdHF14AMfUDump,        0,"Dump MIFARE Ultralight tag to binary file"},
+    {"wrbl",   CmdHF14AMfUWrBl,        0,"Write block - MIFARE Ultralight"},
+    {"crdbl",  CmdHF14AMfUCRdBl,       0,"Read block - MIFARE Ultralight C"},
+    {"crdcard",        CmdHF14AMfUCRdCard,     0,"Read card - MIFARE Ultralight C"},
+    {"cdump",  CmdHF14AMfUCDump,       0,"Dump MIFARE Ultralight C tag to binary file"},
+    {"cwrbl",  CmdHF14AMfUCWrBl,       0,"Write MIFARE Ultralight C block"},
+    {"cauth",  CmdHF14AMfucAuth,       0,"try a Ultralight C Authentication"},
     {NULL, NULL, 0, NULL}
 };
 
index 20f25d1db950743f703fc5f2d6e7706841eed3af..5389f4ab1f80614497ac74a992717f756671b9f8 100644 (file)
@@ -1,5 +1,6 @@
 #include "cmdhfmf.h"
 
+
 //standard ultralight
 int CmdHF14AMfUWrBl(const char *Cmd);
 int CmdHF14AMfURdBl(const char *Cmd);
@@ -14,3 +15,4 @@ void rol (uint8_t *data, const size_t len);
 
 //general stuff
 int CmdHFMFUltra(const char *Cmd);
+int CmdHF14AMfUInfo(const char *Cmd)
Impressum, Datenschutz