]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhf14b.c
fixing iso14443b (issue #103):
[proxmark3-svn] / client / cmdhf14b.c
index 7e4cbd009787452bf77f1f4a5e70c536f2634d32..21a4e1799eec516c84d094067e9f4bf1c15db2f6 100644 (file)
@@ -23,7 +23,6 @@
 #include "cmdhf14b.h"
 #include "cmdmain.h"
 
-
 static int CmdHelp(const char *Cmd);
 
 int CmdHF14BDemod(const char *Cmd)
@@ -146,83 +145,10 @@ demodError:
 
 int CmdHF14BList(const char *Cmd)
 {
-  uint8_t got[960];
-  GetFromBigBuf(got,sizeof(got),0);
-  WaitForResponse(CMD_ACK,NULL);
-
-  PrintAndLog("recorded activity:");
-  PrintAndLog(" time  :rssi: who bytes");
-  PrintAndLog("---------+----+----+-----------");
-
-  int i = 0;
-  int prev = -1;
-
-  for(;;) {
-    if(i >= 900) {
-      break;
-    }
-
-    bool isResponse;
-    int timestamp = *((uint32_t *)(got+i));
-    if(timestamp & 0x80000000) {
-      timestamp &= 0x7fffffff;
-      isResponse = 1;
-    } else {
-      isResponse = 0;
-    }
-    int metric = *((uint32_t *)(got+i+4));
-
-    int len = got[i+8];
-
-    if(len > 100) {
-      break;
-    }
-    if(i + len >= 900) {
-      break;
-    }
-
-    uint8_t *frame = (got+i+9);
-
-       // Break and stick with current result if buffer was not completely full
-       if (frame[0] == 0x44 && frame[1] == 0x44 && frame[2] == 0x44 && frame[3] == 0x44) break; 
-       
-    char line[1000] = "";
-    int j;
-    for(j = 0; j < len; j++) {
-      sprintf(line+(j*3), "%02x  ", frame[j]);
-    }
-
-    char *crc;
-    if(len > 2) {
-      uint8_t b1, b2;
-      ComputeCrc14443(CRC_14443_B, frame, len-2, &b1, &b2);
-      if(b1 != frame[len-2] || b2 != frame[len-1]) {
-        crc = "**FAIL CRC**";
-      } else {
-        crc = "";
-      }
-    } else {
-      crc = "(SHORT)";
-    }
-
-    char metricString[100];
-    if(isResponse) {
-      sprintf(metricString, "%3d", metric);
-    } else {
-      strcpy(metricString, "   ");
-    }
-
-    PrintAndLog(" +%7d: %s: %s %s %s",
-      (prev < 0 ? 0 : timestamp - prev),
-      metricString,
-      (isResponse ? "TAG" : "   "), line, crc);
+       PrintAndLog("Deprecated command, use 'hf list 14b' instead");
 
-    prev = timestamp;
-    i += (len + 9);
-  }
-  return 0;
+       return 0;
 }
-
 int CmdHF14BRead(const char *Cmd)
 {
   UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443, {strtol(Cmd, NULL, 0), 0, 0}};
@@ -282,7 +208,7 @@ int CmdHF14BCmdRaw (const char *cmd) {
     uint8_t power=0;
     char buf[5]="";
     int i=0;
-    uint8_t data[100];
+    uint8_t data[100] = {0x00};
     unsigned int datalen=0, temp;
     char *hexout;
     
@@ -336,7 +262,7 @@ int CmdHF14BCmdRaw (const char *cmd) {
             continue;
         }
         PrintAndLog("Invalid char on input");
-        return 0;
+        return 1;
     }
     if (datalen == 0)
     {
@@ -362,7 +288,7 @@ int CmdHF14BCmdRaw (const char *cmd) {
         if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
             recv = resp.d.asBytes;
             PrintAndLog("received %i octets",resp.arg[0]);
-            if(!resp.arg[0])
+            if(resp.arg[0] == 0)
                 return 0;
             hexout = (char *)malloc(resp.arg[0] * 3 + 1);
             if (hexout != NULL) {
@@ -372,11 +298,13 @@ int CmdHF14BCmdRaw (const char *cmd) {
                 }
                 PrintAndLog("%s", hexout);
                 free(hexout);
-                ComputeCrc14443(CRC_14443_B, recv, resp.arg[0]-2, &first, &second);
-                if(recv[resp.arg[0]-2]==first && recv[resp.arg[0]-1]==second) {
-                    PrintAndLog("CRC OK");
-                } else {
-                    PrintAndLog("CRC failed");
+                               if (resp.arg[0] > 2) {
+                                       ComputeCrc14443(CRC_14443_B, recv, resp.arg[0]-2, &first, &second);
+                                       if(recv[resp.arg[0]-2]==first && recv[resp.arg[0]-1]==second) {
+                                               PrintAndLog("CRC OK");
+                                       } else {
+                                               PrintAndLog("CRC failed");
+                                       }
                 }
             } else {
                 PrintAndLog("malloc failed your client has low memory?");
@@ -406,20 +334,27 @@ int CmdHF14BWrite( const char *Cmd){
        bool isSrix4k = true;
        char str[20];   
 
-       if (cmdp == 'h' || cmdp == 'H') {
+       if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') {
                PrintAndLog("Usage:  hf 14b write <1|2> <BLOCK> <DATA>");
-               PrintAndLog("");
-               PrintAndLog("     sample: hf 14b write 1 127 11223344");
-               PrintAndLog("     sample: hf 14b write 1 255 11223344");
-               PrintAndLog("     sample: hf 14b write 2 15 11223344");
-               PrintAndLog("     sample: hf 14b write 2 255 11223344");
+               PrintAndLog("    [1 = SRIX4K]");
+               PrintAndLog("    [2 = SRI512]");
+               PrintAndLog("    [BLOCK number depends on tag, special block == FF]");
+               PrintAndLog("     sample: hf 14b write 1 7F 11223344");
+               PrintAndLog("           : hf 14b write 1 FF 11223344");
+               PrintAndLog("           : hf 14b write 2 15 11223344");
+               PrintAndLog("           : hf 14b write 2 FF 11223344");
                return 0;
        }
 
-       if ( param_getchar(Cmd, 0) == '2' )
+       if ( cmdp == '2' )
                isSrix4k = false;
        
-       blockno = param_get8(Cmd, 1);
+       //blockno = param_get8(Cmd, 1);
+       
+       if ( param_gethex(Cmd,1, &blockno, 2) ) {
+               PrintAndLog("Block number must include 2 HEX symbols");
+               return 0;
+       }
        
        if ( isSrix4k ){
                if ( blockno > 0x7f && blockno != 0xff ){
@@ -439,11 +374,12 @@ int CmdHF14BWrite( const char *Cmd){
        }
  
        if ( blockno == 0xff)
-               PrintAndLog("Writing to special block %02X [ %s]", blockno,  sprint_hex(data,4) );
+               PrintAndLog("[%s] Write special block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512" , blockno,  sprint_hex(data,4) );
        else
-               PrintAndLog("Writing to block %02X [ %s]", blockno,  sprint_hex(data,4) );
+               PrintAndLog("[%s] Write block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512", blockno,  sprint_hex(data,4) );
  
-       sprintf(str, "-c -p 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
+       sprintf(str, "-c 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
+
        CmdHF14BCmdRaw(str);
        return 0;
 }
@@ -452,7 +388,7 @@ static command_t CommandTable[] =
 {
   {"help",        CmdHelp,        1, "This help"},
   {"demod",       CmdHF14BDemod,  1, "Demodulate ISO14443 Type B from tag"},
-  {"list",        CmdHF14BList,   0, "List ISO 14443 history"},
+  {"list",        CmdHF14BList,   0, "[Deprecated] List ISO 14443b history"},
   {"read",        CmdHF14BRead,   0, "Read HF tag (ISO 14443)"},
   {"sim",         CmdHF14Sim,     0, "Fake ISO 14443 tag"},
   {"simlisten",   CmdHFSimlisten, 0, "Get HF samples as fake tag"},
Impressum, Datenschutz