Merge pull request #38 from marshmellow42/master

Add PSK, space to tabs, new trace, bug fixes to clock & demods
This commit is contained in:
Martin Holst Swende 2015-01-08 21:53:20 +01:00
commit 07c808038c
10 changed files with 19611 additions and 3149 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
command_t * CmdDataCommands(); command_t * CmdDataCommands();
int CmdData(const char *Cmd); int CmdData(const char *Cmd);
void printDemodBuff();
int CmdAmp(const char *Cmd); int CmdAmp(const char *Cmd);
int Cmdaskdemod(const char *Cmd); int Cmdaskdemod(const char *Cmd);
int Cmdaskrawdemod(const char *Cmd); int Cmdaskrawdemod(const char *Cmd);
@ -30,6 +30,8 @@ int CmdFSKdemod(const char *Cmd);
int CmdFSKdemodHID(const char *Cmd); int CmdFSKdemodHID(const char *Cmd);
int CmdFSKdemodIO(const char *Cmd); int CmdFSKdemodIO(const char *Cmd);
int CmdFSKrawdemod(const char *Cmd); int CmdFSKrawdemod(const char *Cmd);
int CmdDetectNRZpskClockRate(const char *Cmd);
int CmdpskNRZrawDemod(const char *Cmd);
int CmdGrid(const char *Cmd); int CmdGrid(const char *Cmd);
int CmdHexsamples(const char *Cmd); int CmdHexsamples(const char *Cmd);
int CmdHide(const char *Cmd); int CmdHide(const char *Cmd);
@ -49,5 +51,10 @@ int CmdScale(const char *Cmd);
int CmdThreshold(const char *Cmd); int CmdThreshold(const char *Cmd);
int CmdDirectionalThreshold(const char *Cmd); int CmdDirectionalThreshold(const char *Cmd);
int CmdZerocrossings(const char *Cmd); int CmdZerocrossings(const char *Cmd);
int CmdIndalaDecode(const char *Cmd);
#define MAX_DEMOD_BUF_LEN (1024*128)
extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
extern int DemodBufferLen;
#endif #endif

View file

@ -606,7 +606,7 @@ int CmdWriteWordPWD(const char *Cmd)
static command_t CommandTable[] = static command_t CommandTable[] =
{ {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"em410xdemod", CmdEMdemodASK, 0, "[clock rate] -- Extract ID from EM410x tag"}, {"em410xdemod", CmdEMdemodASK, 0, "[findone] -- Extract ID from EM410x tag (option 0 for continuous loop, 1 for only 1 tag)"},
{"em410xread", CmdEM410xRead, 1, "[clock rate] -- Extract ID from EM410x tag"}, {"em410xread", CmdEM410xRead, 1, "[clock rate] -- Extract ID from EM410x tag"},
{"em410xsim", CmdEM410xSim, 0, "<UID> -- Simulate EM410x tag"}, {"em410xsim", CmdEM410xSim, 0, "<UID> -- Simulate EM410x tag"},
{"em410xwatch", CmdEM410xWatch, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"}, {"em410xwatch", CmdEM410xWatch, 0, "['h'] -- Watches for EM410x 125/134 kHz tags (option 'h' for 134)"},

View file

@ -20,170 +20,93 @@ int GraphTraceLen;
/* write a bit to the graph */ /* write a bit to the graph */
void AppendGraph(int redraw, int clock, int bit) void AppendGraph(int redraw, int clock, int bit)
{ {
int i; int i;
for (i = 0; i < (int)(clock / 2); ++i) for (i = 0; i < (int)(clock / 2); ++i)
GraphBuffer[GraphTraceLen++] = bit ^ 1; GraphBuffer[GraphTraceLen++] = bit ^ 1;
for (i = (int)(clock / 2); i < clock; ++i)
GraphBuffer[GraphTraceLen++] = bit;
if (redraw) for (i = (int)(clock / 2); i < clock; ++i)
RepaintGraphWindow(); GraphBuffer[GraphTraceLen++] = bit;
if (redraw)
RepaintGraphWindow();
} }
/* clear out our graph window */ // clear out our graph window
int ClearGraph(int redraw) int ClearGraph(int redraw)
{ {
int gtl = GraphTraceLen; int gtl = GraphTraceLen;
GraphTraceLen = 0; GraphTraceLen = 0;
if (redraw) if (redraw)
RepaintGraphWindow(); RepaintGraphWindow();
return gtl; return gtl;
} }
/* // DETECT CLOCK NOW IN LFDEMOD.C
* Detect clock rate
*/ void setGraphBuf(uint8_t *buff, size_t size)
//decommissioned - has difficulty detecting rf/32
/*
int DetectClockOld(int peak)
{ {
int i; int i=0;
int clock = 0xFFFF; ClearGraph(0);
int lastpeak = 0; for (; i < size; ++i){
GraphBuffer[i]=buff[i]-128;
// Detect peak if we don't have one }
if (!peak) GraphTraceLen=size;
for (i = 0; i < GraphTraceLen; ++i) RepaintGraphWindow();
if (GraphBuffer[i] > peak) return;
peak = GraphBuffer[i];
// peak=(int)(peak*.75);
for (i = 1; i < GraphTraceLen; ++i)
{
// If this is the beginning of a peak
if (GraphBuffer[i - 1] != GraphBuffer[i] && GraphBuffer[i] >= peak)
{
// Find lowest difference between peaks
if (lastpeak && i - lastpeak < clock)
clock = i - lastpeak;
lastpeak = i;
}
}
return clock;
} }
*/ size_t getFromGraphBuf(uint8_t *buff)
/*
NOW IN LFDEMOD.C
// by marshmellow
// not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
// maybe somehow adjust peak trimming value based on samples to fix?
int DetectASKClock(int peak)
{ {
int i=0; uint32_t i;
int low=0; for (i=0;i<GraphTraceLen;++i){
int clk[]={16,32,40,50,64,100,128,256}; if (GraphBuffer[i]>127) GraphBuffer[i]=127; //trim
int loopCnt = 256; if (GraphBuffer[i]<-127) GraphBuffer[i]=-127; //trim
if (GraphTraceLen<loopCnt) loopCnt = GraphTraceLen; buff[i]=(uint8_t)(GraphBuffer[i]+128);
if (!peak){ }
for (i=0;i<loopCnt;++i){ return i;
if(GraphBuffer[i]>peak){
peak = GraphBuffer[i];
}
if(GraphBuffer[i]<low){
low = GraphBuffer[i];
}
}
peak=(int)(peak*.75);
low= (int)(low*.75);
}
int ii;
int clkCnt;
int tol = 0;
int bestErr=1000;
int errCnt[]={0,0,0,0,0,0,0,0};
for(clkCnt=0; clkCnt<6;++clkCnt){
if (clk[clkCnt]==32){
tol=1;
}else{
tol=0;
}
bestErr=1000;
for (ii=0; ii<loopCnt; ++ii){
if ((GraphBuffer[ii]>=peak) || (GraphBuffer[ii]<=low)){
errCnt[clkCnt]=0;
for (i=0; i<((int)(GraphTraceLen/clk[clkCnt])-1); ++i){
if (GraphBuffer[ii+(i*clk[clkCnt])]>=peak || GraphBuffer[ii+(i*clk[clkCnt])]<=low){
}else if(GraphBuffer[ii+(i*clk[clkCnt])-tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])-tol]<=low){
}else if(GraphBuffer[ii+(i*clk[clkCnt])+tol]>=peak || GraphBuffer[ii+(i*clk[clkCnt])+tol]<=low){
}else{ //error no peak detected
errCnt[clkCnt]++;
}
}
if(errCnt[clkCnt]==0) return clk[clkCnt];
if(errCnt[clkCnt]<bestErr) bestErr=errCnt[clkCnt];
}
}
}
int iii=0;
int best=0;
for (iii=0; iii<6;++iii){
if (errCnt[iii]<errCnt[best]){
best = iii;
}
}
// PrintAndLog("DEBUG: clkCnt: %d, ii: %d, i: %d peak: %d, low: %d, errcnt: %d, errCnt64: %d",clkCnt,ii,i,peak,low,errCnt[best],errCnt[4]);
return clk[best];
} }
*/ // Get or auto-detect clock rate
void setGraphBuf(uint8_t *buff,int size)
{
int i=0;
ClearGraph(0);
for (; i < size; ++i){
GraphBuffer[i]=buff[i];
}
GraphTraceLen=size;
RepaintGraphWindow();
return;
}
int getFromGraphBuf(uint8_t *buff)
{
uint32_t i;
for (i=0;i<GraphTraceLen;++i){
if (GraphBuffer[i]>127) GraphBuffer[i]=127; //trim
if (GraphBuffer[i]<-127) GraphBuffer[i]=-127; //trim
buff[i]=(uint8_t)(GraphBuffer[i]+128);
}
return i;
}
/* Get or auto-detect clock rate */
int GetClock(const char *str, int peak, int verbose) int GetClock(const char *str, int peak, int verbose)
{ {
int clock; int clock;
// int clock2; sscanf(str, "%i", &clock);
sscanf(str, "%i", &clock); if (!strcmp(str, ""))
if (!strcmp(str, "")) clock = 0;
clock = 0;
/* Auto-detect clock */ // Auto-detect clock
if (!clock) if (!clock)
{ {
uint8_t grph[MAX_GRAPH_TRACE_LEN]={0}; uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
int size = getFromGraphBuf(grph); size_t size = getFromGraphBuf(grph);
clock = DetectASKClock(grph,size,0); clock = DetectASKClock(grph,size,0);
//clock2 = DetectClock2(peak); // Only print this message if we're not looping something
/* Only print this message if we're not looping something */ if (!verbose){
if (!verbose){ PrintAndLog("Auto-detected clock rate: %d", clock);
PrintAndLog("Auto-detected clock rate: %d", clock); }
//PrintAndLog("clock2: %d",clock2); }
}
}
return clock; return clock;
}
int GetNRZpskClock(const char *str, int peak, int verbose)
{
int clock;
sscanf(str, "%i", &clock);
if (!strcmp(str, ""))
clock = 0;
// Auto-detect clock
if (!clock)
{
uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
size_t size = getFromGraphBuf(grph);
clock = DetectpskNRZClock(grph,size,0);
// Only print this message if we're not looping something
if (!verbose){
PrintAndLog("Auto-detected clock rate: %d", clock);
}
}
return clock;
} }

View file

@ -15,9 +15,10 @@
void AppendGraph(int redraw, int clock, int bit); void AppendGraph(int redraw, int clock, int bit);
int ClearGraph(int redraw); int ClearGraph(int redraw);
//int DetectClock(int peak); //int DetectClock(int peak);
int getFromGraphBuf(uint8_t *buff); size_t getFromGraphBuf(uint8_t *buff);
int GetClock(const char *str, int peak, int verbose); int GetClock(const char *str, int peak, int verbose);
void setGraphBuf(uint8_t *buff,int size); int GetNRZpskClock(const char *str, int peak, int verbose);
void setGraphBuf(uint8_t *buff, size_t size);
#define MAX_GRAPH_TRACE_LEN (1024*128) #define MAX_GRAPH_TRACE_LEN (1024*128)
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN]; extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
// Copyright (C) 2014 // Copyright (C) 2014
// //
// This code is licensed to you under the terms of the GNU GPL, version 2 or, // This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of // at your option, any later version. See the LICENSE.txt file for the text of
@ -12,14 +12,18 @@
#include <stdint.h> #include <stdint.h>
int DetectASKClock(uint8_t dest[], size_t size, int clock); int DetectASKClock(uint8_t dest[], size_t size, int clock);
int askmandemod(uint8_t *BinStream,uint32_t *BitLen,int *clk, int *invert); int askmandemod(uint8_t *BinStream, size_t *size, int *clk, int *invert);
uint64_t Em410xDecode(uint8_t *BitStream,uint32_t BitLen); uint64_t Em410xDecode(uint8_t *BitStream,size_t size);
int manrawdecode(uint8_t *BitStream, int *bitLen); int manrawdecode(uint8_t *BitStream, size_t *size);
int BiphaseRawDecode(uint8_t * BitStream, int *bitLen, int offset); int BiphaseRawDecode(uint8_t * BitStream, size_t *size, int offset);
int askrawdemod(uint8_t *BinStream, int *bitLen,int *clk, int *invert); int askrawdemod(uint8_t *BinStream, size_t *size, int *clk, int *invert);
int HIDdemodFSK(uint8_t *dest, size_t size, uint32_t *hi2, uint32_t *hi, uint32_t *lo); int HIDdemodFSK(uint8_t *dest, size_t size, uint32_t *hi2, uint32_t *hi, uint32_t *lo);
int IOdemodFSK(uint8_t *dest, size_t size); int IOdemodFSK(uint8_t *dest, size_t size);
int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow); int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow);
uint32_t bytebits_to_byte(uint8_t* src, int numbits); uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert);
int DetectpskNRZClock(uint8_t dest[], size_t size, int clock);
int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert);
void pskCleanWave(uint8_t *bitStream, size_t size);
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -15,3 +15,10 @@ Transit999-best.pm3: Transit 999 format (UID 99531670)
The files 'modulation-'... are all encoded with identical data (hex 00 01 02 03 04 05 06 07 08 09 0A 0B) The files 'modulation-'... are all encoded with identical data (hex 00 01 02 03 04 05 06 07 08 09 0A 0B)
for the purpose of recognition and testing of demodulation schemes. They were created by writing Q5 tags for the purpose of recognition and testing of demodulation schemes. They were created by writing Q5 tags
appropriately configured. The raw data is in 'modulation-data.dat'. appropriately configured. The raw data is in 'modulation-data.dat'.
ata5577-HIDemu-FC1-C9.pm3: ata5577 in hid prox 26 bit emulation facility code:1 card#:9
casi-12ed825c29.pm3: casi rusco 40 bit (EM410x ID: 12ed825c29)
EM4102-Fob.pm3: (ID: 0400193cbe)
ioprox-XSF-01-3B-44725.pm3: IO Prox FSK RF/64 ID in name
ioprox-XSF-01-BE-03011.pm3: IO Prox FSK RF/64 ID in name
indala-504278295.pm3: PSK 26 bit indala