color,text
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "lfdemod.h"
|
||||
#include "protocols.h" // t55xx defines
|
||||
#include "cmdlft55xx.h" // clone..
|
||||
#include "crc.h" // maxim
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
@@ -36,7 +37,7 @@ static int usage_lf_paradox_clone(void) {
|
||||
PrintAndLogEx(NORMAL, " b <raw hex> : raw hex data. 12 bytes max");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " lf paradox clone b 0f55555695596a6a9999a59a");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf paradox clone b 0f55555695596a6a9999a59a"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -53,16 +54,33 @@ static int usage_lf_paradox_sim(void) {
|
||||
PrintAndLogEx(NORMAL, " <Card Number> : 16-bit value card number");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " lf paradox sim 123 11223");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf paradox sim 123 11223"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
*/
|
||||
|
||||
const uint8_t paradox_lut[] = {
|
||||
0xDB, 0xFC, 0x3F, 0xC5, 0x50, 0x14, 0x05, 0x47,
|
||||
0x9F, 0xED, 0x7D, 0x59, 0x22, 0x84, 0x21, 0x4E,
|
||||
0x39, 0x48, 0x12, 0x88, 0x53, 0xDE, 0xBB, 0xE4,
|
||||
0xB4, 0x2D, 0x4D, 0x55, 0xCA, 0xBE, 0xA3, 0xE2
|
||||
};
|
||||
// FC:108, Card01827
|
||||
// 00000000 01101100 00000111 00100011
|
||||
// hex(0xED xor 0x7D xor 0x22 xor 0x84 xor 0xDE xor 0xBB xor 0xE4 xor 0x4D xor 0xA3 xor 0xE2 xor 0x47) 0xFC
|
||||
|
||||
#define PARADOX_PREAMBLE_LEN 8
|
||||
|
||||
static int CmdParadoxDemod(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
return demodParadox();
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//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
|
||||
static int CmdParadoxDemod(const char *Cmd) {
|
||||
(void)Cmd; // Cmd is not used so far
|
||||
|
||||
int demodParadox(void) {
|
||||
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
|
||||
size_t size = getFromGraphBuf(bits);
|
||||
@@ -71,12 +89,10 @@ static int CmdParadoxDemod(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint32_t hi2 = 0, hi = 0, lo = 0;
|
||||
int waveIdx = 0;
|
||||
int wave_idx = 0;
|
||||
//get binary from fsk wave
|
||||
int idx = detectParadox(bits, &size, &hi2, &hi, &lo, &waveIdx);
|
||||
int idx = detectParadox(bits, &size, &wave_idx);
|
||||
if (idx < 0) {
|
||||
|
||||
if (idx == -1)
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox not enough samples");
|
||||
else if (idx == -2)
|
||||
@@ -85,16 +101,52 @@ static int CmdParadoxDemod(const char *Cmd) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox problem during FSK demod");
|
||||
else if (idx == -4)
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox preamble not found");
|
||||
else if (idx == -5)
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox error in Manchester data, size %zu", size);
|
||||
else
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox error demoding fsk %d", idx);
|
||||
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint8_t *b = bits + idx;
|
||||
uint8_t rawhex[12] = {0};
|
||||
for (uint8_t i = 0, m = 0, p = 1; i < 96; i++) {
|
||||
|
||||
// convert hex
|
||||
rawhex[m] <<= 1;
|
||||
rawhex[m] |= (*b & 1);
|
||||
b++;
|
||||
|
||||
if (p == 8) {
|
||||
m++;
|
||||
p = 1;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t hi2 = 0, hi = 0, lo = 0;
|
||||
uint8_t error = 0;
|
||||
|
||||
// Remove manchester encoding from FSK bits, skip pre
|
||||
for (uint8_t i = idx + PARADOX_PREAMBLE_LEN; i < (idx + 96 - PARADOX_PREAMBLE_LEN ); i += 2) {
|
||||
|
||||
// not manchester data
|
||||
if (bits[i] == bits[i + 1]) {
|
||||
PrintAndLogEx(WARNING, "Error Manchester at %u", i);
|
||||
error++;
|
||||
}
|
||||
|
||||
hi2 = (hi2 << 1) | (hi >> 31);
|
||||
hi = (hi << 1) | (lo >> 31);
|
||||
lo <<= 1;
|
||||
|
||||
if (bits[i] && !bits[i + 1]) {
|
||||
lo |= 1; // 10
|
||||
}
|
||||
}
|
||||
|
||||
setDemodBuff(bits, size, idx);
|
||||
setClockGrid(50, waveIdx + (idx * 50));
|
||||
setClockGrid(50, wave_idx + (idx * 50));
|
||||
|
||||
if (hi2 == 0 && hi == 0 && lo == 0) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Paradox no value found");
|
||||
@@ -103,15 +155,41 @@ static int CmdParadoxDemod(const char *Cmd) {
|
||||
|
||||
uint32_t fc = ((hi & 0x3) << 6) | (lo >> 26);
|
||||
uint32_t cardnum = (lo >> 10) & 0xFFFF;
|
||||
uint8_t chksum = (lo >> 2) & 0xFF;
|
||||
|
||||
|
||||
// Calc CRC & Checksum
|
||||
// 000088f0b - FC: 8 - Card: 36619 - Checksum: 05 - RAW: 0f55555559595aa559a5566a
|
||||
// checksum?
|
||||
uint8_t calc_chksum = 0x47;
|
||||
uint8_t pos = 0;
|
||||
for(uint8_t i = 0; i < 8; i++ ) {
|
||||
|
||||
uint8_t ice = rawhex[i+1];
|
||||
for(uint8_t j = 0x80; j > 0; j >>= 2) {
|
||||
|
||||
if (ice & j) {
|
||||
calc_chksum ^= paradox_lut[pos];
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t crc = CRC8Maxim(rawhex + 1, 8);
|
||||
PrintAndLogEx(DEBUG, " FSK/MAN raw : %s", sprint_hex(rawhex, sizeof(rawhex)));
|
||||
PrintAndLogEx(DEBUG, " raw : %s = (maxim crc8) %02x == %02x", sprint_hex(rawhex + 1, 8), crc, calc_chksum);
|
||||
// PrintAndLogEx(DEBUG, " OTHER sample CRC-8/MAXIM : 55 55 69 A5 55 6A 59 5A = FC");
|
||||
|
||||
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);
|
||||
|
||||
PrintAndLogEx(NORMAL, "Paradox TAG ID: %x%08x - FC: %d - Card: %d - Checksum: %02x - RAW: %08x%08x%08x",
|
||||
PrintAndLogEx(INFO, "Paradox TAG ID: " _GREEN_("%x%08x") " - FC: " _GREEN_("%d") ", CN: " _GREEN_("%d") " - Checksum: %02x - RAW: %08x%08x%08x",
|
||||
hi >> 10,
|
||||
(hi & 0x3) << 26 | (lo >> 10),
|
||||
fc, cardnum,
|
||||
(lo >> 2) & 0xFF,
|
||||
fc,
|
||||
cardnum,
|
||||
chksum,
|
||||
rawHi2,
|
||||
rawHi,
|
||||
rawLo
|
||||
@@ -244,43 +322,25 @@ int CmdLFParadox(const char *Cmd) {
|
||||
}
|
||||
|
||||
// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
|
||||
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
|
||||
int detectParadox(uint8_t *dest, size_t *size, int *wave_start_idx) {
|
||||
//make sure buffer has data
|
||||
if (*size < 96 * 50) return -1;
|
||||
|
||||
if (getSignalProperties()->isnoise) return -2;
|
||||
|
||||
// FSK demodulator
|
||||
*size = fskdemod(dest, *size, 50, 1, 10, 8, waveStartIdx); // paradox fsk2a
|
||||
*size = fskdemod(dest, *size, 50, 1, 10, 8, wave_start_idx); // paradox fsk2a
|
||||
|
||||
//did we get a good demod?
|
||||
if (*size < 96) return -3;
|
||||
|
||||
// 00001111 bit pattern represent start of frame, 01 pattern represents a 0 and 10 represents a 1
|
||||
size_t startIdx = 0;
|
||||
size_t idx = 0;
|
||||
uint8_t preamble[] = {0, 0, 0, 0, 1, 1, 1, 1};
|
||||
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &idx))
|
||||
return -4; //preamble not found
|
||||
|
||||
size_t numStart = startIdx + sizeof(preamble);
|
||||
// final loop, go over previously decoded FSK data and manchester decode into usable tag ID
|
||||
for (size_t idx = numStart; (idx - numStart) < *size - sizeof(preamble); idx += 2) {
|
||||
if (dest[idx] == dest[idx + 1])
|
||||
return -5; //not manchester data
|
||||
|
||||
*hi2 = (*hi2 << 1) | (*hi >> 31);
|
||||
*hi = (*hi << 1) | (*lo >> 31);
|
||||
//Then, shift in a 0 or one into low
|
||||
*lo <<= 1;
|
||||
if (dest[idx] && !dest[idx + 1]) // 1 0
|
||||
*lo |= 1;
|
||||
else // 0 1
|
||||
*lo |= 0;
|
||||
}
|
||||
return (int)startIdx;
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
int demodParadox(void) {
|
||||
return CmdParadoxDemod("");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user