+ if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_PSK1;\r
+ tests[hits].inverted = TRUE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+\r
+ // PSK2 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 0 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK2, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK2;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ } // inverse waves does not affect this demod\r
+\r
+ // PSK3 - needs a call to psk1TOpsk2.\r
+ if ( PSKDemod("0 0 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK3, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK3;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ } // inverse waves does not affect this demod\r
+ \r
+ if ( ASKbiphaseDemod("0 0 0 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BI;\r
+ tests[hits].inverted = FALSE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ if ( ASKbiphaseDemod("0 0 1 1", FALSE) && test(DEMOD_BIa, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BIa;\r
+ tests[hits].inverted = TRUE;\r
+ tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
+ ++hits;\r
+ }\r
+ } \r
+ if ( hits == 1) {\r
+ config.modulation = tests[0].modulation;\r
+ config.inverted = tests[0].inverted;\r
+ config.offset = tests[0].offset;\r
+ config.block0 = tests[0].block0;\r
+ printConfiguration( config );\r
+ return TRUE;\r
+ }\r
+ \r
+ if ( hits > 1) {\r
+ PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
+ for(int i=0; i<hits; ++i){\r
+ PrintAndLog("--[%d]---------------", i+1);\r
+ printConfiguration( tests[i] );\r
+ }\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool testModulation(uint8_t mode, uint8_t modread){\r
+ switch( mode ){\r
+ case DEMOD_FSK:\r
+ if (modread > 3 && modread < 8) return TRUE;\r
+ break;\r
+ case DEMOD_ASK:\r
+ if (modread == DEMOD_ASK) return TRUE;\r
+ break;\r
+ case DEMOD_PSK1:\r
+ if (modread == DEMOD_PSK1) return TRUE;\r
+ break;\r
+ case DEMOD_PSK2:\r
+ if (modread == DEMOD_PSK2) return TRUE;\r
+ break;\r
+ case DEMOD_PSK3:\r
+ if (modread == DEMOD_PSK3) return TRUE;\r
+ break;\r
+ case DEMOD_NRZ:\r
+ if (modread == DEMOD_NRZ) return TRUE;\r
+ break;\r
+ case DEMOD_BI:\r
+ if (modread == DEMOD_BI) return TRUE;\r
+ break;\r
+ case DEMOD_BIa:\r
+ if (modread == DEMOD_BIa) return TRUE;\r
+ break; \r
+ default:\r
+ return FALSE;\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool testBitRate(uint8_t readRate, uint8_t mod){\r
+ uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};\r
+ uint8_t detRate = 0;\r
+ switch( mod ){\r
+ case DEMOD_FSK:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_FSK1:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_FSK1a:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_FSK2:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_FSK2a:\r
+ detRate = GetFskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_ASK:\r
+ detRate = GetAskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_PSK1:\r
+ detRate = GetPskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_PSK2:\r
+ detRate = GetPskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_PSK3:\r
+ detRate = GetPskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_NRZ:\r
+ detRate = GetNrzClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ case DEMOD_BI:\r
+ case DEMOD_BIa:\r
+ detRate = GetAskClock("",FALSE, FALSE); \r
+ if (expected[readRate] == detRate) {\r
+ config.bitrate = readRate;\r
+ return TRUE;\r
+ }\r
+ break;\r
+ default:\r
+ return FALSE;\r
+ }\r
+ return FALSE;\r
+}\r
+\r
+bool test(uint8_t mode, uint8_t *offset){\r
+\r
+ if ( !DemodBufferLen) return FALSE;\r
+ uint8_t si = 0;\r
+ for (uint8_t idx = 0; idx < 64; idx++){\r
+ si = idx;\r
+ if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue; // configuration block with only zeros is impossible.\r
+\r
+ uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
+ uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
+ // 2nibble must be zeroed.\r
+ // moved test to here, since this gets most faults first.\r
+ if ( resv > 0x00) continue;\r
+\r
+ uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //new\r
+ uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //new could check bit rate\r
+ uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r
+ uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; //new\r
+ //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //new could check psk cr\r
+ uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24 , 30, 31 could be tested for 0 if not extended mode\r
+ uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r