mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
NFC App: Add scene for MF Classic custom UID
This commit is contained in:
parent
8936c02487
commit
ee64a962d9
6 changed files with 127 additions and 131 deletions
|
@ -14,11 +14,4 @@ enum NfcCustomEvent {
|
|||
NfcCustomEventRpcSessionClose,
|
||||
NfcCustomEventUpdateLog,
|
||||
NfcCustomEventSaveShadow,
|
||||
};
|
||||
|
||||
enum NfcSceneSetUidState {
|
||||
NfcSceneSetUidStateNotSet,
|
||||
NfcSceneSetUidStateMFClassic1k,
|
||||
NfcSceneSetUidStateMFClassic4k,
|
||||
NfcSceneSetUidStateMFClassicMini,
|
||||
};
|
||||
};
|
|
@ -3,6 +3,7 @@ ADD_SCENE(nfc, read, Read)
|
|||
ADD_SCENE(nfc, saved_menu, SavedMenu)
|
||||
ADD_SCENE(nfc, extra_actions, ExtraActions)
|
||||
ADD_SCENE(nfc, set_type, SetType)
|
||||
ADD_SCENE(nfc, set_type_mf_uid, SetTypeMfUid)
|
||||
ADD_SCENE(nfc, set_sak, SetSak)
|
||||
ADD_SCENE(nfc, set_atqa, SetAtqa)
|
||||
ADD_SCENE(nfc, set_uid, SetUid)
|
||||
|
|
|
@ -67,9 +67,6 @@ bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
|||
if(!scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
|
||||
// Nothing, do not count editing as saving
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetType)) {
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateNotSet);
|
||||
|
||||
dolphin_deed(DolphinDeedNfcAddSave);
|
||||
} else {
|
||||
dolphin_deed(DolphinDeedNfcSave);
|
||||
|
|
|
@ -4,19 +4,10 @@
|
|||
enum SubmenuIndex {
|
||||
SubmenuIndexNFCA4,
|
||||
SubmenuIndexNFCA7,
|
||||
SubmenuIndexMFC1k4Uid,
|
||||
SubmenuIndexMFC4k4Uid,
|
||||
SubmenuIndexMFC1k7Uid,
|
||||
SubmenuIndexMFC4k7Uid,
|
||||
SubmenuIndexMFCMini,
|
||||
SubmenuIndexMFClassicCustomUID,
|
||||
SubmenuIndexGeneratorsStart,
|
||||
};
|
||||
|
||||
static const NfcGenerator ganeator_gag = {
|
||||
.name = "Mifare Classic Custom UID",
|
||||
.generator_func = NULL,
|
||||
};
|
||||
|
||||
void nfc_scene_set_type_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
|
@ -35,32 +26,8 @@ void nfc_scene_set_type_on_enter(void* context) {
|
|||
submenu, "NFC-A 4-bytes UID", SubmenuIndexNFCA4, nfc_scene_set_type_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"MFClassic1k4b Custom uid",
|
||||
SubmenuIndexMFC1k4Uid,
|
||||
nfc_scene_set_type_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"MFClassic4k4b Custom uid",
|
||||
SubmenuIndexMFC4k4Uid,
|
||||
nfc_scene_set_type_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"MFClassic1k7b Custom uid",
|
||||
SubmenuIndexMFC1k7Uid,
|
||||
nfc_scene_set_type_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"MFClassic4k7b Custom uid ",
|
||||
SubmenuIndexMFC4k7Uid,
|
||||
nfc_scene_set_type_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"MFClassic Mini Custom uid ",
|
||||
SubmenuIndexMFCMini,
|
||||
"Mifare Classic Custom UID",
|
||||
SubmenuIndexMFClassicCustomUID,
|
||||
nfc_scene_set_type_submenu_callback,
|
||||
nfc);
|
||||
|
||||
|
@ -89,45 +56,9 @@ bool nfc_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
|||
nfc->dev->format = NfcDeviceSaveFormatUid;
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetSak);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexMFC1k4Uid) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
} else if(event.event == SubmenuIndexMFClassicCustomUID) {
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateMFClassic1k);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexMFC1k7Uid) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 7;
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateMFClassic1k);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexMFC4k4Uid) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateMFClassic4k);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexMFC4k7Uid) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 7;
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateMFClassic4k);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexMFCMini) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
nfc->dev->format = NfcDeviceSaveFormatMifareClassic;
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateMFClassicMini);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetTypeMfUid);
|
||||
consumed = true;
|
||||
} else {
|
||||
nfc_device_clear(nfc->dev);
|
||||
|
|
103
applications/main/nfc/scenes/nfc_scene_set_type_mf_uid.c
Normal file
103
applications/main/nfc/scenes/nfc_scene_set_type_mf_uid.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "../nfc_i.h"
|
||||
#include "lib/nfc/helpers/nfc_generators.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexMFC1k4b,
|
||||
SubmenuIndexMFC4k4b,
|
||||
SubmenuIndexMFC1k7b,
|
||||
SubmenuIndexMFC4k7b,
|
||||
SubmenuIndexMFCMini,
|
||||
};
|
||||
|
||||
static const NfcGenerator ganeator_gag = {
|
||||
.name = "Mifare Classic Custom UID",
|
||||
.generator_func = NULL,
|
||||
};
|
||||
|
||||
void nfc_scene_set_type_mf_uid_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void nfc_scene_set_type_mf_uid_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic 1k 4byte UID",
|
||||
SubmenuIndexMFC1k4b,
|
||||
nfc_scene_set_type_mf_uid_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic 4k 4byte UID",
|
||||
SubmenuIndexMFC4k4b,
|
||||
nfc_scene_set_type_mf_uid_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic 1k 7byte UID",
|
||||
SubmenuIndexMFC1k7b,
|
||||
nfc_scene_set_type_mf_uid_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic 4k 7byte UID",
|
||||
SubmenuIndexMFC4k7b,
|
||||
nfc_scene_set_type_mf_uid_submenu_callback,
|
||||
nfc);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic Mini",
|
||||
SubmenuIndexMFCMini,
|
||||
nfc_scene_set_type_mf_uid_submenu_callback,
|
||||
nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
bool nfc_scene_set_type_mf_uid_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
bool correct_index = false;
|
||||
MfClassicType mf_type = MfClassicType1k;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexMFC1k4b) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
mf_type = MfClassicType1k;
|
||||
correct_index = true;
|
||||
} else if(event.event == SubmenuIndexMFC1k7b) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 7;
|
||||
mf_type = MfClassicType1k;
|
||||
correct_index = true;
|
||||
} else if(event.event == SubmenuIndexMFC4k4b) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
mf_type = MfClassicType4k;
|
||||
correct_index = true;
|
||||
} else if(event.event == SubmenuIndexMFC4k7b) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 7;
|
||||
mf_type = MfClassicType4k;
|
||||
correct_index = true;
|
||||
} else if(event.event == SubmenuIndexMFCMini) {
|
||||
nfc->dev->dev_data.nfc_data.uid_len = 4;
|
||||
mf_type = MfClassicTypeMini;
|
||||
correct_index = true;
|
||||
}
|
||||
if(correct_index) {
|
||||
nfc->generator = &ganeator_gag;
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneSetTypeMfUid, mf_type);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_set_type_mf_uid_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
|
@ -27,10 +27,7 @@ bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) {
|
|||
Nfc* nfc = (Nfc*)context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneSetUid, NfcSceneSetUidStateNotSet);
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventByteInputDone) {
|
||||
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
|
||||
nfc->dev->dev_data.nfc_data = nfc->dev_edit_data;
|
||||
|
@ -38,50 +35,24 @@ bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) {
|
|||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
|
||||
consumed = true;
|
||||
}
|
||||
} else {
|
||||
switch(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneSetUid)) {
|
||||
case NfcSceneSetUidStateMFClassic1k:
|
||||
nfc_generate_mf_classic_ext(
|
||||
&nfc->dev->dev_data,
|
||||
nfc->dev_edit_data.uid_len,
|
||||
MfClassicType1k,
|
||||
false,
|
||||
nfc->dev_edit_data.uid);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneGenerateInfo);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case NfcSceneSetUidStateMFClassic4k:
|
||||
nfc_generate_mf_classic_ext(
|
||||
&nfc->dev->dev_data,
|
||||
nfc->dev_edit_data.uid_len,
|
||||
MfClassicType4k,
|
||||
false,
|
||||
nfc->dev_edit_data.uid);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneGenerateInfo);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case NfcSceneSetUidStateMFClassicMini:
|
||||
nfc_generate_mf_classic_ext(
|
||||
&nfc->dev->dev_data,
|
||||
nfc->dev_edit_data.uid_len,
|
||||
MfClassicTypeMini,
|
||||
false,
|
||||
nfc->dev_edit_data.uid);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneGenerateInfo);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case NfcSceneSetUidStateNotSet:
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetTypeMfUid)) {
|
||||
MfClassicType mf_type =
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneSetTypeMfUid);
|
||||
if(mf_type > MfClassicTypeMini) {
|
||||
furi_crash("Nfc unknown type");
|
||||
break;
|
||||
}
|
||||
nfc_generate_mf_classic_ext(
|
||||
&nfc->dev->dev_data,
|
||||
nfc->dev_edit_data.uid_len,
|
||||
mf_type,
|
||||
false,
|
||||
nfc->dev_edit_data.uid);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneGenerateInfo);
|
||||
consumed = true;
|
||||
|
||||
} else {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue