[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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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";
|
||||
}
|
||||
}
|
||||
|
13
applications/nfc/nfc_worker.c
Normal file → Executable file
13
applications/nfc/nfc_worker.c
Normal file → Executable file
@@ -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;
|
||||
}
|
||||
|
@@ -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");
|
||||
|
@@ -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");
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user