From e7ff2ad1caac78a488b1502f0e38b5336925da32 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 13 Oct 2024 22:17:48 +0200 Subject: [PATCH] hf mf ecfill: wait for execution and return status --- CHANGELOG.md | 1 + armsrc/mifarecmd.c | 8 ++++++++ client/src/cmdhfmf.c | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e08dde6da..3de7fe0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Changed `hf mf ecfill` to wait for execution and return status (@doegox) - Added option to wait for a card to `hf 14a reader` (@doegox) - Added support for quick dump via backdoor auth to `hf mf ecfill` (@doegox) - Fixed `hf mf restore` - really skip strict ACLs unless --force (@doegox) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 5dd2b2420..1f59f45ca 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2377,6 +2377,14 @@ int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype, uint8_t *key) { if (have_uid == false) { // need a full select cycle to get the uid first iso14a_card_select_t card_info; if (iso14443a_select_card(uid, &card_info, &cuid, true, 0, true) == 0) { + if (s == 0) { + // first attempt, if no card let's stop directly + retval = PM3_EFAILED; + if (g_dbglevel >= DBG_ERROR) { + Dbprintf("Card not found"); + } + goto out; + } continue; } diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 5b12be941..32705409a 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -4999,8 +4999,18 @@ static int CmdHF14AMfECFill(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); - // 2021, iceman: should get a response from device when its done. - return PM3_SUCCESS; + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 1500) == false) { + PrintAndLogEx(WARNING, "command execution time out"); + return PM3_ETIMEOUT; + } + + if (resp.status == PM3_SUCCESS) + PrintAndLogEx(SUCCESS, "Fill ( " _GREEN_("ok") " )"); + else + PrintAndLogEx(FAILED, "Fill ( " _RED_("fail") " )"); + + return resp.status; } static int CmdHF14AMfEKeyPrn(const char *Cmd) {