[FL-1547], [FL-1500] NFC app v1 (#593)
* nfc: remove mifare read debug view and scene * nfc: change mifare ultralight data structure * mifare_ultralight: add more commands * nfc: add emulate mifare ul scene * nfc: rework data structures, remove debug scenes and views * nfc: add read emv scenes * nfc: mifare emulation wip * nfc cli: increase detecting time * nfc: save nfc files with new format * nfc: store Mifare Ultralight * nfc: start loading mifare ultralight * nfc: add delete scenes * nfc: add edit UID and name * nfc: finish parsing uid and mifare ul data * nfc: delete success fix * gui_widget: introduce GuiWidget * gui_widget: add string element * gui_widget: add button element * gui_widget: move free elements into gui_widget * nfc: rework info scene with GuiWidget * nfc: rework device info scene * nfc: rework delete scene gui * nfc: add compatible script support * nfc: rework emv reading scenes * nfc: rework bank card save * nfc: add bank card custom view * gui_widget: add icon element * nfc: add icon to bank card * nfc: start worker after switching view Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
65
applications/nfc/views/bank_card.c
Executable file
65
applications/nfc/views/bank_card.c
Executable file
@@ -0,0 +1,65 @@
|
||||
#include "bank_card.h"
|
||||
#include "../gui_widget/gui_widget.h"
|
||||
#include <m-string.h>
|
||||
|
||||
struct BankCard {
|
||||
GuiWidget* widget;
|
||||
};
|
||||
|
||||
BankCard* bank_card_alloc() {
|
||||
BankCard* bank_card = furi_alloc(sizeof(BankCard));
|
||||
bank_card->widget = gui_widget_alloc();
|
||||
return bank_card;
|
||||
}
|
||||
|
||||
void bank_card_free(BankCard* bank_card) {
|
||||
furi_assert(bank_card);
|
||||
gui_widget_free(bank_card->widget);
|
||||
free(bank_card);
|
||||
}
|
||||
|
||||
View* bank_card_get_view(BankCard* bank_card) {
|
||||
furi_assert(bank_card);
|
||||
return gui_widget_get_view(bank_card->widget);
|
||||
}
|
||||
|
||||
void bank_card_clear(BankCard* bank_card) {
|
||||
furi_assert(bank_card);
|
||||
gui_widget_clear(bank_card->widget);
|
||||
}
|
||||
|
||||
void bank_card_set_name(BankCard* bank_card, char* name) {
|
||||
furi_assert(bank_card);
|
||||
furi_assert(name);
|
||||
gui_widget_add_string_element(
|
||||
bank_card->widget, 64, 6, AlignCenter, AlignTop, FontSecondary, name);
|
||||
}
|
||||
|
||||
void bank_card_set_number(BankCard* bank_card, uint8_t* number) {
|
||||
furi_assert(bank_card);
|
||||
furi_assert(number);
|
||||
string_t num_str;
|
||||
string_init(num_str);
|
||||
for(uint8_t i = 0; i < 8; i += 2) {
|
||||
string_cat_printf(num_str, "%02X%02X ", number[i], number[i + 1]);
|
||||
}
|
||||
gui_widget_add_string_element(
|
||||
bank_card->widget, 25, 22, AlignLeft, AlignTop, FontSecondary, string_get_cstr(num_str));
|
||||
gui_widget_add_icon_element(bank_card->widget, 6, 20, &I_EMV_Chip_14x11);
|
||||
string_clear(num_str);
|
||||
}
|
||||
|
||||
void bank_card_set_exp_date(BankCard* bank_card, uint8_t mon, uint16_t year) {
|
||||
furi_assert(bank_card);
|
||||
char exp_date_str[16];
|
||||
snprintf(exp_date_str, sizeof(exp_date_str), "Exp: %02d/%02d", mon, year % 100);
|
||||
gui_widget_add_string_element(
|
||||
bank_card->widget, 122, 54, AlignRight, AlignBottom, FontSecondary, exp_date_str);
|
||||
}
|
||||
|
||||
void bank_card_set_cardholder_name(BankCard* bank_card, char* name) {
|
||||
furi_assert(bank_card);
|
||||
furi_assert(name);
|
||||
gui_widget_add_string_element(
|
||||
bank_card->widget, 6, 37, AlignLeft, AlignTop, FontSecondary, name);
|
||||
}
|
23
applications/nfc/views/bank_card.h
Normal file
23
applications/nfc/views/bank_card.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct BankCard BankCard;
|
||||
|
||||
typedef void (*BankCardBackCallback)(void);
|
||||
|
||||
BankCard* bank_card_alloc();
|
||||
|
||||
void bank_card_free(BankCard* bank_card);
|
||||
|
||||
void bank_card_clear(BankCard* bank_card);
|
||||
|
||||
View* bank_card_get_view(BankCard* bank_card);
|
||||
|
||||
void bank_card_set_name(BankCard* bank_card, char* name);
|
||||
|
||||
void bank_card_set_number(BankCard* bank_card, uint8_t* number);
|
||||
|
||||
void bank_card_set_exp_date(BankCard* bank_card, uint8_t mon, uint16_t year);
|
||||
|
||||
void bank_card_set_cardholder_name(BankCard* bank_card, char* name);
|
@@ -1,142 +0,0 @@
|
||||
#include "nfc_detect.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcDetect {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool found;
|
||||
NfcDeviceData data;
|
||||
} NfcDetectModel;
|
||||
|
||||
void nfc_detect_draw(Canvas* canvas, NfcDetectModel* model) {
|
||||
char buffer[32];
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
if(model->found) {
|
||||
canvas_draw_str(canvas, 0, 12, "Found");
|
||||
canvas_draw_str(canvas, 32, 12, nfc_get_dev_type(model->data.device));
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
if(model->data.protocol != NfcDeviceProtocolUnknown) {
|
||||
canvas_draw_str(canvas, 0, 22, nfc_get_protocol(model->data.protocol));
|
||||
}
|
||||
// Display UID
|
||||
for(uint8_t i = 0; i < model->data.uid_len; i++) {
|
||||
snprintf(buffer + (i * 2), sizeof(buffer) - (i * 2), "%02X", model->data.uid[i]);
|
||||
buffer[model->data.uid_len * 2] = 0;
|
||||
}
|
||||
canvas_draw_str(canvas, 0, 32, "UID: ");
|
||||
canvas_draw_str(canvas, 22, 32, buffer);
|
||||
// Display ATQA and SAK
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"ATQA: %02X %02X SAK: %02X",
|
||||
model->data.atqa[1],
|
||||
model->data.atqa[0],
|
||||
model->data.sak);
|
||||
canvas_draw_str(canvas, 0, 42, buffer);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 0, 12, "Searching");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Place card to the back");
|
||||
}
|
||||
}
|
||||
|
||||
bool nfc_detect_input(InputEvent* event, void* context) {
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_detect_worker_callback(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcDetect* nfc_detect = (NfcDetect*)context;
|
||||
view_dispatcher_send_custom_event(nfc_detect->nfc_common->view_dispatcher, NfcEventDetect);
|
||||
}
|
||||
|
||||
bool nfc_detect_view_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcDetect* nfc_detect = (NfcDetect*)context;
|
||||
if(event == NfcEventDetect) {
|
||||
NfcDeviceData* data = (NfcDeviceData*)&nfc_detect->nfc_common->worker_result;
|
||||
|
||||
with_view_model(
|
||||
nfc_detect->view, (NfcDetectModel * model) {
|
||||
model->found = true;
|
||||
model->data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_detect_enter(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcDetect* nfc_detect = (NfcDetect*)context;
|
||||
with_view_model(
|
||||
nfc_detect->view, (NfcDetectModel * model) {
|
||||
model->found = false;
|
||||
model->data.protocol = NfcDeviceProtocolUnknown;
|
||||
return true;
|
||||
});
|
||||
nfc_worker_start(
|
||||
nfc_detect->nfc_common->worker,
|
||||
NfcWorkerStateDetect,
|
||||
&nfc_detect->nfc_common->worker_result,
|
||||
nfc_detect_worker_callback,
|
||||
nfc_detect);
|
||||
}
|
||||
|
||||
void nfc_detect_exit(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcDetect* nfc_detect = (NfcDetect*)context;
|
||||
nfc_worker_stop(nfc_detect->nfc_common->worker);
|
||||
}
|
||||
|
||||
NfcDetect* nfc_detect_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
NfcDetect* nfc_detect = furi_alloc(sizeof(NfcDetect));
|
||||
nfc_detect->nfc_common = nfc_common;
|
||||
|
||||
// View allocation and configuration
|
||||
nfc_detect->view = view_alloc();
|
||||
view_allocate_model(nfc_detect->view, ViewModelTypeLockFree, sizeof(NfcDetectModel));
|
||||
view_set_context(nfc_detect->view, nfc_detect);
|
||||
view_set_draw_callback(nfc_detect->view, (ViewDrawCallback)nfc_detect_draw);
|
||||
view_set_input_callback(nfc_detect->view, nfc_detect_input);
|
||||
view_set_custom_callback(nfc_detect->view, nfc_detect_view_custom);
|
||||
view_set_enter_callback(nfc_detect->view, nfc_detect_enter);
|
||||
view_set_exit_callback(nfc_detect->view, nfc_detect_exit);
|
||||
|
||||
return nfc_detect;
|
||||
}
|
||||
|
||||
void nfc_detect_free(NfcDetect* nfc_detect) {
|
||||
furi_assert(nfc_detect);
|
||||
|
||||
view_free(nfc_detect->view);
|
||||
free(nfc_detect);
|
||||
}
|
||||
|
||||
View* nfc_detect_get_view(NfcDetect* nfc_detect) {
|
||||
furi_assert(nfc_detect);
|
||||
|
||||
return nfc_detect->view;
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcDetect NfcDetect;
|
||||
|
||||
NfcDetect* nfc_detect_alloc(NfcCommon* nfc_common);
|
||||
|
||||
void nfc_detect_free(NfcDetect* nfc_detect);
|
||||
|
||||
View* nfc_detect_get_view(NfcDetect* nfc_detect);
|
@@ -1,79 +0,0 @@
|
||||
#include "nfc_emulate.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcEmulate {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
};
|
||||
|
||||
void nfc_emulate_draw(Canvas* canvas, void* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 0, 12, "Emulating NFC-A");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Type: T2T");
|
||||
canvas_draw_str(canvas, 2, 32, "UID length: 7");
|
||||
canvas_draw_str(canvas, 2, 42, "UID: 36 9C E7 B1 0A C1 34");
|
||||
canvas_draw_str(canvas, 2, 52, "SAK: 00 ATQA: 00/44");
|
||||
}
|
||||
|
||||
bool nfc_emulate_input(InputEvent* event, void* context) {
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_emulate_enter(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmulate* nfc_emulate = (NfcEmulate*)context;
|
||||
nfc_worker_start(
|
||||
nfc_emulate->nfc_common->worker,
|
||||
NfcWorkerStateEmulate,
|
||||
&nfc_emulate->nfc_common->worker_result,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void nfc_emulate_exit(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmulate* nfc_emulate = (NfcEmulate*)context;
|
||||
nfc_worker_stop(nfc_emulate->nfc_common->worker);
|
||||
}
|
||||
|
||||
NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
NfcEmulate* nfc_emulate = furi_alloc(sizeof(NfcEmulate));
|
||||
nfc_emulate->nfc_common = nfc_common;
|
||||
|
||||
// View allocation and configuration
|
||||
nfc_emulate->view = view_alloc();
|
||||
view_set_context(nfc_emulate->view, nfc_emulate);
|
||||
view_set_draw_callback(nfc_emulate->view, (ViewDrawCallback)nfc_emulate_draw);
|
||||
view_set_input_callback(nfc_emulate->view, nfc_emulate_input);
|
||||
view_set_enter_callback(nfc_emulate->view, nfc_emulate_enter);
|
||||
view_set_exit_callback(nfc_emulate->view, nfc_emulate_exit);
|
||||
|
||||
return nfc_emulate;
|
||||
}
|
||||
|
||||
void nfc_emulate_free(NfcEmulate* nfc_emulate) {
|
||||
furi_assert(nfc_emulate);
|
||||
|
||||
view_free(nfc_emulate->view);
|
||||
free(nfc_emulate);
|
||||
}
|
||||
|
||||
View* nfc_emulate_get_view(NfcEmulate* nfc_emulate) {
|
||||
furi_assert(nfc_emulate);
|
||||
|
||||
return nfc_emulate->view;
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcEmulate NfcEmulate;
|
||||
|
||||
NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common);
|
||||
|
||||
void nfc_emulate_free(NfcEmulate* nfc_emulate);
|
||||
|
||||
View* nfc_emulate_get_view(NfcEmulate* nfc_emulate);
|
@@ -1,133 +0,0 @@
|
||||
#include "nfc_emv.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcEmv {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool found;
|
||||
NfcEmvData emv_data;
|
||||
} NfcEmvModel;
|
||||
|
||||
void nfc_emv_draw(Canvas* canvas, NfcEmvModel* model) {
|
||||
char buffer[32];
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
if(model->found) {
|
||||
canvas_draw_str(canvas, 0, 12, "Found EMV card");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Type:");
|
||||
snprintf(buffer, sizeof(buffer), "%s", model->emv_data.name);
|
||||
canvas_draw_str(canvas, 2, 32, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "Number:\n");
|
||||
canvas_draw_str(canvas, 2, 42, buffer);
|
||||
uint8_t card_num_len = sizeof(model->emv_data.number);
|
||||
for(uint8_t i = 0; i < card_num_len; i++) {
|
||||
snprintf(
|
||||
buffer + (i * 2), sizeof(buffer) - (i * 2), "%02X", model->emv_data.number[i]);
|
||||
}
|
||||
buffer[card_num_len * 2] = 0;
|
||||
canvas_draw_str(canvas, 2, 52, buffer);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 0, 12, "Searching");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Place card to the back");
|
||||
}
|
||||
}
|
||||
|
||||
bool nfc_emv_input(InputEvent* event, void* context) {
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_emv_worker_callback(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmv* nfc_emv = (NfcEmv*)context;
|
||||
view_dispatcher_send_custom_event(nfc_emv->nfc_common->view_dispatcher, NfcEventEmv);
|
||||
}
|
||||
|
||||
bool nfc_emv_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmv* nfc_emv = (NfcEmv*)context;
|
||||
if(event == NfcEventEmv) {
|
||||
NfcEmvData* data = (NfcEmvData*)&nfc_emv->nfc_common->worker_result;
|
||||
|
||||
with_view_model(
|
||||
nfc_emv->view, (NfcEmvModel * model) {
|
||||
model->found = true;
|
||||
model->emv_data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_emv_enter(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmv* nfc_emv = (NfcEmv*)context;
|
||||
with_view_model(
|
||||
nfc_emv->view, (NfcEmvModel * model) {
|
||||
model->found = false;
|
||||
return true;
|
||||
});
|
||||
nfc_worker_start(
|
||||
nfc_emv->nfc_common->worker,
|
||||
NfcWorkerStateReadEMV,
|
||||
&nfc_emv->nfc_common->worker_result,
|
||||
nfc_emv_worker_callback,
|
||||
nfc_emv);
|
||||
}
|
||||
|
||||
void nfc_emv_exit(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcEmv* nfc_emv = (NfcEmv*)context;
|
||||
nfc_worker_stop(nfc_emv->nfc_common->worker);
|
||||
}
|
||||
|
||||
NfcEmv* nfc_emv_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
NfcEmv* nfc_emv = furi_alloc(sizeof(NfcEmv));
|
||||
nfc_emv->nfc_common = nfc_common;
|
||||
|
||||
// View allocation and configuration
|
||||
nfc_emv->view = view_alloc();
|
||||
view_allocate_model(nfc_emv->view, ViewModelTypeLockFree, sizeof(NfcEmvModel));
|
||||
view_set_context(nfc_emv->view, nfc_emv);
|
||||
view_set_draw_callback(nfc_emv->view, (ViewDrawCallback)nfc_emv_draw);
|
||||
view_set_input_callback(nfc_emv->view, nfc_emv_input);
|
||||
view_set_custom_callback(nfc_emv->view, nfc_emv_custom);
|
||||
view_set_enter_callback(nfc_emv->view, nfc_emv_enter);
|
||||
view_set_exit_callback(nfc_emv->view, nfc_emv_exit);
|
||||
|
||||
return nfc_emv;
|
||||
}
|
||||
|
||||
void nfc_emv_free(NfcEmv* nfc_emv) {
|
||||
furi_assert(nfc_emv);
|
||||
|
||||
view_free(nfc_emv->view);
|
||||
free(nfc_emv);
|
||||
}
|
||||
|
||||
View* nfc_emv_get_view(NfcEmv* nfc_emv) {
|
||||
furi_assert(nfc_emv);
|
||||
|
||||
return nfc_emv->view;
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcEmv NfcEmv;
|
||||
|
||||
NfcEmv* nfc_emv_alloc(NfcCommon* nfc_common);
|
||||
|
||||
void nfc_emv_free(NfcEmv* nfc_emv);
|
||||
|
||||
View* nfc_emv_get_view(NfcEmv* nfc_emv);
|
@@ -1,162 +0,0 @@
|
||||
#include "nfc_mifare_ul.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
#include "../nfc_i.h"
|
||||
|
||||
struct NfcMifareUl {
|
||||
NfcCommon* nfc_common;
|
||||
View* view;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool found;
|
||||
NfcMifareUlData nfc_mf_ul_data;
|
||||
} NfcMifareUlModel;
|
||||
|
||||
void nfc_mifare_ul_draw(Canvas* canvas, NfcMifareUlModel* model) {
|
||||
char buffer[32];
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
if(model->found) {
|
||||
canvas_draw_str(canvas, 0, 12, "Found Mifare Ultralight");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "UID:");
|
||||
for(uint8_t i = 0; i < model->nfc_mf_ul_data.nfc_data.uid_len; i++) {
|
||||
snprintf(
|
||||
buffer + (i * 2),
|
||||
sizeof(buffer) - (i * 2),
|
||||
"%02X",
|
||||
model->nfc_mf_ul_data.nfc_data.uid[i]);
|
||||
}
|
||||
buffer[model->nfc_mf_ul_data.nfc_data.uid_len * 2] = 0;
|
||||
canvas_draw_str(canvas, 18, 22, buffer);
|
||||
|
||||
uint8_t man_bl_size = sizeof(model->nfc_mf_ul_data.man_block);
|
||||
canvas_draw_str(canvas, 2, 32, "Manufacturer block:");
|
||||
for(uint8_t i = 0; i < man_bl_size / 2; i++) {
|
||||
snprintf(
|
||||
buffer + (i * 2),
|
||||
sizeof(buffer) - (i * 2),
|
||||
"%02X",
|
||||
model->nfc_mf_ul_data.man_block[i]);
|
||||
}
|
||||
buffer[man_bl_size] = 0;
|
||||
canvas_draw_str(canvas, 2, 42, buffer);
|
||||
|
||||
for(uint8_t i = 0; i < man_bl_size / 2; i++) {
|
||||
snprintf(
|
||||
buffer + (i * 2),
|
||||
sizeof(buffer) - (i * 2),
|
||||
"%02X",
|
||||
model->nfc_mf_ul_data.man_block[man_bl_size / 2 + i]);
|
||||
}
|
||||
buffer[man_bl_size] = 0;
|
||||
canvas_draw_str(canvas, 2, 52, buffer);
|
||||
|
||||
canvas_draw_str(canvas, 2, 62, "OTP: ");
|
||||
for(uint8_t i = 0; i < sizeof(model->nfc_mf_ul_data.otp); i++) {
|
||||
snprintf(
|
||||
buffer + (i * 2), sizeof(buffer) - (i * 2), "%02X", model->nfc_mf_ul_data.otp[i]);
|
||||
}
|
||||
buffer[sizeof(model->nfc_mf_ul_data.otp) * 2] = 0;
|
||||
canvas_draw_str(canvas, 22, 62, buffer);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 0, 12, "Searching");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 2, 22, "Place card to the back");
|
||||
}
|
||||
}
|
||||
|
||||
bool nfc_mifare_ul_input(InputEvent* event, void* context) {
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_worker_callback(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = (NfcMifareUl*)context;
|
||||
view_dispatcher_send_custom_event(
|
||||
nfc_mifare_ul->nfc_common->view_dispatcher, NfcEventMifareUl);
|
||||
}
|
||||
|
||||
bool nfc_mifare_ul_custom(uint32_t event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = (NfcMifareUl*)context;
|
||||
if(event == NfcEventMifareUl) {
|
||||
NfcMifareUlData* data = (NfcMifareUlData*)&nfc_mifare_ul->nfc_common->worker_result;
|
||||
|
||||
with_view_model(
|
||||
nfc_mifare_ul->view, (NfcMifareUlModel * model) {
|
||||
model->found = true;
|
||||
model->nfc_mf_ul_data = *data;
|
||||
return true;
|
||||
});
|
||||
// TODO add and configure next view model
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_enter(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = (NfcMifareUl*)context;
|
||||
with_view_model(
|
||||
nfc_mifare_ul->view, (NfcMifareUlModel * m) {
|
||||
m->found = false;
|
||||
return true;
|
||||
});
|
||||
nfc_worker_start(
|
||||
nfc_mifare_ul->nfc_common->worker,
|
||||
NfcWorkerStateReadMfUltralight,
|
||||
&nfc_mifare_ul->nfc_common->worker_result,
|
||||
nfc_mifare_ul_worker_callback,
|
||||
nfc_mifare_ul);
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_exit(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = (NfcMifareUl*)context;
|
||||
nfc_worker_stop(nfc_mifare_ul->nfc_common->worker);
|
||||
}
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul_alloc(NfcCommon* nfc_common) {
|
||||
furi_assert(nfc_common);
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul = furi_alloc(sizeof(NfcMifareUl));
|
||||
nfc_mifare_ul->nfc_common = nfc_common;
|
||||
|
||||
// View allocation and configuration
|
||||
nfc_mifare_ul->view = view_alloc();
|
||||
view_allocate_model(nfc_mifare_ul->view, ViewModelTypeLockFree, sizeof(NfcMifareUlModel));
|
||||
view_set_context(nfc_mifare_ul->view, nfc_mifare_ul);
|
||||
view_set_draw_callback(nfc_mifare_ul->view, (ViewDrawCallback)nfc_mifare_ul_draw);
|
||||
view_set_input_callback(nfc_mifare_ul->view, nfc_mifare_ul_input);
|
||||
view_set_custom_callback(nfc_mifare_ul->view, nfc_mifare_ul_custom);
|
||||
view_set_enter_callback(nfc_mifare_ul->view, nfc_mifare_ul_enter);
|
||||
view_set_exit_callback(nfc_mifare_ul->view, nfc_mifare_ul_exit);
|
||||
|
||||
return nfc_mifare_ul;
|
||||
}
|
||||
|
||||
void nfc_mifare_ul_free(NfcMifareUl* nfc_mifare_ul) {
|
||||
furi_assert(nfc_mifare_ul);
|
||||
|
||||
view_free(nfc_mifare_ul->view);
|
||||
free(nfc_mifare_ul);
|
||||
}
|
||||
|
||||
View* nfc_mifare_ul_get_view(NfcMifareUl* nfc_mifare_ul) {
|
||||
furi_assert(nfc_mifare_ul);
|
||||
|
||||
return nfc_mifare_ul->view;
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../nfc_types.h"
|
||||
|
||||
typedef struct NfcMifareUl NfcMifareUl;
|
||||
|
||||
NfcMifareUl* nfc_mifare_ul_alloc(NfcCommon* nfc_common);
|
||||
|
||||
void nfc_mifare_ul_free(NfcMifareUl* nfc_mifare_ul);
|
||||
|
||||
View* nfc_mifare_ul_get_view(NfcMifareUl* nfc_mifare_ul);
|
Reference in New Issue
Block a user