[FL-1396] Mifare Classic read (#1034)
* rfal: add new data exchange function * core: add FURI_BIT to common defines * furi_hal_nfc: add data exchange with custom patiry bits * lib: extend nfc common API * assets: add mf classic dictionary * lib: introduce mifare classic library * nfc: add dictionary reader helper * nfc worker: add worker events, add mifare classic read * nfc: rework scenes with worker events * nfc: add read mifare classic GUI * nfc device: add mifare classic save * nfc: add dictionary open fail scene * nfc: mention resources * stream: fix stream read line * subghz: rework file read with fixed stream_read_line * furi_hal_nfc: decrease communication timeout * nfc: rework keys load from dictionary with file_stream * nfc: add read mifare classic suggestion * nfc: fix mifare classic read view * nfc: fix index size * nfc: add switch to no dictionary found scene * nfc: add mifare classic load * nfc: improve read mifare classic design * mifare_classic: add proxmark3 mention * nfc: format sources * nfc: fix typos, add documentation
This commit is contained in:
95
applications/nfc/scenes/nfc_scene_read_mifare_classic.c
Normal file
95
applications/nfc/scenes/nfc_scene_read_mifare_classic.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "../nfc_i.h"
|
||||
|
||||
enum {
|
||||
NfcSceneReadMifareClassicStateInProgress,
|
||||
NfcSceneReadMifareClassicStateDone,
|
||||
};
|
||||
|
||||
void nfc_read_mifare_classic_worker_callback(NfcWorkerEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = context;
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void nfc_read_mifare_classic_dict_attack_result_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = context;
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventDictAttackDone);
|
||||
}
|
||||
|
||||
void nfc_scene_read_mifare_classic_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Setup and start worker
|
||||
memset(&nfc->dev->dev_data.mf_classic_data, 0, sizeof(MfClassicData));
|
||||
dict_attack_set_result_callback(
|
||||
nfc->dict_attack, nfc_read_mifare_classic_dict_attack_result_callback, nfc);
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneReadMifareClassic, NfcSceneReadMifareClassicStateInProgress);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDictAttack);
|
||||
nfc_worker_start(
|
||||
nfc->worker,
|
||||
NfcWorkerStateReadMifareClassic,
|
||||
&nfc->dev->dev_data,
|
||||
nfc_read_mifare_classic_worker_callback,
|
||||
nfc);
|
||||
}
|
||||
|
||||
bool nfc_scene_read_mifare_classic_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadMifareClassic);
|
||||
if(event.type == SceneManagerEventTypeTick) {
|
||||
if(state == NfcSceneReadMifareClassicStateInProgress) {
|
||||
notification_message(nfc->notifications, &sequence_blink_blue_10);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventDictAttackDone) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventDetectedClassic1k) {
|
||||
dict_attack_card_detected(nfc->dict_attack, MfClassicType1k);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventDetectedClassic4k) {
|
||||
dict_attack_card_detected(nfc->dict_attack, MfClassicType4k);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventNewSector) {
|
||||
dict_attack_inc_curr_sector(nfc->dict_attack);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventFoundKeyA) {
|
||||
dict_attack_inc_found_key(nfc->dict_attack, MfClassicKeyA);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventFoundKeyB) {
|
||||
dict_attack_inc_found_key(nfc->dict_attack, MfClassicKeyB);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventNoCardDetected) {
|
||||
dict_attack_card_removed(nfc->dict_attack);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventSuccess) {
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneReadMifareClassic, NfcSceneReadMifareClassicStateDone);
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
dict_attack_set_result(nfc->dict_attack, true);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventFail) {
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneReadMifareClassic, NfcSceneReadMifareClassicStateDone);
|
||||
dict_attack_set_result(nfc->dict_attack, false);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventNoDictFound) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_read_mifare_classic_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
// Stop worker
|
||||
nfc_worker_stop(nfc->worker);
|
||||
dict_attack_reset(nfc->dict_attack);
|
||||
}
|
Reference in New Issue
Block a user