mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
FIX: data plot AutoCorrelate slider, window too big, now limited to number of samples.
enhanced debugstatements, 'lf em 410x_demod' vs 'lf em 410x_read' now read does the same as all other LF, and demod too...
This commit is contained in:
parent
0e31ed346a
commit
91898babc0
9 changed files with 250 additions and 298 deletions
|
@ -929,15 +929,19 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||||
case CMD_SET_LF_SAMPLING_CONFIG:
|
case CMD_SET_LF_SAMPLING_CONFIG:
|
||||||
setSamplingConfig((sample_config *) c->d.asBytes);
|
setSamplingConfig((sample_config *) c->d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
|
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K: {
|
||||||
cmd_send(CMD_ACK,SampleLF(c->arg[0], c->arg[1]),0,0,0,0);
|
uint32_t bits = SampleLF(c->arg[0], c->arg[1]);
|
||||||
|
cmd_send(CMD_ACK, bits, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
|
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
|
||||||
ModThenAcquireRawAdcSamples125k(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
ModThenAcquireRawAdcSamples125k(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
||||||
break;
|
break;
|
||||||
case CMD_LF_SNOOP_RAW_ADC_SAMPLES:
|
case CMD_LF_SNOOP_RAW_ADC_SAMPLES: {
|
||||||
cmd_send(CMD_ACK,SnoopLF(),0,0,0,0);
|
uint32_t bits = SnoopLF();
|
||||||
|
cmd_send(CMD_ACK, bits, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CMD_HID_DEMOD_FSK:
|
case CMD_HID_DEMOD_FSK:
|
||||||
CmdHIDdemodFSK(c->arg[0], 0, 0, 1);
|
CmdHIDdemodFSK(c->arg[0], 0, 0, 1);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -299,15 +299,14 @@ int CmdSetDebugMode(const char *Cmd) {
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
// max output to 512 bits if we have more - should be plenty
|
// max output to 512 bits if we have more - should be plenty
|
||||||
void printDemodBuff(void) {
|
void printDemodBuff(void) {
|
||||||
int bitLen = DemodBufferLen;
|
int len = DemodBufferLen;
|
||||||
if (bitLen < 1) {
|
if (len < 1) {
|
||||||
PrintAndLog("no bits found in demod buffer");
|
PrintAndLog("(printDemodBuff) no bits found in demod buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (bitLen > 512) bitLen = 512;
|
if (len > 512) len = 512;
|
||||||
|
|
||||||
char *bin = sprint_bin_break(DemodBuffer, bitLen,16);
|
PrintAndLog("%s", sprint_bin_break(DemodBuffer, len, 16) );
|
||||||
PrintAndLog("%s",bin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdPrintDemodBuff(const char *Cmd) {
|
int CmdPrintDemodBuff(const char *Cmd) {
|
||||||
|
@ -392,20 +391,29 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
|
||||||
uint8_t askamp = 0;
|
uint8_t askamp = 0;
|
||||||
char amp = param_getchar(Cmd, 0);
|
char amp = param_getchar(Cmd, 0);
|
||||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
|
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
|
||||||
|
|
||||||
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &);
|
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &);
|
||||||
if (!maxLen) maxLen = BIGBUF_SIZE;
|
|
||||||
|
if (!maxLen) maxLen = MAX_GRAPH_TRACE_LEN;
|
||||||
|
|
||||||
if (invert != 0 && invert != 1) {
|
if (invert != 0 && invert != 1) {
|
||||||
PrintAndLog("Invalid argument: %s", Cmd);
|
PrintAndLog("Invalid argument: %s", Cmd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (clk==1){
|
|
||||||
invert=1;
|
if (clk == 1) {
|
||||||
clk=0;
|
invert = 1;
|
||||||
|
clk = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BitLen = getFromGraphBuf(BitStream);
|
size_t BitLen = getFromGraphBuf(BitStream);
|
||||||
if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d", BitLen);
|
|
||||||
if (BitLen<255) return 0;
|
if (g_debugMode) PrintAndLog("DEBUG: (ASKDemod_ext) Bitlen from grphbuff: %d", BitLen);
|
||||||
if (maxLen<BitLen && maxLen != 0) BitLen = maxLen;
|
|
||||||
|
if (BitLen < 255) return 0;
|
||||||
|
|
||||||
|
if (maxLen < BitLen && maxLen != 0) BitLen = maxLen;
|
||||||
|
|
||||||
int foundclk = 0;
|
int foundclk = 0;
|
||||||
//amp before ST check
|
//amp before ST check
|
||||||
if (amp == 'a' || amp == 'A')
|
if (amp == 'a' || amp == 'A')
|
||||||
|
@ -414,31 +422,39 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
|
||||||
bool st = false;
|
bool st = false;
|
||||||
size_t ststart = 0, stend = 0;
|
size_t ststart = 0, stend = 0;
|
||||||
if (*stCheck) st = DetectST(BitStream, &BitLen, &foundclk, &ststart, &stend);
|
if (*stCheck) st = DetectST(BitStream, &BitLen, &foundclk, &ststart, &stend);
|
||||||
|
|
||||||
if (st) {
|
if (st) {
|
||||||
*stCheck = st;
|
*stCheck = st;
|
||||||
clk = (clk == 0) ? foundclk : clk;
|
clk = (clk == 0) ? foundclk : clk;
|
||||||
CursorCPos = ststart;
|
CursorCPos = ststart;
|
||||||
CursorDPos = stend;
|
CursorDPos = stend;
|
||||||
if (verbose || g_debugMode) PrintAndLog("\nFound Sequence Terminator - First one is shown by orange and blue graph markers");
|
if (verbose || g_debugMode)
|
||||||
|
PrintAndLog("Found Sequence Terminator - First one is shown by orange and blue graph markers");
|
||||||
}
|
}
|
||||||
|
|
||||||
int startIdx = 0;
|
int startIdx = 0;
|
||||||
int errCnt = askdemod_ext(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType, &startIdx);
|
int errCnt = askdemod_ext(BitStream, &BitLen, &clk, &invert, maxErr, askamp, askType, &startIdx);
|
||||||
if (errCnt<0 || BitLen<16){ //if fatal error (or -1)
|
|
||||||
if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
|
if (errCnt < 0 || BitLen < 16){ //if fatal error (or -1)
|
||||||
|
if (g_debugMode)
|
||||||
|
PrintAndLog("DEBUG: (ASKDemod_ext) No data found errors:%d, invert:%d, bitlen:%d, clock:%d", errCnt, invert, BitLen, clk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errCnt > maxErr){
|
if (errCnt > maxErr){
|
||||||
if (g_debugMode) PrintAndLog("DEBUG: Too many errors found, errors:%d, bits:%d, clock:%d",errCnt, BitLen, clk);
|
if (g_debugMode)
|
||||||
|
PrintAndLog("DEBUG: (ASKDemod_ext) Too many errors found, errors:%d, bits:%d, clock:%d", errCnt, BitLen, clk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen);
|
|
||||||
|
if (verbose || g_debugMode) PrintAndLog("DEBUG: (ASKDemod_ext) Using clock:%d, invert:%d, bits found:%d", clk, invert, BitLen);
|
||||||
|
|
||||||
//output
|
//output
|
||||||
setDemodBuf(BitStream,BitLen,0);
|
setDemodBuf(BitStream,BitLen,0);
|
||||||
setClockGrid(clk, startIdx);
|
setClockGrid(clk, startIdx);
|
||||||
|
|
||||||
if (verbose || g_debugMode){
|
if (verbose || g_debugMode){
|
||||||
if (errCnt>0)
|
if (errCnt > 0)
|
||||||
PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||||
if (askType)
|
if (askType)
|
||||||
PrintAndLog("ASK/Manchester - Clock: %d - Decoded bitstream:",clk);
|
PrintAndLog("ASK/Manchester - Clock: %d - Decoded bitstream:",clk);
|
||||||
|
@ -636,11 +652,16 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph
|
||||||
size_t Correlation = 0;
|
size_t Correlation = 0;
|
||||||
int maxSum = 0;
|
int maxSum = 0;
|
||||||
int lastMax = 0;
|
int lastMax = 0;
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
if ( window > len ) window = len;
|
||||||
|
|
||||||
if (verbose) PrintAndLog("performing %d correlations", GraphTraceLen - window);
|
if (verbose) PrintAndLog("performing %d correlations", GraphTraceLen - window);
|
||||||
|
|
||||||
for (int i = 0; i < len - window; ++i) {
|
for (int i = 0; i < len - window; ++i) {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int j = 0; j < window; ++j) {
|
for (int j = 0; j < window; ++j) {
|
||||||
sum += (in[j]*in[i + j]) / 256;
|
sum += (in[j] * in[i + j]) / 256;
|
||||||
}
|
}
|
||||||
CorrelBuffer[i] = sum;
|
CorrelBuffer[i] = sum;
|
||||||
if (sum >= maxSum-100 && sum <= maxSum+100){
|
if (sum >= maxSum-100 && sum <= maxSum+100){
|
||||||
|
@ -649,7 +670,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph
|
||||||
lastMax = i;
|
lastMax = i;
|
||||||
if (sum > maxSum) maxSum = sum;
|
if (sum > maxSum) maxSum = sum;
|
||||||
} else if (sum > maxSum){
|
} else if (sum > maxSum){
|
||||||
maxSum=sum;
|
maxSum = sum;
|
||||||
lastMax = i;
|
lastMax = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -789,9 +810,9 @@ int CmdGraphShiftZero(const char *Cmd) {
|
||||||
int AskEdgeDetect(const int *in, int *out, int len, int threshold) {
|
int AskEdgeDetect(const int *in, int *out, int len, int threshold) {
|
||||||
int last = 0;
|
int last = 0;
|
||||||
for(int i = 1; i<len; i++) {
|
for(int i = 1; i<len; i++) {
|
||||||
if (in[i]-in[i-1] >= threshold) //large jump up
|
if (in[i] - in[i-1] >= threshold) //large jump up
|
||||||
last = 127;
|
last = 127;
|
||||||
else if(in[i]-in[i-1] <= -1 * threshold) //large jump down
|
else if (in[i] - in[i-1] <= -1 * threshold) //large jump down
|
||||||
last = -127;
|
last = -127;
|
||||||
out[i-1] = last;
|
out[i-1] = last;
|
||||||
}
|
}
|
||||||
|
@ -919,7 +940,7 @@ int FSKrawDemod(const char *Cmd, bool verbose)
|
||||||
|
|
||||||
// Now output the bitstream to the scrollback by line of 16 bits
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
if (verbose || g_debugMode) {
|
if (verbose || g_debugMode) {
|
||||||
PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", rfLen, invert, fchigh, fclow);
|
PrintAndLog("DEBUG: (FSKrawDemod) Using Clock:%u, invert:%u, fchigh:%u, fclow:%u", rfLen, invert, fchigh, fclow);
|
||||||
PrintAndLog("%s decoded bitstream:", GetFSKType(fchigh, fclow, invert));
|
PrintAndLog("%s decoded bitstream:", GetFSKType(fchigh, fclow, invert));
|
||||||
printDemodBuff();
|
printDemodBuff();
|
||||||
}
|
}
|
||||||
|
@ -963,17 +984,17 @@ int PSKDemod(const char *Cmd, bool verbose)
|
||||||
int startIdx = 0;
|
int startIdx = 0;
|
||||||
errCnt = pskRawDemod_ext(BitStream, &BitLen, &clk, &invert, &startIdx);
|
errCnt = pskRawDemod_ext(BitStream, &BitLen, &clk, &invert, &startIdx);
|
||||||
if (errCnt > maxErr){
|
if (errCnt > maxErr){
|
||||||
if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
|
if (g_debugMode || verbose) PrintAndLog("DEBUG: (PSKdemod) Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
||||||
if (g_debugMode || verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
|
if (g_debugMode || verbose) PrintAndLog("DEBUG: (PSKdemod) no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d", clk, invert, BitLen, errCnt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (verbose || g_debugMode){
|
if (verbose || g_debugMode){
|
||||||
PrintAndLog("\nUsing Clock:%d, invert:%d, Bits Found:%d",clk,invert,BitLen);
|
PrintAndLog("DEBUG: (PSKdemod) Using Clock:%d, invert:%d, Bits Found:%d",clk,invert,BitLen);
|
||||||
if (errCnt>0){
|
if (errCnt>0){
|
||||||
PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
PrintAndLog("DEBUG: (PSKdemod) errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//prime demod buffer for output
|
//prime demod buffer for output
|
||||||
|
@ -1055,7 +1076,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
|
||||||
clk=0;
|
clk=0;
|
||||||
}
|
}
|
||||||
if (invert != 0 && invert != 1) {
|
if (invert != 0 && invert != 1) {
|
||||||
PrintAndLog("Invalid argument: %s", Cmd);
|
PrintAndLog("(NRZrawDemod) Invalid argument: %s", Cmd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
||||||
|
@ -1065,20 +1086,20 @@ int NRZrawDemod(const char *Cmd, bool verbose)
|
||||||
int clkStartIdx = 0;
|
int clkStartIdx = 0;
|
||||||
errCnt = nrzRawDemod(BitStream, &BitLen, &clk, &invert, &clkStartIdx);
|
errCnt = nrzRawDemod(BitStream, &BitLen, &clk, &invert, &clkStartIdx);
|
||||||
if (errCnt > maxErr){
|
if (errCnt > maxErr){
|
||||||
if (g_debugMode) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
if (g_debugMode) PrintAndLog("DEBUG: (NRZrawDemod) Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (errCnt<0 || BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
if (errCnt<0 || BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
||||||
if (g_debugMode) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
if (g_debugMode) PrintAndLog("DEBUG: (NRZrawDemod) no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (verbose || g_debugMode) PrintAndLog("Tried NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
|
if (verbose || g_debugMode) PrintAndLog("DEBUG: (NRZrawDemod) Tried NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
|
||||||
//prime demod buffer for output
|
//prime demod buffer for output
|
||||||
setDemodBuf(BitStream,BitLen,0);
|
setDemodBuf(BitStream,BitLen,0);
|
||||||
setClockGrid(clk, clkStartIdx);
|
setClockGrid(clk, clkStartIdx);
|
||||||
|
|
||||||
|
|
||||||
if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("DEBUG: (NRZrawDemod) Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||||
if (verbose || g_debugMode) {
|
if (verbose || g_debugMode) {
|
||||||
PrintAndLog("NRZ demoded bitstream:");
|
PrintAndLog("NRZ demoded bitstream:");
|
||||||
// Now output the bitstream to the scrollback by line of 16 bits
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
|
@ -1170,7 +1191,7 @@ int CmdRawDemod(const char *Cmd)
|
||||||
void setClockGrid(int clk, int offset) {
|
void setClockGrid(int clk, int offset) {
|
||||||
g_DemodStartIdx = offset;
|
g_DemodStartIdx = offset;
|
||||||
g_DemodClock = clk;
|
g_DemodClock = clk;
|
||||||
if (g_debugMode) PrintAndLog("demodoffset %d, clk %d",offset,clk);
|
if (g_debugMode) PrintAndLog("DBEUG: (setClockGrid) demodoffset %d, clk %d",offset,clk);
|
||||||
|
|
||||||
if (offset > clk) offset %= clk;
|
if (offset > clk) offset %= clk;
|
||||||
if (offset < 0) offset += clk;
|
if (offset < 0) offset += clk;
|
||||||
|
@ -1338,7 +1359,7 @@ int getSamples(int n, bool silent)
|
||||||
GraphTraceLen = n;
|
GraphTraceLen = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClockGrid(0,0);
|
setClockGrid(0, 0);
|
||||||
DemodBufferLen = 0;
|
DemodBufferLen = 0;
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
169
client/cmdlf.c
169
client/cmdlf.c
|
@ -335,7 +335,8 @@ bool lf_read(bool silent, uint32_t samples) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getSamples(resp.arg[0], silent);
|
// resp.arg[0] is bits read not bytes read.
|
||||||
|
getSamples(resp.arg[0]/8, silent);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -816,13 +817,13 @@ int CheckChipType(bool getDeviceData) {
|
||||||
|
|
||||||
if (!getDeviceData) return 0;
|
if (!getDeviceData) return 0;
|
||||||
|
|
||||||
uint32_t word = 0;
|
save_restoreDB(GRAPH_SAVE);
|
||||||
save_restoreGB(GRAPH_SAVE);
|
|
||||||
|
|
||||||
//check for em4x05/em4x69 chips first
|
//check for em4x05/em4x69 chips first
|
||||||
|
uint32_t word = 0;
|
||||||
if (EM4x05IsBlock0(&word)) {
|
if (EM4x05IsBlock0(&word)) {
|
||||||
|
PrintAndLog("\nValid EM4x05/EM4x69 Chip Found\nTry lf em 4x05... commands\n");
|
||||||
save_restoreGB(GRAPH_RESTORE);
|
save_restoreGB(GRAPH_RESTORE);
|
||||||
PrintAndLog("\nValid EM4x05/EM4x69 Chipset found\nTry `lf em 4x05` commands\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,7 +831,6 @@ int CheckChipType(bool getDeviceData) {
|
||||||
if (tryDetectP1(true)) {
|
if (tryDetectP1(true)) {
|
||||||
PrintAndLog("\nValid T55xx Chip Found\nTry `lf t55xx` commands\n");
|
PrintAndLog("\nValid T55xx Chip Found\nTry `lf t55xx` commands\n");
|
||||||
save_restoreGB(GRAPH_RESTORE);
|
save_restoreGB(GRAPH_RESTORE);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,20 +866,13 @@ int CmdLFfind(const char *Cmd) {
|
||||||
if (getDeviceData) {
|
if (getDeviceData) {
|
||||||
|
|
||||||
// only run if graphbuffer is just noise as it should be for hitag/cotag
|
// only run if graphbuffer is just noise as it should be for hitag/cotag
|
||||||
if (graphJustNoise(GraphBuffer, testLen)) {
|
if (is_justnoise(GraphBuffer, testLen)) {
|
||||||
|
|
||||||
if (CheckChipType(getDeviceData) )
|
if (CheckChipType(getDeviceData) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
ans=CmdLFHitagReader("26");
|
ans=CmdLFHitagReader("26"); if (ans==0) {PrintAndLog("\nValid Hitag Found!");return 1;}
|
||||||
if (ans==0)
|
ans=CmdCOTAGRead(""); if (ans>0) {PrintAndLog("\nValid COTAG ID Found!"); return 1;}
|
||||||
return 1;
|
|
||||||
|
|
||||||
ans=CmdCOTAGRead("");
|
|
||||||
if (ans>0){
|
|
||||||
PrintAndLog("\nValid COTAG ID Found!");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
PrintAndLog("Signal looks just like noise. Quitting.");
|
PrintAndLog("Signal looks just like noise. Quitting.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -888,135 +881,32 @@ int CmdLFfind(const char *Cmd) {
|
||||||
// identify chipset
|
// identify chipset
|
||||||
CheckChipType(getDeviceData);
|
CheckChipType(getDeviceData);
|
||||||
|
|
||||||
ans=CmdIOProxDemod("");
|
ans=CmdAWIDDemod(""); if (ans>0) { PrintAndLog("\nValid AWID ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
if (ans>0) {
|
ans=CmdEM410xDemod(""); if (ans>0) { PrintAndLog("\nValid EM410x ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
PrintAndLog("\nValid IO Prox ID Found!");
|
ans=EM4x50Read("", false); if (ans>0) { PrintAndLog("\nValid EM4x50 ID Found!"); return 1;}
|
||||||
return CheckChipType(getDeviceData);
|
ans=CmdFdxDemod(""); if (ans>0) { PrintAndLog("\nValid FDX-B ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
}
|
ans=CmdGuardDemod(""); if (ans>0) { PrintAndLog("\nValid Guardall G-Prox II ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
|
ans=CmdHIDDemod(""); if (ans>0) { PrintAndLog("\nValid HID Prox ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
|
ans=CmdPSKIdteck(""); if (ans>0) { PrintAndLog("\nValid Idteck ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
|
|
||||||
ans=CmdPyramidDemod("");
|
ans=CmdIndalaDemod(""); if (ans>0) { PrintAndLog("\nValid Indala ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
if (ans>0) {
|
ans=CmdIOProxDemod(""); if (ans>0) { PrintAndLog("\nValid IO Prox ID Found!");return CheckChipType(getDeviceData);}
|
||||||
PrintAndLog("\nValid Pyramid ID Found!");
|
ans=CmdJablotronDemod(""); if (ans>0) { PrintAndLog("\nValid Jablotron ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdParadoxDemod("");
|
ans=CmdLFNedapDemod(""); if (ans>0) { PrintAndLog("\nValid NEDAP ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
if (ans>0) {
|
ans=CmdNexWatchDemod(""); if (ans>0) { PrintAndLog("\nValid NexWatch ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
PrintAndLog("\nValid Paradox ID Found!");
|
ans=CmdNoralsyDemod(""); if (ans>0) { PrintAndLog("\nValid Noralsy ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdAWIDDemod("");
|
ans=CmdPacDemod(""); if (ans>0) { PrintAndLog("\nValid PAC/Stanley ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
if (ans>0) {
|
ans=CmdParadoxDemod(""); if (ans>0) { PrintAndLog("\nValid Paradox ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
PrintAndLog("\nValid AWID ID Found!");
|
ans=CmdPrescoDemod(""); if (ans>0) { PrintAndLog("\nValid Presco ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
return CheckChipType(getDeviceData);
|
ans=CmdPyramidDemod(""); if (ans>0) { PrintAndLog("\nValid Pyramid ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdHIDDemod("");
|
ans=CmdSecurakeyDemod(""); if (ans>0) { PrintAndLog("\nValid Securakey ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
if (ans>0) {
|
ans=CmdVikingDemod(""); if (ans>0) { PrintAndLog("\nValid Viking ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
PrintAndLog("\nValid HID Prox ID Found!");
|
ans=CmdVisa2kDemod(""); if (ans>0) { PrintAndLog("\nValid Visa2000 ID Found!"); return CheckChipType(getDeviceData);}
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdAskEM410xDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid EM410x ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdVisa2kDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Visa2000 ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdGuardDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Guardall G-Prox II ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdFdxDemod(""); //biphase
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid FDX-B ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=EM4x50Read("", false);
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid EM4x50 ID Found!");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdJablotronDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Jablotron ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdNoralsyDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Noralsy ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdSecurakeyDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Securakey ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdVikingDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Viking ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdIndalaDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Indala ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
ans=CmdNexWatchDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid NexWatch ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdPSKIdteck("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Idteck ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdJablotronDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Jablotron ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdLFNedapDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid NEDAP ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdVisa2kDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Visa2000 ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdNoralsyDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Noralsy ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdPrescoDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid Presco ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
ans=CmdPacDemod("");
|
|
||||||
if (ans>0) {
|
|
||||||
PrintAndLog("\nValid PAC/Stanley ID Found!");
|
|
||||||
return CheckChipType(getDeviceData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TIdemod?
|
// TIdemod?
|
||||||
PrintAndLog("\nNo Known Tags Found!\n");
|
PrintAndLog("\nNo Known Tags Found!\n");
|
||||||
if (testRaw=='u' || testRaw=='U'){
|
if (testRaw=='u' || testRaw=='U'){
|
||||||
|
@ -1074,6 +964,7 @@ int CmdLFfind(const char *Cmd) {
|
||||||
PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
|
PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
|
||||||
return CheckChipType(getDeviceData);
|
return CheckChipType(getDeviceData);
|
||||||
}
|
}
|
||||||
|
ans = CheckChipType(getDeviceData);
|
||||||
PrintAndLog("\nNo Data Found!\n");
|
PrintAndLog("\nNo Data Found!\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -16,16 +16,16 @@ static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
//////////////// 410x commands
|
//////////////// 410x commands
|
||||||
int usage_lf_em410x_demod(void){
|
int usage_lf_em410x_demod(void){
|
||||||
PrintAndLog("Usage: data askem410xdemod [clock] <0|1> [maxError]");
|
PrintAndLog("Usage: lf em 410x_demod [clock] <0|1> [maxError]");
|
||||||
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
PrintAndLog(" [set clock as integer] optional, if not set, autodetect.");
|
||||||
PrintAndLog(" <invert>, 1 for invert output");
|
PrintAndLog(" <invert>, 1 for invert output");
|
||||||
PrintAndLog(" [set maximum allowed errors], default = 100.");
|
PrintAndLog(" [set maximum allowed errors], default = 100.");
|
||||||
PrintAndLog("");
|
PrintAndLog("");
|
||||||
PrintAndLog(" sample: data askem410xdemod = demod an EM410x Tag ID from GraphBuffer");
|
PrintAndLog(" sample: lf em 410x_demod = demod an EM410x Tag ID from GraphBuffer");
|
||||||
PrintAndLog(" : data askem410xdemod 32 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/32");
|
PrintAndLog(" : lf em 410x_demod 32 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/32");
|
||||||
PrintAndLog(" : data askem410xdemod 32 1 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/32 and inverting data");
|
PrintAndLog(" : lf em 410x_demod 32 1 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/32 and inverting data");
|
||||||
PrintAndLog(" : data askem410xdemod 1 = demod an EM410x Tag ID from GraphBuffer while inverting data");
|
PrintAndLog(" : lf em 410x_demod 1 = demod an EM410x Tag ID from GraphBuffer while inverting data");
|
||||||
PrintAndLog(" : data askem410xdemod 64 1 0 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/64 and inverting data and allowing 0 demod errors");
|
PrintAndLog(" : lf em 410x_demod 64 1 0 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/64 and inverting data and allowing 0 demod errors");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int usage_lf_em410x_write(void) {
|
int usage_lf_em410x_write(void) {
|
||||||
|
@ -188,6 +188,14 @@ int usage_lf_em4x05_info(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read the ID of an EM410x tag.
|
||||||
|
* Format:
|
||||||
|
* 1111 1111 1 <-- standard non-repeatable header
|
||||||
|
* XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
|
||||||
|
* ....
|
||||||
|
* CCCC <-- each bit here is parity for the 10 bits above in corresponding column
|
||||||
|
* 0 <-- stop bit, end of tag
|
||||||
|
*/
|
||||||
|
|
||||||
// Construct the graph for emulating an EM410X tag
|
// Construct the graph for emulating an EM410X tag
|
||||||
void ConstructEM410xEmulGraph(const char *uid,const uint8_t clock) {
|
void ConstructEM410xEmulGraph(const char *uid,const uint8_t clock) {
|
||||||
|
@ -342,19 +350,25 @@ void printEM410x(uint32_t hi, uint64_t id) {
|
||||||
*/
|
*/
|
||||||
int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
|
int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
size_t size = DemodBufferLen;
|
uint8_t bits[512] = {0};
|
||||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
|
size_t size = sizeof(bits);
|
||||||
memcpy(BitStream, DemodBuffer, size);
|
if ( !getDemodBuf(bits, &size) ) {
|
||||||
int ans = Em410xDecode(BitStream, &size, &idx, hi, lo);
|
PrintAndLog("DEBUG: Error - Em410x problem during copy from ASK demod");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ans = Em410xDecode(bits, &size, &idx, hi, lo);
|
||||||
if ( ans < 0){
|
if ( ans < 0){
|
||||||
if (g_debugMode){
|
if (g_debugMode){
|
||||||
if (ans == -1)
|
if (ans == -1)
|
||||||
PrintAndLog("DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
|
PrintAndLog("DEBUG: Error - Em410x not only 0|1 in decoded bitstream");
|
||||||
else if (ans == -2)
|
else if (ans == -2)
|
||||||
PrintAndLog("DEBUG: Error - Em410x preamble not found");
|
PrintAndLog("DEBUG: Error - Em410x not enough samples after demod");
|
||||||
else if (ans == -3)
|
|
||||||
PrintAndLog("DEBUG: Error - Em410x Size not correct: %d", size);
|
|
||||||
else if (ans == -4)
|
else if (ans == -4)
|
||||||
|
PrintAndLog("DEBUG: Error - Em410x preamble not found");
|
||||||
|
else if (ans == -5)
|
||||||
|
PrintAndLog("DEBUG: Error - Em410x Size not correct: %d", size);
|
||||||
|
else if (ans == -6)
|
||||||
PrintAndLog("DEBUG: Error - Em410x parity failed");
|
PrintAndLog("DEBUG: Error - Em410x parity failed");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -365,12 +379,14 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//set GraphBuffer for clone or sim command
|
//set GraphBuffer for clone or sim command
|
||||||
setDemodBuf(BitStream, size, idx);
|
setDemodBuf(DemodBuffer, (size==40) ? 64 : 128, idx+1);
|
||||||
|
setClockGrid(g_DemodClock, g_DemodStartIdx + ((idx+1)*g_DemodClock));
|
||||||
if (g_debugMode){
|
if (g_debugMode){
|
||||||
PrintAndLog("DEBUG: Em410x idx: %d, Len: %d, Printing Demod Buffer:", idx, size);
|
PrintAndLog("DEBUG: Em410x idx: %d, Len: %d, Printing Demod Buffer:", idx, size);
|
||||||
printDemodBuff();
|
printDemodBuff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("ice B %d \n", verbose);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printEM410x(*hi, *lo);
|
printEM410x(*hi, *lo);
|
||||||
|
|
||||||
|
@ -382,21 +398,16 @@ int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) {
|
||||||
return AskEm410xDecode(verbose, hi, lo);
|
return AskEm410xDecode(verbose, hi, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//by marshmellow
|
// this read is the "normal" read, which download lf signal and tries to demod here.
|
||||||
//takes 3 arguments - clock, invert and maxErr as integers
|
int CmdEM410xRead(const char *Cmd) {
|
||||||
//attempts to demodulate ask while decoding manchester
|
lf_read(true, 8192);
|
||||||
//prints binary found and saves in graphbuffer for further commands
|
CmdEM410xDemod(Cmd);
|
||||||
int CmdAskEM410xDemod(const char *Cmd) {
|
return 0;
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
|
||||||
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H')
|
|
||||||
return usage_lf_em410x_demod();
|
|
||||||
|
|
||||||
uint64_t lo = 0;
|
|
||||||
uint32_t hi = 0;
|
|
||||||
return AskEm410xDemod(Cmd, &hi, &lo, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdEMdemodASK(const char *Cmd) {
|
// this read loops on device side.
|
||||||
|
// uses the demod in lfops.c
|
||||||
|
int CmdEM410xRead_device(const char *Cmd) {
|
||||||
char cmdp = param_getchar(Cmd, 0);
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
uint8_t findone = (cmdp == '1') ? 1 : 0;
|
uint8_t findone = (cmdp == '1') ? 1 : 0;
|
||||||
UsbCommand c = {CMD_EM410X_DEMOD, {findone, 0, 0}};
|
UsbCommand c = {CMD_EM410X_DEMOD, {findone, 0, 0}};
|
||||||
|
@ -404,21 +415,19 @@ int CmdEMdemodASK(const char *Cmd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the ID of an EM410x tag.
|
//by marshmellow
|
||||||
* Format:
|
//takes 3 arguments - clock, invert and maxErr as integers
|
||||||
* 1111 1111 1 <-- standard non-repeatable header
|
//attempts to demodulate ask while decoding manchester
|
||||||
* XXXX [row parity bit] <-- 10 rows of 5 bits for our 40 bit tag ID
|
//prints binary found and saves in graphbuffer for further commands
|
||||||
* ....
|
int CmdEM410xDemod(const char *Cmd) {
|
||||||
* CCCC <-- each bit here is parity for the 10 bits above in corresponding column
|
char cmdp = param_getchar(Cmd, 0);
|
||||||
* 0 <-- stop bit, end of tag
|
if (strlen(Cmd) > 10 || cmdp == 'h' || cmdp == 'H') return usage_lf_em410x_demod();
|
||||||
*/
|
|
||||||
int CmdEM410xRead(const char *Cmd) {
|
|
||||||
uint32_t hi = 0;
|
uint32_t hi = 0;
|
||||||
uint64_t lo = 0;
|
uint64_t lo = 0;
|
||||||
|
|
||||||
if(!AskEm410xDemod("", &hi, &lo, false)) return 0;
|
if(AskEm410xDemod(Cmd, &hi, &lo, true) != 1) return 0;
|
||||||
|
|
||||||
printEM410x(hi, lo);
|
|
||||||
g_em410xid = lo;
|
g_em410xid = lo;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1138,7 +1147,7 @@ int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int testLen = (GraphTraceLen < 1000) ? GraphTraceLen : 1000;
|
int testLen = (GraphTraceLen < 1000) ? GraphTraceLen : 1000;
|
||||||
if (graphJustNoise(GraphBuffer, testLen)) {
|
if (is_justnoise(GraphBuffer, testLen)) {
|
||||||
PrintAndLog("no tag found");
|
PrintAndLog("no tag found");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1414,7 +1423,8 @@ int CmdEM4x05Info(const char *Cmd) {
|
||||||
|
|
||||||
static command_t CommandTable[] = {
|
static command_t CommandTable[] = {
|
||||||
{"help", CmdHelp, 1, "This help"},
|
{"help", CmdHelp, 1, "This help"},
|
||||||
{"410x_demod", CmdEMdemodASK, 0, "Extract ID from EM410x tag on antenna)"},
|
//{"410x_demod", CmdEMdemodASK, 0, "Extract ID from EM410x tag on antenna)"},
|
||||||
|
{"410x_demod", CmdEM410xDemod, 0, "Extract ID from EM410x tag on antenna)"},
|
||||||
{"410x_read", CmdEM410xRead, 1, "Extract ID from EM410x tag from GraphBuffer"},
|
{"410x_read", CmdEM410xRead, 1, "Extract ID from EM410x tag from GraphBuffer"},
|
||||||
{"410x_sim", CmdEM410xSim, 0, "simulate EM410x tag"},
|
{"410x_sim", CmdEM410xSim, 0, "simulate EM410x tag"},
|
||||||
{"410x_brute", CmdEM410xBrute, 0, "Reader bruteforce attack by simulating EM410x tags"},
|
{"410x_brute", CmdEM410xBrute, 0, "Reader bruteforce attack by simulating EM410x tags"},
|
||||||
|
|
|
@ -28,10 +28,9 @@
|
||||||
|
|
||||||
extern int CmdLFEM4X(const char *Cmd);
|
extern int CmdLFEM4X(const char *Cmd);
|
||||||
|
|
||||||
extern int CmdEMdemodASK(const char *Cmd);
|
|
||||||
extern int CmdAskEM410xDemod(const char *Cmd);
|
|
||||||
extern int CmdEM410xRead(const char *Cmd);
|
|
||||||
|
|
||||||
|
extern int CmdEM410xDemod(const char *Cmd);
|
||||||
|
extern int CmdEM410xRead(const char *Cmd);
|
||||||
extern int CmdEM410xSim(const char *Cmd);
|
extern int CmdEM410xSim(const char *Cmd);
|
||||||
extern int CmdEM410xBrute(const char *Cmd);
|
extern int CmdEM410xBrute(const char *Cmd);
|
||||||
extern int CmdEM410xWatch(const char *Cmd);
|
extern int CmdEM410xWatch(const char *Cmd);
|
||||||
|
@ -52,7 +51,6 @@ extern void printEM410x(uint32_t hi, uint64_t id);
|
||||||
extern int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo );
|
extern int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo );
|
||||||
extern int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose);
|
extern int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose);
|
||||||
|
|
||||||
|
|
||||||
extern int usage_lf_em410x_sim(void);
|
extern int usage_lf_em410x_sim(void);
|
||||||
extern int usage_lf_em410x_ws(void);
|
extern int usage_lf_em410x_ws(void);
|
||||||
extern int usage_lf_em410x_clone(void);
|
extern int usage_lf_em410x_clone(void);
|
||||||
|
|
|
@ -18,12 +18,10 @@
|
||||||
|
|
||||||
int GraphBuffer[MAX_GRAPH_TRACE_LEN];
|
int GraphBuffer[MAX_GRAPH_TRACE_LEN];
|
||||||
int GraphTraceLen;
|
int GraphTraceLen;
|
||||||
|
|
||||||
int s_Buff[MAX_GRAPH_TRACE_LEN];
|
int s_Buff[MAX_GRAPH_TRACE_LEN];
|
||||||
|
|
||||||
/* write a manchester bit to the graph */
|
/* write a manchester bit to the graph */
|
||||||
void AppendGraph(int redraw, int clock, int bit)
|
void AppendGraph(int redraw, int clock, int bit) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
//set first half the clock bit (all 1's or 0's for a 0 or 1 bit)
|
//set first half the clock bit (all 1's or 0's for a 0 or 1 bit)
|
||||||
for (i = 0; i < (int)(clock / 2); ++i)
|
for (i = 0; i < (int)(clock / 2); ++i)
|
||||||
|
@ -37,8 +35,7 @@ void AppendGraph(int redraw, int clock, int bit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear out our graph window
|
// clear out our graph window
|
||||||
int ClearGraph(int redraw)
|
int ClearGraph(int redraw) {
|
||||||
{
|
|
||||||
int gtl = GraphTraceLen;
|
int gtl = GraphTraceLen;
|
||||||
memset(GraphBuffer, 0x00, GraphTraceLen);
|
memset(GraphBuffer, 0x00, GraphTraceLen);
|
||||||
GraphTraceLen = 0;
|
GraphTraceLen = 0;
|
||||||
|
@ -47,17 +44,16 @@ int ClearGraph(int redraw)
|
||||||
return gtl;
|
return gtl;
|
||||||
}
|
}
|
||||||
// option '1' to save GraphBuffer any other to restore
|
// option '1' to save GraphBuffer any other to restore
|
||||||
void save_restoreGB(uint8_t saveOpt)
|
void save_restoreGB(uint8_t saveOpt) {
|
||||||
{
|
|
||||||
static int SavedGB[MAX_GRAPH_TRACE_LEN];
|
static int SavedGB[MAX_GRAPH_TRACE_LEN];
|
||||||
static int SavedGBlen=0;
|
static int SavedGBlen = 0;
|
||||||
static bool GB_Saved = false;
|
static bool GB_Saved = false;
|
||||||
static int SavedGridOffsetAdj=0;
|
static int SavedGridOffsetAdj = 0;
|
||||||
|
|
||||||
if (saveOpt == GRAPH_SAVE) { //save
|
if (saveOpt == GRAPH_SAVE) { //save
|
||||||
memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
|
memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
|
||||||
SavedGBlen = GraphTraceLen;
|
SavedGBlen = GraphTraceLen;
|
||||||
GB_Saved=true;
|
GB_Saved = true;
|
||||||
SavedGridOffsetAdj = GridOffset;
|
SavedGridOffsetAdj = GridOffset;
|
||||||
} else if (GB_Saved){ //restore
|
} else if (GB_Saved){ //restore
|
||||||
memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
|
memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
|
||||||
|
@ -69,9 +65,8 @@ void save_restoreGB(uint8_t saveOpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DETECT CLOCK NOW IN LFDEMOD.C
|
// DETECT CLOCK NOW IN LFDEMOD.C
|
||||||
void setGraphBuf(uint8_t *buff, size_t size)
|
void setGraphBuf(uint8_t *buf, size_t size) {
|
||||||
{
|
if ( buf == NULL ) return;
|
||||||
if ( buff == NULL ) return;
|
|
||||||
|
|
||||||
ClearGraph(0);
|
ClearGraph(0);
|
||||||
|
|
||||||
|
@ -79,27 +74,26 @@ void setGraphBuf(uint8_t *buff, size_t size)
|
||||||
size = MAX_GRAPH_TRACE_LEN;
|
size = MAX_GRAPH_TRACE_LEN;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < size; ++i)
|
for (uint16_t i = 0; i < size; ++i)
|
||||||
GraphBuffer[i] = buff[i] - 128;
|
GraphBuffer[i] = buf[i] - 128;
|
||||||
|
|
||||||
GraphTraceLen = size;
|
GraphTraceLen = size;
|
||||||
RepaintGraphWindow();
|
RepaintGraphWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t getFromGraphBuf(uint8_t *buff)
|
size_t getFromGraphBuf(uint8_t *buf) {
|
||||||
{
|
|
||||||
if (buff == NULL ) return 0;
|
if (buf == NULL ) return 0;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for (i=0; i < GraphTraceLen; ++i){
|
for (i=0; i < GraphTraceLen; ++i){
|
||||||
if (GraphBuffer[i] > 127) GraphBuffer[i] = 127; //trim
|
if (GraphBuffer[i] > 127) GraphBuffer[i] = 127; //trim
|
||||||
if (GraphBuffer[i] < -127) GraphBuffer[i] = -127; //trim
|
if (GraphBuffer[i] < -127) GraphBuffer[i] = -127; //trim
|
||||||
buff[i] = (uint8_t)(GraphBuffer[i]+128);
|
buf[i] = (uint8_t)(GraphBuffer[i]+128);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A simple test to see if there is any data inside Graphbuffer.
|
// A simple test to see if there is any data inside Graphbuffer.
|
||||||
bool HasGraphData(){
|
bool HasGraphData(){
|
||||||
|
|
||||||
if ( GraphTraceLen <= 0) {
|
if ( GraphTraceLen <= 0) {
|
||||||
PrintAndLog("No data available, try reading something first");
|
PrintAndLog("No data available, try reading something first");
|
||||||
return false;
|
return false;
|
||||||
|
@ -109,6 +103,7 @@ bool HasGraphData(){
|
||||||
|
|
||||||
// Detect high and lows in Grapbuffer.
|
// Detect high and lows in Grapbuffer.
|
||||||
// Only loops the first 256 values.
|
// Only loops the first 256 values.
|
||||||
|
// Optional: 12% fuzz in case highs and lows aren't clipped
|
||||||
void DetectHighLowInGraph(int *high, int *low, bool addFuzz) {
|
void DetectHighLowInGraph(int *high, int *low, bool addFuzz) {
|
||||||
|
|
||||||
uint8_t loopMax = 255;
|
uint8_t loopMax = 255;
|
||||||
|
@ -130,8 +125,7 @@ void DetectHighLowInGraph(int *high, int *low, bool addFuzz) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get or auto-detect ask clock rate
|
// Get or auto-detect ask clock rate
|
||||||
int GetAskClock(const char str[], bool printAns, bool verbose)
|
int GetAskClock(const char str[], bool printAns, bool verbose) {
|
||||||
{
|
|
||||||
int clock;
|
int clock;
|
||||||
sscanf(str, "%i", &clock);
|
sscanf(str, "%i", &clock);
|
||||||
if (!strcmp(str, ""))
|
if (!strcmp(str, ""))
|
||||||
|
@ -140,7 +134,7 @@ int GetAskClock(const char str[], bool printAns, bool verbose)
|
||||||
if (clock != 0) return clock;
|
if (clock != 0) return clock;
|
||||||
|
|
||||||
// Auto-detect clock
|
// Auto-detect clock
|
||||||
uint8_t grph[MAX_GRAPH_TRACE_LEN]={0};
|
uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0};
|
||||||
size_t size = getFromGraphBuf(grph);
|
size_t size = getFromGraphBuf(grph);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
@ -162,8 +156,7 @@ int GetAskClock(const char str[], bool printAns, bool verbose)
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose)
|
uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose) {
|
||||||
{
|
|
||||||
uint8_t carrier = 0;
|
uint8_t carrier = 0;
|
||||||
uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0};
|
uint8_t grph[MAX_GRAPH_TRACE_LEN] = {0};
|
||||||
size_t size = getFromGraphBuf(grph);
|
size_t size = getFromGraphBuf(grph);
|
||||||
|
@ -182,8 +175,7 @@ uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose)
|
||||||
return carrier;
|
return carrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetPskClock(const char str[], bool printAns, bool verbose)
|
int GetPskClock(const char str[], bool printAns, bool verbose) {
|
||||||
{
|
|
||||||
int clock;
|
int clock;
|
||||||
sscanf(str, "%i", &clock);
|
sscanf(str, "%i", &clock);
|
||||||
if (!strcmp(str, ""))
|
if (!strcmp(str, ""))
|
||||||
|
@ -208,8 +200,7 @@ int GetPskClock(const char str[], bool printAns, bool verbose)
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t GetNrzClock(const char str[], bool printAns, bool verbose)
|
uint8_t GetNrzClock(const char str[], bool printAns, bool verbose) {
|
||||||
{
|
|
||||||
int clock;
|
int clock;
|
||||||
sscanf(str, "%i", &clock);
|
sscanf(str, "%i", &clock);
|
||||||
if (!strcmp(str, ""))
|
if (!strcmp(str, ""))
|
||||||
|
@ -236,8 +227,7 @@ uint8_t GetNrzClock(const char str[], bool printAns, bool verbose)
|
||||||
}
|
}
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
//attempt to detect the field clock and bit clock for FSK
|
//attempt to detect the field clock and bit clock for FSK
|
||||||
uint8_t GetFskClock(const char str[], bool printAns, bool verbose)
|
uint8_t GetFskClock(const char str[], bool printAns, bool verbose) {
|
||||||
{
|
|
||||||
int clock;
|
int clock;
|
||||||
sscanf(str, "%i", &clock);
|
sscanf(str, "%i", &clock);
|
||||||
if (!strcmp(str, ""))
|
if (!strcmp(str, ""))
|
||||||
|
@ -282,8 +272,7 @@ uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *f
|
||||||
}
|
}
|
||||||
|
|
||||||
// test samples are not just noise
|
// test samples are not just noise
|
||||||
bool graphJustNoise(int *bits, int size)
|
bool is_justnoise(int *bits, int size) {
|
||||||
{
|
|
||||||
//might not be high enough for noisy environments
|
//might not be high enough for noisy environments
|
||||||
#define THRESHOLD 15;
|
#define THRESHOLD 15;
|
||||||
bool isNoise = true;
|
bool isNoise = true;
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
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);
|
|
||||||
size_t getFromGraphBuf(uint8_t *buff);
|
size_t getFromGraphBuf(uint8_t *buff);
|
||||||
int GetAskClock(const char str[], bool printAns, bool verbose);
|
int GetAskClock(const char str[], bool printAns, bool verbose);
|
||||||
int GetPskClock(const char str[], bool printAns, bool verbose);
|
int GetPskClock(const char str[], bool printAns, bool verbose);
|
||||||
|
@ -22,8 +21,7 @@ uint8_t GetPskCarrier(const char str[], bool printAns, bool verbose);
|
||||||
uint8_t GetNrzClock(const char str[], bool printAns, bool verbose);
|
uint8_t GetNrzClock(const char str[], bool printAns, bool verbose);
|
||||||
uint8_t GetFskClock(const char str[], bool printAns, bool verbose);
|
uint8_t GetFskClock(const char str[], bool printAns, bool verbose);
|
||||||
uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *firstClockEdge);
|
uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *firstClockEdge);
|
||||||
//uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose);
|
bool is_justnoise(int *bits, int size);
|
||||||
bool graphJustNoise(int *BitStream, int size);
|
|
||||||
void setGraphBuf(uint8_t *buff, size_t size);
|
void setGraphBuf(uint8_t *buff, size_t size);
|
||||||
void save_restoreGB(uint8_t saveOpt);
|
void save_restoreGB(uint8_t saveOpt);
|
||||||
|
|
||||||
|
|
|
@ -157,19 +157,21 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea
|
||||||
|
|
||||||
// make sure we don't go beyond our char array memory
|
// make sure we don't go beyond our char array memory
|
||||||
size_t in_index = 0, out_index = 0;
|
size_t in_index = 0, out_index = 0;
|
||||||
int rowlen;
|
|
||||||
if (breaks==0)
|
int rowlen = (len > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len;
|
||||||
rowlen = ( len > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len;
|
|
||||||
else
|
if ( len % breaks != 0)
|
||||||
rowlen = ( len+(len/breaks) > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len+(len/breaks);
|
rowlen = ( len+(len/breaks) > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len+(len/breaks);
|
||||||
|
|
||||||
|
// printf("(sprint_bin_break) rowlen %d\n", rowlen);
|
||||||
|
|
||||||
static char buf[MAX_BIN_BREAK_LENGTH]; // 3072 + end of line characters if broken at 8 bits
|
static char buf[MAX_BIN_BREAK_LENGTH]; // 3072 + end of line characters if broken at 8 bits
|
||||||
//clear memory
|
//clear memory
|
||||||
memset(buf, 0x00, sizeof(buf));
|
memset(buf, 0x00, sizeof(buf));
|
||||||
char *tmp = buf;
|
char *tmp = buf;
|
||||||
|
|
||||||
// loop through the out_index to make sure we don't go too far
|
// loop through the out_index to make sure we don't go too far
|
||||||
for (out_index=0; out_index < rowlen-1; out_index++) {
|
for (out_index=0; out_index < rowlen; out_index++) {
|
||||||
// set character
|
// set character
|
||||||
sprintf(tmp++, "%u", data[in_index]);
|
sprintf(tmp++, "%u", data[in_index]);
|
||||||
// check if a line break is needed and we have room to print it in our array
|
// check if a line break is needed and we have room to print it in our array
|
||||||
|
@ -184,6 +186,44 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea
|
||||||
sprintf(tmp++, "%u", data[in_index]);
|
sprintf(tmp++, "%u", data[in_index]);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
void sprint_bin_break_ex(uint8_t *src, size_t srclen, char *dest , uint8_t breaks) {
|
||||||
|
if ( src == NULL ) return;
|
||||||
|
if ( srclen < 1 ) return;
|
||||||
|
|
||||||
|
// make sure we don't go beyond our char array memory
|
||||||
|
size_t in_index = 0, out_index = 0;
|
||||||
|
int rowlen;
|
||||||
|
if (breaks==0)
|
||||||
|
rowlen = ( len > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len;
|
||||||
|
else
|
||||||
|
rowlen = ( len+(len/breaks) > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len+(len/breaks);
|
||||||
|
|
||||||
|
printf("(sprint_bin_break) rowlen %d\n", rowlen);
|
||||||
|
|
||||||
|
// 3072 + end of line characters if broken at 8 bits
|
||||||
|
dest = (char *)malloc(MAX_BIN_BREAK_LENGTH);
|
||||||
|
if (dest == NULL) return;
|
||||||
|
|
||||||
|
//clear memory
|
||||||
|
memset(dest, 0x00, sizeof(dest));
|
||||||
|
|
||||||
|
// loop through the out_index to make sure we don't go too far
|
||||||
|
for (out_index=0; out_index < rowlen-1; out_index++) {
|
||||||
|
// set character
|
||||||
|
sprintf(dest++, "%u", src[in_index]);
|
||||||
|
// check if a line break is needed and we have room to print it in our array
|
||||||
|
if ( (breaks > 0) && !((in_index+1) % breaks) && (out_index+1 != rowlen) ) {
|
||||||
|
// increment and print line break
|
||||||
|
out_index++;
|
||||||
|
sprintf(dest++, "%s","\n");
|
||||||
|
}
|
||||||
|
in_index++;
|
||||||
|
}
|
||||||
|
// last char.
|
||||||
|
sprintf(dest++, "%u", src[in_index]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
char *sprint_bin(const uint8_t *data, const size_t len) {
|
char *sprint_bin(const uint8_t *data, const size_t len) {
|
||||||
return sprint_bin_break(data, len, 0);
|
return sprint_bin_break(data, len, 0);
|
||||||
|
|
|
@ -176,6 +176,7 @@ bool preambleSearch(uint8_t *BitStream, uint8_t *preamble, size_t pLen, size_t *
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
// search for given preamble in given BitStream and return success=1 or fail=0 and startIndex (where it was found) and length if not fineone
|
// search for given preamble in given BitStream and return success=1 or fail=0 and startIndex (where it was found) and length if not fineone
|
||||||
// fineone does not look for a repeating preamble for em4x05/4x69 sends preamble once, so look for it once in the first pLen bits
|
// fineone does not look for a repeating preamble for em4x05/4x69 sends preamble once, so look for it once in the first pLen bits
|
||||||
|
//(iceman) FINDONE, only finds start index. NOT SIZE!. I see Em410xDecode (lfdemod.c) uses SIZE to determine success
|
||||||
bool preambleSearchEx(uint8_t *BitStream, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone)
|
bool preambleSearchEx(uint8_t *BitStream, uint8_t *preamble, size_t pLen, size_t *size, size_t *startIdx, bool findone)
|
||||||
{
|
{
|
||||||
// Sanity check. If preamble length is bigger than bitstream length.
|
// Sanity check. If preamble length is bigger than bitstream length.
|
||||||
|
@ -184,20 +185,21 @@ bool preambleSearchEx(uint8_t *BitStream, uint8_t *preamble, size_t pLen, size_t
|
||||||
uint8_t foundCnt = 0;
|
uint8_t foundCnt = 0;
|
||||||
for (size_t idx = 0; idx < *size - pLen; idx++) {
|
for (size_t idx = 0; idx < *size - pLen; idx++) {
|
||||||
if (memcmp(BitStream+idx, preamble, pLen) == 0){
|
if (memcmp(BitStream+idx, preamble, pLen) == 0){
|
||||||
if (g_debugMode) prnt("DEBUG: preamble found at %i", idx);
|
|
||||||
//first index found
|
//first index found
|
||||||
foundCnt++;
|
foundCnt++;
|
||||||
if (foundCnt == 1){
|
if (foundCnt == 1){
|
||||||
|
if (g_debugMode) prnt("DEBUG: (preambleSearchEx) preamble found at %i", idx);
|
||||||
*startIdx = idx;
|
*startIdx = idx;
|
||||||
if (findone) return true;
|
if (findone) return true;
|
||||||
}
|
}
|
||||||
if (foundCnt == 2){
|
if (foundCnt == 2){
|
||||||
|
if (g_debugMode) prnt("DEBUG: (preambleSearchEx) preamble 2 found at %i", idx);
|
||||||
*size = idx - *startIdx;
|
*size = idx - *startIdx;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return (foundCnt > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find start of modulating data (for fsk and psk) in case of beginning noise or slow chip startup.
|
// find start of modulating data (for fsk and psk) in case of beginning noise or slow chip startup.
|
||||||
|
@ -445,7 +447,7 @@ int DetectASKClock(uint8_t dest[], size_t size, int *clock, int maxErr) {
|
||||||
if (!clockFnd){
|
if (!clockFnd){
|
||||||
if (DetectCleanAskWave(dest, size, peak, low)==1){
|
if (DetectCleanAskWave(dest, size, peak, low)==1){
|
||||||
int ans = DetectStrongAskClock(dest, size, peak, low, clock);
|
int ans = DetectStrongAskClock(dest, size, peak, low, clock);
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: detectaskclk Clean Ask Wave Detected: clk %i, ShortestWave: %i", clock ,ans);
|
if (g_debugMode==2) prnt("DEBUG ASK: detectaskclk Clean Ask Wave Detected: clk %i, ShortestWave: %i", *clock ,ans);
|
||||||
if (ans > 0){
|
if (ans > 0){
|
||||||
return ans; //return shortest wave start position
|
return ans; //return shortest wave start position
|
||||||
}
|
}
|
||||||
|
@ -1262,7 +1264,7 @@ int cleanAskRawDemod(uint8_t *BinStream, size_t *size, int clk, int invert, int
|
||||||
if (smplCnt > clk-(clk/4)-1) { //full clock
|
if (smplCnt > clk-(clk/4)-1) { //full clock
|
||||||
if (smplCnt > clk + (clk/4)+1) { //too many samples
|
if (smplCnt > clk + (clk/4)+1) { //too many samples
|
||||||
errCnt++;
|
errCnt++;
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: Modulation Error at: %u", i);
|
if (g_debugMode==2) prnt("DEBUG:(cleanAskRawDemod) ASK Modulation Error at: %u", i);
|
||||||
BinStream[bitCnt++] = 7;
|
BinStream[bitCnt++] = 7;
|
||||||
} else if (waveHigh) {
|
} else if (waveHigh) {
|
||||||
BinStream[bitCnt++] = invert;
|
BinStream[bitCnt++] = invert;
|
||||||
|
@ -1320,20 +1322,22 @@ int askdemod_ext(uint8_t *BinStream, size_t *size, int *clk, int *invert, int ma
|
||||||
size_t errCnt = 0;
|
size_t errCnt = 0;
|
||||||
// if clean clipped waves detected run alternate demod
|
// if clean clipped waves detected run alternate demod
|
||||||
if (DetectCleanAskWave(BinStream, *size, high, low)) {
|
if (DetectCleanAskWave(BinStream, *size, high, low)) {
|
||||||
|
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: Clean Wave Detected - using clean wave demod");
|
if (g_debugMode==2) prnt("DEBUG ASK: Clean Wave Detected - using clean wave demod");
|
||||||
|
|
||||||
errCnt = cleanAskRawDemod(BinStream, size, *clk, *invert, high, low, startIdx);
|
errCnt = cleanAskRawDemod(BinStream, size, *clk, *invert, high, low, startIdx);
|
||||||
if (askType) { //askman
|
|
||||||
|
if (askType) { //ask/manchester
|
||||||
uint8_t alignPos = 0;
|
uint8_t alignPos = 0;
|
||||||
errCnt = manrawdecode(BinStream, size, 0, &alignPos);
|
errCnt = manrawdecode(BinStream, size, 0, &alignPos);
|
||||||
*startIdx += *clk/2 * alignPos;
|
*startIdx += *clk/2 * alignPos;
|
||||||
if (g_debugMode) prnt("DEBUG ASK CLEAN: startIdx %i, alignPos %u", *startIdx, alignPos);
|
if (g_debugMode)
|
||||||
|
prnt("DEBUG: (askdemod_ext) CLEAN: startIdx %i, alignPos %u", *startIdx, alignPos);
|
||||||
|
}
|
||||||
return errCnt;
|
return errCnt;
|
||||||
} else { //askraw
|
|
||||||
return errCnt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (g_debugMode) prnt("DEBUG ASK WEAK: startIdx %i", *startIdx);
|
if (g_debugMode) prnt("DEBUG: (askdemod_ext) WEAK: startIdx %i", *startIdx);
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: Weak Wave Detected - using weak wave demod");
|
if (g_debugMode==2) prnt("DEBUG: (askdemod_ext) Weak Wave Detected - using weak wave demod");
|
||||||
|
|
||||||
int lastBit; //set first clock check - can go negative
|
int lastBit; //set first clock check - can go negative
|
||||||
size_t i, bitnum = 0; //output counter
|
size_t i, bitnum = 0; //output counter
|
||||||
|
@ -1351,7 +1355,7 @@ int askdemod_ext(uint8_t *BinStream, size_t *size, int *clk, int *invert, int ma
|
||||||
BinStream[bitnum++] = *invert ^ 1;
|
BinStream[bitnum++] = *invert ^ 1;
|
||||||
} else if (i-lastBit >= *clk+tol) {
|
} else if (i-lastBit >= *clk+tol) {
|
||||||
if (bitnum > 0) {
|
if (bitnum > 0) {
|
||||||
if (g_debugMode==2) prnt("DEBUG ASK: Modulation Error at: %u", i);
|
if (g_debugMode==2) prnt("DEBUG: (askdemod_ext) Modulation Error at: %u", i);
|
||||||
BinStream[bitnum++]=7;
|
BinStream[bitnum++]=7;
|
||||||
errCnt++;
|
errCnt++;
|
||||||
}
|
}
|
||||||
|
@ -1426,8 +1430,8 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId
|
||||||
size_t fsk_wave_demod(uint8_t * dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
size_t fsk_wave_demod(uint8_t * dest, size_t size, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
||||||
size_t last_transition = 0;
|
size_t last_transition = 0;
|
||||||
size_t idx = 1;
|
size_t idx = 1;
|
||||||
if (fchigh==0) fchigh=10;
|
if (fchigh == 0) fchigh = 10;
|
||||||
if (fclow==0) fclow=8;
|
if (fclow == 0) fclow = 8;
|
||||||
//set the threshold close to 0 (graph) or 128 std to avoid static
|
//set the threshold close to 0 (graph) or 128 std to avoid static
|
||||||
size_t preLastSample = 0;
|
size_t preLastSample = 0;
|
||||||
size_t LastSample = 0;
|
size_t LastSample = 0;
|
||||||
|
@ -1486,16 +1490,16 @@ size_t fsk_wave_demod(uint8_t * dest, size_t size, uint8_t fchigh, uint8_t fclow
|
||||||
//rfLen = clock, fchigh = larger field clock, fclow = smaller field clock
|
//rfLen = clock, fchigh = larger field clock, fclow = smaller field clock
|
||||||
size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow, int *startIdx) {
|
||||||
uint8_t lastval = dest[0];
|
uint8_t lastval = dest[0];
|
||||||
size_t idx=0;
|
size_t idx = 0;
|
||||||
size_t numBits=0;
|
size_t numBits = 0;
|
||||||
uint32_t n=1;
|
uint32_t n = 1;
|
||||||
for( idx=1; idx < size; idx++) {
|
for( idx = 1; idx < size; idx++) {
|
||||||
n++;
|
n++;
|
||||||
if (dest[idx]==lastval) continue; //skip until we hit a transition
|
if (dest[idx] == lastval) continue; //skip until we hit a transition
|
||||||
|
|
||||||
//find out how many bits (n) we collected (use 1/2 clk tolerance)
|
//find out how many bits (n) we collected (use 1/2 clk tolerance)
|
||||||
//if lastval was 1, we have a 1->0 crossing
|
//if lastval was 1, we have a 1->0 crossing
|
||||||
if (dest[idx-1]==1) {
|
if (dest[idx-1] == 1) {
|
||||||
n = (n * fclow + rfLen/2) / rfLen;
|
n = (n * fclow + rfLen/2) / rfLen;
|
||||||
} else {// 0->1 crossing
|
} else {// 0->1 crossing
|
||||||
n = (n * fchigh + rfLen/2) / rfLen;
|
n = (n * fchigh + rfLen/2) / rfLen;
|
||||||
|
@ -1506,27 +1510,27 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert,
|
||||||
if (numBits == 0) {
|
if (numBits == 0) {
|
||||||
if (lastval == 1) { //high to low
|
if (lastval == 1) { //high to low
|
||||||
*startIdx += (fclow * idx) - (n*rfLen);
|
*startIdx += (fclow * idx) - (n*rfLen);
|
||||||
if (g_debugMode==2) prnt("DEBUG FSK: startIdx %i, fclow*idx %i, n*rflen %u", *startIdx, fclow*(idx), n*rfLen);
|
if (g_debugMode == 2) prnt("DEBUG (aggregate_bits) FSK startIdx %i, fclow*idx %i, n*rflen %u", *startIdx, fclow*(idx), n*rfLen);
|
||||||
} else {
|
} else {
|
||||||
*startIdx += (fchigh * idx) - (n*rfLen);
|
*startIdx += (fchigh * idx) - (n*rfLen);
|
||||||
if (g_debugMode==2) prnt("DEBUG FSK: startIdx %i, fchigh*idx %i, n*rflen %u", *startIdx, fchigh*(idx), n*rfLen);
|
if (g_debugMode == 2) prnt("DEBUG (aggregate_bits) FSK startIdx %i, fchigh*idx %i, n*rflen %u", *startIdx, fchigh*(idx), n*rfLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//add to our destination the bits we collected
|
//add to our destination the bits we collected
|
||||||
memset(dest+numBits, dest[idx-1]^invert , n);
|
memset(dest+numBits, dest[idx-1] ^ invert , n);
|
||||||
numBits += n;
|
numBits += n;
|
||||||
n=0;
|
n = 0;
|
||||||
lastval=dest[idx];
|
lastval = dest[idx];
|
||||||
}//end for
|
}//end for
|
||||||
// if valid extra bits at the end were all the same frequency - add them in
|
// if valid extra bits at the end were all the same frequency - add them in
|
||||||
if (n > rfLen/fchigh) {
|
if (n > rfLen/fchigh) {
|
||||||
if (dest[idx-2]==1) {
|
if (dest[idx-2] == 1) {
|
||||||
n = (n * fclow + rfLen/2) / rfLen;
|
n = (n * fclow + rfLen/2) / rfLen;
|
||||||
} else {
|
} else {
|
||||||
n = (n * fchigh + rfLen/2) / rfLen;
|
n = (n * fchigh + rfLen/2) / rfLen;
|
||||||
}
|
}
|
||||||
memset(dest+numBits, dest[idx-1]^invert , n);
|
memset(dest+numBits, dest[idx-1] ^ invert , n);
|
||||||
numBits += n;
|
numBits += n;
|
||||||
}
|
}
|
||||||
return numBits;
|
return numBits;
|
||||||
|
@ -1695,9 +1699,9 @@ int detectAWID(uint8_t *dest, size_t *size, int *waveStartIdx) {
|
||||||
//takes 1s and 0s and searches for EM410x format - output EM ID
|
//takes 1s and 0s and searches for EM410x format - output EM ID
|
||||||
int Em410xDecode(uint8_t *bits, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo) {
|
int Em410xDecode(uint8_t *bits, size_t *size, size_t *startIdx, uint32_t *hi, uint64_t *lo) {
|
||||||
// sanity check
|
// sanity check
|
||||||
if (*size < 64) return -3;
|
|
||||||
if (bits[1] > 1) return -1;
|
if (bits[1] > 1) return -1;
|
||||||
|
if (*size < 64) return -2;
|
||||||
|
|
||||||
uint8_t fmtlen;
|
uint8_t fmtlen;
|
||||||
*startIdx = 0;
|
*startIdx = 0;
|
||||||
|
|
||||||
|
@ -1705,11 +1709,8 @@ int Em410xDecode(uint8_t *bits, size_t *size, size_t *startIdx, uint32_t *hi, ui
|
||||||
// include 0 in front to help get start pos
|
// include 0 in front to help get start pos
|
||||||
uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1};
|
uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1};
|
||||||
if (!preambleSearch(bits, preamble, sizeof(preamble), size, startIdx))
|
if (!preambleSearch(bits, preamble, sizeof(preamble), size, startIdx))
|
||||||
return -2;
|
return -4;
|
||||||
|
|
||||||
//XL and normal size.
|
|
||||||
if (*size != 64 && *size != 128) return -3;
|
|
||||||
|
|
||||||
fmtlen = (*size == 128) ? 22 : 10;
|
fmtlen = (*size == 128) ? 22 : 10;
|
||||||
|
|
||||||
//skip last 4bit parity row for simplicity
|
//skip last 4bit parity row for simplicity
|
||||||
|
@ -1728,7 +1729,7 @@ int Em410xDecode(uint8_t *bits, size_t *size, size_t *startIdx, uint32_t *hi, ui
|
||||||
*lo = ((uint64_t)(bytebits_to_byte(bits + 24, 32)) << 32) | (bytebits_to_byte(bits + 24 + 32, 32));
|
*lo = ((uint64_t)(bytebits_to_byte(bits + 24, 32)) << 32) | (bytebits_to_byte(bits + 24 + 32, 32));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: return -4;
|
default: return -6;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue