mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-01 22:08:55 -07:00
1941 lines
76 KiB
C
1941 lines
76 KiB
C
#include "nfc_device.h"
|
|
#include "assets_icons.h"
|
|
#include "nfc_types.h"
|
|
|
|
#include <lib/toolbox/path.h>
|
|
#include <lib/toolbox/hex.h>
|
|
#include <lib/nfc/protocols/nfc_util.h>
|
|
#include <flipper_format/flipper_format.h>
|
|
|
|
#define TAG "NfcDevice"
|
|
#define NFC_DEVICE_KEYS_FOLDER EXT_PATH("nfc/.cache")
|
|
#define NFC_DEVICE_KEYS_EXTENSION ".keys"
|
|
|
|
static const char* nfc_file_header = "Flipper NFC device";
|
|
static const uint32_t nfc_file_version = 3;
|
|
|
|
static const char* nfc_keys_file_header = "Flipper NFC keys";
|
|
static const uint32_t nfc_keys_file_version = 1;
|
|
|
|
// Protocols format versions
|
|
static const uint32_t nfc_mifare_classic_data_format_version = 2;
|
|
static const uint32_t nfc_mifare_ultralight_data_format_version = 1;
|
|
static const uint32_t nfc_felica_data_format_version = 1;
|
|
|
|
NfcDevice* nfc_device_alloc() {
|
|
NfcDevice* nfc_dev = malloc(sizeof(NfcDevice));
|
|
nfc_dev->storage = furi_record_open(RECORD_STORAGE);
|
|
nfc_dev->dialogs = furi_record_open(RECORD_DIALOGS);
|
|
nfc_dev->load_path = furi_string_alloc();
|
|
nfc_dev->dev_data.parsed_data = furi_string_alloc();
|
|
nfc_dev->folder = furi_string_alloc();
|
|
|
|
// Rename cache folder name for backward compatibility
|
|
if(storage_common_stat(nfc_dev->storage, "/ext/nfc/cache", NULL) == FSE_OK) {
|
|
storage_common_rename(nfc_dev->storage, "/ext/nfc/cache", NFC_DEVICE_KEYS_FOLDER);
|
|
}
|
|
return nfc_dev;
|
|
}
|
|
|
|
void nfc_device_free(NfcDevice* nfc_dev) {
|
|
furi_assert(nfc_dev);
|
|
nfc_device_clear(nfc_dev);
|
|
furi_record_close(RECORD_STORAGE);
|
|
furi_record_close(RECORD_DIALOGS);
|
|
furi_string_free(nfc_dev->load_path);
|
|
furi_string_free(nfc_dev->dev_data.parsed_data);
|
|
furi_string_free(nfc_dev->folder);
|
|
free(nfc_dev);
|
|
}
|
|
|
|
static void nfc_device_prepare_format_string(NfcDevice* dev, FuriString* format_string) {
|
|
if(dev->format == NfcDeviceSaveFormatUid) {
|
|
furi_string_set(format_string, "UID");
|
|
} else if(dev->format == NfcDeviceSaveFormatBankCard) {
|
|
furi_string_set(format_string, "Bank card");
|
|
} else if(dev->format == NfcDeviceSaveFormatMifareUl) {
|
|
furi_string_set(format_string, nfc_mf_ul_type(dev->dev_data.mf_ul_data.type, true));
|
|
} else if(dev->format == NfcDeviceSaveFormatMifareClassic) {
|
|
furi_string_set(format_string, "Mifare Classic");
|
|
} else if(dev->format == NfcDeviceSaveFormatMifareDesfire) {
|
|
furi_string_set(format_string, "Mifare DESFire");
|
|
} else if(dev->format == NfcDeviceSaveFormatNfcV) {
|
|
furi_string_set(format_string, "ISO15693");
|
|
} else if(dev->format == NfcDeviceSaveFormatFelica) {
|
|
furi_string_set(format_string, "FeliCa");
|
|
} else {
|
|
furi_string_set(format_string, "Unknown");
|
|
}
|
|
}
|
|
|
|
static bool nfc_device_parse_format_string(NfcDevice* dev, FuriString* format_string) {
|
|
if(furi_string_start_with_str(format_string, "UID")) {
|
|
dev->format = NfcDeviceSaveFormatUid;
|
|
dev->dev_data.protocol = NfcDeviceProtocolUnknown;
|
|
return true;
|
|
}
|
|
if(furi_string_start_with_str(format_string, "Bank card")) {
|
|
dev->format = NfcDeviceSaveFormatBankCard;
|
|
dev->dev_data.protocol = |