Fix EMV reading

2 MasterCard were successfully read

Issues: some VISA and Mastercard and all UnionPay can't be read

TODO: currency, country, Application name
TODO: Support multi application mode to read co-branded card.
This commit is contained in:
Nikita Vostokov
2024-01-15 03:53:03 +00:00
committed by Methodius
parent 3a82b3aa3c
commit 08a5adf18e
6 changed files with 99 additions and 46 deletions

View File

@@ -14,8 +14,8 @@ static void nfc_scene_info_on_enter_emv(NfcApp* instance) {
const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv);
FuriString* temp_str = furi_string_alloc();
furi_string_cat_printf(
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
// furi_string_cat_printf(
// temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
nfc_render_emv_info(data, NfcProtocolFormatTypeFull, temp_str);
widget_add_text_scroll_element(
@@ -54,8 +54,8 @@ static void nfc_scene_read_success_on_enter_emv(NfcApp* instance) {
const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv);
FuriString* temp_str = furi_string_alloc();
furi_string_cat_printf(
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
// furi_string_cat_printf(
// temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
nfc_render_emv_info(data, NfcProtocolFormatTypeShort, temp_str);
widget_add_text_scroll_element(

View File

@@ -3,15 +3,11 @@
#include "../iso14443_4a/iso14443_4a_render.h"
void nfc_render_emv_info(const EmvData* data, NfcProtocolFormatType format_type, FuriString* str) {
nfc_render_iso14443_4a_brief(emv_get_base_data(data), str);
nfc_render_emv_pan(data->emv_application.pan, data->emv_application.pan_len, str);
nfc_render_emv_name(data->emv_application.name, str);
nfc_render_emv_pan(data->emv_application.pan, data->emv_application.pan_len, str);
nfc_render_emv_expired(&data->emv_application, str);
if(format_type != NfcProtocolFormatTypeFull) return;
furi_string_cat(str, "\n\e#ISO14443-4 data");
nfc_render_iso14443_4a_extra(emv_get_base_data(data), str);
if(format_type == NfcProtocolFormatTypeFull) nfc_render_emv_extra(data, str);
}
void nfc_render_emv_data(const EmvData* data, FuriString* str) {
@@ -20,16 +16,49 @@ void nfc_render_emv_data(const EmvData* data, FuriString* str) {
}
void nfc_render_emv_pan(const uint8_t* data, const uint8_t len, FuriString* str) {
for(uint8_t i = 0; i < len; i++) furi_string_cat_printf(str, "%u", data[i]);
if(len == 0) return;
for(uint8_t i = 0; i < len; i += 2) {
furi_string_cat_printf(str, "%02X%02X ", data[i], data[i + 1]);
}
furi_string_cat_printf(str, "\n");
}
void nfc_render_emv_expired(const EmvApplication* apl, FuriString* str) {
if(apl->exp_month == 0) return;
furi_string_cat_printf(str, "Exp: %02X/%02X\n", apl->exp_month, apl->exp_year);
}
void nfc_render_emv_currency(const EmvApplication* apl, FuriString* str) {
UNUSED(apl);
UNUSED(str);
// nfc/assets/currency_code.nfc
}
void nfc_render_emv_country(const EmvApplication* apl, FuriString* str) {
UNUSED(apl);
UNUSED(str);
// nfc/assets/country_code.nfc
}
void nfc_render_emv_name(const char* data, FuriString* str) {
UNUSED(data);
if(strlen(data) == 0) return;
furi_string_cat_printf(str, "\e#");
furi_string_cat(str, data);
furi_string_cat_printf(str, "\n");
}
void nfc_render_emv_application(const EmvApplication* data, FuriString* str) {
UNUSED(data);
void nfc_render_emv_application(const EmvApplication* apl, FuriString* str) {
const uint8_t len = apl->aid_len;
if(len) {
furi_string_cat_printf(str, "AID: ");
for(uint8_t i = 0; i < len; i++) furi_string_cat_printf(str, "%02X", apl->aid[i]);
// nfc/assets/aid.nfc
} else {
furi_string_cat_printf(str, "No Pay Application found");
}
furi_string_cat_printf(str, "\n");
}
}
void nfc_render_emv_extra(const EmvData* data, FuriString* str) {
nfc_render_emv_application(&data->emv_application, str);
}

View File

@@ -13,4 +13,12 @@ void nfc_render_emv_pan(const uint8_t* data, const uint8_t len, FuriString* str)
void nfc_render_emv_name(const char* data, FuriString* str);
void nfc_render_emv_application(const EmvApplication* data, FuriString* str);
void nfc_render_emv_application(const EmvApplication* data, FuriString* str);
void nfc_render_emv_extra(const EmvData* data, FuriString* str);
void nfc_render_emv_expired(const EmvApplication* apl, FuriString* str);
void nfc_render_emv_country(const EmvApplication* apl, FuriString* str);
void nfc_render_emv_currency(const EmvApplication* apl, FuriString* str);