subbrute_protocols.h 15 KB

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