From 046488664b4c00320450201267939668b910ec73 Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Wed, 23 Oct 2024 21:46:34 +0800 Subject: [PATCH] fix: Hitag S Read page failed --- armsrc/hitagS.c | 18 +++++++++--------- client/src/cmdlfhitaghts.c | 9 +++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index edee23a4d..c95b06ca8 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -1295,6 +1295,12 @@ void hts_read(const lf_hitag_data_t *payload, bool ledcontrol) { while ((BUTTON_PRESS() == false) && (data_available() == false)) { + if (payload->page_count == 0) { + if (page_addr > tag.max_page) break; + } else if (page_addr > 255 || page_addr >= payload->page + payload->page_count) { + break; + } + WDT_HIT(); size_t rxlen = 0; @@ -1312,7 +1318,7 @@ void hts_read(const lf_hitag_data_t *payload, bool ledcontrol) { if (rxlen != 40) { DBG Dbprintf("Read page failed!"); - card.pages_reason[page_index] = -4; + card.pages_reason[page_index] = -11; // status = PM3_ERFTRANS; // goto read_end; page_addr++; @@ -1362,18 +1368,12 @@ void hts_read(const lf_hitag_data_t *payload, bool ledcontrol) { //if the authentication is done with a challenge the key and password are unknown DBG Dbprintf("Page[ 2]: __ __ __ __"); DBG Dbprintf("Page[ 3]: __ __ __ __"); - card.pages_reason[page_index++] = -4; - card.pages_reason[page_index++] = -4; + card.pages_reason[page_index++] = -11; + card.pages_reason[page_index++] = -11; } // since page 2+3 are not accessible when LKP == 1 and AUT == 1 fastforward to next readable page page_addr = 4; } - - if (payload->page_count == 0) { - if (page_addr > tag.max_page) break; - } else if (page_addr > 255 || page_addr >= payload->page + payload->page_count) { - break; - } } read_end: diff --git a/client/src/cmdlfhitaghts.c b/client/src/cmdlfhitaghts.c index e72d7194f..c16562b37 100644 --- a/client/src/cmdlfhitaghts.c +++ b/client/src/cmdlfhitaghts.c @@ -226,6 +226,9 @@ static void print_error(int8_t reason) { case -10: PrintAndLogEx(FAILED, "Write to page failed!"); break; + case -11: + PrintAndLogEx(FAILED, "Read page failed!"); + break; default: // PM3_REASON_UNKNOWN PrintAndLogEx(DEBUG, "DEBUG: Error - Hitag S failed"); @@ -404,8 +407,10 @@ static int CmdLFHitagSRead(const char *Cmd) { PrintAndLogEx(NORMAL, "Key"); } else PrintAndLogEx(NORMAL, "Data"); - } else - PrintAndLogEx(INFO, "%02u | -- -- -- -- | read failed reason: " _YELLOW_("%d"), page_addr, card->pages_reason[i]); + } else { + PrintAndLogEx(INFO, "% 3u | -- -- -- -- | .... | N/A | " NOLF, page_addr); + print_error(card->pages_reason[i]); + } } PrintAndLogEx(INFO, "----+-------------+-------+------+------");