subbrute_protocols.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. * - `SubBruteAttackCAME12bit315`: CAME 12-bit 330 MHz sub-brute attack.
  75. * - `SubBruteAttackCAME12bit433`: CAME 12-bit 433 MHz sub-brute attack.
  76. * - `SubBruteAttackCAME12bit868`: CAME 12-bit 868 MHz sub-brute attack.
  77. * - `SubBruteAttackNICE12bit433`: NICE 12-bit 433 MHz sub-brute attack.
  78. * - `SubBruteAttackNICE12bit868`: NICE 12-bit 868 MHz sub-brute attack.
  79. * - `SubBruteAttackAnsonic12bit433075`: Ansonic 12-bit 433.075 MHz sub-brute attack.
  80. * - `SubBruteAttackAnsonic12bit433`: Ansonic 12-bit 433 MHz sub-brute attack.
  81. * - `SubBruteAttackAnsonic12bit434`: Ansonic 12-bit 434 MHz sub-brute attack.
  82. * - `SubBruteAttackHoltek12bitFM433`: Holtek 12-bit FM 433 MHz sub-brute attack.
  83. * - `SubBruteAttackHoltek12bitAM433`: Holtek 12-bit AM 433 MHz sub-brute attack.
  84. * - `SubBruteAttackHoltek12bitAM315`: Holtek 12-bit AM 315 MHz sub-brute attack.
  85. * - `SubBruteAttackHoltek12bitAM868`: Holtek 12-bit AM 868 MHz sub-brute attack.
  86. * - `SubBruteAttackHoltek12bitAM915`: Holtek 12-bit AM 915 MHz sub-brute attack.
  87. * - `SubBruteAttackChamberlain9bit300`: Chamberlain 9-bit 300 MHz sub-brute attack.
  88. * - `SubBruteAttackChamberlain9bit315`: Chamberlain 9-bit 315 MHz sub-brute attack.
  89. * - `SubBruteAttackChamberlain9bit318`: Chamberlain 9-bit 318 MHz sub-brute attack.
  90. * - `SubBruteAttackChamberlain9bit390`: Chamberlain 9-bit 390 MHz sub-brute attack.
  91. * - `SubBruteAttackChamberlain9bit433`: Chamberlain 9-bit 433 MHz sub-brute attack.
  92. * - `SubBruteAttackChamberlain8bit300`: Chamberlain 8-bit 300 MHz sub-brute attack.
  93. * - `SubBruteAttackChamberlain8bit315`: Chamberlain 8-bit 315 MHz sub-brute attack.
  94. * - `SubBruteAttackChamberlain8bit390`: Chamberlain 8-bit 390 MHz sub-brute attack.
  95. * - `SubBruteAttackChamberlain7bit300`: Chamberlain 7-bit 300 MHz sub-brute attack.
  96. * - `SubBruteAttackChamberlain7bit315`: Chamberlain 7-bit 315 MHz sub-brute attack.
  97. * - `SubBruteAttackChamberlain7bit390`: Chamberlain 7-bit 390 MHz sub-brute attack.
  98. * - `SubBruteAttackLinear10bit300`: Linear 10-bit 300 MHz sub-brute attack.
  99. * - `SubBruteAttackLinear10bit310`: Linear 10-bit 310 MHz sub-brute attack.
  100. * - `SubBruteAttackLinearDelta8bit310`: Linear Delta 8-bit 310 MHz sub-brute attack.
  101. * - `SubBruteAttackUNILARM24bit330`: UNILARM 24-bit 330 MHz sub-brute attack.
  102. * - `SubBruteAttackUNILARM24bit433`: UNILARM 24-bit 433 MHz sub-brute attack.
  103. * - `SubBruteAttackSMC532624bit330`: SMC5326 24-bit 330 MHz sub-brute attack.
  104. * - `SubBruteAttackSMC532624bit433`: SMC5326 6-bit 433 MHz sub-brute attack.
  105. * - `SubBruteAttackPT226024bit315`: PT2260 24-bit 315 MHz sub-brute attack.
  106. * - `SubBruteAttackPT226024bit330`: PT2260 24-bit 330 MHz sub-brute attack.
  107. * - `SubBruteAttackPT226024bit390`: PT2260 24-bit 390 MHz sub-brute attack.
  108. * - `SubBruteAttackPT226024bit433`: PT2260 24-bit 433 MHz sub-brute attack.
  109. * - `SubBruteAttackLoadFile`: Sub-brute attack using values loaded from a file.
  110. * - `SubBruteAttackTotalCount`: Total number of sub-brute attacks.
  111. */
  112. typedef enum {
  113. SubBruteAttackCAME12bit303,
  114. SubBruteAttackCAME12bit307,
  115. SubBruteAttackCAME12bit315,
  116. SubBruteAttackCAME12bit330,
  117. SubBruteAttackCAME12bit433,
  118. SubBruteAttackCAME12bit868,
  119. SubBruteAttackNICE12bit433,
  120. SubBruteAttackNICE12bit868,
  121. SubBruteAttackAnsonic12bit433075,
  122. SubBruteAttackAnsonic12bit433,
  123. SubBruteAttackAnsonic12bit434,
  124. SubBruteAttackHoltek12bitFM433,
  125. SubBruteAttackHoltek12bitAM433,
  126. SubBruteAttackHoltek12bitAM315,
  127. SubBruteAttackHoltek12bitAM868,
  128. SubBruteAttackHoltek12bitAM915,
  129. SubBruteAttackChamberlain9bit300,
  130. SubBruteAttackChamberlain9bit315,
  131. SubBruteAttackChamberlain9bit318,
  132. SubBruteAttackChamberlain9bit390,
  133. SubBruteAttackChamberlain9bit433,
  134. SubBruteAttackChamberlain8bit300,
  135. SubBruteAttackChamberlain8bit315,
  136. SubBruteAttackChamberlain8bit390,
  137. SubBruteAttackChamberlain7bit300,
  138. SubBruteAttackChamberlain7bit315,
  139. SubBruteAttackChamberlain7bit390,
  140. SubBruteAttackLinear10bit300,
  141. SubBruteAttackLinear10bit310,
  142. SubBruteAttackLinearDelta8bit310,
  143. SubBruteAttackUNILARM24bit330,
  144. SubBruteAttackUNILARM24bit433,
  145. SubBruteAttackSMC532624bit330,
  146. SubBruteAttackSMC532624bit433,
  147. SubBruteAttackPT226024bit315,
  148. SubBruteAttackPT226024bit330,
  149. SubBruteAttackPT226024bit390,
  150. SubBruteAttackPT226024bit433,
  151. SubBruteAttackLoadFile,
  152. SubBruteAttackTotalCount,
  153. } SubBruteAttacks;
  154. /**
  155. * @struct SubBruteProtocol
  156. * @brief Structure representing the SubBrute protocol.
  157. *
  158. * The SubBruteProtocol struct contains information about the protocol parameters such as frequency,
  159. * bits, transmission time (te), repeat count, preset type, and file details using SubBruteFileProtocol.
  160. */
  161. typedef struct {
  162. uint32_t frequency;
  163. uint8_t bits;
  164. uint32_t te;
  165. uint8_t repeat;
  166. FuriHalSubGhzPreset preset;
  167. SubBruteFileProtocol file;
  168. } SubBruteProtocol;
  169. /**
  170. * @brief Get the SubBruteProtocol object based on the given index
  171. *
  172. * This function returns the SubBruteProtocol object based on the provided index.
  173. *
  174. * @param index The index of the SubBruteProtocol
  175. * @return const SubBruteProtocol* The pointer to the SubBruteProtocol object
  176. */
  177. const SubBruteProtocol* subbrute_protocol(SubBruteAttacks index);
  178. /**
  179. * @brief Retrieves a sub-GHz protocol preset for brute force attack.
  180. *
  181. * Given a FuriHalSubGhzPreset value, this function retrieves a sub-GHz protocol
  182. * preset suitable for performing a brute force attack. The protocol preset is
  183. * returned as a null-terminated string.
  184. *
  185. * @param preset The FuriHalSubGhzPreset value representing the desired sub-GHz
  186. * protocol preset.
  187. * @return A null-terminated string representing the protocol preset.
  188. */
  189. const char* subbrute_protocol_preset(FuriHalSubGhzPreset preset);
  190. /**
  191. * @brief Determines the file protocol used by SubBrute
  192. *
  193. * This function takes a SubBruteFileProtocol and returns the corresponding file protocol used by SubBrute.
  194. *
  195. * @param protocol The SubBruteFileProtocol to retrieve the file protocol for
  196. *
  197. * @returns The file protocol as a C string
  198. */
  199. const char* subbrute_protocol_file(SubBruteFileProtocol protocol);
  200. /**
  201. * @brief Convert a preset name to a FuriHalSubGhzPreset.
  202. *
  203. * This function takes a preset name as a FuriString pointer and converts it to a corresponding FuriHalSubGhzPreset value.
  204. * The converted preset is returned as a FuriHalSubGhzPreset value. If the preset name is not recognized, the behavior is undefined.
  205. *
  206. * @param preset_name The preset name to be converted.
  207. *
  208. * @return The converted FuriHalSubGhzPreset value.
  209. */
  210. FuriHalSubGhzPreset subbrute_protocol_convert_preset(FuriString* preset_name);
  211. /**
  212. * @brief Creates a SubBruteFileProtocol with the given name.
  213. *
  214. * @param name The name of the protocol.
  215. * @return The created SubBruteFileProtocol.
  216. */
  217. SubBruteFileProtocol subbrute_protocol_file_protocol_name(FuriString* name);
  218. /**
  219. * @brief Get the number of protocol repeats for a specific SubBrute attack.
  220. *
  221. * This function returns the number of protocol repeats for a specific SubBrute attack, identified by its index.
  222. *
  223. * @param index The index of the SubBrute attack.
  224. * @return The number of protocol repeats for the specified SubBrute attack.
  225. */
  226. uint8_t subbrute_protocol_repeats_count(SubBruteAttacks index);
  227. /**
  228. * @brief Retrieves the protocol name for a given SubBrute attack.
  229. *
  230. * This function returns the protocol name associated with the specified SubBrute attack.
  231. *
  232. * @param index The index of the SubBrute attack.
  233. * @return The protocol name as a constant character pointer.
  234. */
  235. const char* subbrute_protocol_name(SubBruteAttacks index);
  236. /**
  237. * @brief Executes a sub-brute force attack with default payload.
  238. *
  239. * This function performs a sub-brute force attack using the default payload on the specified stream and file protocol.
  240. * It continues the attack in steps, with each step increasing the payload by a specified number of bits.
  241. *
  242. * @param stream The stream to perform the attack on.
  243. * @param file The file protocol to use for the attack.
  244. * @param step The number of bits to increase the payload with in each step.
  245. * @param bits The initial number of bits in the payload.
  246. * @param te The timeout value in milliseconds.
  247. * @param repeat The number of times to repeat the attack.
  248. *
  249. * @note The function does not return any value.
  250. */
  251. void subbrute_protocol_default_payload(
  252. Stream* stream,
  253. SubBruteFileProtocol file,
  254. uint64_t step,
  255. uint8_t bits,
  256. uint32_t te,
  257. uint8_t repeat);
  258. /**
  259. * @brief Performs a sub-brute force protocol operation with file payload.
  260. *
  261. * This function takes in a stream, step, bits, te, repeat, bit_index,
  262. * file_key, and two_bytes as input parameters and performs a sub-brute
  263. * force protocol operation with a file payload.
  264. *
  265. * @param stream The Stream object to operate on.
  266. * @param step The step value to use during the operation.
  267. * @param bits The number of bits to use.
  268. * @param te The te value to use during the operation.
  269. * @param repeat The number of times to repeat the operation.
  270. * @param bit_index The bit index to use during the operation.
  271. * @param file_key The file key to use during the operation.
  272. * @param two_bytes A boolean indicating whether to use two bytes in the operation.
  273. *
  274. * @return None
  275. */
  276. void subbrute_protocol_file_payload(
  277. Stream* stream,
  278. uint64_t step,
  279. uint8_t bits,
  280. uint32_t te,
  281. uint8_t repeat,
  282. uint8_t bit_index,
  283. uint64_t file_key,
  284. bool two_bytes);
  285. /**
  286. * @brief Generates a file using the SubBrute protocol with default settings.
  287. *
  288. * This function generates a file using the SubBrute protocol with default settings.
  289. *
  290. * @param stream The stream used for writing the file.
  291. * @param frequency The frequency of the SubBrute protocol.
  292. * @param preset The SubGhzPreset used for transmission.
  293. * @param file The SubBruteFileProtocol used for generating the file.
  294. * @param step The step size used for generating the file.
  295. * @param bits The number of bits to generate for each interval.
  296. * @param te The duration of each transmission interval in milliseconds.
  297. */
  298. void subbrute_protocol_default_generate_file(
  299. Stream* stream,
  300. uint32_t frequency,
  301. FuriHalSubGhzPreset preset,
  302. SubBruteFileProtocol file,
  303. uint64_t step,
  304. uint8_t bits,
  305. uint32_t te);
  306. /**
  307. * @brief Generates a file for the SubBrute protocol with the given parameters.
  308. *
  309. * This function generates a file for the SubBrute protocol using the provided parameters.
  310. * The generated file can be used for various purposes, such as testing or data analysis.
  311. *
  312. * @param stream The Stream to output the generated file to.
  313. * @param frequency The frequency to use for the SubBrute protocol.
  314. * @param preset The SubGhzPreset to use for the SubBrute protocol.
  315. * @param file The SubBruteFileProtocol to generate.
  316. * @param step The step value to use for the SubBrute protocol.
  317. * @param bits The number of bits to use for each transmission in the SubBrute protocol.
  318. * @param te The TE value to use for the SubBrute protocol.
  319. * @param bit_index The starting bit index for the SubBrute protocol.
  320. * @param file_key The file key to use for generating the SubBrute file.
  321. * @param two_bytes Indicates whether two bytes should be used for each transmission (true) or not (false).
  322. */
  323. void subbrute_protocol_file_generate_file(
  324. Stream* stream,
  325. uint32_t frequency,
  326. FuriHalSubGhzPreset preset,
  327. SubBruteFileProtocol file,
  328. uint64_t step,
  329. uint8_t bits,
  330. uint32_t te,
  331. uint8_t bit_index,
  332. uint64_t file_key,
  333. bool two_bytes);
  334. /**
  335. * @brief Calculates the maximum value based on the attack type, number of bits, and whether two bytes are used.
  336. *
  337. * This function calculates the maximum value that can be generated based on the specified attack type,
  338. * number of bits, and whether two bytes are used. The result is returned as a 64-bit unsigned integer.
  339. *
  340. * @param attack_type The type of attack to be performed (SubBruteAttacks).
  341. * @param bits The number of bits used for the attack (uint8_t).
  342. * @param two_bytes Whether two bytes are used for the attack (bool).
  343. *
  344. * @return The maximum value that can be generated based on the attack parameters (uint64_t).
  345. */
  346. uint64_t subbrute_protocol_calc_max_value(SubBruteAttacks attack_type, uint8_t bits, bool two_bytes);