Nfc: add basic Mifare DESFire support (#1024)

* Fix TextBox word wrap behavior
* Wrap width is 120 pixels, not 140. (140 is larger than the screen!)
* Glyph width already includes spacing; don't add 1 additional px
* When starting a new line, include wrapped glyph width in new line_width.
* Call canvas_set_font before text_box_insert_endline so that glyph
  width is calculated using correct font.
  Previous approach worked somewhat well using default TextBoxFontText but
  this version is more robust, particularly when using TextBoxFontHex.
* Add basic Mifare DESFire reading, file/app browser
* Fix build with APP_ARCHIVE=0
* Add bool type to flipper_format
* Add ability to save and load DESFire card data
* Skip over NfcSceneDeviceInfo when viewing saved DESFire info
* mf_df_clear: don't leak master key settings key versions
* When opening a DESFire card from Archive, retain UID emulation behavior
* rm unnecessary \r\n
* show Popup instead of leaving view in bad state
* Move NfcReaderRequestData out of union
  This makes it safe to emulate DESFire/EMV without clobbering card data.
* Display saved DESFire cards via NfcSceneDeviceInfo
* Display and save file metadata even when contents are missing
  This can happen when a file doesn't allow unauthenticated reads (see the
  call to mf_df_parse_read_data_response in nfc_worker.c).

Co-authored-by: Kevin Wallace <git+flipperzero@kevin.wallace.seattle.wa.us>
Co-authored-by: あく <alleteam@gmail.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
Kevin Wallace
2022-03-23 06:45:37 -07:00
committed by GitHub
parent d075e00ae1
commit 3857cd7d5f
26 changed files with 1941 additions and 14 deletions

View File

@@ -26,6 +26,10 @@ static const char* test_float_key = "Float data";
static const float test_float_data[] = {1.5f, 1000.0f};
static const float test_float_updated_data[] = {1.2f};
static const char* test_bool_key = "Bool data";
static const bool test_bool_data[] = {true, false};
static const bool test_bool_updated_data[] = {false, true, true};
static const char* test_hex_key = "Hex data";
static const uint8_t test_hex_data[] = {0xDE, 0xAD, 0xBE};
static const uint8_t test_hex_updated_data[] = {0xFE, 0xCA};
@@ -38,6 +42,7 @@ static const char* test_data_nix = "Filetype: Flipper File test\n"
"Int32 data: 1234 -6345 7813 0\n"
"Uint32 data: 1234 0 5678 9098 7654321\n"
"Float data: 1.5 1000.0\n"
"Bool data: true false\n"
"Hex data: DE AD BE";
#define READ_TEST_WIN "ff_win.test"
@@ -48,6 +53,7 @@ static const char* test_data_win = "Filetype: Flipper File test\r\n"
"Int32 data: 1234 -6345 7813 0\r\n"
"Uint32 data: 1234 0 5678 9098 7654321\r\n"
"Float data: 1.5 1000.0\r\n"
"Bool data: true false\r\n"
"Hex data: DE AD BE";
#define READ_TEST_FLP "ff_flp.test"
@@ -129,6 +135,11 @@ static bool test_read(const char* file_name) {
if(memcmp(scratchpad, test_float_data, sizeof(float) * COUNT_OF(test_float_data)) != 0)
break;
if(!flipper_format_get_value_count(file, test_bool_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_bool_data)) break;
if(!flipper_format_read_bool(file, test_bool_key, scratchpad, uint32_value)) break;
if(memcmp(scratchpad, test_bool_data, sizeof(bool) * COUNT_OF(test_bool_data)) != 0) break;
if(!flipper_format_get_value_count(file, test_hex_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_hex_data)) break;
if(!flipper_format_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
@@ -195,6 +206,15 @@ static bool test_read_updated(const char* file_name) {
sizeof(float) * COUNT_OF(test_float_updated_data)) != 0)
break;
if(!flipper_format_get_value_count(file, test_bool_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_bool_updated_data)) break;
if(!flipper_format_read_bool(file, test_bool_key, scratchpad, uint32_value)) break;
if(memcmp(
scratchpad,
test_bool_updated_data,
sizeof(bool) * COUNT_OF(test_bool_updated_data)) != 0)
break;
if(!flipper_format_get_value_count(file, test_hex_key, &uint32_value)) break;
if(uint32_value != COUNT_OF(test_hex_updated_data)) break;
if(!flipper_format_read_hex(file, test_hex_key, scratchpad, uint32_value)) break;
@@ -235,6 +255,9 @@ static bool test_write(const char* file_name) {
if(!flipper_format_write_float(
file, test_float_key, test_float_data, COUNT_OF(test_float_data)))
break;
if(!flipper_format_write_bool(
file, test_bool_key, test_bool_data, COUNT_OF(test_bool_data)))
break;
if(!flipper_format_write_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
break;
result = true;
@@ -299,6 +322,9 @@ static bool test_update(const char* file_name) {
if(!flipper_format_update_float(
file, test_float_key, test_float_updated_data, COUNT_OF(test_float_updated_data)))
break;
if(!flipper_format_update_bool(
file, test_bool_key, test_bool_updated_data, COUNT_OF(test_bool_updated_data)))
break;
if(!flipper_format_update_hex(
file, test_hex_key, test_hex_updated_data, COUNT_OF(test_hex_updated_data)))
break;
@@ -328,6 +354,9 @@ static bool test_update_backward(const char* file_name) {
if(!flipper_format_update_float(
file, test_float_key, test_float_data, COUNT_OF(test_float_data)))
break;
if(!flipper_format_update_bool(
file, test_bool_key, test_bool_data, COUNT_OF(test_bool_data)))
break;
if(!flipper_format_update_hex(file, test_hex_key, test_hex_data, COUNT_OF(test_hex_data)))
break;