From c268844d50031deab01d63ead9c4dc7a4327ff6f Mon Sep 17 00:00:00 2001 From: Davi Mikael <31720422+penegui@users.noreply.github.com> Date: Tue, 24 Mar 2026 20:22:53 -0300 Subject: [PATCH] Fix EMV flow for cards without usable READ RECORD Capture Track 2 (tag 57) from the GPO response when available and avoid sending the fixed READ RECORD APDU if the token was already found. This prevents unnecessary 6A83 responses and improves compatibility with cards that return the required data during GPO. --- armsrc/Standalone/hf_emvpng.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/armsrc/Standalone/hf_emvpng.c b/armsrc/Standalone/hf_emvpng.c index 21c5a593c..d603fdf24 100644 --- a/armsrc/Standalone/hf_emvpng.c +++ b/armsrc/Standalone/hf_emvpng.c @@ -301,9 +301,14 @@ void RunMod(void) { if (iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false)) { DbpString(_YELLOW_("+") "Found ISO 14443 Type A!"); - + + chktoken = false; for (uint8_t i = 0; i < 4; i++) { - chktoken = false; + + if (i == 3 && chktoken) { + break; // já achei a 57 no GPO, não preciso de READ RECORD + } + LED_C_OFF(); LED_B_ON(); uint8_t apdulen = iso14_apdu(apdus[i], (uint16_t) apduslen[i], false, apdubuffer, sizeof(apdubuffer), NULL); @@ -331,13 +336,13 @@ void RunMod(void) { } - } else if (i == 3) { + } else if (i == 2 || i == 3) { - // find track 2 - if (apdubuffer[u] == 0x57 && apdubuffer[u + 1] == 0x13 && !chktoken) { + // find track 2 in GPO or READ RECORD + if (u + 20 < apdulen && apdubuffer[u] == 0x57 && apdubuffer[u + 1] == 0x13 && !chktoken) { chktoken = true; - memcpy(&token, &apdubuffer[u + 2], 19); + memcpy(token, &apdubuffer[u + 2], 19); break; } }