This commit is contained in:
iceman1001 committed 2022-02-12 17:46:34 +01:00
1 parent f1d45b491c
commit ec59acf64c
9 files changed
+961 -886

No files matched your search

+180 -183
View File
@@ -15,7 +15,7 @@
//
//-----------------------------------------------------------------------------
// Modes of operation:
//
//
// --- Read ---
// Proxmark reads an EM4100 tag. LED A is turned on. When the tag is detected, it is saved to flash (RDV4 only) and proxmark enters the emulation mode.
// It's the default mode for non-RDV4 devices, and if no previous read is present in the flash it's the default mode for RDV4 devices.
@@ -28,17 +28,17 @@
// Pressing the button enters writing mode and clones the emulated tag.
// Double pressing the button enters the validation mode.
// Holding the button enters the reading mode.
//
//
// --- Write ---
// Proxmarks writes the last read tag. LEDs A and B are turned on.
// When writing is complete LEDs A and B blink three times and proxmark enters the emulation mode.
//
//
// --- Validate ---
// Proxmark reads an EM4100 tag. LED C is turned on.
// If tag matches the last saved tag, LED C blinks three times. If it doesn't all LEDs blink three times. Proxmark enters the emulation mode afterwards.
// The result of the read is DISCARDED.
// Pressing the button enters the emulation mode.
//
//
// --- Wipe ---
// Proxmark continously wipes all approached T55xx tags. LED D is turned on, LEDs A-C are blinking.
// Pressing the button enters the default mode (reading or emulation).
@@ -129,235 +129,232 @@ static void SaveIDtoFlash(uint64_t id) {
bt[4 - i] = (uint8_t)(id >> 8 * i & 0xff);
}
if (exists_in_spiffs(filename))
rdv40_spiffs_append(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
else
rdv40_spiffs_append(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
else
rdv40_spiffs_write(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
if (exists_in_spiffs(filenameLast))
rdv40_spiffs_remove(filenameLast, RDV40_SPIFFS_SAFETY_NORMAL);
rdv40_spiffs_write(filenameLast, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
if (exists_in_spiffs(filenameLast))
rdv40_spiffs_remove(filenameLast, RDV40_SPIFFS_SAFETY_NORMAL);
rdv40_spiffs_write(filenameLast, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
}
static bool ReadFlash(void) {
if (exists_in_spiffs(filenameLast) == false)
return false;
uint8_t bt[5];
if (rdv40_spiffs_read(filenameLast, (uint8_t *) &bt, 5, RDV40_SPIFFS_SAFETY_NORMAL) < 0)
return false;
low = bt[0];
low <<= 32;
low |= (bt[1] << 24) | (bt[2] << 16) | (bt[3] << 8) | bt[4];
low2 = low;
high = 0;
high2 = 0;
return true;
if (exists_in_spiffs(filenameLast) == false)
return false;
uint8_t bt[5];
if (rdv40_spiffs_read(filenameLast, (uint8_t *) &bt, 5, RDV40_SPIFFS_SAFETY_NORMAL) < 0)
return false;
low = bt[0];
low <<= 32;
low |= (bt[1] << 24) | (bt[2] << 16) | (bt[3] << 8) | bt[4];
low2 = low;
high = 0;
high2 = 0;
return true;
}
#endif
static void Wipe(void) {
DbpString("Wipe mode");
LEDsoff();
for (;;) {
LED_A_ON();
LED_B_ON();
LED_C_ON();
LED_D_ON();
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t) 0, (uint32_t) 0, false);
SpinDelay(60);
LEDsoff();
LED_D_ON();
int b = BUTTON_HELD(100);
if (b != BUTTON_NO_CLICK || data_available())
return;
SpinDelay(100);
DbpString("Wipe mode");
LEDsoff();
b = BUTTON_HELD(100);
if (b != BUTTON_NO_CLICK || data_available())
return;
}
for (;;) {
LED_A_ON();
LED_B_ON();
LED_C_ON();
LED_D_ON();
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t) 0, (uint32_t) 0, false);
SpinDelay(60);
LEDsoff();
LED_D_ON();
int b = BUTTON_HELD(100);
if (b != BUTTON_NO_CLICK || data_available())
return;
SpinDelay(100);
b = BUTTON_HELD(100);
if (b != BUTTON_NO_CLICK || data_available())
return;
}
}
static void Read(void) {
mode = 0;
while (low2 == 0 || mode == 0)
{
DbpString("Read");
LEDsoff();
LED_A_ON();
low2 = 0;
high2 = 0;
lf_em410x_watch(1, &high2, &low2, false);
if (low2 != 0) {
LED_B_ON();
low = low2;
high = high2;
mode = 1;
mode = 0;
#ifdef WITH_FLASH
SaveIDtoFlash(low2);
#endif
SpinDelay(50);
LED_C_ON();
SpinDelay(50);
LED_D_ON();
SpinDelay(50);
LEDsoff();
return;
}
if (data_available())
return;
while (low2 == 0 || mode == 0) {
DbpString("Read");
LEDsoff();
LED_A_ON();
int b = BUTTON_CLICKED(1000);
low2 = 0;
high2 = 0;
lf_em410x_watch(1, &high2, &low2, false);
if ((b == BUTTON_SINGLE_CLICK || b == BUTTON_HOLD) && low != 0) {
mode = 1;
return;
}
if (low2 != 0) {
LED_B_ON();
low = low2;
high = high2;
mode = 1;
if (b == BUTTON_DOUBLE_CLICK) {
Wipe();
#ifdef WITH_FLASH
SaveIDtoFlash(low2);
#endif
if (low != 0) {
mode = 1;
return;
}
}
}
SpinDelay(50);
LED_C_ON();
SpinDelay(50);
LED_D_ON();
SpinDelay(50);
LEDsoff();
return;
}
if (data_available())
return;
int b = BUTTON_CLICKED(1000);
if ((b == BUTTON_SINGLE_CLICK || b == BUTTON_HOLD) && low != 0) {
mode = 1;
return;
}
if (b == BUTTON_DOUBLE_CLICK) {
Wipe();
if (low != 0) {
mode = 1;
return;
}
}
}
}
static void Validate(void) {
DbpString("Validate");
LEDsoff();
LED_C_ON();
DbpString("Validate");
LEDsoff();
LED_C_ON();
for (;;) {
low2 = 0;
high2 = 0;
for (;;) {
low2 = 0;
high2 = 0;
lf_em410x_watch(1, &high2, &low2, false);
lf_em410x_watch(1, &high2, &low2, false);
if (low == low2 && high == high2) {
LED_C_OFF();
SpinDelay(150);
for (int i = 0; i < 3; i++) {
LED_C_ON();
SpinDelay(150);
LED_C_OFF();
SpinDelay(150);
}
if (low == low2 && high == high2) {
LED_C_OFF();
SpinDelay(150);
for (int i = 0; i < 3; i++) {
LED_C_ON();
SpinDelay(150);
LED_C_OFF();
SpinDelay(150);
}
return;
}
else if (low2 != 0 || high2 != 0) {
LEDsoff();
for (int i = 0; i < 3; i++) {
LED_A_ON();
LED_B_ON();
LED_C_ON();
LED_D_ON();
SpinDelay(250);
LEDsoff();
SpinDelay(150);
}
return;
} else if (low2 != 0 || high2 != 0) {
LEDsoff();
for (int i = 0; i < 3; i++) {
LED_A_ON();
LED_B_ON();
LED_C_ON();
LED_D_ON();
SpinDelay(250);
LEDsoff();
SpinDelay(150);
}
return;
}
else
SpinDelay(200);
return;
} else
SpinDelay(200);
int b = BUTTON_HELD(200);
if (b != BUTTON_NO_CLICK || data_available())
return;
}
int b = BUTTON_HELD(200);
if (b != BUTTON_NO_CLICK || data_available())
return;
}
}
static void Write(void) {
DbpString("Write");
LED_A_ON();
LED_B_ON();
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t)(low >> 32), (uint32_t)(low & 0xffffffff), false);
SpinDelay(75);
LEDsoff();
DbpString("Write");
LED_A_ON();
LED_B_ON();
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t)(low >> 32), (uint32_t)(low & 0xffffffff), false);
SpinDelay(75);
LEDsoff();
for (int i = 0; i < 3; i++) {
LED_A_ON();
LED_B_ON();
SpinDelay(75);
LED_A_OFF();
LED_B_OFF();
SpinDelay(75);
}
for (int i = 0; i < 3; i++) {
LED_A_ON();
LED_B_ON();
SpinDelay(75);
LED_A_OFF();
LED_B_OFF();
SpinDelay(75);
}
}
static void Emulate(void) {
DbpString("Emulate");
LEDsoff();
DbpString("Emulate");
LEDsoff();
for (;;) {
int bx = BUTTON_HELD(50);
if (bx == BUTTON_NO_CLICK)
break;
SpinDelay(50);
}
for (;;) {
int bx = BUTTON_HELD(50);
if (bx == BUTTON_NO_CLICK)
break;
SpinDelay(50);
}
LED_B_ON();
construct_EM410x_emul(rev_quads(low));
LED_B_ON();
construct_EM410x_emul(rev_quads(low));
SimulateTagLowFrequencyEx(buflen, 0, false, -1);
int b = BUTTON_CLICKED(800);
int b = BUTTON_CLICKED(800);
if (b == BUTTON_NO_CLICK)
return;
if (b == BUTTON_NO_CLICK)
return;
for (;;) {
int bx = BUTTON_HELD(50);
if (bx == BUTTON_NO_CLICK)
break;
SpinDelay(50);
}
for (;;) {
int bx = BUTTON_HELD(50);
if (bx == BUTTON_NO_CLICK)
break;
SpinDelay(50);
}
if (b == BUTTON_SINGLE_CLICK)
Write();
else if (b == BUTTON_HOLD)
mode = 0;
else if (b == BUTTON_DOUBLE_CLICK)
Validate();
if (b == BUTTON_SINGLE_CLICK)
Write();
else if (b == BUTTON_HOLD)
mode = 0;
else if (b == BUTTON_DOUBLE_CLICK)
Validate();
}
void RunMod() {
StandAloneMode();
LEDsoff();
LED_D_ON();
LEDsoff();
LED_D_ON();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
WDT_HIT();
#ifdef WITH_FLASH
if (ReadFlash())
mode = 1;
else Read();
WDT_HIT();
#ifdef WITH_FLASH
if (ReadFlash())
mode = 1;
else Read();
#else
Read();
Read();
#endif
for (;;) {
WDT_HIT();
LEDsoff();
WDT_HIT();
LEDsoff();
if (data_available()) return;
if (mode == 0)
Read();
else Emulate();
if (mode == 0)
Read();
else Emulate();
}
}