chg: 'lf em/hid/io/awid watch' - colors, unified, NG
This commit is contained in:
@@ -784,9 +784,10 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
reply_mix(CMD_ACK, bits, 0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_HID_DEMOD: {
|
||||
case CMD_LF_HID_WATCH: {
|
||||
uint32_t high, low;
|
||||
CmdHIDdemodFSK(0, &high, &low, 1);
|
||||
int res = lf_hid_watch(0, &high, &low);
|
||||
reply_ng(CMD_LF_HID_WATCH, res, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_HID_SIMULATE: {
|
||||
@@ -832,7 +833,15 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
break;
|
||||
}
|
||||
case CMD_LF_EM410X_WRITE: {
|
||||
WriteEM410x(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]);
|
||||
struct p {
|
||||
uint8_t card;
|
||||
uint8_t clock;
|
||||
uint32_t high;
|
||||
uint32_t low;
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *)packet->data.asBytes;
|
||||
int res = copy_em410x_to_t55xx(payload->card, payload->clock, payload->high, payload->low);
|
||||
reply_ng(CMD_LF_EM410X_WRITE, res, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_TI_READ: {
|
||||
@@ -934,10 +943,10 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
EM4xWriteWord(payload->address, payload->data, payload->password, payload->usepwd);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_AWID_DEMOD: {
|
||||
case CMD_LF_AWID_WATCH: {
|
||||
uint32_t high, low;
|
||||
// Set realtime AWID demodulation
|
||||
CmdAWIDdemodFSK(0, &high, &low, 1);
|
||||
int res = lf_awid_watch(0, &high, &low);
|
||||
reply_ng(CMD_LF_AWID_WATCH, res, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_VIKING_CLONE: {
|
||||
|
||||
128
armsrc/lfops.c
128
armsrc/lfops.c
@@ -171,7 +171,7 @@ t55xx_configurations_t T55xx_Timing = {
|
||||
#define T55XX_LONGLEADINGREFERENCE 4 // Value to tell Write Bit to send long reference
|
||||
|
||||
// ATA55xx shared presets & routines
|
||||
static uint32_t GetT55xxClockBit(uint32_t clock) {
|
||||
static uint32_t GetT55xxClockBit(uint8_t clock) {
|
||||
switch (clock) {
|
||||
case 128:
|
||||
return T55x7_BITRATE_RF_128;
|
||||
@@ -1224,32 +1224,52 @@ void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size,
|
||||
}
|
||||
|
||||
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
|
||||
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
int lf_hid_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
|
||||
size_t size;
|
||||
uint32_t hi2 = 0, hi = 0, lo = 0;
|
||||
int dummyIdx = 0;
|
||||
// Configure to go in 125kHz listen mode
|
||||
LFSetupFPGAForADC(LF_DIVISOR_125, true);
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
BigBuf_Clear_keep_EM();
|
||||
clear_trace();
|
||||
set_tracing(false);
|
||||
|
||||
//clear read buffer
|
||||
BigBuf_Clear_keep_EM();
|
||||
|
||||
while (!BUTTON_PRESS() && !data_available()) {
|
||||
int res = PM3_SUCCESS;
|
||||
uint16_t interval = 0;
|
||||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
WDT_HIT();
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
res = PM3_EOPABORTED;
|
||||
break;
|
||||
}
|
||||
interval = 0;
|
||||
} else {
|
||||
interval++;
|
||||
}
|
||||
|
||||
DoAcquisition_default(-1, false);
|
||||
|
||||
// FSK demodulator
|
||||
size = 50 * 128 * 2; //big enough to catch 2 sequences of largest format
|
||||
// 50 * 128 * 2 - big enough to catch 2 sequences of largest format
|
||||
size = MIN(12800, BigBuf_max_traceLen());
|
||||
|
||||
int idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo, &dummyIdx);
|
||||
if (idx < 0) continue;
|
||||
|
||||
if (idx > 0 && lo > 0 && (size == 96 || size == 192)) {
|
||||
// go over previously decoded manchester data and decode into usable tag ID
|
||||
if (hi2 != 0) { //extra large HID tags 88/192 bits
|
||||
Dbprintf("TAG ID: %x%08x%08x (%d)",
|
||||
Dbprintf("TAG ID: " _GREEN_("%x%08x%08x") " (%d)",
|
||||
hi2,
|
||||
hi,
|
||||
lo,
|
||||
@@ -1311,25 +1331,40 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
|
||||
hi2 = hi = lo = idx = 0;
|
||||
}
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
DbpString("HID fsk demod stopped");
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
BigBuf_free();
|
||||
LEDsoff();
|
||||
return res;
|
||||
}
|
||||
|
||||
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
|
||||
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
|
||||
int lf_awid_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
size_t size;
|
||||
int dummyIdx = 0;
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
BigBuf_Clear_keep_EM();
|
||||
clear_trace();
|
||||
set_tracing(false);
|
||||
|
||||
LFSetupFPGAForADC(LF_DIVISOR_125, true);
|
||||
|
||||
while (!BUTTON_PRESS() && !data_available()) {
|
||||
int res = PM3_SUCCESS;
|
||||
uint16_t interval = 0;
|
||||
while (BUTTON_PRESS() == false) {
|
||||
|
||||
WDT_HIT();
|
||||
if (ledcontrol) LED_A_ON();
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
res = PM3_EOPABORTED;
|
||||
break;
|
||||
}
|
||||
interval = 0;
|
||||
} else {
|
||||
interval++;
|
||||
}
|
||||
|
||||
DoAcquisition_default(-1, false);
|
||||
// FSK demodulator
|
||||
@@ -1380,20 +1415,19 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
|
||||
uint32_t fac = bytebits_to_byte(dest + 9, 8);
|
||||
uint32_t cardnum = bytebits_to_byte(dest + 17, 16);
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
Dbprintf("AWID Found - BitLength: %d, FC: %d, Card: %d - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fac, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
Dbprintf("AWID Found - Bit length: " _GREEN_("%d") ", FC: " _GREEN_("%d") ", Card: " _GREEN_("%d") " - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, fac, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
} else {
|
||||
uint32_t cardnum = bytebits_to_byte(dest + 8 + (fmtLen - 17), 16);
|
||||
if (fmtLen > 32) {
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen - 32);
|
||||
uint32_t code2 = bytebits_to_byte(dest + 8 + (fmtLen - 32), 32);
|
||||
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
|
||||
Dbprintf("AWID Found - Bit length: " _GREEN_("%d") " -unknown bit length- (%d) - Wiegand: %x%08x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, code2, rawHi2, rawHi, rawLo);
|
||||
} else {
|
||||
uint32_t code1 = bytebits_to_byte(dest + 8, fmtLen);
|
||||
Dbprintf("AWID Found - BitLength: %d -unknown BitLength- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
Dbprintf("AWID Found - Bit length: " _GREEN_("%d") " -unknown bit length- (%d) - Wiegand: %x, Raw: %08x%08x%08x", fmtLen, cardnum, code1, rawHi2, rawHi, rawLo);
|
||||
}
|
||||
}
|
||||
if (findone) {
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
*high = rawHi;
|
||||
*low = rawLo;
|
||||
break;
|
||||
@@ -1401,8 +1435,9 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
|
||||
}
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
DbpString("AWID fsk demod stopped");
|
||||
if (ledcontrol) LED_A_OFF();
|
||||
BigBuf_free();
|
||||
LEDsoff();
|
||||
return res;
|
||||
}
|
||||
|
||||
int lf_em410x_watch(int findone, uint32_t *high, uint64_t *low) {
|
||||
@@ -1425,7 +1460,7 @@ int lf_em410x_watch(int findone, uint32_t *high, uint64_t *low) {
|
||||
WDT_HIT();
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 2000) {
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
res = PM3_EOPABORTED;
|
||||
break;
|
||||
@@ -1448,7 +1483,7 @@ int lf_em410x_watch(int findone, uint32_t *high, uint64_t *low) {
|
||||
errCnt = Em410xDecode(dest, &size, &idx, &hi, &lo);
|
||||
if (errCnt == 1) {
|
||||
if (size == 128) {
|
||||
Dbprintf("EM XL TAG ID: %06x%08x%08x - (%05d_%03d_%08d)",
|
||||
Dbprintf("EM XL TAG ID: " _GREEN_("%06x%08x%08x") " - ( %05d_%03d_%08d )",
|
||||
hi,
|
||||
(uint32_t)(lo >> 32),
|
||||
(uint32_t)lo,
|
||||
@@ -1456,7 +1491,7 @@ int lf_em410x_watch(int findone, uint32_t *high, uint64_t *low) {
|
||||
(uint32_t)((lo >> 16LL) & 0xFF),
|
||||
(uint32_t)(lo & 0xFFFFFF));
|
||||
} else {
|
||||
Dbprintf("EM TAG ID: %02x%08x - (%05d_%03d_%08d)",
|
||||
Dbprintf("EM TAG ID: " _GREEN_("%02x%08x") " - ( %05d_%03d_%08d )",
|
||||
(uint32_t)(lo >> 32),
|
||||
(uint32_t)lo,
|
||||
(uint32_t)(lo & 0xFFFF),
|
||||
@@ -1484,8 +1519,8 @@ int lf_io_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
|
||||
int dummyIdx = 0;
|
||||
uint32_t code = 0, code2 = 0;
|
||||
uint8_t version = 0, facilitycode = 0, crc = 0;
|
||||
uint16_t number = 0, calccrc = 0;
|
||||
uint8_t version = 0, facilitycode = 0;
|
||||
uint16_t number = 0;
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
BigBuf_Clear_keep_EM();
|
||||
@@ -1502,7 +1537,7 @@ int lf_io_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
WDT_HIT();
|
||||
|
||||
// cancel w usb command.
|
||||
if (interval == 2000) {
|
||||
if (interval == 4000) {
|
||||
if (data_available()) {
|
||||
res = PM3_EOPABORTED;
|
||||
break;
|
||||
@@ -1554,17 +1589,8 @@ int lf_io_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
facilitycode = bytebits_to_byte(dest + idx + 18, 8);
|
||||
number = (bytebits_to_byte(dest + idx + 36, 8) << 8) | (bytebits_to_byte(dest + idx + 45, 8)); //36,9
|
||||
|
||||
crc = bytebits_to_byte(dest + idx + 54, 8);
|
||||
for (uint8_t i = 1; i < 6; ++i) {
|
||||
calccrc += bytebits_to_byte(dest + idx + 9 * i, 8);
|
||||
}
|
||||
calccrc &= 0xff;
|
||||
calccrc = 0xff - calccrc;
|
||||
Dbprintf("IO Prox " _GREEN_("XSF(%02d)%02x:%05d") " (%08x%08x) (%s)", version, facilitycode, number, code, code2);
|
||||
|
||||
const char *crcStr = (crc == calccrc) ? _GREEN_("ok") : _RED_("fail");
|
||||
|
||||
Dbprintf("IO Prox XSF(%02d)%02x:%05d (%08x%08x) (%s)", version, facilitycode, number, code, code2, crcStr);
|
||||
// if we're only looking for one tag
|
||||
if (findone) {
|
||||
*high = code;
|
||||
*low = code2;
|
||||
@@ -1573,7 +1599,6 @@ int lf_io_watch(int findone, uint32_t *high, uint32_t *low) {
|
||||
code = code2 = 0;
|
||||
version = facilitycode = 0;
|
||||
number = 0;
|
||||
calccrc = 0;
|
||||
}
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
BigBuf_free();
|
||||
@@ -2215,17 +2240,26 @@ void CopyVikingtoT55xx(uint8_t *blocks, uint8_t Q5) {
|
||||
reply_ng(CMD_LF_VIKING_CLONE, PM3_SUCCESS, NULL, 0);
|
||||
}
|
||||
|
||||
int copy_em410x_to_t55xx(uint8_t card, uint8_t clock, uint32_t id_hi, uint32_t id_lo) {
|
||||
|
||||
// Define 9bit header for EM410x tags
|
||||
#define EM410X_HEADER 0x1FF
|
||||
#define EM410X_ID_LENGTH 40
|
||||
|
||||
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
|
||||
uint32_t clockbits = 0;
|
||||
if (card == 1) { //t55x7
|
||||
clockbits = GetT55xxClockBit(clock);
|
||||
if (clockbits == 0) {
|
||||
Dbprintf("Invalid clock rate: %d", clock);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
}
|
||||
|
||||
int i;
|
||||
uint64_t id = EM410X_HEADER;
|
||||
uint64_t rev_id = 0; // reversed ID
|
||||
int c_parity[4]; // column parity
|
||||
int r_parity = 0; // row parity
|
||||
uint32_t clock = 0;
|
||||
|
||||
// Reverse ID bits given as parameter (for simpler operations)
|
||||
for (i = 0; i < EM410X_ID_LENGTH; ++i) {
|
||||
@@ -2275,33 +2309,29 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
|
||||
// Add stop bit
|
||||
id <<= 1;
|
||||
|
||||
Dbprintf("Started writing %s tag ...", card ? "T55x7" : "T5555");
|
||||
LED_D_ON();
|
||||
|
||||
// Write EM410x ID
|
||||
uint32_t data[] = {0, (uint32_t)(id >> 32), (uint32_t)(id & 0xFFFFFFFF)};
|
||||
|
||||
clock = (card & 0xFF00) >> 8;
|
||||
// default to 64
|
||||
clock = (clock == 0) ? 64 : clock;
|
||||
Dbprintf("Clock rate: %d", clock);
|
||||
if (card & 0xFF) { //t55x7
|
||||
clock = GetT55xxClockBit(clock);
|
||||
if (clock == 0) {
|
||||
Dbprintf("Invalid clock rate: %d", clock);
|
||||
return;
|
||||
}
|
||||
data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT);
|
||||
} else { //t5555 (Q5)
|
||||
|
||||
if (card == 1) { // T55x7
|
||||
data[0] = clockbits | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT);
|
||||
} else { // T5555 (Q5)
|
||||
data[0] = T5555_SET_BITRATE(clock) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT);
|
||||
}
|
||||
|
||||
WriteT55xx(data, 0, 3);
|
||||
|
||||
LED_D_OFF();
|
||||
LEDsoff();
|
||||
Dbprintf("Tag %s written with 0x%08x%08x\n",
|
||||
card ? "T55x7" : "T5555",
|
||||
(uint32_t)(id >> 32),
|
||||
(uint32_t)id);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
|
||||
@@ -35,14 +35,17 @@ void CmdASKsimTAG(uint8_t encoding, uint8_t invert, uint8_t separator, uint8_t c
|
||||
void CmdPSKsimTAG(uint8_t carrier, uint8_t invert, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
void CmdNRZsimTAG(uint8_t invert, uint8_t separator, uint8_t clk, uint16_t size, uint8_t *bits, bool ledcontrol);
|
||||
|
||||
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol);
|
||||
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol); // Realtime demodulation mode for AWID26
|
||||
int lf_hid_watch(int findone, uint32_t *high, uint32_t *low);
|
||||
int lf_awid_watch(int findone, uint32_t *high, uint32_t *low); // Realtime demodulation mode for AWID26
|
||||
int lf_em410x_watch(int findone, uint32_t *high, uint64_t *low);
|
||||
int lf_io_watch(int findone, uint32_t *high, uint32_t *low);
|
||||
|
||||
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567
|
||||
|
||||
void CopyVikingtoT55xx(uint8_t *blocks, uint8_t Q5);
|
||||
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo);
|
||||
|
||||
int copy_em410x_to_t55xx(uint8_t card, uint8_t clock, uint32_t id_hi, uint32_t id_lo);
|
||||
|
||||
void T55xxResetRead(uint8_t flags);
|
||||
//id T55xxWriteBlock(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t flags);
|
||||
void T55xxWriteBlock(uint8_t *data);
|
||||
|
||||
Reference in New Issue
Block a user