[FL-2182] NFC-V UID show fix (#955)

* nfc: rework static inline functions
* nfc: show uid for NFC-B,F,V
This commit is contained in:
gornekich 2022-01-12 17:02:20 +03:00 committed by GitHub
parent a0c16e8a19
commit 407f68c08a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 129 deletions

View File

@ -0,0 +1,75 @@
#include "nfc_types.h"
const char* nfc_get_rfal_type(rfalNfcDevType type) {
if(type == RFAL_NFC_LISTEN_TYPE_NFCA) {
return "NFC-A";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCB) {
return "NFC-B";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCF) {
return "NFC-F";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCV) {
return "NFC-V";
} else if(type == RFAL_NFC_LISTEN_TYPE_ST25TB) {
return "NFC-ST25TB";
} else if(type == RFAL_NFC_LISTEN_TYPE_AP2P) {
return "NFC-AP2P";
} else {
return "Unknown";
}
}
const char* nfc_get_dev_type(NfcDeviceType type) {
if(type == NfcDeviceNfca) {
return "NFC-A";
} else if(type == NfcDeviceNfcb) {
return "NFC-B";
} else if(type == NfcDeviceNfcf) {
return "NFC-F";
} else if(type == NfcDeviceNfcv) {
return "NFC-V";
} else {
return "Unknown";
}
}
const char* nfc_get_nfca_type(rfalNfcaListenDeviceType type) {
if(type == RFAL_NFCA_T1T) {
return "T1T";
} else if(type == RFAL_NFCA_T2T) {
return "T2T";
} else if(type == RFAL_NFCA_T4T) {
return "T4T";
} else if(type == RFAL_NFCA_NFCDEP) {
return "NFCDEP";
} else if(type == RFAL_NFCA_T4T_NFCDEP) {
return "T4T_NFCDEP";
} else {
return "Unknown";
}
}
const char* nfc_guess_protocol(NfcProtocol protocol) {
if(protocol == NfcDeviceProtocolEMV) {
return "EMV bank card";
} else if(protocol == NfcDeviceProtocolMifareUl) {
return "Mifare Ultral/NTAG";
} else {
return "Unrecognized";
}
}
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";
}
}

View File

@ -6,76 +6,12 @@
#include <gui/view_dispatcher.h> #include <gui/view_dispatcher.h>
#include "nfc_worker.h" #include "nfc_worker.h"
static inline const char* nfc_get_rfal_type(rfalNfcDevType type) { const char* nfc_get_rfal_type(rfalNfcDevType type);
if(type == RFAL_NFC_LISTEN_TYPE_NFCA) {
return "NFC-A";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCB) {
return "NFC-B";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCF) {
return "NFC-F";
} else if(type == RFAL_NFC_LISTEN_TYPE_NFCV) {
return "NFC-V";
} else if(type == RFAL_NFC_LISTEN_TYPE_ST25TB) {
return "NFC-ST25TB";
} else if(type == RFAL_NFC_LISTEN_TYPE_AP2P) {
return "NFC-AP2P";
} else {
return "Unknown";
}
}
static inline const char* nfc_get_dev_type(NfcDeviceType type) { const char* nfc_get_dev_type(NfcDeviceType type);
if(type == NfcDeviceNfca) {
return "NFC-A may be:";
} else if(type == NfcDeviceNfcb) {
return "NFC-B may be:";
} else if(type == NfcDeviceNfcf) {
return "NFC-F may be:";
} else if(type == NfcDeviceNfcv) {
return "NFC-V may be:";
} else {
return "Unknown";
}
}
static inline const char* nfc_get_nfca_type(rfalNfcaListenDeviceType type) { const char* nfc_get_nfca_type(rfalNfcaListenDeviceType type);
if(type == RFAL_NFCA_T1T) {
return "T1T";
} else if(type == RFAL_NFCA_T2T) {
return "T2T";
} else if(type == RFAL_NFCA_T4T) {
return "T4T";
} else if(type == RFAL_NFCA_NFCDEP) {
return "NFCDEP";
} else if(type == RFAL_NFCA_T4T_NFCDEP) {
return "T4T_NFCDEP";
} else {
return "Unknown";
}
}
static inline const char* nfc_guess_protocol(NfcProtocol protocol) { const char* nfc_guess_protocol(NfcProtocol protocol);
if(protocol == NfcDeviceProtocolEMV) {
return "EMV bank card";
} else if(protocol == NfcDeviceProtocolMifareUl) {
return "Mifare Ultral/NTAG";
} else {
return "Unrecognized";
}
}
static inline const char* nfc_mf_ul_type(MfUltralightType type, bool full_name) { 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";
}
}

View File

@ -1,90 +1,87 @@
#include "../nfc_i.h" #include "../nfc_i.h"
#define NFC_SCENE_READ_SUCCESS_SHIFT " " void nfc_scene_read_card_success_widget_callback(
GuiButtonType result,
void nfc_scene_read_card_success_dialog_callback(DialogExResult result, void* context) { InputType type,
Nfc* nfc = (Nfc*)context; void* context) {
furi_assert(context);
view_dispatcher_send_custom_event(nfc->view_dispatcher, result); Nfc* nfc = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
}
} }
void nfc_scene_read_card_success_on_enter(void* context) { void nfc_scene_read_card_success_on_enter(void* context) {
Nfc* nfc = (Nfc*)context; Nfc* nfc = (Nfc*)context;
string_t data_str;
string_t uid_str;
string_init(data_str);
string_init(uid_str);
// Send notification // Send notification
notification_message(nfc->notifications, &sequence_success); notification_message(nfc->notifications, &sequence_success);
// Setup view // Setup view
NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data; NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
DialogEx* dialog_ex = nfc->dialog_ex; Widget* widget = nfc->widget;
dialog_ex_set_left_button_text(dialog_ex, "Retry"); string_set_str(data_str, nfc_get_dev_type(data->device));
dialog_ex_set_right_button_text(dialog_ex, "More"); string_set_str(uid_str, "UID:");
dialog_ex_set_header(dialog_ex, nfc_get_dev_type(data->device), 36, 8, AlignLeft, AlignCenter); for(uint8_t i = 0; i < data->uid_len; i++) {
dialog_ex_set_icon(dialog_ex, 8, 13, &I_Medium_chip_22x21); string_cat_printf(uid_str, " %02X", data->uid[i]);
// Display UID
if(data->uid_len == 4) {
nfc_text_store_set(
nfc,
NFC_SCENE_READ_SUCCESS_SHIFT "%s\n" NFC_SCENE_READ_SUCCESS_SHIFT
"ATQA: %02X%02X SAK: %02X\nUID: %02X %02X %02X %02X",
nfc_guess_protocol(data->protocol),
data->atqa[0],
data->atqa[1],
data->sak,
data->uid[0],
data->uid[1],
data->uid[2],
data->uid[3]);
} else if(data->uid_len == 7) {
nfc_text_store_set(
nfc,
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_guess_protocol(data->protocol),
data->atqa[0],
data->atqa[1],
data->sak,
data->uid[0],
data->uid[1],
data->uid[2],
data->uid[3],
data->uid[4],
data->uid[5],
data->uid[6]);
} }
dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 16, AlignLeft, AlignTop);
dialog_ex_set_context(dialog_ex, nfc);
dialog_ex_set_result_callback(dialog_ex, nfc_scene_read_card_success_dialog_callback);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx); widget_add_button_element(
widget, GuiButtonTypeLeft, "Retry", nfc_scene_read_card_success_widget_callback, nfc);
if(data->device == NfcDeviceNfca) {
widget_add_button_element(
widget, GuiButtonTypeRight, "More", nfc_scene_read_card_success_widget_callback, nfc);
widget_add_icon_element(widget, 8, 13, &I_Medium_chip_22x21);
string_cat_printf(data_str, " may be:");
widget_add_string_element(
widget, 37, 12, AlignLeft, AlignBottom, FontPrimary, string_get_cstr(data_str));
string_printf(
data_str,
"%s\nATQA: %02X%02X SAK: %02X",
nfc_guess_protocol(data->protocol),
data->atqa[0],
data->atqa[1],
data->sak);
widget_add_string_multiline_element(
widget, 37, 16, AlignLeft, AlignTop, FontSecondary, string_get_cstr(data_str));
widget_add_string_element(
widget, 64, 46, AlignCenter, AlignBottom, FontSecondary, string_get_cstr(uid_str));
} else {
widget_add_string_element(
widget, 64, 12, AlignCenter, AlignBottom, FontPrimary, string_get_cstr(data_str));
widget_add_string_element(
widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(uid_str));
}
string_clear(data_str);
string_clear(uid_str);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
} }
bool nfc_scene_read_card_success_on_event(void* context, SceneManagerEvent event) { bool nfc_scene_read_card_success_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = (Nfc*)context; Nfc* nfc = (Nfc*)context;
NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultLeft) { if(event.event == GuiButtonTypeLeft) {
return scene_manager_previous_scene(nfc->scene_manager); consumed = scene_manager_previous_scene(nfc->scene_manager);
} else if(event.event == DialogExResultRight) { } else if(data->device == NfcDeviceNfca && event.event == GuiButtonTypeRight) {
// Clear device name // Clear device name
nfc_device_set_name(nfc->dev, ""); nfc_device_set_name(nfc->dev, "");
scene_manager_next_scene(nfc->scene_manager, NfcSceneCardMenu); scene_manager_next_scene(nfc->scene_manager, NfcSceneCardMenu);
return true; consumed = true;
} }
} }
return false; return consumed;
} }
void nfc_scene_read_card_success_on_exit(void* context) { void nfc_scene_read_card_success_on_exit(void* context) {
Nfc* nfc = (Nfc*)context; Nfc* nfc = (Nfc*)context;
widget_clear(nfc->widget);
DialogEx* dialog_ex = nfc->dialog_ex;
dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
dialog_ex_set_left_button_text(dialog_ex, NULL);
dialog_ex_set_right_button_text(dialog_ex, NULL);
dialog_ex_set_result_callback(dialog_ex, NULL);
dialog_ex_set_context(dialog_ex, NULL);
} }