mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-11 07:46:09 -07:00
lf psk demods
clarify existing as psk1 added psk2 demod
This commit is contained in:
parent
9c0f13d5dd
commit
04d2721b3c
3 changed files with 63 additions and 23 deletions
|
@ -721,8 +721,8 @@ int CmdFSKdemodHID(const char *Cmd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//by marshmellow (based on existing demod + holiman's refactor)
|
//by marshmellow
|
||||||
//Paradox Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded)
|
//Paradox Prox demod - FSK RF/50 with preamble of 00001111 (then manchester encoded)
|
||||||
//print full Paradox Prox ID and some bit format details if found
|
//print full Paradox Prox ID and some bit format details if found
|
||||||
int CmdFSKdemodParadox(const char *Cmd)
|
int CmdFSKdemodParadox(const char *Cmd)
|
||||||
{
|
{
|
||||||
|
@ -1196,7 +1196,7 @@ int CmdDetectNRZpskClockRate(const char *Cmd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PSKnrzDemod(const char *Cmd)
|
int PSKnrzDemod(const char *Cmd, uint8_t verbose)
|
||||||
{
|
{
|
||||||
int invert=0;
|
int invert=0;
|
||||||
int clk=0;
|
int clk=0;
|
||||||
|
@ -1213,7 +1213,7 @@ int PSKnrzDemod(const char *Cmd)
|
||||||
if (g_debugMode==1) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
if (g_debugMode==1) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PrintAndLog("Tried PSK/NRZ Demod using Clock: %d - invert: %d - Bits Found: %d",clk,invert,BitLen);
|
if (verbose) PrintAndLog("Tried PSK/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);
|
||||||
|
@ -1226,9 +1226,9 @@ int CmdIndalaDecode(const char *Cmd)
|
||||||
{
|
{
|
||||||
int ans;
|
int ans;
|
||||||
if (strlen(Cmd)>0){
|
if (strlen(Cmd)>0){
|
||||||
ans = PSKnrzDemod(Cmd);
|
ans = PSKnrzDemod(Cmd, 0);
|
||||||
} else{ //default to RF/32
|
} else{ //default to RF/32
|
||||||
ans = PSKnrzDemod("32");
|
ans = PSKnrzDemod("32", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ans < 0){
|
if (ans < 0){
|
||||||
|
@ -1307,13 +1307,13 @@ int CmdPskClean(const char *Cmd)
|
||||||
|
|
||||||
// by marshmellow
|
// by marshmellow
|
||||||
// takes 2 arguments - clock and invert both as integers
|
// takes 2 arguments - clock and invert both as integers
|
||||||
//attempts to demodulate ask only
|
// attempts to demodulate psk only
|
||||||
//prints binary found and saves in graphbuffer for further commands
|
// prints binary found and saves in demodbuffer for further commands
|
||||||
int CmdpskNRZrawDemod(const char *Cmd)
|
int CmdpskNRZrawDemod(const char *Cmd)
|
||||||
{
|
{
|
||||||
int errCnt;
|
int errCnt;
|
||||||
|
|
||||||
errCnt = PSKnrzDemod(Cmd);
|
errCnt = PSKnrzDemod(Cmd, 1);
|
||||||
//output
|
//output
|
||||||
if (errCnt<0){
|
if (errCnt<0){
|
||||||
if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt);
|
if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt);
|
||||||
|
@ -1335,6 +1335,32 @@ int CmdpskNRZrawDemod(const char *Cmd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// by marshmellow
|
||||||
|
// takes same args as cmdpsknrzrawdemod
|
||||||
|
int CmdPSK2rawDemod(const char *Cmd)
|
||||||
|
{
|
||||||
|
int errCnt=0;
|
||||||
|
errCnt=PSKnrzDemod(Cmd, 1);
|
||||||
|
if (errCnt<0){
|
||||||
|
if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||||
|
if (errCnt>0){
|
||||||
|
if (g_debugMode){
|
||||||
|
PrintAndLog("# Errors during Demoding (shown as 77 in bit stream): %d",errCnt);
|
||||||
|
PrintAndLog("PSK2 demoded bitstream:");
|
||||||
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
|
printDemodBuff();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
PrintAndLog("PSK2 demoded bitstream:");
|
||||||
|
// Now output the bitstream to the scrollback by line of 16 bits
|
||||||
|
printDemodBuff();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int CmdGrid(const char *Cmd)
|
int CmdGrid(const char *Cmd)
|
||||||
{
|
{
|
||||||
sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY);
|
sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY);
|
||||||
|
@ -1949,8 +1975,9 @@ static command_t CommandTable[] =
|
||||||
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
||||||
{"pskclean", CmdPskClean, 1, "Attempt to clean psk wave"},
|
{"pskclean", CmdPskClean, 1, "Attempt to clean psk wave"},
|
||||||
{"pskdetectclock",CmdDetectNRZpskClockRate, 1, "Detect ASK, PSK, or NRZ clock rate"},
|
{"pskdetectclock",CmdDetectNRZpskClockRate, 1, "Detect ASK, PSK, or NRZ clock rate"},
|
||||||
{"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk indala tags and output ID binary & hex (args optional)"},
|
{"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 indala tags and output ID binary & hex (args optional)"},
|
||||||
{"psknrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk or nrz tags and output binary (args optional)"},
|
{"psk1nrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 or nrz tags and output binary (args optional)"},
|
||||||
|
{"psk2rawdemod", CmdPSK2rawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk2 tags and output binary (args optional)"},
|
||||||
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window"},
|
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window"},
|
||||||
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
|
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
|
||||||
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},
|
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},
|
||||||
|
|
|
@ -816,7 +816,6 @@ int PyramiddemodFSK(uint8_t *dest, size_t size)
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// by marshmellow
|
// by marshmellow
|
||||||
// not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
|
// not perfect especially with lower clocks or VERY good antennas (heavy wave clipping)
|
||||||
// maybe somehow adjust peak trimming value based on samples to fix?
|
// maybe somehow adjust peak trimming value based on samples to fix?
|
||||||
|
@ -885,7 +884,6 @@ int DetectASKClock(uint8_t dest[], size_t size, int clock)
|
||||||
return clk[best];
|
return clk[best];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
//detect psk clock by reading #peaks vs no peaks(or errors)
|
//detect psk clock by reading #peaks vs no peaks(or errors)
|
||||||
int DetectpskNRZClock(uint8_t dest[], size_t size, int clock)
|
int DetectpskNRZClock(uint8_t dest[], size_t size, int clock)
|
||||||
|
@ -999,6 +997,23 @@ void pskCleanWave(uint8_t *BitStream, size_t size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// by marshmellow
|
||||||
|
// convert psk1 demod to psk2 demod
|
||||||
|
// only transition waves are 1s
|
||||||
|
void psk1TOpsk2(uint8_t *BitStream, size_t size)
|
||||||
|
{
|
||||||
|
size_t i=1;
|
||||||
|
uint8_t lastBit=BitStream[0];
|
||||||
|
for (; i<size; i++){
|
||||||
|
if (lastBit!=BitStream[i]){
|
||||||
|
lastBit=BitStream[i];
|
||||||
|
BitStream[i]=1;
|
||||||
|
} else {
|
||||||
|
BitStream[i]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// redesigned by marshmellow adjusted from existing decode functions
|
// redesigned by marshmellow adjusted from existing decode functions
|
||||||
// indala id decoding - only tested on 26 bit tags, but attempted to make it work for more
|
// indala id decoding - only tested on 26 bit tags, but attempted to make it work for more
|
||||||
|
@ -1064,9 +1079,8 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// by marshmellow - demodulate PSK1 wave or NRZ wave (both similar enough)
|
// by marshmellow - demodulate PSK1 wave or NRZ wave (both similar enough)
|
||||||
//peaks switch bit (high=1 low=0) each clock cycle = 1 bit determined by last peak
|
// peaks invert bit (high=1 low=0) each clock cycle = 1 bit determined by last peak
|
||||||
int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert)
|
int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert)
|
||||||
{
|
{
|
||||||
pskCleanWave(dest,*size);
|
pskCleanWave(dest,*size);
|
||||||
|
@ -1087,7 +1101,6 @@ int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert)
|
||||||
uint32_t bestStart = *size;
|
uint32_t bestStart = *size;
|
||||||
uint32_t maxErr = (*size/1000);
|
uint32_t maxErr = (*size/1000);
|
||||||
uint32_t bestErrCnt = maxErr;
|
uint32_t bestErrCnt = maxErr;
|
||||||
//uint8_t midBit=0;
|
|
||||||
uint8_t curBit=0;
|
uint8_t curBit=0;
|
||||||
uint8_t bitHigh=0;
|
uint8_t bitHigh=0;
|
||||||
uint8_t ignorewin=*clk/8;
|
uint8_t ignorewin=*clk/8;
|
||||||
|
@ -1198,7 +1211,6 @@ int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert)
|
||||||
return errCnt;
|
return errCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//by marshmellow
|
//by marshmellow
|
||||||
//detects the bit clock for FSK given the high and low Field Clocks
|
//detects the bit clock for FSK given the high and low Field Clocks
|
||||||
uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow)
|
uint8_t detectFSKClk(uint8_t *BitStream, size_t size, uint8_t fcHigh, uint8_t fcLow)
|
||||||
|
|
|
@ -27,6 +27,7 @@ int IOdemodFSK(uint8_t *dest, size_t size);
|
||||||
int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow);
|
int fskdemod(uint8_t *dest, size_t size, uint8_t rfLen, uint8_t invert, uint8_t fchigh, uint8_t fclow);
|
||||||
uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
|
uint32_t bytebits_to_byte(uint8_t* src, size_t numbits);
|
||||||
int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert);
|
int pskNRZrawDemod(uint8_t *dest, size_t *size, int *clk, int *invert);
|
||||||
|
void psk1TOpsk2(uint8_t *BitStream, size_t size);
|
||||||
int DetectpskNRZClock(uint8_t dest[], size_t size, int clock);
|
int DetectpskNRZClock(uint8_t dest[], size_t size, int clock);
|
||||||
int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert);
|
int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert);
|
||||||
void pskCleanWave(uint8_t *bitStream, size_t size);
|
void pskCleanWave(uint8_t *bitStream, size_t size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue