]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlfcotag.c
ADD: 'lf cotag read' - COTAG can be read now.
[proxmark3-svn] / client / cmdlfcotag.c
index 5e3f28b66cda5f0e88c1bebae6d32d5d5116f46b..8b71a0318368e771ee44ca0c643ee470439a7354 100644 (file)
  
 static int CmdHelp(const char *Cmd);
 
-int CmdCOTAGRead(const char *Cmd) {
-
-//     if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
+int usage_lf_cotag_read(void){
+       PrintAndLog("Usage: lf COTAG read [h] <signaldata>");
+       PrintAndLog("Options:");
+       PrintAndLog("      h          : This help");
+       PrintAndLog("      <0|1|2>    : 0 - HIGH/LOW signal; maxlength bigbuff");
+       PrintAndLog("                 : 1 - translation of HI/LO into bytes with manchester 0,1");
+       PrintAndLog("                 : 2 - raw signal; maxlength bigbuff");
+       PrintAndLog("");
+       PrintAndLog("Sample:");
+       PrintAndLog("        lf cotag read 0");
+       PrintAndLog("        lf cotag read 1");
+       return 0;
+}
+int CmdCOTAGDemod(const char *Cmd) {
+       return 0;
+}
 
-       CmdLFSetConfig("q 89");
+// When reading a COTAG.
+// 0 = HIGH/LOW signal - maxlength bigbuff
+// 1 = translation for HI/LO into bytes with manchester 0,1 - length 300
+// 2 = raw signal -  maxlength bigbuff         
+int CmdCOTAGRead(const char *Cmd) {
+       
+       if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
+       
+       uint8_t bits[320] = {0};
+       uint32_t rawsignal = 0;
+       sscanf(Cmd, "%u", &rawsignal);
  
-       UsbCommand c = {CMD_COTAG, {0, 0, 0}};
+       UsbCommand c = {CMD_COTAG, {rawsignal, 0, 0}};
        clearCommandBuffer();
        SendCommand(&c);
-       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
+       if ( !WaitForResponseTimeout(CMD_ACK, NULL, 7000) ) {
                PrintAndLog("command execution time out");
-               return 1;
+               return 1;       
        }
-       getSamples("", true);
+       
+       switch ( rawsignal ){
+               case 0: 
+               case 2: {
+                       CmdPlot("");
+                       CmdGrid("384");
+                       getSamples("", true); break;
+               }
+               case 1: {
+                       GetFromBigBuf(bits, sizeof(bits), 0);
+                       UsbCommand response;
+                       if ( !WaitForResponseTimeout(CMD_ACK, &response, 500) ) {
+                                       PrintAndLog("timeout while waiting for reply.");
+                                       return 1;
+                       }
+                       
+                       size_t size = sizeof(bits);
+                       int err = manrawdecode(bits, &size, 1);
+                       if (err){
+                               PrintAndLog("DEBUG: Error - COTAG too many errors: %d", err);
+                               return 0;
+                       }
+                       PrintAndLog("%s", sprint_bin(bits, size));
+                       setDemodBuf(bits, sizeof(bits), 0);
+                       
+                       // CmdCOTAGDemod();
+                       break;
+               }
+       }       
        return 0;
 }
 
 static command_t CommandTable[] = {
        {"help",      CmdHelp,         1, "This help"},
-       {"read",      CmdCOTAGRead,     0, "Attempt to read and extract tag data"},
+       {"demod",     CmdCOTAGDemod,   1, "Tries to decode a COTAG signal"},
+       {"read",      CmdCOTAGRead,    0, "Attempt to read and extract tag data"},
        {NULL, NULL, 0, NULL}
 };
 
Impressum, Datenschutz