2022-03-23 22:14:34 +00:00
|
|
|
#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);
|
2022-06-13 01:08:28 +00:00
|
|
|
|
|
|
|
nfc_blink_start(nfc);
|
2022-03-23 22:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nfc_scene_read_mifare_classic_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeTick) {
|
|
|
|
consumed = true;
|
|
|
|
} else if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == NfcCustomEventDictAttackDone) {
|
2022-05-24 14:00:15 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMifareClassicMenu);
|
2022-03-23 22:14:34 +00:00
|
|
|
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);
|
2022-06-13 01:08:28 +00:00
|
|
|
nfc_blink_stop(nfc);
|
2022-03-23 22:14:34 +00:00
|
|
|
notification_message(nfc->notifications, &sequence_success);
|
|
|
|
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);
|
2022-06-13 01:08:28 +00:00
|
|
|
nfc_blink_stop(nfc);
|
2022-03-23 22:14:34 +00:00
|
|
|
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);
|
2022-06-13 01:08:28 +00:00
|
|
|
|
|
|
|
nfc_blink_stop(nfc);
|
2022-03-23 22:14:34 +00:00
|
|
|
}
|