mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 15:26:13 +08:00
Adaptation of the implementation of read function to that currently used in master branch
This commit is contained in:
parent
ce5181bdc9
commit
140037d9f0
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue