mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-27 06:50:21 +00:00
[FL-3648] Mf DESFire fixes (#3367)
* mf desfire: process loading applications with 0 files * mf desfire: add HID desfire support * nfc: fix mfdes loading and rendering crashes * mf desfire: change handling HID cards * mf desfire: fix PVS warnings * mf desfire: fix cmp logic Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
7981cb832e
commit
7db8d5aa82
2 changed files with 59 additions and 39 deletions
|
@ -252,7 +252,12 @@ const uint8_t* iso14443_4a_get_historical_bytes(const Iso14443_4aData* data, uin
|
||||||
furi_assert(count);
|
furi_assert(count);
|
||||||
|
|
||||||
*count = simple_array_get_count(data->ats_data.t1_tk);
|
*count = simple_array_get_count(data->ats_data.t1_tk);
|
||||||
return simple_array_cget_data(data->ats_data.t1_tk);
|
const uint8_t* hist_bytes = NULL;
|
||||||
|
if(*count > 0) {
|
||||||
|
hist_bytes = simple_array_cget_data(data->ats_data.t1_tk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hist_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool iso14443_4a_supports_bit_rate(const Iso14443_4aData* data, Iso14443_4aBitRate bit_rate) {
|
bool iso14443_4a_supports_bit_rate(const Iso14443_4aData* data, Iso14443_4aBitRate bit_rate) {
|
||||||
|
|
|
@ -179,44 +179,53 @@ bool mf_desfire_file_settings_parse(MfDesfireFileSettings* data, const BitBuffer
|
||||||
const size_t data_size = bit_buffer_get_size_bytes(buf);
|
const size_t data_size = bit_buffer_get_size_bytes(buf);
|
||||||
const size_t min_data_size =
|
const size_t min_data_size =
|
||||||
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsData);
|
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsData);
|
||||||
|
const size_t max_data_size =
|
||||||
|
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsValue);
|
||||||
|
|
||||||
if(data_size < min_data_size) break;
|
if(data_size < min_data_size) break;
|
||||||
|
if(data_size <= max_data_size) {
|
||||||
|
MfDesfireFileSettingsLayout layout;
|
||||||
|
bit_buffer_write_bytes(buf, &layout, sizeof(MfDesfireFileSettingsLayout));
|
||||||
|
|
||||||
MfDesfireFileSettingsLayout layout;
|
data->type = layout.header.type;
|
||||||
bit_buffer_write_bytes(buf, &layout, sizeof(MfDesfireFileSettingsLayout));
|
data->comm = layout.header.comm;
|
||||||
|
data->access_rights = layout.header.access_rights;
|
||||||
|
|
||||||
data->type = layout.header.type;
|
if(data->type == MfDesfireFileTypeStandard || data->type == MfDesfireFileTypeBackup) {
|
||||||
data->comm = layout.header.comm;
|
if(data_size != min_data_size) break;
|
||||||
data->access_rights = layout.header.access_rights;
|
|
||||||
|
|
||||||
if(data->type == MfDesfireFileTypeStandard || data->type == MfDesfireFileTypeBackup) {
|
data->data.size = layout.data.size;
|
||||||
if(data_size != min_data_size) break;
|
} else if(data->type == MfDesfireFileTypeValue) {
|
||||||
|
if(data_size !=
|
||||||
|
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsValue))
|
||||||
|
break;
|
||||||
|
|
||||||
data->data.size = layout.data.size;
|
data->value.lo_limit = layout.value.lo_limit;
|
||||||
|
data->value.hi_limit = layout.value.hi_limit;
|
||||||
|
data->value.limited_credit_value = layout.value.limited_credit_value;
|
||||||
|
data->value.limited_credit_enabled = layout.value.limited_credit_enabled;
|
||||||
|
|
||||||
} else if(data->type == MfDesfireFileTypeValue) {
|
} else if(
|
||||||
if(data_size !=
|
data->type == MfDesfireFileTypeLinearRecord ||
|
||||||
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsValue))
|
data->type == MfDesfireFileTypeCyclicRecord) {
|
||||||
|
if(data_size !=
|
||||||
|
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsRecord))
|
||||||
|
break;
|
||||||
|
|
||||||
|
data->record.size = layout.record.size;
|
||||||
|
data->record.max = layout.record.max;
|
||||||
|
data->record.cur = layout.record.cur;
|
||||||
|
|
||||||
|
} else {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
data->value.lo_limit = layout.value.lo_limit;
|
|
||||||
data->value.hi_limit = layout.value.hi_limit;
|
|
||||||
data->value.limited_credit_value = layout.value.limited_credit_value;
|
|
||||||
data->value.limited_credit_enabled = layout.value.limited_credit_enabled;
|
|
||||||
|
|
||||||
} else if(
|
|
||||||
data->type == MfDesfireFileTypeLinearRecord ||
|
|
||||||
data->type == MfDesfireFileTypeCyclicRecord) {
|
|
||||||
if(data_size !=
|
|
||||||
sizeof(MfDesfireFileSettingsHeader) + sizeof(MfDesfireFileSettingsRecord))
|
|
||||||
break;
|
|
||||||
|
|
||||||
data->record.size = layout.record.size;
|
|
||||||
data->record.max = layout.record.max;
|
|
||||||
data->record.cur = layout.record.cur;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
// TODO FL-3750: process HID Desfire command response here
|
||||||
|
// Set default fields for now
|
||||||
|
data->type = 0;
|
||||||
|
data->comm = 0;
|
||||||
|
data->access_rights = 0;
|
||||||
|
data->data.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed = true;
|
parsed = true;
|
||||||
|
@ -478,19 +487,25 @@ bool mf_desfire_application_load(MfDesfireApplication* data, const char* prefix,
|
||||||
do {
|
do {
|
||||||
if(!mf_desfire_key_settings_load(&data->key_settings, prefix, ff)) break;
|
if(!mf_desfire_key_settings_load(&data->key_settings, prefix, ff)) break;
|
||||||
|
|
||||||
const uint32_t key_version_count = data->key_settings.max_keys;
|
|
||||||
simple_array_init(data->key_versions, key_version_count);
|
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for(i = 0; i < key_version_count; ++i) {
|
const uint32_t key_version_count = data->key_settings.max_keys;
|
||||||
if(!mf_desfire_key_version_load(simple_array_get(data->key_versions, i), prefix, i, ff))
|
if(key_version_count) {
|
||||||
break;
|
simple_array_init(data->key_versions, key_version_count);
|
||||||
|
|
||||||
|
for(i = 0; i < key_version_count; ++i) {
|
||||||
|
if(!mf_desfire_key_version_load(
|
||||||
|
simple_array_get(data->key_versions, i), prefix, i, ff))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i != key_version_count) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i != key_version_count) break;
|
|
||||||
|
|
||||||
uint32_t file_count;
|
uint32_t file_count;
|
||||||
if(!mf_desfire_file_count_load(&file_count, prefix, ff)) break;
|
if(!mf_desfire_file_count_load(&file_count, prefix, ff)) {
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
simple_array_init(data->file_ids, file_count);
|
simple_array_init(data->file_ids, file_count);
|
||||||
if(!mf_desfire_file_ids_load(simple_array_get_data(data->file_ids), file_count, prefix, ff))
|
if(!mf_desfire_file_ids_load(simple_array_get_data(data->file_ids), file_count, prefix, ff))
|
||||||
|
|
Loading…
Reference in a new issue