subbrute_device.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include "subbrute_protocols.h"
  3. #include <lib/subghz/protocols/base.h>
  4. #include <lib/subghz/transmitter.h>
  5. #include <lib/subghz/receiver.h>
  6. #include <lib/subghz/environment.h>
  7. #define SUBBRUTE_TEXT_STORE_SIZE 256
  8. #define SUBBRUTE_MAX_LEN_NAME 64
  9. #define SUBBRUTE_PATH EXT_PATH("subghz")
  10. #define SUBBRUTE_FILE_EXT ".sub"
  11. #define SUBBRUTE_PAYLOAD_SIZE 16
  12. typedef enum {
  13. SubBruteFileResultUnknown,
  14. SubBruteFileResultOk,
  15. SubBruteFileResultErrorOpenFile,
  16. SubBruteFileResultMissingOrIncorrectHeader,
  17. SubBruteFileResultFrequencyNotAllowed,
  18. SubBruteFileResultMissingOrIncorrectFrequency,
  19. SubBruteFileResultPresetInvalid,
  20. SubBruteFileResultMissingProtocol,
  21. SubBruteFileResultProtocolNotSupported,
  22. SubBruteFileResultDynamicProtocolNotValid,
  23. SubBruteFileResultProtocolNotFound,
  24. SubBruteFileResultMissingOrIncorrectBit,
  25. SubBruteFileResultMissingOrIncorrectKey,
  26. SubBruteFileResultMissingOrIncorrectTe,
  27. } SubBruteFileResult;
  28. typedef enum {
  29. SubBruteDeviceStateIDLE,
  30. SubBruteDeviceStateReady,
  31. SubBruteDeviceStateTx,
  32. SubBruteDeviceStateFinished
  33. } SubBruteDeviceState;
  34. typedef void (*SubBruteDeviceWorkerCallback)(void* context, SubBruteDeviceState state);
  35. typedef struct {
  36. SubBruteDeviceState state;
  37. SubBruteProtocol* protocol_info;
  38. volatile bool worker_running;
  39. // Current step
  40. uint64_t key_index;
  41. // Index of group to bruteforce in loaded file
  42. uint8_t load_index;
  43. // SubGhz
  44. FuriThread* thread;
  45. SubGhzReceiver* receiver;
  46. SubGhzProtocolDecoderBase* decoder_result;
  47. SubGhzEnvironment* environment;
  48. SubGhzTransmitter* transmitter;
  49. // Attack state
  50. SubBruteAttacks attack;
  51. char file_template[SUBBRUTE_TEXT_STORE_SIZE];
  52. uint64_t max_value;
  53. // Loaded info for attack type
  54. char current_key[SUBBRUTE_PAYLOAD_SIZE];
  55. char file_key[SUBBRUTE_MAX_LEN_NAME];
  56. // Manual transmit
  57. uint32_t last_time_tx_data;
  58. // Callback for changed states
  59. SubBruteDeviceWorkerCallback callback;
  60. void* context;
  61. } SubBruteDevice;
  62. SubBruteDevice* subbrute_device_alloc();
  63. void subbrute_device_free(SubBruteDevice* instance);
  64. bool subbrute_device_save_file(SubBruteDevice* instance, const char* key_name);
  65. const char* subbrute_device_error_get_desc(SubBruteFileResult error_id);
  66. SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* context, SubBruteAttacks type);
  67. uint8_t subbrute_device_load_from_file(SubBruteDevice* context, const char* file_path);
  68. bool subbrute_device_is_worker_running(SubBruteDevice* instance);
  69. SubBruteAttacks subbrute_device_get_attack(SubBruteDevice* instance);
  70. uint64_t subbrute_device_get_max_value(SubBruteDevice* instance);
  71. uint64_t subbrute_device_get_step(SubBruteDevice* instance);
  72. uint64_t subbrute_device_add_step(SubBruteDevice* instance, int8_t step);
  73. void subbrute_device_set_load_index(SubBruteDevice* instance, uint64_t load_index);
  74. void subbrute_device_reset_step(SubBruteDevice* instance);
  75. const char* subbrute_device_get_file_key(SubBruteDevice* instance);
  76. bool subbrute_worker_start(SubBruteDevice* instance);
  77. void subbrute_worker_stop(SubBruteDevice* instance);
  78. bool subbrute_device_transmit_current_key(SubBruteDevice* instance);
  79. bool subbrute_device_can_manual_transmit(SubBruteDevice* instance);
  80. void subbrute_device_set_callback(
  81. SubBruteDevice* instance,
  82. SubBruteDeviceWorkerCallback callback,
  83. void* context);
  84. void subbrute_device_free_protocol_info(SubBruteDevice* instance);
  85. int32_t subbrute_worker_thread(void* context);
  86. void subbrute_device_attack_set_default_values(
  87. SubBruteDevice* context,
  88. SubBruteAttacks default_attack);
  89. bool subbrute_device_create_packet_parsed(
  90. SubBruteDevice* instance,
  91. FlipperFormat* flipper_format,
  92. uint64_t step,
  93. bool small);
  94. void subbrute_device_send_callback(SubBruteDevice* instance);
  95. void subbrute_device_subghz_transmit(SubBruteDevice* instance, FlipperFormat* flipper_format);