diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 5aff24288..397a49769 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -165,6 +165,9 @@ int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) { size_t bitLen = addParity(pre, bits+8, 66, 4, 1); if (bitLen != 88) return 0; + + printf("awid raw bits:\n %s \n", sprint_bin(bits, bitLen)); + return 1; } @@ -260,6 +263,10 @@ int CmdAWIDDemod(const char *Cmd) { return 0; } + setDemodBuf(bits, size, idx); + setClockGrid(50, waveIdx + (idx*50)); + + // Index map // 0 10 20 30 40 50 60 // | | | | | | | @@ -277,9 +284,7 @@ int CmdAWIDDemod(const char *Cmd) { uint32_t rawLo = bytebits_to_byte(bits + idx + 64, 32); uint32_t rawHi = bytebits_to_byte(bits + idx + 32, 32); uint32_t rawHi2 = bytebits_to_byte(bits + idx, 32); - setDemodBuf(bits, 96, idx); - setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock)); - + size = removeParity(bits, idx+8, 4, 1, 88); if (size != 66){ if (g_debugMode) PrintAndLog("DEBUG: Error - AWID at parity check-tag size does not match AWID format"); @@ -389,7 +394,6 @@ int CmdAWIDSim(const char *Cmd) { uint64_t arg1 = (high << 8) + low; uint64_t arg2 = (invert << 8) + clk; - // AWID uses: FSK2a fcHigh: 10, fcLow: 8, clk: 50, invert: 1 // arg1 --- fcHigh<<8 + fcLow // arg2 --- Inversion and clk setting @@ -429,17 +433,12 @@ int CmdAWIDClone(const char *Cmd) { return 1; } - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); - blocks[3] = bytebits_to_byte(bs+64,32); + blocks[1] = bytebits_to_byte(bs, 32); + blocks[2] = bytebits_to_byte(bs + 32, 32); + blocks[3] = bytebits_to_byte(bs + 64, 32); PrintAndLog("Preparing to clone AWID %u to T55x7 with FC: %u, CN: %u", fmtlen, fc, cn); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - PrintAndLog(" 00 | 0x%08x", blocks[0]); - PrintAndLog(" 01 | 0x%08x", blocks[1]); - PrintAndLog(" 02 | 0x%08x", blocks[2]); - PrintAndLog(" 03 | 0x%08x", blocks[3]); + print_blocks(blocks, 4); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 025e9329b..c6c3d64da 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -322,10 +322,6 @@ int CmdFdxClone(const char *Cmd) { countryid = param_get32ex(Cmd, 0, 0, 10); animalid = param_get64ex(Cmd, 1, 0, 10); - //Q5 - if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') - blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT; - verify_values(countryid, animalid); // getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits) @@ -333,21 +329,19 @@ int CmdFdxClone(const char *Cmd) { PrintAndLog("Error with tag bitstream generation."); return 1; } - + + //Q5 + if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') + blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT; + // convert from bit stream to block data - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); - blocks[3] = bytebits_to_byte(bs+64,32); - blocks[4] = bytebits_to_byte(bs+96,32); + blocks[1] = bytebits_to_byte(bs, 32); + blocks[2] = bytebits_to_byte(bs + 32, 32); + blocks[3] = bytebits_to_byte(bs + 64, 32); + blocks[4] = bytebits_to_byte(bs + 96, 32); PrintAndLog("Preparing to clone FDX-B to T55x7 with animal ID: %04u-%"PRIu64, countryid, animalid); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - PrintAndLog(" 00 | 0x%08x", blocks[0]); - PrintAndLog(" 01 | 0x%08x", blocks[1]); - PrintAndLog(" 02 | 0x%08x", blocks[2]); - PrintAndLog(" 03 | 0x%08x", blocks[3]); - PrintAndLog(" 04 | 0x%08x", blocks[4]); + print_blocks(blocks, 5); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index 691fbcf24..2b60d55fe 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -269,11 +269,8 @@ int CmdGuardClone(const char *Cmd) { 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 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0}; + uint32_t blocks[4] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; - if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q') - blocks[0] = T5555_MODULATION_FSK2 | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT; - if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn ) != 3) return usage_lf_guard_clone(); fmtlen &= 0x7f; @@ -285,15 +282,16 @@ int CmdGuardClone(const char *Cmd) { return 1; } - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); - blocks[3] = bytebits_to_byte(bs+64,32); + // Q5 + if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q') + blocks[0] = T5555_MODULATION_FSK2 | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT; + + blocks[1] = bytebits_to_byte(bs, 32); + blocks[2] = bytebits_to_byte(bs + 32, 32); + blocks[3] = bytebits_to_byte(bs + 64, 32); PrintAndLog("Preparing to clone Guardall to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - for ( i = 0; i<4; ++i ) - PrintAndLog(" %02d | 0x%08x", i, blocks[i]); + print_blocks(blocks, 4); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index d2e39823c..c0f61beb9 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -53,7 +53,7 @@ int usage_lf_hid_sim(void){ PrintAndLog(" h - This help"); PrintAndLog(" ID - HID id"); PrintAndLog("Samples:"); - PrintAndLog(" lf hid sim 224"); + PrintAndLog(" lf hid sim 2006ec0c86"); return 0; } int usage_lf_hid_clone(void){ @@ -156,8 +156,7 @@ int CmdHIDDemod(const char *Cmd) { if (hi2 != 0){ //extra large HID tags PrintAndLog("HID Prox TAG ID: %x%08x%08x (%u)", hi2, hi, lo, (lo>>1) & 0xFFFF); - } - else { //standard HID tags <38 bits + } else { //standard HID tags <38 bits uint8_t fmtLen = 0; uint32_t fc = 0; uint32_t cardnum = 0; @@ -196,7 +195,7 @@ int CmdHIDDemod(const char *Cmd) { } PrintAndLog("HID Prox TAG ID: %x%08x (%u) - Format Len: %ubit - FC: %u - Card: %u", hi, lo, (lo>>1) & 0xFFFF, fmtLen, fc, cardnum); } - setDemodBuf(BitStream,BitLen,idx); + setDemodBuf(BitStream, BitLen, idx); setClockGrid(50, waveIdx + (idx*50)); if (g_debugMode){ diff --git a/client/cmdlfio.c b/client/cmdlfio.c index a4943e84c..987a5e17c 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -91,13 +91,13 @@ int CmdIOProxDemod(const char *Cmd) { if (g_debugMode)PrintAndLog("DEBUG: Error - IO prox not enough samples in GraphBuffer"); return retval; } - uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0}; - size_t bitlen = getFromGraphBuf(BitStream); + uint8_t bits[MAX_GRAPH_TRACE_LEN]={0}; + size_t bitlen = getFromGraphBuf(bits); if (bitlen == 0) return retval; int waveIdx = 0; //get binary from fsk wave - idx = detectIOProx(BitStream, &bitlen, &waveIdx); + idx = detectIOProx(bits, &bitlen, &waveIdx); if (idx < 0){ if (g_debugMode){ if (idx == -1){ @@ -119,10 +119,13 @@ int CmdIOProxDemod(const char *Cmd) { if (idx==0){ if (g_debugMode){ PrintAndLog("DEBUG: Error - IO prox data not found - FSK Bits: %d", bitlen); - if (bitlen > 92) PrintAndLog("%s", sprint_bin_break(BitStream,92,16)); + if (bitlen > 92) PrintAndLog("%s", sprint_bin_break(bits,92,16)); } return retval; } + setDemodBuf(bits, bitlen, idx); + setClockGrid(64, waveIdx + (idx*64)); + //Index map //0 10 20 30 40 50 60 //| | | | | | | @@ -133,30 +136,30 @@ int CmdIOProxDemod(const char *Cmd) { //XSF(version)facility:codeone+codetwo (raw) if (g_debugMode) { - PrintAndLog("%d%d%d%d%d%d%d%d %d", BitStream[idx], BitStream[idx+1], BitStream[idx+2], BitStream[idx+3], BitStream[idx+4], BitStream[idx+5], BitStream[idx+6], BitStream[idx+7], BitStream[idx+8]); - PrintAndLog("%d%d%d%d%d%d%d%d %d", BitStream[idx+9], BitStream[idx+10], BitStream[idx+11],BitStream[idx+12],BitStream[idx+13],BitStream[idx+14],BitStream[idx+15],BitStream[idx+16],BitStream[idx+17]); - PrintAndLog("%d%d%d%d%d%d%d%d %d facility", BitStream[idx+18], BitStream[idx+19], BitStream[idx+20],BitStream[idx+21],BitStream[idx+22],BitStream[idx+23],BitStream[idx+24],BitStream[idx+25],BitStream[idx+26]); - PrintAndLog("%d%d%d%d%d%d%d%d %d version", BitStream[idx+27], BitStream[idx+28], BitStream[idx+29],BitStream[idx+30],BitStream[idx+31],BitStream[idx+32],BitStream[idx+33],BitStream[idx+34],BitStream[idx+35]); - PrintAndLog("%d%d%d%d%d%d%d%d %d code1", BitStream[idx+36], BitStream[idx+37], BitStream[idx+38],BitStream[idx+39],BitStream[idx+40],BitStream[idx+41],BitStream[idx+42],BitStream[idx+43],BitStream[idx+44]); - PrintAndLog("%d%d%d%d%d%d%d%d %d code2", BitStream[idx+45], BitStream[idx+46], BitStream[idx+47],BitStream[idx+48],BitStream[idx+49],BitStream[idx+50],BitStream[idx+51],BitStream[idx+52],BitStream[idx+53]); - PrintAndLog("%d%d%d%d%d%d%d%d %d%d checksum", BitStream[idx+54],BitStream[idx+55],BitStream[idx+56],BitStream[idx+57],BitStream[idx+58],BitStream[idx+59],BitStream[idx+60],BitStream[idx+61],BitStream[idx+62],BitStream[idx+63]); + PrintAndLog("%d%d%d%d%d%d%d%d %d", bits[idx], bits[idx+1], bits[idx+2], bits[idx+3], bits[idx+4], bits[idx+5], bits[idx+6], bits[idx+7], bits[idx+8]); + PrintAndLog("%d%d%d%d%d%d%d%d %d", bits[idx+9], bits[idx+10], bits[idx+11],bits[idx+12],bits[idx+13],bits[idx+14],bits[idx+15],bits[idx+16],bits[idx+17]); + PrintAndLog("%d%d%d%d%d%d%d%d %d facility", bits[idx+18], bits[idx+19], bits[idx+20],bits[idx+21],bits[idx+22],bits[idx+23],bits[idx+24],bits[idx+25],bits[idx+26]); + PrintAndLog("%d%d%d%d%d%d%d%d %d version", bits[idx+27], bits[idx+28], bits[idx+29],bits[idx+30],bits[idx+31],bits[idx+32],bits[idx+33],bits[idx+34],bits[idx+35]); + PrintAndLog("%d%d%d%d%d%d%d%d %d code1", bits[idx+36], bits[idx+37], bits[idx+38],bits[idx+39],bits[idx+40],bits[idx+41],bits[idx+42],bits[idx+43],bits[idx+44]); + PrintAndLog("%d%d%d%d%d%d%d%d %d code2", bits[idx+45], bits[idx+46], bits[idx+47],bits[idx+48],bits[idx+49],bits[idx+50],bits[idx+51],bits[idx+52],bits[idx+53]); + PrintAndLog("%d%d%d%d%d%d%d%d %d%d checksum", bits[idx+54],bits[idx+55],bits[idx+56],bits[idx+57],bits[idx+58],bits[idx+59],bits[idx+60],bits[idx+61],bits[idx+62],bits[idx+63]); } - uint32_t code = bytebits_to_byte(BitStream+idx,32); - uint32_t code2 = bytebits_to_byte(BitStream+idx+32,32); - uint8_t version = bytebits_to_byte(BitStream+idx+27,8); //14,4 - uint8_t facilitycode = bytebits_to_byte(BitStream+idx+18,8) ; - uint16_t number = (bytebits_to_byte(BitStream+idx+36,8)<<8)|(bytebits_to_byte(BitStream+idx+45,8)); //36,9 - uint8_t crc = bytebits_to_byte(BitStream+idx+54,8); + uint32_t code = bytebits_to_byte(bits+idx,32); + uint32_t code2 = bytebits_to_byte(bits+idx+32,32); + uint8_t version = bytebits_to_byte(bits+idx+27,8); //14,4 + uint8_t facilitycode = bytebits_to_byte(bits+idx+18,8) ; + uint16_t number = (bytebits_to_byte(bits+idx+36,8)<<8)|(bytebits_to_byte(bits+idx+45,8)); //36,9 + uint8_t crc = bytebits_to_byte(bits+idx+54,8); uint16_t calccrc = 0; for (uint8_t i = 1; i < 6; ++i){ - calccrc += bytebits_to_byte(BitStream + idx + 9 * i ,8); + calccrc += bytebits_to_byte(bits + idx + 9 * i ,8); } calccrc &= 0xff; calccrc = 0xff - calccrc; - if (crc == calccrc) { + if (crc == calccrc) { snprintf(crcStr, 3, "ok"); retval = 1; } else { @@ -167,7 +170,7 @@ int CmdIOProxDemod(const char *Cmd) { } PrintAndLog("IO Prox XSF(%02d)%02x:%05d (%08x%08x) [crc %s]", version, facilitycode, number, code, code2, crcStr); - setDemodBuf(BitStream, 64, idx); + if (g_debugMode){ PrintAndLog("DEBUG: IO prox idx: %d, Len: %d, Printing demod buffer:", idx, 64); printDemodBuff(); @@ -237,6 +240,8 @@ int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) { pre[++pos] = SEPARATOR; memcpy(bits, pre, sizeof(pre)); + + printf("IO raw bits:\n %s \n", sprint_bin(bits, 64)); return 1; } @@ -291,8 +296,7 @@ int CmdIOProxClone(const char *Cmd) { uint16_t cn = 0; uint8_t version = 0, fc = 0; uint8_t bits[64]; - uint8_t *bs=bits; - memset(bs,0,sizeof(bits)); + memset(bits,0,sizeof(bits)); char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_io_clone(); @@ -308,23 +312,20 @@ int CmdIOProxClone(const char *Cmd) { PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn); } + if ( !getIOProxBits(version, fc, cn, bits)) { + PrintAndLog("Error with tag bitstream generation."); + return 1; + } + if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q') blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(64) | 2 << T5555_MAXBLOCK_SHIFT; - if ( !getIOProxBits(version, fc, cn, bs)) { - PrintAndLog("Error with tag bitstream generation."); - return 1; - } - - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); + blocks[1] = bytebits_to_byte(bits, 32); + blocks[2] = bytebits_to_byte(bits + 32, 32); PrintAndLog("Preparing to clone IOProx to T55x7 with Version: %u FC: %u, CN: %u", version, fc, cn); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - PrintAndLog(" 00 | 0x%08x", blocks[0]); - PrintAndLog(" 01 | 0x%08x", blocks[1]); - PrintAndLog(" 02 | 0x%08x", blocks[2]); + print_blocks(blocks, 3); + //UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; UsbCommand c = {CMD_IO_CLONE_TAG, {blocks[1],blocks[2],0}}; clearCommandBuffer(); diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index bb7d7af26..fe59999b1 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -154,8 +154,7 @@ int CmdJablotronClone(const char *Cmd) { uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0}; uint8_t bits[64]; - uint8_t *bs = bits; - memset(bs, 0, sizeof(bits)); + memset(bits, 0, sizeof(bits)); char cmdp = param_getchar(Cmd, 0); if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_clone(); @@ -172,25 +171,21 @@ int CmdJablotronClone(const char *Cmd) { PrintAndLog("Card Number Truncated to 39bits: %"PRIx64, fullcode); } - if ( !getJablotronBits(fullcode, bs)) { + if ( !getJablotronBits(fullcode, bits)) { PrintAndLog("Error with tag bitstream generation."); return 1; } - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); + blocks[1] = bytebits_to_byte(bits, 32); + blocks[2] = bytebits_to_byte(bits + 32, 32); PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %"PRIx64, fullcode); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - PrintAndLog(" 00 | 0x%08x", blocks[0]); - PrintAndLog(" 01 | 0x%08x", blocks[1]); - PrintAndLog(" 02 | 0x%08x", blocks[2]); + print_blocks(blocks, 3); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; - for (int i = 2; i >= 0; --i) { + for (uint8_t i=0; i<4; i++) { c.arg[0] = blocks[i]; c.arg[1] = i; clearCommandBuffer(); diff --git a/client/cmdlfnedap.c b/client/cmdlfnedap.c index c0fea028f..961130743 100644 --- a/client/cmdlfnedap.c +++ b/client/cmdlfnedap.c @@ -241,15 +241,14 @@ int CmdLFNedapClone(const char *Cmd) { uint32_t cardnumber=0, cn = 0; uint32_t blocks[5]; - uint8_t i; - uint8_t bs[128]; - memset(bs, 0x00, sizeof(bs)); + uint8_t bits[128]; + memset(bits, 0x00, sizeof(bits)); if (sscanf(Cmd, "%u", &cn ) != 1) return usage_lf_nedap_clone(); cardnumber = (cn & 0x00FFFFFF); - if ( !GetNedapBits(cardnumber, bs)) { + if ( !GetNedapBits(cardnumber, bits)) { PrintAndLog("Error with tag bitstream generation."); return 1; } @@ -262,21 +261,18 @@ int CmdLFNedapClone(const char *Cmd) { if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q') blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(64) | 7 <= 0; --i) { + for (uint8_t i=0; i<4; i++) { c.arg[0] = blocks[i]; c.arg[1] = i; clearCommandBuffer(); diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index a6073b3ed..947bb57e7 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -201,18 +201,12 @@ int CmdPrescoClone(const char *Cmd) { blocks[4] = fullcode; PrintAndLog("Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u, FullCode: %08x", sitecode, usercode, fullcode); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - PrintAndLog(" 00 | 0x%08x", blocks[0]); - PrintAndLog(" 01 | 0x%08x", blocks[1]); - PrintAndLog(" 02 | 0x%08x", blocks[2]); - PrintAndLog(" 03 | 0x%08x", blocks[3]); - PrintAndLog(" 04 | 0x%08x", blocks[4]); + print_blocks(blocks, 5); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; - for (int i=4; i>=0; i--) { + for (uint8_t i=0; i<5; i++) { c.arg[0] = blocks[i]; c.arg[1] = i; clearCommandBuffer(); diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index d4ac19d27..779324e16 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -16,7 +16,7 @@ int usage_lf_pyramid_clone(void){ PrintAndLog("The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. "); PrintAndLog("Currently only works on 26bit"); PrintAndLog(""); - PrintAndLog("Usage: lf pyramid clone [h] "); + PrintAndLog("Usage: lf pyramid clone [h] [Q5]"); PrintAndLog("Options :"); PrintAndLog(" h : this help"); PrintAndLog(" : 8-bit value facility code"); @@ -33,7 +33,7 @@ int usage_lf_pyramid_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 pyramid sim [h] "); + PrintAndLog("Usage: lf pyramid sim [h] "); PrintAndLog("Options :"); PrintAndLog(" h : this help"); PrintAndLog(" : 8-bit value facility code"); @@ -53,7 +53,7 @@ int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) { if (justNoise(dest, *size)) return -1; // FSK demodulator - *size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // fsk2a RF/50 + *size = fskdemod(dest, *size, 50, 0, 10, 8, waveStartIdx); // fsk2 RF/50 if (*size < 128) return -2; //did we get a good demod? size_t startIdx = 0; uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1}; @@ -252,7 +252,6 @@ int CmdPyramidClone(const char *Cmd) { uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0; uint32_t blocks[5]; - uint8_t i; uint8_t bs[128]; memset(bs, 0x00, sizeof(bs)); @@ -269,24 +268,22 @@ 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 << T55x7_MAXBLOCK_SHIFT; + // Q5 if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q') blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(50) | 4 << T5555_MAXBLOCK_SHIFT; - blocks[1] = bytebits_to_byte(bs,32); - blocks[2] = bytebits_to_byte(bs+32,32); - blocks[3] = bytebits_to_byte(bs+64,32); - blocks[4] = bytebits_to_byte(bs+96,32); + blocks[1] = bytebits_to_byte(bs, 32); + blocks[2] = bytebits_to_byte(bs + 32, 32); + blocks[3] = bytebits_to_byte(bs + 64, 32); + blocks[4] = bytebits_to_byte(bs + 96, 32); PrintAndLog("Preparing to clone Farpointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - for ( i = 0; i<5; ++i ) - PrintAndLog(" %02d | 0x%08" PRIx32, i, blocks[i]); + print_blocks(blocks, 5); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; - for ( i = 0; i<5; ++i ) { + for (uint8_t i = 0; i < 5; ++i ) { c.arg[0] = blocks[i]; c.arg[1] = i; clearCommandBuffer(); @@ -311,10 +308,11 @@ int CmdPyramidSim(const char *Cmd) { memset(bs, 0x00, size); // Pyramid uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0 - uint64_t arg1, arg2; - arg1 = (10 << 8) + 8; - arg2 = 50 | 0; - + uint8_t clk = 50, invert = 0, high = 10, low = 8; + uint16_t arg1, arg2; + arg1 = high << 8 | low; + arg2 = invert << 8 | clk; + if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_pyramid_sim(); facilitycode = (fc & 0x000000FF); diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 9439023c3..bfb97a6fb 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -117,11 +117,15 @@ int CmdVikingClone(const char *Cmd) { rawID = getVikingBits(id); PrintAndLog("Cloning - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF)); - UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFFFFFF, Q5}}; + + UsbCommand c = {CMD_VIKING_CLONE_TAG, {rawID >> 32, rawID & 0xFFFFFFFF, Q5}}; clearCommandBuffer(); SendCommand(&c); - //check for ACK - WaitForResponse(CMD_ACK,NULL); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){ + PrintAndLog("Error occurred, device did not respond during write operation."); + return -1; + } return 0; } diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index 38868ce42..05d9423dd 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -177,15 +177,12 @@ int CmdVisa2kClone(const char *Cmd) { blocks[3] = (visa_parity(id) << 4) | visa_chksum(id); PrintAndLog("Preparing to clone Visa2000 to T55x7 with CardId: %u", id); - PrintAndLog("Blk | Data "); - PrintAndLog("----+------------"); - for(int i = 0; i<4; ++i) - PrintAndLog(" %02d | 0x%08x", i , blocks[i]); + print_blocks(blocks, 4); UsbCommand resp; UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; - for (int i = 3; i >= 0; --i) { + for (uint8_t i = 0; i < 4; i++) { c.arg[0] = blocks[i]; c.arg[1] = i; clearCommandBuffer(); diff --git a/client/ui.c b/client/ui.c index 5365a8938..76d751eb3 100644 --- a/client/ui.c +++ b/client/ui.c @@ -19,12 +19,11 @@ int GridOffset = 0; bool GridLocked = false; bool showDemod = true; -extern pthread_mutex_t print_lock; +pthread_mutex_t print_lock; static char *logfilename = "proxmark3.log"; -void PrintAndLog(char *fmt, ...) -{ +void PrintAndLog(char *fmt, ...) { char *saved_line; int saved_point; va_list argptr, argptr2; @@ -130,7 +129,7 @@ void iceIIR_Butterworth(int *data, const size_t len){ // compute instantaneous frequency by looking at phase difference // between adjacent samples - float freq = cargf(x*conjf(x_prime)); + float freq = cargf(x * conjf(x_prime)); x_prime = x; // retain this sample for next iteration output[i] =(freq > 0) ? 127 : -127; diff --git a/client/ui.h b/client/ui.h index ac4d01279..0cef6e2c8 100644 --- a/client/ui.h +++ b/client/ui.h @@ -32,8 +32,8 @@ void ShowGui(void); void HideGraphWindow(void); void ShowGraphWindow(void); void RepaintGraphWindow(void); -void PrintAndLog(char *fmt, ...); -void SetLogFilename(char *fn); +extern void PrintAndLog(char *fmt, ...); +extern void SetLogFilename(char *fn); extern double CursorScaleFactor; extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset; @@ -42,6 +42,6 @@ extern int flushAfterWrite; //buzzy extern bool GridLocked; extern bool showDemod; -void iceIIR_Butterworth(int * data, const size_t len); -void iceSimple_Filter(int *data, const size_t len, uint8_t k); +extern void iceIIR_Butterworth(int * data, const size_t len); +extern void iceSimple_Filter(int *data, const size_t len, uint8_t k); #endif diff --git a/client/util.c b/client/util.c index 43d63826a..4f79e4c1a 100644 --- a/client/util.c +++ b/client/util.c @@ -163,7 +163,7 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea if ( breaks > 0 && len % breaks != 0) rowlen = ( len+(len/breaks) > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len+(len/breaks); - //printf("(sprint_bin_break) rowlen %d\n", rowlen); + printf("(sprint_bin_break) rowlen %d\n", rowlen); static char buf[MAX_BIN_BREAK_LENGTH]; // 3072 + end of line characters if broken at 8 bits //clear memory @@ -182,8 +182,7 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea } in_index++; } - // last char. - sprintf(tmp++, "%u", data[in_index]); + return buf; } /* @@ -263,6 +262,18 @@ char *sprint_ascii(const uint8_t *data, const size_t len) { return buf; } +void print_blocks(uint32_t *data, size_t len) { + PrintAndLog("Blk | Data "); + PrintAndLog("----+------------"); + + if ( !data ) { + PrintAndLog("..empty data"); + } else { + for (uint8_t i=0; i //included in data.h #include #include +#include "ui.h" // PrintAndLog #ifdef ANDROID #include @@ -102,6 +103,8 @@ extern char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8 extern char *sprint_hex_ascii(const uint8_t *data, const size_t len); extern char *sprint_ascii(const uint8_t *data, const size_t len); +extern void print_blocks(uint32_t *data, size_t len); + extern void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); extern uint64_t bytes_to_num(uint8_t* src, size_t len); extern void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); diff --git a/common/lfdemod.c b/common/lfdemod.c index 9cc3f029a..08d9b3774 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -726,7 +726,7 @@ uint16_t countFC(uint8_t *BitStream, size_t size, uint8_t fskAdj) { if (fcCounter>0 && fcLensFnd<15){ //add new fc length fcCnts[fcLensFnd]++; - fcLens[fcLensFnd++]=fcCounter; + fcLens[fcLensFnd++] = fcCounter; } fcCounter=0; } else { @@ -1521,7 +1521,7 @@ size_t aggregate_bits(uint8_t *dest, size_t size, uint8_t clk, uint8_t invert, u //add to our destination the bits we collected memset(dest+numBits, dest[i-1] ^ invert , n); - if (g_debugMode == 2) prnt("ICCE:: n %u | numbits %u", n, numBits); + //if (g_debugMode == 2) prnt("ICCE:: n %u | numbits %u", n, numBits); numBits += n; n = 0; lastval = dest[i];