X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/2938b3cb12060875655ba9afbd98a69b7eea6d43..1d04b933df776bf60489b67bb5c9b806e308dfc8:/client/cmdlfsecurakey.c diff --git a/client/cmdlfsecurakey.c b/client/cmdlfsecurakey.c index 1d55faf9..44b77060 100644 --- a/client/cmdlfsecurakey.c +++ b/client/cmdlfsecurakey.c @@ -5,13 +5,15 @@ // the license. //----------------------------------------------------------------------------- // Low frequency Securakey tag commands -// ASK/Manchester, RF/40, 96 bits long +// ASK/Manchester, RF/40, 96 bits long (unknown cs) //----------------------------------------------------------------------------- + #include "cmdlfsecurakey.h" + #include #include #include -#include "proxmark3.h" +#include "comms.h" #include "ui.h" #include "util.h" #include "graph.h" @@ -44,7 +46,7 @@ int CmdSecurakeyDemod(const char *Cmd) { //ASK / Manchester bool st = false; if (!ASKDemod_ext("40 0 0", false, false, 1, &st)) { - if (g_debugMode) PrintAndLog("DEBUG: Error - Noralsy: ASK/Manchester Demod failed"); + if (g_debugMode) PrintAndLog("DEBUG: Error - Securakey: ASK/Manchester Demod failed"); return 0; } if (st) return 0; @@ -64,7 +66,7 @@ int CmdSecurakeyDemod(const char *Cmd) { return 0; } setDemodBuf(DemodBuffer, 96, ans); - //setGrid_Clock(40); + setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock)); //got a good demod uint32_t raw1 = bytebits_to_byte(DemodBuffer , 32); @@ -83,33 +85,37 @@ int CmdSecurakeyDemod(const char *Cmd) { // y = card # // standard wiegand parities. // unknown checksum 11 bits? at the end - uint8_t bits_no_spacer[86]; - memcpy(bits_no_spacer, DemodBuffer + 10, 86); + uint8_t bits_no_spacer[85]; + memcpy(bits_no_spacer, DemodBuffer + 11, 85); // remove marker bits (0's every 9th digit after preamble) (pType = 3 (always 0s)) - size = removeParity(bits_no_spacer, 0, 9, 3, 86); - if ( size != 86-10 ) { + size = removeParity(bits_no_spacer, 0, 9, 3, 85); + if ( size != 85-9 ) { if (g_debugMode) PrintAndLog("DEBUG: Error removeParity: %d", size); return 0; } - uint8_t bitLen = (uint8_t)bytebits_to_byte(DemodBuffer+2, 6); + uint8_t bitLen = (uint8_t)bytebits_to_byte(bits_no_spacer+2, 6); uint32_t fc=0, lWiegand=0, rWiegand=0; - // get FC + if (bitLen > 40) { //securakey's max bitlen is 40 bits... + if (g_debugMode) PrintAndLog("DEBUG: Error bitLen too long: %u", bitLen); + return 0; + } // get left 1/2 wiegand & right 1/2 wiegand (for parity test and wiegand print) - lWiegand = bytebits_to_byte(DemodBuffer + 48 - bitLen, bitLen/2); - rWiegand = bytebits_to_byte(DemodBuffer + 48 - bitLen + bitLen/2, bitLen/2); - fc = bytebits_to_byte(DemodBuffer+49-bitLen, bitLen-2-16); + lWiegand = bytebits_to_byte(bits_no_spacer + 48 - bitLen, bitLen/2); + rWiegand = bytebits_to_byte(bits_no_spacer + 48 - bitLen + bitLen/2, bitLen/2); + // get FC + fc = bytebits_to_byte(bits_no_spacer+49-bitLen, bitLen-2-16); // test bitLen if (bitLen != 26 && bitLen != 32) PrintAndLog("***unknown securakey bitLen - share with forum***"); - uint32_t cardid = bytebits_to_byte(DemodBuffer+8+23, 16); - // test parities - bool parity = evenparity32(lWiegand) && oddparity32(rWiegand); + uint32_t cardid = bytebits_to_byte(bits_no_spacer+8+23, 16); + // test parities - evenparity32 looks to add an even parity returns 0 if already even... + bool parity = !evenparity32(lWiegand) && !oddparity32(rWiegand); - PrintAndLog("Securakey Tag Found--BitLen: %u, Card ID: %u, FC: %X, Raw: %08X%08X%08X", bitLen, cardid, fc, raw1 ,raw2, raw3); + PrintAndLog("Securakey Tag Found--BitLen: %u, Card ID: %u, FC: 0x%X, Raw: %08X%08X%08X", bitLen, cardid, fc, raw1 ,raw2, raw3); if (bitLen <= 32) PrintAndLog("Wiegand: %08X, Parity: %s", (lWiegand<<(bitLen/2)) | rWiegand, parity ? "Passed" : "Failed"); PrintAndLog("\nHow the FC translates to printed FC is unknown"); @@ -119,8 +125,7 @@ int CmdSecurakeyDemod(const char *Cmd) { } int CmdSecurakeyRead(const char *Cmd) { - CmdLFRead("s"); - getSamples("8000",true); + lf_read(true, 8000); return CmdSecurakeyDemod(Cmd); }