X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/6c283951062aaad9d0d1ba8670b02895047be438..f5538c1c4ec3fc35e52cc7436029322cc3bb8639:/client/cmdlfjablotron.c?ds=sidebyside diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index a97bb770..3c5edd39 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -12,29 +12,38 @@ static int CmdHelp(const char *Cmd); int usage_lf_jablotron_clone(void){ PrintAndLog("clone a Jablotron tag to a T55x7 tag."); - PrintAndLog("Usage: lf jablotron clone d "); - PrintAndLog("Options :"); - PrintAndLog(" d : jablotron card ID"); - PrintAndLog(" : specify write to Q5 (t5555 instead of t55x7)"); + PrintAndLog("Usage: lf jablotron clone [h] "); + PrintAndLog("Options:"); + PrintAndLog(" h : This help"); + PrintAndLog(" : jablotron card ID"); + PrintAndLog(" : specify write to Q5 (t5555 instead of t55x7)"); PrintAndLog(""); - PrintAndLog("Sample : lf jablotron clone d 123456789"); + PrintAndLog("Sample: lf jablotron clone d 112233"); return 0; } int usage_lf_jablotron_sim(void) { PrintAndLog("Enables simulation of jablotron card with specified card number."); PrintAndLog("Simulation runs until the button is pressed or another USB command is issued."); - PrintAndLog("Per jablotron format, the card number is 9 digit number and can contain *# chars. Larger values are truncated."); PrintAndLog(""); - PrintAndLog("Usage: lf jablotron sim d or H "); - PrintAndLog("Options :"); - PrintAndLog(" d : jablotron card number"); -// PrintAndLog(" H : 8 digit hex card number"); + PrintAndLog("Usage: lf jablotron sim [h] "); + PrintAndLog("Options:"); + PrintAndLog(" h : This help"); + PrintAndLog(" : jablotron card ID"); PrintAndLog(""); - PrintAndLog("Sample : lf jablotron sim d 123456789"); + PrintAndLog("Sample: lf jablotron sim d 112233"); return 0; } +static uint8_t jablontron_chksum(uint8_t *bits){ + uint8_t chksum = 0; + for (int i=16; i < 56; i += 8) { + chksum += bytebits_to_byte(bits+i,8); + } + chksum ^= 0x3A; + return chksum; +} + int getJablotronBits(uint64_t fullcode, uint8_t *bits) { //preamp num_to_bytebits(0xFFFF, 16, bits); @@ -43,13 +52,8 @@ int getJablotronBits(uint64_t fullcode, uint8_t *bits) { num_to_bytebits(fullcode, 40, bits+16); //chksum byte - uint8_t crc = 0; - for (int i=16; i < 56; i += 8) { - crc += bytebits_to_byte(bits+i,8); - } - crc ^= 0x3A; - num_to_bytebits(crc, 8, bits+56); - + uint8_t chksum = jablontron_chksum(bits); + num_to_bytebits(chksum, 8, bits+56); return 1; } @@ -68,41 +72,52 @@ int CmdJablotronDemod(const char *Cmd) { if (g_debugMode){ // if (ans == -5) // PrintAndLog("DEBUG: Error - not enough samples"); - // else if (ans == -1) - // PrintAndLog("DEBUG: Error - only noise found"); + if (ans == -1) + PrintAndLog("DEBUG: Error - Jablotron too few bits found"); // else if (ans == -2) // PrintAndLog("DEBUG: Error - problem during ASK/Biphase demod"); - if (ans == -3) - PrintAndLog("DEBUG: Error - Size not correct: %d", size); + else if (ans == -3) + PrintAndLog("DEBUG: Error - Jablotron Size not correct: %d", size); else if (ans == -4) PrintAndLog("DEBUG: Error - Jablotron preamble not found"); + else if (ans == -5) + PrintAndLog("DEBUG: Error - Jablotron checksum failed"); else PrintAndLog("DEBUG: Error - ans: %d", ans); } return 0; } + + setDemodBuf(DemodBuffer+ans, 64, 0); + //got a good demod - uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32); - uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32); - uint64_t cardid = (raw1 & 0x0000FFFF); - cardid <<= 32; + uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); + uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32); + uint64_t cardid = (raw1 & 0xFFFF); + cardid <<= 24; cardid |= (raw2 >> 8); - PrintAndLog("Jablotron Tag Found: Card ID %12X", cardid); + PrintAndLog("Jablotron Tag Found: Card ID %"PRIx64, cardid); PrintAndLog("Raw: %08X%08X", raw1 ,raw2); - setDemodBuf(DemodBuffer+ans, 64, 0); - - //PrintAndLog("1410-%u-%u-%08X-%02X", fullcode); + uint8_t chksum = raw2 & 0xFF; + PrintAndLog("Checksum: %02X [%s]", + chksum, + (chksum == jablontron_chksum(DemodBuffer)) ? "OK":"FAIL" + ); + + // Printed format: 1410-nn-nnnn-nnnn + PrintAndLog("Printed: 1410-%02X-%04X-%04X", + (raw1 & 0x0000FF00) >> 8, + (raw1 & 0xFF) << 8 | ((raw2 >> 24) & 0xFF), + (raw2 & 0x00FFFF00) >> 8 + ); return 1; } int CmdJablotronRead(const char *Cmd) { - // read lf silently CmdLFRead("s"); - // get samples silently getSamples("30000",false); - // demod and output Presco ID return CmdJablotronDemod(Cmd); } @@ -118,19 +133,20 @@ int CmdJablotronClone(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_clone(); - fullcode = param_get64ex(Cmd, 1, 0, 16); + fullcode = param_get64ex(Cmd, 0, 0, 16); //Q5 - if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') { + if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') { //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 64< [Q5] clone jablotron tag"}, - {"sim", CmdJablotronSim, 0, "h simulate jablotron tag"}, + {"read", CmdJablotronRead, 0, "Attempt to read and extract tag data"}, + {"clone", CmdJablotronClone, 0, "clone jablotron tag"}, + {"sim", CmdJablotronSim, 0, "simulate jablotron tag"}, {NULL, NULL, 0, NULL} };