]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
Merge pull request #112 from marshmellow42/master
[proxmark3-svn] / client / cmdhficlass.c
index 31f7ba973f8d2a956194d9152fdf65584b3f76a7..824aaa3674cc1bd5cf84d38174968d0e3fbd468e 100644 (file)
@@ -30,6 +30,7 @@
 #include "loclass/elite_crack.h"
 #include "loclass/fileutils.h"
 #include "protocols.h"
 #include "loclass/elite_crack.h"
 #include "loclass/fileutils.h"
 #include "protocols.h"
+#include "usb_cmd.h"
 
 static int CmdHelp(const char *Cmd);
 
 
 static int CmdHelp(const char *Cmd);
 
@@ -164,38 +165,47 @@ int CmdHFiClassSim(const char *Cmd)
        return 0;
 }
 
        return 0;
 }
 
-int CmdHFiClassReader(const char *Cmd)
+int HFiClassReader(const char *Cmd, bool loop, bool verbose)
 {
 {
-       UsbCommand c = {CMD_READER_ICLASS, {0}};
+       bool tagFound = false;
+       UsbCommand c = {CMD_READER_ICLASS, {FLAG_ICLASS_READER_CSN|
+                                       FLAG_ICLASS_READER_CONF|FLAG_ICLASS_READER_AA}};
+       if (!loop) c.arg[0] |= FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_ONE_TRY;
        SendCommand(&c);
        UsbCommand resp;
        while(!ukbhit()){
        SendCommand(&c);
        UsbCommand resp;
        while(!ukbhit()){
-               if (WaitForResponseTimeout(CMD_ACK,&resp,4500)) {
-                       uint8_t isOK    = resp.arg[0] & 0xff;
-                       uint8_t * data  = resp.d.asBytes;
+               if (WaitForResponseTimeout(CMD_ACK,&resp, 4500)) {
+                       uint8_t readStatus = resp.arg[0] & 0xff;
+                       uint8_t *data = resp.d.asBytes;
 
 
-                       PrintAndLog("isOk:%02x", isOK);
-                       if( isOK == 0){
+                       if (verbose)
+                               PrintAndLog("Readstatus:%02x", readStatus);
+                       if( readStatus == 0){
                                //Aborted
                                //Aborted
-                               PrintAndLog("Quitting...");
+                               if (verbose) PrintAndLog("Quitting...");
                                return 0;
                        }
                                return 0;
                        }
-                       if(isOK > 0)
-                       {
+                       if( readStatus & FLAG_ICLASS_READER_CSN){
                                PrintAndLog("CSN: %s",sprint_hex(data,8));
                                PrintAndLog("CSN: %s",sprint_hex(data,8));
+                               tagFound = true;
                        }
                        }
-                       if(isOK >= 1)
-                       {
-                               PrintAndLog("CC: %s",sprint_hex(data+8,8));
-                       }else{
-                               PrintAndLog("No CC obtained");
+                       if( readStatus & FLAG_ICLASS_READER_CC)  PrintAndLog("CC: %s",sprint_hex(data+16,8));
+                       if( readStatus & FLAG_ICLASS_READER_CONF){
+                               printIclassDumpInfo(data);
                        }
                        }
+                       if (tagFound && !loop) return 1;
                } else {
                } else {
-                       PrintAndLog("Command execute timeout");
+                       if (verbose) PrintAndLog("Command execute timeout");
                }
                }
+               if (!loop) break;
        }
        }
-
        return 0;
        return 0;
+
+}
+
+int CmdHFiClassReader(const char *Cmd)
+{
+       return HFiClassReader(Cmd, true, true);
 }
 
 int CmdHFiClassReader_Replay(const char *Cmd)
 }
 
 int CmdHFiClassReader_Replay(const char *Cmd)
@@ -269,7 +279,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
        uint8_t key_sel_p[8] = { 0 };
 
        UsbCommand c = {CMD_READER_ICLASS, {0}};
        uint8_t key_sel_p[8] = { 0 };
 
        UsbCommand c = {CMD_READER_ICLASS, {0}};
-       c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE| FLAG_ICLASS_READER_GET_CC;
+       c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE| FLAG_ICLASS_READER_CC;
        SendCommand(&c);
 
 
        SendCommand(&c);
 
 
@@ -284,7 +294,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
        uint8_t * data  = resp.d.asBytes;
 
        memcpy(CSN,data,8);
        uint8_t * data  = resp.d.asBytes;
 
        memcpy(CSN,data,8);
-       memcpy(CCNR,data+8,8);
+       memcpy(CCNR,data+16,8);
 
        PrintAndLog("isOk:%02x", isOK);
 
 
        PrintAndLog("isOk:%02x", isOK);
 
@@ -348,7 +358,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
                        if(dataLength > 0)
                        {
                                PrintAndLog("Got %d bytes data (total so far %d)" ,dataLength,iclass_datalen);
                        if(dataLength > 0)
                        {
                                PrintAndLog("Got %d bytes data (total so far %d)" ,dataLength,iclass_datalen);
-                               memcpy(iclass_data, resp.d.asBytes,dataLength);
+                               memcpy(iclass_data+iclass_datalen, resp.d.asBytes,dataLength);
                                iclass_datalen += dataLength;
                        }else
                        {//Last transfer, datalength 0 means the dump is finished
                                iclass_datalen += dataLength;
                        }else
                        {//Last transfer, datalength 0 means the dump is finished
Impressum, Datenschutz