]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/lfops.c
Client cleanup and restructuring. Stage 1...
[proxmark3-svn] / armsrc / lfops.c
index eeaa5782948173f2cf6af575551d4915e1dc2b11..a7e1f1df160f7adbce283ce510f55d98f6d1f106 100644 (file)
@@ -7,9 +7,7 @@
 #include <proxmark3.h>\r
 #include "apps.h"\r
 #include "hitag2.h"\r
-#include "../common/crc16.c"\r
-\r
-int sprintf(char *dest, const char *fmt, ...);\r
+#include "crc16.h"\r
 \r
 void AcquireRawAdcSamples125k(BOOL at134khz)\r
 {\r
@@ -39,7 +37,6 @@ void DoAcquisition125k(void)
        BYTE *dest = (BYTE *)BigBuf;\r
        int n = sizeof(BigBuf);\r
        int i;\r
-       char output_string[64];\r
        \r
        memset(dest, 0, n);\r
        i = 0;\r
@@ -55,9 +52,8 @@ void DoAcquisition125k(void)
                        if (i >= n) break;\r
                }\r
        }\r
-       sprintf(output_string, "read samples, dest[0]=%x dest[1]=%x",\r
-               dest[0], dest[1]);\r
-       DbpString(output_string);\r
+       Dbprintf("buffer samples: %02x %02x %02x %02x %02x %02x %02x %02x ...",\r
+                       dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);\r
 }\r
 \r
 void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, BYTE *command)\r
@@ -251,13 +247,10 @@ void ReadTItag(void)
                crc = update_crc16(crc, (shift1>>16)&0xff);\r
                crc = update_crc16(crc, (shift1>>24)&0xff);\r
 \r
-               char output_string[64];\r
-               sprintf(output_string, "Info: Tag data_hi=%x, data_lo=%x, crc=%x",\r
+               Dbprintf("Info: Tag data: %x%08x, crc=%x",\r
                        (unsigned int)shift1, (unsigned int)shift0, (unsigned int)shift2 & 0xFFFF);\r
-               DbpString(output_string);\r
                if (crc != (shift2&0xffff)) {\r
-                       sprintf(output_string, "Error: CRC mismatch, expected %x", (unsigned int)crc);\r
-                       DbpString(output_string);\r
+                       Dbprintf("Error: CRC mismatch, expected %x", (unsigned int)crc);\r
                } else {\r
                        DbpString("Info: CRC is good");\r
                }\r
@@ -349,7 +342,6 @@ void AcquireTiType(void)
        n = TIBUFLEN*32;\r
        // unpack buffer\r
        for (i=TIBUFLEN-1; i>=0; i--) {\r
-//             DbpIntegers(0, 0, BigBuf[i]);\r
                for (j=0; j<32; j++) {\r
                        if(BigBuf[i] & (1 << j)) {\r
                                dest[--n] = 1;\r
@@ -365,11 +357,6 @@ void AcquireTiType(void)
 // if not provided a valid crc will be computed from the data and written.\r
 void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)\r
 {\r
-\r
-       // WARNING the order of the bytes in which we calc crc below needs checking\r
-       // i'm 99% sure the crc algorithm is correct, but it may need to eat the\r
-       // bytes in reverse or something\r
-\r
        if(crc == 0) {\r
                crc = update_crc16(crc, (idlo)&0xff);\r
                crc = update_crc16(crc, (idlo>>8)&0xff);\r
@@ -380,10 +367,8 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
                crc = update_crc16(crc, (idhi>>16)&0xff);\r
                crc = update_crc16(crc, (idhi>>24)&0xff);\r
        }\r
-       char output_string[64];\r
-       sprintf(output_string, "Writing the following data to tag: %x, %x, %x",\r
+       Dbprintf("Writing to tag: %x%08x, crc=%x",\r
                (unsigned int) idhi, (unsigned int) idlo, crc);\r
-       DbpString(output_string);\r
 \r
        // TI tags charge at 134.2Khz\r
        FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz\r
@@ -438,7 +423,7 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
        DbpString("Now use tiread to check");\r
 }\r
 \r
-void SimulateTagLowFrequency(int period, int ledcontrol)\r
+void SimulateTagLowFrequency(int period, int gap, int ledcontrol)\r
 {\r
        int i;\r
        BYTE *tab = (BYTE *)BigBuf;\r
@@ -483,7 +468,13 @@ void SimulateTagLowFrequency(int period, int ledcontrol)
                }\r
 \r
                i++;\r
-               if(i == period) i = 0;\r
+               if(i == period) {\r
+                       i = 0;\r
+                       if (gap) { \r
+                               SHORT_COIL();\r
+                               SpinDelayUs(gap);\r
+                       }\r
+               }\r
        }\r
 }\r
 \r
@@ -777,7 +768,7 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
 \r
        if (ledcontrol)\r
                LED_A_ON();\r
-       SimulateTagLowFrequency(n, ledcontrol);\r
+       SimulateTagLowFrequency(n, 0, ledcontrol);\r
 \r
        if (ledcontrol)\r
                LED_A_OFF();\r
@@ -927,10 +918,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                found=1;\r
                                idx+=6;\r
                                if (found && (hi|lo)) {\r
-                                       char output_string[64];\r
-                                       sprintf(output_string, "TAG ID: %x %x %x", \r
+                                       Dbprintf("TAG ID: %x%08x (%d)",\r
                                                (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF);\r
-                                       DbpString(output_string);\r
                                        /* if we're only looking for one tag */\r
                                        if (findone)\r
                                        {\r
@@ -962,10 +951,8 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                found=1;\r
                                idx+=6;\r
                                if (found && (hi|lo)) {\r
-                                       char output_string[64];\r
-                                       sprintf(output_string, "TAG ID: %x %x %x", \r
+                                       Dbprintf("TAG ID: %x%08x (%d)",\r
                                                (unsigned int) hi, (unsigned int) lo, (unsigned int) (lo>>1) & 0xFFFF);\r
-                                       DbpString(output_string);\r
                                        /* if we're only looking for one tag */\r
                                        if (findone)\r
                                        {\r
Impressum, Datenschutz