2023-06-02 17:33:28 +00:00
|
|
|
#include "../fuzzer_i.h"
|
|
|
|
#include "../helpers/fuzzer_custom_event.h"
|
|
|
|
|
2023-06-02 21:32:32 +00:00
|
|
|
// TODO simlify callbacks and attack state
|
|
|
|
|
2023-06-06 10:03:36 +00:00
|
|
|
const NotificationSequence sequence_one_green_50_on_blink_blue = {
|
|
|
|
&message_red_255,
|
|
|
|
&message_delay_50,
|
|
|
|
&message_red_0,
|
|
|
|
&message_blink_start_10,
|
|
|
|
&message_blink_set_color_blue,
|
|
|
|
&message_do_not_reset,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void fuzzer_scene_attack_update_uid(PacsFuzzerApp* app) {
|
|
|
|
furi_assert(app);
|
|
|
|
furi_assert(app->worker);
|
|
|
|
furi_assert(app->attack_view);
|
|
|
|
|
|
|
|
FuzzerPayload uid;
|
|
|
|
fuzzer_worker_get_current_key(app->worker, &uid);
|
|
|
|
|
|
|
|
fuzzer_view_attack_set_uid(app->attack_view, uid);
|
|
|
|
|
|
|
|
free(uid.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fuzzer_scene_attack_set_state(PacsFuzzerApp* app, FuzzerAttackState state) {
|
|
|
|
furi_assert(app);
|
|
|
|
|
|
|
|
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, state);
|
|
|
|
switch(state) {
|
|
|
|
case FuzzerAttackStateIdle:
|
|
|
|
notification_message(app->notifications, &sequence_blink_stop);
|
|
|
|
fuzzer_view_attack_pause(app->attack_view);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FuzzerAttackStateRunning:
|
|
|
|
notification_message(app->notifications, &sequence_blink_start_blue);
|
|
|
|
fuzzer_view_attack_start(app->attack_view);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FuzzerAttackStateEnd:
|
|
|
|
notification_message(app->notifications, &sequence_blink_stop);
|
|
|
|
notification_message(app->notifications, &sequence_single_vibro);
|
|
|
|
fuzzer_view_attack_end(app->attack_view);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FuzzerAttackStateOff:
|
|
|
|
notification_message(app->notifications, &sequence_blink_stop);
|
|
|
|
fuzzer_view_attack_stop(app->attack_view);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-02 21:32:32 +00:00
|
|
|
void fuzzer_scene_attack_worker_tick_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
2023-06-06 10:03:36 +00:00
|
|
|
|
|
|
|
notification_message(app->notifications, &sequence_one_green_50_on_blink_blue);
|
|
|
|
fuzzer_scene_attack_update_uid(app);
|
|
|
|
|
|
|
|
// view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackTick);
|
2023-06-02 21:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_scene_attack_worker_end_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, FuzzerCustomEventViewAttackEnd);
|
|
|
|
}
|
|
|
|
|
2023-06-02 17:33:28 +00:00
|
|
|
void fuzzer_scene_attack_callback(FuzzerCustomEvent event, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_scene_attack_on_enter(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
|
|
|
|
|
|
|
fuzzer_view_attack_set_callback(app->attack_view, fuzzer_scene_attack_callback, app);
|
|
|
|
|
2023-06-02 21:32:32 +00:00
|
|
|
fuzzer_worker_set_uid_chaged_callback(
|
|
|
|
app->worker, fuzzer_scene_attack_worker_tick_callback, app);
|
|
|
|
|
|
|
|
fuzzer_worker_set_end_callback(app->worker, fuzzer_scene_attack_worker_end_callback, app);
|
|
|
|
|
2023-06-03 15:47:53 +00:00
|
|
|
fuzzer_view_attack_reset_data(
|
|
|
|
app->attack_view,
|
2023-06-05 11:10:51 +00:00
|
|
|
fuzzer_proto_get_menu_label(app->fuzzer_state.menu_index),
|
|
|
|
fuzzer_proto_get_name(app->fuzzer_state.proto_index));
|
|
|
|
|
|
|
|
fuzzer_scene_attack_update_uid(app);
|
2023-06-02 21:32:32 +00:00
|
|
|
|
2023-06-05 14:49:30 +00:00
|
|
|
scene_manager_set_scene_state(app->scene_manager, FuzzerSceneAttack, FuzzerAttackStateIdle);
|
2023-06-02 17:33:28 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, FuzzerViewIDAttack);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fuzzer_scene_attack_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == FuzzerCustomEventViewAttackBack) {
|
2023-06-05 14:49:30 +00:00
|
|
|
if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) ==
|
|
|
|
FuzzerAttackStateRunning) {
|
|
|
|
// Pause if attack running
|
|
|
|
fuzzer_worker_pause(app->worker);
|
2023-06-06 10:03:36 +00:00
|
|
|
|
|
|
|
fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle);
|
2023-06-05 14:49:30 +00:00
|
|
|
} else {
|
|
|
|
// Exit
|
|
|
|
fuzzer_worker_stop(app->worker);
|
2023-06-06 10:03:36 +00:00
|
|
|
|
|
|
|
fuzzer_scene_attack_set_state(app, FuzzerAttackStateOff);
|
2023-06-02 21:32:32 +00:00
|
|
|
if(!scene_manager_previous_scene(app->scene_manager)) {
|
|
|
|
scene_manager_stop(app->scene_manager);
|
|
|
|
view_dispatcher_stop(app->view_dispatcher);
|
|
|
|
}
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
consumed = true;
|
2023-06-02 21:32:32 +00:00
|
|
|
} else if(event.event == FuzzerCustomEventViewAttackOk) {
|
2023-06-05 14:49:30 +00:00
|
|
|
if(scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) ==
|
|
|
|
FuzzerAttackStateIdle) {
|
|
|
|
// Start or Continue Attack
|
|
|
|
if(fuzzer_worker_start(
|
|
|
|
app->worker, fuzzer_view_attack_get_time_delay(app->attack_view))) {
|
2023-06-06 10:03:36 +00:00
|
|
|
fuzzer_scene_attack_set_state(app, FuzzerAttackStateRunning);
|
2023-06-05 14:49:30 +00:00
|
|
|
} else {
|
|
|
|
// Error?
|
|
|
|
}
|
|
|
|
} else if(
|
|
|
|
scene_manager_get_scene_state(app->scene_manager, FuzzerSceneAttack) ==
|
|
|
|
FuzzerAttackStateRunning) {
|
2023-06-06 10:03:36 +00:00
|
|
|
// Pause if attack running
|
2023-06-06 13:55:29 +00:00
|
|
|
fuzzer_worker_pause(app->worker);
|
2023-06-06 10:03:36 +00:00
|
|
|
|
|
|
|
fuzzer_scene_attack_set_state(app, FuzzerAttackStateIdle);
|
2023-06-02 21:32:32 +00:00
|
|
|
}
|
|
|
|
consumed = true;
|
2023-06-06 10:03:36 +00:00
|
|
|
// } else if(event.event == FuzzerCustomEventViewAttackTick) {
|
|
|
|
// consumed = true;
|
2023-06-02 21:32:32 +00:00
|
|
|
} else if(event.event == FuzzerCustomEventViewAttackEnd) {
|
2023-06-06 10:03:36 +00:00
|
|
|
fuzzer_scene_attack_set_state(app, FuzzerAttackStateEnd);
|
2023-06-02 21:32:32 +00:00
|
|
|
consumed = true;
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fuzzer_scene_attack_on_exit(void* context) {
|
2023-06-02 21:32:32 +00:00
|
|
|
furi_assert(context);
|
|
|
|
PacsFuzzerApp* app = context;
|
|
|
|
|
2023-06-06 10:03:36 +00:00
|
|
|
// fuzzer_worker_stop(); // XXX
|
|
|
|
|
2023-06-02 21:32:32 +00:00
|
|
|
fuzzer_worker_set_uid_chaged_callback(app->worker, NULL, NULL);
|
|
|
|
fuzzer_worker_set_end_callback(app->worker, NULL, NULL);
|
2023-06-02 17:33:28 +00:00
|
|
|
}
|