subbrute_protocols.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal_subghz.h>
  4. #include <core/string.h>
  5. #include <toolbox/stream/stream.h>
  6. #define SUBBRUTE_PROTOCOL_MAX_REPEATS 9
  7. /**
  8. * @enum SubBruteFileProtocol
  9. * @brief Enum defining various file protocols used in a system
  10. *
  11. * This enum defines different file protocols that can be used in the system.
  12. * Each file protocol is identified by its name.
  13. *
  14. * The possible values for this enum are:
  15. * - CAMEFileProtocol: CAME file protocol
  16. * - NICEFileProtocol: NICE file protocol
  17. * - ChamberlainFileProtocol: Chamberlain file protocol
  18. * - LinearFileProtocol: Linear file protocol
  19. * - LinearDeltaFileProtocol: Linear Delta file protocol
  20. * - PrincetonFileProtocol: Princeton file protocol
  21. * - RAWFileProtocol: RAW file protocol
  22. * - BETTFileProtocol: BETT file protocol
  23. * - ClemsaFileProtocol: Clemsa file protocol
  24. * - DoitrandFileProtocol: Doitrand file protocol
  25. * - GateTXFileProtocol: GateTX file protocol
  26. * - MagellanFileProtocol: Magellan file protocol
  27. * - IntertechnoV3FileProtocol: Intertechno V3 file protocol
  28. * - AnsonicFileProtocol: Ansonic file protocol
  29. * - SMC5326FileProtocol: SMC5326 file protocol
  30. * - UNILARMFileProtocol: UNILARM file protocol
  31. * - PT2260FileProtocol: PT2260 file protocol
  32. * - HoneywellFileProtocol: Honeywell file protocol
  33. * - HoltekFileProtocol: Holtek file protocol
  34. * - UnknownFileProtocol: Unknown file protocol
  35. * - TotalFileProtocol: Total file protocol
  36. */
  37. typedef enum {
  38. CAMEFileProtocol,
  39. NICEFileProtocol,
  40. ChamberlainFileProtocol,
  41. LinearFileProtocol,
  42. LinearDeltaFileProtocol,
  43. PrincetonFileProtocol,
  44. RAWFileProtocol,
  45. BETTFileProtocol,
  46. ClemsaFileProtocol,
  47. DoitrandFileProtocol,
  48. GateTXFileProtocol,
  49. MagellanFileProtocol,
  50. IntertechnoV3FileProtocol,
  51. AnsonicFileProtocol,
  52. SMC5326FileProtocol,
  53. UNILARMFileProtocol,
  54. PT2260FileProtocol,
  55. HoneywellFileProtocol,
  56. HoltekFileProtocol,
  57. UnknownFileProtocol,
  58. TotalFileProtocol,
  59. } SubBruteFileProtocol;
  60. /**
  61. * @enum SubBruteAttacks
  62. *
  63. * Enumeration of all supported sub-brute attacks.
  64. *
  65. * The `SubBruteAttacks` represents the different types of sub-brute attacks
  66. * that can be performed. Each attack has a unique identifier, which can be used
  67. * to specify the attack when calling functions that handle sub-brute attacks.
  68. *
  69. * The possible values of `SubBruteAttacks` are as follows:
  70. *
  71. * - `SubBruteAttackCAME12bit303`: CAME 12-bit 303 MHz sub-brute attack.
  72. * - `SubBruteAttackCAME12bit307`: CAME 12-bit 307 MHz sub-brute attack.
  73. * - `SubBruteAttackCAME12bit315`: CAME 12-bit 315 MHz sub-brute attack.
  74. * - `SubBruteAttackCAME12bit433`: CAME 12-bit 433 MHz sub-brute attack.
  75. * - `SubBruteAttackCAME12bit868`: CAME 12-bit 868 MHz sub-brute attack.
  76. * - `SubBruteAttackNICE12bit433`: NICE 12-bit 433 MHz sub-brute attack.
  77. * - `SubBruteAttackNICE12bit868`: NICE 12-bit 868 MHz sub-brute attack.
  78. * - `SubBruteAttackAnsonic12bit433075`: Ansonic 12-bit 433.075 MHz sub-brute attack.
  79. * - `SubBruteAttackAnsonic12bit433`: Ansonic 12-bit 433 MHz sub-brute attack.
  80. * - `SubBruteAttackAnsonic12bit434`: Ansonic 12-bit 434 MHz sub-brute attack.
  81. * - `SubBruteAttackHoltek12bitFM433`: Holtek 12-bit FM 433 MHz sub-brute attack.
  82. * - `SubBruteAttackHoltek12bitAM433`: Holtek 12-bit AM 433 MHz sub-brute attack.
  83. * - `SubBruteAttackHoltek12bitAM315`: Holtek 12-bit AM 315 MHz sub-brute attack.
  84. * - `SubBruteAttackHoltek12bitAM868`: Holtek 12-bit AM 868 MHz sub-brute attack.
  85. * - `SubBruteAttackHoltek12bitAM915`: Holtek 12-bit AM 915 MHz sub-brute attack.
  86. * - `SubBruteAttackChamberlain9bit300`: Chamberlain 9-bit 300 MHz sub-brute attack.
  87. * - `SubBruteAttackChamberlain9bit315`: Chamberlain 9-bit 315 MHz sub-brute attack.
  88. * - `SubBruteAttackChamberlain9bit390`: Chamberlain 9-bit 390 MHz sub-brute attack.
  89. * - `SubBruteAttackChamberlain9bit433`: Chamberlain 9-bit 433 MHz sub-brute attack.
  90. * - `SubBruteAttackChamberlain8bit300`: Chamberlain 8-bit 300 MHz sub-brute attack.
  91. * - `SubBruteAttackChamberlain8bit315`: Chamberlain 8-bit 315 MHz sub-brute attack.
  92. * - `SubBruteAttackChamberlain8bit390`: Chamberlain 8-bit 390 MHz sub-brute attack.
  93. * - `SubBruteAttackChamberlain7bit300`: Chamberlain 7-bit 300 MHz sub-brute attack.
  94. * - `SubBruteAttackChamberlain7bit315`: Chamberlain 7-bit 315 MHz sub-brute attack.
  95. * - `SubBruteAttackChamberlain7bit390`: Chamberlain 7-bit 390 MHz sub-brute attack.
  96. * - `SubBruteAttackLinear10bit300`: Linear 10-bit 300 MHz sub-brute attack.
  97. * - `SubBruteAttackLinear10bit310`: Linear 10-bit 310 MHz sub-brute attack.
  98. * - `SubBruteAttackLinearDelta8bit310`: Linear Delta 8-bit 310 MHz sub-brute attack.
  99. * - `SubBruteAttackUNILARM24bit330`: UNILARM 24-bit 330 MHz sub-brute attack.
  100. * - `SubBruteAttackUNILARM24bit433`: UNILARM 24-bit 433 MHz sub-brute attack.
  101. * - `SubBruteAttackSMC532624bit330`: SMC5326 24-bit 330 MHz sub-brute attack.
  102. * - `SubBruteAttackSMC532624bit433`: SMC5326 6-bit 433 MHz sub-brute attack.
  103. * - `SubBruteAttackPT226024bit315`: PT2260 24-bit 315 MHz sub-brute attack.
  104. * - `SubBruteAttackPT226024bit330`: PT2260 24-bit 330 MHz sub-brute attack.
  105. * - `SubBruteAttackPT226024bit390`: PT2260 24-bit 390 MHz sub-brute attack.
  106. * - `SubBruteAttackPT226024bit433`: PT2260 24-bit 433 MHz sub-brute attack.
  107. * - `SubBruteAttackLoadFile`: Sub-brute attack using values loaded from a file.
  108. * - `SubBruteAttackTotalCount`: Total number of sub-brute attacks.
  109. */
  110. typedef enum {
  111. SubBruteAttackCAME12bit303,
  112. SubBruteAttackCAME12bit307,
  113. SubBruteAttackCAME12bit315,
  114. SubBruteAttackCAME12bit433,
  115. SubBruteAttackCAME12bit868,
  116. SubBruteAttackNICE12bit433,
  117. SubBruteAttackNICE12bit868,
  118. SubBruteAttackAnsonic12bit433075,
  119. SubBruteAttackAnsonic12bit433,
  120. SubBruteAttackAnsonic12bit434,
  121. SubBruteAttackHoltek12bitFM433,
  122. SubBruteAttackHoltek12bitAM433,
  123. SubBruteAttackHoltek12bitAM315,
  124. SubBruteAttackHoltek12bitAM868,
  125. SubBruteAttackHoltek12bitAM915,
  126. SubBruteAttackChamberlain9bit300,
  127. SubBruteAttackChamberlain9bit315,
  128. SubBruteAttackChamberlain9bit390,
  129. SubBruteAttackChamberlain9bit433,
  130. SubBruteAttackChamberlain8bit300,
  131. SubBruteAttackChamberlain8bit315,
  132. SubBruteAttackChamberlain8bit390,
  133. SubBruteAttackChamberlain7bit300,
  134. SubBruteAttackChamberlain7bit315,
  135. SubBruteAttackChamberlain7bit390,
  136. SubBruteAttackLinear10bit300,
  137. SubBruteAttackLinear10bit310,
  138. SubBruteAttackLinearDelta8bit310,
  139. SubBruteAttackUNILARM24bit330,
  140. SubBruteAttackUNILARM24bit433,
  141. SubBruteAttackSMC532624bit330,
  142. SubBruteAttackSMC532624bit433,
  143. SubBruteAttackPT226024bit315,
  144. SubBruteAttackPT226024bit330,
  145. SubBruteAttackPT226024bit390,
  146. SubBruteAttackPT226024bit433,
  147. SubBruteAttackLoadFile,
  148. SubBruteAttackTotalCount,
  149. } SubBruteAttacks;
  150. /**
  151. * @struct SubBruteProtocol
  152. * @brief Structure representing the SubBrute protocol.
  153. *
  154. * The SubBruteProtocol struct contains information about the protocol parameters such as frequency,
  155. * bits, transmission time (te), repeat count, preset type, and file details using SubBruteFileProtocol.
  156. */
  157. typedef struct {
  158. uint32_t frequency;
  159. uint8_t bits;
  160. uint32_t te;
  161. uint8_t repeat;
  162. FuriHalSubGhzPreset preset;
  163. SubBruteFileProtocol file;
  164. } SubBruteProtocol;
  165. /**
  166. * @brief Get the SubBruteProtocol object based on the given index
  167. *
  168. * This function returns the SubBruteProtocol object based on the provided index.
  169. *
  170. * @param index The index of the SubBruteProtocol
  171. * @return const SubBruteProtocol* The pointer to the SubBruteProtocol object
  172. */
  173. const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index);
  174. /**
  175. * @brief Retrieves a sub-GHz protocol preset for brute force attack.
  176. *
  177. * Given a FuriHalSubGhzPreset value, this function retrieves a sub-GHz protocol
  178. * preset suitable for performing a brute force attack. The protocol preset is
  179. * returned as a null-terminated string.
  180. *
  181. * @param preset The FuriHalSubGhzPreset value representing the desired sub-GHz
  182. * protocol preset.
  183. * @return A null-terminated string representing the protocol preset.
  184. */
  185. const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset);
  186. /**
  187. * @brief Determines the file protocol used by SubBrute
  188. *
  189. * This function takes a SubBruteFileProtocol and returns the corresponding file protocol used by SubBrute.
  190. *
  191. * @param protocol The SubBruteFileProtocol to retrieve the file protocol for
  192. *
  193. * @returns The file protocol as a C string
  194. */
  195. const char* subbrute_protocol_file(SubBruteFileProtocol protocol);
  196. /**
  197. * @brief Convert a preset name to a FuriHalSubGhzPreset.
  198. *
  199. * This function takes a preset name as a FuriString pointer and converts it to a corresponding FuriHalSubGhzPreset value.
  200. * The converted preset is returned as a FuriHalSubGhzPreset value. If the preset name is not recognized, the behavior is undefined.
  201. *
  202. * @param preset_name The preset name to be converted.
  203. *
  204. * @return The converted FuriHalSubGhzPreset value.
  205. */
  206. FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name);
  207. /**
  208. * @brief Creates a SubBruteFileProtocol with the given name.
  209. *
  210. * @param name The name of the protocol.
  211. * @return The created SubBruteFileProtocol.
  212. */
  213. SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name);
  214. /**
  215. * @brief Get the number of protocol repeats for a specific SubBrute attack.
  216. *
  217. * This function returns the number of protocol repeats for a specific SubBrute attack, identified by its index.
  218. *
  219. * @param index The index of the SubBrute attack.
  220. * @return The number of protocol repeats for the specified SubBrute attack.
  221. */
  222. uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index);
  223. /**
  224. * @brief Retrieves the protocol name for a given SubBrute attack.
  225. *
  226. * This function returns the protocol name associated with the specified SubBrute attack.
  227. *
  228. * @param index The index of the SubBrute attack.
  229. * @return The protocol name as a constant character pointer.
  230. */
  231. const char* subbrute_protocol_name(SubBruteAttacks index);
  232. /**
  233. * @brief Executes a sub-brute force attack with default payload.
  234. *
  235. * This function performs a sub-brute force attack using the default payload on the specified stream and file protocol.
  236. * It continues the attack in steps, with each step increasing the payload by a specified number of bits.
  237. *
  238. * @param stream The stream to perform the attack on.
  239. * @param file The file protocol to use for the attack.
  240. * @param step The number of bits to increase the payload with in each step.
  241. * @param bits The initial number of bits in the payload.
  242. * @param te The timeout value in milliseconds.
  243. * @param repeat The number of times to repeat the attack.
  244. *
  245. * @note The function does not return any value.
  246. */
  247. void subbrute_protocol_default_payload(
  248. Stream* stream,
  249. SubBruteFileProtocol file,
  250. uint64_t step,
  251. uint8_t bits,
  252. uint32_t te,
  253. uint8_t repeat);
  254. /**
  255. * @brief Performs a sub-brute force protocol operation with file payload.
  256. *
  257. * This function takes in a stream, step, bits, te, repeat, bit_index,
  258. * file_key, and two_bytes as input parameters and performs a sub-brute
  259. * force protocol operation with a file payload.
  260. *
  261. * @param stream The Stream object to operate on.
  262. * @param step The step value to use during the operation.
  263. * @param bits The number of bits to use.
  264. * @param te The te value to use during the operation.
  265. * @param repeat The number of times to repeat the operation.
  266. * @param bit_index The bit index to use during the operation.
  267. * @param file_key The file key to use during the operation.
  268. * @param two_bytes A boolean indicating whether to use two bytes in the operation.
  269. *
  270. * @return None
  271. */
  272. void subbrute_protocol_file_payload(
  273. Stream* stream,
  274. uint64_t step,
  275. uint8_t bits,
  276. uint32_t te,
  277. uint8_t repeat,
  278. uint8_t bit_index,
  279. uint64_t file_key,
  280. bool two_bytes);
  281. /**
  282. * @brief Generates a file using the SubBrute protocol with default settings.
  283. *
  284. * This function generates a file using the SubBrute protocol with default settings.
  285. *
  286. * @param stream The stream used for writing the file.
  287. * @param frequency The frequency of the SubBrute protocol.
  288. * @param preset The SubGhzPreset used for transmission.
  289. * @param file The SubBruteFileProtocol used for generating the file.
  290. * @param step The step size used for generating the file.
  291. * @param bits The number of bits to generate for each interval.
  292. * @param te The duration of each transmission interval in milliseconds.
  293. */
  294. void subbrute_protocol_default_generate_file(
  295. Stream* stream,
  296. uint32_t frequency,
  297. FuriHalSubGhzPreset preset,
  298. SubBruteFileProtocol file,
  299. uint64_t step,
  300. uint8_t bits,
  301. uint32_t te);
  302. /**
  303. * @brief Generates a file for the SubBrute protocol with the given parameters.
  304. *
  305. * This function generates a file for the SubBrute protocol using the provided parameters.
  306. * The generated file can be used for various purposes, such as testing or data analysis.
  307. *
  308. * @param stream The Stream to output the generated file to.
  309. * @param frequency The frequency to use for the SubBrute protocol.
  310. * @param preset The SubGhzPreset to use for the SubBrute protocol.
  311. * @param file The SubBruteFileProtocol to generate.
  312. * @param step The step value to use for the SubBrute protocol.
  313. * @param bits The number of bits to use for each transmission in the SubBrute protocol.
  314. * @param te The TE value to use for the SubBrute protocol.
  315. * @param bit_index The starting bit index for the SubBrute protocol.
  316. * @param file_key The file key to use for generating the SubBrute file.
  317. * @param two_bytes Indicates whether two bytes should be used for each transmission (true) or not (false).
  318. */
  319. void subbrute_protocol_file_generate_file(
  320. Stream* stream,
  321. uint32_t frequency,
  322. FuriHalSubGhzPreset preset,
  323. SubBruteFileProtocol file,
  324. uint64_t step,
  325. uint8_t bits,
  326. uint32_t te,
  327. uint8_t bit_index,
  328. uint64_t file_key,
  329. bool two_bytes);
  330. /**
  331. * @brief Calculates the maximum value based on the attack type, number of bits, and whether two bytes are used.
  332. *
  333. * This function calculates the maximum value that can be generated based on the specified attack type,
  334. * number of bits, and whether two bytes are used. The result is returned as a 64-bit unsigned integer.
  335. *
  336. * @param attack_type The type of attack to be performed (SubBruteAttacks).
  337. * @param bits The number of bits used for the attack (uint8_t).
  338. * @param two_bytes Whether two bytes are used for the attack (bool).
  339. *
  340. * @return The maximum value that can be generated based on the attack parameters (uint64_t).
  341. */
  342. uint64_t subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes);