From 7bd30f12ac6def96c82df20ed7d927160db289af Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 16 Oct 2014 15:05:27 +0200 Subject: [PATCH] Small fixes, 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".. --- armsrc/iso15693.c | 14 +-- armsrc/lfops.c | 146 ++++++----------------------- client/Makefile | 6 +- client/cmdhf15.c | 28 +++++- client/cmdhfmf.c | 10 +- client/cmdlf.c | 33 +++++-- client/cmdlfio.c | 16 +--- client/cmdlft55xx.c | 28 ++++-- client/cmdlft55xx.h | 1 + client/data.c | 16 ---- client/ui.c | 222 +++++++++++++++++++++++++++++++++++++++++++- client/ui.h | 5 + tools/mkversion.pl | 2 +- 13 files changed, 344 insertions(+), 183 deletions(-) diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 39d9effb..d8bec898 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -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); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 0c0f0275..e086a717 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -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 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; } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 8448731e..0e212b2d 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -522,13 +522,13 @@ int CmdHF14AMfDump(const char *Cmd) int size = GetCardSize(); char cmdp = param_getchar(Cmd, 0); - PrintAndLog("Got %d",size); - - return 0; + if ( size > -1) - cmdp = (char)48+size; - + cmdp = (char)(48+size); + + PrintAndLog("Got %d",cmdp); + switch (cmdp) { case '0' : numSectors = 5; break; case '1' : diff --git a/client/cmdlf.c b/client/cmdlf.c index 71d87f16..2306121b 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -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, " <'0' period> <'1' period> ['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, " ['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 ] -- 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, " [GAP] Simulate arbitrary Manchester LF tag"}, {"snoop", CmdLFSnoop, 0, "['l'|'h'|] [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} }; diff --git a/client/cmdlfio.c b/client/cmdlfio.c index d7d36bc1..919fa442 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -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} }; diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 027f528a..3820e590 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -303,7 +303,6 @@ int CmdDump(const char *Cmd){ char cmdp = param_getchar(Cmd, 0); char s[20]; uint8_t pwd[4] = {0x00}; - if (strlen(Cmd)>1 || cmdp == 'h' || cmdp == 'H') { PrintAndLog("Usage: lf t55xx dump "); @@ -320,7 +319,6 @@ int CmdDump(const char *Cmd){ } } - for ( int i = 0; i <8; ++i){ *s = 0; if ( hasPwd ) { @@ -334,6 +332,15 @@ int CmdDump(const char *Cmd){ return 0; } +int CmdIceFsk(const char *Cmd){ + //uint8_t bits[1000] = {0x00}; + //uint8_t * bitstream = bits; + iceFsk3(GraphBuffer, LF_TRACE_BUFF_SIZE); + + RepaintGraphWindow(); + return 0; +} + char * GetBitRateStr(uint32_t id){ static char buf[40]; char *retStr = buf; @@ -390,7 +397,7 @@ char * GetModulationStr( uint32_t id){ switch (id){ case 0: - sprintf(retStr,"%d - direct",id); + sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id); break; case 1: sprintf(retStr,"%d - PSK 1 phase change when input changes",id); @@ -444,13 +451,14 @@ uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){ static command_t CommandTable[] = { {"help", CmdHelp, 1, "This help"}, - {"rd", CmdReadBlk, 0, " -- Read T55xx block data (page 0)"}, - {"rdPWD", CmdReadBlkPWD, 0, " -- Read T55xx block data in password mode(page 0)"}, - {"wr", CmdWriteBlk, 0, " -- Write T55xx block data (page 0)"}, - {"wrPWD", CmdWriteBlkPWD, 0, " -- Write T55xx block data in password mode(page 0)"}, - {"trace", CmdReadTrace, 0, "Read T55xx traceability data (page 1)"}, - {"info", CmdInfo, 0, "Read T55xx configuration data (page 0 / block 0"}, - {"dump", CmdDump, 0, "Dump T55xx card block 0-7 (is possible)"}, + {"rd", CmdReadBlk, 0, " -- Read T55xx block data (page 0)"}, + {"rdPWD", CmdReadBlkPWD, 0, " -- Read T55xx block data with password mode"}, + {"wr", CmdWriteBlk, 0, " -- Write T55xx block data (page 0)"}, + {"wrPWD", CmdWriteBlkPWD, 0, " -- Write T55xx block data with password"}, + {"trace", CmdReadTrace, 0, "Read T55xx traceability data (page 1 / blk 0-1)"}, + {"info", CmdInfo, 0, "Read T55xx configuration data (page0 /blk 0)"}, + {"dump", CmdDump, 0, "[password] Dump T55xx card block 0-7. optional with password"}, + {"fsk", CmdIceFsk, 0, "FSK demod"}, {NULL, NULL, 0, NULL} }; diff --git a/client/cmdlft55xx.h b/client/cmdlft55xx.h index d7be8add..f4fc3640 100644 --- a/client/cmdlft55xx.h +++ b/client/cmdlft55xx.h @@ -18,6 +18,7 @@ int CmdWriteBlk(const char *Cmd); int CmdWriteBLkPWD(const char *Cmd); int CmdReadTrace(const char *Cmd); int CmdInfo(const char *Cmd); +int CmdIceFsk(const char *Cmd); char * GetBitRateStr(uint32_t id); char * GetSaferStr(uint32_t id); char * GetModulationStr( uint32_t id); diff --git a/client/data.c b/client/data.c index 72acf8a6..3f019326 100644 --- a/client/data.c +++ b/client/data.c @@ -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); - } -*/ } diff --git a/client/ui.c b/client/ui.c index c796d904..1d85cc05 100644 --- a/client/ui.c +++ b/client/ui.c @@ -16,8 +16,11 @@ #include #include #include -#include "ui.h" #include "loclass/cipherutils.h" +#include "ui.h" + +//#include +#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 60)? 100:0; + } + } + + for (j=0; j 0)? 10 : -10; + } + + // show data + for (j=0; j 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; +} diff --git a/client/ui.h b/client/ui.h index 823dccc2..666d7002 100644 --- a/client/ui.h +++ b/client/ui.h @@ -11,6 +11,8 @@ #ifndef UI_H__ #define UI_H__ +#include +#include #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 diff --git a/tools/mkversion.pl b/tools/mkversion.pl index 19616441..e12dd447 100644 --- a/tools/mkversion.pl +++ b/tools/mkversion.pl @@ -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; -- 2.39.2