mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
mf plus: handle load and save errors
This commit is contained in:
@@ -60,6 +60,7 @@ MfPlusData* mf_plus_alloc(void) {
|
||||
|
||||
void mf_plus_free(MfPlusData* data) {
|
||||
furi_check(data);
|
||||
|
||||
furi_string_free(data->device_name);
|
||||
iso14443_4a_free(data->iso14443_4a_data);
|
||||
free(data);
|
||||
@@ -67,8 +68,8 @@ void mf_plus_free(MfPlusData* data) {
|
||||
|
||||
void mf_plus_reset(MfPlusData* data) {
|
||||
furi_check(data);
|
||||
iso14443_4a_reset(data->iso14443_4a_data);
|
||||
|
||||
iso14443_4a_reset(data->iso14443_4a_data);
|
||||
memset(&data->version, 0, sizeof(data->version));
|
||||
furi_string_reset(data->device_name);
|
||||
data->type = MfPlusTypeUnknown;
|
||||
@@ -79,8 +80,8 @@ void mf_plus_reset(MfPlusData* data) {
|
||||
void mf_plus_copy(MfPlusData* data, const MfPlusData* other) {
|
||||
furi_check(data);
|
||||
furi_check(other);
|
||||
iso14443_4a_copy(data->iso14443_4a_data, other->iso14443_4a_data);
|
||||
|
||||
iso14443_4a_copy(data->iso14443_4a_data, other->iso14443_4a_data);
|
||||
data->version = other->version;
|
||||
data->type = other->type;
|
||||
data->security_level = other->security_level;
|
||||
@@ -93,10 +94,9 @@ bool mf_plus_verify(MfPlusData* data, const FuriString* device_type) {
|
||||
}
|
||||
|
||||
bool mf_plus_load(MfPlusData* data, FlipperFormat* ff, uint32_t version) {
|
||||
furi_assert(data);
|
||||
furi_check(data);
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!iso14443_4a_load(data->iso14443_4a_data, ff, version)) break;
|
||||
if(!mf_plus_version_load(&data->version, ff)) break;
|
||||
@@ -110,10 +110,9 @@ bool mf_plus_load(MfPlusData* data, FlipperFormat* ff, uint32_t version) {
|
||||
}
|
||||
|
||||
bool mf_plus_save(const MfPlusData* data, FlipperFormat* ff) {
|
||||
furi_assert(data);
|
||||
furi_check(data);
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!iso14443_4a_save(data->iso14443_4a_data, ff)) break;
|
||||
if(!flipper_format_write_comment_cstr(ff, MF_PLUS_PROTOCOL_NAME " specific data")) break;
|
||||
@@ -128,10 +127,10 @@ bool mf_plus_save(const MfPlusData* data, FlipperFormat* ff) {
|
||||
}
|
||||
|
||||
bool mf_plus_is_equal(const MfPlusData* data, const MfPlusData* other) {
|
||||
furi_assert(data);
|
||||
furi_assert(other);
|
||||
bool equal = false;
|
||||
furi_check(data);
|
||||
furi_check(other);
|
||||
|
||||
bool equal = false;
|
||||
do {
|
||||
if(!iso14443_4a_is_equal(data->iso14443_4a_data, other->iso14443_4a_data)) break;
|
||||
if(memcmp(&data->version, &other->version, sizeof(data->version)) != 0) break;
|
||||
@@ -147,44 +146,35 @@ bool mf_plus_is_equal(const MfPlusData* data, const MfPlusData* other) {
|
||||
const char* mf_plus_get_device_name(const MfPlusData* data, NfcDeviceNameType name_type) {
|
||||
furi_check(data);
|
||||
|
||||
FuriString* full_name = furi_string_alloc();
|
||||
const char* name = NULL;
|
||||
if(name_type == NfcDeviceNameTypeFull) {
|
||||
furi_string_printf(
|
||||
data->device_name,
|
||||
"Mifare %s %s %s",
|
||||
mf_plus_type_strings[data->type], // Includes "Plus" for regular Mifare Plus cards
|
||||
mf_plus_size_strings[data->size],
|
||||
mf_plus_security_level_strings[data->security_level]);
|
||||
} else if(name_type == NfcDeviceNameTypeShort) {
|
||||
furi_string_set_str(data->device_name, MF_PLUS_PROTOCOL_NAME);
|
||||
} else {
|
||||
furi_crash("Unexpected name type");
|
||||
}
|
||||
|
||||
do {
|
||||
if(name_type == NfcDeviceNameTypeFull) {
|
||||
furi_string_reset(data->device_name);
|
||||
furi_string_cat_printf(
|
||||
data->device_name,
|
||||
"Mifare %s %s %s",
|
||||
mf_plus_type_strings[data->type], // Includes "Plus" for regular Mifare Plus cards
|
||||
mf_plus_size_strings[data->size],
|
||||
mf_plus_security_level_strings[data->security_level]);
|
||||
name = furi_string_get_cstr(data->device_name);
|
||||
FURI_LOG_D("Mifare Plus", "Full name: %s", name);
|
||||
} else if(name_type == NfcDeviceNameTypeShort) {
|
||||
name = "Mifare Plus";
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
furi_string_free(full_name);
|
||||
FURI_LOG_D("Mifare Plus", "Name: %s", name);
|
||||
return name;
|
||||
return furi_string_get_cstr(data->device_name);
|
||||
}
|
||||
|
||||
const uint8_t* mf_plus_get_uid(const MfPlusData* data, size_t* uid_len) {
|
||||
furi_assert(data);
|
||||
furi_check(data);
|
||||
|
||||
return iso14443_4a_get_uid(data->iso14443_4a_data, uid_len);
|
||||
}
|
||||
|
||||
bool mf_plus_set_uid(MfPlusData* data, const uint8_t* uid, size_t uid_len) {
|
||||
furi_assert(data);
|
||||
furi_check(data);
|
||||
|
||||
return iso14443_4a_set_uid(data->iso14443_4a_data, uid, uid_len);
|
||||
}
|
||||
Iso14443_4aData* mf_plus_get_base_data(const MfPlusData* data) {
|
||||
furi_check(data);
|
||||
|
||||
return data->iso14443_4a_data;
|
||||
}
|
||||
@@ -341,10 +341,11 @@ bool mf_plus_security_level_save(const MfPlusSecurityLevel* data, FlipperFormat*
|
||||
break;
|
||||
}
|
||||
|
||||
flipper_format_write_string(ff, MF_PLUS_FFF_SECURITY_LEVEL_KEY, security_level_string);
|
||||
bool success =
|
||||
flipper_format_write_string(ff, MF_PLUS_FFF_SECURITY_LEVEL_KEY, security_level_string);
|
||||
furi_string_free(security_level_string);
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool mf_plus_type_save(const MfPlusType* data, FlipperFormat* ff) {
|
||||
@@ -374,10 +375,10 @@ bool mf_plus_type_save(const MfPlusType* data, FlipperFormat* ff) {
|
||||
break;
|
||||
}
|
||||
|
||||
flipper_format_write_string(ff, MF_PLUS_FFF_CARD_TYPE_KEY, type_string);
|
||||
bool success = flipper_format_write_string(ff, MF_PLUS_FFF_CARD_TYPE_KEY, type_string);
|
||||
furi_string_free(type_string);
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool mf_plus_size_save(const MfPlusSize* data, FlipperFormat* ff) {
|
||||
@@ -398,8 +399,8 @@ bool mf_plus_size_save(const MfPlusSize* data, FlipperFormat* ff) {
|
||||
break;
|
||||
}
|
||||
|
||||
flipper_format_write_string(ff, MF_PLUS_FFF_MEMORY_SIZE_KEY, size_string);
|
||||
bool success = flipper_format_write_string(ff, MF_PLUS_FFF_MEMORY_SIZE_KEY, size_string);
|
||||
furi_string_free(size_string);
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user