]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhf14b.c
Merge pull request #969 from pwpiwi/gcc10_fixes
[proxmark3-svn] / client / cmdhf14b.c
index 8a83df8f76f98a3ee6776acaa68f27a8d0244061..2ad3525144d5dc7ad135a4016cfd1a311c19495e 100644 (file)
@@ -108,9 +108,21 @@ int HF14BCmdRaw(bool reply, bool *crc, bool power, uint8_t *data, uint8_t *datal
                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;
+
+       int ret = resp.arg[0];
+       if (verbose) {
+               if (ret < 0) {
+                       PrintAndLog("tag didn't respond");
+               } else if (ret == 0) {
+                       PrintAndLog("received SOF only (maybe iCLASS/Picopass)");
+               } else {
+                       PrintAndLog("received %u octets", ret);
+               }
+       }
+
+       *datalen = ret;
+
+       if (ret < 2) return 0;
 
        memcpy(data, resp.d.asBytes, *datalen);
        if (verbose) PrintAndLog("%s", sprint_hex(data, *datalen));
@@ -139,7 +151,7 @@ static int CmdHF14BCmdRaw (const char *Cmd) {
        uint8_t datalen = 0;
        unsigned int temp;
        int i = 0;
-       if (strlen(Cmd) < 3) {
+       if (strlen(Cmd) < 2) {
                        PrintAndLog("Usage: hf 14b raw [-r] [-c] [-p] [-s || -ss] <0A 0B 0C ... hex>");
                        PrintAndLog("       -r    do not read response");
                        PrintAndLog("       -c    calculate and append CRC");
@@ -225,8 +237,11 @@ static int CmdHF14BCmdRaw (const char *Cmd) {
 
                if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false) == 0) return switch_off_field_14b();
 
-               if (SRx && (cmdLen != 3 || !crc2) ) return switch_off_field_14b();
-               else if (cmd2[0] != 0x50 || cmdLen != 14 || !crc2) return switch_off_field_14b();
+               if (SRx) {
+                       if (cmdLen != 3 || !crc2) return switch_off_field_14b();
+               } else {
+                       if (cmd2[0] != 0x50 || cmdLen != 14 || !crc2) return switch_off_field_14b();
+               }
 
                uint8_t chipID = 0;
                if (SRx) {
@@ -251,7 +266,9 @@ static int CmdHF14BCmdRaw (const char *Cmd) {
                if (cmdLen != 3 || !crc2) return switch_off_field_14b();
                if (SRx && cmd2[0] != chipID) return switch_off_field_14b();
        }
+
        return HF14BCmdRaw(reply, &crc, power, data, &datalen, true);
+
 }
 
 
@@ -512,22 +529,21 @@ static bool HF14B_ST_Info(bool verbose) {
 
 
 // test for other 14b type tags (mimic another reader - don't have tags to identify)
-static bool HF14B_Other_Reader(bool verbose) {
-       uint8_t data[4];
+static bool HF14B_Other_Reader(uint8_t *data, bool verbose) {
        uint8_t datalen;
-
        bool crc = true;
-       datalen = 4;
+
        //std read cmd
        data[0] = 0x00;
        data[1] = 0x0b;
        data[2] = 0x3f;
        data[3] = 0x80;
+       datalen = 4;
 
        if (HF14BCmdRaw(true, &crc, true, data, &datalen, false) != 0) {
                if (datalen > 2 || !crc) {
                        PrintAndLog ("\n14443-3b tag found:");
-                       PrintAndLog ("Unknown tag type answered to a 0x000b3f80 command ans:");
+                       PrintAndLog ("Unknown tag type answered to a 0x000b3f80 command:");
                        PrintAndLog ("%s", sprint_hex(data, datalen));
                        switch_off_field_14b();
                        return true;
@@ -541,7 +557,7 @@ static bool HF14B_Other_Reader(bool verbose) {
        if (HF14BCmdRaw(true, &crc, true, data, &datalen, false) != 0) {
                if (datalen > 0) {
                        PrintAndLog ("\n14443-3b tag found:");
-                       PrintAndLog ("Unknown tag type answered to a 0x0A command ans:");
+                       PrintAndLog ("Unknown tag type answered to a 0x0A command:");
                        PrintAndLog ("%s", sprint_hex(data, datalen));
                        switch_off_field_14b();
                        return true;
@@ -555,7 +571,7 @@ static bool HF14B_Other_Reader(bool verbose) {
        if (HF14BCmdRaw(true, &crc, true, data, &datalen, false) != 0) {
                if (datalen > 0) {
                        PrintAndLog ("\n14443-3b tag found:");
-                       PrintAndLog ("Unknown tag type answered to a 0x0C command ans:");
+                       PrintAndLog ("Unknown tag type answered to a 0x0C command:");
                        PrintAndLog ("%s", sprint_hex(data, datalen));
                        switch_off_field_14b();
                        return true;
@@ -589,7 +605,7 @@ int infoHF14B(bool verbose) {
 
        // try unknown 14b read commands (to be identified later)
        //   could be read of calypso, CEPAS, moneo, or pico pass.
-       if (HF14B_Other_Reader(verbose)) return 1;
+       if (HF14B_Other_Reader(data, verbose)) return 1;
 
        if (verbose) PrintAndLog("no 14443B tag found");
        return 0;
@@ -619,7 +635,7 @@ int readHF14B(bool verbose){
 
        // try unknown 14b read commands (to be identified later)
        //   could be read of calypso, CEPAS, moneo, or pico pass.
-       if (HF14B_Other_Reader(verbose)) return 1;
+       if (HF14B_Other_Reader(data, verbose)) return 1;
 
        if (verbose) PrintAndLog("no 14443B tag found");
        return 0;
@@ -662,7 +678,6 @@ int CmdSriWrite(const char *Cmd) {
        uint8_t blockno = -1;
        uint8_t data[4] = {0x00};
        bool isSrix4k = true;
-       char str[20];
 
        if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') {
                PrintAndLog("Usage:  hf 14b write <1|2> <BLOCK> <DATA>");
@@ -708,7 +723,8 @@ int CmdSriWrite(const char *Cmd) {
        else
                PrintAndLog("[%s] Write block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512", blockno, sprint_hex(data, 4));
 
-       sprintf(str, "-c 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
+       char str[22];
+       sprintf(str, "-ss -c 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
 
        CmdHF14BCmdRaw(str);
        return 0;
Impressum, Datenschutz