Skip to content

Commit

Permalink
[FL-2605] NFC new design (#1364)
Browse files Browse the repository at this point in the history
* nfc: add new read scene

* lib: refactore nfc library

* mifare desfire: add read card fuction

* lib nfc: add auto read worker

* nfc: add supported cards

* nfc: add mifare classic read success scene

* nfc: add troyka support

* submodule: update protobuf

* nfc: mifare classic keys cache

* nfc: rework mifare classic key cache

* Correct spelling

* nfc: add user dictionary

* nfc: introduce block read map in fff

* nfc: rework dict attack

* nfc: improve dict attack

* nfc: rework mifare classic format

* nfc: rework MFC read with Reader

* nfc: add gui for MFC read success scene

* nfc: fix dict attack view gui

* nfc: add retry and exit confirm scenes

* nfc: add retry and exit scenes navigation

* nfc: check user dictionary

* nfc: remove unused scenes

* nfc: rename functions in nfc worker

* nfc: rename mf_classic_dict_attack -> dict_attack

* nfc: change scenes names
* nfc: remove scene tick events
* nfc: rework dict calls with buffer streams
* nfc: fix notifications
* nfc: fix mf desfire navigation
* nfc: remove notification from mf classic read success
* nfc: fix read sectors calculation
* nfc: add fallback for unknown card
* nfc: show file name while emulating
* nfc: fix build
* nfc: fix memory leak
* nfc: fix desfire read
* nfc: add no dict found navigation
* nfc: add read views
* nfc: update card fix
* nfc: fix access bytes save
* nfc: add exit and retry confirm to mf ultralight read success
* nfc: introduce detect reader
* nfc: change record open arg to macros
* nfc: fix start from archive

Co-authored-by: Astra <[email protected]>
Co-authored-by: あく <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2022
1 parent ec19c11 commit 9c59bcd
Show file tree
Hide file tree
Showing 89 changed files with 2,733 additions and 1,990 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
/lib/microtar/ @skotopes @DrZlo13 @hedger
/lib/mlib/ @skotopes @DrZlo13 @hedger
/lib/nanopb/ @skotopes @DrZlo13 @hedger
/lib/nfc_protocols/ @skotopes @DrZlo13 @hedger @gornekich
/lib/nfc/ @skotopes @DrZlo13 @hedger @gornekich
/lib/one_wire/ @skotopes @DrZlo13 @hedger
/lib/qrcode/ @skotopes @DrZlo13 @hedger
/lib/subghz/ @skotopes @DrZlo13 @hedger @Skorpionm
Expand Down
1 change: 1 addition & 0 deletions applications/nfc/helpers/nfc_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ enum NfcCustomEvent {
NfcCustomEventByteInputDone,
NfcCustomEventTextInputDone,
NfcCustomEventDictAttackDone,
NfcCustomEventDictAttackSkip,
NfcCustomEventRpcLoad,
};
26 changes: 13 additions & 13 deletions applications/nfc/helpers/nfc_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,67 +267,67 @@ static void nfc_generate_ntag_i2c_plus_2k(NfcDeviceData* data) {
static const NfcGenerator mf_ul_generator = {
.name = "Mifare Ultralight",
.generator_func = nfc_generate_mf_ul_orig,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator mf_ul_11_generator = {
.name = "Mifare Ultralight EV1 11",
.generator_func = nfc_generate_mf_ul_11,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator mf_ul_h11_generator = {
.name = "Mifare Ultralight EV1 H11",
.generator_func = nfc_generate_mf_ul_h11,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator mf_ul_21_generator = {
.name = "Mifare Ultralight EV1 21",
.generator_func = nfc_generate_mf_ul_21,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator mf_ul_h21_generator = {
.name = "Mifare Ultralight EV1 H21",
.generator_func = nfc_generate_mf_ul_h21,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag203_generator = {
.name = "NTAG203",
.generator_func = nfc_generate_mf_ul_ntag203,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag213_generator = {
.name = "NTAG213",
.generator_func = nfc_generate_ntag213,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag215_generator = {
.name = "NTAG215",
.generator_func = nfc_generate_ntag215,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag216_generator = {
.name = "NTAG216",
.generator_func = nfc_generate_ntag216,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag_i2c_1k_generator = {
.name = "NTAG I2C 1k",
.generator_func = nfc_generate_ntag_i2c_1k,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag_i2c_2k_generator = {
.name = "NTAG I2C 2k",
.generator_func = nfc_generate_ntag_i2c_2k,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag_i2c_plus_1k_generator = {
.name = "NTAG I2C Plus 1k",
.generator_func = nfc_generate_ntag_i2c_plus_1k,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

static const NfcGenerator ntag_i2c_plus_2k_generator = {
.name = "NTAG I2C Plus 2k",
.generator_func = nfc_generate_ntag_i2c_plus_2k,
.next_scene = NfcSceneMifareUlMenu};
.next_scene = NfcSceneMfUltralightMenu};

const NfcGenerator* const nfc_generators[] = {
&mf_ul_generator,
Expand Down
53 changes: 0 additions & 53 deletions applications/nfc/helpers/nfc_mf_classic_dict.c

This file was deleted.

15 changes: 0 additions & 15 deletions applications/nfc/helpers/nfc_mf_classic_dict.h

This file was deleted.

24 changes: 9 additions & 15 deletions applications/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ bool nfc_back_event_callback(void* context) {
return scene_manager_handle_back_event(nfc->scene_manager);
}

void nfc_tick_event_callback(void* context) {
furi_assert(context);
Nfc* nfc = context;
scene_manager_handle_tick_event(nfc->scene_manager);
}

void nfc_rpc_exit_callback(Nfc* nfc) {
if(nfc->rpc_state == NfcRpcStateEmulating) {
// Stop worker
Expand All @@ -36,11 +30,12 @@ void nfc_rpc_exit_callback(Nfc* nfc) {
}
}

static void nfc_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
static bool nfc_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
UNUSED(event);
Nfc* nfc = context;

nfc->rpc_state = NfcRpcStateEmulated;
return true;
}

static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context) {
Expand All @@ -67,20 +62,20 @@ static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, v
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
nfc_worker_start(
nfc->worker,
NfcWorkerStateEmulateMifareUltralight,
NfcWorkerStateMfUltralightEmulate,
&nfc->dev->dev_data,
nfc_rpc_emulate_callback,
nfc);
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
nfc_worker_start(
nfc->worker,
NfcWorkerStateEmulateMifareClassic,
NfcWorkerStateMfClassicEmulate,
&nfc->dev->dev_data,
nfc_rpc_emulate_callback,
nfc);
} else {
nfc_worker_start(
nfc->worker, NfcWorkerStateEmulate, &nfc->dev->dev_data, NULL, nfc);
nfc->worker, NfcWorkerStateUidEmulate, &nfc->dev->dev_data, NULL, nfc);
}
nfc->rpc_state = NfcRpcStateEmulating;
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
Expand All @@ -102,7 +97,6 @@ Nfc* nfc_alloc() {
view_dispatcher_set_event_callback_context(nfc->view_dispatcher, nfc);
view_dispatcher_set_custom_event_callback(nfc->view_dispatcher, nfc_custom_event_callback);
view_dispatcher_set_navigation_event_callback(nfc->view_dispatcher, nfc_back_event_callback);
view_dispatcher_set_tick_event_callback(nfc->view_dispatcher, nfc_tick_event_callback, 100);

// Nfc device
nfc->dev = nfc_device_alloc();
Expand Down Expand Up @@ -155,7 +149,7 @@ Nfc* nfc_alloc() {
view_dispatcher_add_view(
nfc->view_dispatcher, NfcViewBankCard, bank_card_get_view(nfc->bank_card));

// Dict Attack
// Mifare Classic Dict Attack
nfc->dict_attack = dict_attack_alloc();
view_dispatcher_add_view(
nfc->view_dispatcher, NfcViewDictAttack, dict_attack_get_view(nfc->dict_attack));
Expand Down Expand Up @@ -209,7 +203,7 @@ void nfc_free(Nfc* nfc) {
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewBankCard);
bank_card_free(nfc->bank_card);

// Dict Attack
// Mifare Classic Dict Attack
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewDictAttack);
dict_attack_free(nfc->dict_attack);

Expand Down Expand Up @@ -301,9 +295,9 @@ int32_t nfc_app(void* p) {
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
if(nfc_device_load(nfc->dev, p, true)) {
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightEmulate);
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicEmulate);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
}
Expand Down
5 changes: 3 additions & 2 deletions applications/nfc/nfc_cli.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <furi.h>
#include <furi_hal.h>
#include <cli/cli.h>
#include <toolbox/args.h>
#include <lib/toolbox/args.h>

#include "nfc_types.h"
#include <lib/nfc/nfc_types.h>
#include <lib/nfc/nfc_device.h>

static void nfc_cli_print_usage() {
printf("Usage:\r\n");
Expand Down
11 changes: 6 additions & 5 deletions applications/nfc/nfc_i.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include "nfc.h"
#include "nfc_types.h"
#include "nfc_worker.h"
#include "nfc_device.h"

#include <furi.h>
#include <furi_hal.h>
Expand All @@ -24,6 +21,11 @@
#include <gui/modules/text_box.h>
#include <gui/modules/widget.h>

#include <lib/nfc/nfc_types.h>
#include <lib/nfc/nfc_worker.h>
#include <lib/nfc/nfc_device.h>
#include <lib/nfc/helpers/mf_classic_dict.h>

#include "views/bank_card.h"
#include "views/dict_attack.h"

Expand All @@ -32,8 +34,6 @@

#include "rpc/rpc_app.h"

#define NFC_SEND_NOTIFICATION_FALSE (0UL)
#define NFC_SEND_NOTIFICATION_TRUE (1UL)
#define NFC_TEXT_STORE_SIZE 128

typedef enum {
Expand All @@ -56,6 +56,7 @@ struct Nfc {

char text_store[NFC_TEXT_STORE_SIZE + 1];
string_t text_box_store;
uint8_t byte_input_store[6];

void* rpc_ctx;
NfcRpcState rpc_state;
Expand Down
Loading

0 comments on commit 9c59bcd

Please sign in to comment.