mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
switched to PM3 status/error codes as return codes (if possible/sensible)
This commit is contained in:
parent
2b301b140e
commit
f6e37d868e
2 changed files with 46 additions and 46 deletions
|
@ -802,14 +802,14 @@ static bool login(uint32_t password) {
|
||||||
|
|
||||||
// check if ACK is returned
|
// check if ACK is returned
|
||||||
if (check_ack(false))
|
if (check_ack(false))
|
||||||
return true;
|
return PM3_SUCCESS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (DBGLEVEL >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return PM3_EFAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
@ -822,7 +822,7 @@ static int reset(void) {
|
||||||
|
|
||||||
if (request_receive_mode()) {
|
if (request_receive_mode()) {
|
||||||
|
|
||||||
// send login command
|
// send reset command
|
||||||
em4x50_reader_send_byte_with_parity(EM4X50_COMMAND_RESET);
|
em4x50_reader_send_byte_with_parity(EM4X50_COMMAND_RESET);
|
||||||
|
|
||||||
if (check_ack(false))
|
if (check_ack(false))
|
||||||
|
@ -866,11 +866,12 @@ static int standard_read(int *now, uint32_t *words) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool selective_read(uint32_t addresses, uint32_t *words) {
|
static int selective_read(uint32_t addresses, uint32_t *words) {
|
||||||
|
|
||||||
// reads from "first word read" (fwr) to "last word read" (lwr)
|
// reads from "first word read" (fwr) to "last word read" (lwr)
|
||||||
// result is verified by "standard read mode"
|
// result is verified by "standard read mode"
|
||||||
|
|
||||||
|
int status = PM3_EFAILED;
|
||||||
uint8_t fwr = addresses & 0xFF; // first word read (first byte)
|
uint8_t fwr = addresses & 0xFF; // first word read (first byte)
|
||||||
uint8_t lwr = (addresses >> 8) & 0xFF; // last word read (second byte)
|
uint8_t lwr = (addresses >> 8) & 0xFF; // last word read (second byte)
|
||||||
int now = fwr; // number of words
|
int now = fwr; // number of words
|
||||||
|
@ -887,16 +888,16 @@ static bool selective_read(uint32_t addresses, uint32_t *words) {
|
||||||
if (check_ack(false))
|
if (check_ack(false))
|
||||||
|
|
||||||
// save and verify via standard read mode (compare number of words)
|
// save and verify via standard read mode (compare number of words)
|
||||||
if (standard_read(&now, words) == PM3_SUCCESS)
|
if ((status = standard_read(&now, words)) == PM3_SUCCESS)
|
||||||
if (now == (lwr - fwr + 1))
|
if (now == (lwr - fwr + 1))
|
||||||
return true;
|
return status;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DBGLEVEL >= DBG_DEBUG)
|
if (DBGLEVEL >= DBG_DEBUG)
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void em4x50_info(em4x50_data_t *etd) {
|
void em4x50_info(em4x50_data_t *etd) {
|
||||||
|
@ -915,9 +916,9 @@ void em4x50_info(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// login with given password
|
// login with given password
|
||||||
if (etd->pwd_given)
|
if (etd->pwd_given)
|
||||||
blogin = login(etd->password1);
|
blogin = (login(etd->password1) == PM3_SUCCESS);
|
||||||
|
|
||||||
bsuccess = selective_read(addresses, words);
|
bsuccess = (selective_read(addresses, words) == PM3_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = (bsuccess << 1) + blogin;
|
status = (bsuccess << 1) + blogin;
|
||||||
|
@ -941,11 +942,10 @@ void em4x50_read(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// try to login with given password
|
// try to login with given password
|
||||||
if (etd->pwd_given)
|
if (etd->pwd_given)
|
||||||
blogin = login(etd->password1);
|
blogin = (login(etd->password1) == PM3_SUCCESS);
|
||||||
|
|
||||||
// only one word has to be read -> first word read = last word read
|
// only one word has to be read -> first word read = last word read
|
||||||
bsuccess = selective_read(etd->addresses, words);
|
bsuccess = (selective_read(etd->addresses, words) == PM3_SUCCESS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status = (bsuccess << 1) + blogin;
|
status = (bsuccess << 1) + blogin;
|
||||||
|
@ -961,7 +961,7 @@ void em4x50_read(em4x50_data_t *etd) {
|
||||||
|
|
||||||
static int write(uint32_t word, uint32_t addresses) {
|
static int write(uint32_t word, uint32_t addresses) {
|
||||||
|
|
||||||
// writes <word> to specified <address>
|
// writes <word> to specified <addresses>
|
||||||
|
|
||||||
if (request_receive_mode()) {
|
if (request_receive_mode()) {
|
||||||
|
|
||||||
|
@ -997,7 +997,7 @@ static int write(uint32_t word, uint32_t addresses) {
|
||||||
Dbprintf("error in command request");
|
Dbprintf("error in command request");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return PM3_EFAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_password(uint32_t password, uint32_t new_password) {
|
static int write_password(uint32_t password, uint32_t new_password) {
|
||||||
|
@ -1060,7 +1060,7 @@ void em4x50_write(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// if password is given try to login first
|
// if password is given try to login first
|
||||||
if (etd->pwd_given)
|
if (etd->pwd_given)
|
||||||
blogin = login(etd->password1);
|
blogin = (login(etd->password1) == PM3_SUCCESS);
|
||||||
|
|
||||||
// write word to given address
|
// write word to given address
|
||||||
int res = write(etd->word, etd->addresses);
|
int res = write(etd->word, etd->addresses);
|
||||||
|
@ -1076,10 +1076,10 @@ void em4x50_write(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// if password is given login
|
// if password is given login
|
||||||
if (etd->pwd_given)
|
if (etd->pwd_given)
|
||||||
blogin &= login(etd->password1);
|
blogin &= (login(etd->password1) == PM3_SUCCESS);
|
||||||
|
|
||||||
// call a selective read
|
// call a selective read
|
||||||
if (selective_read(etd->addresses, words)) {
|
if (selective_read(etd->addresses, words) == PM3_SUCCESS) {
|
||||||
|
|
||||||
// compare with given word
|
// compare with given word
|
||||||
bsuccess = (words[etd->addresses & 0xFF] == reflect32(etd->word));
|
bsuccess = (words[etd->addresses & 0xFF] == reflect32(etd->word));
|
||||||
|
@ -1097,7 +1097,7 @@ void em4x50_writepwd(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// simple change of password
|
// simple change of password
|
||||||
|
|
||||||
int res = PM3_ENODATA;
|
int res = PM3_EFAILED;
|
||||||
|
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
|
@ -1105,7 +1105,7 @@ void em4x50_writepwd(em4x50_data_t *etd) {
|
||||||
if (get_signalproperties() && find_em4x50_tag()) {
|
if (get_signalproperties() && find_em4x50_tag()) {
|
||||||
|
|
||||||
// login and change password
|
// login and change password
|
||||||
if (login(etd->password1)) {
|
if (login(etd->password1) == PM3_SUCCESS) {
|
||||||
|
|
||||||
res = write_password(etd->password1, etd->password2);
|
res = write_password(etd->password1, etd->password2);
|
||||||
if (res == PM3_ETEAROFF) {
|
if (res == PM3_ETEAROFF) {
|
||||||
|
@ -1139,7 +1139,7 @@ void em4x50_login(uint32_t *password) {
|
||||||
|
|
||||||
// login into EM4x50
|
// login into EM4x50
|
||||||
|
|
||||||
uint8_t status = false;
|
uint8_t status = PM3_EFAILED;
|
||||||
|
|
||||||
em4x50_setup_read();
|
em4x50_setup_read();
|
||||||
|
|
||||||
|
@ -1160,7 +1160,7 @@ static bool brute(uint32_t start, uint32_t stop, uint32_t *pwd) {
|
||||||
|
|
||||||
for (*pwd = start; *pwd <= stop; (*pwd)++) {
|
for (*pwd = start; *pwd <= stop; (*pwd)++) {
|
||||||
|
|
||||||
if (login(*pwd)) {
|
if (login(*pwd) == PM3_SUCCESS) {
|
||||||
pwd_found = true;
|
pwd_found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1311,7 +1311,7 @@ void em4x50_restore(em4x50_data_t *etd) {
|
||||||
|
|
||||||
// login first if password is available
|
// login first if password is available
|
||||||
if (etd->pwd_given)
|
if (etd->pwd_given)
|
||||||
blogin = login(etd->password1);
|
blogin = (login(etd->password1) == PM3_SUCCESS);
|
||||||
|
|
||||||
// write data to each address but ignore addresses
|
// write data to each address but ignore addresses
|
||||||
// 0 -> password, 32 -> serial, 33 -> uid
|
// 0 -> password, 32 -> serial, 33 -> uid
|
||||||
|
@ -1333,7 +1333,7 @@ void em4x50_restore(em4x50_data_t *etd) {
|
||||||
// login not necessary because protected word has been set to 0
|
// login not necessary because protected word has been set to 0
|
||||||
// -> no read protected words
|
// -> no read protected words
|
||||||
// -> selective read can be called immediately
|
// -> selective read can be called immediately
|
||||||
if (selective_read(addresses, words_read)) {
|
if (selective_read(addresses, words_read) == PM3_SUCCESS) {
|
||||||
|
|
||||||
// check if everything is zero
|
// check if everything is zero
|
||||||
bsuccess = true;
|
bsuccess = true;
|
||||||
|
@ -1427,7 +1427,7 @@ void em4x50_chk(uint32_t *offset) {
|
||||||
|
|
||||||
// check passwords from dictionary content in flash memory
|
// check passwords from dictionary content in flash memory
|
||||||
|
|
||||||
int status = 0;
|
int status = PM3_EFAILED;
|
||||||
uint8_t counter[2] = {0x00, 0x00};
|
uint8_t counter[2] = {0x00, 0x00};
|
||||||
uint16_t isok = 0;
|
uint16_t isok = 0;
|
||||||
uint16_t pwd_count = 0;
|
uint16_t pwd_count = 0;
|
||||||
|
@ -1477,8 +1477,7 @@ void em4x50_chk(uint32_t *offset) {
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
pwd |= (*(pwds + 4 * i + j)) << ((3 - j) * 8);
|
pwd |= (*(pwds + 4 * i + j)) << ((3 - j) * 8);
|
||||||
|
|
||||||
status = login(pwd);
|
if ((status = login(pwd)) == PM3_SUCCESS)
|
||||||
if (status == 1)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,8 +303,11 @@ int CmdEM4x50Info(const char *Cmd) {
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (etd.pwd_given) {
|
|
||||||
bool login = resp.status & STATUS_LOGIN;
|
bool login = resp.status & STATUS_LOGIN;
|
||||||
|
bool success = (resp.status & STATUS_SUCCESS) >> 1;
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
if (etd.pwd_given) {
|
||||||
if (login == false) {
|
if (login == false) {
|
||||||
PrintAndLogEx(FAILED, "Login failed");
|
PrintAndLogEx(FAILED, "Login failed");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
|
@ -312,8 +315,6 @@ int CmdEM4x50Info(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, "Login with password " _YELLOW_("%08x"), etd.password1);
|
PrintAndLogEx(SUCCESS, "Login with password " _YELLOW_("%08x"), etd.password1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = (resp.status & STATUS_SUCCESS) >> 1;
|
|
||||||
if (success) {
|
|
||||||
print_info_result(resp.data.asBytes);
|
print_info_result(resp.data.asBytes);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -419,7 +420,7 @@ int CmdEM4x50WritePwd(const char *Cmd) {
|
||||||
|
|
||||||
// envokes changing the password of EM4x50 tag
|
// envokes changing the password of EM4x50 tag
|
||||||
|
|
||||||
int status = 0;
|
int status = PM3_EFAILED;
|
||||||
int pwdLen = 0, npwdLen = 0;
|
int pwdLen = 0, npwdLen = 0;
|
||||||
uint8_t pwd[4] = {0x0}, npwd[4] = {0x0};
|
uint8_t pwd[4] = {0x0}, npwd[4] = {0x0};
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
|
@ -474,7 +475,7 @@ int CmdEM4x50WritePwd(const char *Cmd) {
|
||||||
// print response
|
// print response
|
||||||
if (status != PM3_SUCCESS) {
|
if (status != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(FAILED, "Writing password " _RED_("failed"));
|
PrintAndLogEx(FAILED, "Writing password " _RED_("failed"));
|
||||||
return PM3_ESOFT;
|
return PM3_EFAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Writing new password " _GREEN_("ok"));
|
PrintAndLogEx(SUCCESS, "Writing new password " _GREEN_("ok"));
|
||||||
|
@ -858,12 +859,12 @@ int CmdEM4x50Login(const char *Cmd) {
|
||||||
WaitForResponse(CMD_LF_EM4X50_LOGIN, &resp);
|
WaitForResponse(CMD_LF_EM4X50_LOGIN, &resp);
|
||||||
|
|
||||||
// print response
|
// print response
|
||||||
if ((bool)resp.status)
|
if (resp.status == PM3_SUCCESS)
|
||||||
PrintAndLogEx(SUCCESS, "Login " _GREEN_("ok"));
|
PrintAndLogEx(SUCCESS, "Login " _GREEN_("ok"));
|
||||||
else
|
else
|
||||||
PrintAndLogEx(FAILED, "Login " _RED_("failed"));
|
PrintAndLogEx(FAILED, "Login " _RED_("failed"));
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return resp.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdEM4x50Reset(const char *Cmd) {
|
int CmdEM4x50Reset(const char *Cmd) {
|
||||||
|
@ -1109,7 +1110,7 @@ int CmdEM4x50Sim(const char *Cmd) {
|
||||||
|
|
||||||
int CmdEM4x50StdRead(const char *Cmd) {
|
int CmdEM4x50StdRead(const char *Cmd) {
|
||||||
|
|
||||||
int now = 0;
|
int now = 0, status = PM3_EFAILED;
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
|
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
|
@ -1160,6 +1161,7 @@ int CmdEM4x50StdRead(const char *Cmd) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = PM3_SUCCESS;
|
||||||
PrintAndLogEx(INFO, "----+-------------+-------------");
|
PrintAndLogEx(INFO, "----+-------------+-------------");
|
||||||
PrintAndLogEx(SUCCESS, "Standard read " _GREEN_("ok"));
|
PrintAndLogEx(SUCCESS, "Standard read " _GREEN_("ok"));
|
||||||
|
|
||||||
|
@ -1167,7 +1169,7 @@ int CmdEM4x50StdRead(const char *Cmd) {
|
||||||
PrintAndLogEx(FAILED, "Standard read " _RED_("failed"));
|
PrintAndLogEx(FAILED, "Standard read " _RED_("failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdEM4x50ELoad(const char *Cmd) {
|
int CmdEM4x50ELoad(const char *Cmd) {
|
||||||
|
@ -1274,7 +1276,7 @@ int CmdEM4x50Chk(const char *Cmd) {
|
||||||
// start password check;
|
// start password check;
|
||||||
// if no filename is given dictionary "t55xx_default_pwds.dic" is used
|
// if no filename is given dictionary "t55xx_default_pwds.dic" is used
|
||||||
|
|
||||||
int status = 0;
|
int status = PM3_EFAILED;
|
||||||
int res = 0, slen = 0;
|
int res = 0, slen = 0;
|
||||||
int keys_remain = 0;
|
int keys_remain = 0;
|
||||||
int block_count = 1;
|
int block_count = 1;
|
||||||
|
@ -1362,13 +1364,12 @@ int CmdEM4x50Chk(const char *Cmd) {
|
||||||
SendCommandNG(CMD_LF_EM4X50_CHK, (uint8_t *)&offset, sizeof(offset));
|
SendCommandNG(CMD_LF_EM4X50_CHK, (uint8_t *)&offset, sizeof(offset));
|
||||||
WaitForResponseTimeoutW(CMD_LF_EM4X50_CHK, &resp, -1, false);
|
WaitForResponseTimeoutW(CMD_LF_EM4X50_CHK, &resp, -1, false);
|
||||||
|
|
||||||
status = resp.status;
|
if ((status = resp.status) == PM3_SUCCESS)
|
||||||
if (status != false)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print response
|
// print response
|
||||||
if (status == 1) {
|
if (status == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(SUCCESS, "Key " _GREEN_("found: %02x %02x %02x %02x"),
|
PrintAndLogEx(SUCCESS, "Key " _GREEN_("found: %02x %02x %02x %02x"),
|
||||||
resp.data.asBytes[3],
|
resp.data.asBytes[3],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue