]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
Small fixes,
authoriceman1001 <iceman@iuse.se>
Thu, 16 Oct 2014 13:05:27 +0000 (15:05 +0200)
committericeman1001 <iceman@iuse.se>
Thu, 16 Oct 2014 13:05:27 +0000 (15:05 +0200)
Fix: removed a call to free,  which I think made linux people unhappy during "lf t55xx rd 0"...
Add: "lf t55xx fsk"  now kind of outputs binary from "FSK2a R/40 R/50"..

13 files changed:
armsrc/iso15693.c
armsrc/lfops.c
client/Makefile
client/cmdhf15.c
client/cmdhfmf.c
client/cmdlf.c
client/cmdlfio.c
client/cmdlft55xx.c
client/cmdlft55xx.h
client/data.c
client/ui.c
client/ui.h
tools/mkversion.pl

index 39d9effb05b080d57c453c80c9be683933c46b4b..d8bec898dece7872be78157a3ea009cf6310be7b 100644 (file)
@@ -64,6 +64,8 @@
 #include "string.h"
 #include "../common/iso15693tools.h"
 #include "../common/cmd.h"
+#include "crapto1.h"
+#include "mifareutil.h"
 
 #define arraylen(x) (sizeof(x)/sizeof((x)[0]))
 
@@ -600,10 +602,10 @@ static void BuildIdentifyRequest(void);
 //-----------------------------------------------------------------------------
 void AcquireRawAdcSamplesIso15693(void)
 {
+       uint8_t *dest =  mifare_get_bigbufptr();
+
        int c = 0;
-       uint8_t *dest = (uint8_t *)BigBuf;
        int getNext = 0;
-
        int8_t prev = 0;
 
        FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@@ -682,10 +684,10 @@ void AcquireRawAdcSamplesIso15693(void)
 
 void RecordRawAdcSamplesIso15693(void)
 {
+       uint8_t *dest =  mifare_get_bigbufptr();
+
        int c = 0;
-       uint8_t *dest = (uint8_t *)BigBuf;
        int getNext = 0;
-
        int8_t prev = 0;
 
        FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@@ -693,8 +695,8 @@ void RecordRawAdcSamplesIso15693(void)
        FpgaSetupSsc();
 
        // Start from off (no field generated)
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-       SpinDelay(200);
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
+       SpinDelay(200);
 
        SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
 
index 0c0f027569da23824128c4ff49757db0eb601e1d..e086a7174d3e252bf21909ab46fc764e9bc6b121 100644 (file)
@@ -54,11 +54,11 @@ void SnoopLFRawAdcSamples(int divisor, int trigger_threshold)
 // split into two routines so we can avoid timing issues after sending commands //
 void DoAcquisition125k(int trigger_threshold)
 {
-       uint8_t *dest = (uint8_t *)BigBuf;
-       int n = sizeof(BigBuf);
+       uint8_t *dest =  mifare_get_bigbufptr();
+       int n = 8000;
        int i;
 
-       memset(dest, 0, n);
+       memset(dest, 0x00, n);
        i = 0;
        for(;;) {
                if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
@@ -77,6 +77,7 @@ void DoAcquisition125k(int trigger_threshold)
        }
        Dbprintf("buffer samples: %02x %02x %02x %02x %02x %02x %02x %02x ...",
                        dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
+                       
 }
 
 void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, uint8_t *command)
@@ -829,24 +830,12 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
 
 void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
 {
-       uint8_t *dest = (uint8_t *)BigBuf;
+       uint8_t *dest =  mifare_get_bigbufptr();
        int m=0, n=0, i=0, idx=0, lastval=0;
        int found=0;
        uint32_t code=0, code2=0;
-       //uint32_t hi2=0, hi=0, lo=0;
-
-       FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
-       FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 
-       // Connect the A/D to the peak-detected low-frequency path.
-       SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
-
-       // Give it a bit of time for the resonant antenna to settle.
-       SpinDelay(50);
-
-       // Now set up the SSC to get the ADC samples that are now streaming at us.
-       FpgaSetupSsc();
+       LFSetupFPGAForADC(0, true);
 
        for(;;) {
                WDT_HIT();
@@ -860,7 +849,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                }
 
                i = 0;
-               m = sizeof(BigBuf);
+               m = 30000;
                memset(dest,128,m);
                for(;;) {
                        if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
@@ -872,13 +861,12 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
                                // we don't care about actual value, only if it's more or less than a
                                // threshold essentially we capture zero crossings for later analysis
-                               if(dest[i] < 127) dest[i] = 0; else dest[i] = 1;
-                               i++;
+                               dest[i] = (dest[i] < 127) ? 0 : 1;
+                               ++i;
                                if (ledcontrol)
                                        LED_D_OFF();
-                               if(i >= m) {
+                               if(i >= m)      
                                        break;
-                               }
                        }
                }
 
@@ -898,12 +886,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                for( i=0; idx<m; idx++) {
                        if (dest[idx-1]<dest[idx]) {
                                dest[i]=idx-lastval;
-                               if (dest[i] <= 8) {
-                                               dest[i]=1;
-                               } else {
-                                               dest[i]=0;
-                               }
-
+                               dest[i] = (dest[i] <= 8) ? 1:0;
                                lastval=idx;
                                i++;
                        }
@@ -931,90 +914,23 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                                } else {
                                        n=(n+1)/6;                      // fc/10 in sets of 6
                                }
-                               switch (n) {                    // stuff appropriate bits in buffer
-                                       case 0:
-                                       case 1: // one bit
-                                               dest[i++]=dest[idx-1]^1;
-                                               //Dbprintf("%d",dest[idx-1]);
-                                               break;
-                                       case 2: // two bits
-                                               dest[i++]=dest[idx-1]^1;
-                                               dest[i++]=dest[idx-1]^1;
-                                               //Dbprintf("%d",dest[idx-1]);
-                                               //Dbprintf("%d",dest[idx-1]);
-                                               break;
-                                       case 3: // 3 bit start of frame markers
-                                               for(int j=0; j<3; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 4:
-                                               for(int j=0; j<4; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 5:
-                                               for(int j=0; j<5; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 6:
-                                               for(int j=0; j<6; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 7:
-                                               for(int j=0; j<7; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 8:
-                                               for(int j=0; j<8; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 9:
-                                               for(int j=0; j<9; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 10:
-                                               for(int j=0; j<10; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 11:
-                                               for(int j=0; j<11; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                               //  Dbprintf("%d",dest[idx-1]);
-                                               }
-                                               break;
-                                       case 12:
-                                               for(int j=0; j<12; j++){
-                                                 dest[i++]=dest[idx-1]^1;
-                                                // Dbprintf("%d",dest[idx-1]);
+
+                               // stuff appropriate bits in buffer
+                               if ( n==0 )
+                                       dest[i++]=dest[idx-1]^1;
+                               else {
+                                       if ( n < 13){
+                                               for(int j=0; j<n; j++){
+                                                       dest[i++]=dest[idx-1]^1;
                                                }
-                                               break;
-                                       default:        // this shouldn't happen, don't stuff any bits
-                                               //Dbprintf("%d",dest[idx-1]);
-                                               break;
+                                       }
                                }
+                               
                                n=0;
                                lastval=dest[idx];
                        }
                }//end for
-               /*for(int j=0; j<64;j+=8){
-                 Dbprintf("%d%d%d%d%d%d%d%d",dest[j],dest[j+1],dest[j+2],dest[j+3],dest[j+4],dest[j+5],dest[j+6],dest[j+7]);
-               }
-               Dbprintf("\n");*/
+
                m=i;
                WDT_HIT();
                
@@ -1045,7 +961,7 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                       unknown <<=1;
                       if (dest[idx+j]) unknown |= 1;
                    }
-                   for(int j=36;j<45;j++){
+                   for(int j=37;j<45;j++){
                       //Dbprintf("%d",dest[idx+j]);
                       number <<=1;
                       if (dest[idx+j]) number |= 1;
@@ -1055,13 +971,14 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                       number <<=1;
                       if (dest[idx+j]) number |= 1;
                    }
+                       
                    for(int j=0; j<32; j++){
-                       code <<=1;
-                       if(dest[idx+j]) code |= 1;
+                               code <<=1;
+                               if(dest[idx+j]) code |= 1;
                    }
                    for(int j=32; j<64; j++){
-                       code2 <<=1;
-                       if(dest[idx+j]) code2 |= 1;
+                               code2 <<=1;
+                               if(dest[idx+j]) code2 |= 1;
                    }
                    
                    Dbprintf("XSF(%02d)%02x:%d (%08x%08x)",version,unknown,number,code,code2);
@@ -1070,17 +987,12 @@ void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol)
                }
                // if we're only looking for one tag 
                if (findone){
-                       //*high = hi;
-                       //*low = lo;
                        LED_A_OFF();
                        return;
                }
-      
-               //hi=0;
-               //lo=0;
+
                found=0;
          }
-               
        }
        }
        WDT_HIT();
index 1aa801eebbab757032cb3c6aee6544ca8d6140db..2d52e3dfc7222cdf02a71944e116e194af3a79b2 100644 (file)
@@ -13,13 +13,13 @@ CXX=g++
 VPATH = ../common
 OBJDIR = obj
 
-LDLIBS = -L/mingw/lib -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a  -lreadline -lpthread -lcrypto -lgdi32
+LDLIBS =  -L/mingw/lib -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a -lm -lreadline -lpthread -lcrypto -lgdi32
 LDFLAGS = $(COMMON_FLAGS)
-CFLAGS = -std=c99  -I. -I../include -I../common -I/mingw/include -I/opt/local/include -I../liblua  -Wall $(COMMON_FLAGS) -g -O4  $(ICE_FLAGS)
+CFLAGS = -std=c99 -I. -I../include -I../common -I/mingw/include -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4 $(ICE_FLAGS)
 LUAPLATFORM = generic
 
 ifneq (,$(findstring MINGW,$(platform)))
-CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui -I$(QTDIR)/include/QtWidgets 
+CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui -I$(QTDIR)/include/QtWidgets  -I/mingw/include
 QTLDLIBS = -L$(QTDIR)/lib  -lQt5Core -lQt5Gui -lQt5Widgets 
 MOC = $(QTDIR)/bin/moc
 LUAPLATFORM = mingw
index 195560edd0f74b2ca370c079c01d8663e175adc8..55a33de7617a7cd0f0b2a4bc5025e1dc7763308d 100644 (file)
@@ -44,6 +44,7 @@
 #define Crc(data,datalen)     Iso15693Crc(data,datalen)
 #define AddCrc(data,datalen)  Iso15693AddCrc(data,datalen)
 #define sprintUID(target,uid)  Iso15693sprintUID(target,uid)
+#define TRACE_BUFF_SIZE 12000
 
 // structure and database for uid -> tagtype lookups 
 typedef struct { 
@@ -252,6 +253,17 @@ int CmdHF15Read(const char *Cmd)
 {
        UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693};
        SendCommand(&c);
+
+       uint8_t data[TRACE_BUFF_SIZE] = {0x00};
+       
+       GetFromBigBuf(data,TRACE_BUFF_SIZE,3560);  //3560 -- should be offset..
+       WaitForResponseTimeout(CMD_ACK,NULL, 1500);
+
+       for (int j = 0; j < TRACE_BUFF_SIZE; j++) {
+               GraphBuffer[j] = ((int)data[j]) ;
+       }
+       GraphTraceLen = TRACE_BUFF_SIZE;
+       RepaintGraphWindow();
        return 0;
 }
 
@@ -260,6 +272,17 @@ int CmdHF15Record(const char *Cmd)
 {
        UsbCommand c = {CMD_RECORD_RAW_ADC_SAMPLES_ISO_15693};
        SendCommand(&c);
+
+       uint8_t data[TRACE_BUFF_SIZE] = {0x00};
+       
+       GetFromBigBuf(data,TRACE_BUFF_SIZE,3560);  //3560 -- should be offset..
+       WaitForResponseTimeout(CMD_ACK,NULL, 1500);
+
+       for (int j = 0; j < TRACE_BUFF_SIZE; j++) {
+               GraphBuffer[j] = ((int)data[j]) ;
+       }
+       GraphTraceLen = TRACE_BUFF_SIZE;
+       RepaintGraphWindow();
        return 0;
 }
 
@@ -421,8 +444,9 @@ int CmdHF15CmdInquiry(const char *Cmd)
 int CmdHF15CmdDebug( const char *cmd) {
        int debug=atoi(cmd);
        if (strlen(cmd)<1) {
-               PrintAndLog("Usage: hf 15 cmd debug  <0/1>");
-               PrintAndLog("   0..no debugging output  1..turn debugging on"); 
+               PrintAndLog("Usage: hf 15 cmd debug  <0|1>");
+               PrintAndLog("   0 no debugging");
+               PrintAndLog("   1 turn debugging on");  
                return 0;
        }
 
index 8448731e9c7bd21588f67bb4e1c04a9660d0d3da..0e212b2d13c211b30c47fd9080dc1eee4bd61d32 100644 (file)
@@ -522,13 +522,13 @@ int CmdHF14AMfDump(const char *Cmd)
        int size = GetCardSize();               \r
        char cmdp = param_getchar(Cmd, 0);\r
        \r
-       PrintAndLog("Got %d",size);\r
-       \r
-       return 0;\r
        \r
+\r
        if  ( size > -1) \r
-               cmdp = (char)48+size;\r
-       \r
+               cmdp = (char)(48+size);\r
+\r
+       PrintAndLog("Got %d",cmdp);\r
+               \r
        switch (cmdp) {\r
                case '0' : numSectors = 5; break;\r
                case '1' : \r
index 71d87f1648864c6122e06df546303e60d250bded..2306121b36acbc73720624813ddf29d83288023a 100644 (file)
@@ -468,6 +468,18 @@ int CmdLFSnoop(const char *Cmd)
   }
   SendCommand(&c);
   WaitForResponse(CMD_ACK,NULL);
+  
+  size_t BUFF_SIZE = 8000;
+  uint8_t data[BUFF_SIZE];
+
+  GetFromBigBuf(data,BUFF_SIZE,3560);  //3560 -- should be offset..
+  WaitForResponseTimeout(CMD_ACK,NULL, 1500);
+
+       for (int j = 0; j < BUFF_SIZE; j++) {
+               GraphBuffer[j] = ((int)data[j]);
+       }
+       GraphTraceLen = BUFF_SIZE;
+  
   return 0;
 }
 
@@ -551,22 +563,27 @@ static command_t CommandTable[] =
 {
   {"help",        CmdHelp,            1, "This help"},
   {"cmdread",     CmdLFCommandRead,   0, "<off period> <'0' period> <'1' period> <command> ['h'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'h' for 134)"},
-  {"em4x",        CmdLFEM4X,          1, "{ EM4X RFIDs... }"},
+
   {"flexdemod",   CmdFlexdemod,       1, "Demodulate samples for FlexPass"},
-  {"hid",         CmdLFHID,           1, "{ HID RFIDs... }"},
-  {"io",         CmdLFIO,            1, "{ ioProx tags... }"},
   {"indalademod", CmdIndalaDemod,     1, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"},
   {"indalaclone", CmdIndalaClone,     1, "<UID> ['l']-- Clone Indala to T55x7 (tag must be in antenna)(UID in HEX)(option 'l' for 224 UID"},
+  {"vchdemod",    CmdVchDemod,        1, "['clone'] -- Demodulate samples for VeriChip"},
+
+  
   {"read",        CmdLFRead,          0, "['h' or <divisor>] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134, alternatively: f=12MHz/(divisor+1))"},
   {"sim",         CmdLFSim,           0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"},
   {"simbidir",    CmdLFSimBidir,      0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
   {"simman",      CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
   {"snoop",       CmdLFSnoop,         0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},
-  {"ti",          CmdLFTI,            1, "{ TI RFIDs... }"},
-  {"hitag",       CmdLFHitag,         1, "{ Hitag tags and transponders... }"},
-  {"vchdemod",    CmdVchDemod,        1, "['clone'] -- Demodulate samples for VeriChip"},
-  {"t55xx",       CmdLFT55XX,         1, "{ T55xx RFIDs... }"},
-  {"pcf7931",     CmdLFPCF7931,       1, "{PCF7931 RFIDs...}"},
+  
+  {"em4x",        CmdLFEM4X,          1, "{ EM4X tags }"},      
+  {"hid",         CmdLFHID,           1, "{ HID tags }"},
+  {"hitag",       CmdLFHitag,         1, "{ Hitag tags and transponders }"},
+  {"io",         CmdLFIO,                1, "{ ioProx tags }"},
+  {"pcf7931",     CmdLFPCF7931,       1, "{ PCF7931 tags }"},
+  {"ti",          CmdLFTI,            1, "{ TI tags }"},
+  {"t55xx",       CmdLFT55XX,         1, "{ T55xx tags }"},
   {NULL, NULL, 0, NULL}
 };
 
index d7d36bc1bf10bfe7aeb8e7af6df18567650c973a..919fa4425dba2967dc8a428f36ba56c6d92ffbe9 100644 (file)
@@ -21,20 +21,14 @@ int CmdIODemodFSK(const char *Cmd)
   return 0;
 }
 
-
 int CmdIOProxDemod(const char *Cmd){
   if (GraphTraceLen < 4800) {
     PrintAndLog("too short; need at least 4800 samples");
     return 0;
   }
-
   GraphTraceLen = 4800;
   for (int i = 0; i < GraphTraceLen; ++i) {
-    if (GraphBuffer[i] < 0) {
-      GraphBuffer[i] = 0;
-    } else {
-      GraphBuffer[i] = 1;
-    }
+    GraphBuffer[i] = (GraphBuffer[i] < 0) ? 0 : 1;
   }
   RepaintGraphWindow();
   return 0;
@@ -68,10 +62,10 @@ int CmdIOClone(const char *Cmd)
 
 static command_t CommandTable[] = 
 {
-  {"help",        CmdHelp,            1, "This help"},
-  {"demod",      CmdIOProxDemod,     1, "Demodulate Stream"},
-  {"fskdemod",    CmdIODemodFSK,      1, "Demodulate ioProx Tag"},
-  {"clone",      CmdIOClone,         1, "Clone ioProx Tag"},
+  {"help",      CmdHelp,         1, "This help"},
+  {"demod",        CmdIOProxDemod,  1, "Demodulate Stream"},
+  {"fskdemod",  CmdIODemodFSK,   1, "Demodulate ioProx Tag"},
+  {"clone",        CmdIOClone,      1, "Clone ioProx Tag"},
   {NULL, NULL, 0, NULL}
 };
 
index 027f528a78b636234eab76d5cf1072a038364f1a..3820e590b02e6b21e74090f6fc47fe5337923214 100644 (file)
@@ -303,7 +303,6 @@ int CmdDump(const char *Cmd){
        char cmdp = param_getchar(Cmd, 0);\r
        char s[20];\r
        uint8_t pwd[4] = {0x00};\r
-\r
                \r
        if (strlen(Cmd)>1 || cmdp == 'h' || cmdp == 'H') {\r
                PrintAndLog("Usage:  lf t55xx dump <password>");\r
@@ -320,7 +319,6 @@ int CmdDump(const char *Cmd){
                }\r
        }\r
 \r
-\r
        for ( int i = 0; i <8; ++i){\r
                *s = 0;\r
                if ( hasPwd ) {\r
@@ -334,6 +332,15 @@ int CmdDump(const char *Cmd){
        return 0;\r
 }\r
 \r
+int CmdIceFsk(const char *Cmd){\r
+       //uint8_t bits[1000] = {0x00};\r
+       //uint8_t * bitstream = bits;\r
+       iceFsk3(GraphBuffer, LF_TRACE_BUFF_SIZE);\r
+       \r
+       RepaintGraphWindow();\r
+       return 0;\r
+}\r
+\r
 char * GetBitRateStr(uint32_t id){\r
        static char buf[40];\r
        char *retStr = buf;\r
@@ -390,7 +397,7 @@ char * GetModulationStr( uint32_t id){
        \r
        switch (id){\r
                case 0: \r
-                       sprintf(retStr,"%d - direct",id);\r
+                       sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r
                        break;\r
                case 1:\r
                        sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r
@@ -444,13 +451,14 @@ uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){
 static command_t CommandTable[] =\r
 {\r
   {"help",   CmdHelp,        1, "This help"},\r
-  {"rd",     CmdReadBlk,     0, "<Block> -- Read T55xx block data (page 0)"},\r
-  {"rdPWD",  CmdReadBlkPWD,  0, "<Block> <Password> -- Read T55xx block data in password mode(page 0)"},\r
-  {"wr",     CmdWriteBlk,    0, "<Data> <Block> -- Write T55xx block data (page 0)"},\r
-  {"wrPWD",  CmdWriteBlkPWD, 0, "<Data> <Block> <Password> -- Write T55xx block data in password mode(page 0)"},\r
-  {"trace",  CmdReadTrace,   0, "Read T55xx traceability data (page 1)"},\r
-  {"info",   CmdInfo,        0, "Read T55xx configuration data (page 0 / block 0"},\r
-  {"dump",   CmdDump,        0, "Dump T55xx card block 0-7 (is possible)"},\r
+  {"rd",     CmdReadBlk,     0, "<block> -- Read T55xx block data (page 0)"},\r
+  {"rdPWD",  CmdReadBlkPWD,  0, "<block> <password> -- Read T55xx block data with password mode"},\r
+  {"wr",     CmdWriteBlk,    0, "<data> <block> -- Write T55xx block data (page 0)"},\r
+  {"wrPWD",  CmdWriteBlkPWD, 0, "<data> <block> <password> -- Write T55xx block data with password"},\r
+  {"trace",  CmdReadTrace,   0, "Read T55xx traceability data (page 1 / blk 0-1)"},\r
+  {"info",   CmdInfo,        0, "Read T55xx configuration data (page0 /blk 0)"},\r
+  {"dump",   CmdDump,        0, "[password] Dump T55xx card block 0-7. optional with password"},\r
+  {"fsk",    CmdIceFsk,      0, "FSK demod"},\r
   {NULL, NULL, 0, NULL}\r
 };\r
 \r
index d7be8add1384877de705ad7d58c59bc071b04f02..f4fc3640aa6b3d4fe1ca48dc2c6c60b850b010be 100644 (file)
@@ -18,6 +18,7 @@ int CmdWriteBlk(const char *Cmd);
 int CmdWriteBLkPWD(const char *Cmd);\r
 int CmdReadTrace(const char *Cmd);\r
 int CmdInfo(const char *Cmd);\r
+int CmdIceFsk(const char *Cmd);\r
 char * GetBitRateStr(uint32_t id);\r
 char * GetSaferStr(uint32_t id);\r
 char * GetModulationStr( uint32_t id);\r
index 72acf8a6579930207dc030a74464ac469b12c8c2..3f0193266578b179a1dc1b247965fff150d2f38c 100644 (file)
@@ -22,22 +22,6 @@ void GetFromBigBuf(uint8_t *dest, int bytes, int start_index)
 {
   sample_buf_len = 0;
   sample_buf = dest;
-//     start_index = ((start_index/12)*12);
-//    int n = start_index + bytes;
-    /*
-     if (n % 48 != 0) {
-     PrintAndLog("bad len in GetFromBigBuf");
-     return;
-     }
-     */
   UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
   SendCommand(&c);
-/*
-  for (int i = start_index; i < n; i += 48) {
-        UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
-        SendCommand(&c);
-//        WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
-//        memcpy(dest+(i*4), sample_buf, 48);
-    }
-*/
 }
index c796d9047464db97a261726e57e2da13e70f0942..1d85cc05f0eaa5e2ac1d6a1c392862baa15c79be 100644 (file)
 #include <time.h>
 #include <readline/readline.h>
 #include <pthread.h>
-#include "ui.h"
 #include "loclass/cipherutils.h"
+#include "ui.h"
+
+//#include <liquid/liquid.h>
+#define M_PI 3.14159265358979323846264338327
 
 double CursorScaleFactor;
 int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64;
@@ -125,8 +128,6 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout){
        //      PrintPaddedManchester(bitStream, bitlength, clock);
 
        memcpy(dataout, bitStream, bitlength);
-       
-       free(bitStream);
        return bitlength;
 }
 
@@ -392,4 +393,217 @@ void PrintPaddedManchester( uint8_t* bitStream, size_t len, size_t blocksize){
        
        if ( mod > 0 )
                PrintAndLog(" %s", sprint_bin(bitStream+i, mod) );      
-}
\ No newline at end of file
+}
+
+void iceFsk(int * data, const size_t len){
+
+       //34359738  == 125khz   (2^32 / 125) =
+       
+    // parameters
+    float phase_offset      = 0.00f;   // carrier phase offset
+    float frequency_offset  = 0.30f;   // carrier frequency offset
+    float wn                = 0.01f;   // pll bandwidth
+    float zeta              = 0.707f;  // pll damping factor
+    float K                 = 1000;    // pll loop gain
+    size_t n                = len;     // number of samples
+
+    // generate loop filter parameters (active PI design)
+    float t1 = K/(wn*wn);   // tau_1
+    float t2 = 2*zeta/wn;   // tau_2
+
+    // feed-forward coefficients (numerator)
+    float b0 = (4*K/t1)*(1.+t2/2.0f);
+    float b1 = (8*K/t1);
+    float b2 = (4*K/t1)*(1.-t2/2.0f);
+
+    // feed-back coefficients (denominator)
+    //    a0 =  1.0  is implied
+    float a1 = -2.0f;
+    float a2 =  1.0f;
+
+    // filter buffer
+    float v0=0.0f, v1=0.0f, v2=0.0f;
+    
+    // initialize states
+    float phi     = phase_offset;  // input signal's initial phase
+    float phi_hat = 0.0f;      // PLL's initial phase
+    
+    unsigned int i;
+    float complex x,y;
+       float complex output[n];
+       
+       for (i=0; i<n; i++) {
+               // INPUT SIGNAL
+               x = data[i];
+               phi += frequency_offset;
+               
+               // generate complex sinusoid
+               y = cosf(phi_hat) + _Complex_I*sinf(phi_hat);
+
+               output[i] = y;
+
+               // compute error estimate
+               float delta_phi = cargf( x * conjf(y) );
+
+               
+        // print results to standard output
+        printf("  %6u %12.8f %12.8f %12.8f %12.8f %12.8f\n",
+                  i,
+                  crealf(x), cimagf(x),
+                  crealf(y), cimagf(y),
+                  delta_phi);
+       
+               // push result through loop filter, updating phase estimate
+
+               // advance buffer
+               v2 = v1;  // shift center register to upper register
+               v1 = v0;  // shift lower register to center register
+
+               // compute new lower register
+               v0 = delta_phi - v1*a1 - v2*a2;
+
+               // compute new output
+               phi_hat = v0*b0 + v1*b1 + v2*b2;
+
+       }
+
+       for (i=0; i<len; ++i){
+               data[i] = (int)crealf(output[i]);
+       }
+}
+
+/* Sliding DFT
+   Smooths out 
+*/ 
+void iceFsk2(int * data, const size_t len){
+
+       int i, j;
+       int output[len];
+       
+       // for (i=0; i<len-5; ++i){
+               // for ( j=1; j <=5; ++j) {
+                       // output[i] += data[i*j];
+               // }
+               // output[i] /= 5;
+       // }
+       int rest = 127;
+       int tmp =0;
+       for (i=0; i<len; ++i){
+               if ( data[i] < 127)
+                       output[i] = 0;
+               else {
+                       tmp =  (100 * (data[i]-rest)) / rest;
+                       output[i] = (tmp > 60)? 100:0;
+               }
+       }
+       
+       for (j=0; j<len; ++j)
+               data[j] = output[j];
+}
+
+void iceFsk3(int * data, const size_t len){
+
+       int i,j;
+       int output[len];
+    float fc            = 0.1125f;          // center frequency
+
+    // create very simple low-pass filter to remove images (2nd-order Butterworth)
+    float complex iir_buf[3] = {0,0,0};
+    float b[3] = {0.003621681514929,  0.007243363029857, 0.003621681514929};
+    float a[3] = {1.000000000000000, -1.822694925196308, 0.837181651256023};
+    
+    // process entire input file one sample at a time
+    float         sample      = 0;      // input sample read from file
+    float complex x_prime     = 1.0f;   // save sample for estimating frequency
+    float complex x;
+               
+       for (i=0; i<len; ++i) {
+
+               sample = data[i];
+               
+        // remove DC offset and mix to complex baseband
+        x = (sample - 127.5f) * cexpf( _Complex_I * 2 * M_PI * fc * i );
+
+        // apply low-pass filter, removing spectral image (IIR using direct-form II)
+        iir_buf[2] = iir_buf[1];
+        iir_buf[1] = iir_buf[0];
+        iir_buf[0] = x - a[1]*iir_buf[1] - a[2]*iir_buf[2];
+        x          = b[0]*iir_buf[0] +
+                     b[1]*iir_buf[1] +
+                     b[2]*iir_buf[2];
+                                        
+        // compute instantaneous frequency by looking at phase difference
+        // between adjacent samples
+        float freq = cargf(x*conjf(x_prime));
+        x_prime = x;    // retain this sample for next iteration
+
+               output[i] =(freq > 0)? 10 : -10;
+    } 
+
+       // show data
+       for (j=0; j<len; ++j)
+               data[j] = output[j];
+               
+       CmdLtrim("30");
+       
+       // zero crossings.
+       for (j=0; j<len; ++j){
+               if ( data[j] == 10) break;
+       }
+       int startOne =j;
+       
+       for (;j<len; ++j){
+               if ( data[j] == -10 ) break;
+       }
+       int stopOne = j-1;
+       
+       int fieldlen = stopOne-startOne;
+       printf("FIELD Length: %d \n", fieldlen);
+       
+       
+       // FSK sequence start == 000111
+       int startPos = 0;
+       for (i =0; i<len; ++i){
+               int dec = 0;
+               for ( j = 0; j < 6*fieldlen; ++j){
+                       dec += data[i + j];
+               }
+               if (dec == 0) {
+                       startPos = i;
+                       break;
+               }
+       }
+       
+       printf("000111 position: %d \n", startPos);
+
+       startPos += 6*fieldlen+1;
+       
+       printf("BINARY\n");
+       printf("R/40 :  ");
+       for (i =startPos ; i < len; i += 40){
+               if ( data[i] > 0 ) 
+                       printf("1");
+               else
+                       printf("0");
+       }
+       printf("\n");   
+       
+       printf("R/50 :  ");
+       for (i =startPos ; i < len; i += 50){
+               if ( data[i] > 0 ) 
+                       printf("1");
+               else
+                       printf("0");
+       }
+       printf("\n");   
+       
+}
+
+float complex cexpf (float complex Z)
+{
+  float complex  Res;
+  double rho = exp (__real__ Z);
+  __real__ Res = rho * cosf(__imag__ Z);
+  __imag__ Res = rho * sinf(__imag__ Z);
+  return Res;
+}
index 823dccc2e1db1041344f202ebfb624e1d6b22925..666d7002c5978afd82dcea1b9e09b816dc1107b7 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef UI_H__
 #define UI_H__
 
+#include <math.h>
+#include <complex.h>
 #include "util.h"
 
 void ShowGui(void);
@@ -32,4 +34,7 @@ void PrintPaddedManchester( uint8_t * bitStream, size_t len, size_t blocksize);
 void ManchesterDiffDecodedString( const uint8_t *bitStream, size_t len, uint8_t invert );
 int ManchesterConvertFrom255(const int * data, const size_t len, uint8_t * dataout, int high, int low, int clock, int startIndex);
 int ManchesterConvertFrom1(const int * data, const size_t len, uint8_t * dataout, int clock, int startIndex);
+void iceFsk(int * data, const size_t len);
+void iceFsk2(int * data, const size_t len);
+void iceFsk3(int * data, const size_t len);
 #endif
index 19616441ad15e0338e688b02c6d8be84bb7f9ace..e12dd4472c4c6df0ff9a21bece88b037a199a59e 100644 (file)
@@ -16,7 +16,7 @@ my $gitbranch = `git rev-parse --abbrev-ref HEAD`;
 my $clean = 2;
 my @compiletime = gmtime();
 
-my $fullgitinfo = $gitbranch . '/' . $gitversion;
+my $fullgitinfo = 'iceman' . $gitbranch . '/' . $gitversion;
 
 $fullgitinfo =~ s/(\s)//g;
 
Impressum, Datenschutz