mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-24 05:48:08 +03:00
d31578508a
* digital signal: introduce digital signal * nfca: add nfca signal encoder * nfc: add mifare classic emulation scene * nfca: add classic emulation support to lib and hal * mifare classic: support basic read commands * nfc: add mifare classic menu scene * mifare classic: start parsing commands in emulation * mifare classic: add nested auth * nfc: fix errors * mifare classic: add encrypt function * nfc: fix mifare classic save * lib hex: add hex uint64_t ASCII parser * flipper format: add uint64 hex format support * nfc: add mifare classic key map * nfc: hide mifare classic keys on emulation * mifare classic: add NACK responce * nfc: add partial bytes support in transparent mode * nfc: mifare classic add shadow file support * digital signal: move arr buffer from BSS to heap * mifare classic: process access bits more careful * nfca: fix memory leack * nfc: format sources * mifare classic: cleun up Co-authored-by: あく <alleteam@gmail.com>
95 lines
3.9 KiB
C
95 lines
3.9 KiB
C
#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, NfcSceneMifareClassicMenu);
|
|
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);
|
|
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);
|
|
}
|