diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c index 18c1995d9..aa2ed5e9b 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.c @@ -472,11 +472,8 @@ static void nfc_protocol_support_scene_save_name_on_enter(NfcApp* instance) { bool name_is_empty = furi_string_empty(instance->file_name); if(name_is_empty) { furi_string_set(instance->file_path, NFC_APP_FOLDER); - FuriString* prefix = furi_string_alloc_set( - nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeShort)); - furi_string_replace(prefix, "Mifare", "MF"); - furi_string_replace(prefix, "Ultralight", "UL"); - furi_string_replace(prefix, " Plus", "+"); + FuriString* prefix = furi_string_alloc(); + nfc_device_get_abbreviated_name(instance->nfc_device, prefix); furi_string_replace_all(prefix, " ", "_"); name_generator_make_auto( instance->text_store, NFC_TEXT_STORE_SIZE, furi_string_get_cstr(prefix)); diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 267824d16..91705ba59 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -73,6 +73,19 @@ const char* nfc_device_get_name(const NfcDevice* instance, NfcDeviceNameType nam return nfc_devices[instance->protocol]->get_name(instance->protocol_data, name_type); } +void nfc_device_get_abbreviated_name(const NfcDevice* instance, FuriString* name) { + furi_assert(instance); + furi_assert(instance->protocol < NfcProtocolNum); + + furi_string_set(name, nfc_device_get_name(instance, NfcDeviceNameTypeFull)); + furi_string_replace(name, "Mifare", "MF"); + furi_string_replace(name, " Classic", "C"); // MFC + furi_string_replace(name, "Desfire", "Des"); // MF Des + furi_string_replace(name, "Ultralight", "UL"); // MF UL + furi_string_replace(name, " Plus", "+"); // NTAG I2C+ + furi_string_replace(name, " (Unknown)", ""); +} + const uint8_t* nfc_device_get_uid(const NfcDevice* instance, size_t* uid_len) { furi_assert(instance); furi_assert(instance->protocol < NfcProtocolNum); diff --git a/lib/nfc/nfc_device.h b/lib/nfc/nfc_device.h index 6636e7c76..3d8defe11 100644 --- a/lib/nfc/nfc_device.h +++ b/lib/nfc/nfc_device.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "protocols/nfc_device_base.h" #include "protocols/nfc_protocol.h" @@ -137,6 +138,16 @@ const char* nfc_device_get_protocol_name(NfcProtocol protocol); */ const char* nfc_device_get_name(const NfcDevice* instance, NfcDeviceNameType name_type); +/** + * @brief Get the abbreviated name of an NfcDevice instance. + * + * The return value may change depending on the instance's internal state. + * + * @param[in] instance pointer to the instance to be queried. + * @param[out] name FuriString to save the abbreviated device name to. + */ +void nfc_device_get_abbreviated_name(const NfcDevice* instance, FuriString* name); + /** * @brief Get the unique identifier (UID) of an NfcDevice instance. * diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 7dfcb01fa..5e4b68435 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -2578,6 +2578,7 @@ Function,+,nfc_device_alloc,NfcDevice*, Function,+,nfc_device_clear,void,NfcDevice* Function,+,nfc_device_copy_data,void,"const NfcDevice*, NfcProtocol, NfcDeviceData*" Function,+,nfc_device_free,void,NfcDevice* +Function,+,nfc_device_get_abbreviated_name,void,"const NfcDevice*, FuriString*" Function,+,nfc_device_get_data,const NfcDeviceData*,"const NfcDevice*, NfcProtocol" Function,+,nfc_device_get_name,const char*,"const NfcDevice*, NfcDeviceNameType" Function,+,nfc_device_get_protocol,NfcProtocol,const NfcDevice*