mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
Make style
This commit is contained in:
parent
097595cdef
commit
c36d86bc01
2 changed files with 156 additions and 156 deletions
|
@ -23,36 +23,36 @@
|
||||||
#define CLOCK 64 //for 125kHz
|
#define CLOCK 64 //for 125kHz
|
||||||
|
|
||||||
// low & high - array for storage IDs. Its length must be equal.
|
// low & high - array for storage IDs. Its length must be equal.
|
||||||
// Predefined IDs must be stored in low[].
|
// Predefined IDs must be stored in low[].
|
||||||
// In high[] must be nulls
|
// In high[] must be nulls
|
||||||
uint64_t low[] = {0x565A1140BE,0x365A398149,0x5555555555,0xFFFFFFFFFF};
|
uint64_t low[] = {0x565A1140BE, 0x365A398149, 0x5555555555, 0xFFFFFFFFFF};
|
||||||
uint32_t high[] = {0,0,0,0};
|
uint32_t high[] = {0, 0, 0, 0};
|
||||||
uint8_t *bba,slots_count;
|
uint8_t *bba, slots_count;
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
||||||
void ModInfo(void) {
|
void ModInfo(void) {
|
||||||
DbpString(" LF EM4100 simulator standalone mode");
|
DbpString(" LF EM4100 simulator standalone mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReversQuads(uint64_t bits){
|
uint64_t ReversQuads(uint64_t bits) {
|
||||||
uint64_t result = 0;
|
uint64_t result = 0;
|
||||||
for (int i = 0; i < 16; i++){
|
for (int i = 0; i < 16; i++) {
|
||||||
result += ((bits >> (60 - 4 *i)) & 0xf) << (4 * i);
|
result += ((bits >> (60 - 4 * i)) & 0xf) << (4 * i);
|
||||||
}
|
}
|
||||||
return result >> 24;
|
return result >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillBuff(uint8_t bit) {
|
void FillBuff(uint8_t bit) {
|
||||||
memset (bba + buflen, bit, CLOCK / 2);
|
memset(bba + buflen, bit, CLOCK / 2);
|
||||||
buflen += (CLOCK / 2);
|
buflen += (CLOCK / 2);
|
||||||
memset (bba + buflen, bit^1,CLOCK / 2);
|
memset(bba + buflen, bit ^ 1, CLOCK / 2);
|
||||||
buflen += (CLOCK / 2);
|
buflen += (CLOCK / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConstructEM410xEmulBuf(uint64_t id) {
|
void ConstructEM410xEmulBuf(uint64_t id) {
|
||||||
|
|
||||||
int i, j, binary[4], parity[4];
|
int i, j, binary[4], parity[4];
|
||||||
buflen = 0;
|
buflen = 0;
|
||||||
for (i = 0; i < 9; i++)
|
for (i = 0; i < 9; i++)
|
||||||
FillBuff(1);
|
FillBuff(1);
|
||||||
parity[0] = parity[1] = parity[2] = parity[3] = 0;
|
parity[0] = parity[1] = parity[2] = parity[3] = 0;
|
||||||
|
@ -60,39 +60,39 @@ void ConstructEM410xEmulBuf(uint64_t id) {
|
||||||
for (j = 3; j >= 0; j--, id /= 2)
|
for (j = 3; j >= 0; j--, id /= 2)
|
||||||
binary[j] = id % 2;
|
binary[j] = id % 2;
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
FillBuff(binary[j]);
|
FillBuff(binary[j]);
|
||||||
FillBuff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
|
FillBuff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
parity[j] ^= binary[j];
|
parity[j] ^= binary[j];
|
||||||
}
|
}
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
FillBuff(parity[j]);
|
FillBuff(parity[j]);
|
||||||
FillBuff(0);
|
FillBuff(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_Slot(int i) {
|
void LED_Slot(int i) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
if (slots_count > 4) {
|
if (slots_count > 4) {
|
||||||
LED(i % MAX_IND, 0); //binary indication for slots_count > 4
|
LED(i % MAX_IND, 0); //binary indication for slots_count > 4
|
||||||
} else {
|
} else {
|
||||||
LED(1 << i,0); //simple indication for slots_count <=4
|
LED(1 << i, 0); //simple indication for slots_count <=4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunMod() {
|
void RunMod() {
|
||||||
StandAloneMode();
|
StandAloneMode();
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
int selected = 0; //selected slot after start
|
int selected = 0; //selected slot after start
|
||||||
slots_count = sizeof(low)/sizeof(low[0]);
|
slots_count = sizeof(low) / sizeof(low[0]);
|
||||||
bba = BigBuf_get_addr();
|
bba = BigBuf_get_addr();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (data_available()) break;
|
if (data_available()) break;
|
||||||
SpinDelay(100);
|
SpinDelay(100);
|
||||||
SpinUp(100);
|
SpinUp(100);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
ConstructEM410xEmulBuf(ReversQuads(low[selected]));
|
ConstructEM410xEmulBuf(ReversQuads(low[selected]));
|
||||||
SimulateTagLowFrequency(buflen, 0, true);
|
SimulateTagLowFrequency(buflen, 0, true);
|
||||||
selected = (selected + 1) % slots_count;
|
selected = (selected + 1) % slots_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
// the license.
|
// the license.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// LF rwc - This mode can simulate ID from selected slot, read ID to
|
// LF rwc - This mode can simulate ID from selected slot, read ID to
|
||||||
// selected slot, write from selected slot to T5555 tag and store
|
// selected slot, write from selected slot to T5555 tag and store
|
||||||
// readed ID to flash (only RDV4). Also you can set predefined IDs
|
// readed ID to flash (only RDV4). Also you can set predefined IDs
|
||||||
// in any slot.
|
// in any slot.
|
||||||
// To recall stored ID from flash execute:
|
// To recall stored ID from flash execute:
|
||||||
// mem spifss dump o emdump p
|
// mem spifss dump o emdump p
|
||||||
// or:
|
// or:
|
||||||
|
@ -36,36 +36,36 @@
|
||||||
#define CLOCK 64 //for 125kHz
|
#define CLOCK 64 //for 125kHz
|
||||||
|
|
||||||
// low & high - array for storage IDs. Its length must be equal.
|
// low & high - array for storage IDs. Its length must be equal.
|
||||||
// Predefined IDs must be stored in low[].
|
// Predefined IDs must be stored in low[].
|
||||||
// In high[] must be nulls
|
// In high[] must be nulls
|
||||||
uint64_t low[] = {0x565AF781C7,0x540053E4E2,0x1234567890,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};
|
uint32_t high[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
uint8_t *bba,slots_count;
|
uint8_t *bba, slots_count;
|
||||||
int buflen;
|
int buflen;
|
||||||
|
|
||||||
void ModInfo(void) {
|
void ModInfo(void) {
|
||||||
DbpString(" LF EM4100 simulate standalone V2");
|
DbpString(" LF EM4100 simulate standalone V2");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReversQuads(uint64_t bits){
|
uint64_t ReversQuads(uint64_t bits) {
|
||||||
uint64_t result = 0;
|
uint64_t result = 0;
|
||||||
for (int i = 0; i < 16; i++){
|
for (int i = 0; i < 16; i++) {
|
||||||
result += ((bits >> (60 - 4 *i)) & 0xf) << (4 * i);
|
result += ((bits >> (60 - 4 * i)) & 0xf) << (4 * i);
|
||||||
}
|
}
|
||||||
return result >> 24;
|
return result >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillBuff(uint8_t bit) {
|
void FillBuff(uint8_t bit) {
|
||||||
memset (bba + buflen, bit, CLOCK / 2);
|
memset(bba + buflen, bit, CLOCK / 2);
|
||||||
buflen += (CLOCK / 2);
|
buflen += (CLOCK / 2);
|
||||||
memset (bba + buflen, bit^1,CLOCK / 2);
|
memset(bba + buflen, bit ^ 1, CLOCK / 2);
|
||||||
buflen += (CLOCK / 2);
|
buflen += (CLOCK / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConstructEM410xEmulBuf(uint64_t id) {
|
void ConstructEM410xEmulBuf(uint64_t id) {
|
||||||
|
|
||||||
int i, j, binary[4], parity[4];
|
int i, j, binary[4], parity[4];
|
||||||
buflen = 0;
|
buflen = 0;
|
||||||
for (i = 0; i < 9; i++)
|
for (i = 0; i < 9; i++)
|
||||||
FillBuff(1);
|
FillBuff(1);
|
||||||
parity[0] = parity[1] = parity[2] = parity[3] = 0;
|
parity[0] = parity[1] = parity[2] = parity[3] = 0;
|
||||||
|
@ -73,23 +73,23 @@ void ConstructEM410xEmulBuf(uint64_t id) {
|
||||||
for (j = 3; j >= 0; j--, id /= 2)
|
for (j = 3; j >= 0; j--, id /= 2)
|
||||||
binary[j] = id % 2;
|
binary[j] = id % 2;
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
FillBuff(binary[j]);
|
FillBuff(binary[j]);
|
||||||
FillBuff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
|
FillBuff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
parity[j] ^= binary[j];
|
parity[j] ^= binary[j];
|
||||||
}
|
}
|
||||||
for (j = 0; j < 4; j++)
|
for (j = 0; j < 4; j++)
|
||||||
FillBuff(parity[j]);
|
FillBuff(parity[j]);
|
||||||
FillBuff(0);
|
FillBuff(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_Slot(int i) {
|
void LED_Slot(int i) {
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
if (slots_count > 4) {
|
if (slots_count > 4) {
|
||||||
LED(i % MAX_IND, 0); //binary indication, usefully for slots_count > 4
|
LED(i % MAX_IND, 0); //binary indication, usefully for slots_count > 4
|
||||||
} else {
|
} else {
|
||||||
LED(1 << i,0); //simple indication for slots_count <=4
|
LED(1 << i, 0); //simple indication for slots_count <=4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlashLEDs(uint32_t speed, uint8_t times) {
|
void FlashLEDs(uint32_t speed, uint8_t times) {
|
||||||
|
@ -103,100 +103,100 @@ void FlashLEDs(uint32_t speed, uint8_t times) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
void SaveIDtoFlash (int addr, uint64_t id) {
|
void SaveIDtoFlash(int addr, uint64_t id) {
|
||||||
uint8_t bt[5];
|
uint8_t bt[5];
|
||||||
char *filename = "emdump";
|
char *filename = "emdump";
|
||||||
rdv40_spiffs_mount();
|
rdv40_spiffs_mount();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
bt[4-i] = (uint8_t) (id >> 8 * i & 0xff);
|
bt[4 - i] = (uint8_t)(id >> 8 * i & 0xff);
|
||||||
}
|
}
|
||||||
if (exists_in_spiffs(filename) == false){
|
if (exists_in_spiffs(filename) == false) {
|
||||||
rdv40_spiffs_write(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
|
rdv40_spiffs_write(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
|
||||||
} else {
|
} else {
|
||||||
rdv40_spiffs_append(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
|
rdv40_spiffs_append(filename, &bt[0], 5, RDV40_SPIFFS_SAFETY_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void RunMod() {
|
void RunMod() {
|
||||||
StandAloneMode();
|
StandAloneMode();
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
int selected = 0;
|
int selected = 0;
|
||||||
//state 0 - select slot
|
//state 0 - select slot
|
||||||
// 1 - read tag to selected slot,
|
// 1 - read tag to selected slot,
|
||||||
// 2 - simulate tag from selected slot
|
// 2 - simulate tag from selected slot
|
||||||
// 3 - write to T5555 tag
|
// 3 - write to T5555 tag
|
||||||
uint8_t state = 0;
|
uint8_t state = 0;
|
||||||
slots_count = sizeof(low)/sizeof(low[0]);
|
slots_count = sizeof(low) / sizeof(low[0]);
|
||||||
bba = BigBuf_get_addr();
|
bba = BigBuf_get_addr();
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (data_available()) break;
|
if (data_available()) break;
|
||||||
int button_pressed = BUTTON_HELD(1000);
|
int button_pressed = BUTTON_HELD(1000);
|
||||||
SpinDelay(300);
|
SpinDelay(300);
|
||||||
switch (state){
|
switch (state) {
|
||||||
case 0:
|
case 0:
|
||||||
// Select mode
|
// Select mode
|
||||||
if (button_pressed == 1) {
|
if (button_pressed == 1) {
|
||||||
// Long press - switch to simulate mode
|
// Long press - switch to simulate mode
|
||||||
SpinUp(100);
|
SpinUp(100);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 2;
|
state = 2;
|
||||||
} else if (button_pressed < 0) {
|
} else if (button_pressed < 0) {
|
||||||
// Click - switch to next slot
|
// Click - switch to next slot
|
||||||
selected = (selected + 1) % slots_count;
|
selected = (selected + 1) % slots_count;
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// Read mode.
|
// Read mode.
|
||||||
if (button_pressed > 0) {
|
if (button_pressed > 0) {
|
||||||
// Long press - switch to read mode
|
// Long press - switch to read mode
|
||||||
SpinUp(100);
|
SpinUp(100);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 3;
|
state = 3;
|
||||||
} else if (button_pressed < 0) {
|
} else if (button_pressed < 0) {
|
||||||
// Click - exit to select mode
|
// Click - exit to select mode
|
||||||
CmdEM410xdemod(1, &high[selected], &low[selected], 0);
|
CmdEM410xdemod(1, &high[selected], &low[selected], 0);
|
||||||
FlashLEDs(100,5);
|
FlashLEDs(100, 5);
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
SaveIDtoFlash(selected, low[selected]);
|
SaveIDtoFlash(selected, low[selected]);
|
||||||
#endif
|
#endif
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Simulate mode
|
// Simulate mode
|
||||||
if (button_pressed > 0) {
|
if (button_pressed > 0) {
|
||||||
// Long press - switch to read mode
|
// Long press - switch to read mode
|
||||||
SpinDown(100);
|
SpinDown(100);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 1;
|
state = 1;
|
||||||
} else if (button_pressed < 0) {
|
} else if (button_pressed < 0) {
|
||||||
// Click - start simulating. Click again to exit from simulate mode
|
// Click - start simulating. Click again to exit from simulate mode
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
ConstructEM410xEmulBuf(ReversQuads(low[selected]));
|
ConstructEM410xEmulBuf(ReversQuads(low[selected]));
|
||||||
FlashLEDs(100,5);
|
FlashLEDs(100, 5);
|
||||||
SimulateTagLowFrequency(buflen, 0, 1);
|
SimulateTagLowFrequency(buflen, 0, 1);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 0; // Switch to select mode
|
state = 0; // Switch to select mode
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Write tag mode
|
// Write tag mode
|
||||||
if (button_pressed > 0) {
|
if (button_pressed > 0) {
|
||||||
// Long press - switch to select mode
|
// Long press - switch to select mode
|
||||||
SpinDown(100);
|
SpinDown(100);
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 0;
|
state = 0;
|
||||||
} else if (button_pressed < 0) {
|
} else if (button_pressed < 0) {
|
||||||
// Click - write ID to tag
|
// Click - write ID to tag
|
||||||
WriteEM410x(0, (uint32_t) (low[selected] >> 32), (uint32_t) (low[selected] & 0xffffffff));
|
WriteEM410x(0, (uint32_t)(low[selected] >> 32), (uint32_t)(low[selected] & 0xffffffff));
|
||||||
LED_Slot(selected);
|
LED_Slot(selected);
|
||||||
state = 0; // Switch to select mode
|
state = 0; // Switch to select mode
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue