From 2c9a74b906ebe185842ace0dad64f88c32021a2f Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Thu, 20 Mar 2025 21:46:34 +0800 Subject: [PATCH] =?UTF-8?q?Improve=20Hitag=20=C2=B5=20error=20reason=20and?= =?UTF-8?q?=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- armsrc/hitagu.c | 14 +++++++------- client/src/cmdlfhitagu.c | 28 ++++++---------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/armsrc/hitagu.c b/armsrc/hitagu.c index 30816f5af..897439f7c 100644 --- a/armsrc/hitagu.c +++ b/armsrc/hitagu.c @@ -540,7 +540,7 @@ static int htu_select_tag(const lf_hitag_data_t *payload, uint8_t *tx, size_t si // Check if the response is valid if (rxlen < 1 + 48 + 16 || Crc16(rx, rxlen, 0, CRC16_POLY_CCITT, false, false) != 0) { DBG Dbprintf("Read UID command failed! %i", rxlen); - return -1; // Read UID failed + return -2; // Read UID failed } // Process the UID from the response @@ -565,7 +565,7 @@ static int htu_select_tag(const lf_hitag_data_t *payload, uint8_t *tx, size_t si if (rxlen < 1 + 16 + 16 || Crc16(rx, rxlen, 0, CRC16_POLY_CCITT, false, false) != 0) { // 8265 bug? sometile lost Data field first bit DBG Dbprintf("Get System Information command failed! %i", rxlen); - return -2; // Get System Information failed + return -3; // Get System Information failed } // 3. Read config block @@ -590,7 +590,7 @@ static int htu_select_tag(const lf_hitag_data_t *payload, uint8_t *tx, size_t si // Check if the response is valid if (rxlen < 1 + 32 + 16 || Crc16(rx, rxlen, 0, CRC16_POLY_CCITT, false, false) != 0) { DBG Dbprintf("Read config block command failed! %i", rxlen); - return -2; // Read config block failed + return -3; // Read config block failed } // Process the config block from the response @@ -616,7 +616,7 @@ static int htu_select_tag(const lf_hitag_data_t *payload, uint8_t *tx, size_t si // Check if login succeeded if (rxlen < 1 + 16 || Crc16(rx, rxlen, 0, CRC16_POLY_CCITT, false, false) != 0) { DBG Dbprintf("Login command failed! %i", rxlen); - return -3; // Login failed + return -4; // Login failed } else { DBG DbpString("Login successful"); } @@ -772,14 +772,14 @@ void htu_read(const lf_hitag_data_t *payload, bool ledcontrol) { if (flags & HITAGU_FLAG_CRCT && Crc16(rx, rxlen, 0, CRC16_POLY_CCITT, false, false) != 0) { DBG Dbprintf("Error: response CRC invalid"); - card.pages_reason[i] = -1; + card.pages_reason[i] = -6; continue; } // Check response if (rxlen < 1 + HITAGU_BLOCK_SIZE * 8 + (flags & HITAGU_FLAG_CRCT ? 16 : 0)) { DbpString("Error: invalid response received after read command"); - card.pages_reason[i] = -11; + card.pages_reason[i] = -7; } else { DBG Dbprintf("Read successful, response: %d bits", rxlen); // todo: For certain pages, update our cached data @@ -885,7 +885,7 @@ void htu_write_page(const lf_hitag_data_t *payload, bool ledcontrol) { status = PM3_ENODATA; } else if (rxlen != 1 + 16) { DbpString("Error: htu_write_page No valid response received after write command"); - reason = -1; + reason = -5; status = PM3_ERFTRANS; } else { DBG Dbprintf("Write successful, response: %d bits", rxlen); diff --git a/client/src/cmdlfhitagu.c b/client/src/cmdlfhitagu.c index 54b318bd7..da7fb34d0 100644 --- a/client/src/cmdlfhitagu.c +++ b/client/src/cmdlfhitagu.c @@ -253,46 +253,30 @@ static void print_error(int8_t reason) { //todo: USE ENUM OR DEFINES switch (reason) { case 0: { - PrintAndLogEx(FAILED, "No data"); + PrintAndLogEx(INFO, "No data"); break; } case -2: { - PrintAndLogEx(FAILED, "UID Request failed!"); + PrintAndLogEx(FAILED, "READ UID failed!"); break; } case -3: { - PrintAndLogEx(FAILED, "Select UID failed!"); + PrintAndLogEx(FAILED, "Get System Information / Config failed!"); break; } case -4: { - PrintAndLogEx(FAILED, "No write access on block. Not authorized?"); + PrintAndLogEx(FAILED, "Login failed! Wrong password?"); break; } case -5: { - PrintAndLogEx(FAILED, "Write failed! Wrong password?"); + PrintAndLogEx(FAILED, "No write access on block. Not authorized?"); break; } case -6: { - PrintAndLogEx(FAILED, "Error, " _YELLOW_("AUT=1") " This tag is configured in Authentication Mode"); + PrintAndLogEx(FAILED, "Response CRC invalid!"); break; } case -7: { - PrintAndLogEx(FAILED, "Error, unknown function"); - break; - } - case -8: { - PrintAndLogEx(FAILED, "Authenticate failed!"); - break; - } - case -9: { - PrintAndLogEx(FAILED, "No write access on block"); - break; - } - case -10: { - PrintAndLogEx(FAILED, "Write to block failed!"); - break; - } - case -11: { PrintAndLogEx(FAILED, "Read block failed!"); break; }