+bool detectFSK(){
+ // detect fsk clock
+ if (!GetFskClock("", FALSE, FALSE)) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: FSK clock failed");
+ return FALSE;
+ }
+ // demod
+ int ans = FSKrawDemod("0 0", FALSE);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: FSK Demod failed");
+ return FALSE;
+ }
+ return TRUE;
+}
+// PSK clocks should be easy to detect ( but difficult to demod a non-repeating pattern... )
+bool detectPSK(){
+ int ans = GetPskClock("", FALSE, FALSE);
+ if (ans <= 0) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: PSK clock failed");
+ return FALSE;
+ }
+ //demod
+ //try psk1 -- 0 0 6 (six errors?!?)
+ ans = PSKDemod("0 0 6", FALSE);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: PSK1 Demod failed");
+
+ //try psk1 inverted
+ ans = PSKDemod("0 1 6", FALSE);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: PSK1 inverted Demod failed");
+ return FALSE;
+ }
+ }
+ // either PSK1 or PSK1 inverted is ok from here.
+ // lets check PSK2 later.
+ return TRUE;
+}
+// try manchester - NOTE: ST only applies to T55x7 tags.
+bool detectASK_MAN(){
+ bool stcheck = FALSE;
+ int ans = ASKDemod_ext("0 0 0", FALSE, FALSE, 1, &stcheck);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: ASK/Manchester Demod failed");
+ return FALSE;
+ }
+ return TRUE;
+}
+bool detectASK_BI(){
+ int ans = ASKbiphaseDemod("0 0 1", FALSE);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: ASK/biphase normal demod failed");
+
+ ans = ASKbiphaseDemod("0 1 1", FALSE);
+ if (!ans) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error - EM: ASK/biphase inverted demod failed");
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+// param: idx - start index in demoded data.
+bool setDemodBufferEM(uint32_t *word, size_t idx){
+
+ //test for even parity bits.
+ size_t size = removeParity(DemodBuffer, idx + EM_PREAMBLE_LEN, 9, 0, 44);
+ if (!size) {
+ if (g_debugMode) PrintAndLog("DEBUG: Error -EM Parity not detected");
+ return FALSE;
+ }
+
+ //todo test last 8 bits for even parity || (xor)
+ setDemodBuf(DemodBuffer, 40, 0);
+
+ *word = bytebits_to_byteLSBF(DemodBuffer, 32);
+
+ uint8_t lo = (uint8_t) bytebits_to_byteLSBF(DemodBuffer , 8);
+ uint8_t lo2 = (uint8_t) bytebits_to_byteLSBF(DemodBuffer + 8, 8);
+ uint8_t hi = (uint8_t) bytebits_to_byteLSBF(DemodBuffer + 16, 8);
+ uint8_t hi2 = (uint8_t) bytebits_to_byteLSBF(DemodBuffer + 24, 8);
+ uint8_t cs = (uint8_t) bytebits_to_byteLSBF(DemodBuffer + 32, 8);
+ uint8_t cs2 = lo ^ lo2 ^ hi ^ hi2;
+ if (g_debugMode) PrintAndLog("EM4x05/4x69 : %08X CS: %02X %s"
+ , *word
+ , cs
+ , (cs2==cs) ? "Passed" : "Failed"
+ );
+
+ return (cs2==cs);
+}
+
+// FSK, PSK, ASK/MANCHESTER, ASK/BIPHASE, ASK/DIPHASE
+// should cover 90% of known used configs
+// the rest will need to be manually demoded for now...
+bool demodEM4x05resp(uint32_t *word) {
+ size_t idx = 0;