Просмотр исходного кода

cut NFC part from esubghz chat to make it usable for now

NFC part requires complete remake sadly
MX 2 лет назад
Родитель
Сommit
89e22ac950

+ 599 - 692
apps_broken_by_last_refactors/esubghz_chat/esubghz_chat.c

@@ -16,859 +16,766 @@
 
 
 /* Callback for RX events from the Sub-GHz worker. Records the current ticks as
 /* Callback for RX events from the Sub-GHz worker. Records the current ticks as
  * the time of the last reception. */
  * the time of the last reception. */
-static void have_read_cb(void* context)
-{
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+static void have_read_cb(void* context) {
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	state->last_time_rx_data = furi_get_tick();
+    state->last_time_rx_data = furi_get_tick();
 }
 }
 
 
 /* Sets the header for the chat input field depending on whether or not a
 /* Sets the header for the chat input field depending on whether or not a
  * message preview exists. */
  * message preview exists. */
-void set_chat_input_header(ESubGhzChatState *state)
-{
-	if (strlen(state->msg_preview) == 0) {
-		text_input_set_header_text(state->text_input, "Message");
-	} else {
-		text_input_set_header_text(state->text_input,
-				state->msg_preview);
-	}
+void set_chat_input_header(ESubGhzChatState* state) {
+    if(strlen(state->msg_preview) == 0) {
+        text_input_set_header_text(state->text_input, "Message");
+    } else {
+        text_input_set_header_text(state->text_input, state->msg_preview);
+    }
 }
 }
 
 
 /* Appends the latest message to the chat box and prepares the message preview.
 /* Appends the latest message to the chat box and prepares the message preview.
  */
  */
-void append_msg(ESubGhzChatState *state, const char *msg)
-{
-	/* append message to text box */
-	furi_string_cat_printf(state->chat_box_store, "\n%s", msg);
-
-	/* prepare message preview */
-	strncpy(state->msg_preview, msg, MSG_PREVIEW_SIZE);
-	state->msg_preview[MSG_PREVIEW_SIZE] = 0;
-	set_chat_input_header(state);
-
-	/* reset text box contents and focus */
-	text_box_set_text(state->chat_box,
-			furi_string_get_cstr(state->chat_box_store));
-	text_box_set_focus(state->chat_box, TextBoxFocusEnd);
+void append_msg(ESubGhzChatState* state, const char* msg) {
+    /* append message to text box */
+    furi_string_cat_printf(state->chat_box_store, "\n%s", msg);
+
+    /* prepare message preview */
+    strncpy(state->msg_preview, msg, MSG_PREVIEW_SIZE);
+    state->msg_preview[MSG_PREVIEW_SIZE] = 0;
+    set_chat_input_header(state);
+
+    /* reset text box contents and focus */
+    text_box_set_text(state->chat_box, furi_string_get_cstr(state->chat_box_store));
+    text_box_set_focus(state->chat_box, TextBoxFocusEnd);
 }
 }
 
 
 /* Decrypts a message for post_rx(). */
 /* Decrypts a message for post_rx(). */
-static bool post_rx_decrypt(ESubGhzChatState *state, size_t rx_size)
-{
-	bool ret = crypto_ctx_decrypt(state->crypto_ctx,
-			state->rx_buffer, rx_size,
-			(uint8_t*) state->rx_str_buffer);
-
-	if (ret) {
-		state->rx_str_buffer[rx_size - (MSG_OVERHEAD)] = 0;
-	} else {
-		state->rx_str_buffer[0] = 0;
-	}
-
-	return ret;
+static bool post_rx_decrypt(ESubGhzChatState* state, size_t rx_size) {
+    bool ret = crypto_ctx_decrypt(
+        state->crypto_ctx, state->rx_buffer, rx_size, (uint8_t*)state->rx_str_buffer);
+
+    if(ret) {
+        state->rx_str_buffer[rx_size - (MSG_OVERHEAD)] = 0;
+    } else {
+        state->rx_str_buffer[0] = 0;
+    }
+
+    return ret;
 }
 }
 
 
 /* Post RX handler, decrypts received messages and calls append_msg(). */
 /* Post RX handler, decrypts received messages and calls append_msg(). */
-static void post_rx(ESubGhzChatState *state, size_t rx_size)
-{
-	furi_assert(state);
+static void post_rx(ESubGhzChatState* state, size_t rx_size) {
+    furi_assert(state);
 
 
-	if (rx_size == 0) {
-		return;
-	}
+    if(rx_size == 0) {
+        return;
+    }
 
 
-	furi_check(rx_size <= RX_TX_BUFFER_SIZE);
+    furi_check(rx_size <= RX_TX_BUFFER_SIZE);
 
 
-	/* decrypt if necessary */
-	if (!state->encrypted) {
-		memcpy(state->rx_str_buffer, state->rx_buffer, rx_size);
-		state->rx_str_buffer[rx_size] = 0;
+    /* decrypt if necessary */
+    if(!state->encrypted) {
+        memcpy(state->rx_str_buffer, state->rx_buffer, rx_size);
+        state->rx_str_buffer[rx_size] = 0;
 
 
-		/* remove trailing newline if it is there, for compat with CLI
+        /* remove trailing newline if it is there, for compat with CLI
 		 * Sub-GHz chat */
 		 * Sub-GHz chat */
-		if (state->rx_str_buffer[rx_size - 1] == '\n') {
-			state->rx_str_buffer[rx_size - 1] = 0;
-		}
-	} else {
-		/* if decryption fails output an error message */
-		if (!post_rx_decrypt(state, rx_size)) {
-			strcpy(state->rx_str_buffer, "ERR: Decryption failed!");
-		}
-	}
-
-	/* append message to text box and prepare message preview */
-	append_msg(state, state->rx_str_buffer);
-
-	/* send notification (make the flipper vibrate) */
-	notification_message(state->notification, &sequence_single_vibro);
+        if(state->rx_str_buffer[rx_size - 1] == '\n') {
+            state->rx_str_buffer[rx_size - 1] = 0;
+        }
+    } else {
+        /* if decryption fails output an error message */
+        if(!post_rx_decrypt(state, rx_size)) {
+            strcpy(state->rx_str_buffer, "ERR: Decryption failed!");
+        }
+    }
+
+    /* append message to text box and prepare message preview */
+    append_msg(state, state->rx_str_buffer);
+
+    /* send notification (make the flipper vibrate) */
+    notification_message(state->notification, &sequence_single_vibro);
 }
 }
 
 
 /* Reads the message from msg_input, encrypts it if necessary and then
 /* Reads the message from msg_input, encrypts it if necessary and then
  * transmits it. */
  * transmits it. */
-void tx_msg_input(ESubGhzChatState *state)
-{
-	/* encrypt message if necessary */
-	size_t msg_len = strlen(furi_string_get_cstr(state->msg_input));
-	size_t tx_size = msg_len;
-	if (state->encrypted) {
-		tx_size += MSG_OVERHEAD;
-		furi_check(tx_size <= sizeof(state->tx_buffer));
-
-		crypto_ctx_encrypt(state->crypto_ctx,
-				(uint8_t *)
-				furi_string_get_cstr(state->msg_input),
-				msg_len,
-				state->tx_buffer);
-	} else {
-		tx_size += 2;
-		furi_check(tx_size <= sizeof(state->tx_buffer));
-		memcpy(state->tx_buffer,
-				furi_string_get_cstr(state->msg_input),
-				msg_len);
-
-		/* append \r\n for compat with Sub-GHz CLI chat */
-		state->tx_buffer[msg_len] = '\r';
-		state->tx_buffer[msg_len + 1] = '\n';
-	}
-
-	/* transmit */
-	subghz_tx_rx_worker_write(state->subghz_worker, state->tx_buffer,
-			tx_size);
+void tx_msg_input(ESubGhzChatState* state) {
+    /* encrypt message if necessary */
+    size_t msg_len = strlen(furi_string_get_cstr(state->msg_input));
+    size_t tx_size = msg_len;
+    if(state->encrypted) {
+        tx_size += MSG_OVERHEAD;
+        furi_check(tx_size <= sizeof(state->tx_buffer));
+
+        crypto_ctx_encrypt(
+            state->crypto_ctx,
+            (uint8_t*)furi_string_get_cstr(state->msg_input),
+            msg_len,
+            state->tx_buffer);
+    } else {
+        tx_size += 2;
+        furi_check(tx_size <= sizeof(state->tx_buffer));
+        memcpy(state->tx_buffer, furi_string_get_cstr(state->msg_input), msg_len);
+
+        /* append \r\n for compat with Sub-GHz CLI chat */
+        state->tx_buffer[msg_len] = '\r';
+        state->tx_buffer[msg_len + 1] = '\n';
+    }
+
+    /* transmit */
+    subghz_tx_rx_worker_write(state->subghz_worker, state->tx_buffer, tx_size);
 }
 }
 
 
 /* Displays information on frequency, encryption and radio type in the text
 /* Displays information on frequency, encryption and radio type in the text
  * box. Also clears the text input buffer to remove the password and starts the
  * box. Also clears the text input buffer to remove the password and starts the
  * Sub-GHz worker. After starting the worker a join message is transmitted. */
  * Sub-GHz worker. After starting the worker a join message is transmitted. */
-void enter_chat(ESubGhzChatState *state)
-{
-	furi_string_cat_printf(state->chat_box_store, "Frequency: %lu",
-			state->frequency);
-
-	furi_string_cat_printf(state->chat_box_store, "\nEncrypted: %s",
-			(state->encrypted ? "yes" : "no"));
+void enter_chat(ESubGhzChatState* state) {
+    furi_string_cat_printf(state->chat_box_store, "Frequency: %lu", state->frequency);
 
 
-	subghz_tx_rx_worker_start(state->subghz_worker, state->subghz_device,
-			state->frequency);
+    furi_string_cat_printf(
+        state->chat_box_store, "\nEncrypted: %s", (state->encrypted ? "yes" : "no"));
 
 
-	if (strcmp(state->subghz_device->name, "cc1101_ext") == 0) {
-		furi_string_cat_printf(state->chat_box_store,
-				"\nRadio: External");
-	} else {
-		furi_string_cat_printf(state->chat_box_store,
-				"\nRadio: Internal");
-	}
+    subghz_tx_rx_worker_start(state->subghz_worker, state->subghz_device, state->frequency);
 
 
+    if(strcmp(state->subghz_device->name, "cc1101_ext") == 0) {
+        furi_string_cat_printf(state->chat_box_store, "\nRadio: External");
+    } else {
+        furi_string_cat_printf(state->chat_box_store, "\nRadio: Internal");
+    }
 
 
-	/* concatenate the name prefix and join message */
-	furi_string_set(state->msg_input, state->name_prefix);
-	furi_string_cat_str(state->msg_input, " joined chat.");
+    /* concatenate the name prefix and join message */
+    furi_string_set(state->msg_input, state->name_prefix);
+    furi_string_cat_str(state->msg_input, " joined chat.");
 
 
-	/* encrypt and transmit message */
-	tx_msg_input(state);
+    /* encrypt and transmit message */
+    tx_msg_input(state);
 
 
-	/* clear message input buffer */
-	furi_string_set_char(state->msg_input, 0, 0);
+    /* clear message input buffer */
+    furi_string_set_char(state->msg_input, 0, 0);
 }
 }
 
 
 /* Sends a leave message */
 /* Sends a leave message */
-void exit_chat(ESubGhzChatState *state)
-{
-	/* concatenate the name prefix and leave message */
-	furi_string_set(state->msg_input, state->name_prefix);
-	furi_string_cat_str(state->msg_input, " left chat.");
+void exit_chat(ESubGhzChatState* state) {
+    /* concatenate the name prefix and leave message */
+    furi_string_set(state->msg_input, state->name_prefix);
+    furi_string_cat_str(state->msg_input, " left chat.");
 
 
-	/* encrypt and transmit message */
-	tx_msg_input(state);
+    /* encrypt and transmit message */
+    tx_msg_input(state);
 
 
-	/* clear message input buffer */
-	furi_string_set_char(state->msg_input, 0, 0);
+    /* clear message input buffer */
+    furi_string_set_char(state->msg_input, 0, 0);
 
 
-	/* wait for leave message to be delivered */
-	furi_delay_ms(CHAT_LEAVE_DELAY);
+    /* wait for leave message to be delivered */
+    furi_delay_ms(CHAT_LEAVE_DELAY);
 }
 }
 
 
 /* Whether or not to display the locked message. */
 /* Whether or not to display the locked message. */
-static bool kbd_lock_msg_display(ESubGhzChatState *state)
-{
-	return (state->kbd_lock_msg_ticks != 0);
+static bool kbd_lock_msg_display(ESubGhzChatState* state) {
+    return (state->kbd_lock_msg_ticks != 0);
 }
 }
 
 
 /* Whether or not to hide the locked message again. */
 /* Whether or not to hide the locked message again. */
-static bool kbd_lock_msg_reset_timeout(ESubGhzChatState *state)
-{
-	if (state->kbd_lock_msg_ticks == 0) {
-		return false;
-	}
+static bool kbd_lock_msg_reset_timeout(ESubGhzChatState* state) {
+    if(state->kbd_lock_msg_ticks == 0) {
+        return false;
+    }
 
 
-	if (furi_get_tick() - state->kbd_lock_msg_ticks > KBD_UNLOCK_TIMEOUT) {
-		return true;
-	}
+    if(furi_get_tick() - state->kbd_lock_msg_ticks > KBD_UNLOCK_TIMEOUT) {
+        return true;
+    }
 
 
-	return false;
+    return false;
 }
 }
 
 
 /* Resets the timeout for the locked message and turns off the backlight if
 /* Resets the timeout for the locked message and turns off the backlight if
  * specified. */
  * specified. */
-static void kbd_lock_msg_reset(ESubGhzChatState *state, bool backlight_off)
-{
-	state->kbd_lock_msg_ticks = 0;
-	state->kbd_lock_count = 0;
-
-	if (backlight_off) {
-		notification_message(state->notification,
-				&sequence_display_backlight_off);
-	}
+static void kbd_lock_msg_reset(ESubGhzChatState* state, bool backlight_off) {
+    state->kbd_lock_msg_ticks = 0;
+    state->kbd_lock_count = 0;
+
+    if(backlight_off) {
+        notification_message(state->notification, &sequence_display_backlight_off);
+    }
 }
 }
 
 
 /* Locks the keyboard. */
 /* Locks the keyboard. */
-static void kbd_lock(ESubGhzChatState *state)
-{
-	state->kbd_locked = true;
-	kbd_lock_msg_reset(state, true);
+static void kbd_lock(ESubGhzChatState* state) {
+    state->kbd_locked = true;
+    kbd_lock_msg_reset(state, true);
 }
 }
 
 
 /* Unlocks the keyboard. */
 /* Unlocks the keyboard. */
-static void kbd_unlock(ESubGhzChatState *state)
-{
-	state->kbd_locked = false;
-	kbd_lock_msg_reset(state, false);
+static void kbd_unlock(ESubGhzChatState* state) {
+    state->kbd_locked = false;
+    kbd_lock_msg_reset(state, false);
 }
 }
 
 
 /* Custom event callback for view dispatcher. Just calls scene manager. */
 /* Custom event callback for view dispatcher. Just calls scene manager. */
-static bool esubghz_chat_custom_event_callback(void* context, uint32_t event)
-{
-	FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_custom_event_callback");
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-	return scene_manager_handle_custom_event(state->scene_manager, event);
+static bool esubghz_chat_custom_event_callback(void* context, uint32_t event) {
+    FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_custom_event_callback");
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+    return scene_manager_handle_custom_event(state->scene_manager, event);
 }
 }
 
 
 /* Navigation event callback for view dispatcher. Just calls scene manager. */
 /* Navigation event callback for view dispatcher. Just calls scene manager. */
-static bool esubghz_chat_navigation_event_callback(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_navigation_event_callback");
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-	return scene_manager_handle_back_event(state->scene_manager);
+static bool esubghz_chat_navigation_event_callback(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_navigation_event_callback");
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+    return scene_manager_handle_back_event(state->scene_manager);
 }
 }
 
 
-static void esubghz_chat_check_messages(ESubGhzChatState *state)
-{
-	/* if the maximum message size was reached or the
+static void esubghz_chat_check_messages(ESubGhzChatState* state) {
+    /* if the maximum message size was reached or the
 	 * MESSAGE_COMPLETION_TIMEOUT has expired, retrieve a message and call
 	 * MESSAGE_COMPLETION_TIMEOUT has expired, retrieve a message and call
 	 * post_rx() */
 	 * post_rx() */
-	size_t avail = 0;
-	while ((avail = subghz_tx_rx_worker_available(state->subghz_worker)) >
-			0) {
-		volatile uint32_t since_last_rx = furi_get_tick() -
-			state->last_time_rx_data;
-		if (avail < RX_TX_BUFFER_SIZE && since_last_rx <
-				MESSAGE_COMPLETION_TIMEOUT) {
-			break;
-		}
-
-		size_t rx_size = subghz_tx_rx_worker_read(state->subghz_worker,
-				state->rx_buffer, RX_TX_BUFFER_SIZE);
-		post_rx(state, rx_size);
-	}
+    size_t avail = 0;
+    while((avail = subghz_tx_rx_worker_available(state->subghz_worker)) > 0) {
+        volatile uint32_t since_last_rx = furi_get_tick() - state->last_time_rx_data;
+        if(avail < RX_TX_BUFFER_SIZE && since_last_rx < MESSAGE_COMPLETION_TIMEOUT) {
+            break;
+        }
+
+        size_t rx_size =
+            subghz_tx_rx_worker_read(state->subghz_worker, state->rx_buffer, RX_TX_BUFFER_SIZE);
+        post_rx(state, rx_size);
+    }
 }
 }
 
 
 /* Tick event callback for view dispatcher. Called every TICK_INTERVAL. Resets
 /* Tick event callback for view dispatcher. Called every TICK_INTERVAL. Resets
  * the locked message if necessary. Retrieves a received message from the
  * the locked message if necessary. Retrieves a received message from the
  * Sub-GHz worker and calls post_rx(). Then calls the scene manager. */
  * Sub-GHz worker and calls post_rx(). Then calls the scene manager. */
-static void esubghz_chat_tick_event_callback(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_tick_event_callback");
+static void esubghz_chat_tick_event_callback(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "esubghz_chat_tick_event_callback");
 
 
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	/* reset locked message if necessary */
-	if (kbd_lock_msg_reset_timeout(state)) {
-		kbd_lock_msg_reset(state, true);
-	}
+    /* reset locked message if necessary */
+    if(kbd_lock_msg_reset_timeout(state)) {
+        kbd_lock_msg_reset(state, true);
+    }
 
 
-	esubghz_chat_check_messages(state);
+    esubghz_chat_check_messages(state);
 
 
-	/* call scene manager */
-	scene_manager_handle_tick_event(state->scene_manager);
+    /* call scene manager */
+    scene_manager_handle_tick_event(state->scene_manager);
 }
 }
 
 
 /* Hooks into the view port's draw callback to overlay the keyboard locked
 /* Hooks into the view port's draw callback to overlay the keyboard locked
  * message. */
  * message. */
-static void esubghz_hooked_draw_callback(Canvas* canvas, void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "esubghz_hooked_draw_callback");
-
-	furi_assert(canvas);
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	/* call original callback */
-	state->orig_draw_cb(canvas, state->view_dispatcher);
-
-	/* display if the keyboard is locked */
-	if (state->kbd_locked) {
-		canvas_set_font(canvas, FontPrimary);
-		elements_multiline_text_framed(canvas, 42, 30, "Locked");
-	}
-
-	/* display the unlock message if necessary */
-	if (kbd_lock_msg_display(state)) {
-		canvas_set_font(canvas, FontSecondary);
-		elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
-		elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
-		canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
-		canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
-		canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
-		canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
-	}
+static void esubghz_hooked_draw_callback(Canvas* canvas, void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "esubghz_hooked_draw_callback");
+
+    furi_assert(canvas);
+
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+
+    /* call original callback */
+    state->orig_draw_cb(canvas, state->view_dispatcher);
+
+    /* display if the keyboard is locked */
+    if(state->kbd_locked) {
+        canvas_set_font(canvas, FontPrimary);
+        elements_multiline_text_framed(canvas, 42, 30, "Locked");
+    }
+
+    /* display the unlock message if necessary */
+    if(kbd_lock_msg_display(state)) {
+        canvas_set_font(canvas, FontSecondary);
+        elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
+        elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
+        canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
+        canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
+        canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
+        canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
+    }
 }
 }
 
 
 /* Hooks into the view port's input callback to handle the user locking the
 /* Hooks into the view port's input callback to handle the user locking the
  * keyboard. */
  * keyboard. */
-static void esubghz_hooked_input_callback(InputEvent* event, void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "esubghz_hooked_input_callback");
+static void esubghz_hooked_input_callback(InputEvent* event, void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "esubghz_hooked_input_callback");
 
 
-	furi_assert(event);
+    furi_assert(event);
 
 
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	/* if the keyboard is locked no key presses are forwarded */
-	if (state->kbd_locked) {
-		/* key has been pressed, display the unlock message and
+    /* if the keyboard is locked no key presses are forwarded */
+    if(state->kbd_locked) {
+        /* key has been pressed, display the unlock message and
 		 * initiate the timer */
 		 * initiate the timer */
-		if (state->kbd_lock_count == 0) {
-			state->kbd_lock_msg_ticks = furi_get_tick();
-		}
-
-		/* back button has been pressed, increase the lock counter */
-		if (event->key == InputKeyBack && event->type ==
-				InputTypeShort) {
-			state->kbd_lock_count++;
-		}
-
-		/* unlock the keyboard */
-		if (state->kbd_lock_count >= KBD_UNLOCK_CNT) {
-			kbd_unlock(state);
-		}
-
-		/* do not handle the event */
-		return;
-	}
-
-	/* handle long press of back key to exit for real */
-	if (event->key == InputKeyBack) {
-		if (state->view_dispatcher->current_view ==
-				text_input_get_view(state->text_input)) {
-			if (event->type == InputTypeLong) {
-				state->exit_for_real = true;
-				view_dispatcher_stop(state->view_dispatcher);
-				return;
-			}
-		}
-	}
-
-	if (event->key == InputKeyOk) {
-		/* if we are in the chat view and no input is ongoing, allow
+        if(state->kbd_lock_count == 0) {
+            state->kbd_lock_msg_ticks = furi_get_tick();
+        }
+
+        /* back button has been pressed, increase the lock counter */
+        if(event->key == InputKeyBack && event->type == InputTypeShort) {
+            state->kbd_lock_count++;
+        }
+
+        /* unlock the keyboard */
+        if(state->kbd_lock_count >= KBD_UNLOCK_CNT) {
+            kbd_unlock(state);
+        }
+
+        /* do not handle the event */
+        return;
+    }
+
+    /* handle long press of back key to exit for real */
+    if(event->key == InputKeyBack) {
+        if(state->view_dispatcher->current_view == text_input_get_view(state->text_input)) {
+            if(event->type == InputTypeLong) {
+                state->exit_for_real = true;
+                view_dispatcher_stop(state->view_dispatcher);
+                return;
+            }
+        }
+    }
+
+    if(event->key == InputKeyOk) {
+        /* if we are in the chat view and no input is ongoing, allow
 		 * locking */
 		 * locking */
-		if (state->view_dispatcher->current_view ==
-				text_box_get_view(state->chat_box) &&
-				!(state->kbd_ok_input_ongoing)) {
-			/* lock keyboard upon long press of Ok button */
-			if (event->type == InputTypeLong) {
-				kbd_lock(state);
-			}
-
-			/* do not handle any Ok key events to prevent blocking
+        if(state->view_dispatcher->current_view == text_box_get_view(state->chat_box) &&
+           !(state->kbd_ok_input_ongoing)) {
+            /* lock keyboard upon long press of Ok button */
+            if(event->type == InputTypeLong) {
+                kbd_lock(state);
+            }
+
+            /* do not handle any Ok key events to prevent blocking
 			 * of other keys */
 			 * of other keys */
-			return;
-		}
-
-		/* handle ongoing inputs when changing to chat view */
-		if (event->type == InputTypePress) {
-			state->kbd_ok_input_ongoing = true;
-		} else if (event->type == InputTypeRelease) {
-			state->kbd_ok_input_ongoing = false;
-		}
-	}
-
-	if (event->key == InputKeyLeft) {
-		/* if we are in the chat view and no input is ongoing, allow
+            return;
+        }
+
+        /* handle ongoing inputs when changing to chat view */
+        if(event->type == InputTypePress) {
+            state->kbd_ok_input_ongoing = true;
+        } else if(event->type == InputTypeRelease) {
+            state->kbd_ok_input_ongoing = false;
+        }
+    }
+
+    if(event->key == InputKeyLeft) {
+        /* if we are in the chat view and no input is ongoing, allow
 		 * switching to msg input */
 		 * switching to msg input */
-		if (state->view_dispatcher->current_view ==
-				text_box_get_view(state->chat_box) &&
-				!(state->kbd_left_input_ongoing)) {
-			/* go to msg input upon short press of Left button */
-			if (event->type == InputTypeShort) {
-				view_dispatcher_send_custom_event(state->view_dispatcher,
-						ESubGhzChatEvent_GotoMsgInput);
-			}
-
-			/* do not handle any Left key events to prevent
+        if(state->view_dispatcher->current_view == text_box_get_view(state->chat_box) &&
+           !(state->kbd_left_input_ongoing)) {
+            /* go to msg input upon short press of Left button */
+            if(event->type == InputTypeShort) {
+                view_dispatcher_send_custom_event(
+                    state->view_dispatcher, ESubGhzChatEvent_GotoMsgInput);
+            }
+
+            /* do not handle any Left key events to prevent
 			 * blocking of other keys */
 			 * blocking of other keys */
-			return;
-		}
-
-		/* handle ongoing inputs when changing to chat view */
-		if (event->type == InputTypePress) {
-			state->kbd_left_input_ongoing = true;
-		} else if (event->type == InputTypeRelease) {
-			state->kbd_left_input_ongoing = false;
-		}
-	}
-
-	if (event->key == InputKeyRight) {
-		/* if we are in the chat view and no input is ongoing, allow
+            return;
+        }
+
+        /* handle ongoing inputs when changing to chat view */
+        if(event->type == InputTypePress) {
+            state->kbd_left_input_ongoing = true;
+        } else if(event->type == InputTypeRelease) {
+            state->kbd_left_input_ongoing = false;
+        }
+    }
+
+    if(event->key == InputKeyRight) {
+        /* if we are in the chat view and no input is ongoing, allow
 		 * switching to key display */
 		 * switching to key display */
-		if (state->view_dispatcher->current_view ==
-				text_box_get_view(state->chat_box) &&
-				!(state->kbd_right_input_ongoing)) {
-			/* go to key display upon short press of Right button
+        if(state->view_dispatcher->current_view == text_box_get_view(state->chat_box) &&
+           !(state->kbd_right_input_ongoing)) {
+            /* go to key display upon short press of Right button
 			 */
 			 */
-			if (event->type == InputTypeShort) {
-				view_dispatcher_send_custom_event(state->view_dispatcher,
-						ESubGhzChatEvent_GotoKeyDisplay);
-			}
+            if(event->type == InputTypeShort) {
+                view_dispatcher_send_custom_event(
+                    state->view_dispatcher, ESubGhzChatEvent_GotoKeyDisplay);
+            }
 
 
-			/* do not handle any Right key events to prevent
+            /* do not handle any Right key events to prevent
 			 * blocking of other keys */
 			 * blocking of other keys */
-			return;
-		}
-
-		/* handle ongoing inputs when changing to chat view */
-		if (event->type == InputTypePress) {
-			state->kbd_right_input_ongoing = true;
-		} else if (event->type == InputTypeRelease) {
-			state->kbd_right_input_ongoing = false;
-		}
-	}
-
-	/* call original callback */
-	state->orig_input_cb(event, state->view_dispatcher);
+            return;
+        }
+
+        /* handle ongoing inputs when changing to chat view */
+        if(event->type == InputTypePress) {
+            state->kbd_right_input_ongoing = true;
+        } else if(event->type == InputTypeRelease) {
+            state->kbd_right_input_ongoing = false;
+        }
+    }
+
+    /* call original callback */
+    state->orig_input_cb(event, state->view_dispatcher);
 }
 }
 
 
-static const char *esubghz_get_bgloader_app_path(const char *args)
-{
-	size_t base_args_len = strlen(APP_BASE_ARGS);
+static const char* esubghz_get_bgloader_app_path(const char* args) {
+    size_t base_args_len = strlen(APP_BASE_ARGS);
 
 
-	return (args + base_args_len + 1);
+    return (args + base_args_len + 1);
 }
 }
 
 
-static bool esubghz_run_with_bgloader(const char *args)
-{
-	size_t base_args_len = strlen(APP_BASE_ARGS);
+static bool esubghz_run_with_bgloader(const char* args) {
+    size_t base_args_len = strlen(APP_BASE_ARGS);
 
 
-	if (args == NULL) {
-		return false;
-	}
+    if(args == NULL) {
+        return false;
+    }
 
 
-	if (strncmp(args, APP_BASE_ARGS, base_args_len) != 0) {
-		return false;
-	}
+    if(strncmp(args, APP_BASE_ARGS, base_args_len) != 0) {
+        return false;
+    }
 
 
-	if (strlen(args) < base_args_len + 2) {
-		return false;
-	}
+    if(strlen(args) < base_args_len + 2) {
+        return false;
+    }
 
 
-	if (args[base_args_len] != ':') {
-		return false;
-	}
+    if(args[base_args_len] != ':') {
+        return false;
+    }
 
 
-	const char *app_path = esubghz_get_bgloader_app_path(args);
-	return furi_record_exists(app_path);
+    const char* app_path = esubghz_get_bgloader_app_path(args);
+    return furi_record_exists(app_path);
 }
 }
 
 
-static void esubghz_attach_to_gui(ESubGhzChatState *state)
-{
-	Gui *gui = furi_record_open(RECORD_GUI);
-	view_dispatcher_attach_to_gui(state->view_dispatcher, gui,
-			ViewDispatcherTypeFullscreen);
+static void esubghz_attach_to_gui(ESubGhzChatState* state) {
+    Gui* gui = furi_record_open(RECORD_GUI);
+    view_dispatcher_attach_to_gui(state->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
 }
 }
 
 
-static void esubghz_detach_from_gui(ESubGhzChatState *state)
-{
-	gui_remove_view_port(state->view_dispatcher->gui,
-			state->view_dispatcher->view_port);
-	state->view_dispatcher->gui = NULL;
-	furi_record_close(RECORD_GUI);
+static void esubghz_detach_from_gui(ESubGhzChatState* state) {
+    gui_remove_view_port(state->view_dispatcher->gui, state->view_dispatcher->view_port);
+    state->view_dispatcher->gui = NULL;
+    furi_record_close(RECORD_GUI);
 }
 }
 
 
-static void esubghz_bgloader_loop(ESubGhzChatState *state, const char
-		*bg_app_path)
-{
-	while (true) {
-		view_dispatcher_run(state->view_dispatcher);
-		
-		if (state->exit_for_real) {
-			/* exit for real */
-			break;
-		}
-		
-		BGLoaderApp *bg_app = furi_record_open(bg_app_path);
-		
-		/* signal loader that we're ready to go to background */
-		BGLoaderMessage msg;
-		msg.type = BGLoaderMessageType_LoaderBackground;
-		furi_check(furi_message_queue_put(bg_app->to_loader, &msg,
-					FuriWaitForever) == FuriStatusOk);
-		
-		esubghz_detach_from_gui(state);
-
-		while (true) {
-			/* wait for loader to wake us up again */
-			if (furi_message_queue_get(bg_app->to_app, &msg,
-						TICK_INTERVAL) != FuriStatusOk)
-			{
-				/* check for messages on timeout */
-				esubghz_chat_check_messages(state);
-				continue;
-			}
-			if (msg.type == BGLoaderMessageType_AppReattached) {
-				break;
-			} else {
-				furi_check(0);
-			}
-		}
-		
-		furi_record_close(bg_app_path);
-		
-		esubghz_attach_to_gui(state);
+static void esubghz_bgloader_loop(ESubGhzChatState* state, const char* bg_app_path) {
+    while(true) {
+        view_dispatcher_run(state->view_dispatcher);
+
+        if(state->exit_for_real) {
+            /* exit for real */
+            break;
         }
         }
+
+        BGLoaderApp* bg_app = furi_record_open(bg_app_path);
+
+        /* signal loader that we're ready to go to background */
+        BGLoaderMessage msg;
+        msg.type = BGLoaderMessageType_LoaderBackground;
+        furi_check(
+            furi_message_queue_put(bg_app->to_loader, &msg, FuriWaitForever) == FuriStatusOk);
+
+        esubghz_detach_from_gui(state);
+
+        while(true) {
+            /* wait for loader to wake us up again */
+            if(furi_message_queue_get(bg_app->to_app, &msg, TICK_INTERVAL) != FuriStatusOk) {
+                /* check for messages on timeout */
+                esubghz_chat_check_messages(state);
+                continue;
+            }
+            if(msg.type == BGLoaderMessageType_AppReattached) {
+                break;
+            } else {
+                furi_check(0);
+            }
+        }
+
+        furi_record_close(bg_app_path);
+
+        esubghz_attach_to_gui(state);
+    }
 }
 }
 
 
-static bool helper_strings_alloc(ESubGhzChatState *state)
-{
-	furi_assert(state);
+static bool helper_strings_alloc(ESubGhzChatState* state) {
+    furi_assert(state);
 
 
-	state->name_prefix = furi_string_alloc();
-	if (state->name_prefix == NULL) {
-		return false;
-	}
+    state->name_prefix = furi_string_alloc();
+    if(state->name_prefix == NULL) {
+        return false;
+    }
 
 
-	state->msg_input = furi_string_alloc();
-	if (state->msg_input == NULL) {
-		furi_string_free(state->name_prefix);
-		return false;
-	}
+    state->msg_input = furi_string_alloc();
+    if(state->msg_input == NULL) {
+        furi_string_free(state->name_prefix);
+        return false;
+    }
 
 
-	return true;
+    return true;
 }
 }
 
 
-static void helper_strings_free(ESubGhzChatState *state)
-{
-	furi_assert(state);
+static void helper_strings_free(ESubGhzChatState* state) {
+    furi_assert(state);
 
 
-	furi_string_free(state->name_prefix);
-	furi_string_free(state->msg_input);
+    furi_string_free(state->name_prefix);
+    furi_string_free(state->msg_input);
 }
 }
 
 
-static bool chat_box_alloc(ESubGhzChatState *state)
-{
-	furi_assert(state);
+static bool chat_box_alloc(ESubGhzChatState* state) {
+    furi_assert(state);
 
 
-	state->chat_box = text_box_alloc();
-	if (state->chat_box == NULL) {
-		return false;
-	}
+    state->chat_box = text_box_alloc();
+    if(state->chat_box == NULL) {
+        return false;
+    }
 
 
-	state->chat_box_store = furi_string_alloc();
-	if (state->chat_box_store == NULL) {
-		text_box_free(state->chat_box);
-		return false;
-	}
+    state->chat_box_store = furi_string_alloc();
+    if(state->chat_box_store == NULL) {
+        text_box_free(state->chat_box);
+        return false;
+    }
 
 
-	furi_string_reserve(state->chat_box_store, CHAT_BOX_STORE_SIZE);
-	furi_string_set_char(state->chat_box_store, 0, 0);
-	text_box_set_text(state->chat_box,
-			furi_string_get_cstr(state->chat_box_store));
-	text_box_set_focus(state->chat_box, TextBoxFocusEnd);
+    furi_string_reserve(state->chat_box_store, CHAT_BOX_STORE_SIZE);
+    furi_string_set_char(state->chat_box_store, 0, 0);
+    text_box_set_text(state->chat_box, furi_string_get_cstr(state->chat_box_store));
+    text_box_set_focus(state->chat_box, TextBoxFocusEnd);
 
 
-	return true;
+    return true;
 }
 }
 
 
-static void chat_box_free(ESubGhzChatState *state)
-{
-	furi_assert(state);
+static void chat_box_free(ESubGhzChatState* state) {
+    furi_assert(state);
 
 
-	text_box_free(state->chat_box);
-	furi_string_free(state->chat_box_store);
+    text_box_free(state->chat_box);
+    furi_string_free(state->chat_box_store);
 }
 }
 
 
-int32_t esubghz_chat(const char *args)
-{
-	/* init the crypto system */
-	crypto_init();
+int32_t esubghz_chat(const char* args) {
+    /* init the crypto system */
+    crypto_init();
+
+    int32_t err = -1;
+
+    FURI_LOG_I(APPLICATION_NAME, "Starting...");
 
 
-	int32_t err = -1;
-
-	FURI_LOG_I(APPLICATION_NAME, "Starting...");
+    /* allocate necessary structs and buffers */
 
 
-	/* allocate necessary structs and buffers */
-
-	ESubGhzChatState *state = malloc(sizeof(ESubGhzChatState));
-	if (state == NULL) {
-		goto err_alloc;
-	}
-	memset(state, 0, sizeof(*state));
-
-	state->scene_manager = scene_manager_alloc(
-			&esubghz_chat_scene_event_handlers, state);
-	if (state->scene_manager == NULL) {
-		goto err_alloc_sm;
-	}
-
-	state->view_dispatcher = view_dispatcher_alloc();
-	if (state->view_dispatcher == NULL) {
-		goto err_alloc_vd;
-	}
-
-	if (!helper_strings_alloc(state)) {
-		goto err_alloc_hs;
-	}
-
-	state->menu = menu_alloc();
-	if (state->menu == NULL) {
-		goto err_alloc_menu;
-	}
-
-	state->text_input = text_input_alloc();
-	if (state->text_input == NULL) {
-		goto err_alloc_ti;
-	}
-
-	state->hex_key_input = byte_input_alloc();
-	if (state->hex_key_input == NULL) {
-		goto err_alloc_hki;
-	}
-
-	if (!chat_box_alloc(state)) {
-		goto err_alloc_cb;
-	}
-
-	state->key_display = dialog_ex_alloc();
-	if (state->key_display == NULL) {
-		goto err_alloc_kd;
-	}
-
-	state->nfc_popup = popup_alloc();
-	if (state->nfc_popup == NULL) {
-		goto err_alloc_np;
-	}
-
-	state->subghz_worker = subghz_tx_rx_worker_alloc();
-	if (state->subghz_worker == NULL) {
-		goto err_alloc_worker;
-	}
-
-	state->nfc_worker = nfc_worker_alloc();
-	if (state->nfc_worker == NULL) {
-		goto err_alloc_nworker;
-	}
-
-	state->nfc_dev_data = malloc(sizeof(NfcDeviceData));
-	if (state->nfc_dev_data == NULL) {
-		goto err_alloc_ndevdata;
-	}
-	memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
-
-	state->crypto_ctx = crypto_ctx_alloc();
-	if (state->crypto_ctx == NULL) {
-		goto err_alloc_crypto;
-	}
-
-	/* set the default frequency */
-	state->frequency = DEFAULT_FREQ;
-
-	/* in the first few views there is no background support */
-	state->exit_for_real = true;
-
-	/* set the have_read callback of the Sub-GHz worker */
-	subghz_tx_rx_worker_set_callback_have_read(state->subghz_worker,
-			have_read_cb, state);
-
-	/* enter suppress charge mode */
-	furi_hal_power_suppress_charge_enter();
-
-	/* init internal device */
-	subghz_devices_init();
-
-	state->subghz_device = radio_device_loader_set(state->subghz_device,
-			SubGhzRadioDeviceTypeExternalCC1101);
-
-	subghz_devices_reset(state->subghz_device);
-	subghz_devices_idle(state->subghz_device);
-
-	/* set chat name prefix */
-	furi_string_printf(state->name_prefix, "%s",
-			furi_hal_version_get_name_ptr());
-
-	/* get notification record, we use this to make the flipper vibrate */
-	/* no error handling here, don't know how */
-	state->notification = furi_record_open(RECORD_NOTIFICATION);
-
-	/* hook into the view port's draw and input callbacks */
-	state->orig_draw_cb = state->view_dispatcher->view_port->draw_callback;
-	state->orig_input_cb = state->view_dispatcher->view_port->input_callback;
-	view_port_draw_callback_set(state->view_dispatcher->view_port,
-			esubghz_hooked_draw_callback, state);
-	view_port_input_callback_set(state->view_dispatcher->view_port,
-			esubghz_hooked_input_callback, state);
-
-	view_dispatcher_enable_queue(state->view_dispatcher);
-
-	/* set callbacks for view dispatcher */
-	view_dispatcher_set_event_callback_context(state->view_dispatcher, state);
-	view_dispatcher_set_custom_event_callback(
-			state->view_dispatcher,
-			esubghz_chat_custom_event_callback);
-	view_dispatcher_set_navigation_event_callback(
-			state->view_dispatcher,
-			esubghz_chat_navigation_event_callback);
-	view_dispatcher_set_tick_event_callback(
-			state->view_dispatcher,
-			esubghz_chat_tick_event_callback,
-			TICK_INTERVAL);
-
-	/* add our two views to the view dispatcher */
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_Menu,
-			menu_get_view(state->menu));
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_Input,
-			text_input_get_view(state->text_input));
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_HexKeyInput,
-			byte_input_get_view(state->hex_key_input));
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_ChatBox,
-			text_box_get_view(state->chat_box));
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_KeyDisplay,
-			dialog_ex_get_view(state->key_display));
-	view_dispatcher_add_view(state->view_dispatcher, ESubGhzChatView_NfcPopup,
-			popup_get_view(state->nfc_popup));
-
-	/* get the GUI record and attach the view dispatcher to the GUI */
-	/* no error handling here, don't know how */
-	Gui *gui = furi_record_open(RECORD_GUI);
-	view_dispatcher_attach_to_gui(state->view_dispatcher, gui,
-			ViewDispatcherTypeFullscreen);
-
-	/* switch to the key menu scene */
-	scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeyMenu);
-
-	/* run the view dispatcher, this call only returns when we close the
+    ESubGhzChatState* state = malloc(sizeof(ESubGhzChatState));
+    if(state == NULL) {
+        goto err_alloc;
+    }
+    memset(state, 0, sizeof(*state));
+
+    state->scene_manager = scene_manager_alloc(&esubghz_chat_scene_event_handlers, state);
+    if(state->scene_manager == NULL) {
+        goto err_alloc_sm;
+    }
+
+    state->view_dispatcher = view_dispatcher_alloc();
+    if(state->view_dispatcher == NULL) {
+        goto err_alloc_vd;
+    }
+
+    if(!helper_strings_alloc(state)) {
+        goto err_alloc_hs;
+    }
+
+    state->menu = menu_alloc();
+    if(state->menu == NULL) {
+        goto err_alloc_menu;
+    }
+
+    state->text_input = text_input_alloc();
+    if(state->text_input == NULL) {
+        goto err_alloc_ti;
+    }
+
+    state->hex_key_input = byte_input_alloc();
+    if(state->hex_key_input == NULL) {
+        goto err_alloc_hki;
+    }
+
+    if(!chat_box_alloc(state)) {
+        goto err_alloc_cb;
+    }
+
+    state->key_display = dialog_ex_alloc();
+    if(state->key_display == NULL) {
+        goto err_alloc_kd;
+    }
+
+    state->nfc_popup = popup_alloc();
+    if(state->nfc_popup == NULL) {
+        goto err_alloc_np;
+    }
+
+    state->subghz_worker = subghz_tx_rx_worker_alloc();
+    if(state->subghz_worker == NULL) {
+        goto err_alloc_worker;
+    }
+
+    state->crypto_ctx = crypto_ctx_alloc();
+    if(state->crypto_ctx == NULL) {
+        goto err_alloc_crypto;
+    }
+
+    /* set the default frequency */
+    state->frequency = DEFAULT_FREQ;
+
+    /* in the first few views there is no background support */
+    state->exit_for_real = true;
+
+    /* set the have_read callback of the Sub-GHz worker */
+    subghz_tx_rx_worker_set_callback_have_read(state->subghz_worker, have_read_cb, state);
+
+    /* enter suppress charge mode */
+    furi_hal_power_suppress_charge_enter();
+
+    /* init internal device */
+    subghz_devices_init();
+
+    state->subghz_device =
+        radio_device_loader_set(state->subghz_device, SubGhzRadioDeviceTypeExternalCC1101);
+
+    subghz_devices_reset(state->subghz_device);
+    subghz_devices_idle(state->subghz_device);
+
+    /* set chat name prefix */
+    furi_string_printf(state->name_prefix, "%s", furi_hal_version_get_name_ptr());
+
+    /* get notification record, we use this to make the flipper vibrate */
+    /* no error handling here, don't know how */
+    state->notification = furi_record_open(RECORD_NOTIFICATION);
+
+    /* hook into the view port's draw and input callbacks */
+    state->orig_draw_cb = state->view_dispatcher->view_port->draw_callback;
+    state->orig_input_cb = state->view_dispatcher->view_port->input_callback;
+    view_port_draw_callback_set(
+        state->view_dispatcher->view_port, esubghz_hooked_draw_callback, state);
+    view_port_input_callback_set(
+        state->view_dispatcher->view_port, esubghz_hooked_input_callback, state);
+
+    view_dispatcher_enable_queue(state->view_dispatcher);
+
+    /* set callbacks for view dispatcher */
+    view_dispatcher_set_event_callback_context(state->view_dispatcher, state);
+    view_dispatcher_set_custom_event_callback(
+        state->view_dispatcher, esubghz_chat_custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(
+        state->view_dispatcher, esubghz_chat_navigation_event_callback);
+    view_dispatcher_set_tick_event_callback(
+        state->view_dispatcher, esubghz_chat_tick_event_callback, TICK_INTERVAL);
+
+    /* add our two views to the view dispatcher */
+    view_dispatcher_add_view(
+        state->view_dispatcher, ESubGhzChatView_Menu, menu_get_view(state->menu));
+    view_dispatcher_add_view(
+        state->view_dispatcher, ESubGhzChatView_Input, text_input_get_view(state->text_input));
+    view_dispatcher_add_view(
+        state->view_dispatcher,
+        ESubGhzChatView_HexKeyInput,
+        byte_input_get_view(state->hex_key_input));
+    view_dispatcher_add_view(
+        state->view_dispatcher, ESubGhzChatView_ChatBox, text_box_get_view(state->chat_box));
+    view_dispatcher_add_view(
+        state->view_dispatcher,
+        ESubGhzChatView_KeyDisplay,
+        dialog_ex_get_view(state->key_display));
+    view_dispatcher_add_view(
+        state->view_dispatcher, ESubGhzChatView_NfcPopup, popup_get_view(state->nfc_popup));
+
+    /* get the GUI record and attach the view dispatcher to the GUI */
+    /* no error handling here, don't know how */
+    Gui* gui = furi_record_open(RECORD_GUI);
+    view_dispatcher_attach_to_gui(state->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
+
+    /* switch to the key menu scene */
+    scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_KeyMenu);
+
+    /* run the view dispatcher, this call only returns when we close the
 	 * application */
 	 * application */
-	if (!esubghz_run_with_bgloader(args)) {
-		view_dispatcher_run(state->view_dispatcher);
-	} else {
-		const char *bg_app_path = esubghz_get_bgloader_app_path(args);
-		esubghz_bgloader_loop(state, bg_app_path);
-	}
-
-	/* if it is running, stop the Sub-GHz worker */
-	if (subghz_tx_rx_worker_is_running(state->subghz_worker)) {
-		exit_chat(state);
-		subghz_tx_rx_worker_stop(state->subghz_worker);
-	}
-
-	/* if it is running, stop the NFC worker */
-	nfc_worker_stop(state->nfc_worker);
-
-	err = 0;
-
-	/* close GUI record */
-	furi_record_close(RECORD_GUI);
-
-	/* remove our two views from the view dispatcher */
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_Menu);
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_Input);
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_HexKeyInput);
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_ChatBox);
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_KeyDisplay);
-	view_dispatcher_remove_view(state->view_dispatcher,
-			ESubGhzChatView_NfcPopup);
-
-	/* close notification record */
-	furi_record_close(RECORD_NOTIFICATION);
-
-	/* clear the key and potential password */
-	crypto_explicit_bzero(state->text_input_store,
-			sizeof(state->text_input_store));
-	crypto_explicit_bzero(state->hex_key_input_store,
-			sizeof(state->hex_key_input_store));
-	crypto_explicit_bzero(state->key_hex_str, sizeof(state->key_hex_str));
-	crypto_ctx_clear(state->crypto_ctx);
-
-	/* clear nfc data */
-	if (state->nfc_dev_data->parsed_data != NULL) {
-		furi_string_free(state->nfc_dev_data->parsed_data);
-	}
-	crypto_explicit_bzero(state->nfc_dev_data, sizeof(NfcDeviceData));
-
-	/* deinit devices */
-	radio_device_loader_end(state->subghz_device);
-
-	subghz_devices_deinit();
-
-	/* exit suppress charge mode */
-	furi_hal_power_suppress_charge_exit();
-
-	/* free everything we allocated */
-
-	crypto_ctx_free(state->crypto_ctx);
+    if(!esubghz_run_with_bgloader(args)) {
+        view_dispatcher_run(state->view_dispatcher);
+    } else {
+        const char* bg_app_path = esubghz_get_bgloader_app_path(args);
+        esubghz_bgloader_loop(state, bg_app_path);
+    }
 
 
-err_alloc_crypto:
-	free(state->nfc_dev_data);
+    /* if it is running, stop the Sub-GHz worker */
+    if(subghz_tx_rx_worker_is_running(state->subghz_worker)) {
+        exit_chat(state);
+        subghz_tx_rx_worker_stop(state->subghz_worker);
+    }
+
+    err = 0;
+
+    /* close GUI record */
+    furi_record_close(RECORD_GUI);
+
+    /* remove our two views from the view dispatcher */
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_Menu);
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_Input);
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_HexKeyInput);
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_ChatBox);
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_KeyDisplay);
+    view_dispatcher_remove_view(state->view_dispatcher, ESubGhzChatView_NfcPopup);
+
+    /* close notification record */
+    furi_record_close(RECORD_NOTIFICATION);
 
 
-err_alloc_ndevdata:
-	nfc_worker_free(state->nfc_worker);
+    /* clear the key and potential password */
+    crypto_explicit_bzero(state->text_input_store, sizeof(state->text_input_store));
+    crypto_explicit_bzero(state->hex_key_input_store, sizeof(state->hex_key_input_store));
+    crypto_explicit_bzero(state->key_hex_str, sizeof(state->key_hex_str));
+    crypto_ctx_clear(state->crypto_ctx);
 
 
-err_alloc_nworker:
-	subghz_tx_rx_worker_free(state->subghz_worker);
+    /* deinit devices */
+    radio_device_loader_end(state->subghz_device);
+
+    subghz_devices_deinit();
+
+    /* exit suppress charge mode */
+    furi_hal_power_suppress_charge_exit();
+
+    /* free everything we allocated */
+
+    crypto_ctx_free(state->crypto_ctx);
+
+err_alloc_crypto:
+    subghz_tx_rx_worker_free(state->subghz_worker);
 
 
 err_alloc_worker:
 err_alloc_worker:
-	popup_free(state->nfc_popup);
+    popup_free(state->nfc_popup);
 
 
 err_alloc_np:
 err_alloc_np:
-	dialog_ex_free(state->key_display);
+    dialog_ex_free(state->key_display);
 
 
 err_alloc_kd:
 err_alloc_kd:
-	chat_box_free(state);
+    chat_box_free(state);
 
 
 err_alloc_cb:
 err_alloc_cb:
-	byte_input_free(state->hex_key_input);
+    byte_input_free(state->hex_key_input);
 
 
 err_alloc_hki:
 err_alloc_hki:
-	text_input_free(state->text_input);
+    text_input_free(state->text_input);
 
 
 err_alloc_ti:
 err_alloc_ti:
-	menu_free(state->menu);
+    menu_free(state->menu);
 
 
 err_alloc_menu:
 err_alloc_menu:
-	helper_strings_free(state);
+    helper_strings_free(state);
 
 
 err_alloc_hs:
 err_alloc_hs:
-	view_dispatcher_free(state->view_dispatcher);
+    view_dispatcher_free(state->view_dispatcher);
 
 
 err_alloc_vd:
 err_alloc_vd:
-	scene_manager_free(state->scene_manager);
+    scene_manager_free(state->scene_manager);
 
 
 err_alloc_sm:
 err_alloc_sm:
-	free(state);
+    free(state);
 
 
 err_alloc:
 err_alloc:
-	if (err != 0) {
-		FURI_LOG_E(APPLICATION_NAME, "Failed to launch (alloc error)!");
-	} else {
-		FURI_LOG_I(APPLICATION_NAME, "Clean exit.");
-	}
+    if(err != 0) {
+        FURI_LOG_E(APPLICATION_NAME, "Failed to launch (alloc error)!");
+    } else {
+        FURI_LOG_I(APPLICATION_NAME, "Clean exit.");
+    }
 
 
-	return err;
+    return err;
 }
 }

+ 76 - 82
apps_broken_by_last_refactors/esubghz_chat/esubghz_chat_i.h

@@ -11,7 +11,6 @@
 #include <gui/modules/text_box.h>
 #include <gui/modules/text_box.h>
 #include <gui/modules/text_input.h>
 #include <gui/modules/text_input.h>
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
-#include <lib/nfc/nfc_worker.h>
 #include <lib/subghz/subghz_tx_rx_worker.h>
 #include <lib/subghz/subghz_tx_rx_worker.h>
 #include <toolbox/sha256.h>
 #include <toolbox/sha256.h>
 
 
@@ -35,92 +34,87 @@
 #define KEY_HEX_STR_SIZE ((KEY_BITS / 8) * 3)
 #define KEY_HEX_STR_SIZE ((KEY_BITS / 8) * 3)
 
 
 typedef struct {
 typedef struct {
-	SceneManager *scene_manager;
-	ViewDispatcher *view_dispatcher;
-	NotificationApp *notification;
-
-	// UI elements
-	Menu *menu;
-	TextBox *chat_box;
-	FuriString *chat_box_store;
-	TextInput *text_input;
-	char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
-	ByteInput *hex_key_input;
-	uint8_t hex_key_input_store[KEY_BITS / 8];
-	DialogEx *key_display;
-	char key_hex_str[KEY_HEX_STR_SIZE + 1];
-	Popup *nfc_popup;
-
-	// for Sub-GHz
-	uint32_t frequency;
-	SubGhzTxRxWorker *subghz_worker;
-	const SubGhzDevice *subghz_device;
-
-	// for NFC
-	NfcWorker *nfc_worker;
-	NfcDeviceData *nfc_dev_data;
-
-	// message assembly before TX
-	FuriString *name_prefix;
-	FuriString *msg_input;
-
-	// message preview
-	char msg_preview[MSG_PREVIEW_SIZE + 1];
-
-	// encryption
-	bool encrypted;
-	ESubGhzChatCryptoCtx *crypto_ctx;
-
-	// RX and TX buffers
-	uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
-	uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
-	char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
-	volatile uint32_t last_time_rx_data;
-
-	// for locking
-	ViewPortDrawCallback orig_draw_cb;
-	ViewPortInputCallback orig_input_cb;
-	bool kbd_locked;
-	uint32_t kbd_lock_msg_ticks;
-	uint8_t kbd_lock_count;
-
-	// for ongoing inputs
-	bool kbd_ok_input_ongoing;
-	bool kbd_left_input_ongoing;
-	bool kbd_right_input_ongoing;
-
-	// for background support
-	bool exit_for_real;
+    SceneManager* scene_manager;
+    ViewDispatcher* view_dispatcher;
+    NotificationApp* notification;
+
+    // UI elements
+    Menu* menu;
+    TextBox* chat_box;
+    FuriString* chat_box_store;
+    TextInput* text_input;
+    char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
+    ByteInput* hex_key_input;
+    uint8_t hex_key_input_store[KEY_BITS / 8];
+    DialogEx* key_display;
+    char key_hex_str[KEY_HEX_STR_SIZE + 1];
+    Popup* nfc_popup;
+
+    // for Sub-GHz
+    uint32_t frequency;
+    SubGhzTxRxWorker* subghz_worker;
+    const SubGhzDevice* subghz_device;
+
+    // message assembly before TX
+    FuriString* name_prefix;
+    FuriString* msg_input;
+
+    // message preview
+    char msg_preview[MSG_PREVIEW_SIZE + 1];
+
+    // encryption
+    bool encrypted;
+    ESubGhzChatCryptoCtx* crypto_ctx;
+
+    // RX and TX buffers
+    uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
+    uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
+    char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
+    volatile uint32_t last_time_rx_data;
+
+    // for locking
+    ViewPortDrawCallback orig_draw_cb;
+    ViewPortInputCallback orig_input_cb;
+    bool kbd_locked;
+    uint32_t kbd_lock_msg_ticks;
+    uint8_t kbd_lock_count;
+
+    // for ongoing inputs
+    bool kbd_ok_input_ongoing;
+    bool kbd_left_input_ongoing;
+    bool kbd_right_input_ongoing;
+
+    // for background support
+    bool exit_for_real;
 } ESubGhzChatState;
 } ESubGhzChatState;
 
 
 typedef enum {
 typedef enum {
-	ESubGhzChatEvent_FreqEntered,
-	ESubGhzChatEvent_KeyMenuNoEncryption,
-	ESubGhzChatEvent_KeyMenuPassword,
-	ESubGhzChatEvent_KeyMenuHexKey,
-	ESubGhzChatEvent_KeyMenuGenKey,
-	ESubGhzChatEvent_KeyMenuReadKeyFromNfc,
-	ESubGhzChatEvent_KeyReadPopupFailed,
-	ESubGhzChatEvent_KeyReadPopupSucceeded,
-	ESubGhzChatEvent_PassEntered,
-	ESubGhzChatEvent_HexKeyEntered,
-	ESubGhzChatEvent_MsgEntered,
-	ESubGhzChatEvent_GotoMsgInput,
-	ESubGhzChatEvent_GotoKeyDisplay,
-	ESubGhzChatEvent_KeyDisplayBack,
-	ESubGhzChatEvent_KeyDisplayShare,
+    ESubGhzChatEvent_FreqEntered,
+    ESubGhzChatEvent_KeyMenuNoEncryption,
+    ESubGhzChatEvent_KeyMenuPassword,
+    ESubGhzChatEvent_KeyMenuHexKey,
+    ESubGhzChatEvent_KeyMenuGenKey,
+    ESubGhzChatEvent_KeyReadPopupFailed,
+    ESubGhzChatEvent_KeyReadPopupSucceeded,
+    ESubGhzChatEvent_PassEntered,
+    ESubGhzChatEvent_HexKeyEntered,
+    ESubGhzChatEvent_MsgEntered,
+    ESubGhzChatEvent_GotoMsgInput,
+    ESubGhzChatEvent_GotoKeyDisplay,
+    ESubGhzChatEvent_KeyDisplayBack,
+    ESubGhzChatEvent_KeyDisplayShare,
 } ESubGhzChatEvent;
 } ESubGhzChatEvent;
 
 
 typedef enum {
 typedef enum {
-	ESubGhzChatView_Menu,
-	ESubGhzChatView_Input,
-	ESubGhzChatView_HexKeyInput,
-	ESubGhzChatView_ChatBox,
-	ESubGhzChatView_KeyDisplay,
-	ESubGhzChatView_NfcPopup,
+    ESubGhzChatView_Menu,
+    ESubGhzChatView_Input,
+    ESubGhzChatView_HexKeyInput,
+    ESubGhzChatView_ChatBox,
+    ESubGhzChatView_KeyDisplay,
+    ESubGhzChatView_NfcPopup,
 } ESubGhzChatView;
 } ESubGhzChatView;
 
 
-void set_chat_input_header(ESubGhzChatState *state);
-void append_msg(ESubGhzChatState *state, const char *msg);
-void tx_msg_input(ESubGhzChatState *state);
-void enter_chat(ESubGhzChatState *state);
+void set_chat_input_header(ESubGhzChatState* state);
+void append_msg(ESubGhzChatState* state, const char* msg);
+void tx_msg_input(ESubGhzChatState* state);
+void enter_chat(ESubGhzChatState* state);

+ 128 - 116
apps_broken_by_last_refactors/esubghz_chat/scenes/esubghz_chat_key_display.c

@@ -1,130 +1,142 @@
 #include "../esubghz_chat_i.h"
 #include "../esubghz_chat_i.h"
 
 
-void key_display_result_cb(DialogExResult result, void* context)
-{
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	switch(result) {
-	case DialogExResultLeft:
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyDisplayBack);
-		break;
-
-	case DialogExResultCenter:
-		if (state->encrypted) {
-			view_dispatcher_send_custom_event(state->view_dispatcher,
-					ESubGhzChatEvent_KeyDisplayShare);
-		}
-		break;
-
-	default:
-		break;
-	}
+void key_display_result_cb(DialogExResult result, void* context) {
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+
+    switch(result) {
+    case DialogExResultLeft:
+        view_dispatcher_send_custom_event(state->view_dispatcher, ESubGhzChatEvent_KeyDisplayBack);
+        break;
+
+    case DialogExResultCenter:
+        if(state->encrypted) {
+            view_dispatcher_send_custom_event(
+                state->view_dispatcher, ESubGhzChatEvent_KeyDisplayShare);
+        }
+        break;
+
+    default:
+        break;
+    }
 }
 }
 
 
 /* Prepares the key display scene. */
 /* Prepares the key display scene. */
-void scene_on_enter_key_display(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_display");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	if (state->encrypted) {
-		uint8_t key[KEY_BITS / 8];
-		crypto_ctx_get_key(state->crypto_ctx, key);
-		snprintf(state->key_hex_str, KEY_HEX_STR_SIZE,
-				"%02hX%02hX%02hX%02hX"
-				"%02hX%02hX%02hX%02hX\n"
-				"%02hX%02hX%02hX%02hX"
-				"%02hX%02hX%02hX%02hX\n"
-				"%02hX%02hX%02hX%02hX"
-				"%02hX%02hX%02hX%02hX\n"
-				"%02hX%02hX%02hX%02hX"
-				"%02hX%02hX%02hX%02hX",
-				key[0], key[1], key[2], key[3],
-				key[4], key[5], key[6], key[7],
-				key[8], key[9], key[10], key[11],
-				key[12], key[13], key[14], key[15],
-				key[16], key[17], key[18], key[19],
-				key[20], key[21], key[22], key[23],
-				key[24], key[25], key[26], key[27],
-				key[28], key[29], key[30], key[31]);
-		crypto_explicit_bzero(key, sizeof(key));
-	} else {
-		strcpy(state->key_hex_str, "No Key");
-	}
-
-	dialog_ex_reset(state->key_display);
-
-	dialog_ex_set_text(state->key_display, state->key_hex_str, 64, 2,
-			AlignCenter, AlignTop);
-
-	dialog_ex_set_icon(state->key_display, 0, 0, NULL);
-
-	dialog_ex_set_left_button_text(state->key_display, "Back");
-
-	if (state->encrypted) {
-		dialog_ex_set_center_button_text(state->key_display, "Share");
-	}
-
-	dialog_ex_set_result_callback(state->key_display,
-			key_display_result_cb);
-	dialog_ex_set_context(state->key_display, state);
-
-	view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_KeyDisplay);
+void scene_on_enter_key_display(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_display");
+
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+
+    if(state->encrypted) {
+        uint8_t key[KEY_BITS / 8];
+        crypto_ctx_get_key(state->crypto_ctx, key);
+        snprintf(
+            state->key_hex_str,
+            KEY_HEX_STR_SIZE,
+            "%02hX%02hX%02hX%02hX"
+            "%02hX%02hX%02hX%02hX\n"
+            "%02hX%02hX%02hX%02hX"
+            "%02hX%02hX%02hX%02hX\n"
+            "%02hX%02hX%02hX%02hX"
+            "%02hX%02hX%02hX%02hX\n"
+            "%02hX%02hX%02hX%02hX"
+            "%02hX%02hX%02hX%02hX",
+            key[0],
+            key[1],
+            key[2],
+            key[3],
+            key[4],
+            key[5],
+            key[6],
+            key[7],
+            key[8],
+            key[9],
+            key[10],
+            key[11],
+            key[12],
+            key[13],
+            key[14],
+            key[15],
+            key[16],
+            key[17],
+            key[18],
+            key[19],
+            key[20],
+            key[21],
+            key[22],
+            key[23],
+            key[24],
+            key[25],
+            key[26],
+            key[27],
+            key[28],
+            key[29],
+            key[30],
+            key[31]);
+        crypto_explicit_bzero(key, sizeof(key));
+    } else {
+        strcpy(state->key_hex_str, "No Key");
+    }
+
+    dialog_ex_reset(state->key_display);
+
+    dialog_ex_set_text(state->key_display, state->key_hex_str, 64, 2, AlignCenter, AlignTop);
+
+    dialog_ex_set_icon(state->key_display, 0, 0, NULL);
+
+    dialog_ex_set_left_button_text(state->key_display, "Back");
+
+    if(state->encrypted) {
+        // No way to share, NFC part is removed for now
+        //dialog_ex_set_center_button_text(state->key_display, "Share");
+    }
+
+    dialog_ex_set_result_callback(state->key_display, key_display_result_cb);
+    dialog_ex_set_context(state->key_display, state);
+
+    view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_KeyDisplay);
 }
 }
 
 
 /* Handles scene manager events for the key display scene. */
 /* Handles scene manager events for the key display scene. */
-bool scene_on_event_key_display(void* context, SceneManagerEvent event)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_display");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	bool consumed = false;
-
-	switch(event.type) {
-	case SceneManagerEventTypeCustom:
-		switch(event.event) {
-		/* switch to message input scene */
-		case ESubGhzChatEvent_KeyDisplayBack:
-			if (!scene_manager_previous_scene(
-						state->scene_manager)) {
-				/* error condition, exit for real */
-				state->exit_for_real = true;
-				view_dispatcher_stop(state->view_dispatcher);
-			}
-			consumed = true;
-			break;
-
-		/* open key sharing popup */
-		case ESubGhzChatEvent_KeyDisplayShare:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_KeySharePopup);
-			consumed = true;
-			break;
-		}
-		break;
-
-	default:
-		consumed = false;
-		break;
-	}
-
-	return consumed;
+bool scene_on_event_key_display(void* context, SceneManagerEvent event) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_display");
+
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+
+    bool consumed = false;
+
+    switch(event.type) {
+    case SceneManagerEventTypeCustom:
+        switch(event.event) {
+        /* switch to message input scene */
+        case ESubGhzChatEvent_KeyDisplayBack:
+            if(!scene_manager_previous_scene(state->scene_manager)) {
+                /* error condition, exit for real */
+                state->exit_for_real = true;
+                view_dispatcher_stop(state->view_dispatcher);
+            }
+            consumed = true;
+            break;
+        }
+        break;
+
+    default:
+        consumed = false;
+        break;
+    }
+
+    return consumed;
 }
 }
 
 
 /* Cleans up the key display scene. */
 /* Cleans up the key display scene. */
-void scene_on_exit_key_display(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_display");
+void scene_on_exit_key_display(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_display");
 
 
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	dialog_ex_reset(state->key_display);
-	crypto_explicit_bzero(state->key_hex_str, sizeof(state->key_hex_str));
+    dialog_ex_reset(state->key_display);
+    crypto_explicit_bzero(state->key_hex_str, sizeof(state->key_hex_str));
 }
 }

+ 122 - 163
apps_broken_by_last_refactors/esubghz_chat/scenes/esubghz_chat_key_menu.c

@@ -1,196 +1,155 @@
 #include "../esubghz_chat_i.h"
 #include "../esubghz_chat_i.h"
 
 
 typedef enum {
 typedef enum {
-	ESubGhzChatKeyMenuItems_NoEncryption,
-	ESubGhzChatKeyMenuItems_Password,
-	ESubGhzChatKeyMenuItems_HexKey,
-	ESubGhzChatKeyMenuItems_GenKey,
-	ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
+    ESubGhzChatKeyMenuItems_NoEncryption,
+    ESubGhzChatKeyMenuItems_Password,
+    ESubGhzChatKeyMenuItems_HexKey,
+    ESubGhzChatKeyMenuItems_GenKey,
 } ESubGhzChatKeyMenuItems;
 } ESubGhzChatKeyMenuItems;
 
 
-static void key_menu_cb(void* context, uint32_t index)
-{
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+static void key_menu_cb(void* context, uint32_t index) {
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	uint8_t key[KEY_BITS / 8];
+    uint8_t key[KEY_BITS / 8];
 
 
-	switch(index) {
-	case ESubGhzChatKeyMenuItems_NoEncryption:
-		state->encrypted = false;
+    switch(index) {
+    case ESubGhzChatKeyMenuItems_NoEncryption:
+        state->encrypted = false;
 
 
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyMenuNoEncryption);
-		break;
+        view_dispatcher_send_custom_event(
+            state->view_dispatcher, ESubGhzChatEvent_KeyMenuNoEncryption);
+        break;
 
 
-	case ESubGhzChatKeyMenuItems_Password:
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyMenuPassword);
-		break;
+    case ESubGhzChatKeyMenuItems_Password:
+        view_dispatcher_send_custom_event(
+            state->view_dispatcher, ESubGhzChatEvent_KeyMenuPassword);
+        break;
 
 
-	case ESubGhzChatKeyMenuItems_HexKey:
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyMenuHexKey);
-		break;
+    case ESubGhzChatKeyMenuItems_HexKey:
+        view_dispatcher_send_custom_event(state->view_dispatcher, ESubGhzChatEvent_KeyMenuHexKey);
+        break;
 
 
-	case ESubGhzChatKeyMenuItems_GenKey:
-		/* generate a random key */
-		furi_hal_random_fill_buf(key, KEY_BITS / 8);
+    case ESubGhzChatKeyMenuItems_GenKey:
+        /* generate a random key */
+        furi_hal_random_fill_buf(key, KEY_BITS / 8);
 
 
-		/* initiate the crypto context */
-		bool ret = crypto_ctx_set_key(state->crypto_ctx, key,
-				state->name_prefix, furi_get_tick());
+        /* initiate the crypto context */
+        bool ret = crypto_ctx_set_key(state->crypto_ctx, key, state->name_prefix, furi_get_tick());
 
 
-		/* cleanup */
-		crypto_explicit_bzero(key, sizeof(key));
+        /* cleanup */
+        crypto_explicit_bzero(key, sizeof(key));
 
 
-		if (!ret) {
-			crypto_ctx_clear(state->crypto_ctx);
-			return;
-		}
+        if(!ret) {
+            crypto_ctx_clear(state->crypto_ctx);
+            return;
+        }
 
 
-		/* set encrypted flag and enter the chat */
-		state->encrypted = true;
+        /* set encrypted flag and enter the chat */
+        state->encrypted = true;
 
 
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyMenuGenKey);
-		break;
+        view_dispatcher_send_custom_event(state->view_dispatcher, ESubGhzChatEvent_KeyMenuGenKey);
+        break;
 
 
-	case ESubGhzChatKeyMenuItems_ReadKeyFromNfc:
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyMenuReadKeyFromNfc);
-		break;
-
-	default:
-		break;
-	}
+    default:
+        break;
+    }
 }
 }
 
 
 /* Prepares the key menu scene. */
 /* Prepares the key menu scene. */
-void scene_on_enter_key_menu(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_menu");
+void scene_on_enter_key_menu(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_menu");
 
 
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	menu_reset(state->menu);
+    menu_reset(state->menu);
 
 
-	/* clear the crypto CTX in case we got back from password or hex key
+    /* clear the crypto CTX in case we got back from password or hex key
 	 * input */
 	 * input */
-	crypto_ctx_clear(state->crypto_ctx);
-
-	menu_add_item(
-		state->menu,
-		"No encryption",
-		&I_chat_14px,
-		ESubGhzChatKeyMenuItems_NoEncryption,
-		key_menu_cb,
-		state
-	);
-	menu_add_item(
-		state->menu,
-		"Password",
-		&I_keyboard_14px,
-		ESubGhzChatKeyMenuItems_Password,
-		key_menu_cb,
-		state
-	);
-	menu_add_item(
-		state->menu,
-		"Hex Key",
-		&I_hex_14px,
-		ESubGhzChatKeyMenuItems_HexKey,
-		key_menu_cb,
-		state
-	);
-	menu_add_item(
-		state->menu,
-		"Generate Key",
-		&I_u2f_14px,
-		ESubGhzChatKeyMenuItems_GenKey,
-		key_menu_cb,
-		state
-	);
-	menu_add_item(
-		state->menu,
-		"Read Key from NFC",
-		&I_Nfc_14px,
-		ESubGhzChatKeyMenuItems_ReadKeyFromNfc,
-		key_menu_cb,
-		state
-	);
-
-	view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
+    crypto_ctx_clear(state->crypto_ctx);
+
+    menu_add_item(
+        state->menu,
+        "No encryption",
+        &I_chat_14px,
+        ESubGhzChatKeyMenuItems_NoEncryption,
+        key_menu_cb,
+        state);
+    menu_add_item(
+        state->menu,
+        "Password",
+        &I_keyboard_14px,
+        ESubGhzChatKeyMenuItems_Password,
+        key_menu_cb,
+        state);
+    menu_add_item(
+        state->menu, "Hex Key", &I_hex_14px, ESubGhzChatKeyMenuItems_HexKey, key_menu_cb, state);
+    menu_add_item(
+        state->menu,
+        "Generate Key",
+        &I_u2f_14px,
+        ESubGhzChatKeyMenuItems_GenKey,
+        key_menu_cb,
+        state);
+
+    view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
 }
 }
 
 
 /* Handles scene manager events for the key menu scene. */
 /* Handles scene manager events for the key menu scene. */
-bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_menu");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	bool consumed = false;
-
-	switch(event.type) {
-	case SceneManagerEventTypeCustom:
-		switch(event.event) {
-		/* switch to frequency input scene */
-		case ESubGhzChatEvent_KeyMenuNoEncryption:
-		case ESubGhzChatEvent_KeyMenuGenKey:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_FreqInput);
-			consumed = true;
-			break;
-
-		/* switch to password input scene */
-		case ESubGhzChatEvent_KeyMenuPassword:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_PassInput);
-			consumed = true;
-			break;
-
-		/* switch to hex key input scene */
-		case ESubGhzChatEvent_KeyMenuHexKey:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_HexKeyInput);
-			consumed = true;
-			break;
-
-		/* switch to hex key read scene */
-		case ESubGhzChatEvent_KeyMenuReadKeyFromNfc:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_KeyReadPopup);
-			consumed = true;
-			break;
-		}
-
-		break;
-
-	case SceneManagerEventTypeBack:
-		/* stop the application if the user presses back here */
-		view_dispatcher_stop(state->view_dispatcher);
-		consumed = true;
-		break;
-
-	default:
-		consumed = false;
-		break;
-	}
-
-	return consumed;
+bool scene_on_event_key_menu(void* context, SceneManagerEvent event) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_menu");
+
+    furi_assert(context);
+    ESubGhzChatState* state = context;
+
+    bool consumed = false;
+
+    switch(event.type) {
+    case SceneManagerEventTypeCustom:
+        switch(event.event) {
+        /* switch to frequency input scene */
+        case ESubGhzChatEvent_KeyMenuNoEncryption:
+        case ESubGhzChatEvent_KeyMenuGenKey:
+            scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_FreqInput);
+            consumed = true;
+            break;
+
+        /* switch to password input scene */
+        case ESubGhzChatEvent_KeyMenuPassword:
+            scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_PassInput);
+            consumed = true;
+            break;
+
+        /* switch to hex key input scene */
+        case ESubGhzChatEvent_KeyMenuHexKey:
+            scene_manager_next_scene(state->scene_manager, ESubGhzChatScene_HexKeyInput);
+            consumed = true;
+            break;
+        }
+
+        break;
+
+    case SceneManagerEventTypeBack:
+        /* stop the application if the user presses back here */
+        view_dispatcher_stop(state->view_dispatcher);
+        consumed = true;
+        break;
+
+    default:
+        consumed = false;
+        break;
+    }
+
+    return consumed;
 }
 }
 
 
 /* Cleans up the key menu scene. */
 /* Cleans up the key menu scene. */
-void scene_on_exit_key_menu(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_menu");
+void scene_on_exit_key_menu(void* context) {
+    FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_menu");
 
 
-	furi_assert(context);
-	ESubGhzChatState* state = context;
+    furi_assert(context);
+    ESubGhzChatState* state = context;
 
 
-	menu_reset(state->menu);
+    menu_reset(state->menu);
 }
 }
-

+ 0 - 303
apps_broken_by_last_refactors/esubghz_chat/scenes/esubghz_chat_key_read_popup.c

@@ -1,303 +0,0 @@
-#include "../esubghz_chat_i.h"
-#include "../helpers/nfc_helpers.h"
-
-typedef enum {
-	KeyReadPopupState_Idle,
-	KeyReadPopupState_Detecting,
-	KeyReadPopupState_Reading,
-	KeyReadPopupState_Fail,
-	KeyReadPopupState_Success,
-} KeyReadPopupState;
-
-static bool read_worker_cb(NfcWorkerEvent event, void* context)
-{
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	view_dispatcher_send_custom_event(state->view_dispatcher, event);
-
-	return true;
-}
-
-static void key_read_popup_timeout_cb(void* context)
-{
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	uint32_t cur_state = scene_manager_get_scene_state(
-			state->scene_manager, ESubGhzChatScene_KeyReadPopup);
-
-	/* done displaying our failure */
-	if (cur_state == KeyReadPopupState_Fail) {
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyReadPopupFailed);
-	/* done displaying our success */
-	} else if (cur_state == KeyReadPopupState_Success) {
-		view_dispatcher_send_custom_event(state->view_dispatcher,
-				ESubGhzChatEvent_KeyReadPopupSucceeded);
-	}
-}
-
-struct ReplayDictNfcReaderContext {
-	uint8_t *cur;
-	uint8_t *max;
-};
-
-static bool replay_dict_nfc_reader(uint64_t *run_id, uint32_t *counter, void
-		*context)
-{
-	struct ReplayDictNfcReaderContext *ctx = (struct
-			ReplayDictNfcReaderContext *) context;
-
-	if (ctx->cur + sizeof(struct ReplayDictNfcEntry) > ctx->max) {
-		return false;
-	}
-
-	struct ReplayDictNfcEntry *entry = (struct ReplayDictNfcEntry *)
-		ctx->cur;
-	*run_id = entry->run_id;
-	*counter = __ntohl(entry->counter);
-
-	ctx->cur += sizeof(struct ReplayDictNfcEntry);
-
-	return true;
-}
-
-static bool key_read_popup_handle_key_read(ESubGhzChatState *state)
-{
-	NfcDeviceData *dev_data = state->nfc_dev_data;
-
-	/* check for config pages */
-	if (dev_data->mf_ul_data.data_read < NFC_CONFIG_PAGES * 4) {
-		return false;
-	}
-
-	size_t data_read = dev_data->mf_ul_data.data_read - (NFC_CONFIG_PAGES *
-			4);
-
-	/* check if key was transmitted */
-	if (data_read < KEY_BITS / 8) {
-		return false;
-	}
-
-	/* initiate the crypto context */
-	bool ret = crypto_ctx_set_key(state->crypto_ctx,
-			dev_data->mf_ul_data.data, state->name_prefix,
-			furi_get_tick());
-
-	/* cleanup */
-	crypto_explicit_bzero(dev_data->mf_ul_data.data, KEY_BITS / 8);
-
-	if (!ret) {
-		crypto_ctx_clear(state->crypto_ctx);
-		return false;
-	}
-
-	/* read the frequency */
-	if (data_read >= (KEY_BITS / 8) + sizeof(struct FreqNfcEntry)) {
-		struct FreqNfcEntry *freq_entry = (struct FreqNfcEntry *)
-			(dev_data->mf_ul_data.data + (KEY_BITS / 8));
-		state->frequency = __ntohl(freq_entry->frequency);
-	}
-
-	/* read the replay dict */
-	struct ReplayDictNfcReaderContext rd_ctx = {
-		.cur = dev_data->mf_ul_data.data + (KEY_BITS / 8) +
-			sizeof(struct FreqNfcEntry),
-		.max = dev_data->mf_ul_data.data + (data_read < NFC_MAX_BYTES ?
-				data_read : NFC_MAX_BYTES)
-	};
-
-	crypto_ctx_read_replay_dict(state->crypto_ctx, replay_dict_nfc_reader,
-			&rd_ctx);
-
-	/* set encrypted flag */
-	state->encrypted = true;
-
-	return true;
-}
-
-static void key_read_popup_set_state(ESubGhzChatState *state, KeyReadPopupState
-		new_state)
-{
-	uint32_t cur_state = scene_manager_get_scene_state(
-			state->scene_manager, ESubGhzChatScene_KeyReadPopup);
-	if (cur_state == new_state) {
-		return;
-	}
-
-	if (new_state == KeyReadPopupState_Detecting) {
-		popup_reset(state->nfc_popup);
-		popup_disable_timeout(state->nfc_popup);
-		popup_set_text(state->nfc_popup, "Tap Flipper\n to sender", 97,
-				24, AlignCenter, AlignTop);
-		popup_set_icon(state->nfc_popup, 0, 8, &I_NFC_manual_60x50);
-		notification_message(state->notification,
-				&sequence_blink_start_cyan);
-	} else if (new_state == KeyReadPopupState_Reading) {
-		popup_reset(state->nfc_popup);
-		popup_disable_timeout(state->nfc_popup);
-		popup_set_header(state->nfc_popup, "Reading key\nDon't "
-				"move...", 85, 24, AlignCenter, AlignTop);
-		popup_set_icon(state->nfc_popup, 12, 23, &I_Loading_24);
-		notification_message(state->notification,
-				&sequence_blink_start_yellow);
-	} else if (new_state == KeyReadPopupState_Fail) {
-		nfc_worker_stop(state->nfc_worker);
-
-		popup_reset(state->nfc_popup);
-		popup_set_header(state->nfc_popup, "Failure!", 64, 2,
-				AlignCenter, AlignTop);
-		popup_set_text(state->nfc_popup, "Failed\nto read\nkey.", 78,
-				16, AlignLeft, AlignTop);
-		popup_set_icon(state->nfc_popup, 21, 13, &I_Cry_dolph_55x52);
-
-		popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
-		popup_set_context(state->nfc_popup, state);
-		popup_set_callback(state->nfc_popup,
-				key_read_popup_timeout_cb);
-		popup_enable_timeout(state->nfc_popup);
-
-		notification_message(state->notification,
-				&sequence_blink_stop);
-	} else if (new_state == KeyReadPopupState_Success) {
-		nfc_worker_stop(state->nfc_worker);
-
-		popup_reset(state->nfc_popup);
-		popup_set_header(state->nfc_popup, "Key\nread!", 13, 22,
-				AlignLeft, AlignBottom);
-		popup_set_icon(state->nfc_popup, 32, 5, &I_DolphinNice_96x59);
-
-		popup_set_timeout(state->nfc_popup, KEY_READ_POPUP_MS);
-		popup_set_context(state->nfc_popup, state);
-		popup_set_callback(state->nfc_popup,
-				key_read_popup_timeout_cb);
-		popup_enable_timeout(state->nfc_popup);
-
-		notification_message(state->notification, &sequence_success);
-		notification_message(state->notification,
-				&sequence_blink_stop);
-	}
-
-	scene_manager_set_scene_state(state->scene_manager,
-			ESubGhzChatScene_KeyReadPopup, new_state);
-
-	view_dispatcher_switch_to_view(state->view_dispatcher,
-			ESubGhzChatView_NfcPopup);
-}
-
-/* Prepares the key share read scene. */
-void scene_on_enter_key_read_popup(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_read_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	key_read_popup_set_state(state, KeyReadPopupState_Detecting);
-
-	state->nfc_dev_data->parsed_data = furi_string_alloc();
-	if (state->nfc_dev_data->parsed_data == NULL) {
-		/* can't do anything here, crash */
-		furi_check(0);
-	}
-
-	nfc_worker_start(state->nfc_worker, NfcWorkerStateRead,
-			state->nfc_dev_data, read_worker_cb, state);
-}
-
-/* Handles scene manager events for the key read popup scene. */
-bool scene_on_event_key_read_popup(void* context, SceneManagerEvent event)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_read_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	bool consumed = false;
-
-	switch(event.type) {
-	case SceneManagerEventTypeCustom:
-		switch(event.event) {
-		/* card detected */
-		case NfcWorkerEventCardDetected:
-			key_read_popup_set_state(state,
-					KeyReadPopupState_Reading);
-			consumed = true;
-			break;
-
-		/* no card detected */
-		case NfcWorkerEventNoCardDetected:
-			key_read_popup_set_state(state,
-					KeyReadPopupState_Detecting);
-			consumed = true;
-			break;
-
-		/* key probably read */
-		case NfcWorkerEventReadMfUltralight:
-			if (key_read_popup_handle_key_read(state)) {
-				key_read_popup_set_state(state,
-						KeyReadPopupState_Success);
-			} else {
-				key_read_popup_set_state(state,
-						KeyReadPopupState_Fail);
-			}
-			consumed = true;
-			break;
-
-		/* close the popup and go back */
-		case ESubGhzChatEvent_KeyReadPopupFailed:
-			if (!scene_manager_previous_scene(
-						state->scene_manager)) {
-				view_dispatcher_stop(state->view_dispatcher);
-			}
-			consumed = true;
-			break;
-
-		/* success, go to frequency input */
-		case ESubGhzChatEvent_KeyReadPopupSucceeded:
-			scene_manager_next_scene(state->scene_manager,
-					ESubGhzChatScene_FreqInput);
-			consumed = true;
-			break;
-
-		/* something else happend, treat as failure */
-		default:
-			key_read_popup_set_state(state,
-					KeyReadPopupState_Fail);
-			consumed = true;
-			break;
-		}
-
-		break;
-
-	default:
-		consumed = false;
-		break;
-	}
-
-	return consumed;
-}
-
-/* Cleans up the key read popup scene. */
-void scene_on_exit_key_read_popup(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_read_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	popup_reset(state->nfc_popup);
-	scene_manager_set_scene_state(state->scene_manager,
-			ESubGhzChatScene_KeyReadPopup, KeyReadPopupState_Idle);
-
-	notification_message(state->notification, &sequence_blink_stop);
-
-	nfc_worker_stop(state->nfc_worker);
-
-	crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
-	if (state->nfc_dev_data->parsed_data != NULL) {
-		furi_string_free(state->nfc_dev_data->parsed_data);
-	}
-	memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
-}

+ 0 - 140
apps_broken_by_last_refactors/esubghz_chat/scenes/esubghz_chat_key_share_popup.c

@@ -1,140 +0,0 @@
-#include "../esubghz_chat_i.h"
-#include "../helpers/nfc_helpers.h"
-
-struct ReplayDictNfcWriterContext {
-	uint8_t *cur;
-	uint8_t *max;
-};
-
-static bool replay_dict_nfc_writer(uint64_t run_id, uint32_t counter, void
-		*context)
-{
-	struct ReplayDictNfcWriterContext *ctx = (struct
-			ReplayDictNfcWriterContext *) context;
-
-	struct ReplayDictNfcEntry entry = {
-		.run_id = run_id,
-		.counter = __htonl(counter),
-		.unused = 0
-	};
-
-	if (ctx->cur + sizeof(entry) > ctx->max) {
-		return false;
-	}
-
-	memcpy(ctx->cur, &entry, sizeof(entry));
-	ctx->cur += sizeof(entry);
-
-	return true;
-}
-
-static void prepare_nfc_dev_data(ESubGhzChatState *state)
-{
-	NfcDeviceData *dev_data = state->nfc_dev_data;
-
-	dev_data->protocol = NfcDeviceProtocolMifareUl;
-	furi_hal_random_fill_buf(dev_data->nfc_data.uid, 7);
-	dev_data->nfc_data.uid_len = 7;
-	dev_data->nfc_data.atqa[0] = 0x44;
-	dev_data->nfc_data.atqa[1] = 0x00;
-	dev_data->nfc_data.sak = 0x00;
-
-	dev_data->mf_ul_data.type = MfUltralightTypeNTAG215;
-	dev_data->mf_ul_data.version.header = 0x00;
-	dev_data->mf_ul_data.version.vendor_id = 0x04;
-	dev_data->mf_ul_data.version.prod_type = 0x04;
-	dev_data->mf_ul_data.version.prod_subtype = 0x02;
-	dev_data->mf_ul_data.version.prod_ver_major = 0x01;
-	dev_data->mf_ul_data.version.prod_ver_minor = 0x00;
-	dev_data->mf_ul_data.version.storage_size = 0x11;
-	dev_data->mf_ul_data.version.protocol_type = 0x03;
-
-	size_t data_written = 0;
-
-	/* write key */
-	crypto_ctx_get_key(state->crypto_ctx, dev_data->mf_ul_data.data);
-	data_written += (KEY_BITS / 8);
-
-	/* write frequency */
-	struct FreqNfcEntry *freq_entry = (struct FreqNfcEntry *)
-		(dev_data->mf_ul_data.data + data_written);
-	freq_entry->frequency = __htonl(state->frequency);
-	freq_entry->unused1 = 0;
-	freq_entry->unused2 = 0;
-	freq_entry->unused3 = 0;
-	data_written += sizeof(struct FreqNfcEntry);
-
-	/* write the replay dict */
-	struct ReplayDictNfcWriterContext wr_ctx = {
-		.cur = dev_data->mf_ul_data.data + data_written,
-		.max = dev_data->mf_ul_data.data + NFC_MAX_BYTES
-	};
-
-	size_t n_entries = crypto_ctx_dump_replay_dict(state->crypto_ctx,
-			replay_dict_nfc_writer, &wr_ctx);
-	data_written += n_entries * sizeof(struct ReplayDictNfcEntry);
-
-	/* calculate size of data, add 16 for config pages */
-	dev_data->mf_ul_data.data_size = data_written + (NFC_CONFIG_PAGES * 4);
-}
-
-/* Prepares the key share popup scene. */
-void scene_on_enter_key_share_popup(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_share_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	popup_reset(state->nfc_popup);
-
-	popup_disable_timeout(state->nfc_popup);
-
-	popup_set_header(state->nfc_popup, "Sharing...", 67, 13, AlignLeft,
-			AlignTop);
-	popup_set_icon(state->nfc_popup, 0, 3, &I_NFC_dolphin_emulation_47x61);
-	popup_set_text(state->nfc_popup, "Sharing\nKey via\nNFC", 90, 28,
-			AlignCenter, AlignTop);
-
-	prepare_nfc_dev_data(state);
-	nfc_worker_start(state->nfc_worker, NfcWorkerStateMfUltralightEmulate,
-			state->nfc_dev_data, NULL, NULL);
-
-	notification_message(state->notification,
-			&sequence_blink_start_magenta);
-
-	view_dispatcher_switch_to_view(state->view_dispatcher,
-			ESubGhzChatView_NfcPopup);
-}
-
-/* Handles scene manager events for the key share popup scene. */
-bool scene_on_event_key_share_popup(void* context, SceneManagerEvent event)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_share_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	UNUSED(state);
-	UNUSED(event);
-
-	return false;
-}
-
-/* Cleans up the key share popup scene. */
-void scene_on_exit_key_share_popup(void* context)
-{
-	FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_share_popup");
-
-	furi_assert(context);
-	ESubGhzChatState* state = context;
-
-	popup_reset(state->nfc_popup);
-
-	notification_message(state->notification, &sequence_blink_stop);
-
-	nfc_worker_stop(state->nfc_worker);
-
-	crypto_explicit_bzero(state->nfc_dev_data->mf_ul_data.data, KEY_BITS / 8);
-	memset(state->nfc_dev_data, 0, sizeof(NfcDeviceData));
-}

+ 0 - 2
apps_broken_by_last_refactors/esubghz_chat/scenes/esubghz_chat_scene_config.h

@@ -2,8 +2,6 @@ ADD_SCENE(esubghz_chat, freq_input, FreqInput)
 ADD_SCENE(esubghz_chat, key_menu, KeyMenu)
 ADD_SCENE(esubghz_chat, key_menu, KeyMenu)
 ADD_SCENE(esubghz_chat, pass_input, PassInput)
 ADD_SCENE(esubghz_chat, pass_input, PassInput)
 ADD_SCENE(esubghz_chat, hex_key_input, HexKeyInput)
 ADD_SCENE(esubghz_chat, hex_key_input, HexKeyInput)
-ADD_SCENE(esubghz_chat, key_read_popup, KeyReadPopup)
 ADD_SCENE(esubghz_chat, chat_input, ChatInput)
 ADD_SCENE(esubghz_chat, chat_input, ChatInput)
 ADD_SCENE(esubghz_chat, chat_box, ChatBox)
 ADD_SCENE(esubghz_chat, chat_box, ChatBox)
 ADD_SCENE(esubghz_chat, key_display, KeyDisplay)
 ADD_SCENE(esubghz_chat, key_display, KeyDisplay)
-ADD_SCENE(esubghz_chat, key_share_popup, KeySharePopup)