From: iceman1001 Date: Mon, 13 Feb 2017 09:58:28 +0000 (+0100) Subject: FIX: T5555/Q5 datarate when used in "Q" parameter, consequential fix in lf commands... X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/ff9c043da29150aa785723326537ba93ddac0614?ds=sidebyside;hp=b1d615df78a3c258f2568a07fcc4d0d9ca4ab921 FIX: T5555/Q5 datarate when used in "Q" parameter, consequential fix in lf commands. (RF-2/2) ie: ((64-2)>>1) ADD: Marshmellow42 's timing fixes for em4305. --- diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 28b8b5df..c8eed468 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -710,7 +710,7 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) for (i=0; i>1)<>1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT; LED_D_ON(); // Program the data blocks for supplied ID @@ -1414,7 +1414,7 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) { // and the Config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2) uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo}; //TODO add selection of chip for Q5 or T55x7 - // data[0] = (((32-2)/2)<>1)<>1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_PSK1 | 7 << T5555_MAXBLOCK_SHIFT; WriteT55xx(data, 0, 8); //Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=7;Inverse data) // T5567WriteBlock(0x603E10E2,0); @@ -1437,7 +1437,7 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) { uint32_t data[] = {T55x7_BITRATE_RF_32 | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT), block1, block2}; //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) - if (Q5) data[0] = (32 << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT; + if (Q5) data[0] = (((32-2)>>1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT; // Program the data blocks for supplied ID and the block 0 config WriteT55xx(data, 0, 3); LED_D_OFF(); @@ -1521,8 +1521,8 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) { } data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT); } else { //t5555 (Q5) - clock = (clock-2)>>1; //n = (RF-2)/2 - data[0] = (clock << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT); + // t5555 (Q5) BITRATE = (RF-2)/2 (iceman) + data[0] = ( ((clock-2) >> 1) << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT); } WriteT55xx(data, 0, 3); @@ -1648,7 +1648,7 @@ void SendForward(uint8_t fwd_bit_count) { // 16FC * 8us == 128us / 21.3 == 6.009 steps. ok #ifndef EM_START_GAP -#define EM_START_GAP 56*8 +#define EM_START_GAP 60*8 #endif #ifndef EM_ONE_GAP #define EM_ONE_GAP 32*8 @@ -1669,8 +1669,7 @@ void SendForward(uint8_t fwd_bit_count) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(EM_START_GAP); - - TurnReadLFOn(EM_ZERO_GAP); + TurnReadLFOn(16); // now start writting with bitbanging the antenna. while(fwd_bit_sz-- > 0) { //prepare next bit modulation @@ -1679,8 +1678,8 @@ void SendForward(uint8_t fwd_bit_count) { else { //These timings work for 4469/4269/4305 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - WaitUS(EM_ZERO_GAP); - TurnReadLFOn(EM_ZERO_GAP); + WaitUS(20); + TurnReadLFOn(12); } } } @@ -1691,7 +1690,10 @@ void EM4xLogin(uint32_t pwd) { len = Prepare_Cmd( FWD_CMD_LOGIN ); len += Prepare_Data( pwd & 0xFFFF, pwd >> 16 ); SendForward(len); - WaitMS(20); + //WaitMS(20); - no wait for login command. + // should receive + // 0000 1010 ok. + // 0000 0001 fail } void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) { @@ -1703,6 +1705,12 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) { //clear buffer now so it does not interfere with timing later BigBuf_Clear_ext(false); + /* should we read answer from Logincommand? + * + * should receive + * 0000 1010 ok. + * 0000 0001 fail + **/ if (usepwd) EM4xLogin(pwd); forward_ptr = forwardLink_data; @@ -1728,7 +1736,13 @@ void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) { //clear buffer now so it does not interfere with timing later BigBuf_Clear_ext(false); - + + /* should we read answer from Logincommand? + * + * should receive + * 0000 1010 ok. + * 0000 0001 fail + **/ if (usePwd) EM4xLogin(pwd); forward_ptr = forwardLink_data; diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index db2614aa..9883437a 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -281,9 +281,9 @@ int CmdAWIDClone(const char *Cmd) { if ( !fc || !cn) return usage_lf_awid_clone(); - if (param_getchar(Cmd, 4) == 'Q' || param_getchar(Cmd, 4) == 'q') + if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q') //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) - blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<>1) << T5555_BITRATE_SHIFT | 3< <'0' T5555> <'1' T55x7> [clock rate] -- Write EM410x UID to T5555(Q5) or T55x7 tag, optionally setting clock rate"}, - {"em4x50read", CmdEM4x50Read, 1, "Extract data from EM4x50 tag"}, - {"readword", CmdReadWord, 1, "Read EM4xxx data"}, - {"writeword", CmdWriteWord, 1, "Write EM4xxx data"}, + {"em4x50read", CmdEM4x50Read, 1, "demod data from EM4x50 tag from the graphbuffer"}, + {"readword", CmdReadWord, 1, "read EM4x05/4x69 data"}, + {"writeword", CmdWriteWord, 1, "write EM405/4x69 data"}, {NULL, NULL, 0, NULL} }; diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 0e6b43f4..292ebad6 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -202,7 +202,7 @@ int CmdFdxClone(const char *Cmd) { uint32_t countryid = 0; uint64_t animalid = 0; - uint32_t blocks[5] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4<>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT; } verify_values(countryid, animalid); diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index d9010a19..ddfd2963 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -15,8 +15,9 @@ int usage_lf_guard_clone(void){ PrintAndLog("The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. "); PrintAndLog("Currently work only on 26bit"); PrintAndLog(""); - PrintAndLog("Usage: lf guard clone "); + PrintAndLog("Usage: lf guard clone "); PrintAndLog("Options :"); + PrintAndLog(" : format length 26|32|36|40"); PrintAndLog(" : 8-bit value facility code"); PrintAndLog(" : 16-bit value card number"); PrintAndLog(""); @@ -30,8 +31,9 @@ int usage_lf_guard_sim(void) { PrintAndLog("The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated."); PrintAndLog("Currently work only on 26bit"); PrintAndLog(""); - PrintAndLog("Usage: lf guard sim "); + PrintAndLog("Usage: lf guard sim "); PrintAndLog("Options :"); + PrintAndLog(" : format length 26|32|36|40"); PrintAndLog(" : 8-bit value facility code"); PrintAndLog(" : 16-bit value card number"); PrintAndLog(""); @@ -40,44 +42,61 @@ int usage_lf_guard_sim(void) { } // Works for 26bits. -int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) { +int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) { - // Intializes random number generator - time_t t; - srand((unsigned) time(&t)); - //uint8_t xorKey = rand() % 0xFF; uint8_t xorKey = 0x66; uint8_t i; uint8_t pre[96]; + uint8_t rawbytes[12]; memset(pre, 0x00, sizeof(pre)); + memset(rawbytes, 0x00, sizeof(rawbytes)); - // Get 26 wiegand from FacilityCode, CardNumber - uint8_t wiegand[24]; - memset(wiegand, 0x00, sizeof(wiegand)); - num_to_bytebits(fc, 8, wiegand); - num_to_bytebits(cn, 16, wiegand+8); - - // add wiegand parity bits (dest, source, len) - wiegand_add_parity(pre, wiegand, 24); - - // lets start. 12bytes of data to be produced. - uint8_t rawbytes[12]; - memset(rawbytes, 0x00, sizeof(rawbytes)); + // add format length (decimal) + switch (fmtlen) { + case 32: { + rawbytes[1] = (32 << 2); + + break; + } + case 36: { + // FC = ((ByteStream[3] & 0x7F)<<7) | (ByteStream[4]>>1); + // Card = ((ByteStream[4]&1)<<19) | (ByteStream[5]<<11) | (ByteStream[6]<<3) | (ByteStream[7]>>5); + rawbytes[1] = (36 << 2); + // Get 26 wiegand from FacilityCode, CardNumber + uint8_t wiegand[34]; + memset(wiegand, 0x00, sizeof(wiegand)); + num_to_bytebits(fc, 8, wiegand); + num_to_bytebits(cn, 26, wiegand+8); + + // add wiegand parity bits (dest, source, len) + wiegand_add_parity(pre, wiegand, 34); + break; + } + case 40: { + rawbytes[1] = (40 << 2); + break; + } + case 26: + default: { + rawbytes[1] = (26 << 2); + // Get 26 wiegand from FacilityCode, CardNumber + uint8_t wiegand[24]; + memset(wiegand, 0x00, sizeof(wiegand)); + num_to_bytebits(fc, 8, wiegand); + num_to_bytebits(cn, 16, wiegand+8); + + // add wiegand parity bits (dest, source, len) + wiegand_add_parity(pre, wiegand, 24); + break; + } + } + // 2bit checksum, unknown today, + // these two bits are the last ones of rawbyte[1], hence the LSHIFT above. + // xor key rawbytes[0] = xorKey; - - // add format length (decimal) - // len | hex | bin - // 26 | 1A | 0001 1010 - rawbytes[1] = (26 << 2); - // 36 | 24 | 0010 0100 - //rawbytes[1] = (36 << 2); - // 40 | 28 | 0010 1000 - //rawbytes[1] = (40 << 2); - // 2bit checksum, unknown today, - // these two bits are the last ones of rawbyte[1], hence the LSHIFT above. rawbytes[2] = 1; rawbytes[3] = 0; @@ -87,6 +106,7 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) { if (g_debugMode) printf(" WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes))); + // XOR (only works on wiegand stuff) for (i = 1; i < 12; ++i) rawbytes[i] ^= xorKey ; @@ -127,24 +147,25 @@ int CmdGuardClone(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_clone(); - uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0; + uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0; uint8_t i; uint8_t bs[96]; memset(bs, 0x00, sizeof(bs)); //GuardProxII - compat mode, ASK/Biphase, data rate 64, 3 data blocks - uint32_t blocks[5] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3<>1) << T5555_BITRATE_SHIFT | 3 << T5555_MAXBLOCK_SHIFT; - if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_clone(); + if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 2) return usage_lf_guard_clone(); + fmtlen &= 0x7f; facilitycode = (fc & 0x000000FF); cardnumber = (cn & 0x0000FFFF); - if ( !GetGuardBits(facilitycode, cardnumber, bs)) { + if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) { PrintAndLog("Error with tag bitstream generation."); return 1; } @@ -180,18 +201,19 @@ int CmdGuardSim(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim(); - uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0; + uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0; uint8_t clock = 64, encoding = 2, separator = 0, invert = 0; uint8_t bs[96]; memset(bs, 0x00, sizeof(bs)); - if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_sim(); + if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 2) return usage_lf_guard_sim(); + fmtlen &= 0x7F; facilitycode = (fc & 0x000000FF); cardnumber = (cn & 0x0000FFFF); - if ( !GetGuardBits(facilitycode, cardnumber, bs)) { + if ( !GetGuardBits(fmtlen, facilitycode, cardnumber, bs)) { PrintAndLog("Error with tag bitstream generation."); return 1; } diff --git a/client/cmdlfio.c b/client/cmdlfio.c index 20530d17..0424ed17 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -185,7 +185,7 @@ int CmdIOSim(const char *Cmd) { int CmdIOClone(const char *Cmd) { - uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2<>1) << T5555_BITRATE_SHIFT | 2 << T5555_MAXBLOCK_SHIFT; if ( !getIOProxBits(version, fc, cn, bs)) { PrintAndLog("Error with tag bitstream generation."); diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index f1da737d..dc5e10d7 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -132,7 +132,7 @@ int CmdJablotronRead(const char *Cmd) { int CmdJablotronClone(const char *Cmd) { uint64_t fullcode = 0; - uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2<>1) << T5555_BITRATE_SHIFT | 2 << T5555_MAXBLOCK_SHIFT; } // clearing the topbit needed for the preambl detection. diff --git a/client/cmdlfnedap.c b/client/cmdlfnedap.c index eeb07939..8f5832ad 100644 --- a/client/cmdlfnedap.c +++ b/client/cmdlfnedap.c @@ -229,11 +229,11 @@ int CmdLFNedapClone(const char *Cmd) { ((ASK/DIphase data rawdemod ab 0 64 1 0 //NEDAP - compat mode, ASK/DIphase, data rate 64, 4 data blocks // DI-pahse (CDP) T55x7_MODULATION_DIPHASE - blocks[0] = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 7<>1) << T5555_BITRATE_SHIFT | 7 <>1) << T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT; } if ( !getnoralsyBits(id, year, bs)) { diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index accd6f22..84b6f4a2 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -173,14 +173,14 @@ int CmdPrescoClone(const char *Cmd) { bool Q5 = false; uint32_t sitecode=0, usercode=0, fullcode=0; - uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4<>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR; if ((sitecode & 0xFF) != sitecode) { sitecode &= 0xFF; diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index b6c8ed6a..33fd10c6 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -100,11 +100,11 @@ int CmdPyramidClone(const char *Cmd) { } //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks - blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<>1) << T5555_BITRATE_SHIFT | 4 << T5555_MAXBLOCK_SHIFT; blocks[1] = bytebits_to_byte(bs,32); blocks[2] = bytebits_to_byte(bs+32,32); diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index 42e1a00f..c0837108 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -45,6 +45,17 @@ static uint8_t visa_chksum( uint32_t id ) { return sum & 0xF; } +/** +* +* 56495332 00096ebd 00000077 —> tag id 618173 +* aaaaaaaa iiiiiiii -----..c +* +* a = fixed value ascii 'VIS2' +* i = card id +* c = checksum (xor of card id) +* . = unknown +* +**/ //see ASKDemod for what args are accepted int CmdVisa2kDemod(const char *Cmd) { @@ -82,7 +93,7 @@ int CmdVisa2kDemod(const char *Cmd) { uint32_t raw1 = bytebits_to_byte(DemodBuffer, 32); uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32); uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32); - + // chksum uint8_t calc = visa_chksum(raw2); uint8_t chk = raw3 & 0xF; @@ -106,7 +117,7 @@ int CmdVisa2kRead(const char *Cmd) { int CmdVisa2kClone(const char *Cmd) { uint64_t id = 0; - uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR |3<>1) << T5555_BITRATE_SHIFT | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT; } //