subbrute_protocols.h 15 KB

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