From 9b6d1f74dade3156c616e658b9990820b2cd4b16 Mon Sep 17 00:00:00 2001 From: LW Date: Sat, 14 Dec 2019 01:41:16 -0800 Subject: [PATCH] fix nested loop with cards that do not NACK --- armsrc/mifarecmd.c | 7 +++++++ client/cmdhf14b.c | 2 +- client/mifare/mifarehost.c | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index bed2f076..8ad9a78b 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -895,6 +895,13 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat target_nt[i] = 0; while(target_nt[i] == 0) { // continue until we have an unambiguous nonce + // break out of the loop on button press or new usb data as + // cards that do not NACK bad keys will get stuck here + if(BUTTON_PRESS() || usb_poll_validate_length()) { + isOK = -2; + break; + } + // prepare next select. No need to power down the card. if(mifare_classic_halt(pcs, cuid)) { if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Halt error"); diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index 577b4fc8..2aa40dd0 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -679,7 +679,7 @@ int CmdSriWrite(const char *Cmd) { uint8_t blockno = -1; uint8_t data[4] = {0x00}; bool isSrix4k = true; - char str[20]; + char str[22]; if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') { PrintAndLog("Usage: hf 14b write <1|2> "); diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 90c69878..9631508c 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -335,7 +335,11 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, memcpy(c.d.asBytes, key, 6); SendCommand(&c); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) { + // cards that do not NACK bad keys cause it to get stuck in a loop, so break it out + UsbCommand c = {CMD_PING}; + SendCommand(&c); + (void)WaitForResponseTimeout(CMD_ACK,NULL,500); return -1; }