diff options
author | gornekich <n.gorbadey@gmail.com> | 2021-12-21 15:33:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-21 15:33:17 +0300 |
commit | b0f582df9950c2a1a18c4f3b8a9a4fe4da4a3613 (patch) | |
tree | bc4e9396140202df0bb8642291532e27ab4bff9e /applications/nfc | |
parent | 439fb9c18dde63e3b4420e618978226ab50e75ff (diff) |
[FL-1972], [FL-1920] Mifare Ultralight and NTAG separation (#918)
* nfc: rename read mifare ultralight menu
* nfc: separate ntag and mifare ultralight
* nfc: save Mifare Ultralight type
* nfc: add valid ack and nack messages
* nfc: add compatible write command implementation
* nfc: support f6 target
Diffstat (limited to 'applications/nfc')
-rwxr-xr-x | applications/nfc/nfc_device.c | 19 | ||||
-rw-r--r-- | applications/nfc/nfc_types.h | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | applications/nfc/nfc_worker.c | 13 | ||||
-rwxr-xr-x | applications/nfc/scenes/nfc_scene_delete.c | 16 | ||||
-rwxr-xr-x | applications/nfc/scenes/nfc_scene_device_info.c | 16 | ||||
-rwxr-xr-x | applications/nfc/scenes/nfc_scene_read_card_success.c | 4 | ||||
-rwxr-xr-x | applications/nfc/scenes/nfc_scene_read_mifare_ul_success.c | 5 | ||||
-rwxr-xr-x | applications/nfc/scenes/nfc_scene_scripts_menu.c | 2 |
8 files changed, 62 insertions, 33 deletions
diff --git a/applications/nfc/nfc_device.c b/applications/nfc/nfc_device.c index 17a261f2..cfd0db2d 100755 --- a/applications/nfc/nfc_device.c +++ b/applications/nfc/nfc_device.c @@ -1,4 +1,5 @@ #include "nfc_device.h" +#include "nfc_types.h" #include <lib/toolbox/path.h> #include <lib/flipper_file/flipper_file.h> @@ -29,7 +30,7 @@ void nfc_device_prepare_format_string(NfcDevice* dev, string_t format_string) { } else if(dev->format == NfcDeviceSaveFormatBankCard) { string_set_str(format_string, "Bank card"); } else if(dev->format == NfcDeviceSaveFormatMifareUl) { - string_set_str(format_string, "Mifare Ultralight"); + string_set_str(format_string, nfc_mf_ul_type(dev->dev_data.mf_ul_data.type, true)); } else { string_set_str(format_string, "Unknown"); } @@ -40,14 +41,20 @@ bool nfc_device_parse_format_string(NfcDevice* dev, string_t format_string) { dev->format = NfcDeviceSaveFormatUid; dev->dev_data.nfc_data.protocol = NfcDeviceProtocolUnknown; return true; - } else if(string_start_with_str_p(format_string, "Bank card")) { + } + if(string_start_with_str_p(format_string, "Bank card")) { dev->format = NfcDeviceSaveFormatBankCard; dev->dev_data.nfc_data.protocol = NfcDeviceProtocolEMV; return true; - } else if(string_start_with_str_p(format_string, "Mifare Ultralight")) { - dev->format = NfcDeviceSaveFormatMifareUl; - dev->dev_data.nfc_data.protocol = NfcDeviceProtocolMifareUl; - return true; + } + // Check Mifare Ultralight types + for(MfUltralightType type = MfUltralightTypeUnknown; type < MfUltralightTypeNum; type++) { + if(string_start_with_str_p(format_string, nfc_mf_ul_type(type, true))) { + dev->format = NfcDeviceSaveFormatMifareUl; + dev->dev_data.nfc_data.protocol = NfcDeviceProtocolMifareUl; + dev->dev_data.mf_ul_data.type = type; + return true; + } } return false; } diff --git a/applications/nfc/nfc_types.h b/applications/nfc/nfc_types.h index 6c37076a..12bcc093 100644 --- a/applications/nfc/nfc_types.h +++ b/applications/nfc/nfc_types.h @@ -54,12 +54,28 @@ static inline const char* nfc_get_nfca_type(rfalNfcaListenDeviceType type) { } } -static inline const char* nfc_get_protocol(NfcProtocol protocol) { +static inline const char* nfc_guess_protocol(NfcProtocol protocol) { if(protocol == NfcDeviceProtocolEMV) { return "EMV bank card"; } else if(protocol == NfcDeviceProtocolMifareUl) { - return "Mifare Ultralight"; + return "Mifare Ultral/NTAG"; } else { return "Unrecognized"; } } + +static inline const char* nfc_mf_ul_type(MfUltralightType type, bool full_name) { + if(type == MfUltralightTypeNTAG213) { + return "NTAG213"; + } else if(type == MfUltralightTypeNTAG215) { + return "NTAG215"; + } else if(type == MfUltralightTypeNTAG216) { + return "NTAG216"; + } else if(type == MfUltralightTypeUL11 && full_name) { + return "Mifare Ultralight 11"; + } else if(type == MfUltralightTypeUL21 && full_name) { + return "Mifare Ultralight 21"; + } else { + return "Mifare Ultralight"; + } +} diff --git a/applications/nfc/nfc_worker.c b/applications/nfc/nfc_worker.c index 5f810cf6..ad1aa6e5 100644..100755 --- a/applications/nfc/nfc_worker.c +++ b/applications/nfc/nfc_worker.c @@ -503,7 +503,7 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { FURI_LOG_D( TAG, "Mifare Ultralight Type: %d, Pages: %d", - mf_ul_read.type, + mf_ul_read.data.type, mf_ul_read.pages_to_read); FURI_LOG_D(TAG, "Reading signature ..."); tx_len = mf_ul_prepare_read_signature(tx_buff); @@ -629,8 +629,14 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { tx_len = mf_ul_prepare_emulation_response( rx_buff, *rx_len, tx_buff, &mf_ul_emulate); if(tx_len > 0) { - err = - furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); + if(tx_len < 8) { + err = furi_hal_nfc_raw_bitstream_exchange( + tx_buff, tx_len, &rx_buff, &rx_len, false); + *rx_len /= 8; + } else { + err = furi_hal_nfc_data_exchange( + tx_buff, tx_len / 8, &rx_buff, &rx_len, false); + } if(err == ERR_NONE) { continue; } else { @@ -638,7 +644,6 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { break; } } else { - FURI_LOG_D(TAG, "Not valid command: %02X", rx_buff[0]); furi_hal_nfc_deactivate(); break; } diff --git a/applications/nfc/scenes/nfc_scene_delete.c b/applications/nfc/scenes/nfc_scene_delete.c index 498e6ecd..d67511c4 100755 --- a/applications/nfc/scenes/nfc_scene_delete.c +++ b/applications/nfc/scenes/nfc_scene_delete.c @@ -44,15 +44,15 @@ void nfc_scene_delete_on_enter(void* context) { } widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); - if(data->protocol > NfcDeviceProtocolUnknown) { + const char* protocol_name = NULL; + if(data->protocol == NfcDeviceProtocolEMV) { + 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); + } + if(protocol_name) { widget_add_string_element( - nfc->widget, - 10, - 32, - AlignLeft, - AlignTop, - FontSecondary, - nfc_get_protocol(data->protocol)); + nfc->widget, 10, 32, AlignLeft, AlignTop, FontSecondary, protocol_name); } // TODO change dinamically widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); diff --git a/applications/nfc/scenes/nfc_scene_device_info.c b/applications/nfc/scenes/nfc_scene_device_info.c index 1495c127..659ced9d 100755 --- a/applications/nfc/scenes/nfc_scene_device_info.c +++ b/applications/nfc/scenes/nfc_scene_device_info.c @@ -68,15 +68,15 @@ void nfc_scene_device_info_on_enter(void* context) { } widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str); - if(data->protocol > NfcDeviceProtocolUnknown) { + const char* protocol_name = NULL; + if(data->protocol == NfcDeviceProtocolEMV) { + 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); + } + if(protocol_name) { widget_add_string_element( - nfc->widget, - 10, - 32, - AlignLeft, - AlignTop, - FontSecondary, - nfc_get_protocol(data->protocol)); + nfc->widget, 10, 32, AlignLeft, AlignTop, FontSecondary, protocol_name); } // TODO change dinamically widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A"); diff --git a/applications/nfc/scenes/nfc_scene_read_card_success.c b/applications/nfc/scenes/nfc_scene_read_card_success.c index c70bf1b2..d03dc831 100755 --- a/applications/nfc/scenes/nfc_scene_read_card_success.c +++ b/applications/nfc/scenes/nfc_scene_read_card_success.c @@ -27,7 +27,7 @@ void nfc_scene_read_card_success_on_enter(void* context) { nfc, NFC_SCENE_READ_SUCCESS_SHIFT "%s\n" NFC_SCENE_READ_SUCCESS_SHIFT "ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X", - nfc_get_protocol(data->protocol), + nfc_guess_protocol(data->protocol), data->atqa[0], data->atqa[1], data->sak, @@ -41,7 +41,7 @@ void nfc_scene_read_card_success_on_enter(void* context) { NFC_SCENE_READ_SUCCESS_SHIFT "%s\n" NFC_SCENE_READ_SUCCESS_SHIFT "ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X %02X %02X %02X", - nfc_get_protocol(data->protocol), + nfc_guess_protocol(data->protocol), data->atqa[0], data->atqa[1], data->sak, diff --git a/applications/nfc/scenes/nfc_scene_read_mifare_ul_success.c b/applications/nfc/scenes/nfc_scene_read_mifare_ul_success.c index 9c8dfc78..a11af2b5 100755 --- a/applications/nfc/scenes/nfc_scene_read_mifare_ul_success.c +++ b/applications/nfc/scenes/nfc_scene_read_mifare_ul_success.c @@ -28,11 +28,13 @@ void nfc_scene_read_mifare_ul_success_on_enter(void* context) { // Setup dialog view NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data; + MifareUlData* mf_ul_data = &nfc->dev->dev_data.mf_ul_data; DialogEx* dialog_ex = nfc->dialog_ex; dialog_ex_set_left_button_text(dialog_ex, "Retry"); dialog_ex_set_right_button_text(dialog_ex, "More"); dialog_ex_set_center_button_text(dialog_ex, "Data"); - dialog_ex_set_header(dialog_ex, "Mifare Ultralight", 22, 8, AlignLeft, AlignCenter); + dialog_ex_set_header( + dialog_ex, nfc_mf_ul_type(mf_ul_data->type, true), 64, 8, AlignCenter, AlignCenter); dialog_ex_set_icon(dialog_ex, 8, 13, &I_Medium_chip_22x21); // Display UID nfc_text_store_set( @@ -54,7 +56,6 @@ void nfc_scene_read_mifare_ul_success_on_enter(void* context) { dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_mifare_ul_success_dialog_callback); // Setup TextBox view - MifareUlData* mf_ul_data = &nfc->dev->dev_data.mf_ul_data; TextBox* text_box = nfc->text_box; text_box_set_context(text_box, nfc); text_box_set_exit_callback(text_box, nfc_scene_read_mifare_ul_success_text_box_callback); diff --git a/applications/nfc/scenes/nfc_scene_scripts_menu.c b/applications/nfc/scenes/nfc_scene_scripts_menu.c index c82c4564..ffb856d3 100755 --- a/applications/nfc/scenes/nfc_scene_scripts_menu.c +++ b/applications/nfc/scenes/nfc_scene_scripts_menu.c @@ -23,7 +23,7 @@ void nfc_scene_scripts_menu_on_enter(void* context) { nfc); submenu_add_item( submenu, - "Read Mifare Ultralight", + "Read Mifare Ultral/Ntag", SubmenuIndexMifareUltralight, nfc_scene_scripts_menu_submenu_callback, nfc); |