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

27
applications/nfc/scenes/nfc_scene_device_info.c Executable file → Normal file
View File

@@ -32,7 +32,7 @@ void nfc_scene_device_info_on_enter(void* context) {
// Setup Custom Widget view
widget_add_text_box_element(
nfc->widget, 0, 0, 128, 22, AlignCenter, AlignCenter, nfc->dev->dev_name);
nfc->widget, 0, 0, 128, 22, AlignCenter, AlignTop, nfc->dev->dev_name);
widget_add_button_element(
nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_device_info_widget_callback, nfc);
widget_add_button_element(
@@ -64,7 +64,8 @@ void nfc_scene_device_info_on_enter(void* context) {
widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
const char* protocol_name = NULL;
if(data->protocol == NfcDeviceProtocolEMV) {
if(data->protocol == NfcDeviceProtocolEMV ||
data->protocol == NfcDeviceProtocolMifareDesfire) {
protocol_name = nfc_guess_protocol(data->protocol);
} else if(data->protocol == NfcDeviceProtocolMifareUl) {
protocol_name = nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, false);
@@ -101,6 +102,25 @@ void nfc_scene_device_info_on_enter(void* context) {
nfc->text_box_store, "%02X%02X ", mf_ul_data->data[i], mf_ul_data->data[i + 1]);
}
text_box_set_text(text_box, string_get_cstr(nfc->text_box_store));
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) {
MifareDesfireData* mf_df_data = &nfc->dev->dev_data.mf_df_data;
uint16_t n_apps = 0;
uint16_t n_files = 0;
for(MifareDesfireApplication* app = mf_df_data->app_head; app; app = app->next) {
n_apps++;
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
n_files++;
}
}
nfc_text_store_set(
nfc,
"%d application%s, %d file%s",
n_apps,
n_apps == 1 ? "" : "s",
n_files,
n_files == 1 ? "" : "s");
widget_add_string_element(
nfc->widget, 64, 17, AlignCenter, AlignBottom, FontSecondary, nfc->text_store);
} else if(nfc->dev->format == NfcDeviceSaveFormatBankCard) {
NfcEmvData* emv_data = &nfc->dev->dev_data.emv_data;
BankCard* bank_card = nfc->bank_card;
@@ -162,6 +182,9 @@ bool nfc_scene_device_info_on_event(void* context, SceneManagerEvent event) {
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoData);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewBankCard);
consumed = true;
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMifareDesfireData);
consumed = true;
}
} else if(state == NfcSceneDeviceInfoData && event.event == NfcCustomEventViewExit) {
scene_manager_set_scene_state(