esubghz_chat_i.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include <furi.h>
  3. #include "ui_hacks_for_no_reason/view_dispatcher_i.h"
  4. #include "ui_hacks_for_no_reason/view_port_i.h"
  5. #include <gui/scene_manager.h>
  6. #include <gui/modules/byte_input.h>
  7. #include <gui/modules/dialog_ex.h>
  8. #include <gui/modules/menu.h>
  9. #include <gui/modules/popup.h>
  10. #include <gui/modules/text_box.h>
  11. #include <gui/modules/text_input.h>
  12. #include <notification/notification_messages.h>
  13. #include <lib/subghz/subghz_tx_rx_worker.h>
  14. #include <mbedtls/sha256.h>
  15. #include "crypto_wrapper.h"
  16. #include "scenes/esubghz_chat_scene.h"
  17. #include "esubghz_chat_icons.h"
  18. #include <lib/nfclegacy/nfc_worker.h>
  19. #define APPLICATION_NAME "ESubGhzChat"
  20. #define DEFAULT_FREQ 433920000
  21. #define KEY_READ_POPUP_MS 3000
  22. #define RX_TX_BUFFER_SIZE 1024
  23. #define CHAT_BOX_STORE_SIZE 4096
  24. #define TEXT_INPUT_STORE_SIZE 256
  25. #define MSG_PREVIEW_SIZE 32
  26. #define KEY_HEX_STR_SIZE ((KEY_BITS / 8) * 3)
  27. typedef struct {
  28. SceneManager* scene_manager;
  29. ViewDispatcher* view_dispatcher;
  30. NotificationApp* notification;
  31. // UI elements
  32. Menu* menu;
  33. TextBox* chat_box;
  34. FuriString* chat_box_store;
  35. TextInput* text_input;
  36. char text_input_store[TEXT_INPUT_STORE_SIZE + 1];
  37. ByteInput* hex_key_input;
  38. uint8_t hex_key_input_store[KEY_BITS / 8];
  39. DialogEx* key_display;
  40. char key_hex_str[KEY_HEX_STR_SIZE + 1];
  41. Popup* nfc_popup;
  42. // for Sub-GHz
  43. uint32_t frequency;
  44. SubGhzTxRxWorker* subghz_worker;
  45. const SubGhzDevice* subghz_device;
  46. // for NFC
  47. NfcWorker* nfc_worker;
  48. NfcDeviceData* nfc_dev_data;
  49. // message assembly before TX
  50. FuriString* name_prefix;
  51. FuriString* msg_input;
  52. // message preview
  53. char msg_preview[MSG_PREVIEW_SIZE + 1];
  54. // encryption
  55. bool encrypted;
  56. ESubGhzChatCryptoCtx* crypto_ctx;
  57. // RX and TX buffers
  58. uint8_t rx_buffer[RX_TX_BUFFER_SIZE];
  59. uint8_t tx_buffer[RX_TX_BUFFER_SIZE];
  60. char rx_str_buffer[RX_TX_BUFFER_SIZE + 1];
  61. volatile uint32_t last_time_rx_data;
  62. // for locking
  63. ViewPortDrawCallback orig_draw_cb;
  64. ViewPortInputCallback orig_input_cb;
  65. bool kbd_locked;
  66. uint32_t kbd_lock_msg_ticks;
  67. uint8_t kbd_lock_count;
  68. // for ongoing inputs
  69. bool kbd_ok_input_ongoing;
  70. bool kbd_left_input_ongoing;
  71. bool kbd_right_input_ongoing;
  72. // for background support
  73. bool exit_for_real;
  74. } ESubGhzChatState;
  75. typedef enum {
  76. ESubGhzChatEvent_FreqEntered,
  77. ESubGhzChatEvent_KeyMenuNoEncryption,
  78. ESubGhzChatEvent_KeyMenuPassword,
  79. ESubGhzChatEvent_KeyMenuHexKey,
  80. ESubGhzChatEvent_KeyMenuGenKey,
  81. ESubGhzChatEvent_KeyMenuReadKeyFromNfc,
  82. ESubGhzChatEvent_KeyReadPopupFailed,
  83. ESubGhzChatEvent_KeyReadPopupSucceeded,
  84. ESubGhzChatEvent_PassEntered,
  85. ESubGhzChatEvent_HexKeyEntered,
  86. ESubGhzChatEvent_MsgEntered,
  87. ESubGhzChatEvent_GotoMsgInput,
  88. ESubGhzChatEvent_GotoKeyDisplay,
  89. ESubGhzChatEvent_KeyDisplayBack,
  90. ESubGhzChatEvent_KeyDisplayShare,
  91. } ESubGhzChatEvent;
  92. typedef enum {
  93. ESubGhzChatView_Menu,
  94. ESubGhzChatView_Input,
  95. ESubGhzChatView_HexKeyInput,
  96. ESubGhzChatView_ChatBox,
  97. ESubGhzChatView_KeyDisplay,
  98. ESubGhzChatView_NfcPopup,
  99. } ESubGhzChatView;
  100. void set_chat_input_header(ESubGhzChatState* state);
  101. void append_msg(ESubGhzChatState* state, const char* msg);
  102. void tx_msg_input(ESubGhzChatState* state);
  103. void enter_chat(ESubGhzChatState* state);