Improve Hitag µ error reason and messages

This commit is contained in:
douniwan5788 2025-03-20 21:46:34 +08:00
parent 93c6250894
commit 2c9a74b906
2 changed files with 13 additions and 29 deletions

View file

@ -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);

View file

@ -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;
}