+// detect configuration?\r
+bool tryDetectModulation(){\r
+ \r
+ uint8_t hits = 0;\r
+ t55xx_conf_block_t tests[11];\r
+ \r
+ if (GetFskClock("", FALSE, FALSE)){ \r
+ if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_FSK;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_FSK;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ } else {\r
+ if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_ASK;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+\r
+ if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_ASK;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_NRZ;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+\r
+ if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_NRZ;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_PSK1;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ \r
+ if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {\r
+ tests[hits].modulation = DEMOD_PSK1;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+\r
+ //PSK2\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].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ }\r
+ if ( PSKDemod("0 1 1", FALSE)) {\r
+ psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
+ if (test(DEMOD_PSK2, &tests[hits].offset)){\r
+ tests[hits].modulation = DEMOD_PSK2;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ }\r
+\r
+ /* DEPENDANT ON NEW CODE IN MARSHMELLOWS pull request\r
+ //biphase //offset, clock, invert, maxErr\r
+ if ( ASKbiphaseDemod("0 0 0 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BI;\r
+ tests[hits].inversed = FALSE;\r
+ ++hits;\r
+ }\r
+ if ( ASKbiphaseDemod("0 0 1 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {\r
+ tests[hits].modulation = DEMOD_BI;\r
+ tests[hits].inversed = TRUE;\r
+ ++hits;\r
+ }\r
+ */\r
+ } \r
+ if ( hits == 1) {\r
+ config.modulation = tests[0].modulation;\r
+ config.inversed = tests[0].inversed;\r
+ config.offset = tests[0].offset;\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 == 8) return TRUE;\r
+ break;\r
+ case DEMOD_PSK1:\r
+ if (modread == 1) return TRUE;\r
+ break;\r
+ case DEMOD_PSK2:\r
+ if (modread == 2) return TRUE;\r
+ break;\r
+ case DEMOD_PSK3:\r
+ if (modread == 3) return TRUE;\r
+ break;\r
+ case DEMOD_NRZ:\r
+ if (!modread) return TRUE;\r
+ break;\r
+ case DEMOD_BI:\r
+ if (modread == 16) return TRUE;\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) \r
+ return FALSE;\r
+ if ( PackBits(0, 32, DemodBuffer) == 0x00 )\r
+ return FALSE;\r
+ for (uint8_t idx=1; idx<33; idx++){\r
+ uint8_t si = idx;\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
+ uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3+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
+ \r
+ bool extMode = FALSE;\r
+\r
+ //PrintAndLog("test: %X %X %X ", safer, resv, extend);\r
+ \r
+ // 2nibble must be zeroed.\r
+ if ( resv > 0x00) continue;\r
+\r
+ //if extended mode\r
+ if ( (safer == 0x6 || safer == 0x9) && extend) extMode = TRUE;\r