From 51d8b18f3eaa627e2c9f3c869a6079fc13dd45f6 Mon Sep 17 00:00:00 2001 From: Nikita Vostokov <1042932+wosk@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:26:16 +0000 Subject: [PATCH] Read SFI until PAN find * get rid of input result buffers --- lib/nfc/protocols/emv/emv_poller.c | 22 ++++--------------- lib/nfc/protocols/emv/emv_poller_i.c | 6 +++++ lib/nfc/protocols/emv/emv_poller_i.h | 2 -- .../iso14443_4a/iso14443_4a_poller_i.c | 6 +++++ 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/nfc/protocols/emv/emv_poller.c b/lib/nfc/protocols/emv/emv_poller.c index 7907908fd..6ca21df1c 100644 --- a/lib/nfc/protocols/emv/emv_poller.c +++ b/lib/nfc/protocols/emv/emv_poller.c @@ -6,9 +6,8 @@ #define TAG "EMVPoller" -// SKOLKO????????????????????????????????????????????????????????????????? +// MAX Le is 255 bytes + 2 for CRC #define EMV_BUF_SIZE (512U) -#define EMV_RESULT_BUF_SIZE (512U) typedef NfcCommand (*EmvPollerReadHandler)(EmvPoller* instance); @@ -24,8 +23,6 @@ static EmvPoller* emv_poller_alloc(Iso14443_4aPoller* iso14443_4a_poller) { instance->data = emv_alloc(); instance->tx_buffer = bit_buffer_alloc(EMV_BUF_SIZE); instance->rx_buffer = bit_buffer_alloc(EMV_BUF_SIZE); - instance->input_buffer = bit_buffer_alloc(EMV_BUF_SIZE); - instance->result_buffer = bit_buffer_alloc(EMV_RESULT_BUF_SIZE); instance->state = EmvPollerStateIdle; @@ -44,14 +41,10 @@ static void emv_poller_free(EmvPoller* instance) { emv_free(instance->data); bit_buffer_free(instance->tx_buffer); bit_buffer_free(instance->rx_buffer); - bit_buffer_free(instance->input_buffer); - bit_buffer_free(instance->result_buffer); free(instance); } static NfcCommand emv_poller_handler_idle(EmvPoller* instance) { - bit_buffer_reset(instance->input_buffer); - bit_buffer_reset(instance->result_buffer); bit_buffer_reset(instance->tx_buffer); bit_buffer_reset(instance->rx_buffer); @@ -106,21 +99,14 @@ static NfcCommand emv_poller_handler_get_processing_options(EmvPoller* instance) } static NfcCommand emv_poller_handler_read_files(EmvPoller* instance) { - instance->error = emv_poller_read_afl(instance); - - if(instance->error == EmvErrorNone) { - FURI_LOG_D(TAG, "Read files success"); - instance->state = EmvPollerStateReadExtra; - } else { - FURI_LOG_E(TAG, "Failed to read files"); - instance->state = EmvPollerStateReadFailed; - } + emv_poller_read_afl(instance); + emv_poller_read_log_entry(instance); + instance->state = EmvPollerStateReadExtra; return NfcCommandContinue; } static NfcCommand emv_poller_handler_read_extra_data(EmvPoller* instance) { - emv_poller_read_log_entry(instance); emv_poller_get_last_online_atc(instance); emv_poller_get_pin_try_counter(instance); diff --git a/lib/nfc/protocols/emv/emv_poller_i.c b/lib/nfc/protocols/emv/emv_poller_i.c index 2fbae4fc4..c237125b2 100644 --- a/lib/nfc/protocols/emv/emv_poller_i.c +++ b/lib/nfc/protocols/emv/emv_poller_i.c @@ -619,6 +619,12 @@ EmvError emv_poller_read_afl(EmvPoller* instance) { error = EmvErrorProtocol; FURI_LOG_T(TAG, "Failed to parse SFI 0x%X record %d", sfi, record); } + + // Some READ RECORD returns 1 byte response 0x12/0x13 (IDK WTF), + // then poller return Timeout to all subsequent requests. + // TODO: remove below lines when it was fixed + if(instance->data->emv_application.pan_len != 0) + return EmvErrorNone; // Card number fetched } } diff --git a/lib/nfc/protocols/emv/emv_poller_i.h b/lib/nfc/protocols/emv/emv_poller_i.h index 620d2f359..704365747 100644 --- a/lib/nfc/protocols/emv/emv_poller_i.h +++ b/lib/nfc/protocols/emv/emv_poller_i.h @@ -35,8 +35,6 @@ struct EmvPoller { EmvData* data; BitBuffer* tx_buffer; BitBuffer* rx_buffer; - BitBuffer* input_buffer; - BitBuffer* result_buffer; EmvPollerEventData emv_event_data; EmvPollerEvent emv_event; NfcGenericEvent general_event; diff --git a/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c b/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c index b8e2ebda6..2065b81a2 100644 --- a/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c +++ b/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c @@ -103,6 +103,12 @@ Iso14443_4aError iso14443_4a_poller_send_block_pwt_ext( iso14443_4a_get_fwt_fc_max(instance->data)); if(iso14443_3a_error != Iso14443_3aErrorNone) { + FURI_LOG_RAW_T("RAW RX(%d):", bit_buffer_get_size_bytes(instance->rx_buffer)); + for(size_t x = 0; x < bit_buffer_get_size_bytes(instance->rx_buffer); x++) { + FURI_LOG_RAW_T("%02X ", bit_buffer_get_byte(instance->rx_buffer, x)); + } + FURI_LOG_RAW_T("\r\n"); + error = iso14443_4a_process_error(iso14443_3a_error); break;