]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/pcf7931.c
Fix some printf/scanf format strings
[proxmark3-svn] / armsrc / pcf7931.c
index e3bac3863a38010a6288f6def950e6e986fc2727..2fae74cc60f947ca944fac8494b31a07b9b7d5ce 100644 (file)
@@ -1,5 +1,6 @@
 #include "proxmark3.h"
 #include "apps.h"
 #include "proxmark3.h"
 #include "apps.h"
+#include "usb_cdc.h"
 #include "lfsampling.h"
 #include "pcf7931.h"
 #include "util.h"
 #include "lfsampling.h"
 #include "pcf7931.h"
 #include "util.h"
@@ -152,8 +153,14 @@ bool IsBlock0PCF7931(uint8_t *block) {
 
 bool IsBlock1PCF7931(uint8_t *block) {
        // assuming all RFU bits are set to 0
 
 bool IsBlock1PCF7931(uint8_t *block) {
        // assuming all RFU bits are set to 0
+
+       uint8_t rb1 = block[14] & 0x80;
+       uint8_t rfb = block[14] & 0x7f;
+       uint8_t rlb = block[15];
+
        if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0)
        if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0)
-               if((block[14] & 0x7f) <= 9 && block[15] <= 9)
+               // block 1 is sent only if (RLB >= 1 && RFB <= 1) or RB1 enabled
+               if(rfb <= rlb && rfb <= 9 && rlb <= 9 && ((rfb <= 1 && rlb >= 1) || rb1))
                        return true;
 
        return false;
                        return true;
 
        return false;
@@ -192,6 +199,7 @@ void ReadPCF7931() {
                        Dbprintf("Error, no tag or bad tag");
                        return;
                }
                        Dbprintf("Error, no tag or bad tag");
                        return;
                }
+
                // exit if too many errors during reading
                if (tries > 50 && (2*errors > tries)) {
                        Dbprintf("Error reading the tag");
                // exit if too many errors during reading
                if (tries > 50 && (2*errors > tries)) {
                        Dbprintf("Error reading the tag");
@@ -201,9 +209,11 @@ void ReadPCF7931() {
 
                // our logic breaks if we don't get at least two blocks
                if (n < 2) {
 
                // our logic breaks if we don't get at least two blocks
                if (n < 2) {
+                       // skip if all 0s block or no blocks
                        if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16))
                                continue;
 
                        if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16))
                                continue;
 
+                       // add block to single blocks list
                        if (single_blocks_cnt < max_blocks) {
                                for (i = 0; i < single_blocks_cnt; ++i) {
                                        if (!memcmp(single_blocks[i], tmp_blocks[0], 16)) {
                        if (single_blocks_cnt < max_blocks) {
                                for (i = 0; i < single_blocks_cnt; ++i) {
                                        if (!memcmp(single_blocks[i], tmp_blocks[0], 16)) {
@@ -213,6 +223,7 @@ void ReadPCF7931() {
                                }
                                if (j != 1) {
                                        memcpy(single_blocks[single_blocks_cnt], tmp_blocks[0], 16);
                                }
                                if (j != 1) {
                                        memcpy(single_blocks[single_blocks_cnt], tmp_blocks[0], 16);
+                                       print_result("got single block", single_blocks[single_blocks_cnt], 16);
                                        single_blocks_cnt++;
                                }
                                j = 0;
                                        single_blocks_cnt++;
                                }
                                j = 0;
@@ -222,6 +233,10 @@ void ReadPCF7931() {
                }
 
                Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
                }
 
                Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
+               for (i = 0; i < n; ++i)
+               {
+                       print_result("got consecutive blocks", tmp_blocks[i], 16);
+               }
 
                i = 0;
                if(!found_0_1) {
 
                i = 0;
                if(!found_0_1) {
@@ -284,7 +299,7 @@ void ReadPCF7931() {
                        goto end;
                }
        }
                        goto end;
                }
        }
-       while (found_blocks != max_blocks);
+       while (found_blocks < max_blocks);
 
  end:
        Dbprintf("-----------------------------------------");
 
  end:
        Dbprintf("-----------------------------------------");
Impressum, Datenschutz