Merge branch 'gsurkov/3764_expansion_control' of https://github.com/flipperdevices/flipperzero-firmware into xfw-dev

This commit is contained in:
Willy-JL
2024-02-09 15:11:55 +00:00
71 changed files with 1646 additions and 594 deletions

View File

@@ -61,4 +61,9 @@ ADD_SCENE(nfc, set_sak, SetSak)
ADD_SCENE(nfc, set_atqa, SetAtqa)
ADD_SCENE(nfc, set_uid, SetUid)
ADD_SCENE(nfc, slix_unlock_menu, SlixUnlockMenu)
ADD_SCENE(nfc, slix_key_input, SlixKeyInput)
ADD_SCENE(nfc, slix_unlock, SlixUnlock)
ADD_SCENE(nfc, slix_unlock_success, SlixUnlockSuccess)
ADD_SCENE(nfc, generate_info, GenerateInfo)

View File

@@ -4,6 +4,7 @@ enum SubmenuIndex {
SubmenuIndexReadCardType,
SubmenuIndexMfClassicKeys,
SubmenuIndexMfUltralightUnlock,
SubmenuIndexSlixUnlock,
};
void nfc_scene_extra_actions_submenu_callback(void* context, uint32_t index) {
@@ -34,6 +35,12 @@ void nfc_scene_extra_actions_on_enter(void* context) {
SubmenuIndexMfUltralightUnlock,
nfc_scene_extra_actions_submenu_callback,
instance);
submenu_add_item(
submenu,
"Unlock SLIX-L",
SubmenuIndexSlixUnlock,
nfc_scene_extra_actions_submenu_callback,
instance);
submenu_set_selected_item(
submenu, scene_manager_get_scene_state(instance->scene_manager, NfcSceneExtraActions));
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu);
@@ -54,6 +61,9 @@ bool nfc_scene_extra_actions_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == SubmenuIndexReadCardType) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSelectProtocol);
consumed = true;
} else if(event.event == SubmenuIndexSlixUnlock) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlockMenu);
consumed = true;
}
scene_manager_set_scene_state(instance->scene_manager, NfcSceneExtraActions, event.event);
}

View File

@@ -28,7 +28,11 @@ bool nfc_scene_retry_confirm_on_event(void* context, SceneManagerEvent event) {
if(event.event == DialogExResultRight) {
consumed = scene_manager_previous_scene(nfc->scene_manager);
} else if(event.event == DialogExResultLeft) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneMfClassicDictAttack)) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSlixUnlock)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneSlixUnlock);
} else if(scene_manager_has_previous_scene(
nfc->scene_manager, NfcSceneMfClassicDictAttack)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicDictAttack);
} else if(scene_manager_has_previous_scene(

View File

@@ -67,6 +67,10 @@ bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveSuccess);
consumed = true;
}
} else if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneReadMenu)) {
scene_manager_search_and_switch_to_previous_scene(
instance->scene_manager, NfcSceneReadMenu);
consumed = true;
} else {
if(nfc_device_get_protocol(instance->nfc_device) == NfcProtocolMfClassic)
mfclassic_sync_uid(instance->nfc_device);

View File

@@ -0,0 +1,48 @@
#include "../nfc_app_i.h"
#include <nfc/helpers/nfc_util.h>
void nfc_scene_slix_key_input_byte_input_callback(void* context) {
NfcApp* instance = context;
SlixPassword password = nfc_util_bytes2num(instance->byte_input_store, sizeof(SlixPassword));
slix_unlock_set_password(instance->slix_unlock, password);
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventByteInputDone);
}
void nfc_scene_slix_key_input_on_enter(void* context) {
NfcApp* instance = context;
// Setup view
ByteInput* byte_input = instance->byte_input;
byte_input_set_header_text(byte_input, "Enter the password in hex");
byte_input_set_result_callback(
byte_input,
nfc_scene_slix_key_input_byte_input_callback,
NULL,
instance,
instance->byte_input_store,
sizeof(SlixPassword));
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewByteInput);
}
bool nfc_scene_slix_key_input_on_event(void* context, SceneManagerEvent event) {
NfcApp* instance = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventByteInputDone) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlock);
consumed = true;
}
}
return consumed;
}
void nfc_scene_slix_key_input_on_exit(void* context) {
NfcApp* instance = context;
// Clear view
byte_input_set_result_callback(instance->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(instance->byte_input, "");
}

View File

@@ -0,0 +1,70 @@
#include "../nfc_app_i.h"
#include <nfc/protocols/slix/slix_poller.h>
NfcCommand nfc_scene_slix_unlock_worker_callback(NfcGenericEvent event, void* context) {
furi_assert(event.protocol == NfcProtocolSlix);
NfcCommand command = NfcCommandContinue;
NfcApp* instance = context;
SlixPollerEvent* slix_event = event.event_data;
if(slix_event->type == SlixPollerEventTypePrivacyUnlockRequest) {
SlixPassword pwd = 0;
bool get_password_success = slix_unlock_get_next_password(instance->slix_unlock, &pwd);
slix_event->data->privacy_password.password = pwd;
slix_event->data->privacy_password.password_set = get_password_success;
} else if(slix_event->type == SlixPollerEventTypeError) {
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerFailure);
} else if(slix_event->type == SlixPollerEventTypeReady) {
nfc_device_set_data(
instance->nfc_device, NfcProtocolSlix, nfc_poller_get_data(instance->poller));
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess);
command = NfcCommandStop;
}
return command;
}
void nfc_scene_slix_unlock_on_enter(void* context) {
NfcApp* instance = context;
popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50);
popup_set_header(instance->popup, "Unlocking", 97, 15, AlignCenter, AlignTop);
popup_set_text(
instance->popup, "Apply card to\nFlipper's back", 97, 27, AlignCenter, AlignTop);
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewPopup);
instance->poller = nfc_poller_alloc(instance->nfc, NfcProtocolSlix);
nfc_poller_start(instance->poller, nfc_scene_slix_unlock_worker_callback, instance);
}
bool nfc_scene_slix_unlock_on_event(void* context, SceneManagerEvent event) {
NfcApp* instance = context;
UNUSED(instance);
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventPollerFailure) {
consumed = true;
} else if(event.event == NfcCustomEventPollerSuccess) {
notification_message(instance->notifications, &sequence_success);
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlockSuccess);
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = scene_manager_search_and_switch_to_previous_scene(
instance->scene_manager, NfcSceneSlixUnlockMenu);
}
return consumed;
}
void nfc_scene_slix_unlock_on_exit(void* context) {
NfcApp* instance = context;
nfc_poller_stop(instance->poller);
nfc_poller_free(instance->poller);
popup_reset(instance->popup);
}

View File

@@ -0,0 +1,60 @@
#include "../nfc_app_i.h"
enum SubmenuIndex {
SubmenuIndexSlixUnlockMenuManual,
SubmenuIndexSlixUnlockMenuTonieBox,
};
void nfc_scene_slix_unlock_menu_submenu_callback(void* context, uint32_t index) {
NfcApp* instance = context;
view_dispatcher_send_custom_event(instance->view_dispatcher, index);
}
void nfc_scene_slix_unlock_menu_on_enter(void* context) {
NfcApp* instance = context;
Submenu* submenu = instance->submenu;
uint32_t state =
scene_manager_get_scene_state(instance->scene_manager, NfcSceneSlixUnlockMenu);
submenu_add_item(
submenu,
"Enter Password Manually",
SubmenuIndexSlixUnlockMenuManual,
nfc_scene_slix_unlock_menu_submenu_callback,
instance);
submenu_add_item(
submenu,
"Auth As TommyBox",
SubmenuIndexSlixUnlockMenuTonieBox,
nfc_scene_slix_unlock_menu_submenu_callback,
instance);
submenu_set_selected_item(submenu, state);
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu);
}
bool nfc_scene_slix_unlock_menu_on_event(void* context, SceneManagerEvent event) {
NfcApp* instance = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexSlixUnlockMenuManual) {
slix_unlock_set_method(instance->slix_unlock, SlixUnlockMethodManual);
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixKeyInput);
consumed = true;
} else if(event.event == SubmenuIndexSlixUnlockMenuTonieBox) {
slix_unlock_set_method(instance->slix_unlock, SlixUnlockMethodTonieBox);
scene_manager_next_scene(instance->scene_manager, NfcSceneSlixUnlock);
consumed = true;
}
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneSlixUnlockMenu, event.event);
}
return consumed;
}
void nfc_scene_slix_unlock_menu_on_exit(void* context) {
NfcApp* instance = context;
submenu_reset(instance->submenu);
}

View File

@@ -0,0 +1,71 @@
#include "../nfc_app_i.h"
static void nfc_scene_slix_unlock_success_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
NfcApp* instance = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(instance->view_dispatcher, result);
}
}
void nfc_scene_slix_unlock_success_on_enter(void* context) {
NfcApp* instance = context;
Widget* widget = instance->widget;
widget_add_string_element(widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "SLIX Unlocked!");
FuriString* temp_str = furi_string_alloc_set_str("UID:");
size_t uid_len = 0;
const uint8_t* uid = nfc_device_get_uid(instance->nfc_device, &uid_len);
for(size_t i = 0; i < uid_len; i++) {
furi_string_cat_printf(temp_str, " %02X", uid[i]);
}
furi_string_cat_printf(temp_str, "\nPrivacy Mode: Disabled");
widget_add_string_multiline_element(
widget, 0, 12, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(temp_str));
furi_string_free(temp_str);
widget_add_button_element(
widget,
GuiButtonTypeLeft,
"Retry",
nfc_scene_slix_unlock_success_widget_callback,
instance);
widget_add_button_element(
widget,
GuiButtonTypeRight,
"More",
nfc_scene_slix_unlock_success_widget_callback,
instance);
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewWidget);
}
bool nfc_scene_slix_unlock_success_on_event(void* context, SceneManagerEvent event) {
NfcApp* instance = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
scene_manager_next_scene(instance->scene_manager, NfcSceneRetryConfirm);
consumed = true;
} else if(event.event == GuiButtonTypeRight) {
scene_manager_next_scene(instance->scene_manager, NfcSceneReadMenu);
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_next_scene(instance->scene_manager, NfcSceneExitConfirm);
consumed = true;
}
return consumed;
}
void nfc_scene_slix_unlock_success_on_exit(void* context) {
NfcApp* instance = context;
widget_reset(instance->widget);
}