mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
refactor: Merge enum hitag_function. read/write has already been differentiated by command
This commit is contained in:
parent
495759d6bd
commit
8b7f34b4d9
7 changed files with 61 additions and 67 deletions
|
@ -1153,7 +1153,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
|
||||
|
||||
switch (payload->cmd) {
|
||||
case RHT2F_UID_ONLY: {
|
||||
case HT2F_UID_ONLY: {
|
||||
ht2_read_uid(NULL, true, true, false);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1666,14 +1666,14 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
|
||||
// Check configuration
|
||||
switch (payload->cmd) {
|
||||
case RHT1F_PLAIN: {
|
||||
case HT1F_PLAIN: {
|
||||
DBG Dbprintf("Read public blocks in plain mode");
|
||||
// this part will be unreadable
|
||||
memset(tag.sectors + 2, 0x0, 30);
|
||||
blocknr = 0;
|
||||
break;
|
||||
}
|
||||
case RHT1F_AUTHENTICATE: {
|
||||
case HT1F_AUTHENTICATE: {
|
||||
DBG Dbprintf("Read all blocks in authed mode");
|
||||
|
||||
memcpy(nonce, payload->nonce, 4);
|
||||
|
@ -1699,7 +1699,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
blocknr = 0;
|
||||
break;
|
||||
}
|
||||
case RHT2F_PASSWORD: {
|
||||
case HT2F_PASSWORD: {
|
||||
DBG Dbprintf("List identifier in password mode");
|
||||
if (memcmp(payload->pwd, "\x00\x00\x00\x00", 4) == 0) {
|
||||
memcpy(password, tag.sectors[1], sizeof(password));
|
||||
|
@ -1711,7 +1711,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
bAuthenticating = false;
|
||||
break;
|
||||
}
|
||||
case RHT2F_AUTHENTICATE: {
|
||||
case HT2F_AUTHENTICATE: {
|
||||
DBG DbpString("Authenticating using NrAr pair:");
|
||||
memcpy(NrAr, payload->NrAr, 8);
|
||||
DBG Dbhexdump(8, NrAr, false);
|
||||
|
@ -1722,7 +1722,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
bAuthenticating = false;
|
||||
break;
|
||||
}
|
||||
case RHT2F_CRYPTO: {
|
||||
case HT2F_CRYPTO: {
|
||||
DBG DbpString("Authenticating using key:");
|
||||
memcpy(key, payload->key, 6); //HACK; 4 or 6?? I read both in the code.
|
||||
DBG Dbhexdump(6, key, false);
|
||||
|
@ -1734,7 +1734,7 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
bAuthenticating = false;
|
||||
break;
|
||||
}
|
||||
case RHT2F_TEST_AUTH_ATTEMPTS: {
|
||||
case HT2F_TEST_AUTH_ATTEMPTS: {
|
||||
DBG Dbprintf("Testing " _YELLOW_("%d") " authentication attempts", (auth_table_len / 8));
|
||||
auth_table_pos = 0;
|
||||
memcpy(NrAr, auth_table, 8);
|
||||
|
@ -1812,27 +1812,27 @@ void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
// By default reset the transmission buffer
|
||||
tx = txbuf;
|
||||
switch (payload->cmd) {
|
||||
case RHT1F_PLAIN: {
|
||||
case HT1F_PLAIN: {
|
||||
bStop = !hitag1_plain(rx, rxlen, tx, &txlen, false);
|
||||
break;
|
||||
}
|
||||
case RHT1F_AUTHENTICATE: {
|
||||
case HT1F_AUTHENTICATE: {
|
||||
bStop = !hitag1_authenticate(rx, rxlen, tx, &txlen);
|
||||
break;
|
||||
}
|
||||
case RHT2F_PASSWORD: {
|
||||
case HT2F_PASSWORD: {
|
||||
bStop = !hitag2_password(rx, rxlen, tx, &txlen, false);
|
||||
break;
|
||||
}
|
||||
case RHT2F_AUTHENTICATE: {
|
||||
case HT2F_AUTHENTICATE: {
|
||||
bStop = !hitag2_authenticate(rx, rxlen, tx, &txlen, false);
|
||||
break;
|
||||
}
|
||||
case RHT2F_CRYPTO: {
|
||||
case HT2F_CRYPTO: {
|
||||
bStop = !hitag2_crypto(rx, rxlen, tx, &txlen, false);
|
||||
break;
|
||||
}
|
||||
case RHT2F_TEST_AUTH_ATTEMPTS: {
|
||||
case HT2F_TEST_AUTH_ATTEMPTS: {
|
||||
bStop = !hitag2_test_auth_attempts(rx, rxlen, tx, &txlen);
|
||||
break;
|
||||
}
|
||||
|
@ -2083,7 +2083,7 @@ void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
|
||||
// Check configuration
|
||||
switch (payload->cmd) {
|
||||
case WHT2F_CRYPTO: {
|
||||
case HT2F_CRYPTO: {
|
||||
DBG DbpString("Authenticating using key:");
|
||||
memcpy(key, payload->key, 6); //HACK; 4 or 6?? I read both in the code.
|
||||
memcpy(writedata, payload->data, 4);
|
||||
|
@ -2093,7 +2093,7 @@ void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
bAuthenticating = false;
|
||||
}
|
||||
break;
|
||||
case WHT2F_PASSWORD: {
|
||||
case HT2F_PASSWORD: {
|
||||
DBG DbpString("Authenticating using password:");
|
||||
if (memcmp(payload->pwd, "\x00\x00\x00\x00", 4) == 0) {
|
||||
memcpy(password, tag.sectors[1], sizeof(password));
|
||||
|
@ -2180,11 +2180,11 @@ void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
tx = txbuf;
|
||||
|
||||
switch (payload->cmd) {
|
||||
case WHT2F_CRYPTO: {
|
||||
case HT2F_CRYPTO: {
|
||||
bStop = !hitag2_crypto(rx, rxlen, tx, &txlen, true);
|
||||
break;
|
||||
}
|
||||
case WHT2F_PASSWORD: {
|
||||
case HT2F_PASSWORD: {
|
||||
bStop = !hitag2_password(rx, rxlen, tx, &txlen, true);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1117,7 +1117,7 @@ static int hts_select_tag(const lf_hitag_data_t *packet, uint8_t *tx, size_t siz
|
|||
|
||||
uint64_t key_le = 0;
|
||||
// if the tag is in authentication mode try the key or challenge
|
||||
if (packet->cmd == RHTSF_KEY || packet->cmd == WHTSF_KEY) {
|
||||
if (packet->cmd == HTSF_KEY) {
|
||||
|
||||
DBG DbpString("Authenticating using key:");
|
||||
DBG Dbhexdump(6, packet->key, false);
|
||||
|
@ -1137,7 +1137,7 @@ static int hts_select_tag(const lf_hitag_data_t *packet, uint8_t *tx, size_t siz
|
|||
|
||||
DBG Dbprintf("%02X %02X %02X %02X %02X %02X %02X %02X", tx[0], tx[1], tx[2], tx[3], tx[4], tx[5], tx[6], tx[7]);
|
||||
|
||||
} else if (packet->cmd == RHTSF_CHALLENGE || packet->cmd == WHTSF_CHALLENGE) {
|
||||
} else if (packet->cmd == HTSF_CHALLENGE) {
|
||||
|
||||
DBG DbpString("Authenticating using nr,ar pair:");
|
||||
DBG Dbhexdump(8, packet->NrAr, false);
|
||||
|
@ -1157,7 +1157,7 @@ static int hts_select_tag(const lf_hitag_data_t *packet, uint8_t *tx, size_t siz
|
|||
tx[i] = ((NrAr >> (56 - (i * 8))) & 0xFF);
|
||||
}
|
||||
|
||||
} else if (packet->cmd == RHTSF_82xx || packet->cmd == WHTSF_82xx) {
|
||||
} else if (packet->cmd == HTSF_82xx) {
|
||||
// 8268/8310 Authentication by writing password to block 64
|
||||
|
||||
// send write page request
|
||||
|
@ -1191,7 +1191,7 @@ static int hts_select_tag(const lf_hitag_data_t *packet, uint8_t *tx, size_t siz
|
|||
}
|
||||
|
||||
return 0;
|
||||
} else if (packet->cmd == RHTSF_PLAIN || packet->cmd == WHTSF_PLAIN) {
|
||||
} else if (packet->cmd == HTSF_PLAIN) {
|
||||
Dbprintf("Error, " _YELLOW_("AUT=1") " This tag is configured in Authentication Mode");
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -1214,7 +1214,7 @@ static int hts_select_tag(const lf_hitag_data_t *packet, uint8_t *tx, size_t siz
|
|||
pwdh0 = 0;
|
||||
pwdl0 = 0;
|
||||
pwdl1 = 0;
|
||||
if (packet->cmd == RHTSF_KEY || packet->cmd == WHTSF_KEY) {
|
||||
if (packet->cmd == HTSF_KEY) {
|
||||
|
||||
uint64_t state = ht2_hitag2_init(reflect48(key_le), reflect32(tag.data.s.uid_le), reflect32(*(uint32_t *)rnd));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -1296,7 +1296,7 @@ void hts_read(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
pageNum++;
|
||||
//display key and password if possible
|
||||
if (pageNum == 2 && tag.data.s.auth == 1 && tag.data.s.LKP) {
|
||||
if (payload->cmd == RHTSF_KEY) {
|
||||
if (payload->cmd == HTSF_KEY) {
|
||||
DBG Dbprintf("Page[ 2]: %02X %02X %02X %02X",
|
||||
payload->key[1],
|
||||
payload->key[0],
|
||||
|
@ -1383,9 +1383,9 @@ void hts_write_page(const lf_hitag_data_t *payload, bool ledcontrol) {
|
|||
// //ACK received to write the page. send data
|
||||
// uint8_t data[4] = {0, 0, 0, 0};
|
||||
// switch (payload->cmd) {
|
||||
// case WHTSF_PLAIN:
|
||||
// case WHTSF_CHALLENGE:
|
||||
// case WHTSF_KEY:
|
||||
// case HTSF_PLAIN:
|
||||
// case HTSF_CHALLENGE:
|
||||
// case HTSF_KEY:
|
||||
// data[0] = payload->data[3];
|
||||
// data[1] = payload->data[2];
|
||||
// data[2] = payload->data[1];
|
||||
|
@ -1505,7 +1505,7 @@ void hts_check_challenges(const uint8_t *data, uint32_t datalen, bool ledcontrol
|
|||
|
||||
lf_hitag_data_t payload;
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
payload.cmd = RHTSF_CHALLENGE;
|
||||
payload.cmd = HTSF_CHALLENGE;
|
||||
|
||||
memcpy(payload.NrAr, data + dataoffset, 8);
|
||||
|
||||
|
|
|
@ -769,8 +769,8 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
break;
|
||||
}
|
||||
|
||||
packet.cmd = WHTSF_82xx;
|
||||
memcpy(packet.pwd, "\xBB\xDD\x33\x99", 4);
|
||||
packet.cmd = HTSF_82xx;
|
||||
memcpy(packet.pwd, "\xBB\xDD\x33\x99", HITAGS_PAGE_SIZE);
|
||||
SendCommandNG(CMD_LF_HITAGS_WRITE, (uint8_t *)&packet, sizeof(packet));
|
||||
if (WaitForResponseTimeout(CMD_LF_HITAGS_WRITE, &resp, 4000) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
|
|
|
@ -491,10 +491,10 @@ static int ht2_check_dictionary(uint32_t key_count, uint8_t *keys, uint8_t keyl
|
|||
while (key_count--) {
|
||||
|
||||
if (keylen == 4) {
|
||||
packet.cmd = RHT2F_PASSWORD;
|
||||
packet.cmd = HT2F_PASSWORD;
|
||||
memcpy(packet.pwd, pkeys, keylen);
|
||||
} else {
|
||||
packet.cmd = RHT2F_CRYPTO;
|
||||
packet.cmd = HT2F_CRYPTO;
|
||||
memcpy(packet.key, pkeys, keylen);
|
||||
}
|
||||
|
||||
|
@ -806,7 +806,7 @@ static bool ht2_get_uid(uint32_t *uid) {
|
|||
|
||||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
packet.cmd = RHT2F_UID_ONLY;
|
||||
packet.cmd = HT2F_UID_ONLY;
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_HITAG_READER, (uint8_t *) &packet, sizeof(packet));
|
||||
|
@ -1017,17 +1017,17 @@ static int CmdLFHitagRd(const char *Cmd) {
|
|||
int pm3cmd;
|
||||
if (use_ht2 && use_pwd) {
|
||||
pm3cmd = CMD_LF_HITAG_READER;
|
||||
packet.cmd = RHT2F_PASSWORD;
|
||||
packet.cmd = HT2F_PASSWORD;
|
||||
memcpy(packet.pwd, key, sizeof(packet.pwd));
|
||||
|
||||
} else if (use_ht2 && use_nrar) {
|
||||
pm3cmd = CMD_LF_HITAG_READER;
|
||||
packet.cmd = RHT2F_AUTHENTICATE;
|
||||
packet.cmd = HT2F_AUTHENTICATE;
|
||||
memcpy(packet.NrAr, nrar, sizeof(packet.NrAr));
|
||||
} else if (use_ht2 && use_crypto) {
|
||||
|
||||
pm3cmd = CMD_LF_HITAG_READER;
|
||||
packet.cmd = RHT2F_CRYPTO;
|
||||
packet.cmd = HT2F_CRYPTO;
|
||||
memcpy(packet.key, key, sizeof(packet.key));
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "Sorry, not yet implemented");
|
||||
|
@ -1122,7 +1122,7 @@ static int CmdLFHitag2CheckChallenges(const char *Cmd) {
|
|||
|
||||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(lf_hitag_data_t));
|
||||
packet.cmd = RHT2F_TEST_AUTH_ATTEMPTS;
|
||||
packet.cmd = HT2F_TEST_AUTH_ATTEMPTS;
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_HITAG_READER, (uint8_t *)&packet, sizeof(packet));
|
||||
|
@ -1266,14 +1266,14 @@ static int CmdLFHitagWriter(const char *Cmd) {
|
|||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
if (use_ht2 && use_pwd) {
|
||||
packet.cmd = WHT2F_PASSWORD;
|
||||
packet.cmd = HT2F_PASSWORD;
|
||||
packet.page = page;
|
||||
memcpy(packet.pwd, key, sizeof(packet.pwd));
|
||||
memcpy(packet.data, data, sizeof(data));
|
||||
PrintAndLogEx(INFO, "Authenticating to " _YELLOW_("Hitag 2") " in Password mode");
|
||||
|
||||
} else if (use_ht2 && use_crypto) {
|
||||
packet.cmd = WHT2F_CRYPTO;
|
||||
packet.cmd = HT2F_CRYPTO;
|
||||
packet.page = page;
|
||||
memcpy(packet.key, key, sizeof(packet.key));
|
||||
memcpy(packet.data, data, sizeof(data));
|
||||
|
@ -1441,12 +1441,12 @@ static int CmdLFHitag2Dump(const char *Cmd) {
|
|||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
if (use_ht2 && use_pwd) {
|
||||
packet.cmd = RHT2F_PASSWORD;
|
||||
packet.cmd = HT2F_PASSWORD;
|
||||
memcpy(packet.pwd, key, sizeof(packet.pwd));
|
||||
PrintAndLogEx(INFO, "Authenticating to " _YELLOW_("Hitag 2") " in Password mode");
|
||||
|
||||
} else if (use_ht2 && use_crypto) {
|
||||
packet.cmd = RHT2F_CRYPTO;
|
||||
packet.cmd = HT2F_CRYPTO;
|
||||
memcpy(packet.key, key, sizeof(packet.key));
|
||||
PrintAndLogEx(INFO, "Authenticating to " _YELLOW_("Hitag 2") " in Crypto mode");
|
||||
|
||||
|
@ -2414,7 +2414,7 @@ int ht2_read_paxton(void) {
|
|||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
packet.cmd = RHT2F_PASSWORD;
|
||||
packet.cmd = HT2F_PASSWORD;
|
||||
memcpy(packet.pwd, ht2_default_keys, sizeof(packet.pwd));
|
||||
|
||||
clearCommandBuffer();
|
||||
|
|
|
@ -188,17 +188,17 @@ static int CmdLFHitagSRead(const char *Cmd) {
|
|||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
if (use_nrar) {
|
||||
packet.cmd = RHTSF_CHALLENGE;
|
||||
packet.cmd = HTSF_CHALLENGE;
|
||||
memcpy(packet.NrAr, nrar, sizeof(packet.NrAr));
|
||||
}
|
||||
|
||||
if (use_82xx) {
|
||||
packet.cmd = RHTSF_82xx;
|
||||
packet.cmd = HTSF_82xx;
|
||||
memcpy(packet.pwd, key, sizeof(packet.pwd));
|
||||
}
|
||||
|
||||
if (use_crypto) {
|
||||
packet.cmd = RHTSF_KEY;
|
||||
packet.cmd = HTSF_KEY;
|
||||
memcpy(packet.key, key, sizeof(packet.key));
|
||||
}
|
||||
|
||||
|
@ -350,18 +350,18 @@ static int CmdLFHitagSWrite(const char *Cmd) {
|
|||
memcpy(packet.data, data, sizeof(data));
|
||||
|
||||
if (use_nrar) {
|
||||
packet.cmd = WHTSF_CHALLENGE;
|
||||
packet.cmd = HTSF_CHALLENGE;
|
||||
memcpy(packet.NrAr, nrar, sizeof(packet.NrAr));
|
||||
PrintAndLogEx(INFO, "Authenticating to " _YELLOW_("Hitag S") " in Challenge mode");
|
||||
}
|
||||
|
||||
if (use_82xx) {
|
||||
packet.cmd = WHTSF_82xx;
|
||||
packet.cmd = HTSF_82xx;
|
||||
memcpy(packet.pwd, key, sizeof(packet.pwd));
|
||||
}
|
||||
|
||||
if (use_crypto) {
|
||||
packet.cmd = WHTSF_KEY;
|
||||
packet.cmd = HTSF_KEY;
|
||||
memcpy(packet.key, key, sizeof(packet.key));
|
||||
PrintAndLogEx(INFO, "Authenticating to " _YELLOW_("Hitag S") " in Crypto mode");
|
||||
}
|
||||
|
|
|
@ -49,28 +49,22 @@
|
|||
#define HITAG2_CONFIG_BLOCK 3
|
||||
|
||||
typedef enum {
|
||||
RHTSF_PLAIN,
|
||||
WHTSF_PLAIN,
|
||||
RHTSF_82xx,
|
||||
WHTSF_82xx,
|
||||
RHTSF_CHALLENGE,
|
||||
WHTSF_CHALLENGE,
|
||||
RHTSF_KEY,
|
||||
WHTSF_KEY,
|
||||
HTS_LAST_CMD = WHTSF_KEY,
|
||||
HTSF_PLAIN,
|
||||
HTSF_82xx,
|
||||
HTSF_CHALLENGE,
|
||||
HTSF_KEY,
|
||||
HTS_LAST_CMD = HTSF_KEY,
|
||||
|
||||
RHT1F_PLAIN,
|
||||
RHT1F_AUTHENTICATE,
|
||||
HT1_LAST_CMD = RHT1F_AUTHENTICATE,
|
||||
HT1F_PLAIN,
|
||||
HT1F_AUTHENTICATE,
|
||||
HT1_LAST_CMD = HT1F_AUTHENTICATE,
|
||||
|
||||
RHT2F_PASSWORD,
|
||||
RHT2F_AUTHENTICATE,
|
||||
RHT2F_CRYPTO,
|
||||
WHT2F_CRYPTO,
|
||||
RHT2F_TEST_AUTH_ATTEMPTS,
|
||||
RHT2F_UID_ONLY,
|
||||
WHT2F_PASSWORD,
|
||||
HT2_LAST_CMD = WHT2F_PASSWORD,
|
||||
HT2F_PASSWORD,
|
||||
HT2F_AUTHENTICATE,
|
||||
HT2F_CRYPTO,
|
||||
HT2F_TEST_AUTH_ATTEMPTS,
|
||||
HT2F_UID_ONLY,
|
||||
HT2_LAST_CMD = HT2F_UID_ONLY,
|
||||
} PACKED hitag_function;
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue