]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: undeclared var on deviceside,
authoriceman1001 <iceman@iuse.se>
Wed, 5 Oct 2016 20:07:32 +0000 (22:07 +0200)
committericeman1001 <iceman@iuse.se>
Wed, 5 Oct 2016 20:07:32 +0000 (22:07 +0200)
FIX:  "hf legic dump" is almost there.

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

index 64a75fce08975f93f761efc6ca989d4d15b9e4a7..9944ac462dda40b1bb144944e21ff3e17a46c7d7 100644 (file)
@@ -188,7 +188,7 @@ void frame_send_tag(uint16_t response, uint8_t bits) {
        WaitTicks( TAG_FRAME_WAIT );
 
        for (; mask < BITMASK(bits); mask <<= 1) {      
-               if (send & mask)
+               if (response & mask)
                        OPEN_COIL;
                else
                        SHORT_COIL;
@@ -431,7 +431,7 @@ int legic_write_byte(uint8_t byte, uint16_t addr, uint8_t addr_sz) {
                                   
     uint32_t cmd_sz = addr_sz+1+8+4;          //crc+data+cmd
 
-    legic_prng_forward(2); /* we wait anyways */
+    legic_prng_forward(2);
        
        WaitTicks(330);
        
@@ -444,7 +444,7 @@ int legic_write_byte(uint8_t byte, uint16_t addr, uint8_t addr_sz) {
     int t, old_level = 0, edges = 0;
     int next_bit_at = 0;
 
-       WaitUS(TAG_FRAME_WAIT);
+       WaitTicks(TAG_FRAME_WAIT);
 
     for( t = 0; t < 80; ++t) {
         edges = 0;
index 72c12a405368ba41f79d8c866a34efe124d3107b..b2c6a3dfebf83619b8139da3859fceaa48d6f3e9 100644 (file)
@@ -39,9 +39,9 @@ int usage_legic_load(void){
        PrintAndLog("      hf legic load filename");
        return 0;
 }
-int usage_legic_read(void){    
+int usage_legic_rdmem(void){   
        PrintAndLog("Read data from a legic tag.");
-       PrintAndLog("Usage:  hf legic read [h] <offset> <length> <IV>");
+       PrintAndLog("Usage:  hf legic rdmem [h] <offset> <length> <IV>");
        PrintAndLog("Options:");
        PrintAndLog("  h             : this help");
        PrintAndLog("  <offset>      : offset in data array to start download from (hex)");
@@ -49,9 +49,9 @@ int usage_legic_read(void){
        PrintAndLog("  <IV>          : (optional) Initialization vector to use (hex, odd and 7bits)");
        PrintAndLog("");
        PrintAndLog("Samples:");
-       PrintAndLog("      hf legic read 0 21        - reads from byte[0] 21 bytes(system header)");
-       PrintAndLog("      hf legic read 0 4 55      - reads from byte[0] 4 bytes with IV 0x55");
-       PrintAndLog("      hf legic read 0 100 55    - reads 256bytes with IV 0x55");
+       PrintAndLog("      hf legic rdmem 0 21        - reads from byte[0] 21 bytes(system header)");
+       PrintAndLog("      hf legic rdmem 0 4 55      - reads from byte[0] 4 bytes with IV 0x55");
+       PrintAndLog("      hf legic rdmem 0 100 55    - reads 256bytes with IV 0x55");
        return 0;
 }
 int usage_legic_sim(void){
@@ -142,7 +142,7 @@ int CmdLegicInfo(const char *Cmd) {
        int dcf = 0;
        int bIsSegmented = 0;
 
-       CmdLegicRFRead("0 21 55");
+       CmdLegicRdmem("0 21 55");
        
        // copy data from device
        GetEMLFromBigBuf(data, sizeof(data), 0);
@@ -417,13 +417,13 @@ int CmdLegicInfo(const char *Cmd) {
        return 0;
 }
 
-int CmdLegicRFRead(const char *Cmd) {
+int CmdLegicRdmem(const char *Cmd) {
 
        // params:
        // offset in data memory
        // number of bytes to read
        char cmdp = param_getchar(Cmd, 0);
-       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_read();
+       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_rdmem();
        
        uint32_t offset = 0, len = 0, IV = 1;
        sscanf(Cmd, "%x %x %x", &offset, &len, &IV);
@@ -906,8 +906,94 @@ int CmdLegicReader(const char *Cmd){
 }
 
 int CmdLegicDump(const char *Cmd){
+
+       FILE *fout;
+       char filename[FILE_PATH_SIZE] = {0x00};
+       char *fnameptr = filename;
+       size_t fileNlen = 0;
+       bool errors = false;
+       uint16_t dumplen = 0x100;
+       
        char cmdp = param_getchar(Cmd, 0);
-       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_dump();
+       
+       while(param_getchar(Cmd, cmdp) != 0x00)
+       {
+               switch(param_getchar(Cmd, cmdp))
+               {
+               case 'h':
+               case 'H':
+                       return usage_legic_dump();
+               case 'o':
+               case 'O':
+                       fileNlen = param_getstr(Cmd, cmdp+1, filename);
+                       if (!fileNlen) errors = true; 
+                       if (fileNlen > FILE_PATH_SIZE-5) fileNlen = FILE_PATH_SIZE-5;
+                       cmdp += 2;
+                       break;
+               default:
+                       PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+                       errors = true;
+                       break;
+               }
+               if(errors) break;
+       }
+
+       //Validations
+       if(errors) return usage_legic_dump();
+       
+       // tagtype
+       //uint32_t tagtype = GetHF14AMfU_Type();
+       //if (tagtype == -1) return -1;
+       
+       UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}};
+       clearCommandBuffer();
+       SendCommand(&c);
+       UsbCommand resp;
+       if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
+               PrintAndLog("Command execute time-out");
+               return 1;
+       }
+               
+       uint8_t isOK = resp.arg[0] & 0xFF;
+       if ( !isOK ) {
+               PrintAndLog("Failed dumping tag data");
+               return 2;
+       }
+
+       uint16_t readlen = resp.arg[1];
+       uint8_t *data = malloc(readlen);
+       if ( !data ){
+               PrintAndLog("Fail, cannot allocate memory");
+               return 3;
+       }
+       
+       if ( readlen != dumplen )
+               PrintAndLog("Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
+
+       // copy data from device
+       GetEMLFromBigBuf(data, readlen, 0);
+       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500)) {
+               PrintAndLog("Fail, transfer from device time-out");
+               if ( data ) free(data);
+               return 4;
+       }
+
+       // user supplied filename?
+       if (fileNlen < 1)
+               sprintf(fnameptr,"%02X%02X%02X%02X.bin", data[0], data[1], data[2], data[3]);
+       else
+               sprintf(fnameptr + fileNlen,".bin");
+
+       if ((fout = fopen(filename,"wb")) == NULL) { 
+               PrintAndLog("Could not create file name %s", filename);
+               if ( data ) free(data);
+               return 5;
+       }
+       fwrite( data, 1, readlen, fout );
+       fclose(fout);
+       if ( data ) free(data);
+       
+       PrintAndLog("Wrote %d bytes to %s", readlen, filename);
        return 0;
 }      
        
@@ -916,7 +1002,7 @@ static command_t CommandTable[] =  {
        {"reader",      CmdLegicReader,         1, "LEGIC Prime Reader UID and Type tag info"},
        {"info",        CmdLegicInfo,           0, "Display deobfuscated and decoded LEGIC Prime tag data"},
        {"dump",        CmdLegicDump,           0, "Dump LEGIC Prime card to binary file"},
-       {"rdmem",       CmdLegicRFRead,         0, "[offset][length] <iv> -- read bytes from a LEGIC card"},
+       {"rdmem",       CmdLegicRdmem,          0, "[offset][length] <iv> -- read bytes from a LEGIC card"},
        {"save",        CmdLegicSave,           0, "<filename> [<length>] -- Store samples"},
        {"load",        CmdLegicLoad,           0, "<filename> -- Restore samples"},
        {"sim",         CmdLegicRfSim,          0, "[phase drift [frame drift [req/resp drift]]] Start tag simulator (use after load or read)"},
index 6d9739981e946159faee9de704e90a96521d61ce..a8fbd3171796d43d7bf464f57388bc39062c6fc4 100644 (file)
@@ -26,7 +26,7 @@
 int CmdHFLegic(const char *Cmd);
 int CmdLegicInfo(const char *Cmd);
 
-int CmdLegicRFRead(const char *Cmd);
+int CmdLegicRdmem(const char *Cmd);
 int CmdLegicLoad(const char *Cmd);
 int CmdLegicSave(const char *Cmd);
 int CmdLegicRfSim(const char *Cmd);
@@ -44,7 +44,7 @@ int CmdLegicDump(const char *Cmd);
 
 int usage_legic_calccrc8(void);
 int usage_legic_load(void);
-int usage_legic_read(void);
+int usage_legic_rdmem(void);
 int usage_legic_sim(void);
 int usage_legic_write(void);
 int usage_legic_rawwrite(void);
Impressum, Datenschutz