From fd88d7448ec78dd4f1645ab93bafc5fde120588c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 30 Sep 2019 19:47:36 +0200 Subject: [PATCH] fix 'lf t55xx resetread' - NG and better fault handling --- armsrc/lfops.c | 5 ++--- client/cmdlft55xx.c | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 4d3d568f4..e2e8daadf 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1694,9 +1694,8 @@ void T55xxResetRead(uint8_t flags) { DoPartialAcquisition(0, true, BigBuf_max_traceLen(), 0); // Turn the field off - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off - reply_mix(CMD_ACK, 0, 0, 0, 0, 0); - + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + reply_ng(CMD_LF_T55XX_RESET_READ, PM3_SUCCESS, NULL, 0); LED_A_OFF(); } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 8cc8142a7..922602f9b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2426,19 +2426,30 @@ static int CmdResetRead(const char *Cmd) { flags = downlink_mode << 3; + PacketResponseNG resp; + clearCommandBuffer(); SendCommandNG(CMD_LF_T55XX_RESET_READ, &flags, sizeof(flags)); - if (!WaitForResponseTimeout(CMD_ACK, NULL, 2500)) { + if (!WaitForResponseTimeout(CMD_LF_T55XX_RESET_READ, &resp, 2500)) { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; } - uint8_t got[BIGBUF_SIZE - 1]; - if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) { - PrintAndLogEx(WARNING, "command execution time out"); - return PM3_ETIMEOUT; + if (resp.status == PM3_SUCCESS) { + + uint8_t *got = calloc(BIGBUF_SIZE - 1, sizeof(uint8_t)); + if (got == NULL) { + PrintAndLogEx(WARNING, "failed to allocate memory"); + return PM3_EMALLOC; + } + + if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) { + PrintAndLogEx(WARNING, "command execution time out"); + return PM3_ETIMEOUT; + } + setGraphBuf(got, sizeof(got)); + free(got); } - setGraphBuf(got, sizeof(got)); return PM3_SUCCESS; }