From 975034854df159b12ae7ddfc1e6bd32150b24a2d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 18 Dec 2020 02:14:50 +0100 Subject: [PATCH] rework 14b apdu timeout computations --- armsrc/iso14443b.c | 6 +++--- client/src/cmdhf14b.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index 11542a498..c3c61e980 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -1201,7 +1201,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, int timeo if (Handle14443bSamplesFromTag(ci, cq)) { - *eof_time = dma_start_time + (samples) - DELAY_TAG_TO_ARM; // end of EOF + *eof_time = GetCountSspClkDelta(dma_start_time) - (DELAY_TAG_TO_ARM * 128); // end of EOF if (Demod.len > Demod.max_len) { ret = -2; // overflow @@ -1209,7 +1209,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, int timeo break; } - if (samples > timeout && Demod.state < DEMOD_PHASE_REF_TRAINING) { + if (((GetCountSspClkDelta(dma_start_time) >> 7) > timeout) && Demod.state < DEMOD_PHASE_REF_TRAINING) { ret = -1; break; } @@ -1225,7 +1225,7 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, int timeo - (Demod.len * (8 + 2)) // time for byte transfers - (12) // time for SOF transfer - (12); // time for EOF transfer - LogTrace(Demod.output, Demod.len, (sof_time * 4), (*eof_time * 4), NULL, false); + LogTrace(Demod.output, Demod.len, sof_time, *eof_time, NULL, false); } return Demod.len; } diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index ffec87950..17c31e0a7 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -26,7 +26,7 @@ #include "mifare/ndef.h" // NDEFRecordsDecodeAndPrint #define TIMEOUT 2000 -#define APDU_TIMEOUT 4000 +#define APDU_TIMEOUT 2000 // iso14b apdu input frame length static uint16_t apdu_frame_length = 0; @@ -1450,7 +1450,7 @@ static int handle_14b_apdu(bool chainingin, uint8_t *datain, int datainlen, bool SendCommandMIX(CMD_HF_ISO14443B_COMMAND, ISO14B_APDU | flags, 0, time_wait, NULL, 0); PacketResponseNG resp; - if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, APDU_TIMEOUT)) { + if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, MAX(APDU_TIMEOUT, user_timeout))) { uint8_t *recv = resp.data.asBytes; int rlen = resp.oldarg[0]; uint8_t res = resp.oldarg[1];