]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
Merged two iclass-reader functions into one to remove duplicated code, update loclass...
[proxmark3-svn] / client / cmdhficlass.c
index 01bdfc11bb3b9c17ed0dae22e9c9ae8b0866d7d8..a7ef53c1552401544db176d5ccf0235b0df8ad75 100644 (file)
@@ -401,19 +401,30 @@ int CmdHFiClassSim(const char *Cmd)
 
 int CmdHFiClassReader(const char *Cmd)
 {
-  uint8_t readerType = 0;
-
-  if (strlen(Cmd)<1) {
-       PrintAndLog("Usage:  hf iclass reader    <reader type>");
-       PrintAndLog("        sample: hf iclass reader 0");
-       return 0;
-  }    
-
-  readerType = param_get8(Cmd, 0);
-  PrintAndLog("--readertype:%02x", readerType);
-
-  UsbCommand c = {CMD_READER_ICLASS, {readerType}};
+  UsbCommand c = {CMD_READER_ICLASS, {0}};
   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;
+
+            PrintAndLog("isOk:%02x", isOK);
+
+            if(isOK > 0)
+            {
+                PrintAndLog("CSN: %s",sprint_hex(data,8));
+            }
+            if(isOK >= 1)
+            {
+                PrintAndLog("CC: %s",sprint_hex(data+8,8));
+            }else{
+                PrintAndLog("No CC obtained");
+            }
+        } else {
+            PrintAndLog("Command execute timeout");
+        }
+    }
 
   return 0;
 }
@@ -464,7 +475,8 @@ int CmdHFiClassReader_Dump(const char *Cmd)
     return 1;
   }
     
-  UsbCommand c = {CMD_ICLASS_ISO14443A_GETPUBLIC, {0}};
+  UsbCommand c = {CMD_READER_ICLASS, {0}};
+  c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE;
 
   SendCommand(&c);
   
@@ -474,7 +486,6 @@ int CmdHFiClassReader_Dump(const char *Cmd)
         uint8_t isOK    = resp.arg[0] & 0xff;
         uint8_t * data  = resp.d.asBytes;
 
-
         memcpy(CSN,data,8);
         memcpy(CCNR,data+8,8);
 
@@ -484,12 +495,12 @@ int CmdHFiClassReader_Dump(const char *Cmd)
         {
             PrintAndLog("CSN: %s",sprint_hex(CSN,8));
         }
-        if(isOK > 1)
+        if(isOK >= 1)
         {
-            PrintAndLog("CC: %s",sprint_hex(CCNR,8));
+            //PrintAndLog("CC: %s",sprint_hex(CCNR,8));
             diversifyKey(CSN,KEY, div_key);
-            doMAC(CCNR,div_key, MAC);
-
+            doMAC(CCNR,12,div_key, MAC);
+            PrintAndLog("MAC:  %s",sprint_hex(MAC,sizeof(MAC)));
             UsbCommand d = {CMD_READER_ICLASS_REPLAY, {readerType}};
             memcpy(d.d.asBytes, MAC, 4);
             SendCommand(&d);
@@ -541,7 +552,7 @@ int CmdHFiClass_iso14443A_write(const char *Cmd)
         return 1;
   }
   
-  UsbCommand c = {CMD_ICLASS_ISO14443A_GETPUBLIC, {0}};
+  UsbCommand c = {CMD_ICLASS_ISO14443A_WRITE, {0}};
   SendCommand(&c);
   UsbCommand resp;
 
@@ -561,7 +572,7 @@ int CmdHFiClass_iso14443A_write(const char *Cmd)
   diversifyKey(CSN,KEY, div_key);
 
   PrintAndLog("Div Key: %s",sprint_hex(div_key,8));
-  doMAC(CCNR, div_key, MAC);
+  doMAC(CCNR, 12,div_key, MAC);
 
   UsbCommand c2 = {CMD_ICLASS_ISO14443A_WRITE, {readerType,blockNo}};
   memcpy(c2.d.asBytes, bldata, 8);
Impressum, Datenschutz