NRF24 plugins updates

Updates by Sil333033 with some changes, furi_hal speaker direct calls was removed and replaced with notification service to avoid bypassing of user set silent mode
This commit is contained in:
MX 2023-07-18 02:53:30 +03:00
parent e2028eb731
commit bb6d3cb796
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
7 changed files with 85 additions and 45 deletions

View file

@ -517,4 +517,14 @@ uint8_t nrf24_find_channel(
}
return ch;
}
bool nrf24_check_connected(FuriHalSpiBusHandle* handle) {
uint8_t status = nrf24_status(handle);
if(status != 0x00) {
return true;
} else {
return false;
}
}

View file

@ -361,6 +361,13 @@ void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian);
*/
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
/** Check if the nrf24 is connected
* @param handle - pointer to FuriHalSpiHandle
*
* @return true if connected, otherwise false
*/
bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
#ifdef __cplusplus
}
#endif

View file

@ -9,15 +9,14 @@
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <nrf24.h>
#include <notification/notification_messages.h>
#include "mousejacker_ducky.h"
#include <nrf24_mouse_jacker_icons.h>
#define TAG "mousejacker"
#define LOGITECH_MAX_CHANNEL 85
#define NRFSNIFF_APP_PATH_FOLDER "/ext/nrfsniff"
#define NRFSNIFF_APP_PATH_EXTENSION ".txt"
#define NRFSNIFF_APP_FILENAME "addresses.txt"
#define MOUSEJACKER_APP_PATH_FOLDER "/ext/mousejacker"
#define NRFSNIFF_APP_PATH_FOLDER_ADDRESSES EXT_PATH("apps_data/nrf24sniff/addresses.txt")
#define LOCAL_BADUSB_FOLDER EXT_PATH("badusb")
#define MOUSEJACKER_APP_PATH_EXTENSION ".txt"
#define MAX_ADDRS 100
@ -32,12 +31,13 @@ typedef struct {
} PluginEvent;
uint8_t addrs_count = 0;
uint8_t addr_idx = 0;
int8_t addr_idx = 0;
uint8_t loaded_addrs[MAX_ADDRS][6]; // first byte is rate, the rest are the address
char target_fmt_text[] = "Target addr: %s";
char target_address_str[12] = "None";
char target_text[30];
char index_text[30];
static void render_callback(Canvas* const canvas, void* ctx) {
furi_assert(ctx);
@ -53,8 +53,15 @@ static void render_callback(Canvas* const canvas, void* ctx) {
snprintf(target_text, sizeof(target_text), target_fmt_text, target_address_str);
canvas_draw_str_aligned(canvas, 7, 10, AlignLeft, AlignBottom, target_text);
canvas_draw_str_aligned(canvas, 22, 20, AlignLeft, AlignBottom, "<- select address ->");
canvas_draw_str_aligned(canvas, 10, 30, AlignLeft, AlignBottom, "Press Ok button to ");
canvas_draw_str_aligned(canvas, 10, 40, AlignLeft, AlignBottom, "browse for ducky script");
snprintf(
index_text, sizeof(index_text), "Address index: %d/%d", addr_idx + 1, addrs_count);
canvas_draw_str_aligned(canvas, 10, 30, AlignLeft, AlignBottom, index_text);
canvas_draw_str_aligned(canvas, 10, 40, AlignLeft, AlignBottom, "Press Ok button to ");
canvas_draw_str_aligned(canvas, 10, 50, AlignLeft, AlignBottom, "browse for ducky script");
if(!plugin_state->is_nrf24_connected) {
canvas_draw_str_aligned(
canvas, 10, 60, AlignLeft, AlignBottom, "Connect NRF24 to GPIO!");
}
} else if(plugin_state->addr_err) {
canvas_draw_str_aligned(
canvas, 10, 10, AlignLeft, AlignBottom, "Error: No nrfsniff folder");
@ -94,6 +101,7 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
static void mousejacker_state_init(PluginState* const plugin_state) {
plugin_state->is_thread_running = false;
plugin_state->is_nrf24_connected = true;
}
static void hexlify(uint8_t* in, uint8_t size, char* out) {
@ -107,7 +115,7 @@ static bool open_ducky_script(Stream* stream, PluginState* plugin_state) {
bool result = false;
FuriString* path;
path = furi_string_alloc();
furi_string_set(path, MOUSEJACKER_APP_PATH_FOLDER);
furi_string_set(path, LOCAL_BADUSB_FOLDER);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
@ -132,27 +140,17 @@ static bool open_ducky_script(Stream* stream, PluginState* plugin_state) {
}
static bool open_addrs_file(Stream* stream) {
DialogsApp* dialogs = furi_record_open("dialogs");
bool result = false;
FuriString* path;
path = furi_string_alloc();
furi_string_set(path, NRFSNIFF_APP_PATH_FOLDER);
furi_string_set(path, NRFSNIFF_APP_PATH_FOLDER_ADDRESSES);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(
&browser_options, NRFSNIFF_APP_PATH_EXTENSION, &I_sub1_10px);
browser_options.hide_ext = false;
bool ret = dialog_file_browser_show(dialogs, path, path, &browser_options);
furi_record_close("dialogs");
if(ret) {
if(!file_stream_open(stream, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_D(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(path));
} else {
result = true;
}
if(!file_stream_open(stream, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_D(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(path));
} else {
result = true;
}
furi_string_free(path);
return result;
}
@ -277,12 +275,6 @@ static int32_t mj_worker_thread(void* ctx) {
return 0;
}
void start_mjthread(PluginState* plugin_state) {
if(!plugin_state->is_thread_running) {
furi_thread_start(plugin_state->mjthread);
}
}
int32_t mousejacker_app(void* p) {
UNUSED(p);
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
@ -297,6 +289,8 @@ int32_t mousejacker_app(void* p) {
return 255;
}
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
// Set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, render_callback, plugin_state);
@ -307,7 +301,6 @@ int32_t mousejacker_app(void* p) {
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
plugin_state->storage = furi_record_open(RECORD_STORAGE);
storage_common_mkdir(plugin_state->storage, MOUSEJACKER_APP_PATH_FOLDER);
plugin_state->file_stream = file_stream_alloc(plugin_state->storage);
plugin_state->mjthread = furi_thread_alloc();
@ -344,21 +337,25 @@ int32_t mousejacker_app(void* p) {
case InputKeyRight:
if(!plugin_state->addr_err) {
addr_idx++;
if(addr_idx > addrs_count) addr_idx = 0;
if(addr_idx >= addrs_count) addr_idx = 0;
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
}
break;
case InputKeyLeft:
if(!plugin_state->addr_err) {
addr_idx--;
if(addr_idx == 0) addr_idx = addrs_count - 1;
if(addr_idx < 0) addr_idx = addrs_count - 1;
hexlify(loaded_addrs[addr_idx] + 1, 5, target_address_str);
}
break;
case InputKeyOk:
if(!plugin_state->addr_err) {
if(!plugin_state->is_thread_running) {
start_mjthread(plugin_state);
if(!nrf24_check_connected(nrf24_HANDLE)) {
plugin_state->is_nrf24_connected = false;
view_port_update(view_port);
notification_message(notification, &sequence_error);
} else if(!plugin_state->is_thread_running) {
furi_thread_start(plugin_state->mjthread);
view_port_update(view_port);
}
}
@ -388,6 +385,7 @@ int32_t mousejacker_app(void* p) {
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_STORAGE);
view_port_free(view_port);
furi_message_queue_free(event_queue);
@ -395,4 +393,4 @@ int32_t mousejacker_app(void* p) {
free(plugin_state);
return 0;
}
}

View file

@ -26,6 +26,7 @@ typedef struct {
bool addr_err;
bool is_thread_running;
bool is_ducky_running;
bool is_nrf24_connected;
bool close_thread_please;
Storage* storage;
FuriThread* mjthread;

View file

@ -517,4 +517,14 @@ uint8_t nrf24_find_channel(
}
return ch;
}
bool nrf24_check_connected(FuriHalSpiBusHandle* handle) {
uint8_t status = nrf24_status(handle);
if(status != 0x00) {
return true;
} else {
return false;
}
}

View file

@ -361,6 +361,13 @@ void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian);
*/
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
/** Check if the nrf24 is connected
* @param handle - pointer to FuriHalSpiHandle
*
* @return true if connected, otherwise false
*/
bool nrf24_check_connected(FuriHalSpiBusHandle* handle);
#ifdef __cplusplus
}
#endif

View file

@ -10,11 +10,11 @@
#define LOGITECH_MAX_CHANNEL 85
#define COUNT_THRESHOLD 2
#define DEFAULT_SAMPLE_TIME 8000
#define DEFAULT_SAMPLE_TIME 4000
#define MAX_ADDRS 100
#define MAX_CONFIRMED 32
#define NRFSNIFF_APP_PATH_FOLDER "/ext/nrfsniff"
#define NRFSNIFF_APP_PATH_FOLDER STORAGE_APP_DATA_PATH_PREFIX
#define NRFSNIFF_APP_FILENAME "addresses.txt"
#define TAG "nrfsniff"
@ -341,6 +341,7 @@ int32_t nrfsniff_app(void* p) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_common_migrate(storage, EXT_PATH("nrfsniff"), NRFSNIFF_APP_PATH_FOLDER);
storage_common_mkdir(storage, NRFSNIFF_APP_PATH_FOLDER);
PluginEvent event;
@ -387,13 +388,19 @@ int32_t nrfsniff_app(void* p) {
break;
case InputKeyOk:
// toggle sniffing
sniffing_state = !sniffing_state;
if(sniffing_state) {
clear_cache();
start_sniffing();
start = furi_get_tick();
} else
wrap_up(storage, notification);
if(nrf24_check_connected(nrf24_HANDLE)) {
sniffing_state = !sniffing_state;
if(sniffing_state) {
clear_cache();
start_sniffing();
start = furi_get_tick();
} else {
wrap_up(storage, notification);
}
} else {
notification_message(notification, &sequence_error);
}
break;
case InputKeyBack:
if(event.input.type == InputTypeLong) processing = false;