From 844e0f10e59ef53a6be2b71106b9d143fafeab01 Mon Sep 17 00:00:00 2001 From: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:56:49 +0300 Subject: [PATCH 1/4] [FL-3639] Fix MF DESFire record file handling (#3167) --- .../nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c | 1 + lib/nfc/protocols/mf_desfire/mf_desfire.h | 1 + lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c index 883ea720..b5ca0d13 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c +++ b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c @@ -197,6 +197,7 @@ void nfc_render_mf_desfire_file_settings_data( furi_string_cat_printf(str, "size %lu\n", record_size); break; case MfDesfireFileTypeValue: + record_size = MF_DESFIRE_VALUE_SIZE; furi_string_cat_printf( str, "lo %lu hi %lu\n", settings->value.lo_limit, settings->value.hi_limit); furi_string_cat_printf( diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire.h b/lib/nfc/protocols/mf_desfire/mf_desfire.h index 4d09dc85..8505b792 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire.h +++ b/lib/nfc/protocols/mf_desfire/mf_desfire.h @@ -29,6 +29,7 @@ extern "C" { #define MF_DESFIRE_UID_SIZE (7) #define MF_DESFIRE_BATCH_SIZE (5) #define MF_DESFIRE_APP_ID_SIZE (3) +#define MF_DESFIRE_VALUE_SIZE (4) typedef struct { uint8_t hw_vendor; diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c b/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c index e86cb4c6..17377d66 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c @@ -353,7 +353,7 @@ MfDesfireError mf_desfire_poller_async_read_file_records( furi_assert(instance); bit_buffer_reset(instance->input_buffer); - bit_buffer_append_byte(instance->input_buffer, MF_DESFIRE_CMD_READ_DATA); + bit_buffer_append_byte(instance->input_buffer, MF_DESFIRE_CMD_READ_RECORDS); bit_buffer_append_byte(instance->input_buffer, id); bit_buffer_append_bytes(instance->input_buffer, (const uint8_t*)&offset, 3); bit_buffer_append_bytes(instance->input_buffer, (const uint8_t*)&size, 3); From 3d872cf37a2c4ec616021e1a6da4115610a6637a Mon Sep 17 00:00:00 2001 From: gornekich Date: Sat, 28 Oct 2023 18:22:07 +0400 Subject: [PATCH 2/4] [FL-3637] NFC RC fixes (#3165) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * firmware: remove nfc lib build settings section * furi hal nfc: fix nfc irq gpio deinit * lib nfc: remove deprecated exception from sources * nfc: use ASK demodulator in transparent mode * mf ultralight: add upper page bound for NTAGI2C1K * furi hal nfc: set event if nfc event was started * nfc: fix PVS warnings * lib signal reader: remove gpio pull setting in alloc * furi: added math.h include for compatibility with existing apps * nfc: remove resolved TODO in mf desfire poller * bump api symbol version Co-authored-by: hedger Co-authored-by: あく --- firmware.scons | 9 --------- firmware/targets/f18/api_symbols.csv | 2 +- firmware/targets/f7/api_symbols.csv | 2 +- firmware/targets/f7/furi_hal/furi_hal_nfc_event.c | 5 +++-- firmware/targets/f7/furi_hal/furi_hal_nfc_irq.c | 2 +- firmware/targets/f7/furi_hal/furi_hal_nfc_iso15693.c | 2 +- furi/furi.h | 3 +++ lib/nfc/SConscript | 2 +- lib/nfc/protocols/mf_ultralight/mf_ultralight.c | 2 +- .../protocols/mf_ultralight/mf_ultralight_listener_i.c | 2 ++ lib/signal_reader/parsers/iso15693/iso15693_parser.c | 2 +- 11 files changed, 15 insertions(+), 18 deletions(-) diff --git a/firmware.scons b/firmware.scons index d8e96ad7..82f775d7 100644 --- a/firmware.scons +++ b/firmware.scons @@ -71,15 +71,6 @@ env = ENV.Clone( "FURI_DEBUG" if ENV["DEBUG"] else "FURI_NDEBUG", ], }, - "nfc": { - "CCFLAGS": [ - "-Og", - ], - "CPPDEFINES": [ - "NDEBUG", - "FURI_DEBUG", - ], - }, }, FW_API_TABLE=None, _APP_ICONS=None, diff --git a/firmware/targets/f18/api_symbols.csv b/firmware/targets/f18/api_symbols.csv index 8e15030a..4789d316 100644 --- a/firmware/targets/f18/api_symbols.csv +++ b/firmware/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,40.0,, +Version,+,40.1,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 3ae099b5..038a22ea 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,40.0,, +Version,+,40.1,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc_event.c b/firmware/targets/f7/furi_hal/furi_hal_nfc_event.c index cce16c5d..266b606f 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc_event.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc_event.c @@ -25,9 +25,10 @@ FuriHalNfcError furi_hal_nfc_event_stop() { void furi_hal_nfc_event_set(FuriHalNfcEventInternalType event) { furi_assert(furi_hal_nfc_event); - furi_assert(furi_hal_nfc_event->thread); - furi_thread_flags_set(furi_hal_nfc_event->thread, event); + if(furi_hal_nfc_event->thread) { + furi_thread_flags_set(furi_hal_nfc_event->thread, event); + } } FuriHalNfcError furi_hal_nfc_abort() { diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc_irq.c b/firmware/targets/f7/furi_hal/furi_hal_nfc_irq.c index 63dc3541..170d8dee 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc_irq.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc_irq.c @@ -23,6 +23,6 @@ void furi_hal_nfc_init_gpio_isr() { } void furi_hal_nfc_deinit_gpio_isr() { - furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); furi_hal_gpio_remove_int_callback(&gpio_nfc_irq_rfid_pull); + furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeAnalog, GpioPullNo, GpioSpeedLow); } diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc_iso15693.c b/firmware/targets/f7/furi_hal/furi_hal_nfc_iso15693.c index 19ac6dc0..cc936644 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc_iso15693.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc_iso15693.c @@ -48,7 +48,7 @@ static FuriHalNfcIso15693Listener* furi_hal_nfc_iso15693_listener_alloc() { instance->signal = iso15693_signal_alloc(&gpio_spi_r_mosi); instance->parser = - iso15693_parser_alloc(&gpio_spi_r_miso, FURI_HAL_NFC_ISO15693_MAX_FRAME_SIZE); + iso15693_parser_alloc(&gpio_nfc_irq_rfid_pull, FURI_HAL_NFC_ISO15693_MAX_FRAME_SIZE); return instance; } diff --git a/furi/furi.h b/furi/furi.h index cfdeb2c0..b1299c9a 100644 --- a/furi/furi.h +++ b/furi/furi.h @@ -24,6 +24,9 @@ // FreeRTOS timer, REMOVE AFTER REFACTORING #include +// Workaround for math.h leaking through HAL in older versions +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/nfc/SConscript b/lib/nfc/SConscript index 0e09b693..6c55cf5d 100644 --- a/lib/nfc/SConscript +++ b/lib/nfc/SConscript @@ -51,7 +51,7 @@ env.Append( libenv = env.Clone(FW_LIB_NAME="nfc") libenv.ApplyLibFlags() -sources = libenv.GlobRecursive("*.c*", exclude="deprecated/*c") +sources = libenv.GlobRecursive("*.c*") lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) libenv.Install("${LIB_DIST_DIR}", lib) diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c index 40d99768..fd845f3c 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c @@ -297,7 +297,7 @@ bool mf_ultralight_load(MfUltralightData* data, FlipperFormat* ff, uint32_t vers uint32_t pages_total = 0; if(!flipper_format_read_uint32(ff, MF_ULTRALIGHT_PAGES_TOTAL_KEY, &pages_total, 1)) break; uint32_t pages_read = 0; - if(data_format_version < mf_ultralight_data_format_version) { + if(data_format_version < mf_ultralight_data_format_version) { //-V547 pages_read = pages_total; } else { if(!flipper_format_read_uint32(ff, MF_ULTRALIGHT_PAGES_READ_KEY, &pages_read, 1)) diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c index 3d6b9a94..64647492 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c @@ -518,6 +518,8 @@ static uint16_t mf_ultralight_get_upper_page_bound(MfUltralightType type) { upper_page_bound = 511; else if(type == MfUltralightTypeNTAGI2C2K) upper_page_bound = 479; + else if(type == MfUltralightTypeNTAGI2C1K) + upper_page_bound = 225; else { upper_page_bound = mf_ultralight_get_config_page_num(type) - 2; } diff --git a/lib/signal_reader/parsers/iso15693/iso15693_parser.c b/lib/signal_reader/parsers/iso15693/iso15693_parser.c index a398516c..c5326a35 100644 --- a/lib/signal_reader/parsers/iso15693/iso15693_parser.c +++ b/lib/signal_reader/parsers/iso15693/iso15693_parser.c @@ -68,7 +68,7 @@ Iso15693Parser* iso15693_parser_alloc(const GpioPin* pin, size_t max_frame_size) signal_reader_set_sample_rate( instance->signal_reader, SignalReaderTimeUnit64Mhz, ISO15693_PARSER_BITRATE_F64MHZ); signal_reader_set_pull(instance->signal_reader, GpioPullDown); - signal_reader_set_polarity(instance->signal_reader, SignalReaderPolarityInverted); + signal_reader_set_polarity(instance->signal_reader, SignalReaderPolarityNormal); signal_reader_set_trigger(instance->signal_reader, SignalReaderTriggerRisingFallingEdge); return instance; From cfaf7455232db493f81ce5c036100029fd18bad2 Mon Sep 17 00:00:00 2001 From: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Date: Sat, 28 Oct 2023 17:29:14 +0300 Subject: [PATCH 3/4] [FL-3643] Fix crash when reading files > 64B (#3166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Increase MF DESFire result buffer * Ignore chunks that do not fit into the result buffer and show warning * Display information about partial files Co-authored-by: あく --- .../mf_desfire/mf_desfire_render.c | 18 +++++++++++++++++- .../protocols/mf_desfire/mf_desfire_poller.c | 11 ++++++----- .../protocols/mf_desfire/mf_desfire_poller_i.c | 10 +++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c index b5ca0d13..94b333f5 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c +++ b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c @@ -190,6 +190,8 @@ void nfc_render_mf_desfire_file_settings_data( uint32_t record_count = 1; uint32_t record_size = 0; + const uint32_t total_size = simple_array_get_count(data->data); + switch(settings->type) { case MfDesfireFileTypeStandard: case MfDesfireFileTypeBackup: @@ -220,9 +222,20 @@ void nfc_render_mf_desfire_file_settings_data( } for(uint32_t rec = 0; rec < record_count; rec++) { - furi_string_cat_printf(str, "record %lu\n", rec); + const uint32_t size_offset = rec * record_size; + const uint32_t size_remaining = total_size > size_offset ? total_size - size_offset : 0; + + if(size_remaining < record_size) { + furi_string_cat_printf( + str, "record %lu (partial %lu of %lu)\n", rec, size_remaining, record_size); + record_size = size_remaining; + } else { + furi_string_cat_printf(str, "record %lu\n", rec); + } + for(uint32_t ch = 0; ch < record_size; ch += 4) { furi_string_cat_printf(str, "%03lx|", ch); + for(uint32_t i = 0; i < 4; i++) { if(ch + i < record_size) { const uint32_t data_index = rec * record_size + ch + i; @@ -233,6 +246,7 @@ void nfc_render_mf_desfire_file_settings_data( furi_string_cat_printf(str, " "); } } + for(uint32_t i = 0; i < 4 && ch + i < record_size; i++) { const uint32_t data_index = rec * record_size + ch + i; const uint8_t data_byte = @@ -243,8 +257,10 @@ void nfc_render_mf_desfire_file_settings_data( furi_string_cat_printf(str, "."); } } + furi_string_push_back(str, '\n'); } + furi_string_push_back(str, '\n'); } } diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c b/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c index c74bbc89..11db021d 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c @@ -6,7 +6,8 @@ #define TAG "MfDesfirePoller" -#define MF_DESFIRE_BUF_SIZE_MAX (64U) +#define MF_DESFIRE_BUF_SIZE (64U) +#define MF_DESFIRE_RESULT_BUF_SIZE (512U) typedef NfcCommand (*MfDesfirePollerReadHandler)(MfDesfirePoller* instance); @@ -20,10 +21,10 @@ static MfDesfirePoller* mf_desfire_poller_alloc(Iso14443_4aPoller* iso14443_4a_p MfDesfirePoller* instance = malloc(sizeof(MfDesfirePoller)); instance->iso14443_4a_poller = iso14443_4a_poller; instance->data = mf_desfire_alloc(); - instance->tx_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE_MAX); - instance->rx_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE_MAX); - instance->input_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE_MAX); - instance->result_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE_MAX); + instance->tx_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE); + instance->rx_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE); + instance->input_buffer = bit_buffer_alloc(MF_DESFIRE_BUF_SIZE); + instance->result_buffer = bit_buffer_alloc(MF_DESFIRE_RESULT_BUF_SIZE); instance->mf_desfire_event.data = &instance->mf_desfire_event_data; diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c b/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c index 17377d66..38ae2f46 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_poller_i.c @@ -59,7 +59,15 @@ MfDesfireError mf_desfire_send_chunks( break; } - bit_buffer_append_right(rx_buffer, instance->rx_buffer, sizeof(uint8_t)); + const size_t rx_size = bit_buffer_get_size_bytes(instance->rx_buffer); + const size_t rx_capacity_remaining = + bit_buffer_get_capacity_bytes(rx_buffer) - bit_buffer_get_size_bytes(rx_buffer); + + if(rx_size <= rx_capacity_remaining) { + bit_buffer_append_right(rx_buffer, instance->rx_buffer, sizeof(uint8_t)); + } else { + FURI_LOG_W(TAG, "RX buffer overflow: ignoring %zu bytes", rx_size); + } } } while(false); From 0fe93fcfa48ea08479b72c6650fbf4ccf95d445d Mon Sep 17 00:00:00 2001 From: Augusto Zanellato Date: Sat, 28 Oct 2023 16:45:08 +0200 Subject: [PATCH 4/4] fix crash after st25tb save (#3170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- .../main/nfc/helpers/protocol_support/st25tb/st25tb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/applications/main/nfc/helpers/protocol_support/st25tb/st25tb.c b/applications/main/nfc/helpers/protocol_support/st25tb/st25tb.c index eef723fe..32b2f477 100644 --- a/applications/main/nfc/helpers/protocol_support/st25tb/st25tb.c +++ b/applications/main/nfc/helpers/protocol_support/st25tb/st25tb.c @@ -95,6 +95,11 @@ const NfcProtocolSupportBase nfc_protocol_support_st25tb = { .on_enter = nfc_protocol_support_common_on_enter_empty, .on_event = nfc_scene_saved_menu_on_event_st25tb, }, + .scene_save_name = + { + .on_enter = nfc_protocol_support_common_on_enter_empty, + .on_event = nfc_protocol_support_common_on_event_empty, + }, .scene_emulate = { .on_enter = nfc_protocol_support_common_on_enter_empty,