[RDV4] Readed IDs store to file in spiffs

This commit is contained in:
Artem Gnatyuk 2020-03-21 21:27:57 +07:00
parent 311f43172f
commit 097595cdef

View file

@ -5,12 +5,16 @@
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// LF rwc - This mode can simulate tag ID from selected slot and read tag ID
// to selected slot and to flash (only RDV4). Also you can set
// predefined IDs in any slot.
// LF rwc - This mode can simulate ID from selected slot, read ID to
// selected slot, write from selected slot to T5555 tag and store
// readed ID to flash (only RDV4). Also you can set predefined IDs
// in any slot.
// To recall stored ID from flash execute:
// mem dump o offset l 5 p
// where offset = 5 * selected slot
// mem spifss dump o emdump p
// or:
// mem spifss dump o emdump f emdump
// then from shell:
// hexdump emdump -e '5/1 "%02X" /0 "\n"'
//-----------------------------------------------------------------------------
#include "standalone.h"
#include "proxmark3_arm.h"
@ -22,6 +26,7 @@
#include "ticks.h"
#include "string.h"
#include "BigBuf.h"
#include "spiffs.h"
#ifdef WITH_FLASH
#include "flashmem.h"
@ -33,13 +38,13 @@
// low & high - array for storage IDs. Its length must be equal.
// Predefined IDs must be stored in low[].
// In high[] must be nulls
uint64_t low[] = {0x565AF781C7,0x540053E4E2,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint64_t low[] = {0x565AF781C7,0x540053E4E2,0x1234567890,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint32_t high[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint8_t *bba,slots_count;
int buflen;
void ModInfo(void) {
DbpString(" LF EM4100 read/write/clone standalone mode");
DbpString(" LF EM4100 simulate standalone V2");
}
uint64_t ReversQuads(uint64_t bits){
@ -99,11 +104,16 @@ void FlashLEDs(uint32_t speed, uint8_t times) {
#ifdef WITH_FLASH
void SaveIDtoFlash (int addr, uint64_t id) {
uint8_t b, *ptr;
uint8_t bt[5];
char *filename = "emdump";
rdv40_spiffs_mount();
for (int i = 0; i < 5; i++) {
b = (uint8_t) (id >> 8 * i & 0xff);
ptr = &b;
Flash_WriteData(addr * 5 + 4 - i,ptr,1);
bt[4-i] = (uint8_t) (id >> 8 * i & 0xff);
}
if (exists_in_spiffs(filename) == false){
rdv40_spiffs_write(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
} else {
rdv40_spiffs_append(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
}
}
#endif
@ -112,9 +122,10 @@ void RunMod() {
StandAloneMode();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
int selected = 0;
//state 0 - select slot,
//state 0 - select slot
// 1 - read tag to selected slot,
// 2 - simulate tag from selected slot
// 3 - write to T5555 tag
uint8_t state = 0;
slots_count = sizeof(low)/sizeof(low[0]);
bba = BigBuf_get_addr();
@ -130,7 +141,7 @@ void RunMod() {
if (button_pressed == 1) {
// Long press - switch to simulate mode
SpinUp(100);
SpinOff(100);
LED_Slot(selected);
state = 2;
} else if (button_pressed < 0) {
// Click - switch to next slot
@ -139,13 +150,21 @@ void RunMod() {
}
break;
case 1:
// Read mode. Click - exit to select mode
CmdEM410xdemod(1, &high[selected], &low[selected], 0);
FlashLEDs(100,5);
#ifdef WITH_FLASH
SaveIDtoFlash(selected, low[selected]);
#endif
state = 0;
// Read mode.
if (button_pressed > 0) {
// Long press - switch to read mode
SpinUp(100);
LED_Slot(selected);
state = 3;
} else if (button_pressed < 0) {
// Click - exit to select mode
CmdEM410xdemod(1, &high[selected], &low[selected], 0);
FlashLEDs(100,5);
#ifdef WITH_FLASH
SaveIDtoFlash(selected, low[selected]);
#endif
state = 0;
}
break;
case 2:
// Simulate mode
@ -155,7 +174,7 @@ void RunMod() {
LED_Slot(selected);
state = 1;
} else if (button_pressed < 0) {
// Click - start simulating. Click again to exit from simelate mode
// Click - start simulating. Click again to exit from simulate mode
LED_Slot(selected);
ConstructEM410xEmulBuf(ReversQuads(low[selected]));
FlashLEDs(100,5);
@ -164,6 +183,20 @@ void RunMod() {
state = 0; // Switch to select mode
}
break;
case 3:
// Write tag mode
if (button_pressed > 0) {
// Long press - switch to select mode
SpinDown(100);
LED_Slot(selected);
state = 0;
} else if (button_pressed < 0) {
// Click - write ID to tag
WriteEM410x(0, (uint32_t) (low[selected] >> 32), (uint32_t) (low[selected] & 0xffffffff));
LED_Slot(selected);
state = 0; // Switch to select mode
}
break;
}
}
}