mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
Adaptation of the implementation of read function to that currently used in master branch
This commit is contained in:
parent
ce5181bdc9
commit
140037d9f0
4 changed files with 19 additions and 47 deletions
|
@ -907,13 +907,9 @@ void em4x50_info(em4x50_data_t *etd) {
|
||||||
|
|
||||||
void em4x50_read(em4x50_data_t *etd) {
|
void em4x50_read(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// reads in two different ways:
|
// reads by using "selective read mode" -> bidirectional communication
|
||||||
// - using "selective read mode" -> bidirectional communication
|
|
||||||
// - using "standard read mode" -> unidirectional communication (read
|
|
||||||
// data that tag transmits "voluntarily")
|
|
||||||
|
|
||||||
bool bsuccess = false, blogin = false;
|
bool bsuccess = false, blogin = false;
|
||||||
int now = 0;
|
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
uint32_t words[EM4X50_NO_WORDS] = {0x0};
|
uint32_t words[EM4X50_NO_WORDS] = {0x0};
|
||||||
|
|
||||||
|
@ -922,26 +918,16 @@ void em4x50_read(em4x50_data_t *etd) {
|
||||||
// set gHigh and gLow
|
// set gHigh and gLow
|
||||||
if (get_signalproperties() && find_em4x50_tag()) {
|
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);
|
LOW(GPIO_SSC_DOUT);
|
||||||
lf_finalize();
|
lf_finalize();
|
||||||
|
|
|
@ -321,17 +321,17 @@ bool detect_4x50_block(void) {
|
||||||
.addresses = EM4X50_DEVICE_ID,
|
.addresses = EM4X50_DEVICE_ID,
|
||||||
};
|
};
|
||||||
em4x50_word_t words[EM4X50_NO_WORDS];
|
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) {
|
int read_em4x50_uid(void) {
|
||||||
em4x50_data_t etd = {
|
em4x50_data_t etd = {
|
||||||
.pwd_given = false,
|
.pwd_given = false,
|
||||||
.addr_given = true,
|
.addr_given = true,
|
||||||
.addresses = EM4X50_DEVICE_SERIAL,
|
.addresses = (EM4X50_DEVICE_SERIAL << 8) | EM4X50_DEVICE_SERIAL,
|
||||||
};
|
};
|
||||||
em4x50_word_t words[EM4X50_NO_WORDS];
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||||
int res = em4x50_read(&etd, words, false);
|
int res = em4x50_read(&etd, words);
|
||||||
if (res == PM3_SUCCESS)
|
if (res == PM3_SUCCESS)
|
||||||
PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4));
|
PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4));
|
||||||
return res;
|
return res;
|
||||||
|
@ -543,11 +543,10 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
||||||
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
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
|
// envoke reading
|
||||||
// - without option -> standard read mode
|
// - with given address (option b) (and optional password if address is
|
||||||
// - with given address (option a) (and optional password if address is
|
|
||||||
// read protected) -> selective read mode
|
// read protected) -> selective read mode
|
||||||
|
|
||||||
em4x50_data_t edata = { .pwd_given = false, .addr_given = false };
|
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;
|
bool isOK = (resp.status & STATUS_SUCCESS) >> 1;
|
||||||
if (isOK == false) {
|
if (isOK == false)
|
||||||
if (verbose)
|
|
||||||
PrintAndLogEx(FAILED, "Reading " _RED_("failed"));
|
|
||||||
|
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
|
||||||
|
|
||||||
if (edata.pwd_given) {
|
if (edata.pwd_given) {
|
||||||
bool login = resp.status & STATUS_LOGIN;
|
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;
|
uint8_t *data = resp.data.asBytes;
|
||||||
em4x50_word_t words[EM4X50_NO_WORDS];
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||||
int now = (resp.status & STATUS_NO_WORDS) >> 2;
|
prepare_result(data, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
|
||||||
if (edata.addr_given) {
|
|
||||||
prepare_result(data, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
|
|
||||||
} else {
|
|
||||||
prepare_result(data, 0, now - 1, words);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
|
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edata.addr_given)
|
print_result(words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF);
|
||||||
print_result(words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF);
|
|
||||||
else
|
|
||||||
print_result(words, 0, now - 1);
|
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -650,11 +637,10 @@ int CmdEM4x50Read(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
||||||
if (errors)
|
|
||||||
return usage_lf_em4x50_read();
|
return usage_lf_em4x50_read();
|
||||||
|
|
||||||
return em4x50_read(&etd, NULL, true);
|
return em4x50_read(&etd, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdEM4x50Dump(const char *Cmd) {
|
int CmdEM4x50Dump(const char *Cmd) {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
int read_em4x50_uid(void);
|
int read_em4x50_uid(void);
|
||||||
bool detect_4x50_block(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 CmdEM4x50Info(const char *Cmd);
|
||||||
int CmdEM4x50Write(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];
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
||||||
|
|
||||||
int res = em4x50_read(&etd, words, false);
|
int res = em4x50_read(&etd, words);
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
return returnToLuaWithError(L, "Failed to read EM4x50 data");
|
return returnToLuaWithError(L, "Failed to read EM4x50 data");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue