]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhf14b.c
ADD: @marshmellow42 's 14b fixes.
[proxmark3-svn] / client / cmdhf14b.c
index 0144111e72db2a48334ceff8ff3c47c8d743f9e5..d3b86488e59ea8f4538fe1124be3cd37f1e9003e 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
-#include <string.h>
+//#include <string.h>
 #include <stdint.h>
 #include "iso14443crc.h"
 #include "proxmark3.h"
@@ -35,7 +35,7 @@ int CmdHF14BList(const char *Cmd)
 
 int CmdHF14BSim(const char *Cmd)
 {
-       UsbCommand c={CMD_SIMULATE_TAG_ISO_14443B};
+  UsbCommand c={CMD_SIMULATE_TAG_ISO_14443B};
        clearCommandBuffer();
        SendCommand(&c);
        return 0;
@@ -43,7 +43,7 @@ int CmdHF14BSim(const char *Cmd)
 
 int CmdHF14BSnoop(const char *Cmd)
 {
-       UsbCommand c = {CMD_SNOOP_ISO_14443B};
+  UsbCommand c = {CMD_SNOOP_ISO_14443B};
        clearCommandBuffer();
        SendCommand(&c);
        return 0;
@@ -105,26 +105,29 @@ int HF14BCmdRaw(bool reply, bool *crc, bool power, uint8_t *data, uint8_t *datal
 
        if (!reply) return 1; 
 
-       if (!WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+       if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
                if (verbose) PrintAndLog("timeout while waiting for reply.");
-                       return 0;
-               }
-               *datalen = resp.arg[0];
-               if (verbose) PrintAndLog("received %u octets", *datalen);
-               if(*datalen<2) return 0;
+               return 0;
+       }
 
-               memcpy(data, resp.d.asBytes, *datalen);
-               if (verbose) PrintAndLog("%s", sprint_hex(data, *datalen));
+       int len = resp.arg[0];
+       if (verbose) {
+               PrintAndLog("received %u octets", len);
+       }
+       if ( len < 2 ) return 0;
 
-               uint8_t first, second;
-               ComputeCrc14443(CRC_14443_B, data, *datalen-2, &first, &second);
-               if(data[*datalen-2] == first && data[*datalen-1] == second) {
-                       if (verbose) PrintAndLog("CRC OK");
-                       *crc = true;
-               } else {
-                       if (verbose) PrintAndLog("CRC failed");
-                       *crc = false;
-               }
+       memcpy(data, resp.d.asBytes, len);
+       if (verbose) PrintAndLog("%s", sprint_hex(data, len));
+
+       uint8_t first, second;
+       ComputeCrc14443(CRC_14443_B, data, len-2, &first, &second);
+       if(data[len-2] == first && data[len-1] == second) {
+               if (verbose) PrintAndLog("CRC OK");
+               *crc = true;
+       } else {
+               if (verbose) PrintAndLog("CRC failed");
+               *crc = false;
+       }
        return 1;
 }
 
@@ -133,7 +136,7 @@ int CmdHF14BCmdRaw (const char *Cmd) {
     bool crc = false;
        bool power = false;
     char buf[5]="";
-    uint8_t data[100] = {0x00};
+    uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
     uint8_t datalen = 0;
     unsigned int temp;
     int i = 0;
@@ -257,7 +260,7 @@ static void print_st_info(uint8_t *data){
        return;
 }
 
-int HF14BStdReader(uint8_t *data, uint8_t *datalen){
+int HF14BStdInfo(uint8_t *data, uint8_t *datalen){
 
        //05 00 00 = find one tag in field
        //1d xx xx xx xx 20 00 08 01 00 = attrib xx=crc
@@ -290,9 +293,9 @@ int HF14BStdReader(uint8_t *data, uint8_t *datalen){
        print_atqb_resp(data);
 
        return 1;
-       }
+}
 
-int HF14B_ST_Reader(uint8_t *data, uint8_t *datalen){
+int HF14B_ST_Info(uint8_t *data, uint8_t *datalen){
        bool crc = true;
        *datalen = 2;
        //wake cmd
@@ -333,7 +336,7 @@ int HF14B_ST_Reader(uint8_t *data, uint8_t *datalen){
 }
 
 // test for other 14b type tags (mimic another reader - don't have tags to identify)
-int HF14B_Other_Reader(uint8_t *data, uint8_t *datalen){
+int HF14B_Other_Info(uint8_t *data, uint8_t *datalen){
        bool crc = true;
        *datalen = 4;
        //std read cmd
@@ -381,29 +384,29 @@ int HF14B_Other_Reader(uint8_t *data, uint8_t *datalen){
 
 }
 
-int HF14BReader(bool verbose){
+int HF14BInfo(bool verbose){
        uint8_t data[100];
        uint8_t datalen = 5;
 
        // try std 14b (atqb)
-       if (HF14BStdReader(data, &datalen)) return 1;
+       if (HF14BStdInfo(data, &datalen)) return 1;
 
        // try st 14b
-       if (HF14B_ST_Reader(data, &datalen)) return 1;
+       if (HF14B_ST_Info(data, &datalen)) return 1;
 
        // try unknown 14b read commands (to be identified later)
        //   could be read of calypso, CEPAS, moneo, or pico pass.
-       if (HF14B_Other_Reader(data, &datalen)) return 1;
+       if (HF14B_Other_Info(data, &datalen)) return 1;
 
        if (verbose) PrintAndLog("no 14443B tag found");
        return 0;
 }
 
-int CmdHF14BReader(const char *Cmd){
-       return HF14BReader(true);
+int CmdHF14Binfo(const char *Cmd){
+       return HF14BInfo(true);
 }
 
-int CmdHF14BWrite( const char *Cmd){
+int CmdSriWrite( const char *Cmd){
 /*
  * For SRIX4K  blocks 00 - 7F
  * hf 14b raw -c -p 09 $srix4kwblock $srix4kwdata
@@ -473,15 +476,14 @@ int CmdHF14BWrite( const char *Cmd){
 static command_t CommandTable[] = 
 {
        {"help",        CmdHelp,        1, "This help"},
+       {"info",        CmdHF14Binfo,   0, "Find and print info about a 14b type tag (HF ISO 14443b)"},
        {"list",        CmdHF14BList,   0, "[Deprecated] List ISO 14443b history"},
-       {"reader",      CmdHF14BReader, 0, "Find 14b tag (HF ISO 14443b)"},
-       {"sim",         CmdHF14BSim,     0, "Fake ISO 14443B tag"},
-
-       {"snoop",       CmdHF14BSnoop,  0, "Eavesdrop ISO 14443B"},
+  {"sim",         CmdHF14BSim,    0, "Fake ISO 14443B tag"},
+  {"snoop",       CmdHF14BSnoop,  0, "Eavesdrop ISO 14443B"},
        {"sri512read",  CmdSri512Read,  0, "Read contents of a SRI512 tag"},
        {"srix4kread",  CmdSrix4kRead,  0, "Read contents of a SRIX4K tag"},
+  {"sriwrite",    CmdSriWrite,    0, "Write data to a SRI512 | SRIX4K tag"},
        {"raw",         CmdHF14BCmdRaw, 0, "Send raw hex data to tag"},
-       {"write",       CmdHF14BWrite,  0, "Write data to a SRI512 | SRIX4K tag"},
        {NULL, NULL, 0, NULL}
 };
 
Impressum, Datenschutz