Skip to content

Commit

Permalink
Merge branch 'release-candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Mar 25, 2022
2 parents f2a8485 + b29c0d3 commit 631e532
Show file tree
Hide file tree
Showing 339 changed files with 6,242 additions and 32,150 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- [ Describe how to verify changes ]

# Checklist (do not modify)
# Checklist (For Reviewer)

- [ ] PR has description of feature/bug or link to Confluence/Jira task
- [ ] Description contains actions to verify feature/bugfix
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
pull_request:

env:
TARGETS: f6 f7
TARGETS: f7
DEFAULT_TARGET: f7

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
pull_request:

env:
TARGETS: f6 f7
TARGETS: f7

jobs:
lint_c_cpp:
Expand Down
3 changes: 2 additions & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cask "gcc-arm-embedded"
brew "protobuf"
brew "gdb"
brew "heatshrink"
brew "open-ocd"
brew "clang-format"
brew "dfu-util"
brew "imagemagick"
brew "imagemagick"
21 changes: 11 additions & 10 deletions applications/bad_usb/bad_usb_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

if(*app->file_name != '\0') {
scene_manager_next_scene(app->scene_manager, BadUsbSceneWork);
} else if(bad_usb_check_assets()) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
} else {
if(furi_hal_usb_is_locked()) {
app->error = BadUsbAppErrorCloseRpc;
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
} else {
if(*app->file_name != '\0') {
scene_manager_next_scene(app->scene_manager, BadUsbSceneWork);
} else if(bad_usb_check_assets()) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
} else {
app->error = BadUsbAppErrorNoFiles;
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
}
}

return app;
Expand Down Expand Up @@ -115,15 +121,10 @@ void bad_usb_app_free(BadUsbApp* app) {
}

int32_t bad_usb_app(void* p) {
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
furi_hal_usb_set_config(&usb_hid);

BadUsbApp* bad_usb_app = bad_usb_app_alloc((char*)p);

view_dispatcher_run(bad_usb_app->view_dispatcher);

furi_hal_usb_set_config(usb_mode_prev);
bad_usb_app_free(bad_usb_app);

return 0;
}
6 changes: 6 additions & 0 deletions applications/bad_usb/bad_usb_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#define BAD_USB_APP_EXTENSION ".txt"
#define BAD_USB_FILE_NAME_LEN 40

typedef enum {
BadUsbAppErrorNoFiles,
BadUsbAppErrorCloseRpc,
} BadUsbAppError;

struct BadUsbApp {
Gui* gui;
ViewDispatcher* view_dispatcher;
Expand All @@ -26,6 +31,7 @@ struct BadUsbApp {
DialogsApp* dialogs;
Widget* widget;

BadUsbAppError error;
char file_name[BAD_USB_FILE_NAME_LEN + 1];
BadUsb* bad_usb_view;
BadUsbScript* bad_usb_script;
Expand Down
54 changes: 53 additions & 1 deletion applications/bad_usb/bad_usb_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum {
} WorkerEvtFlags;

struct BadUsbScript {
FuriHalUsbHidConfig hid_cfg;
BadUsbState st;
string_t file_path;
uint32_t defdelay;
Expand Down Expand Up @@ -101,6 +102,7 @@ static const DuckyKey ducky_keys[] = {
};

static const char ducky_cmd_comment[] = {"REM"};
static const char ducky_cmd_id[] = {"ID"};
static const char ducky_cmd_delay[] = {"DELAY "};
static const char ducky_cmd_string[] = {"STRING "};
static const char ducky_cmd_defdelay_1[] = {"DEFAULT_DELAY "};
Expand Down Expand Up @@ -240,12 +242,15 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, string_t line) {
if(i == line_len - 1) return SCRIPT_STATE_NEXT_LINE; // Skip empty lines
}

FURI_LOG_I(WORKER_TAG, "line:%s", line_tmp);
FURI_LOG_D(WORKER_TAG, "line:%s", line_tmp);

// General commands
if(strncmp(line_tmp, ducky_cmd_comment, strlen(ducky_cmd_comment)) == 0) {
// REM - comment line
return (0);
} else if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
// ID - executed in ducky_script_preload
return (0);
} else if(strncmp(line_tmp, ducky_cmd_delay, strlen(ducky_cmd_delay)) == 0) {
// DELAY
line_tmp = &line_tmp[ducky_get_command_len(line_tmp) + 1];
Expand Down Expand Up @@ -302,17 +307,47 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, string_t line) {
return SCRIPT_STATE_ERROR;
}

static bool ducky_set_usb_id(BadUsbScript* bad_usb, const char* line) {
if(sscanf(line, "%lX:%lX", &bad_usb->hid_cfg.vid, &bad_usb->hid_cfg.pid) == 2) {
bad_usb->hid_cfg.manuf[0] = '\0';
bad_usb->hid_cfg.product[0] = '\0';

uint8_t id_len = ducky_get_command_len(line);
if(!ducky_is_line_end(line[id_len + 1])) {
sscanf(
&line[id_len + 1],
"%31[^\r\n:]:%31[^\r\n]",
bad_usb->hid_cfg.manuf,
bad_usb->hid_cfg.product);
}
FURI_LOG_D(
WORKER_TAG,
"set id: %04X:%04X mfr:%s product:%s",
bad_usb->hid_cfg.vid,
bad_usb->hid_cfg.pid,
bad_usb->hid_cfg.manuf,
bad_usb->hid_cfg.product);
return true;
}
return false;
}

static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
uint8_t ret = 0;
uint32_t line_len = 0;

string_reset(bad_usb->line);

do {
ret = storage_file_read(script_file, bad_usb->file_buf, FILE_BUFFER_LEN);
for(uint16_t i = 0; i < ret; i++) {
if(bad_usb->file_buf[i] == '\n' && line_len > 0) {
bad_usb->st.line_nb++;
line_len = 0;
} else {
if(bad_usb->st.line_nb == 0) { // Save first line
string_push_back(bad_usb->line, bad_usb->file_buf[i]);
}
line_len++;
}
}
Expand All @@ -324,7 +359,20 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
}
} while(ret > 0);

const char* line_tmp = string_get_cstr(bad_usb->line);
bool id_set = false; // Looking for ID command at first line
if(strncmp(line_tmp, ducky_cmd_id, strlen(ducky_cmd_id)) == 0) {
id_set = ducky_set_usb_id(bad_usb, &line_tmp[strlen(ducky_cmd_id) + 1]);
}

if(id_set) {
furi_check(furi_hal_usb_set_config(&usb_hid, &bad_usb->hid_cfg));
} else {
furi_check(furi_hal_usb_set_config(&usb_hid, NULL));
}

storage_file_seek(script_file, 0, true);
string_reset(bad_usb->line);

return true;
}
Expand Down Expand Up @@ -403,6 +451,8 @@ static int32_t bad_usb_worker(void* context) {
BadUsbWorkerState worker_state = BadUsbStateInit;
int32_t delay_val = 0;

FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();

FURI_LOG_I(WORKER_TAG, "Init");
File* script_file = storage_file_alloc(furi_record_open("storage"));
string_init(bad_usb->line);
Expand Down Expand Up @@ -522,6 +572,8 @@ static int32_t bad_usb_worker(void* context) {

furi_hal_hid_set_state_callback(NULL, NULL);

furi_hal_usb_set_config(usb_mode_prev, NULL);

storage_file_close(script_file);
storage_file_free(script_file);
string_clear(bad_usb->line);
Expand Down
36 changes: 23 additions & 13 deletions applications/bad_usb/scenes/bad_usb_scene_error.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../bad_usb_app_i.h"

typedef enum {
SubghzCustomEventErrorBack,
BadUsbCustomEventErrorBack,
} BadUsbCustomEvent;

static void
Expand All @@ -10,23 +10,33 @@ static void
BadUsbApp* app = context;

if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(app->view_dispatcher, SubghzCustomEventErrorBack);
view_dispatcher_send_custom_event(app->view_dispatcher, BadUsbCustomEventErrorBack);
}
}

void bad_usb_scene_error_on_enter(void* context) {
BadUsbApp* app = context;

widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);

widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
if(app->error == BadUsbAppErrorNoFiles) {
widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);
widget_add_string_multiline_element(
app->widget,
81,
4,
AlignCenter,
AlignTop,
FontSecondary,
"No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
} else if(app->error == BadUsbAppErrorCloseRpc) {
widget_add_string_multiline_element(
app->widget,
63,
10,
AlignCenter,
AlignTop,
FontSecondary,
"Disconnect from\ncompanion app\nto use this function");
}

widget_add_button_element(
app->widget, GuiButtonTypeLeft, "Back", bad_usb_scene_error_event_callback, app);
Expand All @@ -39,7 +49,7 @@ bool bad_usb_scene_error_on_event(void* context, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventErrorBack) {
if(event.event == BadUsbCustomEventErrorBack) {
view_dispatcher_stop(app->view_dispatcher);
consumed = true;
}
Expand Down
4 changes: 4 additions & 0 deletions applications/bad_usb/scenes/bad_usb_scene_file_select.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../bad_usb_app_i.h"
#include "furi_hal_power.h"
#include "furi_hal_usb.h"

static bool bad_usb_file_select(BadUsbApp* bad_usb) {
furi_assert(bad_usb);
Expand All @@ -18,9 +19,12 @@ static bool bad_usb_file_select(BadUsbApp* bad_usb) {
void bad_usb_scene_file_select_on_enter(void* context) {
BadUsbApp* bad_usb = context;

furi_hal_usb_disable();

if(bad_usb_file_select(bad_usb)) {
scene_manager_next_scene(bad_usb->scene_manager, BadUsbSceneWork);
} else {
furi_hal_usb_enable();
//scene_manager_previous_scene(bad_usb->scene_manager);
view_dispatcher_stop(bad_usb->view_dispatcher);
}
Expand Down
5 changes: 3 additions & 2 deletions applications/debug_tools/usb_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int32_t usb_mouse_app(void* p) {
ViewPort* view_port = view_port_alloc();

FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
furi_hal_usb_set_config(&usb_hid);
furi_hal_usb_unlock();
furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true);

view_port_draw_callback_set(view_port, usb_mouse_render_callback, NULL);
view_port_input_callback_set(view_port, usb_mouse_input_callback, event_queue);
Expand Down Expand Up @@ -110,7 +111,7 @@ int32_t usb_mouse_app(void* p) {
view_port_update(view_port);
}

furi_hal_usb_set_config(usb_mode_prev);
furi_hal_usb_set_config(usb_mode_prev, NULL);

// remove & free all stuff created by app
gui_remove_view_port(gui, view_port);
Expand Down
24 changes: 19 additions & 5 deletions applications/debug_tools/usb_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef struct {
Gui* gui;
ViewDispatcher* view_dispatcher;
Submenu* submenu;
FuriHalUsbHidConfig hid_cfg;
} UsbTestApp;

typedef enum {
Expand All @@ -19,26 +20,33 @@ typedef enum {
UsbTestSubmenuIndexVcpSingle,
UsbTestSubmenuIndexVcpDual,
UsbTestSubmenuIndexHid,
UsbTestSubmenuIndexHidWithParams,
UsbTestSubmenuIndexHidU2F,
} SubmenuIndex;

void usb_test_submenu_callback(void* context, uint32_t index) {
furi_assert(context);
//UsbTestApp* app = context;
UsbTestApp* app = context;
if(index == UsbTestSubmenuIndexEnable) {
furi_hal_usb_enable();
} else if(index == UsbTestSubmenuIndexDisable) {
furi_hal_usb_disable();
} else if(index == UsbTestSubmenuIndexRestart) {
furi_hal_usb_reinit();
} else if(index == UsbTestSubmenuIndexVcpSingle) {
furi_hal_usb_set_config(&usb_cdc_single);
furi_hal_usb_set_config(&usb_cdc_single, NULL);
} else if(index == UsbTestSubmenuIndexVcpDual) {
furi_hal_usb_set_config(&usb_cdc_dual);
furi_hal_usb_set_config(&usb_cdc_dual, NULL);
} else if(index == UsbTestSubmenuIndexHid) {
furi_hal_usb_set_config(&usb_hid);
furi_hal_usb_set_config(&usb_hid, NULL);
} else if(index == UsbTestSubmenuIndexHidWithParams) {
app->hid_cfg.vid = 0x1234;
app->hid_cfg.pid = 0xabcd;
strncpy(app->hid_cfg.manuf, "WEN", sizeof(app->hid_cfg.manuf));
strncpy(app->hid_cfg.product, "FLIP", sizeof(app->hid_cfg.product));
furi_hal_usb_set_config(&usb_hid, &app->hid_cfg);
} else if(index == UsbTestSubmenuIndexHidU2F) {
furi_hal_usb_set_config(&usb_hid_u2f);
furi_hal_usb_set_config(&usb_hid_u2f, NULL);
}
}

Expand Down Expand Up @@ -71,6 +79,12 @@ UsbTestApp* usb_test_app_alloc() {
app->submenu, "Dual VCP", UsbTestSubmenuIndexVcpDual, usb_test_submenu_callback, app);
submenu_add_item(
app->submenu, "HID KB+Mouse", UsbTestSubmenuIndexHid, usb_test_submenu_callback, app);
submenu_add_item(
app->submenu,
"HID KB+Mouse custom ID",
UsbTestSubmenuIndexHidWithParams,
usb_test_submenu_callback,
app);
submenu_add_item(
app->submenu, "HID U2F", UsbTestSubmenuIndexHidU2F, usb_test_submenu_callback, app);
view_set_previous_callback(submenu_get_view(app->submenu), usb_test_exit);
Expand Down
2 changes: 2 additions & 0 deletions applications/desktop/scenes/desktop_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void desktop_scene_main_interact_animation_callback(void* context) {
desktop->view_dispatcher, DesktopAnimationEventInteractAnimation);
}

#ifdef APP_ARCHIVE
static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* flipper_app) {
furi_assert(desktop);
furi_assert(flipper_app);
Expand All @@ -65,6 +66,7 @@ static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* fl

furi_thread_start(desktop->scene_thread);
}
#endif

void desktop_scene_main_callback(DesktopEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
Expand Down
Loading

0 comments on commit 631e532

Please sign in to comment.