Fixes: lf simpsk - make sure Carrier input is ok.

fix: 'lf awid sim' - Clk param is used CorreCt
fix: 'lf HID sim' - unified way logging
fix: 'lf indala sim' - adding a draft simulation Command
fix: 'lf io sim'  - unified way logging
fix: 'lf nedap sim' - getting bits is wrong still..
fix: 'lf paradox sim'  - Helptext
lfdemod.C  got some reworked loops,  still some debug messages to be ...
This commit is contained in:
iceman1001
2017-08-10 14:19:57 +02:00
parent 78f01b0ffa
commit bd4d1ec74e
13 changed files with 162 additions and 123 deletions

View File

@@ -702,7 +702,8 @@ int CmdLFpskSim(const char *Cmd) {
if (clk <= 0) clk = 32;
if (carrier == 0) carrier = 2;
if (carrier != 2 && carrier != 4 && carrier != 8 )
carrier = 2;
if (pskType != 1){
if (pskType == 2){

View File

@@ -43,7 +43,7 @@ int usage_lf_awid_sim(void) {
PrintAndLog("");
PrintAndLog("Samples:");
PrintAndLog(" lf awid sim 26 224 1337");
PrintAndLog(" lf awid sim 50 2001 13371337");
PrintAndLog(" lf awid sim 50 2001 deadc0de");
return 0;
}
@@ -98,15 +98,16 @@ static int sendPing(void){
}
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bs, size_t bs_len){
PrintAndLog("Trying FC: %u; CN: %u", fc, cn);
if ( !getAWIDBits(fmtlen, fc, cn, bs)) {
PrintAndLog("Error with tag bitstream generation.");
return false;
}
uint64_t arg1 = (10<<8) + 8; // fcHigh = 10, fcLow = 8
uint64_t arg2 = 50; // clk RF/50 invert=0
uint8_t clk = 50, high = 10, low = 8, invert = 1;
uint64_t arg1 = (high << 8) + low;
uint64_t arg2 = (invert << 8) + clk;
UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, bs_len}};
memcpy(c.d.asBytes, bs, bs_len);
clearCommandBuffer();
@@ -228,7 +229,7 @@ int CmdAWIDRead_device(const char *Cmd) {
}
//by marshmellow
//AWID Prox demod - FSK RF/50 with preamble of 00000001 (always a 96 bit data stream)
//AWID Prox demod - FSK2a RF/50 with preamble of 00000001 (always a 96 bit data stream)
//print full AWID Prox ID and some bit format details if found
int CmdAWIDDemod(const char *Cmd) {
uint8_t bits[MAX_GRAPH_TRACE_LEN]={0};
@@ -277,7 +278,8 @@ int CmdAWIDDemod(const char *Cmd) {
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");
@@ -362,13 +364,9 @@ int CmdAWIDSim(const char *Cmd) {
uint32_t fc = 0, cn = 0;
uint8_t fmtlen = 0;
uint8_t bits[96];
uint8_t *bs = bits;
size_t size = sizeof(bits);
memset(bs, 0x00, size);
memset(bits, 0x00, size);
uint64_t arg1 = ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8
uint64_t arg2 = 50; // clk RF/50 invert=0
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_awid_sim();
@@ -382,16 +380,22 @@ int CmdAWIDSim(const char *Cmd) {
PrintAndLog("Emulating AWID %u -- FC: %u; CN: %u\n", fmtlen, fc, cn);
PrintAndLog("Press pm3-button to abort simulation or run another command");
if (!getAWIDBits(fmtlen, fc, cn, bs)) {
if (!getAWIDBits(fmtlen, fc, cn, bits)) {
PrintAndLog("Error with tag bitstream generation.");
return 1;
}
// AWID uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0
uint8_t clk = 50, high = 10, low = 8, invert = 1;
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
// 96 --- Bitstream length: 96-bits == 12 bytes
UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
memcpy(c.d.asBytes, bs, size);
memcpy(c.d.asBytes, bits, size);
clearCommandBuffer();
SendCommand(&c);
return 0;

View File

@@ -133,12 +133,14 @@ int CmdHIDDemod(const char *Cmd) {
if (idx < 0) {
if (g_debugMode){
if (idx==-1){
PrintAndLog("DEBUG: Error - HID just noise detected");
PrintAndLog("DEBUG: Error - HID not enough samples");
} else if (idx == -2) {
PrintAndLog("DEBUG: Error - HID problem during FSK demod");
PrintAndLog("DEBUG: Error - HID just noise detected");
} else if (idx == -3) {
PrintAndLog("DEBUG: Error - HID preamble not found");
PrintAndLog("DEBUG: Error - HID problem during FSK demod");
} else if (idx == -4) {
PrintAndLog("DEBUG: Error - HID preamble not found");
} else if (idx == -5) {
PrintAndLog("DEBUG: Error - HID error in Manchester data, SIZE: %d", BitLen);
} else {
PrintAndLog("DEBUG: Error - HID error demoding fsk %d", idx);

View File

@@ -26,29 +26,27 @@ int usage_lf_indala_demod(void) {
}
int usage_lf_indala_sim(void) {
PrintAndLog("Enables simulation of Indala card with specified facility-code and card number.");
PrintAndLog("Enables simulation of Indala card with specified uid.");
PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLog("");
PrintAndLog("Usage: lf indala sim [h] <version> <facility-code> <card-number>");
PrintAndLog("Usage: lf indala sim [h] <uid>");
PrintAndLog("Options :");
PrintAndLog(" h : This help");
PrintAndLog(" <version> : 8bit version");
PrintAndLog(" <facility-code> : 8bit value facility code");
PrintAndLog(" <card number> : 16bit value card number");
PrintAndLog(" h : This help");
PrintAndLog(" <uid> : 64/224 UID");
PrintAndLog("");
PrintAndLog("Samples");
PrintAndLog(" lf indala sim 26 101 1337");
PrintAndLog(" lf indala sim deadc0de");
return 0;
}
int usage_lf_indala_clone(void) {
PrintAndLog("Enables cloning of Indala card with specified facility-code and card number onto T55x7.");
PrintAndLog("Enables cloning of Indala card with specified uid onto T55x7.");
PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
PrintAndLog("");
PrintAndLog("Usage: lf indala clone [h] <uid> [Q5]");
PrintAndLog("Options :");
PrintAndLog(" h : This help");
PrintAndLog(" <uid> : 64/221 UID");
PrintAndLog(" <uid> : 64/224 UID");
PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip");
PrintAndLog("");
PrintAndLog("Samples");
@@ -56,6 +54,23 @@ int usage_lf_indala_clone(void) {
return 0;
}
// redesigned by marshmellow adjusted from existing decode functions
// indala id decoding - only tested on 26 bit tags, but attempted to make it work for more
int detectIndala26(uint8_t *dest, size_t *size, uint8_t *invert) {
//26 bit 40134 format (don't know other formats)
uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
uint8_t preamble_i[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
size_t startidx = 0;
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startidx)){
// if didn't find preamble try again inverting
if (!preambleSearch(dest, preamble_i, sizeof(preamble_i), size, &startidx)) return -1;
*invert ^= 1;
}
if (*size != 64 && *size != 224) return -2;
return (int) startidx;
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdIndalaRead(const char *Cmd) {
lf_read(true, 30000);
@@ -124,7 +139,6 @@ int CmdIndalaDemod(const char *Cmd) {
// but the other appears to currently be more accurate than this approach most of the time.
int CmdIndalaDemodAlt(const char *Cmd) {
// Usage: recover 64bit UID by default, specify "224" as arg to recover a 224bit UID
int state = -1;
int count = 0;
int i, j;
@@ -319,25 +333,44 @@ int CmdIndalaDemodAlt(const char *Cmd) {
}
int CmdIndalaSim(const char *Cmd) {
uint16_t cn = 0;
uint8_t bits[64];
uint8_t *bs = bits;
size_t size = sizeof(bits);
memset(bs, 0x00, size);
uint64_t arg1 = ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8
uint64_t arg2 = (64 << 8)| + 1; // clk RF/64 invert=1
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_indala_sim();
uint8_t bits[224];
size_t size = sizeof(bits);
memset(bits, 0x00, size);
// uid
uint8_t hexuid[100];
int len = 0;
param_gethex_ex(Cmd, 0, hexuid, &len);
if ( len > 28 )
return usage_lf_indala_sim();
// convert to binarray
uint8_t counter = 224;
for (uint8_t i=0; i< len; i++) {
for(uint8_t j=0; j<8; j++) {
bits[counter--] = hexuid[i] & 1;
hexuid[i] >>= 1;
}
}
PrintAndLog("Emulating Indala UID: %u \n", cn);
PrintAndLog("Press pm3-button to abort simulation or run another command");
// indala PSK
uint8_t clk = 32, carrier = 2, invert = 0;
uint16_t arg1, arg2;
arg1 = clk << 8 | carrier;
arg2 = invert;
// It has to send either 64bits (8bytes) or 224bits (28bytes). Zero padding needed if not.
// lf simpsk 1 c 32 r 2 d 0102030405060708
// PrintAndLog("Emulating Indala UID: %u \n", cn);
// PrintAndLog("Press pm3-button to abort simulation or run another command");
UsbCommand c = {CMD_PSK_SIM_TAG, {arg1, arg2, size}};
memcpy(c.d.asBytes, bs, size);
memcpy(c.d.asBytes, bits, size);
clearCommandBuffer();
SendCommand(&c);
return 0;
@@ -347,7 +380,6 @@ int CmdIndalaSim(const char *Cmd) {
int CmdIndalaClone(const char *Cmd) {
UsbCommand c;
uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7;
uid1 = uid2 = uid3 = uid4 = uid5 = uid6 = uid7 = 0;
int n = 0, i = 0;

View File

@@ -33,6 +33,8 @@ extern int CmdIndalaRead(const char *Cmd);
extern int CmdIndalaClone(const char *Cmd);
extern int CmdIndalaSim(const char *Cmd);
extern int detectIndala26(uint8_t *bitStream, size_t *size, uint8_t *invert);
extern int usage_lf_indala_demod(void);
extern int usage_lf_indala_clone(void);
extern int usage_lf_indala_sim(void);

View File

@@ -101,9 +101,9 @@ int CmdIOProxDemod(const char *Cmd) {
if (idx < 0){
if (g_debugMode){
if (idx == -1){
PrintAndLog("DEBUG: Error - IO prox just noise detected");
PrintAndLog("DEBUG: Error - IO prox not enough samples");
} else if (idx == -2) {
PrintAndLog("DEBUG: Error - IO prox not enough samples");
PrintAndLog("DEBUG: Error - IO prox just noise detected");
} else if (idx == -3) {
PrintAndLog("DEBUG: Error - IO prox error during fskdemod");
} else if (idx == -4) {

View File

@@ -49,14 +49,13 @@ int detectNedap(uint8_t *dest, size_t *size) {
return (int) startIdx;
}
int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
// preamble 1111 1111 10 = 0XF8
num_to_bytebits(0xF8, 10, pre);
// preamble 1111 1111 10 = 0xFF8
num_to_bytebits(0xFF8, 12, pre);
// fixed tagtype code? 0010 1101 = 0x2D
num_to_bytebits(0x2D, 8, pre+10);
@@ -64,7 +63,7 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
// 46 encrypted bits - UNKNOWN ALGO
// -- 16 bits checksum. Should be 4x4 checksum, based on UID and 2 constant values.
// -- 30 bits undocumented?
num_to_bytebits(cn, 46, pre+18);
//num_to_bytebits(cn, 46, pre+18);
//----from this part, the UID in clear text, with a 1bit ZERO as separator between bytes.
pre[64] = 0;
@@ -95,10 +94,10 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
pre[63] = GetParity( DemodBuffer, EVEN, 63);
pre[127] = GetParity( DemodBuffer+64, EVEN, 63);
memcpy(nedapBits, pre, 128);
//1111111110001011010000010110100011001001000010110101001101011001000110011010010000000000100001110001001000000001000101011100111
// 1111111110001011010000010110100011001001000010110101001101011001000110011010010000000000100001110001001000000001000101011100111
return 1;
}
/*
@@ -317,6 +316,7 @@ int CmdLFNedapSim(const char *Cmd) {
return 1;
}
PrintAndLog("bin %s", sprint_bin_break(bs, 128, 32));
PrintAndLog("Simulating Nedap - CardNumber: %u", cardnumber );
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};

View File

@@ -68,7 +68,7 @@ int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint
}
//by marshmellow
//Paradox Prox demod - FSK RF/50 with preamble of 00001111 (then manchester encoded)
//Paradox Prox demod - FSK2a RF/50 with preamble of 00001111 (then manchester encoded)
//print full Paradox Prox ID and some bit format details if found
int CmdParadoxDemod(const char *Cmd) {
//raw fsk demod no manchester decoding no start bit finding just get binary from wave

View File

@@ -12,5 +12,8 @@ extern int CmdLFParadox(const char *Cmd);
extern int CmdParadoxDemod(const char *Cmd);
extern int CmdParadoxRead(const char *Cmd);
//extern int CmdParadoxClone(const char *Cmd);
extern int CmdParadoxSim(const char *Cmd);
extern int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx);
#endif

View File

@@ -491,7 +491,6 @@ int param_getstr(const char *line, int paramnum, char * str)
The following methods comes from Rfidler sourcecode.
https://github.com/ApertureLabsLtd/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/
*/
// convert hex to sequence of 0/1 bit values
// returns number of bits converted
int hextobinarray(char *target, char *source)