mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2026-05-12 11:18:11 -07:00
Merge branch 'dev_standalone' into malsehn_standalone
This commit is contained in:
@@ -35,6 +35,9 @@ define KNOWN_STANDALONE_DEFINITIONS
|
||||
| LF_SAMYRUN | HID26 read/clone/sim |
|
||||
| | - Samy Kamkar |
|
||||
+----------------------------------------------------------+
|
||||
| LF_THAREXDE | read and sim em4x50 tags |
|
||||
| (RDV4 only) | |
|
||||
+----------------------------------------------------------+
|
||||
| HF_14ASNIFF | 14a sniff to flashmem |
|
||||
| (RDV4 only) | |
|
||||
+----------------------------------------------------------+
|
||||
@@ -64,10 +67,10 @@ define KNOWN_STANDALONE_DEFINITIONS
|
||||
+----------------------------------------------------------+
|
||||
endef
|
||||
|
||||
STANDALONE_MODES := LF_SKELETON LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RWC LF_HIDBRUTE LF_ICEHID LF_PROXBRUTE LF_SAMYRUN
|
||||
STANDALONE_MODES += HF_14ASNIFF HF_AVEFUL HF_BOG HF_COLIN HF_ICECLASS HF_LEGIC HF_MATTYRUN HF_MSDSAL HF_YOUNG
|
||||
STANDALONE_MODES := LF_SKELETON LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RWC LF_HIDBRUTE LF_ICEHID LF_PROXBRUTE LF_SAMYRUN LF_THAREXDE
|
||||
STANDALONE_MODES += HF_14ASNIFF HF_BOG HF_COLIN HF_LEGIC HF_MATTYRUN HF_MSDSAL HF_YOUNG
|
||||
STANDALONE_MODES_REQ_SMARTCARD :=
|
||||
STANDALONE_MODES_REQ_FLASH := LF_ICEHID HF_14ASNIFF HF_BOG HF_COLIN HF_ICECLASS
|
||||
STANDALONE_MODES_REQ_FLASH := LF_THAREXDE LF_ICEHID HF_14ASNIFF HF_BOG HF_COLIN
|
||||
ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES)),)
|
||||
STANDALONE_PLATFORM_DEFS += -DWITH_STANDALONE_$(STANDALONE)
|
||||
ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES_REQ_SMARTCARD)),)
|
||||
|
||||
@@ -69,3 +69,7 @@ endif
|
||||
ifneq (,$(findstring WITH_STANDALONE_HF_ICECLASS,$(APP_CFLAGS)))
|
||||
SRC_STANDALONE = hf_iceclass.c
|
||||
endif
|
||||
# WITH_STANDALONE_LF_THAREXDE
|
||||
ifneq (,$(findstring WITH_STANDALONE_LF_THAREXDE,$(APP_CFLAGS)))
|
||||
SRC_STANDALONE = lf_tharexde.c
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Tharexde, 2020
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// main code for EM4x50 simulator and collector aka THAREXDE
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <inttypes.h>
|
||||
#include "standalone.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "appmain.h"
|
||||
#include "BigBuf.h"
|
||||
#include "fpgaloader.h"
|
||||
#include "util.h"
|
||||
#include "dbprint.h"
|
||||
#include "spiffs.h"
|
||||
#include "../em4x50.h"
|
||||
|
||||
/*
|
||||
* `lf_tharexde` simulates hardcoded words/blocks, reads words of standard read
|
||||
* mode of EM4x50 tags and stores them in internal flash.
|
||||
* It requires RDV4 hardware (for flash and battery).
|
||||
*
|
||||
* On entering stand-alone mode, this module will start reading/record EM4x50 data.
|
||||
* Every found / collected data will be written/appended to the logfile in flash
|
||||
* as a text string.
|
||||
*
|
||||
* LEDs:
|
||||
* - LED A: simulating
|
||||
* - LED B: reading / record
|
||||
* - LED C: writing to flash
|
||||
* - LED D: unmounting/sync'ing flash (normally < 100ms)
|
||||
*
|
||||
* To retrieve log file from flash:
|
||||
*
|
||||
* 1. mem spiffs dump o lf_em4x50collect.log f lf_em4x50collect.log
|
||||
* Copies log file from flash to your client.
|
||||
*
|
||||
* 2. exit the Proxmark3 client
|
||||
*
|
||||
* 3. more lf_tharexdecollect.log
|
||||
*
|
||||
* This module emits debug strings during normal operation -- so try it out in
|
||||
* the lab connected to PM3 client before taking it into the field.
|
||||
*
|
||||
* To delete the log file from flash:
|
||||
*
|
||||
* 1. mem spiffs remove lf_tharexdecollect.log
|
||||
*/
|
||||
|
||||
#define STATE_SIM 0
|
||||
#define STATE_READ 1
|
||||
#define LF_EM4X50SIMULATE_INPUTFILE "lf_em4x50simulate.eml"
|
||||
#define LF_EM4X50COLLECT_LOGFILE "lf_em4x50collect.log"
|
||||
#define EM4X50_TAG_WORD 45
|
||||
|
||||
bool input_exists;
|
||||
bool log_exists;
|
||||
|
||||
static void LoadDataInstructions(void) {
|
||||
Dbprintf("");
|
||||
Dbprintf("[=] To load datafile into flash and display it:");
|
||||
Dbprintf("[=] " _YELLOW_("1.") " edit inputfile "LF_EM4X50SIMULATE_INPUTFILE);
|
||||
Dbprintf("[=] " _YELLOW_("2.") " start proxmark3 client");
|
||||
Dbprintf("[=] " _YELLOW_("3.") " mem spiffs load f "LF_EM4X50SIMULATE_INPUTFILE" o "LF_EM4X50SIMULATE_INPUTFILE);
|
||||
Dbprintf("[=] " _YELLOW_("4.") " start standalone mode");
|
||||
}
|
||||
|
||||
static void DownloadLogInstructions(void) {
|
||||
Dbprintf("");
|
||||
Dbprintf("[=] To get the logfile from flash and display it:");
|
||||
Dbprintf("[=] " _YELLOW_("1.") " mem spiffs dump o "LF_EM4X50COLLECT_LOGFILE" f "LF_EM4X50COLLECT_LOGFILE);
|
||||
Dbprintf("[=] " _YELLOW_("2.") " exit proxmark3 client");
|
||||
Dbprintf("[=] " _YELLOW_("3.") " cat "LF_EM4X50COLLECT_LOGFILE);
|
||||
}
|
||||
|
||||
static bool strip_check_parities(uint64_t data, uint32_t *word) {
|
||||
|
||||
uint8_t rparity = 0, cparity = 0;
|
||||
uint8_t rparity_m = 0, cparity_m = 0, stop_bit_m = 0;
|
||||
|
||||
// strip parities
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
*word <<= 1;
|
||||
*word += (data >> (EM4X50_TAG_WORD - 1 - 9 * i - j)) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate row parities
|
||||
for (int i = 0; i < 4; i++) {
|
||||
rparity <<= 1;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
rparity ^= (*word >> (31 - 8 * i - j)) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate column parities
|
||||
for (int i = 0; i < 8; i++) {
|
||||
cparity <<= 1;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
cparity ^= (*word >> (31 - 8 * j - i)) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
// measured row parities
|
||||
for (int i = 0; i < 4; i++) {
|
||||
rparity_m <<= 1;
|
||||
rparity_m += (data >> (EM4X50_TAG_WORD - 9 * (i + 1))) & 1;
|
||||
}
|
||||
|
||||
// measured column parities
|
||||
cparity_m = (data >> 1) & 0xFF;
|
||||
|
||||
// measured stop bit
|
||||
stop_bit_m = data & 1;
|
||||
|
||||
if ((cparity_m == cparity) && (rparity_m == rparity) && (stop_bit_m == 0))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int get_input_data_from_file(uint32_t *words) {
|
||||
|
||||
size_t now = 0;
|
||||
|
||||
if (exists_in_spiffs(LF_EM4X50SIMULATE_INPUTFILE)) {
|
||||
|
||||
uint32_t size = size_in_spiffs((char *)LF_EM4X50SIMULATE_INPUTFILE);
|
||||
uint8_t *mem = BigBuf_malloc(size);
|
||||
|
||||
Dbprintf(_YELLOW_("[=] found input file %s"), LF_EM4X50SIMULATE_INPUTFILE);
|
||||
|
||||
rdv40_spiffs_read_as_filetype((char *)LF_EM4X50SIMULATE_INPUTFILE, mem, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
|
||||
now = size / 9;
|
||||
for (int i = 0; i < now; i++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
words[i] |= (hex2int(mem[2 * j + 9 * i]) << 4 | hex2int(mem[2 * j + 1 + 9 * i])) << ((3 - j) * 8);
|
||||
|
||||
Dbprintf(_YELLOW_("[=] read data from input file"));
|
||||
}
|
||||
|
||||
BigBuf_free();
|
||||
|
||||
return (now > 0) ? now : 0;
|
||||
}
|
||||
|
||||
static void append(uint8_t *entry, size_t entry_len) {
|
||||
|
||||
LED_C_ON();
|
||||
if (log_exists == false) {
|
||||
rdv40_spiffs_write(LF_EM4X50COLLECT_LOGFILE, entry, entry_len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
log_exists = true;
|
||||
} else {
|
||||
rdv40_spiffs_append(LF_EM4X50COLLECT_LOGFILE, entry, entry_len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
}
|
||||
LED_C_OFF();
|
||||
}
|
||||
|
||||
void ModInfo(void) {
|
||||
DbpString(_YELLOW_(" LF EM4x50 collector mode") " - a.k.a tharexde");
|
||||
}
|
||||
|
||||
void RunMod(void) {
|
||||
|
||||
bool state_change = true;
|
||||
uint8_t state = STATE_SIM;
|
||||
// declarations for simulating
|
||||
uint32_t words[33] = {0x0};
|
||||
size_t now = 0;
|
||||
// declarations for reading
|
||||
int no_words = 0;
|
||||
uint64_t data[EM4X50_TAG_WORD];
|
||||
uint32_t word = 0;
|
||||
uint8_t entry[81];
|
||||
|
||||
rdv40_spiffs_lazy_mount();
|
||||
|
||||
StandAloneMode();
|
||||
Dbprintf(_YELLOW_("[=] Standalone mode THAREXDE started"));
|
||||
|
||||
for (;;) {
|
||||
|
||||
WDT_HIT();
|
||||
if (data_available()) break;
|
||||
|
||||
// press button - toggle between SIM and READ
|
||||
// hold button - exit
|
||||
int button_pressed = BUTTON_CLICKED(1000);
|
||||
if (button_pressed == BUTTON_SINGLE_CLICK) {
|
||||
|
||||
SpinUp(100);
|
||||
state = (state == STATE_SIM) ? STATE_READ : STATE_SIM;
|
||||
state_change = true;
|
||||
|
||||
} else if (button_pressed == BUTTON_HOLD) {
|
||||
|
||||
SpinDown(100);
|
||||
break;
|
||||
}
|
||||
|
||||
if (state == STATE_SIM) {
|
||||
|
||||
if (state_change) {
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT);
|
||||
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125);
|
||||
|
||||
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
|
||||
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
|
||||
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
|
||||
|
||||
LED_A_ON();
|
||||
LED_B_OFF();
|
||||
Dbprintf(_YELLOW_("[=] switched to EM4x50 simulating mode"));
|
||||
|
||||
now = get_input_data_from_file(words);
|
||||
if (now > 0) {
|
||||
Dbprintf(_YELLOW_("[=] simulating %i blocks"), now);
|
||||
for (int i = 0; i < now; i++)
|
||||
Dbprintf(_YELLOW_("[=] %2i -> %lx"), i + 1, words[i]);
|
||||
|
||||
} else {
|
||||
Dbprintf(_RED_("[!] error in input data"));
|
||||
}
|
||||
|
||||
state_change = false;
|
||||
}
|
||||
|
||||
em4x50_sim_send_listen_window2();
|
||||
for (int i = 0; i < now; i++) {
|
||||
em4x50_sim_send_listen_window2();
|
||||
em4x50_sim_send_word3(words[i]);
|
||||
}
|
||||
|
||||
} else if (state == STATE_READ) {
|
||||
|
||||
if (state_change) {
|
||||
|
||||
LED_B_ON();
|
||||
LED_A_OFF();
|
||||
Dbprintf(_YELLOW_("[=] switched to EM4x50 reading mode"));
|
||||
|
||||
memset(entry, 0, sizeof(entry));
|
||||
memset(data, 0, sizeof(data));
|
||||
|
||||
log_exists = exists_in_spiffs(LF_EM4X50COLLECT_LOGFILE);
|
||||
|
||||
state_change = false;
|
||||
}
|
||||
|
||||
no_words = em4x50_standalone_read(data);
|
||||
|
||||
if (no_words > 0) {
|
||||
|
||||
memset(entry, 0, sizeof(entry));
|
||||
|
||||
sprintf((char *)entry, "found new EM4x50 tag:");
|
||||
Dbprintf("%s", entry);
|
||||
strcat((char *)entry, "\n");
|
||||
append(entry, strlen((char *)entry));
|
||||
|
||||
for (int i = 0; i < no_words; i++) {
|
||||
|
||||
if (strip_check_parities(data[i], &word))
|
||||
sprintf((char *)entry, " %2i -> 0x%08"PRIx32" (parity check ok)", i + 1, word);
|
||||
else
|
||||
sprintf((char *)entry, " %2i -> 0x%08"PRIx32" (parity check failed)", i + 1, word);
|
||||
|
||||
Dbprintf("%s", entry);
|
||||
strcat((char *)entry, "\n");
|
||||
append(entry, strlen((char *)entry));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (state == STATE_READ)
|
||||
DownloadLogInstructions();
|
||||
else
|
||||
LoadDataInstructions();
|
||||
|
||||
LED_D_ON();
|
||||
rdv40_spiffs_lazy_unmount();
|
||||
LED_D_OFF();
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LEDsoff();
|
||||
Dbprintf(_YELLOW_("[=] Standalone mode THAREXDE stopped"));
|
||||
|
||||
}
|
||||
@@ -1037,6 +1037,14 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
em4x50_wipe((em4x50_data_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_EM4X50_SIM: {
|
||||
em4x50_sim((em4x50_data_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_LF_EM4X50_TEST: {
|
||||
em4x50_test((em4x50_data_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_ISO15693
|
||||
|
||||
+498
-46
File diff suppressed because it is too large
Load Diff
@@ -17,10 +17,16 @@ typedef struct {
|
||||
uint8_t sectors[34][7];
|
||||
} em4x50_tag_t;
|
||||
|
||||
int em4x50_standalone_read(uint64_t *words);
|
||||
bool em4x50_sim_send_listen_window2(void);
|
||||
bool em4x50_sim_send_word3(uint32_t word);
|
||||
|
||||
void em4x50_info(em4x50_data_t *etd);
|
||||
void em4x50_write(em4x50_data_t *etd);
|
||||
void em4x50_write_password(em4x50_data_t *etd);
|
||||
void em4x50_read(em4x50_data_t *etd);
|
||||
void em4x50_wipe(em4x50_data_t *etd);
|
||||
void em4x50_sim(em4x50_data_t *etd);
|
||||
void em4x50_test(em4x50_data_t *etd);
|
||||
|
||||
#endif /* EM4X50_H */
|
||||
|
||||
@@ -31,6 +31,7 @@ void lf_wait_periods(size_t periods);
|
||||
void lf_init(bool reader, bool simulate);
|
||||
void lf_finalize(void);
|
||||
size_t lf_detect_field_drop(size_t max);
|
||||
|
||||
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len);
|
||||
void lf_modulation(bool modulation);
|
||||
|
||||
|
||||
@@ -1398,6 +1398,8 @@ static command_t CommandTable[] = {
|
||||
{"4x50_write_password", CmdEM4x50WritePassword, IfPm3EM4x50, "change passwword of EM4x50 tag"},
|
||||
{"4x50_read", CmdEM4x50Read, IfPm3EM4x50, "read word data from EM4x50"},
|
||||
{"4x50_wipe", CmdEM4x50Wipe, IfPm3EM4x50, "wipe data from EM4x50"},
|
||||
{"4x50_sim", CmdEM4x50Sim, IfPm3EM4x50, "simulate EM4x50 tag"},
|
||||
{"4x50_test", CmdEM4x50Test, IfPm3EM4x50, "test functionality for EM4x50"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
+164
-5
@@ -93,7 +93,32 @@ static int usage_lf_em4x50_wipe(void) {
|
||||
PrintAndLogEx(NORMAL, " h - this help");
|
||||
PrintAndLogEx(NORMAL, " p <pwd> - password (hex)");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_wwipe p 11223344"));
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_wipe p 11223344"));
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
static int usage_lf_em4x50_sim(void) {
|
||||
PrintAndLogEx(NORMAL, "Simulate EM4x50 tag. ");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_sim [h] w <word>");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h - this help");
|
||||
PrintAndLogEx(NORMAL, " w <word> - word (hex)");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_sim w 12345678"));
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
static int usage_lf_em4x50_test(void) {
|
||||
PrintAndLogEx(NORMAL, "Test functionality for EM4x50 tag. ");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_test [h] ...");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h - this help");
|
||||
PrintAndLogEx(NORMAL, " c <0|1> - carrier on|off (optional)");
|
||||
PrintAndLogEx(NORMAL, " b <byte> - byte (hex) (optional)");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_test ..."));
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -539,10 +564,10 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) {
|
||||
|
||||
uint8_t *data = resp.data.asBytes;
|
||||
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||
int now = (resp.status & STATUS_NO_WORDS) >> 2;
|
||||
if (edata.addr_given) {
|
||||
prepare_result(data, etd->address, etd->address, words);
|
||||
} else {
|
||||
int now = (resp.status & STATUS_NO_WORDS) >> 2;
|
||||
prepare_result(data, 0, now - 1, words);
|
||||
}
|
||||
|
||||
@@ -550,7 +575,11 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) {
|
||||
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
|
||||
}
|
||||
|
||||
print_result(words, etd->address, etd->address);
|
||||
if (edata.addr_given)
|
||||
print_result(words, etd->address, etd->address);
|
||||
else
|
||||
print_result(words, 0, now - 1);
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -598,8 +627,9 @@ int CmdEM4x50Read(const char *Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
||||
return usage_lf_em4x50_read();
|
||||
//if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
||||
if (errors)
|
||||
return usage_lf_em4x50_read();
|
||||
|
||||
return em4x50_read(&etd, NULL, true);
|
||||
}
|
||||
@@ -740,3 +770,132 @@ int CmdEM4x50Wipe(const char *Cmd) {
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int CmdEM4x50Sim(const char *Cmd) {
|
||||
|
||||
// fills EM4x50 tag with zeros including password
|
||||
|
||||
bool errors = false, bword = false;
|
||||
uint8_t cmdp = 0;
|
||||
em4x50_data_t etd;
|
||||
PacketResponseNG resp;
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
return usage_lf_em4x50_sim();
|
||||
|
||||
case 'w': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bword = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'f': {
|
||||
if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) {
|
||||
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
bword = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "\nUnknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (errors || !bword)
|
||||
return usage_lf_em4x50_sim();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_SIM, (uint8_t *)&etd, sizeof(etd));
|
||||
|
||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
||||
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.\n");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// print response
|
||||
bool isOK = resp.status;
|
||||
if (isOK) {
|
||||
PrintAndLogEx(SUCCESS,"\nsimulation data " _GREEN_("ok") "\n");
|
||||
} else {
|
||||
PrintAndLogEx(FAILED,"\nsimulating data " _RED_("failed") "\n");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int CmdEM4x50Test(const char *Cmd) {
|
||||
|
||||
// fills EM4x50 tag with zeros including password
|
||||
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
em4x50_data_t etd;
|
||||
PacketResponseNG resp;
|
||||
|
||||
etd.carrier = 2;
|
||||
|
||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
|
||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||
case 'h':
|
||||
return usage_lf_em4x50_test();
|
||||
|
||||
case 'c':
|
||||
param_getdec(Cmd, cmdp + 1, &etd.carrier);
|
||||
if (etd.carrier != 0 && etd.carrier != 1) {
|
||||
PrintAndLogEx(FAILED, "\ncarrier has to be either 0 or 1\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
if (param_gethex(Cmd, cmdp + 1, &etd.byte, 2)) {
|
||||
PrintAndLogEx(FAILED, "\nbyte has to be 2 hex symbols\n");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
cmdp += 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
PrintAndLogEx(WARNING, "\nUnknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (errors)
|
||||
return usage_lf_em4x50_test();
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X50_TEST, (uint8_t *)&etd, sizeof(etd));
|
||||
|
||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
||||
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.\n");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
// print response
|
||||
bool isOK = resp.status;
|
||||
if (isOK) {
|
||||
PrintAndLogEx(SUCCESS,"\ntest " _GREEN_("ok") "\n");
|
||||
} else {
|
||||
PrintAndLogEx(FAILED,"\ntest " _RED_("failed") "\n");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -24,5 +24,7 @@ int CmdEM4x50WritePassword(const char *Cmd);
|
||||
int CmdEM4x50Read(const char *Cmd);
|
||||
int CmdEM4x50Dump(const char *Cmd);
|
||||
int CmdEM4x50Wipe(const char *Cmd);
|
||||
int CmdEM4x50Sim(const char *Cmd);
|
||||
int CmdEM4x50Test(const char *Cmd);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,8 @@ typedef struct {
|
||||
bool addr_given;
|
||||
bool pwd_given;
|
||||
bool newpwd_given;
|
||||
uint8_t carrier;
|
||||
uint8_t byte;
|
||||
uint8_t password[4];
|
||||
uint8_t new_password[4];
|
||||
uint8_t addresses[4];
|
||||
|
||||
@@ -493,6 +493,8 @@ typedef struct {
|
||||
#define CMD_LF_EM4X50_WRITE_PASSWORD 0x0242
|
||||
#define CMD_LF_EM4X50_READ 0x0243
|
||||
#define CMD_LF_EM4X50_WIPE 0x0244
|
||||
#define CMD_LF_EM4X50_SIM 0x0245
|
||||
#define CMD_LF_EM4X50_TEST 0x0246
|
||||
// Sampling configuration for LF reader/sniffer
|
||||
#define CMD_LF_SAMPLING_SET_CONFIG 0x021D
|
||||
#define CMD_LF_FSK_SIMULATE 0x021E
|
||||
|
||||
Reference in New Issue
Block a user