]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: "hf legic dump" now automatically detects tagtype and dumps accordingly.
authoriceman1001 <iceman@iuse.se>
Wed, 5 Oct 2016 20:58:06 +0000 (22:58 +0200)
committericeman1001 <iceman@iuse.se>
Wed, 5 Oct 2016 20:58:06 +0000 (22:58 +0200)
CHG:  still #define codestyle  should it be with or without semicolons?

armsrc/legicrf.c
client/cmdhflegic.c
client/cmdhflegic.h

index 8042fc8dca23a30de0915418e4354fae0291b474..766bd443ce139e7cc2bc4cf1957c3ee2ee17365f 100644 (file)
@@ -1,5 +1,6 @@
 //-----------------------------------------------------------------------------
 // (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
+//     2016 Iceman
 //
 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
 // at your option, any later version. See the LICENSE.txt file for the text of
@@ -85,7 +86,7 @@ static void setup_timer(void) {
 #define FUZZ_EQUAL(value, target, fuzz) ((value) > ((target)-(fuzz)) && (value) < ((target)+(fuzz)))
 
 #ifndef SHORT_COIL
-# define SHORT_COIL    LOW(GPIO_SSC_DOUT);
+# define SHORT_COIL     LOW(GPIO_SSC_DOUT);
 #endif
 #ifndef OPEN_COIL
 # define OPEN_COIL     HIGH(GPIO_SSC_DOUT);
@@ -102,7 +103,7 @@ static void setup_timer(void) {
                WaitTicks( (RWD_TIME_PAUSE) ); \
                OPEN_COIL; \
                WaitTicks((x)); \
-       } while (0) 
+       } while (0); 
 #endif
 
 // ToDo: define a meaningful maximum size for auth_table. The bigger this is, the lower will be the available memory for traces. 
@@ -210,9 +211,9 @@ void frame_sendAsReader(uint32_t data, uint8_t bits){
                                
        for (; mask < BITMASK(bits); mask <<= 1) {      
                if (send & mask)
-                       COIL_PULSE(RWD_TIME_1);
+                       COIL_PULSE(RWD_TIME_1)
                else
-                       COIL_PULSE(RWD_TIME_0);
+                       COIL_PULSE(RWD_TIME_0)
        }
 
        // Final pause to mark the end of the frame
index b2c6a3dfebf83619b8139da3859fceaa48d6f3e9..b9a51b637cc608b4360bc2f7169a5c656b3b2e58 100644 (file)
@@ -142,7 +142,7 @@ int CmdLegicInfo(const char *Cmd) {
        int dcf = 0;
        int bIsSegmented = 0;
 
-       CmdLegicRdmem("0 21 55");
+       CmdLegicRdmem("0 22 55");
        
        // copy data from device
        GetEMLFromBigBuf(data, sizeof(data), 0);
@@ -864,41 +864,59 @@ int CmdLegicCalcCrc8(const char *Cmd){
        if (data) free(data);
        return 0;
 } 
-int HFLegicReader(const char *Cmd, bool verbose) {
 
-       char cmdp = param_getchar(Cmd, 0);
-       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_info();
-       
+int legic_print_type(uint32_t tagtype, uint8_t spaces){
+       char spc[11] = "          ";
+       spc[10]=0x00;
+       char *spacer = spc + (10-spaces);
+
+       if ( tagtype == 22 )    
+               PrintAndLog("%sTYPE : MIM%d card (outdated)", spacer, tagtype);
+       else if ( tagtype == 256 )
+               PrintAndLog("%sTYPE : MIM%d card (234 bytes)", spacer, tagtype);
+       else if ( tagtype == 1024 )
+               PrintAndLog("%sTYPE : MIM%d card (1002 bytes)", spacer, tagtype);
+       else
+               PrintAndLog("%sTYPE : Unknown %06x", spacer, tagtype);
+       return 0;
+}
+int legic_get_type(legic_card_select_t *card){
+
+       if ( card == NULL ) return 1;
+
        UsbCommand c = {CMD_LEGIC_INFO, {0,0,0}};
        clearCommandBuffer();
     SendCommand(&c);
        UsbCommand resp;
-       if (!WaitForResponseTimeout(CMD_ACK, &resp, 500)) {
-               if ( verbose ) PrintAndLog("command execution time out");
-               return 1;
-       }
+       if (!WaitForResponseTimeout(CMD_ACK, &resp, 500))
+               return 2;
        
        uint8_t isOK = resp.arg[0] & 0xFF;
-       if ( !isOK ) {
-               if ( verbose ) PrintAndLog("legic card select failed");
-               return 1;
-       }
+       if ( !isOK ) 
+               return 3;
+       
+       memcpy(card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t));
+       return 0;
+}
+
+int HFLegicReader(const char *Cmd, bool verbose) {
+
+       char cmdp = param_getchar(Cmd, 0);
+       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_reader();
        
        legic_card_select_t card;
-       memcpy(&card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t));
-
-       PrintAndLog("  UID : %s", sprint_hex(card.uid, sizeof(card.uid)));
-       switch(card.cardsize) {
-               case 22:
-               case 256: 
-               case 1024:
-                       PrintAndLog(" TYPE : MIM%d card (%d bytes)", card.cardsize, card.cardsize); break;                              
-               default: {
-                       PrintAndLog("Unknown card format: %d", card.cardsize); 
+       switch(legic_get_type(&card)){
+               case 1: 
+                       if ( verbose ) PrintAndLog("command execution time out"); 
                        return 1;
-               }
+               case 2: 
+               case 3: 
+                       if ( verbose ) PrintAndLog("legic card select failed");
+                       return 2;
+               default: break;
        }
+       PrintAndLog(" UID : %s", sprint_hex(card.uid, sizeof(card.uid)));
+       legic_print_type(card.cardsize, 0);
        return 0;
 }
 int CmdLegicReader(const char *Cmd){
@@ -912,9 +930,8 @@ int CmdLegicDump(const char *Cmd){
        char *fnameptr = filename;
        size_t fileNlen = 0;
        bool errors = false;
-       uint16_t dumplen = 0x100;
-       
-       char cmdp = param_getchar(Cmd, 0);
+       uint16_t dumplen;       
+       uint8_t cmdp = 0;
        
        while(param_getchar(Cmd, cmdp) != 0x00)
        {
@@ -942,9 +959,16 @@ int CmdLegicDump(const char *Cmd){
        if(errors) return usage_legic_dump();
        
        // tagtype
-       //uint32_t tagtype = GetHF14AMfU_Type();
-       //if (tagtype == -1) return -1;
+       legic_card_select_t card;
+       if (legic_get_type(&card)) {
+               PrintAndLog("Failed to identify tagtype");
+               return -1;
+       }
+       dumplen = card.cardsize;
        
+       legic_print_type(dumplen, 0);   
+       PrintAndLog("Reading tag memory...");
+
        UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}};
        clearCommandBuffer();
        SendCommand(&c);
index a8fbd3171796d43d7bf464f57388bc39062c6fc4..fecde8e321bc58579f73840fa6bef528e107e38b 100644 (file)
@@ -24,8 +24,8 @@
 #include "legic.h" // legic_card_select_t struct
 
 int CmdHFLegic(const char *Cmd);
-int CmdLegicInfo(const char *Cmd);
 
+int CmdLegicInfo(const char *Cmd);
 int CmdLegicRdmem(const char *Cmd);
 int CmdLegicLoad(const char *Cmd);
 int CmdLegicSave(const char *Cmd);
@@ -33,14 +33,13 @@ int CmdLegicRfSim(const char *Cmd);
 int CmdLegicRfWrite(const char *Cmd);
 int CmdLegicRfRawWrite(const char *Cmd);
 int CmdLegicRfFill(const char *Cmd);
-
 int CmdLegicCalcCrc8(const char *Cmd);
-
-int CmdLegicReader(const char *Cmd);
-int HFLegicReader(const char *Cmd, bool verbose);
-
 int CmdLegicDump(const char *Cmd);
+int CmdLegicReader(const char *Cmd);
 
+int HFLegicReader(const char *Cmd, bool verbose);
+int legic_print_type(uint32_t tagtype, uint8_t spaces);
+int legic_get_type(legic_card_select_t *card);
 
 int usage_legic_calccrc8(void);
 int usage_legic_load(void);
Impressum, Datenschutz