-
Notifications
You must be signed in to change notification settings - Fork 47
/
subbrute.c
218 lines (165 loc) · 6.82 KB
/
subbrute.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "subbrute_i.h"
#include "scenes/subbrute_scene.h"
#define TAG "SubBruteApp"
static bool subbrute_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
SubBruteState* instance = context;
return scene_manager_handle_custom_event(instance->scene_manager, event);
}
static bool subbrute_back_event_callback(void* context) {
furi_assert(context);
SubBruteState* instance = context;
return scene_manager_handle_back_event(instance->scene_manager);
}
static void subbrute_tick_event_callback(void* context) {
furi_assert(context);
SubBruteState* instance = context;
scene_manager_handle_tick_event(instance->scene_manager);
}
SubBruteState* subbrute_alloc() {
SubBruteState* instance = malloc(sizeof(SubBruteState));
memset(instance->text_store, 0, sizeof(instance->text_store));
instance->file_path = furi_string_alloc();
instance->scene_manager = scene_manager_alloc(&subbrute_scene_handlers, instance);
instance->view_dispatcher = view_dispatcher_alloc();
instance->gui = furi_record_open(RECORD_GUI);
view_dispatcher_set_event_callback_context(instance->view_dispatcher, instance);
view_dispatcher_set_custom_event_callback(
instance->view_dispatcher, subbrute_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
instance->view_dispatcher, subbrute_back_event_callback);
view_dispatcher_set_tick_event_callback(
instance->view_dispatcher, subbrute_tick_event_callback, 100);
//Dialog
instance->dialogs = furi_record_open(RECORD_DIALOGS);
// Notifications
instance->notifications = furi_record_open(RECORD_NOTIFICATION);
subghz_devices_init();
// init radio device
instance->radio_device = subbrute_radio_device_loader_set(
instance->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
subghz_devices_reset(instance->radio_device);
subghz_devices_idle(instance->radio_device);
// Devices
instance->device = subbrute_device_alloc(instance->radio_device);
// SubBruteWorker
instance->worker = subbrute_worker_alloc(instance->radio_device);
// TextInput
instance->text_input = text_input_alloc();
view_dispatcher_add_view(
instance->view_dispatcher,
SubBruteViewTextInput,
text_input_get_view(instance->text_input));
// Custom Widget
instance->widget = widget_alloc();
view_dispatcher_add_view(
instance->view_dispatcher, SubBruteViewWidget, widget_get_view(instance->widget));
// VarList
instance->var_list = variable_item_list_alloc();
view_dispatcher_add_view(
instance->view_dispatcher,
SubBruteViewVarList,
variable_item_list_get_view(instance->var_list));
// Popup
instance->popup = popup_alloc();
view_dispatcher_add_view(
instance->view_dispatcher, SubBruteViewPopup, popup_get_view(instance->popup));
// ViewStack
instance->view_stack = view_stack_alloc();
view_dispatcher_add_view(
instance->view_dispatcher, SubBruteViewStack, view_stack_get_view(instance->view_stack));
// SubBruteMainView
instance->view_main = subbrute_main_view_alloc();
view_dispatcher_add_view(
instance->view_dispatcher,
SubBruteViewMain,
subbrute_main_view_get_view(instance->view_main));
// SubBruteAttackView
instance->view_attack = subbrute_attack_view_alloc();
view_dispatcher_add_view(
instance->view_dispatcher,
SubBruteViewAttack,
subbrute_attack_view_get_view(instance->view_attack));
instance->settings = subbrute_settings_alloc();
subbrute_settings_load(instance->settings);
// Uncomment to enable Debug pin output on PIN 17(1W)
// subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
return instance;
}
void subbrute_free(SubBruteState* instance) {
furi_assert(instance);
// Uncomment to enable Debug pin output on PIN 17(1W)
// subghz_devices_set_async_mirror_pin(instance->radio_device, NULL);
// SubBruteWorker
subbrute_worker_stop(instance->worker);
subbrute_worker_free(instance->worker);
// SubBruteDevice
subbrute_device_free(instance->device);
subghz_devices_deinit();
//subbrute_settings_save(instance->settings);
subbrute_settings_free(instance->settings);
// Notifications
notification_message(instance->notifications, &sequence_blink_stop);
furi_record_close(RECORD_NOTIFICATION);
instance->notifications = NULL;
// View Main
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewMain);
subbrute_main_view_free(instance->view_main);
// View Attack
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewAttack);
subbrute_attack_view_free(instance->view_attack);
// TextInput
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewTextInput);
text_input_free(instance->text_input);
// Custom Widget
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewWidget);
widget_free(instance->widget);
// VarList
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewVarList);
variable_item_list_free(instance->var_list);
// Popup
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewPopup);
popup_free(instance->popup);
// ViewStack
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewStack);
view_stack_free(instance->view_stack);
// Dialog
furi_record_close(RECORD_DIALOGS);
instance->dialogs = NULL;
// Scene manager
scene_manager_free(instance->scene_manager);
// View Dispatcher
view_dispatcher_free(instance->view_dispatcher);
// GUI
furi_record_close(RECORD_GUI);
instance->gui = NULL;
furi_string_free(instance->file_path);
// The rest
free(instance);
}
void subbrute_text_input_callback(void* context) {
furi_assert(context);
SubBruteState* instance = context;
view_dispatcher_send_custom_event(
instance->view_dispatcher, SubBruteCustomEventTypeTextEditDone);
}
void subbrute_popup_closed_callback(void* context) {
furi_assert(context);
SubBruteState* instance = context;
view_dispatcher_send_custom_event(
instance->view_dispatcher, SubBruteCustomEventTypePopupClosed);
}
// ENTRYPOINT
int32_t subbrute_app(void* p) {
UNUSED(p);
furi_hal_power_suppress_charge_enter();
SubBruteState* instance = subbrute_alloc();
view_dispatcher_attach_to_gui(
instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
notification_message(instance->notifications, &sequence_display_backlight_on);
view_dispatcher_run(instance->view_dispatcher);
subbrute_free(instance);
furi_hal_power_suppress_charge_exit();
return 0;
}