subbrute_protocols.h 15 KB

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