[FL- 3014] Untangle NFC from Unit Tests (#2106)

* Untangle NFC from Unit Tests
* nfc tests: add log error

Co-authored-by: Sergey Gavrilov <who.just.the.doctor@gmail.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Astra 2022-12-10 15:02:34 +02:00 committed by GitHub
parent b85f533a20
commit 7fb1af07b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 30 deletions

View File

@ -6,7 +6,7 @@
#include <lib/nfc/helpers/mf_classic_dict.h> #include <lib/nfc/helpers/mf_classic_dict.h>
#include <lib/digital_signal/digital_signal.h> #include <lib/digital_signal/digital_signal.h>
#include <lib/nfc/nfc_device.h> #include <lib/nfc/nfc_device.h>
#include <applications/main/nfc/helpers/nfc_generators.h> #include <lib/nfc/helpers/nfc_generators.h>
#include <lib/flipper_format/flipper_format_i.h> #include <lib/flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/file_stream.h> #include <lib/toolbox/stream/file_stream.h>
@ -102,7 +102,10 @@ static bool nfc_test_digital_signal_test_encode(
do { do {
// Read test data // Read test data
if(!nfc_test_read_signal_from_file(file_name)) break; if(!nfc_test_read_signal_from_file(file_name)) {
FURI_LOG_E(TAG, "Failed to read signal from file");
break;
}
// Encode signal // Encode signal
FURI_CRITICAL_ENTER(); FURI_CRITICAL_ENTER();

View File

@ -27,6 +27,7 @@
#include <lib/nfc/nfc_device.h> #include <lib/nfc/nfc_device.h>
#include <lib/nfc/helpers/mf_classic_dict.h> #include <lib/nfc/helpers/mf_classic_dict.h>
#include <lib/nfc/parsers/nfc_supported_card.h> #include <lib/nfc/parsers/nfc_supported_card.h>
#include <lib/nfc/helpers/nfc_generators.h>
#include "views/dict_attack.h" #include "views/dict_attack.h"
#include "views/detect_reader.h" #include "views/detect_reader.h"
@ -50,9 +51,6 @@ typedef enum {
NfcRpcStateEmulated, NfcRpcStateEmulated,
} NfcRpcState; } NfcRpcState;
// Forward declaration due to circular dependency
typedef struct NfcGenerator NfcGenerator;
struct Nfc { struct Nfc {
NfcWorker* worker; NfcWorker* worker;
ViewDispatcher* view_dispatcher; ViewDispatcher* view_dispatcher;

View File

@ -1,5 +1,5 @@
#include "../nfc_i.h" #include "../nfc_i.h"
#include "../helpers/nfc_generators.h" #include "lib/nfc/helpers/nfc_generators.h"
void nfc_scene_generate_info_dialog_callback(DialogExResult result, void* context) { void nfc_scene_generate_info_dialog_callback(DialogExResult result, void* context) {
Nfc* nfc = context; Nfc* nfc = context;
@ -39,7 +39,12 @@ bool nfc_scene_generate_info_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultRight) { if(event.event == DialogExResultRight) {
scene_manager_next_scene(nfc->scene_manager, nfc->generator->next_scene); // Switch either to NfcSceneMfClassicMenu or NfcSceneMfUltralightMenu
if(nfc->dev->dev_data.protocol == NfcDeviceProtocolMifareClassic) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicMenu);
} else if(nfc->dev->dev_data.protocol == NfcDeviceProtocolMifareUl) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightMenu);
}
consumed = true; consumed = true;
} }
} }

View File

@ -1,5 +1,5 @@
#include "../nfc_i.h" #include "../nfc_i.h"
#include "../helpers/nfc_generators.h" #include "lib/nfc/helpers/nfc_generators.h"
enum SubmenuIndex { enum SubmenuIndex {
SubmenuIndexNFCA4, SubmenuIndexNFCA4,

View File

@ -81,7 +81,6 @@ FIRMWARE_APPS = {
"basic_services", "basic_services",
"updater_app", "updater_app",
"unit_tests", "unit_tests",
"nfc",
], ],
} }

View File

@ -376,103 +376,86 @@ static void nfc_generate_mf_classic_4k_7b_uid(NfcDeviceData* data) {
static const NfcGenerator mf_ul_generator = { static const NfcGenerator mf_ul_generator = {
.name = "Mifare Ultralight", .name = "Mifare Ultralight",
.generator_func = nfc_generate_mf_ul_orig, .generator_func = nfc_generate_mf_ul_orig,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator mf_ul_11_generator = { static const NfcGenerator mf_ul_11_generator = {
.name = "Mifare Ultralight EV1 11", .name = "Mifare Ultralight EV1 11",
.generator_func = nfc_generate_mf_ul_11, .generator_func = nfc_generate_mf_ul_11,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator mf_ul_h11_generator = { static const NfcGenerator mf_ul_h11_generator = {
.name = "Mifare Ultralight EV1 H11", .name = "Mifare Ultralight EV1 H11",
.generator_func = nfc_generate_mf_ul_h11, .generator_func = nfc_generate_mf_ul_h11,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator mf_ul_21_generator = { static const NfcGenerator mf_ul_21_generator = {
.name = "Mifare Ultralight EV1 21", .name = "Mifare Ultralight EV1 21",
.generator_func = nfc_generate_mf_ul_21, .generator_func = nfc_generate_mf_ul_21,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator mf_ul_h21_generator = { static const NfcGenerator mf_ul_h21_generator = {
.name = "Mifare Ultralight EV1 H21", .name = "Mifare Ultralight EV1 H21",
.generator_func = nfc_generate_mf_ul_h21, .generator_func = nfc_generate_mf_ul_h21,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag203_generator = { static const NfcGenerator ntag203_generator = {
.name = "NTAG203", .name = "NTAG203",
.generator_func = nfc_generate_mf_ul_ntag203, .generator_func = nfc_generate_mf_ul_ntag203,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag213_generator = { static const NfcGenerator ntag213_generator = {
.name = "NTAG213", .name = "NTAG213",
.generator_func = nfc_generate_ntag213, .generator_func = nfc_generate_ntag213,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag215_generator = { static const NfcGenerator ntag215_generator = {
.name = "NTAG215", .name = "NTAG215",
.generator_func = nfc_generate_ntag215, .generator_func = nfc_generate_ntag215,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag216_generator = { static const NfcGenerator ntag216_generator = {
.name = "NTAG216", .name = "NTAG216",
.generator_func = nfc_generate_ntag216, .generator_func = nfc_generate_ntag216,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag_i2c_1k_generator = { static const NfcGenerator ntag_i2c_1k_generator = {
.name = "NTAG I2C 1k", .name = "NTAG I2C 1k",
.generator_func = nfc_generate_ntag_i2c_1k, .generator_func = nfc_generate_ntag_i2c_1k,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag_i2c_2k_generator = { static const NfcGenerator ntag_i2c_2k_generator = {
.name = "NTAG I2C 2k", .name = "NTAG I2C 2k",
.generator_func = nfc_generate_ntag_i2c_2k, .generator_func = nfc_generate_ntag_i2c_2k,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag_i2c_plus_1k_generator = { static const NfcGenerator ntag_i2c_plus_1k_generator = {
.name = "NTAG I2C Plus 1k", .name = "NTAG I2C Plus 1k",
.generator_func = nfc_generate_ntag_i2c_plus_1k, .generator_func = nfc_generate_ntag_i2c_plus_1k,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator ntag_i2c_plus_2k_generator = { static const NfcGenerator ntag_i2c_plus_2k_generator = {
.name = "NTAG I2C Plus 2k", .name = "NTAG I2C Plus 2k",
.generator_func = nfc_generate_ntag_i2c_plus_2k, .generator_func = nfc_generate_ntag_i2c_plus_2k,
.next_scene = NfcSceneMfUltralightMenu,
}; };
static const NfcGenerator mifare_classic_1k_4b_uid_generator = { static const NfcGenerator mifare_classic_1k_4b_uid_generator = {
.name = "Mifare Classic 1k 4byte UID", .name = "Mifare Classic 1k 4byte UID",
.generator_func = nfc_generate_mf_classic_1k_4b_uid, .generator_func = nfc_generate_mf_classic_1k_4b_uid,
.next_scene = NfcSceneMfClassicMenu,
}; };
static const NfcGenerator mifare_classic_1k_7b_uid_generator = { static const NfcGenerator mifare_classic_1k_7b_uid_generator = {
.name = "Mifare Classic 1k 7byte UID", .name = "Mifare Classic 1k 7byte UID",
.generator_func = nfc_generate_mf_classic_1k_7b_uid, .generator_func = nfc_generate_mf_classic_1k_7b_uid,
.next_scene = NfcSceneMfClassicMenu,
}; };
static const NfcGenerator mifare_classic_4k_4b_uid_generator = { static const NfcGenerator mifare_classic_4k_4b_uid_generator = {
.name = "Mifare Classic 4k 4byte UID", .name = "Mifare Classic 4k 4byte UID",
.generator_func = nfc_generate_mf_classic_4k_4b_uid, .generator_func = nfc_generate_mf_classic_4k_4b_uid,
.next_scene = NfcSceneMfClassicMenu,
}; };
static const NfcGenerator mifare_classic_4k_7b_uid_generator = { static const NfcGenerator mifare_classic_4k_7b_uid_generator = {
.name = "Mifare Classic 4k 7byte UID", .name = "Mifare Classic 4k 7byte UID",
.generator_func = nfc_generate_mf_classic_4k_7b_uid, .generator_func = nfc_generate_mf_classic_4k_7b_uid,
.next_scene = NfcSceneMfClassicMenu,
}; };
const NfcGenerator* const nfc_generators[] = { const NfcGenerator* const nfc_generators[] = {

View File

@ -1,14 +1,13 @@
#pragma once #pragma once
#include "../nfc_i.h" #include "../nfc_device.h"
typedef void (*NfcGeneratorFunc)(NfcDeviceData* data); typedef void (*NfcGeneratorFunc)(NfcDeviceData* data);
struct NfcGenerator { typedef struct {
const char* name; const char* name;
NfcGeneratorFunc generator_func; NfcGeneratorFunc generator_func;
NfcScene next_scene; } NfcGenerator;
};
extern const NfcGenerator* const nfc_generators[]; extern const NfcGenerator* const nfc_generators[];