mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 02:26:59 -07:00
lf cleaning
remove unneeded code/functions fix lfdemod askmandemod bug with maxErr=0 silence output for getting samples in lf search
This commit is contained in:
parent
643fb10b2d
commit
2767fc0291
13 changed files with 169 additions and 853 deletions
745
client/cmddata.c
745
client/cmddata.c
|
@ -58,37 +58,16 @@ int CmdSetDebugMode(const char *Cmd)
|
|||
//by marshmellow
|
||||
void printDemodBuff(void)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
int bitLen = DemodBufferLen;
|
||||
if (bitLen<16) {
|
||||
if (bitLen<1) {
|
||||
PrintAndLog("no bits found in demod buffer");
|
||||
return;
|
||||
}
|
||||
if (bitLen>512) bitLen=512; //max output to 512 bits if we have more - should be plenty
|
||||
|
||||
// ensure equally divided by 16
|
||||
bitLen &= 0xfff0;
|
||||
char *bin = sprint_bin_break(DemodBuffer,bitLen,16);
|
||||
PrintAndLog("%s",bin);
|
||||
|
||||
for (i = 0; i <= (bitLen-16); i+=16) {
|
||||
PrintAndLog("%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i",
|
||||
DemodBuffer[i],
|
||||
DemodBuffer[i+1],
|
||||
DemodBuffer[i+2],
|
||||
DemodBuffer[i+3],
|
||||
DemodBuffer[i+4],
|
||||
DemodBuffer[i+5],
|
||||
DemodBuffer[i+6],
|
||||
DemodBuffer[i+7],
|
||||
DemodBuffer[i+8],
|
||||
DemodBuffer[i+9],
|
||||
DemodBuffer[i+10],
|
||||
DemodBuffer[i+11],
|
||||
DemodBuffer[i+12],
|
||||
DemodBuffer[i+13],
|
||||
DemodBuffer[i+14],
|
||||
DemodBuffer[i+15]
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -114,105 +93,8 @@ int CmdPrintDemodBuff(const char *Cmd)
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
int CmdAmp(const char *Cmd)
|
||||
{
|
||||
int i, rising, falling;
|
||||
int max = INT_MIN, min = INT_MAX;
|
||||
|
||||
for (i = 10; i < GraphTraceLen; ++i) {
|
||||
if (GraphBuffer[i] > max)
|
||||
max = GraphBuffer[i];
|
||||
if (GraphBuffer[i] < min)
|
||||
min = GraphBuffer[i];
|
||||
}
|
||||
|
||||
if (max != min) {
|
||||
rising = falling= 0;
|
||||
for (i = 0; i < GraphTraceLen; ++i) {
|
||||
if (GraphBuffer[i + 1] < GraphBuffer[i]) {
|
||||
if (rising) {
|
||||
GraphBuffer[i] = max;
|
||||
rising = 0;
|
||||
}
|
||||
falling = 1;
|
||||
}
|
||||
if (GraphBuffer[i + 1] > GraphBuffer[i]) {
|
||||
if (falling) {
|
||||
GraphBuffer[i] = min;
|
||||
falling = 0;
|
||||
}
|
||||
rising= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic command to demodulate ASK.
|
||||
*
|
||||
* Argument is convention: positive or negative (High mod means zero
|
||||
* or high mod means one)
|
||||
*
|
||||
* Updates the Graph trace with 0/1 values
|
||||
*
|
||||
* Arguments:
|
||||
* c : 0 or 1 (or invert)
|
||||
*/
|
||||
//this method ignores the clock
|
||||
|
||||
//this function strictly converts highs and lows to 1s and 0s for each sample in the graphbuffer
|
||||
int Cmdaskdemod(const char *Cmd)
|
||||
{
|
||||
int i;
|
||||
int c, high = 0, low = 0;
|
||||
|
||||
sscanf(Cmd, "%i", &c);
|
||||
|
||||
/* Detect high and lows */
|
||||
for (i = 0; i < GraphTraceLen; ++i)
|
||||
{
|
||||
if (GraphBuffer[i] > high)
|
||||
high = GraphBuffer[i];
|
||||
else if (GraphBuffer[i] < low)
|
||||
low = GraphBuffer[i];
|
||||
}
|
||||
high=abs(high*.75);
|
||||
low=abs(low*.75);
|
||||
if (c != 0 && c != 1) {
|
||||
PrintAndLog("Invalid argument: %s", Cmd);
|
||||
return 0;
|
||||
}
|
||||
//prime loop
|
||||
if (GraphBuffer[0] > 0) {
|
||||
GraphBuffer[0] = 1-c;
|
||||
} else {
|
||||
GraphBuffer[0] = c;
|
||||
}
|
||||
for (i = 1; i < GraphTraceLen; ++i) {
|
||||
/* Transitions are detected at each peak
|
||||
* Transitions are either:
|
||||
* - we're low: transition if we hit a high
|
||||
* - we're high: transition if we hit a low
|
||||
* (we need to do it this way because some tags keep high or
|
||||
* low for long periods, others just reach the peak and go
|
||||
* down)
|
||||
*/
|
||||
//[marhsmellow] change == to >= for high and <= for low for fuzz
|
||||
if ((GraphBuffer[i] >= high) && (GraphBuffer[i - 1] == c)) {
|
||||
GraphBuffer[i] = 1 - c;
|
||||
} else if ((GraphBuffer[i] <= low) && (GraphBuffer[i - 1] == (1 - c))){
|
||||
GraphBuffer[i] = c;
|
||||
} else {
|
||||
/* No transition */
|
||||
GraphBuffer[i] = GraphBuffer[i - 1];
|
||||
}
|
||||
}
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//this function strictly converts >1 to 1 and <1 to 0 for each sample in the graphbuffer
|
||||
int CmdGetBitStream(const char *Cmd)
|
||||
{
|
||||
|
@ -229,43 +111,6 @@ int CmdGetBitStream(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//by marshmellow
|
||||
void printBitStream(uint8_t BitStream[], uint32_t bitLen)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
if (bitLen<16) {
|
||||
PrintAndLog("Too few bits found: %d",bitLen);
|
||||
return;
|
||||
}
|
||||
if (bitLen>512) bitLen=512;
|
||||
|
||||
// ensure equally divided by 16
|
||||
bitLen &= 0xfff0;
|
||||
|
||||
|
||||
for (i = 0; i <= (bitLen-16); i+=16) {
|
||||
PrintAndLog("%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i",
|
||||
BitStream[i],
|
||||
BitStream[i+1],
|
||||
BitStream[i+2],
|
||||
BitStream[i+3],
|
||||
BitStream[i+4],
|
||||
BitStream[i+5],
|
||||
BitStream[i+6],
|
||||
BitStream[i+7],
|
||||
BitStream[i+8],
|
||||
BitStream[i+9],
|
||||
BitStream[i+10],
|
||||
BitStream[i+11],
|
||||
BitStream[i+12],
|
||||
BitStream[i+13],
|
||||
BitStream[i+14],
|
||||
BitStream[i+15]
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//by marshmellow
|
||||
//print 64 bit EM410x ID in multiple formats
|
||||
void printEM410x(uint32_t hi, uint64_t id)
|
||||
|
@ -282,11 +127,11 @@ void printEM410x(uint32_t hi, uint64_t id)
|
|||
}
|
||||
if (hi){
|
||||
//output 88 bit em id
|
||||
PrintAndLog("\nEM TAG ID : %06x%016llx", hi, id);
|
||||
PrintAndLog("\nEM TAG ID : %06X%016llX", hi, id);
|
||||
} else{
|
||||
//output 40 bit em id
|
||||
PrintAndLog("\nEM TAG ID : %010llx", id);
|
||||
PrintAndLog("Unique TAG ID : %010llx", id2lo);
|
||||
PrintAndLog("\nEM TAG ID : %010llX", id);
|
||||
PrintAndLog("Unique TAG ID : %010llX", id2lo);
|
||||
PrintAndLog("\nPossible de-scramble patterns");
|
||||
PrintAndLog("HoneyWell IdentKey {");
|
||||
PrintAndLog("DEZ 8 : %08lld",id & 0xFFFFFF);
|
||||
|
@ -311,7 +156,7 @@ void printEM410x(uint32_t hi, uint64_t id)
|
|||
);
|
||||
uint64_t paxton = (((id>>32) << 24) | (id & 0xffffff)) + 0x143e00;
|
||||
PrintAndLog("}\nOther : %05lld_%03lld_%08lld",(id&0xFFFF),((id>>16LL) & 0xFF),(id & 0xFFFFFF));
|
||||
PrintAndLog("Pattern Paxton : %0d", paxton);
|
||||
PrintAndLog("Pattern Paxton : %lld [0x%llX]", paxton, paxton);
|
||||
|
||||
uint32_t p1id = (id & 0xFFFFFF);
|
||||
uint8_t arr[32] = {0x00};
|
||||
|
@ -352,12 +197,12 @@ void printEM410x(uint32_t hi, uint64_t id)
|
|||
p1 |= arr[2] << 4;
|
||||
p1 |= arr[1] << 5;
|
||||
p1 |= arr[0] << 9;
|
||||
PrintAndLog("Pattern 1 : 0x%X - %d", p1, p1);
|
||||
PrintAndLog("Pattern 1 : %d [0x%X]", p1, p1);
|
||||
|
||||
uint16_t sebury1 = id & 0xFFFF;
|
||||
uint8_t sebury2 = (id >> 16) & 0x7F;
|
||||
uint32_t sebury3 = id & 0x7FFFFF;
|
||||
PrintAndLog("Pattern Sebury : %d %d %d (hex: %X %X %X)", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3);
|
||||
PrintAndLog("Pattern Sebury : %d %d %d [0x%X 0x%X 0x%X]", sebury1, sebury2, sebury3, sebury1, sebury2, sebury3);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -430,20 +275,23 @@ int ASKmanDemod(const char *Cmd, bool verbose, bool emSearch)
|
|||
clk=0;
|
||||
}
|
||||
size_t BitLen = getFromGraphBuf(BitStream);
|
||||
if (g_debugMode==1) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
|
||||
if (BitLen==0) return 0;
|
||||
int errCnt=0;
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Bitlen from grphbuff: %d",BitLen);
|
||||
if (!BitLen) return 0;
|
||||
if (maxLen<BitLen && maxLen != 0) BitLen = maxLen;
|
||||
errCnt = askmandemod(BitStream, &BitLen, &clk, &invert, maxErr);
|
||||
int errCnt = askmandemod(BitStream, &BitLen, &clk, &invert, maxErr);
|
||||
if (errCnt<0||BitLen<16){ //if fatal error (or -1)
|
||||
if (g_debugMode==1) PrintAndLog("no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
|
||||
if (g_debugMode) PrintAndLog("DEBUG: no data found %d, errors:%d, bitlen:%d, clock:%d",errCnt,invert,BitLen,clk);
|
||||
return 0;
|
||||
}
|
||||
if (verbose || g_debugMode) PrintAndLog("\nUsing Clock: %d - Invert: %d - Bits Found: %d",clk,invert,BitLen);
|
||||
if (errCnt>maxErr){
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Too many errors found, errors:%d, bits:%d, clock:%d",errCnt, BitLen, clk);
|
||||
return 0;
|
||||
}
|
||||
if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen);
|
||||
|
||||
//output
|
||||
if (errCnt>0){
|
||||
if (verbose || g_debugMode) PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||
if (verbose || g_debugMode) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||
}
|
||||
if (verbose || g_debugMode) PrintAndLog("ASK/Manchester decoded bitstream:");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
|
@ -519,7 +367,7 @@ int Cmdmandecoderaw(const char *Cmd)
|
|||
BitStream[i]=DemodBuffer[i];
|
||||
}
|
||||
if (high>1 || low <0 ){
|
||||
PrintAndLog("Error: please raw demod the wave first then mancheseter raw decode");
|
||||
PrintAndLog("Error: please raw demod the wave first then manchester raw decode");
|
||||
return 0;
|
||||
}
|
||||
size=i;
|
||||
|
@ -529,7 +377,7 @@ int Cmdmandecoderaw(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
PrintAndLog("Manchester Decoded - # errors:%d - data:",errCnt);
|
||||
printBitStream(BitStream, size);
|
||||
PrintAndLog("%s", sprint_bin_break(BitStream, size, 16));
|
||||
if (errCnt==0){
|
||||
uint64_t id = 0;
|
||||
uint32_t hi = 0;
|
||||
|
@ -549,11 +397,7 @@ int Cmdmandecoderaw(const char *Cmd)
|
|||
//take 01 or 10 = 0 and 11 or 00 = 1
|
||||
//takes 2 arguments "offset" default = 0 if 1 it will shift the decode by one bit
|
||||
// and "invert" default = 0 if 1 it will invert output
|
||||
// since it is not like manchester and doesn't have an incorrect bit pattern we
|
||||
// cannot determine if our decode is correct or if it should be shifted by one bit
|
||||
// the argument offset allows us to manually shift if the output is incorrect
|
||||
// (better would be to demod and decode at the same time so we can distinguish large
|
||||
// width waves vs small width waves to help the decode positioning) or askbiphdemod
|
||||
// the argument offset allows us to manually shift if the output is incorrect - [EDIT: now auto detects]
|
||||
int CmdBiphaseDecodeRaw(const char *Cmd)
|
||||
{
|
||||
size_t size=0;
|
||||
|
@ -592,39 +436,15 @@ int CmdBiphaseDecodeRaw(const char *Cmd)
|
|||
}
|
||||
|
||||
if (errCnt>0){
|
||||
PrintAndLog("# Errors found during Demod (shown as 77 in bit stream): %d",errCnt);
|
||||
PrintAndLog("# Errors found during Demod (shown as 7 in bit stream): %d",errCnt);
|
||||
}
|
||||
PrintAndLog("Biphase Decoded using offset: %d - # invert:%d - data:",offset,invert);
|
||||
printBitStream(BitStream, size);
|
||||
PrintAndLog("%s", sprint_bin_break(BitStream, size, 16));
|
||||
|
||||
if (offset) setDemodBuf(DemodBuffer,DemodBufferLen-offset, offset); //remove first bit from raw demod
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set demod buffer back to raw after biphase demod
|
||||
void setBiphasetoRawDemodBuf(uint8_t *BitStream, size_t size)
|
||||
{
|
||||
uint8_t rawStream[512]={0x00};
|
||||
size_t i=0;
|
||||
uint8_t curPhase=0;
|
||||
if (size > 256) {
|
||||
PrintAndLog("ERROR - Biphase Demod Buffer overrun");
|
||||
return;
|
||||
}
|
||||
for (size_t idx=0; idx<size; idx++){
|
||||
if(!BitStream[idx]){
|
||||
rawStream[i++] = curPhase;
|
||||
rawStream[i++] = curPhase;
|
||||
curPhase ^= 1;
|
||||
} else {
|
||||
rawStream[i++] = curPhase;
|
||||
rawStream[i++] = curPhase ^ 1;
|
||||
}
|
||||
}
|
||||
setDemodBuf(rawStream,i,0);
|
||||
return;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//takes 4 arguments - clock, invert, maxErr as integers and amplify as char
|
||||
//attempts to demodulate ask only
|
||||
|
@ -649,26 +469,31 @@ int ASKrawDemod(const char *Cmd, bool verbose)
|
|||
if (amp == 'a' || amp == 'A') askAmp=1;
|
||||
size_t BitLen = getFromGraphBuf(BitStream);
|
||||
if (BitLen==0) return 0;
|
||||
int errCnt=0;
|
||||
errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp);
|
||||
int errCnt = askrawdemod(BitStream, &BitLen, &clk, &invert, maxErr, askAmp);
|
||||
if (errCnt==-1||BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
||||
if (verbose || g_debugMode) PrintAndLog("no data found");
|
||||
if (g_debugMode) PrintAndLog("errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
|
||||
return 0;
|
||||
}
|
||||
if (verbose || g_debugMode) PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, BitLen);
|
||||
if (errCnt>maxErr) {
|
||||
if (g_debugMode)
|
||||
PrintAndLog("Too many errors found, errCnt: %d, BitLen: %d, clk: %d, invert: %d", errCnt, BitLen, clk, invert);
|
||||
return 0;
|
||||
}
|
||||
if (verbose || g_debugMode)
|
||||
PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk, invert, BitLen);
|
||||
|
||||
//move BitStream back to DemodBuffer
|
||||
setDemodBuf(BitStream,BitLen,0);
|
||||
|
||||
//output
|
||||
if (errCnt>0 && (verbose || g_debugMode)){
|
||||
PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d", errCnt);
|
||||
PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d", errCnt);
|
||||
}
|
||||
if (verbose || g_debugMode){
|
||||
PrintAndLog("ASK demoded bitstream:");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
printBitStream(BitStream,BitLen);
|
||||
printDemodBuff();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -937,67 +762,6 @@ int CmdBitsamples(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to a bitstream
|
||||
*/
|
||||
int CmdBitstream(const char *Cmd)
|
||||
{
|
||||
int i, j;
|
||||
int bit;
|
||||
int gtl;
|
||||
int clock;
|
||||
int low = 0;
|
||||
int high = 0;
|
||||
int hithigh, hitlow, first;
|
||||
|
||||
/* Detect high and lows and clock */
|
||||
for (i = 0; i < GraphTraceLen; ++i)
|
||||
{
|
||||
if (GraphBuffer[i] > high)
|
||||
high = GraphBuffer[i];
|
||||
else if (GraphBuffer[i] < low)
|
||||
low = GraphBuffer[i];
|
||||
}
|
||||
|
||||
/* Get our clock */
|
||||
clock = GetAskClock(Cmd, high, 1);
|
||||
gtl = ClearGraph(0);
|
||||
|
||||
bit = 0;
|
||||
for (i = 0; i < (int)(gtl / clock); ++i)
|
||||
{
|
||||
hithigh = 0;
|
||||
hitlow = 0;
|
||||
first = 1;
|
||||
/* Find out if we hit both high and low peaks */
|
||||
for (j = 0; j < clock; ++j)
|
||||
{
|
||||
if (GraphBuffer[(i * clock) + j] == high)
|
||||
hithigh = 1;
|
||||
else if (GraphBuffer[(i * clock) + j] == low)
|
||||
hitlow = 1;
|
||||
/* it doesn't count if it's the first part of our read
|
||||
because it's really just trailing from the last sequence */
|
||||
if (first && (hithigh || hitlow))
|
||||
hithigh = hitlow = 0;
|
||||
else
|
||||
first = 0;
|
||||
|
||||
if (hithigh && hitlow)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we didn't hit both high and low peaks, we had a bit transition */
|
||||
if (!hithigh || !hitlow)
|
||||
bit ^= 1;
|
||||
|
||||
AppendGraph(0, clock, bit);
|
||||
}
|
||||
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdBuffClear(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = {CMD_BUFF_CLEAR};
|
||||
|
@ -1076,7 +840,7 @@ int CmdGraphShiftZero(const char *Cmd)
|
|||
|
||||
//by marshmellow
|
||||
//use large jumps in read samples to identify edges of waves and then amplify that wave to max
|
||||
//similar to dirtheshold, threshold, and askdemod commands
|
||||
//similar to dirtheshold, threshold commands
|
||||
//takes a threshold length which is the measured length between two samples then determines an edge
|
||||
int CmdAskEdgeDetect(const char *Cmd)
|
||||
{
|
||||
|
@ -1134,6 +898,25 @@ int CmdDetectClockRate(const char *Cmd)
|
|||
return ans;
|
||||
}
|
||||
|
||||
char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
|
||||
{
|
||||
char *fskType;
|
||||
if (fchigh==10 && fclow==8){
|
||||
if (invert) //fsk2a
|
||||
fskType = "FSK2a";
|
||||
else //fsk2
|
||||
fskType = "FSK2";
|
||||
} else if (fchigh == 8 && fclow == 5) {
|
||||
if (invert)
|
||||
fskType = "FSK1";
|
||||
else
|
||||
fskType = "FSK1a";
|
||||
} else {
|
||||
fskType = "FSK??";
|
||||
}
|
||||
return fskType;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//fsk raw demod and print binary
|
||||
//takes 4 arguments - Clock, invert, fchigh, fclow
|
||||
|
@ -1177,21 +960,20 @@ int FSKrawDemod(const char *Cmd, bool verbose)
|
|||
rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
|
||||
if (rfLen == 0) rfLen = 50;
|
||||
}
|
||||
if (verbose) PrintAndLog("Args invert: %d - Clock:%d - fchigh:%d - fclow: %d",invert,rfLen,fchigh, fclow);
|
||||
int size = fskdemod(BitStream,BitLen,(uint8_t)rfLen,(uint8_t)invert,(uint8_t)fchigh,(uint8_t)fclow);
|
||||
if (size>0){
|
||||
setDemodBuf(BitStream,size,0);
|
||||
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
if(size > (8*32)+2) size = (8*32)+2; //only output a max of 8 blocks of 32 bits most tags will have full bit stream inside that sample size
|
||||
if (verbose) {
|
||||
PrintAndLog("FSK decoded bitstream:");
|
||||
printBitStream(BitStream,size);
|
||||
if (verbose || g_debugMode) {
|
||||
PrintAndLog("\nUsing Clock:%d, invert:%d, fchigh:%d, fclow:%d", rfLen, invert, fchigh, fclow);
|
||||
PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert));
|
||||
printDemodBuff();
|
||||
}
|
||||
|
||||
return 1;
|
||||
} else{
|
||||
if (verbose) PrintAndLog("no FSK data found");
|
||||
if (g_debugMode) PrintAndLog("no FSK data found");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1395,9 +1177,9 @@ int CmdFSKdemodIO(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
if (idx==0){
|
||||
if (g_debugMode==1){
|
||||
if (g_debugMode){
|
||||
PrintAndLog("DEBUG: IO Prox Data not found - FSK Bits: %d",BitLen);
|
||||
if (BitLen > 92) printBitStream(BitStream,92);
|
||||
if (BitLen > 92) PrintAndLog("%s", sprint_bin_break(BitStream,92,16));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1411,7 +1193,7 @@ int CmdFSKdemodIO(const char *Cmd)
|
|||
//XSF(version)facility:codeone+codetwo (raw)
|
||||
//Handle the data
|
||||
if (idx+64>BitLen) {
|
||||
if (g_debugMode==1) PrintAndLog("not enough bits found - bitlen: %d",BitLen);
|
||||
if (g_debugMode) PrintAndLog("not enough bits found - bitlen: %d",BitLen);
|
||||
return 0;
|
||||
}
|
||||
PrintAndLog("%d%d%d%d%d%d%d%d %d",BitStream[idx], BitStream[idx+1], BitStream[idx+2], BitStream[idx+3], BitStream[idx+4], BitStream[idx+5], BitStream[idx+6], BitStream[idx+7], BitStream[idx+8]);
|
||||
|
@ -1432,7 +1214,6 @@ int CmdFSKdemodIO(const char *Cmd)
|
|||
|
||||
for (uint8_t i=1; i<6; ++i){
|
||||
calccrc += bytebits_to_byte(BitStream+idx+9*i,8);
|
||||
//PrintAndLog("%d", calccrc);
|
||||
}
|
||||
calccrc &= 0xff;
|
||||
calccrc = 0xff - calccrc;
|
||||
|
@ -1690,124 +1471,6 @@ int CmdFSKdemodPyramid(const char *Cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int CmdFSKdemod(const char *Cmd) //old CmdFSKdemod needs updating
|
||||
{
|
||||
static const int LowTone[] = {
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1, -1
|
||||
};
|
||||
static const int HighTone[] = {
|
||||
1, 1, 1, 1, 1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, -1, -1, -1, -1,
|
||||
1, 1, 1, 1, -1, -1, -1, -1, -1,
|
||||
};
|
||||
|
||||
int lowLen = sizeof (LowTone) / sizeof (int);
|
||||
int highLen = sizeof (HighTone) / sizeof (int);
|
||||
int convLen = (highLen > lowLen) ? highLen : lowLen;
|
||||
uint32_t hi = 0, lo = 0;
|
||||
|
||||
int i, j;
|
||||
int minMark = 0, maxMark = 0;
|
||||
|
||||
for (i = 0; i < GraphTraceLen - convLen; ++i) {
|
||||
int lowSum = 0, highSum = 0;
|
||||
|
||||
for (j = 0; j < lowLen; ++j) {
|
||||
lowSum += LowTone[j]*GraphBuffer[i+j];
|
||||
}
|
||||
for (j = 0; j < highLen; ++j) {
|
||||
highSum += HighTone[j] * GraphBuffer[i + j];
|
||||
}
|
||||
lowSum = abs(100 * lowSum / lowLen);
|
||||
highSum = abs(100 * highSum / highLen);
|
||||
GraphBuffer[i] = (highSum << 16) | lowSum;
|
||||
}
|
||||
|
||||
for(i = 0; i < GraphTraceLen - convLen - 16; ++i) {
|
||||
int lowTot = 0, highTot = 0;
|
||||
// 10 and 8 are f_s divided by f_l and f_h, rounded
|
||||
for (j = 0; j < 10; ++j) {
|
||||
lowTot += (GraphBuffer[i+j] & 0xffff);
|
||||
}
|
||||
for (j = 0; j < 8; j++) {
|
||||
highTot += (GraphBuffer[i + j] >> 16);
|
||||
}
|
||||
GraphBuffer[i] = lowTot - highTot;
|
||||
if (GraphBuffer[i] > maxMark) maxMark = GraphBuffer[i];
|
||||
if (GraphBuffer[i] < minMark) minMark = GraphBuffer[i];
|
||||
}
|
||||
|
||||
GraphTraceLen -= (convLen + 16);
|
||||
RepaintGraphWindow();
|
||||
|
||||
// Find bit-sync (3 lo followed by 3 high) (HID ONLY)
|
||||
int max = 0, maxPos = 0;
|
||||
for (i = 0; i < 6000; ++i) {
|
||||
int dec = 0;
|
||||
for (j = 0; j < 3 * lowLen; ++j) {
|
||||
dec -= GraphBuffer[i + j];
|
||||
}
|
||||
for (; j < 3 * (lowLen + highLen ); ++j) {
|
||||
dec += GraphBuffer[i + j];
|
||||
}
|
||||
if (dec > max) {
|
||||
max = dec;
|
||||
maxPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
// place start of bit sync marker in graph
|
||||
GraphBuffer[maxPos] = maxMark;
|
||||
GraphBuffer[maxPos + 1] = minMark;
|
||||
|
||||
maxPos += j;
|
||||
|
||||
// place end of bit sync marker in graph
|
||||
GraphBuffer[maxPos] = maxMark;
|
||||
GraphBuffer[maxPos+1] = minMark;
|
||||
|
||||
PrintAndLog("actual data bits start at sample %d", maxPos);
|
||||
PrintAndLog("length %d/%d", highLen, lowLen);
|
||||
|
||||
uint8_t bits[46] = {0x00};
|
||||
|
||||
// find bit pairs and manchester decode them
|
||||
for (i = 0; i < arraylen(bits) - 1; ++i) {
|
||||
int dec = 0;
|
||||
for (j = 0; j < lowLen; ++j) {
|
||||
dec -= GraphBuffer[maxPos + j];
|
||||
}
|
||||
for (; j < lowLen + highLen; ++j) {
|
||||
dec += GraphBuffer[maxPos + j];
|
||||
}
|
||||
maxPos += j;
|
||||
// place inter bit marker in graph
|
||||
GraphBuffer[maxPos] = maxMark;
|
||||
GraphBuffer[maxPos + 1] = minMark;
|
||||
|
||||
// hi and lo form a 64 bit pair
|
||||
hi = (hi << 1) | (lo >> 31);
|
||||
lo = (lo << 1);
|
||||
// store decoded bit as binary (in hi/lo) and text (in bits[])
|
||||
if(dec < 0) {
|
||||
bits[i] = '1';
|
||||
lo |= 1;
|
||||
} else {
|
||||
bits[i] = '0';
|
||||
}
|
||||
}
|
||||
PrintAndLog("bits: '%s'", bits);
|
||||
PrintAndLog("hex: %08x %08x", hi, lo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//attempt to psk1 demod graph buffer
|
||||
int PSKDemod(const char *Cmd, bool verbose)
|
||||
|
@ -1835,17 +1498,17 @@ int PSKDemod(const char *Cmd, bool verbose)
|
|||
int errCnt=0;
|
||||
errCnt = pskRawDemod(BitStream, &BitLen, &clk, &invert);
|
||||
if (errCnt > maxErr){
|
||||
if (g_debugMode==1 && verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||
if (g_debugMode || verbose) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||
return 0;
|
||||
}
|
||||
if (errCnt<0|| BitLen<16){ //throw away static - allow 1 and -1 (in case of threshold command first)
|
||||
if (g_debugMode==1 && verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||
if (g_debugMode || verbose) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||
return 0;
|
||||
}
|
||||
if (verbose){
|
||||
PrintAndLog("Tried PSK Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
|
||||
if (verbose || g_debugMode){
|
||||
PrintAndLog("\nUsing Clock:%d, invert:%d, Bits Found:%d",clk,invert,BitLen);
|
||||
if (errCnt>0){
|
||||
PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||
PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||
}
|
||||
}
|
||||
//prime demod buffer for output
|
||||
|
@ -1970,7 +1633,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
|
|||
//prime demod buffer for output
|
||||
setDemodBuf(BitStream,BitLen,0);
|
||||
|
||||
if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||
if (errCnt>0 && (verbose || g_debugMode)) PrintAndLog("# Errors during Demoding (shown as 7 in bit stream): %d",errCnt);
|
||||
if (verbose || g_debugMode) {
|
||||
PrintAndLog("NRZ demoded bitstream:");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
|
@ -2026,7 +1689,7 @@ int CmdPSK1rawDemod(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("PSK demoded bitstream:");
|
||||
PrintAndLog("PSK1 demoded bitstream:");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
printDemodBuff();
|
||||
return 1;
|
||||
|
@ -2295,10 +1958,10 @@ int CmdTuneSamples(const char *Cmd)
|
|||
PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
|
||||
PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
|
||||
|
||||
#define LF_UNUSABLE_V 2948 // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
|
||||
#define LF_MARGINAL_V 14739 // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
|
||||
#define HF_UNUSABLE_V 3167 // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||
#define HF_MARGINAL_V 7917 // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||
#define LF_UNUSABLE_V 2948 // was 2000. Changed due to bugfix in voltage measurements. LF results are now 47% higher.
|
||||
#define LF_MARGINAL_V 14739 // was 10000. Changed due to bugfix bug in voltage measurements. LF results are now 47% higher.
|
||||
#define HF_UNUSABLE_V 3167 // was 2000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||
#define HF_MARGINAL_V 7917 // was 5000. Changed due to bugfix in voltage measurements. HF results are now 58% higher.
|
||||
|
||||
if (peakv < LF_UNUSABLE_V)
|
||||
PrintAndLog("# Your LF antenna is unusable.");
|
||||
|
@ -2374,245 +2037,6 @@ int CmdRtrim(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Manchester demodulate a bitstream. The bitstream needs to be already in
|
||||
* the GraphBuffer as 0 and 1 values
|
||||
*
|
||||
* Give the clock rate as argument in order to help the sync - the algorithm
|
||||
* resyncs at each pulse anyway.
|
||||
*
|
||||
* Not optimized by any means, this is the 1st time I'm writing this type of
|
||||
* routine, feel free to improve...
|
||||
*
|
||||
* 1st argument: clock rate (as number of samples per clock rate)
|
||||
* Typical values can be 64, 32, 128...
|
||||
*/
|
||||
int CmdManchesterDemod(const char *Cmd)
|
||||
{
|
||||
int i, j, invert= 0;
|
||||
int bit;
|
||||
int clock;
|
||||
int lastval = 0;
|
||||
int low = 0;
|
||||
int high = 0;
|
||||
int hithigh, hitlow, first;
|
||||
int lc = 0;
|
||||
int bitidx = 0;
|
||||
int bit2idx = 0;
|
||||
int warnings = 0;
|
||||
|
||||
/* check if we're inverting output */
|
||||
if (*Cmd == 'i')
|
||||
{
|
||||
PrintAndLog("Inverting output");
|
||||
invert = 1;
|
||||
++Cmd;
|
||||
do
|
||||
++Cmd;
|
||||
while(*Cmd == ' '); // in case a 2nd argument was given
|
||||
}
|
||||
|
||||
/* Holds the decoded bitstream: each clock period contains 2 bits */
|
||||
/* later simplified to 1 bit after manchester decoding. */
|
||||
/* Add 10 bits to allow for noisy / uncertain traces without aborting */
|
||||
/* int BitStream[GraphTraceLen*2/clock+10]; */
|
||||
|
||||
/* But it does not work if compiling on WIndows: therefore we just allocate a */
|
||||
/* large array */
|
||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN] = {0};
|
||||
|
||||
/* Detect high and lows */
|
||||
for (i = 0; i < GraphTraceLen; i++)
|
||||
{
|
||||
if (GraphBuffer[i] > high)
|
||||
high = GraphBuffer[i];
|
||||
else if (GraphBuffer[i] < low)
|
||||
low = GraphBuffer[i];
|
||||
}
|
||||
|
||||
/* Get our clock */
|
||||
clock = GetAskClock(Cmd, high, 1);
|
||||
|
||||
int tolerance = clock/4;
|
||||
|
||||
/* Detect first transition */
|
||||
/* Lo-Hi (arbitrary) */
|
||||
/* skip to the first high */
|
||||
for (i= 0; i < GraphTraceLen; i++)
|
||||
if (GraphBuffer[i] == high)
|
||||
break;
|
||||
/* now look for the first low */
|
||||
for (; i < GraphTraceLen; i++)
|
||||
{
|
||||
if (GraphBuffer[i] == low)
|
||||
{
|
||||
lastval = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're not working with 1/0s, demod based off clock */
|
||||
if (high != 1)
|
||||
{
|
||||
bit = 0; /* We assume the 1st bit is zero, it may not be
|
||||
* the case: this routine (I think) has an init problem.
|
||||
* Ed.
|
||||
*/
|
||||
for (; i < (int)(GraphTraceLen / clock); i++)
|
||||
{
|
||||
hithigh = 0;
|
||||
hitlow = 0;
|
||||
first = 1;
|
||||
|
||||
/* Find out if we hit both high and low peaks */
|
||||
for (j = 0; j < clock; j++)
|
||||
{
|
||||
if (GraphBuffer[(i * clock) + j] == high)
|
||||
hithigh = 1;
|
||||
else if (GraphBuffer[(i * clock) + j] == low)
|
||||
hitlow = 1;
|
||||
|
||||
/* it doesn't count if it's the first part of our read
|
||||
because it's really just trailing from the last sequence */
|
||||
if (first && (hithigh || hitlow))
|
||||
hithigh = hitlow = 0;
|
||||
else
|
||||
first = 0;
|
||||
|
||||
if (hithigh && hitlow)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we didn't hit both high and low peaks, we had a bit transition */
|
||||
if (!hithigh || !hitlow)
|
||||
bit ^= 1;
|
||||
|
||||
BitStream[bit2idx++] = bit ^ invert;
|
||||
}
|
||||
}
|
||||
|
||||
/* standard 1/0 bitstream */
|
||||
else
|
||||
{
|
||||
|
||||
/* Then detect duration between 2 successive transitions */
|
||||
for (bitidx = 1; i < GraphTraceLen; i++)
|
||||
{
|
||||
if (GraphBuffer[i-1] != GraphBuffer[i])
|
||||
{
|
||||
lc = i-lastval;
|
||||
lastval = i;
|
||||
|
||||
// Error check: if bitidx becomes too large, we do not
|
||||
// have a Manchester encoded bitstream or the clock is really
|
||||
// wrong!
|
||||
if (bitidx > (GraphTraceLen*2/clock+8) ) {
|
||||
PrintAndLog("Error: the clock you gave is probably wrong, aborting.");
|
||||
return 0;
|
||||
}
|
||||
// Then switch depending on lc length:
|
||||
// Tolerance is 1/4 of clock rate (arbitrary)
|
||||
if (abs(lc-clock/2) < tolerance) {
|
||||
// Short pulse : either "1" or "0"
|
||||
BitStream[bitidx++]=GraphBuffer[i-1];
|
||||
} else if (abs(lc-clock) < tolerance) {
|
||||
// Long pulse: either "11" or "00"
|
||||
BitStream[bitidx++]=GraphBuffer[i-1];
|
||||
BitStream[bitidx++]=GraphBuffer[i-1];
|
||||
} else {
|
||||
// Error
|
||||
warnings++;
|
||||
PrintAndLog("Warning: Manchester decode error for pulse width detection.");
|
||||
PrintAndLog("(too many of those messages mean either the stream is not Manchester encoded, or clock is wrong)");
|
||||
|
||||
if (warnings > 10)
|
||||
{
|
||||
PrintAndLog("Error: too many detection errors, aborting.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// At this stage, we now have a bitstream of "01" ("1") or "10" ("0"), parse it into final decoded bitstream
|
||||
// Actually, we overwrite BitStream with the new decoded bitstream, we just need to be careful
|
||||
// to stop output at the final bitidx2 value, not bitidx
|
||||
for (i = 0; i < bitidx; i += 2) {
|
||||
if ((BitStream[i] == 0) && (BitStream[i+1] == 1)) {
|
||||
BitStream[bit2idx++] = 1 ^ invert;
|
||||
} else if ((BitStream[i] == 1) && (BitStream[i+1] == 0)) {
|
||||
BitStream[bit2idx++] = 0 ^ invert;
|
||||
} else {
|
||||
// We cannot end up in this state, this means we are unsynchronized,
|
||||
// move up 1 bit:
|
||||
i++;
|
||||
warnings++;
|
||||
PrintAndLog("Unsynchronized, resync...");
|
||||
PrintAndLog("(too many of those messages mean the stream is not Manchester encoded)");
|
||||
|
||||
if (warnings > 10)
|
||||
{
|
||||
PrintAndLog("Error: too many decode errors, aborting.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLog("Manchester decoded bitstream");
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
for (i = 0; i < (bit2idx-16); i+=16) {
|
||||
PrintAndLog("%i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i",
|
||||
BitStream[i],
|
||||
BitStream[i+1],
|
||||
BitStream[i+2],
|
||||
BitStream[i+3],
|
||||
BitStream[i+4],
|
||||
BitStream[i+5],
|
||||
BitStream[i+6],
|
||||
BitStream[i+7],
|
||||
BitStream[i+8],
|
||||
BitStream[i+9],
|
||||
BitStream[i+10],
|
||||
BitStream[i+11],
|
||||
BitStream[i+12],
|
||||
BitStream[i+13],
|
||||
BitStream[i+14],
|
||||
BitStream[i+15]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Modulate our data into manchester */
|
||||
int CmdManchesterMod(const char *Cmd)
|
||||
{
|
||||
int i, j;
|
||||
int clock;
|
||||
int bit, lastbit, wave;
|
||||
|
||||
/* Get our clock */
|
||||
clock = GetAskClock(Cmd, 0, 1);
|
||||
|
||||
wave = 0;
|
||||
lastbit = 1;
|
||||
for (i = 0; i < (int)(GraphTraceLen / clock); i++)
|
||||
{
|
||||
bit = GraphBuffer[i * clock] ^ 1;
|
||||
|
||||
for (j = 0; j < (int)(clock/2); j++)
|
||||
GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave;
|
||||
for (j = (int)(clock/2); j < clock; j++)
|
||||
GraphBuffer[(i * clock) + j] = bit ^ lastbit ^ wave ^ 1;
|
||||
|
||||
/* Keep track of how we start our wave and if we changed or not this time */
|
||||
wave ^= bit ^ lastbit;
|
||||
lastbit = bit;
|
||||
}
|
||||
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdNorm(const char *Cmd)
|
||||
{
|
||||
int i;
|
||||
|
@ -2677,20 +2101,6 @@ int CmdScale(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdThreshold(const char *Cmd)
|
||||
{
|
||||
int threshold = atoi(Cmd);
|
||||
|
||||
for (int i = 0; i < GraphTraceLen; ++i) {
|
||||
if (GraphBuffer[i] >= threshold)
|
||||
GraphBuffer[i] = 1;
|
||||
else
|
||||
GraphBuffer[i] = -1;
|
||||
}
|
||||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdDirectionalThreshold(const char *Cmd)
|
||||
{
|
||||
int8_t upThres = param_get8(Cmd, 0);
|
||||
|
@ -2758,19 +2168,15 @@ int CmdZerocrossings(const char *Cmd)
|
|||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"amp", CmdAmp, 1, "Amplify peaks"},
|
||||
//{"askdemod", Cmdaskdemod, 1, "<0 or 1> -- Attempt to demodulate simple ASK tags"},
|
||||
{"askedgedetect", CmdAskEdgeDetect, 1, "[threshold] Adjust Graph for manual ask demod using length of sample differences to detect the edge of a wave (default = 25)"},
|
||||
{"askem410xdemod", CmdAskEM410xDemod, 1, "[clock] [invert<0|1>] [maxErr] -- Demodulate an EM410x tag from GraphBuffer (args optional)"},
|
||||
{"askgproxiidemod", CmdG_Prox_II_Demod, 1, "Demodulate a G Prox II tag from GraphBuffer"},
|
||||
{"autocorr", CmdAutoCorr, 1, "[window length] [g] -- Autocorrelation over window - g to save back to GraphBuffer (overwrite)"},
|
||||
{"biphaserawdecode",CmdBiphaseDecodeRaw,1,"[offset] [invert<0|1>] Biphase decode bin stream in DemodBuffer (offset = 0|1 bits to shift the decode start)"},
|
||||
{"bitsamples", CmdBitsamples, 0, "Get raw samples as bitstring"},
|
||||
//{"bitstream", CmdBitstream, 1, "[clock rate] -- Convert waveform into a bitstream"},
|
||||
{"buffclear", CmdBuffClear, 1, "Clear sample buffer and graph window"},
|
||||
{"dec", CmdDec, 1, "Decimate samples"},
|
||||
{"detectclock", CmdDetectClockRate, 1, "[modulation] Detect clock rate of wave in GraphBuffer (options: 'a','f','n','p' for ask, fsk, nrz, psk respectively)"},
|
||||
//{"fskdemod", CmdFSKdemod, 1, "Demodulate graph window as a HID FSK"},
|
||||
{"fskawiddemod", CmdFSKdemodAWID, 1, "Demodulate an AWID FSK tag from GraphBuffer"},
|
||||
//{"fskfcdetect", CmdFSKfcDetect, 1, "Try to detect the Field Clock of an FSK wave"},
|
||||
{"fskhiddemod", CmdFSKdemodHID, 1, "Demodulate a HID FSK tag from GraphBuffer"},
|
||||
|
@ -2785,9 +2191,7 @@ static command_t CommandTable[] =
|
|||
{"load", CmdLoad, 1, "<filename> -- Load trace (to graph window"},
|
||||
{"ltrim", CmdLtrim, 1, "<samples> -- Trim samples from left of trace"},
|
||||
{"rtrim", CmdRtrim, 1, "<location to end trace> -- Trim samples from right of trace"},
|
||||
//{"mandemod", CmdManchesterDemod, 1, "[i] [clock rate] -- Manchester demodulate binary stream (option 'i' to invert output)"},
|
||||
{"manrawdecode", Cmdmandecoderaw, 1, "Manchester decode binary stream in DemodBuffer"},
|
||||
{"manmod", CmdManchesterMod, 1, "[clock rate] -- Manchester modulate a binary stream"},
|
||||
{"norm", CmdNorm, 1, "Normalize max/min to +/-128"},
|
||||
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
||||
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] -- print the data in the DemodBuffer - 'x' for hex output"},
|
||||
|
@ -2798,7 +2202,6 @@ static command_t CommandTable[] =
|
|||
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},
|
||||
{"setdebugmode", CmdSetDebugMode, 1, "<0|1> -- Turn on or off Debugging Mode for demods"},
|
||||
{"shiftgraphzero", CmdGraphShiftZero, 1, "<shift> -- Shift 0 for Graphed wave + or - shift value"},
|
||||
//{"threshold", CmdThreshold, 1, "<threshold> -- Maximize/minimize every value in the graph window depending on threshold"},
|
||||
{"dirthreshold", CmdDirectionalThreshold, 1, "<thres up> <thres down> -- Max rising higher up-thres/ Min falling lower down-thres, keep rest as prev."},
|
||||
{"tune", CmdTuneSamples, 0, "Get hw tune samples for graph window"},
|
||||
{"undec", CmdUndec, 1, "Un-decimate samples by 2"},
|
||||
|
|
|
@ -15,10 +15,7 @@ command_t * CmdDataCommands();
|
|||
|
||||
int CmdData(const char *Cmd);
|
||||
void printDemodBuff(void);
|
||||
void printBitStream(uint8_t BitStream[], uint32_t bitLen);
|
||||
void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx);
|
||||
int CmdAmp(const char *Cmd);
|
||||
int Cmdaskdemod(const char *Cmd);
|
||||
int CmdAskEM410xDemod(const char *Cmd);
|
||||
int CmdG_Prox_II_Demod(const char *Cmd);
|
||||
int Cmdaskrawdemod(const char *Cmd);
|
||||
|
@ -27,12 +24,10 @@ int AutoCorrelate(int window, bool SaveGrph, bool verbose);
|
|||
int CmdAutoCorr(const char *Cmd);
|
||||
int CmdBiphaseDecodeRaw(const char *Cmd);
|
||||
int CmdBitsamples(const char *Cmd);
|
||||
int CmdBitstream(const char *Cmd);
|
||||
int CmdBuffClear(const char *Cmd);
|
||||
int CmdDec(const char *Cmd);
|
||||
int CmdDetectClockRate(const char *Cmd);
|
||||
int CmdFSKdemodAWID(const char *Cmd);
|
||||
int CmdFSKdemod(const char *Cmd);
|
||||
int CmdFSKdemodHID(const char *Cmd);
|
||||
int CmdFSKdemodIO(const char *Cmd);
|
||||
int CmdFSKdemodParadox(const char *Cmd);
|
||||
|
@ -49,8 +44,6 @@ int CmdLoad(const char *Cmd);
|
|||
int CmdLtrim(const char *Cmd);
|
||||
int CmdRtrim(const char *Cmd);
|
||||
int Cmdmandecoderaw(const char *Cmd);
|
||||
int CmdManchesterDemod(const char *Cmd);
|
||||
int CmdManchesterMod(const char *Cmd);
|
||||
int CmdNorm(const char *Cmd);
|
||||
int CmdNRZrawDemod(const char *Cmd);
|
||||
int CmdPlot(const char *Cmd);
|
||||
|
@ -60,7 +53,6 @@ int CmdSamples(const char *Cmd);
|
|||
int CmdTuneSamples(const char *Cmd);
|
||||
int CmdSave(const char *Cmd);
|
||||
int CmdScale(const char *Cmd);
|
||||
int CmdThreshold(const char *Cmd);
|
||||
int CmdDirectionalThreshold(const char *Cmd);
|
||||
int CmdZerocrossings(const char *Cmd);
|
||||
int CmdIndalaDecode(const char *Cmd);
|
||||
|
|
|
@ -522,7 +522,8 @@ static void ChkBitstream(const char *str)
|
|||
}
|
||||
}
|
||||
}
|
||||
//appears to attempt to simulate manchester
|
||||
//Attempt to simulate any wave in buffer (one bit per output sample)
|
||||
// converts GraphBuffer to bitstream (based on zero crossings) if needed.
|
||||
int CmdLFSim(const char *Cmd)
|
||||
{
|
||||
int i,j;
|
||||
|
@ -530,11 +531,11 @@ int CmdLFSim(const char *Cmd)
|
|||
|
||||
sscanf(Cmd, "%i", &gap);
|
||||
|
||||
/* convert to bitstream if necessary */
|
||||
// convert to bitstream if necessary
|
||||
|
||||
ChkBitstream(Cmd);
|
||||
|
||||
//can send 512 bits at a time (1 byte sent per bit...)
|
||||
//can send only 512 bits at a time (1 byte sent per bit...)
|
||||
printf("Sending [%d bytes]", GraphTraceLen);
|
||||
for (i = 0; i < GraphTraceLen; i += USB_CMD_DATA_SIZE) {
|
||||
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {i, 0, 0}};
|
||||
|
@ -606,8 +607,8 @@ int usage_lf_simpsk(void)
|
|||
// - allow pull data from DemodBuffer
|
||||
int CmdLFfskSim(const char *Cmd)
|
||||
{
|
||||
//might be able to autodetect FC and clock from Graphbuffer if using demod buffer
|
||||
//will need FChigh, FClow, Clock, and bitstream
|
||||
//might be able to autodetect FCs and clock from Graphbuffer if using demod buffer
|
||||
// otherwise will need FChigh, FClow, Clock, and bitstream
|
||||
uint8_t fcHigh=0, fcLow=0, clk=0;
|
||||
uint8_t invert=0;
|
||||
bool errors = FALSE;
|
||||
|
@ -682,6 +683,8 @@ int CmdLFfskSim(const char *Cmd)
|
|||
} else {
|
||||
setDemodBuf(data, dataLen, 0);
|
||||
}
|
||||
|
||||
//default if not found
|
||||
if (clk == 0) clk = 50;
|
||||
if (fcHigh == 0) fcHigh = 10;
|
||||
if (fcLow == 0) fcLow = 8;
|
||||
|
@ -706,9 +709,8 @@ int CmdLFfskSim(const char *Cmd)
|
|||
int CmdLFaskSim(const char *Cmd)
|
||||
{
|
||||
//autodetect clock from Graphbuffer if using demod buffer
|
||||
//will need clock, invert, manchester/raw as m or r, separator as s, and bitstream
|
||||
// needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
|
||||
uint8_t encoding = 1, separator = 0;
|
||||
//char cmdp = Cmd[0], par3='m', par4=0;
|
||||
uint8_t clk=0, invert=0;
|
||||
bool errors = FALSE;
|
||||
char hexData[32] = {0x00};
|
||||
|
@ -913,30 +915,6 @@ int CmdLFSimBidir(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* simulate an LF Manchester encoded tag with specified bitstream, clock rate and inter-id gap */
|
||||
/*
|
||||
int CmdLFSimManchester(const char *Cmd)
|
||||
{
|
||||
static int clock, gap;
|
||||
static char data[1024], gapstring[8];
|
||||
|
||||
sscanf(Cmd, "%i %s %i", &clock, &data[0], &gap);
|
||||
|
||||
ClearGraph(0);
|
||||
|
||||
for (int i = 0; i < strlen(data) ; ++i)
|
||||
AppendGraph(0, clock, data[i]- '0');
|
||||
|
||||
CmdManchesterMod("");
|
||||
|
||||
RepaintGraphWindow();
|
||||
|
||||
sprintf(&gapstring[0], "%i", gap);
|
||||
CmdLFSim(gapstring);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int CmdVchDemod(const char *Cmd)
|
||||
{
|
||||
// Is this the entire sync pattern, or does this also include some
|
||||
|
@ -1033,8 +1011,8 @@ int CmdLFfind(const char *Cmd)
|
|||
}
|
||||
|
||||
if (!offline && (cmdp != '1')){
|
||||
ans=CmdLFRead("");
|
||||
ans=CmdSamples("20000");
|
||||
CmdLFRead("s");
|
||||
getSamples("30000",false);
|
||||
} else if (GraphTraceLen < 1000) {
|
||||
PrintAndLog("Data in Graphbuffer was too small.");
|
||||
return 0;
|
||||
|
@ -1105,20 +1083,18 @@ int CmdLFfind(const char *Cmd)
|
|||
PrintAndLog("\nChecking for Unknown tags:\n");
|
||||
ans=AutoCorrelate(4000, FALSE, FALSE);
|
||||
if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans);
|
||||
ans=GetFskClock("",FALSE,FALSE); //CmdDetectClockRate("F"); //
|
||||
ans=GetFskClock("",FALSE,FALSE);
|
||||
if (ans != 0){ //fsk
|
||||
ans=FSKrawDemod("",FALSE);
|
||||
ans=FSKrawDemod("",TRUE);
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nUnknown FSK Modulated Tag Found!");
|
||||
printDemodBuff();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ans=ASKmanDemod("",FALSE,FALSE);
|
||||
ans=ASKmanDemod("0 0 0",TRUE,FALSE);
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
|
||||
PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
|
||||
printDemodBuff();
|
||||
return 1;
|
||||
}
|
||||
ans=CmdPSK1rawDemod("");
|
||||
|
@ -1126,7 +1102,6 @@ int CmdLFfind(const char *Cmd)
|
|||
PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'");
|
||||
PrintAndLog("\nCould also be PSK3 - [currently not supported]");
|
||||
PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
|
||||
printDemodBuff();
|
||||
return 1;
|
||||
}
|
||||
PrintAndLog("\nNo Data Found!\n");
|
||||
|
@ -1152,7 +1127,6 @@ static command_t CommandTable[] =
|
|||
{"simfsk", CmdLFfskSim, 0, "[c <clock>] [i] [H <fcHigh>] [L <fcLow>] [d <hexdata>] -- Simulate LF FSK tag from demodbuffer or input"},
|
||||
{"simpsk", CmdLFpskSim, 0, "[1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>] -- Simulate LF PSK tag from demodbuffer or input"},
|
||||
{"simbidir", CmdLFSimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
|
||||
//{"simman", CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
|
||||
{"snoop", CmdLFSnoop, 0, "['l'|'h'|<divisor>] [trigger threshold]-- Snoop LF (l:125khz, h:134khz)"},
|
||||
{"ti", CmdLFTI, 1, "{ TI RFIDs... }"},
|
||||
{"hitag", CmdLFHitag, 1, "{ Hitag tags and transponders... }"},
|
||||
|
|
|
@ -23,7 +23,6 @@ int CmdLFaskSim(const char *Cmd);
|
|||
int CmdLFfskSim(const char *Cmd);
|
||||
int CmdLFpskSim(const char *Cmd);
|
||||
int CmdLFSimBidir(const char *Cmd);
|
||||
//int CmdLFSimManchester(const char *Cmd);
|
||||
int CmdLFSnoop(const char *Cmd);
|
||||
int CmdVchDemod(const char *Cmd);
|
||||
int CmdLFfind(const char *Cmd);
|
||||
|
|
|
@ -140,7 +140,6 @@ int CmdEM410xSim(const char *Cmd)
|
|||
* rate gets lower, then grow the number of samples
|
||||
* Changed by martin, 4000 x 4 = 16000,
|
||||
* see http://www.proxmark.org/forum/viewtopic.php?pid=7235#p7235
|
||||
|
||||
*/
|
||||
int CmdEM410xWatch(const char *Cmd)
|
||||
{
|
||||
|
@ -151,7 +150,7 @@ int CmdEM410xWatch(const char *Cmd)
|
|||
}
|
||||
|
||||
CmdLFRead("s");
|
||||
getSamples("8192",true); //capture enough to get 2 full messages
|
||||
getSamples("8201",true); //capture enough to get 2 complete preambles (4096*2+9)
|
||||
} while (!CmdEM410xRead(""));
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "cmdlfhid.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
/*
|
||||
int CmdHIDDemod(const char *Cmd)
|
||||
{
|
||||
if (GraphTraceLen < 4800) {
|
||||
|
@ -36,7 +36,7 @@ int CmdHIDDemod(const char *Cmd)
|
|||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
int CmdHIDDemodFSK(const char *Cmd)
|
||||
{
|
||||
int findone=0;
|
||||
|
@ -106,7 +106,7 @@ int CmdHIDClone(const char *Cmd)
|
|||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"},
|
||||
//{"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"},
|
||||
{"fskdemod", CmdHIDDemodFSK, 0, "['1'] Realtime HID FSK demodulator (option '1' for one tag only)"},
|
||||
{"sim", CmdHIDSim, 0, "<ID> -- HID tag simulator"},
|
||||
{"clone", CmdHIDClone, 0, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
#define CMDLFHID_H__
|
||||
|
||||
int CmdLFHID(const char *Cmd);
|
||||
|
||||
int CmdHIDDemod(const char *Cmd);
|
||||
//int CmdHIDDemod(const char *Cmd);
|
||||
int CmdHIDDemodFSK(const char *Cmd);
|
||||
int CmdHIDSim(const char *Cmd);
|
||||
int CmdHIDClone(const char *Cmd);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@ int CmdIODemodFSK(const char *Cmd)
|
|||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int CmdIOProxDemod(const char *Cmd){
|
||||
if (GraphTraceLen < 4800) {
|
||||
PrintAndLog("too short; need at least 4800 samples");
|
||||
|
@ -37,7 +37,7 @@ int CmdIOProxDemod(const char *Cmd){
|
|||
RepaintGraphWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
int CmdIOClone(const char *Cmd)
|
||||
{
|
||||
unsigned int hi = 0, lo = 0;
|
||||
|
@ -67,7 +67,7 @@ int CmdIOClone(const char *Cmd)
|
|||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
|
||||
//{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
|
||||
{"fskdemod", CmdIODemodFSK, 0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
|
||||
{"clone", CmdIOClone, 0, "Clone ioProx Tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
|
@ -83,4 +83,4 @@ int CmdHelp(const char *Cmd)
|
|||
{
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,31 +147,37 @@ int CmdT55xxSetConfig(const char *Cmd) {
|
|||
param_getstr(Cmd, cmdp+1, modulation);
|
||||
cmdp += 2;
|
||||
|
||||
if ( strcmp(modulation, "FSK" ) == 0)
|
||||
if ( strcmp(modulation, "FSK" ) == 0) {
|
||||
config.modulation = DEMOD_FSK;
|
||||
else if ( strcmp(modulation, "FSK1" ) == 0)
|
||||
} else if ( strcmp(modulation, "FSK1" ) == 0) {
|
||||
config.modulation = DEMOD_FSK1;
|
||||
else if ( strcmp(modulation, "FSK1a" ) == 0)
|
||||
config.inverted=1;
|
||||
} else if ( strcmp(modulation, "FSK1a" ) == 0) {
|
||||
config.modulation = DEMOD_FSK1a;
|
||||
else if ( strcmp(modulation, "FSK2" ) == 0)
|
||||
config.inverted=0;
|
||||
} else if ( strcmp(modulation, "FSK2" ) == 0) {
|
||||
config.modulation = DEMOD_FSK2;
|
||||
else if ( strcmp(modulation, "FSK2a" ) == 0)
|
||||
config.inverted=0;
|
||||
} else if ( strcmp(modulation, "FSK2a" ) == 0) {
|
||||
config.modulation = DEMOD_FSK2a;
|
||||
else if ( strcmp(modulation, "ASK" ) == 0)
|
||||
config.inverted=1;
|
||||
} else if ( strcmp(modulation, "ASK" ) == 0) {
|
||||
config.modulation = DEMOD_ASK;
|
||||
else if ( strcmp(modulation, "NRZ" ) == 0)
|
||||
} else if ( strcmp(modulation, "NRZ" ) == 0) {
|
||||
config.modulation = DEMOD_NRZ;
|
||||
else if ( strcmp(modulation, "PSK1" ) == 0)
|
||||
} else if ( strcmp(modulation, "PSK1" ) == 0) {
|
||||
config.modulation = DEMOD_PSK1;
|
||||
else if ( strcmp(modulation, "PSK2" ) == 0)
|
||||
} else if ( strcmp(modulation, "PSK2" ) == 0) {
|
||||
config.modulation = DEMOD_PSK2;
|
||||
else if ( strcmp(modulation, "PSK3" ) == 0)
|
||||
} else if ( strcmp(modulation, "PSK3" ) == 0) {
|
||||
config.modulation = DEMOD_PSK3;
|
||||
else if ( strcmp(modulation, "BIa" ) == 0)
|
||||
} else if ( strcmp(modulation, "BIa" ) == 0) {
|
||||
config.modulation = DEMOD_BIa;
|
||||
else if ( strcmp(modulation, "BI" ) == 0)
|
||||
config.inverted=1;
|
||||
} else if ( strcmp(modulation, "BI" ) == 0) {
|
||||
config.modulation = DEMOD_BI;
|
||||
else {
|
||||
config.inverted=0;
|
||||
} else {
|
||||
PrintAndLog("Unknown modulation '%s'", modulation);
|
||||
errors = TRUE;
|
||||
}
|
||||
|
@ -264,55 +270,36 @@ bool DecodeT55xxBlock(){
|
|||
|
||||
switch( config.modulation ){
|
||||
case DEMOD_FSK:
|
||||
//CmdLtrim("26");
|
||||
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );
|
||||
CmdLtrim(cmdStr);
|
||||
sprintf(cmdStr,"%d %d", bitRate[config.bitrate], config.inverted );
|
||||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_FSK1:
|
||||
//CmdLtrim("26");
|
||||
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );
|
||||
CmdLtrim(cmdStr);
|
||||
sprintf(cmdStr,"%d 1 8 5", bitRate[config.bitrate] );
|
||||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_FSK1a:
|
||||
//CmdLtrim("26");
|
||||
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );
|
||||
CmdLtrim(cmdStr);
|
||||
sprintf(cmdStr,"%d 0 8 5", bitRate[config.bitrate] );
|
||||
sprintf(cmdStr,"%d %d 8 5", bitRate[config.bitrate], config.inverted );
|
||||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_FSK2:
|
||||
//CmdLtrim("26");
|
||||
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );
|
||||
CmdLtrim(cmdStr);
|
||||
sprintf(cmdStr,"%d 0 10 8", bitRate[config.bitrate] );
|
||||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_FSK2a:
|
||||
//CmdLtrim("26");
|
||||
sprintf(cmdStr,"%d", bitRate[config.bitrate]/2 );
|
||||
CmdLtrim(cmdStr);
|
||||
sprintf(cmdStr,"%d 1 10 8", bitRate[config.bitrate] );
|
||||
sprintf(cmdStr,"%d %d 10 8", bitRate[config.bitrate], config.inverted );
|
||||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_ASK:
|
||||
sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
sprintf(cmdStr,"%d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
ans = ASKmanDemod(cmdStr, FALSE, FALSE);
|
||||
break;
|
||||
case DEMOD_PSK1:
|
||||
sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
sprintf(cmdStr,"%d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
ans = PSKDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_PSK2:
|
||||
sprintf(cmdStr,"%d 1", bitRate[config.bitrate] );
|
||||
ans = PSKDemod(cmdStr, FALSE);
|
||||
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||
break;
|
||||
case DEMOD_PSK3:
|
||||
sprintf(cmdStr,"%d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
case DEMOD_PSK2: //inverted won't affect this
|
||||
case DEMOD_PSK3: //not fully implemented
|
||||
sprintf(cmdStr,"%d 0 1", bitRate[config.bitrate] );
|
||||
ans = PSKDemod(cmdStr, FALSE);
|
||||
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||
break;
|
||||
|
@ -321,11 +308,8 @@ bool DecodeT55xxBlock(){
|
|||
ans = NRZrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_BI:
|
||||
sprintf(cmdStr,"0 %d 0 1", bitRate[config.bitrate] );
|
||||
ans = ASKbiphaseDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_BIa:
|
||||
sprintf(cmdStr,"0 %d 1 1", bitRate[config.bitrate] );
|
||||
sprintf(cmdStr,"0 %d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
ans = ASKbiphaseDemod(cmdStr, FALSE);
|
||||
break;
|
||||
default:
|
||||
|
@ -516,33 +500,9 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
|
|||
uint8_t detRate = 0;
|
||||
switch( mod ){
|
||||
case DEMOD_FSK:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_FSK1:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_FSK1a:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_FSK2:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_FSK2a:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
|
@ -551,6 +511,8 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
|
|||
}
|
||||
break;
|
||||
case DEMOD_ASK:
|
||||
case DEMOD_BI:
|
||||
case DEMOD_BIa:
|
||||
detRate = GetAskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
|
@ -558,19 +520,7 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
|
|||
}
|
||||
break;
|
||||
case DEMOD_PSK1:
|
||||
detRate = GetPskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_PSK2:
|
||||
detRate = GetPskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_PSK3:
|
||||
detRate = GetPskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
|
@ -585,13 +535,6 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
|
|||
return TRUE;
|
||||
}
|
||||
break;
|
||||
case DEMOD_BI:
|
||||
detRate = GetAskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate) {
|
||||
config.bitrate = readRate;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -606,18 +549,18 @@ bool test(uint8_t mode, uint8_t *offset){
|
|||
si = idx;
|
||||
if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;
|
||||
|
||||
uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
|
||||
uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
|
||||
uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
|
||||
// 2nibble must be zeroed.
|
||||
// moved test to here, since this gets most faults first.
|
||||
if ( resv > 0x00) continue;
|
||||
|
||||
uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //new
|
||||
uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //new could check bit rate
|
||||
uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate
|
||||
uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate
|
||||
uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode
|
||||
uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; //new
|
||||
//uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //new could check psk cr
|
||||
uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24 , 30, 31 could be tested for 0 if not extended mode
|
||||
uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1;
|
||||
//uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
|
||||
uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
|
||||
uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
|
||||
|
||||
//if extended mode
|
||||
|
@ -628,9 +571,8 @@ bool test(uint8_t mode, uint8_t *offset){
|
|||
}
|
||||
//test modulation
|
||||
if (!testModulation(mode, modread)) continue;
|
||||
|
||||
*offset = idx;
|
||||
if (!testBitRate(bitRate, mode)) continue;
|
||||
*offset = idx;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -922,7 +864,7 @@ int AquireData( uint8_t block ){
|
|||
}
|
||||
|
||||
char * GetBitRateStr(uint32_t id){
|
||||
static char buf[40];
|
||||
static char buf[20];
|
||||
char *retStr = buf;
|
||||
switch (id){
|
||||
case 0:
|
||||
|
@ -957,7 +899,6 @@ char * GetBitRateStr(uint32_t id){
|
|||
return buf;
|
||||
}
|
||||
|
||||
|
||||
char * GetSaferStr(uint32_t id){
|
||||
static char buf[40];
|
||||
char *retStr = buf;
|
||||
|
@ -974,7 +915,7 @@ char * GetSaferStr(uint32_t id){
|
|||
}
|
||||
|
||||
char * GetModulationStr( uint32_t id){
|
||||
static char buf[40];
|
||||
static char buf[60];
|
||||
char *retStr = buf;
|
||||
|
||||
switch (id){
|
||||
|
|
|
@ -53,11 +53,11 @@ void save_restoreGB(uint8_t saveOpt)
|
|||
static bool GB_Saved = false;
|
||||
|
||||
if (saveOpt==1) { //save
|
||||
memcpy(SavedGB,GraphBuffer, sizeof(GraphBuffer));
|
||||
memcpy(SavedGB, GraphBuffer, sizeof(GraphBuffer));
|
||||
SavedGBlen = GraphTraceLen;
|
||||
GB_Saved=true;
|
||||
} else if (GB_Saved){
|
||||
memcpy(GraphBuffer,SavedGB, sizeof(GraphBuffer));
|
||||
memcpy(GraphBuffer, SavedGB, sizeof(GraphBuffer));
|
||||
GraphTraceLen = SavedGBlen;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -121,19 +121,24 @@ char * sprint_hex(const uint8_t * data, const size_t len) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
char * sprint_bin(const uint8_t * data, const size_t len) {
|
||||
char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) {
|
||||
|
||||
int maxLen = ( len > 1024) ? 1024 : len;
|
||||
static char buf[1024];
|
||||
char * tmp = buf;
|
||||
size_t i;
|
||||
char *tmp = buf;
|
||||
|
||||
for (i=0; i < maxLen; ++i, ++tmp)
|
||||
sprintf(tmp, "%u", data[i]);
|
||||
for (size_t i=0; i < maxLen; ++i){
|
||||
sprintf(tmp++, "%u", data[i]);
|
||||
if (breaks > 0 && !((i+1) % breaks))
|
||||
sprintf(tmp++, "%s","\n");
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *sprint_bin(const uint8_t *data, const size_t len) {
|
||||
return sprint_bin_break(data, len, 0);
|
||||
}
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
|
||||
{
|
||||
while (len--) {
|
||||
|
|
|
@ -39,6 +39,7 @@ void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
|
|||
void print_hex(const uint8_t * data, const size_t len);
|
||||
char * sprint_hex(const uint8_t * data, const size_t len);
|
||||
char * sprint_bin(const uint8_t * data, const size_t len);
|
||||
char * sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
|
||||
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
|
||||
uint64_t bytes_to_num(uint8_t* src, size_t len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue