bit ^= 1;
AppendGraph(0, clock, bit);
- // for (j = 0; j < (int)(clock/2); j++)
- // GraphBuffer[(i * clock) + j] = bit ^ 1;
- // for (j = (int)(clock/2); j < clock; j++)
- // GraphBuffer[(i * clock) + j] = bit;
}
RepaintGraphWindow();
{
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
//set defaults
- int rfLen = 50;
+ int rfLen = 0;
int invert=0;
- int fchigh=10;
- int fclow=8;
+ int fchigh=0;
+ int fclow=0;
//set options from parameters entered with the command
sscanf(Cmd, "%i %i %i %i", &rfLen, &invert, &fchigh, &fclow);
if (strlen(Cmd)>0 && strlen(Cmd)<=2) {
if (rfLen==1){
invert=1; //if invert option only is used
- rfLen = 50;
- } else if(rfLen==0) rfLen=50;
+ rfLen = 0;
+ }
}
- PrintAndLog("Args invert: %d - Clock:%d - fchigh:%d - fclow: %d",invert,rfLen,fchigh, fclow);
+
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
size_t BitLen = getFromGraphBuf(BitStream);
+ //get field clock lengths
+ uint16_t fcs=0;
+ if (fchigh==0 || fclow == 0){
+ fcs=countFC(BitStream, BitLen);
+ if (fcs==0){
+ fchigh=10;
+ fclow=8;
+ }else{
+ fchigh = (fcs >> 8) & 0xFF;
+ fclow = fcs & 0xFF;
+ }
+ }
+ //get bit clock length
+ if (rfLen==0){
+ rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
+ if (rfLen == 0) rfLen = 50;
+ }
+ 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){
PrintAndLog("FSK decoded bitstream:");
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
size_t BitLen = getFromGraphBuf(BitStream);
//get binary from fsk wave
- size_t idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
+ int idx = HIDdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
if (idx<0){
- if (g_debugMode) PrintAndLog("DEBUG: Error demoding fsk");
+ if (g_debugMode){
+ if (idx==-1){
+ PrintAndLog("DEBUG: Just Noise Detected");
+ } else if (idx == -2) {
+ PrintAndLog("DEBUG: Error demoding fsk");
+ } else if (idx == -3) {
+ PrintAndLog("DEBUG: Preamble not found");
+ } else if (idx == -4) {
+ PrintAndLog("DEBUG: Error in Manchester data, SIZE: %d", BitLen);
+ } else {
+ PrintAndLog("DEBUG: Error demoding fsk %d", idx);
+ }
+ }
return 0;
}
if (hi2==0 && hi==0 && lo==0) {
return 1;
}
-//by marshmellow (based on existing demod + holiman's refactor)
-//Paradox Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded)
+//by marshmellow
+//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
int CmdFSKdemodParadox(const char *Cmd)
{
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
size_t BitLen = getFromGraphBuf(BitStream);
//get binary from fsk wave
- size_t idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
+ int idx = ParadoxdemodFSK(BitStream,&BitLen,&hi2,&hi,&lo);
if (idx<0){
- if (g_debugMode) PrintAndLog("DEBUG: Error demoding fsk");
+ if (g_debugMode){
+ if (idx==-1){
+ PrintAndLog("DEBUG: Just Noise Detected");
+ } else if (idx == -2) {
+ PrintAndLog("DEBUG: Error demoding fsk");
+ } else if (idx == -3) {
+ PrintAndLog("DEBUG: Preamble not found");
+ } else if (idx == -4) {
+ PrintAndLog("DEBUG: Error in Manchester data");
+ } else {
+ PrintAndLog("DEBUG: Error demoding fsk %d", idx);
+ }
+ }
return 0;
}
if (hi2==0 && hi==0 && lo==0){
//get binary from fsk wave
idx = IOdemodFSK(BitStream,BitLen);
if (idx<0){
- if (g_debugMode==1) PrintAndLog("DEBUG: demoding fsk error: %d", idx);
+ if (g_debugMode){
+ if (idx==-1){
+ PrintAndLog("DEBUG: Just Noise Detected");
+ } else if (idx == -2) {
+ PrintAndLog("DEBUG: not enough samples");
+ } else if (idx == -3) {
+ PrintAndLog("DEBUG: error during fskdemod");
+ } else if (idx == -4) {
+ PrintAndLog("DEBUG: Preamble not found");
+ } else if (idx == -5) {
+ PrintAndLog("DEBUG: Separator bits not found");
+ } else {
+ PrintAndLog("DEBUG: Error demoding fsk %d", idx);
+ }
+ }
return 0;
}
if (idx==0){
size_t size = getFromGraphBuf(BitStream);
//get binary from fsk wave
- int idx = AWIDdemodFSK(BitStream, size);
+ int idx = AWIDdemodFSK(BitStream, &size);
if (idx<=0){
if (g_debugMode==1){
if (idx == -1)
PrintAndLog("DEBUG: Error - not enough samples");
else if (idx == -2)
- PrintAndLog("DEBUG: Error - only noise found - no waves");
+ PrintAndLog("DEBUG: Error - only noise found");
else if (idx == -3)
PrintAndLog("DEBUG: Error - problem during FSK demod");
// else if (idx == -3)
else if (idx == -4)
PrintAndLog("DEBUG: Error - AWID preamble not found");
else if (idx == -5)
- PrintAndLog("DEBUG: Error - Second AWID preamble not found");
+ PrintAndLog("DEBUG: Error - Size not correct: %d", size);
else
PrintAndLog("DEBUG: Error %d",idx);
}
size_t size = getFromGraphBuf(BitStream);
//get binary from fsk wave
- int idx = PyramiddemodFSK(BitStream, size);
+ int idx = PyramiddemodFSK(BitStream, &size);
if (idx < 0){
if (g_debugMode==1){
if (idx == -5)
PrintAndLog("DEBUG: Error - not enough samples");
else if (idx == -1)
- PrintAndLog("DEBUG: Error - only noise found - no waves");
+ PrintAndLog("DEBUG: Error - only noise found");
else if (idx == -2)
PrintAndLog("DEBUG: Error - problem during FSK demod");
else if (idx == -3)
- PrintAndLog("DEBUG: Error - Second Pyramid preamble not found");
+ PrintAndLog("DEBUG: Error - Size not correct: %d", size);
else if (idx == -4)
PrintAndLog("DEBUG: Error - Pyramid preamble not found");
else
PrintAndLog("Pyramid ID Found - BitLength: %d -unknown BitLength- (%d), Raw: %x%08x%08x%08x", fmtLen, cardnum, rawHi3, rawHi2, rawHi, rawLo);
}
}
- //todo - convert hi2, hi, lo to demodbuffer for future sim/clone commands
if (g_debugMode){
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, 128);
printDemodBuff();
PrintAndLog("actual data bits start at sample %d", maxPos);
PrintAndLog("length %d/%d", highLen, lowLen);
- uint8_t bits[46];
- bits[sizeof(bits)-1] = '\0';
+ uint8_t bits[46] = {0x00};
// find bit pairs and manchester decode them
for (i = 0; i < arraylen(bits) - 1; ++i) {
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
size_t size = getFromGraphBuf(BitStream);
-
- uint32_t ans = countFC(BitStream, size);
- int fc1, fc2, rf1;
+ uint16_t ans = countFC(BitStream, size);
+ if (ans==0) {
+ if (g_debugMode) PrintAndLog("DEBUG: No data found");
+ return 0;
+ }
+ uint8_t fc1, fc2;
fc1 = (ans >> 8) & 0xFF;
fc2 = ans & 0xFF;
- rf1 = (ans >>16) & 0xFF;
+
+ uint8_t rf1 = detectFSKClk(BitStream, size, fc1, fc2);
+ if (rf1==0) {
+ if (g_debugMode) PrintAndLog("DEBUG: Clock detect error");
+ return 0;
+ }
PrintAndLog("Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1);
return 1;
}
+//by marshmellow
+//attempt to detect the bit clock for PSK or NRZ modulations
int CmdDetectNRZpskClockRate(const char *Cmd)
{
GetNRZpskClock("",0,0);
return 0;
}
-int PSKnrzDemod(const char *Cmd)
+//by marshmellow
+//attempt to psk1 or nrz demod graph buffer
+//NOTE CURRENTLY RELIES ON PEAKS :(
+int PSKnrzDemod(const char *Cmd, uint8_t verbose)
{
int invert=0;
int clk=0;
if (g_debugMode==1) PrintAndLog("no data found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
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
setDemodBuf(BitStream,BitLen,0);
{
int ans;
if (strlen(Cmd)>0){
- ans = PSKnrzDemod(Cmd);
+ ans = PSKnrzDemod(Cmd, 0);
} else{ //default to RF/32
- ans = PSKnrzDemod("32");
+ ans = PSKnrzDemod("32", 0);
}
if (ans < 0){
PrintAndLog("Error2: %d",ans);
return -1;
}
- char showbits[251];
+ char showbits[251]={0x00};
if (invert)
if (g_debugMode==1)
PrintAndLog("Had to invert bits");
showbits[idx]='\0';
PrintAndLog("Indala UID=%s (%x%08x%08x%08x%08x%08x%08x)", showbits, uid1, uid2, uid3, uid4, uid5, uid6, uid7);
}
+ if (g_debugMode){
+ PrintAndLog("DEBUG: printing demodbuffer:");
+ printDemodBuff();
+ }
return 1;
}
+//by marshmellow
+//attempt to clean psk wave noise after a peak
+//NOTE RELIES ON PEAKS :(
int CmdPskClean(const char *Cmd)
{
uint8_t bitStream[MAX_GRAPH_TRACE_LEN]={0};
return 0;
}
-//by marshmellow
-//takes 2 arguments - clock and invert both as integers
-//attempts to demodulate ask only
-//prints binary found and saves in graphbuffer for further commands
+// by marshmellow
+// takes 2 arguments - clock and invert both as integers
+// attempts to demodulate psk only
+// prints binary found and saves in demodbuffer for further commands
int CmdpskNRZrawDemod(const char *Cmd)
{
int errCnt;
- errCnt = PSKnrzDemod(Cmd);
+ errCnt = PSKnrzDemod(Cmd, 1);
//output
if (errCnt<0){
if (g_debugMode) PrintAndLog("Error demoding: %d",errCnt);
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)
{
sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY);
int CmdSamples(const char *Cmd)
{
- uint8_t got[40000];
+ uint8_t got[40000] = {0x00};
int n = strtol(Cmd, NULL, 0);
if (n == 0)
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
{"pskclean", CmdPskClean, 1, "Attempt to clean psk wave"},
{"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)"},
- {"psknrzrawdemod",CmdpskNRZrawDemod, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk or nrz tags and output binary (args optional)"},
+ {"pskindalademod",CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Attempt to demodulate psk1 indala tags and output ID binary & hex (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"},
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},