diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 14029803e..f3e1ebf06 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -907,13 +907,9 @@ void em4x50_info(em4x50_data_t *etd) { void em4x50_read(em4x50_data_t *etd) { - // reads in two different ways: - // - using "selective read mode" -> bidirectional communication - // - using "standard read mode" -> unidirectional communication (read - // data that tag transmits "voluntarily") + // reads by using "selective read mode" -> bidirectional communication bool bsuccess = false, blogin = false; - int now = 0; uint8_t status = 0; uint32_t words[EM4X50_NO_WORDS] = {0x0}; @@ -922,26 +918,16 @@ void em4x50_read(em4x50_data_t *etd) { // set gHigh and gLow if (get_signalproperties() && find_em4x50_tag()) { - if (etd->addr_given) { + // try to login with given password + if (etd->pwd_given) + blogin = login(etd->password1); - // selective read mode + // only one word has to be read -> first word read = last word read + bsuccess = selective_read(etd->addresses, words); - // try to login with given password - if (etd->pwd_given) - blogin = login(etd->password1); - - // only one word has to be read -> first word read = last word read - bsuccess = selective_read(etd->addresses, words); - - } else { - - // standard read mode - bsuccess = standard_read(&now, words); - - } } - status = (now << 2) + (bsuccess << 1) + blogin; + status = (bsuccess << 1) + blogin; LOW(GPIO_SSC_DOUT); lf_finalize(); diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index f1d51efd5..7f889a058 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -321,17 +321,17 @@ bool detect_4x50_block(void) { .addresses = EM4X50_DEVICE_ID, }; em4x50_word_t words[EM4X50_NO_WORDS]; - return (em4x50_read(&etd, words, false) == PM3_SUCCESS); + return (em4x50_read(&etd, words) == PM3_SUCCESS); } int read_em4x50_uid(void) { em4x50_data_t etd = { .pwd_given = false, .addr_given = true, - .addresses = EM4X50_DEVICE_SERIAL, + .addresses = (EM4X50_DEVICE_SERIAL << 8) | EM4X50_DEVICE_SERIAL, }; em4x50_word_t words[EM4X50_NO_WORDS]; - int res = em4x50_read(&etd, words, false); + int res = em4x50_read(&etd, words); if (res == PM3_SUCCESS) PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4)); return res; @@ -543,11 +543,10 @@ int CmdEM4x50WritePassword(const char *Cmd) { return (success) ? PM3_SUCCESS : PM3_ESOFT; } -int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { +int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out) { // envoke reading - // - without option -> standard read mode - // - with given address (option a) (and optional password if address is + // - with given address (option b) (and optional password if address is // read protected) -> selective read mode em4x50_data_t edata = { .pwd_given = false, .addr_given = false }; @@ -566,12 +565,8 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) { } bool isOK = (resp.status & STATUS_SUCCESS) >> 1; - if (isOK == false) { - if (verbose) - PrintAndLogEx(FAILED, "Reading " _RED_("failed")); - + if (isOK == false) return PM3_ESOFT; - } if (edata.pwd_given) { bool login = resp.status & STATUS_LOGIN; @@ -584,21 +579,13 @@ 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->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words); - } else { - prepare_result(data, 0, now - 1, words); - } + prepare_result(data, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words); if (out != NULL) { memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS); } - if (edata.addr_given) - print_result(words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF); - else - print_result(words, 0, now - 1); + print_result(words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF); return PM3_SUCCESS; } @@ -650,11 +637,10 @@ int CmdEM4x50Read(const char *Cmd) { } } - //if (errors || strlen(Cmd) == 0 || etd.addr_given == false) - if (errors) + if (errors || strlen(Cmd) == 0 || etd.addr_given == false) return usage_lf_em4x50_read(); - return em4x50_read(&etd, NULL, true); + return em4x50_read(&etd, NULL); } int CmdEM4x50Dump(const char *Cmd) { diff --git a/client/src/cmdlfem4x50.h b/client/src/cmdlfem4x50.h index 2eaeb8b86..5873e257e 100644 --- a/client/src/cmdlfem4x50.h +++ b/client/src/cmdlfem4x50.h @@ -16,7 +16,7 @@ int read_em4x50_uid(void); bool detect_4x50_block(void); -int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose); +int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out); int CmdEM4x50Info(const char *Cmd); int CmdEM4x50Write(const char *Cmd); diff --git a/client/src/scripting.c b/client/src/scripting.c index 3ed82591a..f594bd3aa 100644 --- a/client/src/scripting.c +++ b/client/src/scripting.c @@ -1171,7 +1171,7 @@ static int l_em4x50_read(lua_State *L) { em4x50_word_t words[EM4X50_NO_WORDS]; - int res = em4x50_read(&etd, words, false); + int res = em4x50_read(&etd, words); if (res != PM3_SUCCESS) { return returnToLuaWithError(L, "Failed to read EM4x50 data"); }