added function reset

This commit is contained in:
tharexde 2020-09-27 23:39:04 +02:00
commit c20ab4ca20
7 changed files with 101 additions and 29 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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 */

View file

@ -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}
};

View file

@ -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;
}

View file

@ -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

View file

@ -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