bigbrodude6119 2 лет назад
Сommit
d6eb1e1921

+ 1 - 0
README.md

@@ -0,0 +1 @@
+# Evil Portal

+ 13 - 0
application.fam

@@ -0,0 +1,13 @@
+App(
+    appid="evil_portal",
+    name="[ESP32] Evil Portal",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="evil_portal_app",
+    cdefines=["APP_EVIL_PORTAL"],
+    requires=["gui"],
+    stack_size=1 * 1024,
+    order=90,
+    fap_icon="icons/evil_portal_10px.png",
+    fap_category="GPIO",
+    fap_icon_assets="assets",
+)

BIN
assets/KeyBackspaceSelected_16x9.png


BIN
assets/KeyBackspace_16x9.png


BIN
assets/KeySaveSelected_24x11.png


BIN
assets/KeySave_24x11.png


BIN
assets/WarningDolphin_45x42.png


+ 129 - 0
evil_portal_app.c

@@ -0,0 +1,129 @@
+#include "evil_portal_app_i.h"
+#include "helpers/evil_portal_storage.h"
+
+#include <furi.h>
+#include <furi_hal.h>
+
+static bool evil_portal_app_custom_event_callback(void *context,
+                                                  uint32_t event) {
+  furi_assert(context);
+  Evil_PortalApp *app = context;
+  return scene_manager_handle_custom_event(app->scene_manager, event);
+}
+
+static bool evil_portal_app_back_event_callback(void *context) {
+  furi_assert(context);
+  Evil_PortalApp *app = context;
+  return scene_manager_handle_back_event(app->scene_manager);
+}
+
+static void evil_portal_app_tick_event_callback(void *context) {
+  furi_assert(context);
+  Evil_PortalApp *app = context;
+  scene_manager_handle_tick_event(app->scene_manager);
+}
+
+Evil_PortalApp *evil_portal_app_alloc() {
+  Evil_PortalApp *app = malloc(sizeof(Evil_PortalApp));
+
+  app->sent_html = false;
+  app->sent_ap = false;
+  app->has_command_queue = false;
+  app->command_index = 0;
+  app->portal_logs = malloc(5000);
+
+  app->gui = furi_record_open(RECORD_GUI);
+
+  app->view_dispatcher = view_dispatcher_alloc();
+  app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
+  view_dispatcher_enable_queue(app->view_dispatcher);
+  view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+
+  view_dispatcher_set_custom_event_callback(
+      app->view_dispatcher, evil_portal_app_custom_event_callback);
+  view_dispatcher_set_navigation_event_callback(
+      app->view_dispatcher, evil_portal_app_back_event_callback);
+  view_dispatcher_set_tick_event_callback(
+      app->view_dispatcher, evil_portal_app_tick_event_callback, 100);
+
+  view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui,
+                                ViewDispatcherTypeFullscreen);
+
+  app->var_item_list = variable_item_list_alloc();
+  view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewVarItemList,
+                           variable_item_list_get_view(app->var_item_list));
+
+  for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
+    app->selected_option_index[i] = 0;
+  }
+
+  app->text_box = text_box_alloc();
+  view_dispatcher_add_view(app->view_dispatcher,
+                           Evil_PortalAppViewConsoleOutput,
+                           text_box_get_view(app->text_box));
+  app->text_box_store = furi_string_alloc();
+  furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
+
+  app->text_input = uart_text_input_alloc();
+  view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewTextInput,
+                           uart_text_input_get_view(app->text_input));
+
+  app->text_input = uart_text_input_alloc();
+  view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewStartPortal,
+                           uart_text_input_get_view(app->text_input));
+
+  scene_manager_next_scene(app->scene_manager, Evil_PortalSceneStart);
+
+  return app;
+}
+
+void evil_portal_app_free(Evil_PortalApp *app) {
+  // save latest logs
+  if (strlen(app->portal_logs) > 0) {
+    write_logs(app->portal_logs);
+  }
+
+  // Send reset event to dev board
+  evil_portal_uart_tx((uint8_t *)("reset"), strlen("reset"));
+  evil_portal_uart_tx((uint8_t *)("\n"), 1);
+
+  furi_assert(app);
+
+  // Views
+  view_dispatcher_remove_view(app->view_dispatcher,
+                              Evil_PortalAppViewVarItemList);
+  view_dispatcher_remove_view(app->view_dispatcher,
+                              Evil_PortalAppViewConsoleOutput);
+  view_dispatcher_remove_view(app->view_dispatcher,
+                              Evil_PortalAppViewTextInput);
+  view_dispatcher_remove_view(app->view_dispatcher,
+                              Evil_PortalAppViewStartPortal);
+
+  text_box_free(app->text_box);
+  furi_string_free(app->text_box_store);
+  uart_text_input_free(app->text_input);
+
+  // View dispatcher
+  view_dispatcher_free(app->view_dispatcher);
+  scene_manager_free(app->scene_manager);
+
+  evil_portal_uart_free(app->uart);
+
+  // Close records
+  furi_record_close(RECORD_GUI);
+
+  free(app);
+}
+
+int32_t evil_portal_app(void *p) {
+  UNUSED(p);
+  Evil_PortalApp *evil_portal_app = evil_portal_app_alloc();
+
+  evil_portal_app->uart = evil_portal_uart_init(evil_portal_app);
+
+  view_dispatcher_run(evil_portal_app->view_dispatcher);
+
+  evil_portal_app_free(evil_portal_app);
+
+  return 0;
+}

+ 11 - 0
evil_portal_app.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Evil_PortalApp Evil_PortalApp;
+
+#ifdef __cplusplus
+}
+#endif

+ 61 - 0
evil_portal_app_i.h

@@ -0,0 +1,61 @@
+#pragma once
+
+#include "evil_portal_app.h"
+#include "evil_portal_custom_event.h"
+#include "evil_portal_uart.h"
+#include "scenes/evil_portal_scene.h"
+#include "uart_text_input.h"
+
+#include <gui/gui.h>
+#include <gui/modules/text_box.h>
+#include <gui/modules/variable_item_list.h>
+#include <gui/scene_manager.h>
+#include <gui/view_dispatcher.h>
+
+#define NUM_MENU_ITEMS (4)
+
+#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
+#define EVIL_PORTAL_TEXT_INPUT_STORE_SIZE (512)
+#define UART_CH (FuriHalUartIdUSART1)
+
+struct Evil_PortalApp {
+  Gui *gui;
+  ViewDispatcher *view_dispatcher;
+  SceneManager *scene_manager;
+
+  char* portal_logs;
+
+  char text_input_store[EVIL_PORTAL_TEXT_INPUT_STORE_SIZE + 1];
+  FuriString *text_box_store;
+  size_t text_box_store_strlen;
+  TextBox *text_box;
+  UART_TextInput *text_input;
+
+  VariableItemList *var_item_list;
+
+  Evil_PortalUart *uart;
+  int selected_menu_index;
+  int selected_option_index[NUM_MENU_ITEMS];
+  const char *selected_tx_string;
+  const char *command_queue[1];
+  int command_index;
+  bool has_command_queue;
+  bool is_command;
+  bool is_custom_tx_string;
+  bool focus_console_start;
+  bool show_stopscan_tip;
+  bool sent_ap;
+  bool sent_html;
+  int BAUDRATE;
+  int TERMINAL_MODE; // 1=AT mode, 0=other mode
+
+  uint8_t *index_html;
+  uint8_t *ap_name;
+};
+
+typedef enum {
+  Evil_PortalAppViewVarItemList,
+  Evil_PortalAppViewConsoleOutput,
+  Evil_PortalAppViewTextInput,
+  Evil_PortalAppViewStartPortal,
+} Evil_PortalAppView;

+ 8 - 0
evil_portal_custom_event.h

@@ -0,0 +1,8 @@
+#pragma once
+
+typedef enum {
+  Evil_PortalEventRefreshConsoleOutput = 0,
+  Evil_PortalEventStartConsole,
+  Evil_PortalEventStartKeyboard,
+  Evil_PortalEventStartPortal,
+} Evil_PortalCustomEvent;

+ 163 - 0
evil_portal_uart.c

@@ -0,0 +1,163 @@
+#include "evil_portal_app_i.h"
+#include "evil_portal_uart.h"
+#include "helpers/evil_portal_storage.h"
+
+// #define UART_CH (FuriHalUartIdUSART1)
+// #define BAUDRATE (115200)
+
+struct Evil_PortalUart {
+  Evil_PortalApp *app;
+  FuriThread *rx_thread;
+  FuriStreamBuffer *rx_stream;
+  uint8_t rx_buf[RX_BUF_SIZE + 1];
+  void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void *context);
+};
+
+typedef enum {
+  WorkerEvtStop = (1 << 0),
+  WorkerEvtRxDone = (1 << 1),
+} WorkerEvtFlags;
+
+void evil_portal_uart_set_handle_rx_data_cb(
+    Evil_PortalUart *uart,
+    void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void *context)) {
+  furi_assert(uart);
+  uart->handle_rx_data_cb = handle_rx_data_cb;
+}
+
+#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
+
+void evil_portal_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void *context) {
+  Evil_PortalUart *uart = (Evil_PortalUart *)context;
+
+  if (ev == UartIrqEventRXNE) {
+    furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
+    furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
+  }
+}
+
+static int32_t uart_worker(void *context) {
+  Evil_PortalUart *uart = (void *)context;
+
+
+  // FURI_LOG_I("EP", "in worker");
+  while (1) {
+
+    uint32_t events = furi_thread_flags_wait(WORKER_ALL_RX_EVENTS,
+                                             FuriFlagWaitAny, FuriWaitForever);
+    furi_check((events & FuriFlagError) == 0);
+    if (events & WorkerEvtStop)
+    // FURI_LOG_I("EP", "event 1");
+      break;
+    if (events & WorkerEvtRxDone) {
+      // FURI_LOG_I("EP", "event 2");
+      size_t len = furi_stream_buffer_receive(uart->rx_stream, uart->rx_buf,
+                                              RX_BUF_SIZE, 0);
+
+      // FURI_LOG_I("EP", "comp len");
+      if (len > 0) {
+        // FURI_LOG_I("EP", "check cb");
+        if (uart->handle_rx_data_cb) {
+          uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);
+
+          if (uart->app->has_command_queue) {
+            // FURI_LOG_I("EP", "Has command queue");
+            // FURI_LOG_I("EP", (char *)uart->rx_buf);            
+            if (uart->app->command_index < 1) {
+              
+              // check the current command
+              // if command x do x
+              if (0 ==
+                  strncmp("setap",
+                          uart->app->command_queue[uart->app->command_index],
+                          strlen("setap"))) {                
+                char *out_data =
+                    malloc((size_t)(strlen((char *)uart->app->ap_name) +
+                                    strlen("setap=")));
+                strcat(out_data, "setap=");
+                strcat(out_data, (char *)uart->app->ap_name);
+
+                evil_portal_uart_tx((uint8_t *)(out_data), strlen(out_data));
+                evil_portal_uart_tx((uint8_t *)("\n"), 1);
+
+                uart->app->sent_ap = true;
+
+                free(out_data);
+                free(uart->app->ap_name);
+              }
+
+              uart->app->command_index = 0;
+              uart->app->has_command_queue = false;
+              uart->app->command_queue[0] = "";
+            }
+
+            // if(0 == strncmp("ack", (char *)uart->rx_buf, strlen("ack"))) {
+
+            //   } else {
+            //     uart->app->command_index = 0;
+            //     uart->app->has_command_queue = false;
+            //     uart->app->command_queue[0] = "";
+            //   }
+            // }
+          }
+
+          // rx_buf has response
+          // wait for ack
+          // if response is ack
+          // check for commands
+          // if has commands
+          // send next command
+
+          strcat(uart->app->portal_logs, (char *)uart->rx_buf);
+          if (strlen(uart->app->portal_logs) > 4000) {
+            write_logs(uart->app->portal_logs);
+          }
+        }
+      }
+    }
+  }
+
+  furi_stream_buffer_free(uart->rx_stream);
+
+  return 0;
+}
+
+void evil_portal_uart_tx(uint8_t *data, size_t len) {
+  furi_hal_uart_tx(UART_CH, data, len);
+}
+
+Evil_PortalUart *evil_portal_uart_init(Evil_PortalApp *app) {
+  Evil_PortalUart *uart = malloc(sizeof(Evil_PortalUart));
+  uart->app = app;
+  // Init all rx stream and thread early to avoid crashes
+  uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
+  uart->rx_thread = furi_thread_alloc();
+  furi_thread_set_name(uart->rx_thread, "Evil_PortalUartRxThread");
+  furi_thread_set_stack_size(uart->rx_thread, 1024);
+  furi_thread_set_context(uart->rx_thread, uart);
+  furi_thread_set_callback(uart->rx_thread, uart_worker);
+
+  furi_thread_start(uart->rx_thread);
+
+  furi_hal_console_disable();
+  if (app->BAUDRATE == 0) {
+    app->BAUDRATE = 115200;
+  }
+  furi_hal_uart_set_br(UART_CH, app->BAUDRATE);
+  furi_hal_uart_set_irq_cb(UART_CH, evil_portal_uart_on_irq_cb, uart);
+
+  return uart;
+}
+
+void evil_portal_uart_free(Evil_PortalUart *uart) {
+  furi_assert(uart);
+
+  furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
+  furi_thread_join(uart->rx_thread);
+  furi_thread_free(uart->rx_thread);
+
+  furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
+  furi_hal_console_enable();
+
+  free(uart);
+}

+ 14 - 0
evil_portal_uart.h

@@ -0,0 +1,14 @@
+#pragma once
+
+#include "furi_hal.h"
+
+#define RX_BUF_SIZE (320)
+
+typedef struct Evil_PortalUart Evil_PortalUart;
+
+void evil_portal_uart_set_handle_rx_data_cb(
+    Evil_PortalUart *uart,
+    void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void *context));
+void evil_portal_uart_tx(uint8_t *data, size_t len);
+Evil_PortalUart *evil_portal_uart_init(Evil_PortalApp *app);
+void evil_portal_uart_free(Evil_PortalUart *uart);

+ 111 - 0
helpers/evil_portal_storage.c

@@ -0,0 +1,111 @@
+#include "evil_portal_storage.h"
+
+static Storage *evil_portal_open_storage() {
+  return furi_record_open(RECORD_STORAGE);
+}
+
+static void evil_portal_close_storage() { furi_record_close(RECORD_STORAGE); }
+
+void evil_portal_read_index_html(void *context) {
+
+  Evil_PortalApp *app = context;
+  Storage *storage = evil_portal_open_storage();
+  FileInfo fi;
+
+  if (storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) ==
+      FSE_OK) {
+    File *index_html = storage_file_alloc(storage);
+    if (storage_file_open(index_html, EVIL_PORTAL_INDEX_SAVE_PATH, FSAM_READ,
+                          FSOM_OPEN_EXISTING)) {
+      app->index_html = malloc((size_t)fi.size);
+      uint8_t *buf_ptr = app->index_html;
+      size_t read = 0;
+      while (read < fi.size) {
+        size_t to_read = fi.size - read;
+        if (to_read > UINT16_MAX)
+          to_read = UINT16_MAX;
+        uint16_t now_read =
+            storage_file_read(index_html, buf_ptr, (uint16_t)to_read);
+        read += now_read;
+        buf_ptr += now_read;
+      }
+      free(buf_ptr);
+    }
+    storage_file_close(index_html);
+    storage_file_free(index_html);
+  }
+
+  evil_portal_close_storage();
+}
+
+void evil_portal_read_ap_name(void *context) {
+  Evil_PortalApp *app = context;
+  Storage *storage = evil_portal_open_storage();
+  FileInfo fi;
+
+  if (storage_common_stat(storage, EVIL_PORTAL_AP_SAVE_PATH, &fi) == FSE_OK) {
+    File *ap_name = storage_file_alloc(storage);
+    if (storage_file_open(ap_name, EVIL_PORTAL_AP_SAVE_PATH, FSAM_READ,
+                          FSOM_OPEN_EXISTING)) {
+      app->ap_name = malloc((size_t)fi.size);
+      uint8_t *buf_ptr = app->ap_name;
+      size_t read = 0;
+      while (read < fi.size) {
+        size_t to_read = fi.size - read;
+        if (to_read > UINT16_MAX)
+          to_read = UINT16_MAX;
+        uint16_t now_read =
+            storage_file_read(ap_name, buf_ptr, (uint16_t)to_read);
+        read += now_read;
+        buf_ptr += now_read;
+      }
+      free(buf_ptr);
+    }
+    storage_file_close(ap_name);
+    storage_file_free(ap_name);
+  }
+  evil_portal_close_storage();
+}
+
+char* sequential_file_resolve_path(
+    Storage* storage,
+    const char* dir,
+    const char* prefix,
+    const char* extension) {
+    if(storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
+        return NULL;
+    }
+
+    char file_path[256];
+    int file_index = 0;
+
+    do {
+        if(snprintf(
+               file_path, sizeof(file_path), "%s/%s_%d.%s", dir, prefix, file_index, extension) <
+           0) {
+            return NULL;
+        }
+        file_index++;
+    } while(storage_file_exists(storage, file_path));
+
+    return strdup(file_path);
+}
+
+
+void write_logs(char* portal_logs) {
+  Storage *storage = evil_portal_open_storage();
+
+  char* seq_file_path = sequential_file_resolve_path(storage, EVIL_PORTAL_LOG_SAVE_PATH, "log", "txt");
+  
+  File* file = storage_file_alloc(storage);
+
+  if (storage_file_open(file, seq_file_path, FSAM_WRITE,
+                          FSOM_CREATE_ALWAYS)) {
+       storage_file_write(file, portal_logs, strlen(portal_logs));
+    }
+    storage_file_close(file);
+    storage_file_free(file);
+  evil_portal_close_storage();
+
+  portal_logs = "";
+}

+ 33 - 0
helpers/evil_portal_storage.h

@@ -0,0 +1,33 @@
+#include "../evil_portal_app_i.h"
+#include <flipper_format/flipper_format_i.h>
+#include <lib/toolbox/stream/file_stream.h>
+#include <stdlib.h>
+#include <storage/storage.h>
+#include <string.h>
+
+#define EVIL_PORTAL_SETTINGS_FILE_VERSION 1
+#define PORTAL_FILE_DIRECTORY_PATH EXT_PATH("apps_data/evil_portal")
+#define EVIL_PORTAL_SETTINGS_SAVE_PATH                                         \
+  PORTAL_FILE_DIRECTORY_PATH "/evil_portal.conf"
+#define EVIL_PORTAL_SETTINGS_SAVE_PATH_TMP EVIL_PORTAL_SETTINGS_SAVE_PATH ".tmp"
+#define EVIL_PORTAL_INDEX_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/index.html"
+#define EVIL_PORTAL_INDEX_SAVE_PATH_TMP EVIL_PORTAL_INDEX_SAVE_PATH ".tmp"
+#define EVIL_PORTAL_AP_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/ap.txt"
+#define EVIL_PORTAL_AP_SAVE_PATH_TMP EVIL_PORTAL_AP_SAVE_PATH ".tmp"
+#define EVIL_PORTAL_LOG_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/logs"
+#define EVIL_PORTAL_LOG_SAVE_PATH_TMP EVIL_PORTAL_LOG_SAVE_PATH ".tmp"
+#define EVIL_PORTAL_SETTINGS_HEADER "EvilPortal Config File"
+#define EVIL_PORTAL_SETTINGS_KEY_PORTAL "PORTAL"
+#define EVIL_PORTAL_SETTINGS_KEY_HAPTIC "Haptic"
+#define EVIL_PORTAL_SETTINGS_KEY_LED "Led"
+#define EVIL_PORTAL_SETTINGS_KEY_SPEAKER "Speaker"
+#define EVIL_PORTAL_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings"
+#define EVIL_PORTAL_BUF_SIZE 4092
+
+// void captive_portal_save_settings(void* context);
+// void captive_portal_read_settings(void* context);
+void evil_portal_read_index_html(void *context);
+void evil_portal_read_ap_name(void *context);
+void write_logs(char* portal_logs);
+char *sequential_file_resolve_path(Storage *storage, const char *dir,
+                                   const char *prefix, const char *extension);

BIN
icons/evil_portal_10px.png


+ 31 - 0
scenes/evil_portal_scene.c

@@ -0,0 +1,31 @@
+#include "evil_portal_scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
+void (*const evil_portal_scene_on_enter_handlers[])(void *) = {
+#include "evil_portal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
+bool (*const evil_portal_scene_on_event_handlers[])(void *context,
+                                                    SceneManagerEvent event) = {
+#include "evil_portal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
+void (*const evil_portal_scene_on_exit_handlers[])(void *context) = {
+#include "evil_portal_scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers evil_portal_scene_handlers = {
+    .on_enter_handlers = evil_portal_scene_on_enter_handlers,
+    .on_event_handlers = evil_portal_scene_on_event_handlers,
+    .on_exit_handlers = evil_portal_scene_on_exit_handlers,
+    .scene_num = Evil_PortalSceneNum,
+};

+ 31 - 0
scenes/evil_portal_scene.h

@@ -0,0 +1,31 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(prefix, name, id) Evil_PortalScene##id,
+typedef enum {
+#include "evil_portal_scene_config.h"
+  Evil_PortalSceneNum,
+} Evil_PortalScene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers evil_portal_scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(prefix, name, id)                                            \
+  void prefix##_scene_##name##_on_enter(void *);
+#include "evil_portal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(prefix, name, id)                                            \
+  bool prefix##_scene_##name##_on_event(void *context, SceneManagerEvent event);
+#include "evil_portal_scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(prefix, name, id)                                            \
+  void prefix##_scene_##name##_on_exit(void *context);
+#include "evil_portal_scene_config.h"
+#undef ADD_SCENE

+ 3 - 0
scenes/evil_portal_scene_config.h

@@ -0,0 +1,3 @@
+ADD_SCENE(evil_portal, start, Start)
+ADD_SCENE(evil_portal, console_output, ConsoleOutput)
+ADD_SCENE(evil_portal, text_input, UART_TextInput)

+ 183 - 0
scenes/evil_portal_scene_console_output.c

@@ -0,0 +1,183 @@
+#include "../evil_portal_app_i.h"
+#include "../helpers/evil_portal_storage.h"
+
+void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
+                                                  void *context) {
+  furi_assert(context);
+  Evil_PortalApp *app = context;
+
+  // If text box store gets too big, then truncate it
+  app->text_box_store_strlen += len;
+  if (app->text_box_store_strlen >= EVIL_PORTAL_TEXT_BOX_STORE_SIZE - 1) {
+    furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
+    app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
+  }
+
+  // Null-terminate buf and append to text box store
+  buf[len] = '\0';
+  furi_string_cat_printf(app->text_box_store, "%s", buf);
+
+  view_dispatcher_send_custom_event(app->view_dispatcher,
+                                    Evil_PortalEventRefreshConsoleOutput);
+}
+
+void evil_portal_scene_console_output_on_enter(void *context) {
+  Evil_PortalApp *app = context;
+
+  TextBox *text_box = app->text_box;
+  text_box_reset(app->text_box);
+  text_box_set_font(text_box, TextBoxFontText);
+  if (app->focus_console_start) {
+    text_box_set_focus(text_box, TextBoxFocusStart);
+  } else {
+    text_box_set_focus(text_box, TextBoxFocusEnd);
+  }
+
+  if (app->is_command) {
+    furi_string_reset(app->text_box_store);
+    app->text_box_store_strlen = 0;
+
+    if (0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
+      const char *help_msg = "This project is a WIP.\ngithub.com/.\n\n";
+      furi_string_cat_str(app->text_box_store, help_msg);
+      app->text_box_store_strlen += strlen(help_msg);
+    }
+
+    if (0 == strncmp("savelogs", app->selected_tx_string, strlen("savelogs"))) {
+      const char *help_msg = "Logs saved.\n\n";
+      furi_string_cat_str(app->text_box_store, help_msg);
+      app->text_box_store_strlen += strlen(help_msg);
+      write_logs(app->portal_logs);
+    }
+
+    if (0 == strncmp("sethtml", app->selected_tx_string, strlen("sethtml"))) {
+      // create a command queue
+      // add sethtml
+      // add setap
+      // add start
+
+
+
+      // if (!app->sent_html) {
+      //   const char *help_msg = "Set HTML before\nstarting portal.\n\n";
+      //   furi_string_cat_str(app->text_box_store, help_msg);
+      //   app->text_box_store_strlen += strlen(help_msg);
+      // } else if (!app->sent_ap) {
+      //   const char *help_msg = "Set ap name before\nstarting portal.\n\n";
+      //   furi_string_cat_str(app->text_box_store, help_msg);
+      //   app->text_box_store_strlen += strlen(help_msg);
+      // }
+
+      // app->command_queue[0] = "sethtml";
+      app->command_queue[0] = "setap";
+      // app->command_queue[1] = "start";
+      app->has_command_queue = true;
+      app->command_index = 0;
+    }
+
+    if (app->show_stopscan_tip) {
+      const char *help_msg = "Press BACK to return\n";
+      furi_string_cat_str(app->text_box_store, help_msg);
+      app->text_box_store_strlen += strlen(help_msg);
+    }
+  }
+
+  // Set starting text - for "View Log", this will just be what was already in
+  // the text box store
+  text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+
+  scene_manager_set_scene_state(app->scene_manager,
+                                Evil_PortalSceneConsoleOutput, 0);
+  view_dispatcher_switch_to_view(app->view_dispatcher,
+                                 Evil_PortalAppViewConsoleOutput);
+
+  // Register callback to receive data
+  evil_portal_uart_set_handle_rx_data_cb(
+      app->uart,
+      evil_portal_console_output_handle_rx_data_cb); // setup callback for rx
+                                                     // thread
+
+  // Send command with CR+LF or newline '\n'
+  // it is sent here
+  if (app->is_command && app->selected_tx_string) {
+    if (app->TERMINAL_MODE == 1) {
+      evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
+                          strlen(app->selected_tx_string));
+      evil_portal_uart_tx((uint8_t *)("\r\n"), 2);
+    } else {
+      // handle special commands here
+      if (0 == strncmp("sethtml", app->selected_tx_string, strlen("sethtml"))) {
+        evil_portal_read_index_html(context);
+
+        char *data = malloc(
+            (size_t)(strlen((char *)app->index_html) + strlen("sethtml=")));
+        strcat(data, "sethtml=");
+        strcat(data, (char *)app->index_html);
+
+        evil_portal_uart_tx((uint8_t *)(data), strlen(data));
+        evil_portal_uart_tx((uint8_t *)("\n"), 1);
+
+        app->sent_html = true;
+
+        free(data);
+        free(app->index_html);
+
+        evil_portal_read_ap_name(context);
+      } else if (0 ==
+                 strncmp("setap", app->selected_tx_string, strlen("setap"))) {
+
+        evil_portal_read_ap_name(context);
+
+        char *data =
+            malloc((size_t)(strlen((char *)app->ap_name) + strlen("setap=")));
+        strcat(data, "setap=");
+        strcat(data, (char *)app->ap_name);
+
+        evil_portal_uart_tx((uint8_t *)(data), strlen(data));
+        evil_portal_uart_tx((uint8_t *)("\n"), 1);
+
+        app->sent_ap = true;
+
+        free(data);
+        free(app->ap_name);
+      } else if (0 ==
+                 strncmp("reset", app->selected_tx_string, strlen("reset"))) {
+        app->sent_html = false;
+        app->sent_ap = false;
+        evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
+                            strlen(app->selected_tx_string));
+        evil_portal_uart_tx((uint8_t *)("\n"), 1);
+      } else if (0 ==
+                 strncmp("help", app->selected_tx_string, strlen("help"))) {
+        // do nothing?
+      } else {
+        evil_portal_uart_tx((uint8_t *)(app->selected_tx_string),
+                            strlen(app->selected_tx_string));
+        evil_portal_uart_tx((uint8_t *)("\n"), 1);
+      }
+    }
+  }   
+}
+
+bool evil_portal_scene_console_output_on_event(void *context,
+                                               SceneManagerEvent event) {
+  Evil_PortalApp *app = context;
+
+  bool consumed = false;
+
+  if (event.type == SceneManagerEventTypeCustom) {
+    text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
+    consumed = true;
+  } else if (event.type == SceneManagerEventTypeTick) {
+    consumed = true;
+  }
+
+  return consumed;
+}
+
+void evil_portal_scene_console_output_on_exit(void *context) {
+  Evil_PortalApp *app = context;
+
+  // Unregister rx callback
+  evil_portal_uart_set_handle_rx_data_cb(app->uart, NULL);
+}

+ 161 - 0
scenes/evil_portal_scene_start.c

@@ -0,0 +1,161 @@
+#include "../evil_portal_app_i.h"
+
+// For each command, define whether additional arguments are needed
+// (enabling text input to fill them out), and whether the console
+// text box should focus at the start of the output or the end
+typedef enum { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs;
+
+typedef enum {
+  FOCUS_CONSOLE_END = 0,
+  FOCUS_CONSOLE_START,
+  FOCUS_CONSOLE_TOGGLE
+} FocusConsole;
+
+#define SHOW_STOPSCAN_TIP (true)
+#define NO_TIP (false)
+
+#define MAX_OPTIONS (9)
+typedef struct {
+  const char *item_string;
+  const char *options_menu[MAX_OPTIONS];
+  int num_options_menu;
+  const char *actual_commands[MAX_OPTIONS];
+  InputArgs needs_keyboard;
+  FocusConsole focus_console;
+  bool show_stopscan_tip;
+} Evil_PortalItem;
+
+// NUM_MENU_ITEMS defined in evil_portal_app_i.h - if you add an entry here,
+// increment it!
+const Evil_PortalItem items[NUM_MENU_ITEMS] = {
+     // send command
+    {"Start portal", {""}, 1, {"sethtml"}, NO_ARGS, FOCUS_CONSOLE_START, NO_TIP},
+
+    // stop portal
+    {"Stop portal", {""}, 1, {"reset"}, NO_ARGS, FOCUS_CONSOLE_START, NO_TIP},
+
+    // console
+    {"Save logs",
+     {""},
+     1,
+     {"savelogs"},
+     NO_ARGS,
+     FOCUS_CONSOLE_START,
+     SHOW_STOPSCAN_TIP},
+
+     // help
+    {"Help",
+     {""},
+     1,
+     {"help"},
+     NO_ARGS,
+     FOCUS_CONSOLE_START,
+     SHOW_STOPSCAN_TIP},
+};
+
+static void evil_portal_scene_start_var_list_enter_callback(void *context,
+                                                            uint32_t index) {
+  furi_assert(context);
+  Evil_PortalApp *app = context;
+
+  furi_assert(index < NUM_MENU_ITEMS);
+  const Evil_PortalItem *item = &items[index];
+
+  const int selected_option_index = app->selected_option_index[index];
+  furi_assert(selected_option_index < item->num_options_menu);
+  app->selected_tx_string = item->actual_commands[selected_option_index];
+  app->is_command = true;
+  app->is_custom_tx_string = false;
+  app->selected_menu_index = index;
+  app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
+                                 ? (selected_option_index == 0)
+                                 : item->focus_console;
+  app->show_stopscan_tip = item->show_stopscan_tip;
+
+  bool needs_keyboard = (item->needs_keyboard == TOGGLE_ARGS)
+                            ? (selected_option_index != 0)
+                            : item->needs_keyboard;
+                            
+  if (needs_keyboard) {
+    view_dispatcher_send_custom_event(app->view_dispatcher,
+                                      Evil_PortalEventStartKeyboard);
+  } else {
+    view_dispatcher_send_custom_event(app->view_dispatcher,
+                                      Evil_PortalEventStartConsole);
+  }
+}
+
+static void
+evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
+  furi_assert(item);
+
+  Evil_PortalApp *app = variable_item_get_context(item);
+  furi_assert(app);
+
+  const Evil_PortalItem *menu_item = &items[app->selected_menu_index];
+  uint8_t item_index = variable_item_get_current_value_index(item);
+  furi_assert(item_index < menu_item->num_options_menu);
+  variable_item_set_current_value_text(item,
+                                       menu_item->options_menu[item_index]);
+  app->selected_option_index[app->selected_menu_index] = item_index;
+}
+
+void evil_portal_scene_start_on_enter(void *context) {
+  Evil_PortalApp *app = context;
+  VariableItemList *var_item_list = app->var_item_list;
+
+  variable_item_list_set_enter_callback(
+      var_item_list, evil_portal_scene_start_var_list_enter_callback, app);
+
+  VariableItem *item;
+  for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
+    item = variable_item_list_add(
+        var_item_list, items[i].item_string, items[i].num_options_menu,
+        evil_portal_scene_start_var_list_change_callback, app);
+    variable_item_set_current_value_index(item, app->selected_option_index[i]);
+    variable_item_set_current_value_text(
+        item, items[i].options_menu[app->selected_option_index[i]]);
+  }
+
+  variable_item_list_set_selected_item(
+      var_item_list,
+      scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
+
+  view_dispatcher_switch_to_view(app->view_dispatcher,
+                                 Evil_PortalAppViewVarItemList);
+}
+
+bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
+  UNUSED(context);
+  Evil_PortalApp *app = context;
+  bool consumed = false;
+
+  if (event.type == SceneManagerEventTypeCustom) {
+    if (event.event == Evil_PortalEventStartPortal) {
+      scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
+                                    app->selected_menu_index);
+      scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewStartPortal);
+    } else if (event.event == Evil_PortalEventStartKeyboard) {
+      scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
+                                    app->selected_menu_index);
+      scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewTextInput);
+    } else if (event.event == Evil_PortalEventStartConsole) {
+      scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
+                                    app->selected_menu_index);
+      scene_manager_next_scene(app->scene_manager,
+                               Evil_PortalAppViewConsoleOutput);
+    }
+    consumed = true;
+  } else if (event.type == SceneManagerEventTypeTick) {
+    app->selected_menu_index =
+        variable_item_list_get_selected_item_index(app->var_item_list);
+    consumed = true;
+  }
+
+  return consumed;
+}
+
+void evil_portal_scene_start_on_exit(void *context) {
+  Evil_PortalApp *app = context;
+  variable_item_list_reset(app->var_item_list);
+}

+ 65 - 0
scenes/evil_portal_scene_start_portal.c

@@ -0,0 +1,65 @@
+#include "../evil_portal_app_i.h"
+
+void evil_portal_scene_start_portal_callback(void *context) {
+  Evil_PortalApp *app = context;
+
+  view_dispatcher_send_custom_event(app->view_dispatcher,
+                                    Evil_PortalEventStartConsole);
+}
+
+void evil_portal_scene_start_portal_on_enter(void *context) {
+  Evil_PortalApp *app = context;
+
+  if (false == app->is_custom_tx_string) {
+    // Fill text input with selected string so that user can add to it
+    size_t length = strlen(app->selected_tx_string);
+    furi_assert(length < EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
+    bzero(app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
+    strncpy(app->text_input_store, app->selected_tx_string, length);
+
+    // Add space - because flipper keyboard currently doesn't have a space
+    // app->start_portal_store[length] = ' ';
+    app->text_input_store[length + 1] = '\0';
+    app->is_custom_tx_string = true;
+  }
+
+  // Setup view
+  UART_TextInput *text_input = app->text_input;
+  // Add help message to header
+  if (0 == strncmp("AT", app->selected_tx_string, strlen("AT"))) {
+    app->TERMINAL_MODE = 1;
+    uart_text_input_set_header_text(text_input, "Send AT command to UART");
+  } else {
+    app->TERMINAL_MODE = 0;
+    uart_text_input_set_header_text(text_input, "Send command to UART");
+  }
+  uart_text_input_set_result_callback(
+      text_input, evil_portal_scene_start_portal_callback, app,
+      app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE, false);
+
+  view_dispatcher_switch_to_view(app->view_dispatcher,
+                                 Evil_PortalAppViewTextInput);
+}
+
+bool evil_portal_scene_start_portal_on_event(void *context,
+                                           SceneManagerEvent event) {
+  Evil_PortalApp *app = context;
+  bool consumed = false;
+
+  if (event.type == SceneManagerEventTypeCustom) {
+    if (event.event == Evil_PortalEventStartConsole) {
+      app->selected_tx_string = app->text_input_store;
+      scene_manager_next_scene(app->scene_manager,
+                               Evil_PortalAppViewConsoleOutput);
+      consumed = true;
+    }
+  }
+
+  return consumed;
+}
+
+void evil_portal_scene_start_portal_on_exit(void *context) {
+  Evil_PortalApp *app = context;
+
+  uart_text_input_reset(app->text_input);
+}

+ 65 - 0
scenes/evil_portal_scene_text_input.c

@@ -0,0 +1,65 @@
+#include "../evil_portal_app_i.h"
+
+void evil_portal_scene_text_input_callback(void *context) {
+  Evil_PortalApp *app = context;
+
+  view_dispatcher_send_custom_event(app->view_dispatcher,
+                                    Evil_PortalEventStartConsole);
+}
+
+void evil_portal_scene_text_input_on_enter(void *context) {
+  Evil_PortalApp *app = context;
+
+  if (false == app->is_custom_tx_string) {
+    // Fill text input with selected string so that user can add to it
+    size_t length = strlen(app->selected_tx_string);
+    furi_assert(length < EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
+    bzero(app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
+    strncpy(app->text_input_store, app->selected_tx_string, length);
+
+    // Add space - because flipper keyboard currently doesn't have a space
+    // app->text_input_store[length] = ' ';
+    app->text_input_store[length + 1] = '\0';
+    app->is_custom_tx_string = true;
+  }
+
+  // Setup view
+  UART_TextInput *text_input = app->text_input;
+  // Add help message to header
+  if (0 == strncmp("AT", app->selected_tx_string, strlen("AT"))) {
+    app->TERMINAL_MODE = 1;
+    uart_text_input_set_header_text(text_input, "Send AT command to UART");
+  } else {
+    app->TERMINAL_MODE = 0;
+    uart_text_input_set_header_text(text_input, "Send command to UART");
+  }
+  uart_text_input_set_result_callback(
+      text_input, evil_portal_scene_text_input_callback, app,
+      app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE, false);
+
+  view_dispatcher_switch_to_view(app->view_dispatcher,
+                                 Evil_PortalAppViewTextInput);
+}
+
+bool evil_portal_scene_text_input_on_event(void *context,
+                                           SceneManagerEvent event) {
+  Evil_PortalApp *app = context;
+  bool consumed = false;
+
+  if (event.type == SceneManagerEventTypeCustom) {
+    if (event.event == Evil_PortalEventStartConsole) {
+      app->selected_tx_string = app->text_input_store;
+      scene_manager_next_scene(app->scene_manager,
+                               Evil_PortalAppViewConsoleOutput);
+      consumed = true;
+    }
+  }
+
+  return consumed;
+}
+
+void evil_portal_scene_text_input_on_exit(void *context) {
+  Evil_PortalApp *app = context;
+
+  uart_text_input_reset(app->text_input);
+}

+ 623 - 0
uart_text_input.c

@@ -0,0 +1,623 @@
+#include "uart_text_input.h"
+#include <gui/elements.h>
+// #include "evil_portal_icons.h"
+#include "evil_portal_app_i.h"
+#include <furi.h>
+
+struct UART_TextInput {
+  View *view;
+  FuriTimer *timer;
+};
+
+typedef struct {
+  const char text;
+  const uint8_t x;
+  const uint8_t y;
+} UART_TextInputKey;
+
+typedef struct {
+  const char *header;
+  char *text_buffer;
+  size_t text_buffer_size;
+  bool clear_default_text;
+
+  UART_TextInputCallback callback;
+  void *callback_context;
+
+  uint8_t selected_row;
+  uint8_t selected_column;
+
+  UART_TextInputValidatorCallback validator_callback;
+  void *validator_callback_context;
+  FuriString *validator_text;
+  bool valadator_message_visible;
+} UART_TextInputModel;
+
+static const uint8_t keyboard_origin_x = 1;
+static const uint8_t keyboard_origin_y = 29;
+static const uint8_t keyboard_row_count = 4;
+
+#define mode_AT "Send AT command to UART"
+
+#define ENTER_KEY '\r'
+#define BACKSPACE_KEY '\b'
+
+static const UART_TextInputKey keyboard_keys_row_1[] = {
+    {'{', 1, 0},  {'(', 9, 0},    {'[', 17, 0},  {'|', 25, 0},
+    {'@', 33, 0}, {'&', 41, 0},   {'#', 49, 0},  {';', 57, 0},
+    {'^', 65, 0}, {'*', 73, 0},   {'`', 81, 0},  {'"', 89, 0},
+    {'~', 97, 0}, {'\'', 105, 0}, {'.', 113, 0}, {'/', 120, 0},
+};
+
+static const UART_TextInputKey keyboard_keys_row_2[] = {
+    {'q', 1, 10},  {'w', 9, 10},   {'e', 17, 10},  {'r', 25, 10},
+    {'t', 33, 10}, {'y', 41, 10},  {'u', 49, 10},  {'i', 57, 10},
+    {'o', 65, 10}, {'p', 73, 10},  {'0', 81, 10},  {'1', 89, 10},
+    {'2', 97, 10}, {'3', 105, 10}, {'=', 113, 10}, {'-', 120, 10},
+};
+
+static const UART_TextInputKey keyboard_keys_row_3[] = {
+    {'a', 1, 21},   {'s', 9, 21},
+    {'d', 18, 21},  {'f', 25, 21},
+    {'g', 33, 21},  {'h', 41, 21},
+    {'j', 49, 21},  {'k', 57, 21},
+    {'l', 65, 21},  {BACKSPACE_KEY, 72, 13},
+    {'4', 89, 21},  {'5', 97, 21},
+    {'6', 105, 21}, {'$', 113, 21},
+    {'%', 120, 21},
+
+};
+
+static const UART_TextInputKey keyboard_keys_row_4[] = {
+    {'z', 1, 33},        {'x', 9, 33},   {'c', 18, 33}, {'v', 25, 33},
+    {'b', 33, 33},       {'n', 41, 33},  {'m', 49, 33}, {'_', 57, 33},
+    {ENTER_KEY, 64, 24}, {'7', 89, 33},  {'8', 97, 33}, {'9', 105, 33},
+    {'!', 113, 33},      {'+', 120, 33},
+};
+
+static uint8_t get_row_size(uint8_t row_index) {
+  uint8_t row_size = 0;
+
+  switch (row_index + 1) {
+  case 1:
+    row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
+    break;
+  case 2:
+    row_size = sizeof(keyboard_keys_row_2) / sizeof(UART_TextInputKey);
+    break;
+  case 3:
+    row_size = sizeof(keyboard_keys_row_3) / sizeof(UART_TextInputKey);
+    break;
+  case 4:
+    row_size = sizeof(keyboard_keys_row_4) / sizeof(UART_TextInputKey);
+    break;
+  }
+
+  return row_size;
+}
+
+static const UART_TextInputKey *get_row(uint8_t row_index) {
+  const UART_TextInputKey *row = NULL;
+
+  switch (row_index + 1) {
+  case 1:
+    row = keyboard_keys_row_1;
+    break;
+  case 2:
+    row = keyboard_keys_row_2;
+    break;
+  case 3:
+    row = keyboard_keys_row_3;
+    break;
+  case 4:
+    row = keyboard_keys_row_4;
+    break;
+  }
+
+  return row;
+}
+
+static char get_selected_char(UART_TextInputModel *model) {
+  return get_row(model->selected_row)[model->selected_column].text;
+}
+
+static bool char_is_lowercase(char letter) {
+  return (letter >= 0x61 && letter <= 0x7A);
+}
+
+static bool char_is_uppercase(char letter) {
+  return (letter >= 0x41 && letter <= 0x5A);
+}
+
+static char char_to_lowercase(const char letter) {
+  switch (letter) {
+  case ' ':
+    return 0x5f;
+    break;
+  case ')':
+    return 0x28;
+    break;
+  case '}':
+    return 0x7b;
+    break;
+  case ']':
+    return 0x5b;
+    break;
+  case '\\':
+    return 0x2f;
+    break;
+  case ':':
+    return 0x3b;
+    break;
+  case ',':
+    return 0x2e;
+    break;
+  case '?':
+    return 0x21;
+    break;
+  case '>':
+    return 0x3c;
+    break;
+  }
+  if (char_is_uppercase(letter)) {
+    return (letter + 0x20);
+  } else {
+    return letter;
+  }
+}
+
+static char char_to_uppercase(const char letter) {
+  switch (letter) {
+  case '_':
+    return 0x20;
+    break;
+  case '(':
+    return 0x29;
+    break;
+  case '{':
+    return 0x7d;
+    break;
+  case '[':
+    return 0x5d;
+    break;
+  case '/':
+    return 0x5c;
+    break;
+  case ';':
+    return 0x3a;
+    break;
+  case '.':
+    return 0x2c;
+    break;
+  case '!':
+    return 0x3f;
+    break;
+  case '<':
+    return 0x3e;
+    break;
+  }
+  if (char_is_lowercase(letter)) {
+    return (letter - 0x20);
+  } else {
+    return letter;
+  }
+}
+
+static void uart_text_input_backspace_cb(UART_TextInputModel *model) {
+  uint8_t text_length =
+      model->clear_default_text ? 1 : strlen(model->text_buffer);
+  if (text_length > 0) {
+    model->text_buffer[text_length - 1] = 0;
+  }
+}
+
+static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model) {
+  UART_TextInputModel *model = _model;
+  // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
+  uint8_t needed_string_width = canvas_width(canvas) - 8;
+  uint8_t start_pos = 4;
+
+  const char *text = model->text_buffer;
+
+  canvas_clear(canvas);
+  canvas_set_color(canvas, ColorBlack);
+
+  canvas_draw_str(canvas, 2, 7, model->header);
+  elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
+
+  if (canvas_string_width(canvas, text) > needed_string_width) {
+    canvas_draw_str(canvas, start_pos, 17, "...");
+    start_pos += 6;
+    needed_string_width -= 8;
+  }
+
+  while (text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
+    text++;
+  }
+
+  if (model->clear_default_text) {
+    elements_slightly_rounded_box(canvas, start_pos - 1, 14,
+                                  canvas_string_width(canvas, text) + 2, 10);
+    canvas_set_color(canvas, ColorWhite);
+  } else {
+    canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1,
+                    18, "|");
+    canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2,
+                    18, "|");
+  }
+  canvas_draw_str(canvas, start_pos, 17, text);
+
+  canvas_set_font(canvas, FontKeyboard);
+
+  for (uint8_t row = 0; row <= keyboard_row_count; row++) {
+    const uint8_t column_count = get_row_size(row);
+    const UART_TextInputKey *keys = get_row(row);
+
+    for (size_t column = 0; column < column_count; column++) {
+      if (keys[column].text == ENTER_KEY) {
+        canvas_set_color(canvas, ColorBlack);
+        if (model->selected_row == row && model->selected_column == column) {
+          //   canvas_draw_icon(canvas, keyboard_origin_x + keys[column].x,
+          //                    keyboard_origin_y + keys[column].y,
+          //                    &I_KeySaveSelected_24x11);
+        } else {
+          //   canvas_draw_icon(canvas, keyboard_origin_x + keys[column].x,
+          //                    keyboard_origin_y + keys[column].y,
+          //                    &I_KeySave_24x11);
+        }
+      } else if (keys[column].text == BACKSPACE_KEY) {
+        canvas_set_color(canvas, ColorBlack);
+        if (model->selected_row == row && model->selected_column == column) {
+          //   canvas_draw_icon(canvas, keyboard_origin_x + keys[column].x,
+          //                    keyboard_origin_y + keys[column].y,
+          //                    &I_KeyBackspaceSelected_16x9);
+        } else {
+          //   canvas_draw_icon(canvas, keyboard_origin_x + keys[column].x,
+          //                    keyboard_origin_y + keys[column].y,
+          //                    &I_KeyBackspace_16x9);
+        }
+      } else {
+        if (model->selected_row == row && model->selected_column == column) {
+          canvas_set_color(canvas, ColorBlack);
+          canvas_draw_box(canvas, keyboard_origin_x + keys[column].x - 1,
+                          keyboard_origin_y + keys[column].y - 8, 7, 10);
+          canvas_set_color(canvas, ColorWhite);
+        } else {
+          canvas_set_color(canvas, ColorBlack);
+        }
+        if (0 == strcmp(model->header, mode_AT)) {
+          canvas_draw_glyph(canvas, keyboard_origin_x + keys[column].x,
+                            keyboard_origin_y + keys[column].y,
+                            char_to_uppercase(keys[column].text));
+        } else {
+          canvas_draw_glyph(canvas, keyboard_origin_x + keys[column].x,
+                            keyboard_origin_y + keys[column].y,
+                            keys[column].text);
+        }
+      }
+    }
+  }
+  if (model->valadator_message_visible) {
+    canvas_set_font(canvas, FontSecondary);
+    canvas_set_color(canvas, ColorWhite);
+    canvas_draw_box(canvas, 8, 10, 110, 48);
+    canvas_set_color(canvas, ColorBlack);
+    // canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
+    canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
+    canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
+    elements_multiline_text(canvas, 62, 20,
+                            furi_string_get_cstr(model->validator_text));
+    canvas_set_font(canvas, FontKeyboard);
+  }
+}
+
+static void uart_text_input_handle_up(UART_TextInput *uart_text_input,
+                                      UART_TextInputModel *model) {
+  UNUSED(uart_text_input);
+  if (model->selected_row > 0) {
+    model->selected_row--;
+    if (model->selected_column > get_row_size(model->selected_row) - 6) {
+      model->selected_column = model->selected_column + 1;
+    }
+  }
+}
+
+static void uart_text_input_handle_down(UART_TextInput *uart_text_input,
+                                        UART_TextInputModel *model) {
+  UNUSED(uart_text_input);
+  if (model->selected_row < keyboard_row_count - 1) {
+    model->selected_row++;
+    if (model->selected_column > get_row_size(model->selected_row) - 4) {
+      model->selected_column = model->selected_column - 1;
+    }
+  }
+}
+
+static void uart_text_input_handle_left(UART_TextInput *uart_text_input,
+                                        UART_TextInputModel *model) {
+  UNUSED(uart_text_input);
+  if (model->selected_column > 0) {
+    model->selected_column--;
+  } else {
+    model->selected_column = get_row_size(model->selected_row) - 1;
+  }
+}
+
+static void uart_text_input_handle_right(UART_TextInput *uart_text_input,
+                                         UART_TextInputModel *model) {
+  UNUSED(uart_text_input);
+  if (model->selected_column < get_row_size(model->selected_row) - 1) {
+    model->selected_column++;
+  } else {
+    model->selected_column = 0;
+  }
+}
+
+static void uart_text_input_handle_ok(UART_TextInput *uart_text_input,
+                                      UART_TextInputModel *model, bool shift) {
+  char selected = get_selected_char(model);
+  uint8_t text_length = strlen(model->text_buffer);
+
+  if (0 == strcmp(model->header, mode_AT)) {
+    selected = char_to_uppercase(selected);
+  }
+
+  if (shift) {
+    if (0 == strcmp(model->header, mode_AT)) {
+      selected = char_to_lowercase(selected);
+    } else {
+      selected = char_to_uppercase(selected);
+    }
+  }
+
+  if (selected == ENTER_KEY) {
+    if (model->validator_callback &&
+        (!model->validator_callback(model->text_buffer, model->validator_text,
+                                    model->validator_callback_context))) {
+      model->valadator_message_visible = true;
+      furi_timer_start(uart_text_input->timer,
+                       furi_kernel_get_tick_frequency() * 4);
+    } else if (model->callback != 0 && text_length > 0) {
+      model->callback(model->callback_context);
+    }
+  } else if (selected == BACKSPACE_KEY) {
+    uart_text_input_backspace_cb(model);
+  } else {
+    if (model->clear_default_text) {
+      text_length = 0;
+    }
+    if (text_length < (model->text_buffer_size - 1)) {
+      model->text_buffer[text_length] = selected;
+      model->text_buffer[text_length + 1] = 0;
+    }
+  }
+  model->clear_default_text = false;
+}
+
+static bool uart_text_input_view_input_callback(InputEvent *event,
+                                                void *context) {
+  UART_TextInput *uart_text_input = context;
+  furi_assert(uart_text_input);
+
+  bool consumed = false;
+
+  // Acquire model
+  UART_TextInputModel *model = view_get_model(uart_text_input->view);
+
+  if ((!(event->type == InputTypePress) &&
+       !(event->type == InputTypeRelease)) &&
+      model->valadator_message_visible) {
+    model->valadator_message_visible = false;
+    consumed = true;
+  } else if (event->type == InputTypeShort) {
+    consumed = true;
+    switch (event->key) {
+    case InputKeyUp:
+      uart_text_input_handle_up(uart_text_input, model);
+      break;
+    case InputKeyDown:
+      uart_text_input_handle_down(uart_text_input, model);
+      break;
+    case InputKeyLeft:
+      uart_text_input_handle_left(uart_text_input, model);
+      break;
+    case InputKeyRight:
+      uart_text_input_handle_right(uart_text_input, model);
+      break;
+    case InputKeyOk:
+      uart_text_input_handle_ok(uart_text_input, model, false);
+      break;
+    default:
+      consumed = false;
+      break;
+    }
+  } else if (event->type == InputTypeLong) {
+    consumed = true;
+    switch (event->key) {
+    case InputKeyUp:
+      uart_text_input_handle_up(uart_text_input, model);
+      break;
+    case InputKeyDown:
+      uart_text_input_handle_down(uart_text_input, model);
+      break;
+    case InputKeyLeft:
+      uart_text_input_handle_left(uart_text_input, model);
+      break;
+    case InputKeyRight:
+      uart_text_input_handle_right(uart_text_input, model);
+      break;
+    case InputKeyOk:
+      uart_text_input_handle_ok(uart_text_input, model, true);
+      break;
+    case InputKeyBack:
+      uart_text_input_backspace_cb(model);
+      break;
+    default:
+      consumed = false;
+      break;
+    }
+  } else if (event->type == InputTypeRepeat) {
+    consumed = true;
+    switch (event->key) {
+    case InputKeyUp:
+      uart_text_input_handle_up(uart_text_input, model);
+      break;
+    case InputKeyDown:
+      uart_text_input_handle_down(uart_text_input, model);
+      break;
+    case InputKeyLeft:
+      uart_text_input_handle_left(uart_text_input, model);
+      break;
+    case InputKeyRight:
+      uart_text_input_handle_right(uart_text_input, model);
+      break;
+    case InputKeyBack:
+      uart_text_input_backspace_cb(model);
+      break;
+    default:
+      consumed = false;
+      break;
+    }
+  }
+
+  // Commit model
+  view_commit_model(uart_text_input->view, consumed);
+
+  return consumed;
+}
+
+void uart_text_input_timer_callback(void *context) {
+  furi_assert(context);
+  UART_TextInput *uart_text_input = context;
+
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { model->valadator_message_visible = false; }, true);
+}
+
+UART_TextInput *uart_text_input_alloc() {
+  UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
+  uart_text_input->view = view_alloc();
+  view_set_context(uart_text_input->view, uart_text_input);
+  view_allocate_model(uart_text_input->view, ViewModelTypeLocking,
+                      sizeof(UART_TextInputModel));
+  view_set_draw_callback(uart_text_input->view,
+                         uart_text_input_view_draw_callback);
+  view_set_input_callback(uart_text_input->view,
+                          uart_text_input_view_input_callback);
+
+  uart_text_input->timer = furi_timer_alloc(uart_text_input_timer_callback,
+                                            FuriTimerTypeOnce, uart_text_input);
+
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { model->validator_text = furi_string_alloc(); }, false);
+
+  uart_text_input_reset(uart_text_input);
+
+  return uart_text_input;
+}
+
+void uart_text_input_free(UART_TextInput *uart_text_input) {
+  furi_assert(uart_text_input);
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { furi_string_free(model->validator_text); }, false);
+
+  // Send stop command
+  furi_timer_stop(uart_text_input->timer);
+  // Release allocated memory
+  furi_timer_free(uart_text_input->timer);
+
+  view_free(uart_text_input->view);
+
+  free(uart_text_input);
+}
+
+void uart_text_input_reset(UART_TextInput *uart_text_input) {
+  furi_assert(uart_text_input);
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      {
+        model->text_buffer_size = 0;
+        model->header = "";
+        model->selected_row = 0;
+        model->selected_column = 0;
+        model->clear_default_text = false;
+        model->text_buffer = NULL;
+        model->text_buffer_size = 0;
+        model->callback = NULL;
+        model->callback_context = NULL;
+        model->validator_callback = NULL;
+        model->validator_callback_context = NULL;
+        furi_string_reset(model->validator_text);
+        model->valadator_message_visible = false;
+      },
+      true);
+}
+
+View *uart_text_input_get_view(UART_TextInput *uart_text_input) {
+  furi_assert(uart_text_input);
+  return uart_text_input->view;
+}
+
+void uart_text_input_set_result_callback(UART_TextInput *uart_text_input,
+                                         UART_TextInputCallback callback,
+                                         void *callback_context,
+                                         char *text_buffer,
+                                         size_t text_buffer_size,
+                                         bool clear_default_text) {
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      {
+        model->callback = callback;
+        model->callback_context = callback_context;
+        model->text_buffer = text_buffer;
+        model->text_buffer_size = text_buffer_size;
+        model->clear_default_text = clear_default_text;
+        if (text_buffer && text_buffer[0] != '\0') {
+          // Set focus on Save
+          model->selected_row = 2;
+          model->selected_column = 8;
+        }
+      },
+      true);
+}
+
+void uart_text_input_set_validator(UART_TextInput *uart_text_input,
+                                   UART_TextInputValidatorCallback callback,
+                                   void *callback_context) {
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      {
+        model->validator_callback = callback;
+        model->validator_callback_context = callback_context;
+      },
+      true);
+}
+
+UART_TextInputValidatorCallback
+uart_text_input_get_validator_callback(UART_TextInput *uart_text_input) {
+  UART_TextInputValidatorCallback validator_callback = NULL;
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { validator_callback = model->validator_callback; }, false);
+  return validator_callback;
+}
+
+void *uart_text_input_get_validator_callback_context(
+    UART_TextInput *uart_text_input) {
+  void *validator_callback_context = NULL;
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { validator_callback_context = model->validator_callback_context; },
+      false);
+  return validator_callback_context;
+}
+
+void uart_text_input_set_header_text(UART_TextInput *uart_text_input,
+                                     const char *text) {
+  with_view_model(
+      uart_text_input->view, UART_TextInputModel * model,
+      { model->header = text; }, true);
+}

+ 82 - 0
uart_text_input.h

@@ -0,0 +1,82 @@
+#pragma once
+
+#include <gui/view.h>
+#include "uart_validators.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Text input anonymous structure */
+typedef struct UART_TextInput UART_TextInput;
+typedef void (*UART_TextInputCallback)(void* context);
+typedef bool (*UART_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
+
+/** Allocate and initialize text input 
+ * 
+ * This text input is used to enter string
+ *
+ * @return     UART_TextInput instance
+ */
+UART_TextInput* uart_text_input_alloc();
+
+/** Deinitialize and free text input
+ *
+ * @param      uart_text_input  UART_TextInput instance
+ */
+void uart_text_input_free(UART_TextInput* uart_text_input);
+
+/** Clean text input view Note: this function does not free memory
+ *
+ * @param      uart_text_input  Text input instance
+ */
+void uart_text_input_reset(UART_TextInput* uart_text_input);
+
+/** Get text input view
+ *
+ * @param      uart_text_input  UART_TextInput instance
+ *
+ * @return     View instance that can be used for embedding
+ */
+View* uart_text_input_get_view(UART_TextInput* uart_text_input);
+
+/** Set text input result callback
+ *
+ * @param      uart_text_input          UART_TextInput instance
+ * @param      callback            callback fn
+ * @param      callback_context    callback context
+ * @param      text_buffer         pointer to YOUR text buffer, that we going
+ *                                 to modify
+ * @param      text_buffer_size    YOUR text buffer size in bytes. Max string
+ *                                 length will be text_buffer_size-1.
+ * @param      clear_default_text  clear text from text_buffer on first OK
+ *                                 event
+ */
+void uart_text_input_set_result_callback(
+    UART_TextInput* uart_text_input,
+    UART_TextInputCallback callback,
+    void* callback_context,
+    char* text_buffer,
+    size_t text_buffer_size,
+    bool clear_default_text);
+
+void uart_text_input_set_validator(
+    UART_TextInput* uart_text_input,
+    UART_TextInputValidatorCallback callback,
+    void* callback_context);
+
+UART_TextInputValidatorCallback
+    uart_text_input_get_validator_callback(UART_TextInput* uart_text_input);
+
+void* uart_text_input_get_validator_callback_context(UART_TextInput* uart_text_input);
+
+/** Set text input header text
+ *
+ * @param      uart_text_input  UART_TextInput instance
+ * @param      text        text to be shown
+ */
+void uart_text_input_set_header_text(UART_TextInput* uart_text_input, const char* text);
+
+#ifdef __cplusplus
+}
+#endif

+ 57 - 0
uart_validators.c

@@ -0,0 +1,57 @@
+#include <furi.h>
+#include "uart_validators.h"
+#include <storage/storage.h>
+
+struct ValidatorIsFile {
+    char* app_path_folder;
+    const char* app_extension;
+    char* current_name;
+};
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context) {
+    furi_assert(context);
+    ValidatorIsFile* instance = context;
+
+    if(instance->current_name != NULL) {
+        if(strcmp(instance->current_name, text) == 0) {
+            return true;
+        }
+    }
+
+    bool ret = true;
+    FuriString* path = furi_string_alloc_printf(
+        "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) {
+        ret = false;
+        furi_string_printf(error, "This name\nexists!\nChoose\nanother one.");
+    } else {
+        ret = true;
+    }
+    furi_string_free(path);
+    furi_record_close(RECORD_STORAGE);
+
+    return ret;
+}
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name) {
+    ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
+
+    instance->app_path_folder = strdup(app_path_folder);
+    instance->app_extension = app_extension;
+    if(current_name != NULL) {
+        instance->current_name = strdup(current_name);
+    }
+
+    return instance;
+}
+
+void validator_is_file_free(ValidatorIsFile* instance) {
+    furi_assert(instance);
+    free(instance->app_path_folder);
+    free(instance->current_name);
+    free(instance);
+}

+ 21 - 0
uart_validators.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <core/common_defines.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct ValidatorIsFile ValidatorIsFile;
+
+ValidatorIsFile* validator_is_file_alloc_init(
+    const char* app_path_folder,
+    const char* app_extension,
+    const char* current_name);
+
+void validator_is_file_free(ValidatorIsFile* instance);
+
+bool validator_is_file_callback(const char* text, FuriString* error, void* context);
+
+#ifdef __cplusplus
+}
+#endif