From c20ab4ca206dad9dcc9583865087491aed3168fc Mon Sep 17 00:00:00 2001 From: tharexde Date: Sun, 27 Sep 2020 23:39:04 +0200 Subject: [PATCH] added function reset --- armsrc/appmain.c | 4 +++ armsrc/em4x50.c | 76 +++++++++++++++++++++++++--------------- armsrc/em4x50.h | 1 + client/src/cmdlfem4x.c | 1 + client/src/cmdlfem4x50.c | 46 ++++++++++++++++++++++++ client/src/cmdlfem4x50.h | 1 + include/pm3_cmd.h | 1 + 7 files changed, 101 insertions(+), 29 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 2ba931a01..bf8b1e782 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1045,6 +1045,10 @@ static void PacketReceived(PacketCommandNG *packet) { em4x50_login((em4x50_data_t *)packet->data.asBytes); break; } + case CMD_LF_EM4X50_RESET: { + em4x50_reset(); + break; + } #endif #ifdef WITH_ISO15693 diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 95769e98b..bba99e92d 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -1100,35 +1100,6 @@ void em4x50_wipe(em4x50_data_t *etd) { reply_ng(CMD_ACK, bsuccess, (uint8_t *)tag.sectors, 238); } -int em4x50_standalone_read(uint64_t *words) { - - int now = 0; - uint8_t bits[EM4X50_TAG_WORD]; - - em4x50_setup_read(); - - if (get_signalproperties() && find_em4x50_tag()) { - - if (find_double_listen_window(false)) { - - memset(bits, 0, sizeof(bits)); - - while (get_word_from_bitstream(bits) == EM4X50_TAG_WORD) { - words[now] = 0; - - for (int i = 0; i < EM4X50_TAG_WORD; i++) { - words[now] <<= 1; - words[now] += bits[i] & 1; - } - - now++; - } - } - } - - return now; -} - void em4x50_brute(em4x50_data_t *etd) { // searching for password in given range @@ -1211,3 +1182,50 @@ void em4x50_login(em4x50_data_t *etd) { lf_finalize(); reply_ng(CMD_ACK, status, 0, 0); } + +void em4x50_reset(void) { + + // reset EM4x50 + + uint8_t status = 0; + + em4x50_setup_read(); + + // set gHigh and gLow + if (get_signalproperties() && find_em4x50_tag()) { + + status = reset(); + } + + lf_finalize(); + reply_ng(CMD_ACK, status, 0, 0); +} + +int em4x50_standalone_read(uint64_t *words) { + + int now = 0; + uint8_t bits[EM4X50_TAG_WORD]; + + em4x50_setup_read(); + + if (get_signalproperties() && find_em4x50_tag()) { + + if (find_double_listen_window(false)) { + + memset(bits, 0, sizeof(bits)); + + while (get_word_from_bitstream(bits) == EM4X50_TAG_WORD) { + words[now] = 0; + + for (int i = 0; i < EM4X50_TAG_WORD; i++) { + words[now] <<= 1; + words[now] += bits[i] & 1; + } + + now++; + } + } + } + + return now; +} diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index 5c3648a39..35452021d 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -28,5 +28,6 @@ void em4x50_read(em4x50_data_t *etd); void em4x50_wipe(em4x50_data_t *etd); void em4x50_brute(em4x50_data_t *etd); void em4x50_login(em4x50_data_t *etd); +void em4x50_reset(void); #endif /* EM4X50_H */ diff --git a/client/src/cmdlfem4x.c b/client/src/cmdlfem4x.c index 16a408956..52ce472e5 100644 --- a/client/src/cmdlfem4x.c +++ b/client/src/cmdlfem4x.c @@ -1400,6 +1400,7 @@ static command_t CommandTable[] = { {"4x50_wipe", CmdEM4x50Wipe, IfPm3EM4x50, "wipe data from EM4x50"}, {"4x50_brute", CmdEM4x50Brute, IfPm3EM4x50, "guess password of EM4x50"}, {"4x50_login", CmdEM4x50Login, IfPm3EM4x50, "login into EM4x50"}, + {"4x50_reset", CmdEM4x50Reset, IfPm3EM4x50, "reset EM4x50"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 4c1dbad67..2b73aa2a1 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -122,6 +122,17 @@ static int usage_lf_em4x50_login(void) { PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } +static int usage_lf_em4x50_reset(void) { + PrintAndLogEx(NORMAL, "Reset EM4x50 tag. Tag must be on antenna. "); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: lf em 4x50_reset [h]"); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h - this help"); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_reset")); + PrintAndLogEx(NORMAL, ""); + return PM3_SUCCESS; +} static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t *words) { @@ -869,3 +880,38 @@ int CmdEM4x50Login(const char *Cmd) { return PM3_SUCCESS; } + +int CmdEM4x50Reset(const char *Cmd) { + + bool errors = false; + uint8_t cmdp = 0; + PacketResponseNG resp; + + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_lf_em4x50_reset(); + default: + PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; + } + } + + if (errors) + return usage_lf_em4x50_reset(); + + // start + clearCommandBuffer(); + SendCommandNG(CMD_LF_EM4X50_RESET, 0, 0); + WaitForResponse(CMD_ACK, &resp); + + // print response + if ((bool)resp.status) + PrintAndLogEx(NORMAL, "\nreset " _GREEN_("ok") "\n"); + else + PrintAndLogEx(NORMAL, "\nreset " _RED_("failed") "\n"); + + return PM3_SUCCESS; +} diff --git a/client/src/cmdlfem4x50.h b/client/src/cmdlfem4x50.h index dbf94c660..6462810d0 100644 --- a/client/src/cmdlfem4x50.h +++ b/client/src/cmdlfem4x50.h @@ -26,5 +26,6 @@ int CmdEM4x50Dump(const char *Cmd); int CmdEM4x50Wipe(const char *Cmd); int CmdEM4x50Brute(const char *Cmd); int CmdEM4x50Login(const char *Cmd); +int CmdEM4x50Reset(const char *Cmd); #endif diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 8060a3998..08207306c 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -495,6 +495,7 @@ typedef struct { #define CMD_LF_EM4X50_WIPE 0x0244 #define CMD_LF_EM4X50_BRUTE 0x0245 #define CMD_LF_EM4X50_LOGIN 0x0246 +#define CMD_LF_EM4X50_RESET 0x0247 // Sampling configuration for LF reader/sniffer #define CMD_LF_SAMPLING_SET_CONFIG 0x021D #define CMD_LF_FSK_SIMULATE 0x021E