subbrute_device.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. #include "subbrute_device.h"
  2. #include "subbrute_i.h"
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. #include <furi_hal_subghz.h>
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <lib/subghz/types.h>
  9. #include <lib/subghz/protocols/base.h>
  10. #include <storage/storage.h>
  11. #include <dialogs/dialogs.h>
  12. #include <stream/stream.h>
  13. #include <stream/buffered_file_stream.h>
  14. #include <lib/toolbox/path.h>
  15. #include <lib/flipper_format/flipper_format_i.h>
  16. #define TAG "SubBruteDevice"
  17. /**
  18. * List of protocols
  19. */
  20. static const char* protocol_came = "CAME";
  21. static const char* protocol_cham_code = "Cham_Code";
  22. static const char* protocol_linear = "Linear";
  23. static const char* protocol_nice_flo = "Nice FLO";
  24. static const char* protocol_princeton = "Princeton";
  25. static const char* protocol_raw = "RAW";
  26. /**
  27. * Values to not use less memory for packet parse operations
  28. */
  29. static const char* subbrute_key_file_start =
  30. "Filetype: Flipper SubGhz Key File\nVersion: 1\nFrequency: %u\nPreset: %s\nProtocol: %s\nBit: %d";
  31. static const char* subbrute_key_file_key = "%s\nKey: %s\n";
  32. static const char* subbrute_key_file_princeton_end = "%s\nKey: %s\nTE: %d\n";
  33. static const char* subbrute_key_small_no_tail = "Bit: %d\nKey: %s\n";
  34. static const char* subbrute_key_small_with_tail = "Bit: %d\nKey: %s\nTE: %d\n";
  35. // Why nobody set in as const in all codebase?
  36. static const char* preset_ook270_async = "FuriHalSubGhzPresetOok270Async";
  37. static const char* preset_ook650_async = "FuriHalSubGhzPresetOok650Async";
  38. static const char* preset_2fsk_dev238_async = "FuriHalSubGhzPreset2FSKDev238Async";
  39. static const char* preset_2fsk_dev476_async = "FuriHalSubGhzPreset2FSKDev476Async";
  40. static const char* preset_msk99_97_kb_async = "FuriHalSubGhzPresetMSK99_97KbAsync";
  41. static const char* preset_gfs99_97_kb_async = "FuriHalSubGhzPresetGFS99_97KbAsync";
  42. SubBruteDevice* subbrute_device_alloc() {
  43. SubBruteDevice* instance = malloc(sizeof(SubBruteDevice));
  44. instance->state = SubBruteDeviceStateIDLE;
  45. instance->key_index = 0;
  46. string_init(instance->load_path);
  47. string_init(instance->preset_name);
  48. string_init(instance->protocol_name);
  49. instance->decoder_result = NULL;
  50. instance->receiver = NULL;
  51. instance->environment = subghz_environment_alloc();
  52. subbrute_device_attack_set_default_values(instance, SubBruteAttackCAME12bit307);
  53. return instance;
  54. }
  55. void subbrute_device_free(SubBruteDevice* instance) {
  56. furi_assert(instance);
  57. #ifdef FURI_DEBUG
  58. FURI_LOG_D(TAG, "subbrute_device_free");
  59. #endif
  60. // I don't know how to free this
  61. instance->decoder_result = NULL;
  62. if(instance->receiver != NULL) {
  63. #ifdef FURI_DEBUG
  64. FURI_LOG_D(TAG, "subghz_receiver_free");
  65. #endif
  66. subghz_receiver_free(instance->receiver);
  67. instance->receiver = NULL;
  68. }
  69. subghz_environment_free(instance->environment);
  70. instance->environment = NULL;
  71. #ifdef FURI_DEBUG
  72. FURI_LOG_D(TAG, "before free");
  73. #endif
  74. string_clear(instance->load_path);
  75. string_clear(instance->preset_name);
  76. string_clear(instance->protocol_name);
  77. free(instance);
  78. }
  79. bool subbrute_device_save_file(SubBruteDevice* instance, const char* dev_file_name) {
  80. furi_assert(instance);
  81. #ifdef FURI_DEBUG
  82. FURI_LOG_D(TAG, "subbrute_device_save_file: %s", dev_file_name);
  83. #endif
  84. bool result = subbrute_device_create_packet_parsed(instance, instance->key_index, false);
  85. if(!result) {
  86. FURI_LOG_E(TAG, "subbrute_device_create_packet_parsed failed!");
  87. //subbrute_device_notification_message(instance, &sequence_error);
  88. return false;
  89. }
  90. Storage* storage = furi_record_open(RECORD_STORAGE);
  91. Stream* stream = buffered_file_stream_alloc(storage);
  92. result = false;
  93. do {
  94. if(!buffered_file_stream_open(stream, dev_file_name, FSAM_READ_WRITE, FSOM_OPEN_ALWAYS)) {
  95. buffered_file_stream_close(stream);
  96. break;
  97. }
  98. stream_write_cstring(stream, instance->payload);
  99. result = true;
  100. } while(false);
  101. buffered_file_stream_close(stream);
  102. stream_free(stream);
  103. if(!result) {
  104. FURI_LOG_E(TAG, "stream_write_string failed!");
  105. //subbrute_device_notification_message(instance, &sequence_error);
  106. }
  107. furi_record_close(RECORD_STORAGE);
  108. return result;
  109. }
  110. const char* subbrute_device_error_get_desc(SubBruteFileResult error_id) {
  111. const char* result;
  112. switch(error_id) {
  113. case(SubBruteFileResultOk):
  114. result = "OK";
  115. break;
  116. case(SubBruteFileResultErrorOpenFile):
  117. result = "invalid name/path";
  118. break;
  119. case(SubBruteFileResultMissingOrIncorrectHeader):
  120. result = "Missing or incorrect header";
  121. break;
  122. case(SubBruteFileResultFrequencyNotAllowed):
  123. result = "Invalid frequency!";
  124. break;
  125. case(SubBruteFileResultMissingOrIncorrectFrequency):
  126. result = "Missing or incorrect Frequency";
  127. break;
  128. case(SubBruteFileResultPresetInvalid):
  129. result = "Preset FAIL";
  130. break;
  131. case(SubBruteFileResultMissingProtocol):
  132. result = "Missing Protocol";
  133. break;
  134. case(SubBruteFileResultProtocolNotSupported):
  135. result = "RAW unsupported";
  136. break;
  137. case(SubBruteFileResultDynamicProtocolNotValid):
  138. result = "Dynamic protocol unsupported";
  139. break;
  140. case(SubBruteFileResultProtocolNotFound):
  141. result = "Protocol not found";
  142. break;
  143. case(SubBruteFileResultMissingOrIncorrectBit):
  144. result = "Missing or incorrect Bit";
  145. break;
  146. case(SubBruteFileResultMissingOrIncorrectKey):
  147. result = "Missing or incorrect Key";
  148. break;
  149. case(SubBruteFileResultMissingOrIncorrectTe):
  150. result = "Missing or incorrect TE";
  151. break;
  152. case SubBruteFileResultUnknown:
  153. default:
  154. result = "Unknown error";
  155. break;
  156. }
  157. return result;
  158. }
  159. bool subbrute_device_create_packet_parsed(SubBruteDevice* instance, uint64_t step, bool small) {
  160. furi_assert(instance);
  161. //char step_payload[32];
  162. //memset(step_payload, '0', sizeof(step_payload));
  163. memset(instance->payload, 0, sizeof(instance->payload));
  164. string_t candidate;
  165. string_init(candidate);
  166. if(instance->attack == SubBruteAttackLoadFile) {
  167. if(step >= sizeof(instance->file_key)) {
  168. return false;
  169. }
  170. char subbrute_payload_byte[4];
  171. string_set_str(candidate, instance->file_key);
  172. snprintf(subbrute_payload_byte, 4, "%02X ", (uint8_t)step);
  173. string_replace_at(candidate, instance->load_index * 3, 3, subbrute_payload_byte);
  174. //snprintf(step_payload, sizeof(step_payload), "%02X", (uint8_t)instance->file_key[step]);
  175. } else {
  176. //snprintf(step_payload, sizeof(step_payload), "%16X", step);
  177. //snprintf(step_payload, sizeof(step_payload), "%016llX", step);
  178. string_t buffer;
  179. string_init(buffer);
  180. string_init_printf(buffer, "%16X", step);
  181. int j = 0;
  182. string_set_str(candidate, " ");
  183. for(uint8_t i = 0; i < 16; i++) {
  184. if(string_get_char(buffer, i) != ' ') {
  185. string_set_char(candidate, i + j, string_get_char(buffer, i));
  186. } else {
  187. string_set_char(candidate, i + j, '0');
  188. }
  189. if(i % 2 != 0) {
  190. j++;
  191. }
  192. }
  193. string_clear(buffer);
  194. }
  195. #ifdef FURI_DEBUG
  196. FURI_LOG_D(TAG, "candidate: %s, step: %d", string_get_cstr(candidate), step);
  197. #endif
  198. if(small) {
  199. if(instance->has_tail) {
  200. snprintf(
  201. instance->payload,
  202. sizeof(instance->payload),
  203. subbrute_key_small_with_tail,
  204. instance->bit,
  205. string_get_cstr(candidate),
  206. instance->te);
  207. } else {
  208. snprintf(
  209. instance->payload,
  210. sizeof(instance->payload),
  211. subbrute_key_small_no_tail,
  212. instance->bit,
  213. string_get_cstr(candidate));
  214. }
  215. } else {
  216. if(instance->has_tail) {
  217. snprintf(
  218. instance->payload,
  219. sizeof(instance->payload),
  220. subbrute_key_file_princeton_end,
  221. instance->file_template,
  222. string_get_cstr(candidate),
  223. instance->te);
  224. } else {
  225. snprintf(
  226. instance->payload,
  227. sizeof(instance->payload),
  228. subbrute_key_file_key,
  229. instance->file_template,
  230. string_get_cstr(candidate));
  231. }
  232. }
  233. #ifdef FURI_DEBUG
  234. //FURI_LOG_D(TAG, "payload: %s", instance->payload);
  235. #endif
  236. string_clear(candidate);
  237. return true;
  238. }
  239. SubBruteFileResult subbrute_device_attack_set(SubBruteDevice* instance, SubBruteAttacks type) {
  240. furi_assert(instance);
  241. #ifdef FURI_DEBUG
  242. FURI_LOG_D(TAG, "subbrute_device_attack_set: %d", type);
  243. #endif
  244. subbrute_device_attack_set_default_values(instance, type);
  245. switch(type) {
  246. case SubBruteAttackLoadFile:
  247. // In this case values must be already set
  248. // file_result =
  249. // subbrute_device_load_from_file(instance, string_get_cstr(instance->load_path));
  250. // if(file_result != SubBruteFileResultOk) {
  251. // // Failed load file so failed to set attack type
  252. // return file_result; // RETURN
  253. // }
  254. break;
  255. case SubBruteAttackCAME12bit307:
  256. case SubBruteAttackCAME12bit433:
  257. case SubBruteAttackCAME12bit868:
  258. if(type == SubBruteAttackCAME12bit307) {
  259. instance->frequency = 307800000;
  260. } else if(type == SubBruteAttackCAME12bit433) {
  261. instance->frequency = 433920000;
  262. } else /* ALWAYS TRUE if(type == SubBruteAttackCAME12bit868) */ {
  263. instance->frequency = 868350000;
  264. }
  265. instance->bit = 12;
  266. string_set_str(instance->protocol_name, protocol_came);
  267. string_set_str(instance->preset_name, preset_ook650_async);
  268. break;
  269. case SubBruteAttackChamberlain9bit315:
  270. instance->frequency = 315000000;
  271. instance->bit = 9;
  272. string_set_str(instance->protocol_name, protocol_cham_code);
  273. string_set_str(instance->preset_name, preset_ook650_async);
  274. break;
  275. case SubBruteAttackChamberlain9bit390:
  276. instance->frequency = 390000000;
  277. instance->bit = 9;
  278. string_set_str(instance->protocol_name, protocol_cham_code);
  279. string_set_str(instance->preset_name, preset_ook650_async);
  280. break;
  281. case SubBruteAttackLinear10bit300:
  282. instance->frequency = 300000000;
  283. instance->bit = 10;
  284. string_set_str(instance->protocol_name, protocol_linear);
  285. string_set_str(instance->preset_name, preset_ook650_async);
  286. break;
  287. case SubBruteAttackLinear10bit310:
  288. instance->frequency = 310000000;
  289. instance->bit = 10;
  290. string_set_str(instance->protocol_name, protocol_linear);
  291. string_set_str(instance->preset_name, preset_ook650_async);
  292. break;
  293. case SubBruteAttackNICE12bit433:
  294. instance->frequency = 433920000;
  295. instance->bit = 12;
  296. string_set_str(instance->protocol_name, protocol_nice_flo);
  297. string_set_str(instance->preset_name, preset_ook650_async);
  298. break;
  299. case SubBruteAttackNICE12bit868:
  300. instance->frequency = 868350000;
  301. instance->bit = 12;
  302. string_set_str(instance->protocol_name, protocol_nice_flo);
  303. string_set_str(instance->preset_name, preset_ook650_async);
  304. break;
  305. default:
  306. FURI_LOG_E(TAG, "Unknown attack type: %d", type);
  307. return SubBruteFileResultProtocolNotFound; // RETURN
  308. }
  309. if(!furi_hal_subghz_is_tx_allowed(instance->frequency)) {
  310. FURI_LOG_E(TAG, "Frequency invalid: %d", instance->frequency);
  311. return SubBruteFileResultMissingOrIncorrectFrequency; // RETURN
  312. }
  313. // For non-file types we didn't set SubGhzProtocolDecoderBase
  314. instance->receiver = subghz_receiver_alloc_init(instance->environment);
  315. subghz_receiver_set_filter(instance->receiver, SubGhzProtocolFlag_Decodable);
  316. furi_hal_subghz_reset();
  317. uint8_t protocol_check_result = SubBruteFileResultProtocolNotFound;
  318. if(type != SubBruteAttackLoadFile) {
  319. instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
  320. instance->receiver, string_get_cstr(instance->protocol_name));
  321. if(!instance->decoder_result ||
  322. instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
  323. FURI_LOG_E(TAG, "Can't load SubGhzProtocolDecoderBase in phase non-file decoder set");
  324. } else {
  325. protocol_check_result = SubBruteFileResultOk;
  326. }
  327. } else {
  328. // And here we need to set preset enum
  329. instance->preset = subbrute_device_convert_preset(string_get_cstr(instance->preset_name));
  330. protocol_check_result = SubBruteFileResultOk;
  331. }
  332. subghz_receiver_free(instance->receiver);
  333. instance->receiver = NULL;
  334. if(protocol_check_result != SubBruteFileResultOk) {
  335. return SubBruteFileResultProtocolNotFound;
  336. }
  337. instance->has_tail =
  338. (strcmp(string_get_cstr(instance->protocol_name), protocol_princeton) == 0);
  339. // Calc max value
  340. if(instance->attack == SubBruteAttackLoadFile) {
  341. instance->max_value = 0xFF;
  342. } else {
  343. string_t max_value_s;
  344. string_init(max_value_s);
  345. for(uint8_t i = 0; i < instance->bit; i++) {
  346. string_cat_printf(max_value_s, "1");
  347. }
  348. instance->max_value = (uint64_t)strtol(string_get_cstr(max_value_s), NULL, 2);
  349. string_clear(max_value_s);
  350. }
  351. // Now we are ready to set file template for using in the future with snprintf
  352. // for sending attack payload
  353. snprintf(
  354. instance->file_template,
  355. sizeof(instance->file_template),
  356. subbrute_key_file_start,
  357. instance->frequency,
  358. string_get_cstr(instance->preset_name),
  359. string_get_cstr(instance->protocol_name),
  360. instance->bit);
  361. // strncat(instance->file_template, "\n", sizeof(instance->file_template));
  362. // strncat(instance->file_template, subbrute_key_file_key, sizeof(instance->file_template));
  363. // if(instance->has_tail) {
  364. // strncat(
  365. // instance->file_template,
  366. // subbrute_key_file_princeton_end,
  367. // sizeof(instance->file_template));
  368. // }
  369. #ifdef FURI_DEBUG
  370. FURI_LOG_D(TAG, "tail: %d, file_template: %s", instance->has_tail, instance->file_template);
  371. #endif
  372. // Init payload
  373. subbrute_device_create_packet_parsed(instance, instance->key_index, false);
  374. return SubBruteFileResultOk;
  375. }
  376. uint8_t subbrute_device_load_from_file(SubBruteDevice* instance, string_t file_path) {
  377. furi_assert(instance);
  378. #ifdef FURI_DEBUG
  379. FURI_LOG_D(TAG, "subbrute_device_load_from_file: %s", string_get_cstr(file_path));
  380. #endif
  381. SubBruteFileResult result = SubBruteFileResultUnknown;
  382. Storage* storage = furi_record_open(RECORD_STORAGE);
  383. FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
  384. string_t temp_str;
  385. string_init(temp_str);
  386. uint32_t temp_data32;
  387. instance->receiver = subghz_receiver_alloc_init(instance->environment);
  388. subghz_receiver_set_filter(instance->receiver, SubGhzProtocolFlag_Decodable);
  389. furi_hal_subghz_reset();
  390. do {
  391. if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_path))) {
  392. FURI_LOG_E(TAG, "Error open file %s", string_get_cstr(file_path));
  393. result = SubBruteFileResultErrorOpenFile;
  394. break;
  395. }
  396. if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
  397. FURI_LOG_E(TAG, "Missing or incorrect header");
  398. result = SubBruteFileResultMissingOrIncorrectHeader;
  399. break;
  400. }
  401. // Frequency
  402. if(flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
  403. instance->frequency = temp_data32;
  404. if(!furi_hal_subghz_is_tx_allowed(instance->frequency)) {
  405. result = SubBruteFileResultFrequencyNotAllowed;
  406. break;
  407. }
  408. } else {
  409. FURI_LOG_E(TAG, "Missing or incorrect Frequency");
  410. result = SubBruteFileResultMissingOrIncorrectFrequency;
  411. break;
  412. }
  413. // Preset
  414. if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
  415. FURI_LOG_E(TAG, "Preset FAIL");
  416. result = SubBruteFileResultPresetInvalid;
  417. } else {
  418. string_init_set_str(instance->preset_name, string_get_cstr(temp_str));
  419. }
  420. // Protocol
  421. if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
  422. FURI_LOG_E(TAG, "Missing Protocol");
  423. result = SubBruteFileResultMissingProtocol;
  424. break;
  425. } else {
  426. string_init_set_str(instance->protocol_name, string_get_cstr(temp_str));
  427. #ifdef FURI_DEBUG
  428. FURI_LOG_D(TAG, "Protocol: %s", string_get_cstr(instance->protocol_name));
  429. #endif
  430. }
  431. instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
  432. instance->receiver, string_get_cstr(instance->protocol_name));
  433. if(!instance->decoder_result ||
  434. strcmp(string_get_cstr(instance->protocol_name), "RAW") == 0) {
  435. FURI_LOG_E(TAG, "RAW unsupported");
  436. result = SubBruteFileResultProtocolNotSupported;
  437. break;
  438. }
  439. if(instance->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) {
  440. FURI_LOG_E(TAG, "Protocol is dynamic - not supported");
  441. result = SubBruteFileResultDynamicProtocolNotValid;
  442. break;
  443. }
  444. #ifdef FURI_DEBUG
  445. else {
  446. FURI_LOG_D(TAG, "Decoder: %s", instance->decoder_result->protocol->name);
  447. }
  448. #endif
  449. // instance->decoder_result = subghz_receiver_search_decoder_base_by_name(
  450. // instance->receiver, string_get_cstr(instance->protocol_name));
  451. //
  452. // if(!instance->decoder_result) {
  453. // FURI_LOG_E(TAG, "Protocol not found");
  454. // result = SubBruteFileResultProtocolNotFound;
  455. // break;
  456. // }
  457. // Bit
  458. if(!flipper_format_read_uint32(fff_data_file, "Bit", &temp_data32, 1)) {
  459. FURI_LOG_E(TAG, "Missing or incorrect Bit");
  460. result = SubBruteFileResultMissingOrIncorrectBit;
  461. break;
  462. } else {
  463. instance->bit = temp_data32;
  464. #ifdef FURI_DEBUG
  465. FURI_LOG_D(TAG, "Bit: %d", instance->bit);
  466. #endif
  467. }
  468. // Key
  469. if(!flipper_format_read_string(fff_data_file, "Key", temp_str)) {
  470. FURI_LOG_E(TAG, "Missing or incorrect Key");
  471. result = SubBruteFileResultMissingOrIncorrectKey;
  472. break;
  473. } else {
  474. snprintf(
  475. instance->file_key, sizeof(instance->file_key), "%s", string_get_cstr(temp_str));
  476. #ifdef FURI_DEBUG
  477. FURI_LOG_D(TAG, "Key: %s", instance->file_key);
  478. #endif
  479. }
  480. // TE
  481. if(!flipper_format_read_uint32(fff_data_file, "TE", &temp_data32, 1)) {
  482. FURI_LOG_E(TAG, "Missing or incorrect TE");
  483. //result = SubBruteFileResultMissingOrIncorrectTe;
  484. //break;
  485. } else {
  486. instance->te = temp_data32;
  487. instance->has_tail = true;
  488. }
  489. // Repeat
  490. if(flipper_format_read_uint32(fff_data_file, "Repeat", &temp_data32, 1)) {
  491. #ifdef FURI_DEBUG
  492. FURI_LOG_D(TAG, "Repeat: %d", temp_data32);
  493. #endif
  494. instance->repeat = temp_data32;
  495. } else {
  496. #ifdef FURI_DEBUG
  497. FURI_LOG_D(TAG, "Repeat: 3 (default)");
  498. #endif
  499. instance->repeat = 3;
  500. }
  501. result = SubBruteFileResultOk;
  502. } while(0);
  503. string_clear(temp_str);
  504. flipper_format_file_close(fff_data_file);
  505. flipper_format_free(fff_data_file);
  506. furi_record_close(RECORD_STORAGE);
  507. subghz_receiver_free(instance->receiver);
  508. instance->decoder_result = NULL;
  509. instance->receiver = NULL;
  510. if(result == SubBruteFileResultOk) {
  511. #ifdef FURI_DEBUG
  512. FURI_LOG_D(TAG, "Loaded successfully");
  513. #endif
  514. }
  515. return result;
  516. }
  517. void subbrute_device_attack_set_default_values(
  518. SubBruteDevice* instance,
  519. SubBruteAttacks default_attack) {
  520. furi_assert(instance);
  521. #ifdef FURI_DEBUG
  522. FURI_LOG_D(TAG, "subbrute_device_attack_set_default_values");
  523. #endif
  524. instance->attack = default_attack;
  525. instance->key_index = 0x00;
  526. instance->load_index = 0x00;
  527. memset(instance->file_template, 0, sizeof(instance->file_template));
  528. memset(instance->current_key, 0, sizeof(instance->current_key));
  529. memset(instance->text_store, 0, sizeof(instance->text_store));
  530. memset(instance->payload, 0, sizeof(instance->payload));
  531. if(default_attack != SubBruteAttackLoadFile) {
  532. memset(instance->file_key, 0, sizeof(instance->file_key));
  533. instance->max_value = (uint64_t)0x00;
  534. string_clear(instance->protocol_name);
  535. string_clear(instance->preset_name);
  536. string_clear(instance->load_path);
  537. string_init(instance->load_path);
  538. string_init_set_str(instance->protocol_name, protocol_raw);
  539. string_init_set_str(instance->preset_name, preset_ook650_async);
  540. instance->preset = FuriHalSubGhzPresetOok650Async;
  541. instance->repeat = 5;
  542. instance->te = 0;
  543. instance->has_tail = false;
  544. }
  545. #ifdef FURI_DEBUG
  546. FURI_LOG_D(
  547. TAG, "subbrute_device_attack_set_default_values done. has_tail: %d", instance->has_tail);
  548. //furi_delay_ms(250);
  549. #endif
  550. }
  551. FuriHalSubGhzPreset subbrute_device_convert_preset(const char* preset_name) {
  552. string_t preset;
  553. string_init_set_str(preset, preset_name);
  554. FuriHalSubGhzPreset preset_value;
  555. if(string_cmp_str(preset, preset_ook270_async) == 0) {
  556. preset_value = FuriHalSubGhzPresetOok270Async;
  557. } else if(string_cmp_str(preset, preset_ook650_async) == 0) {
  558. preset_value = FuriHalSubGhzPresetOok650Async;
  559. } else if(string_cmp_str(preset, preset_2fsk_dev238_async) == 0) {
  560. preset_value = FuriHalSubGhzPreset2FSKDev238Async;
  561. } else if(string_cmp_str(preset, preset_2fsk_dev476_async) == 0) {
  562. preset_value = FuriHalSubGhzPreset2FSKDev476Async;
  563. } else if(string_cmp_str(preset, preset_msk99_97_kb_async) == 0) {
  564. preset_value = FuriHalSubGhzPresetMSK99_97KbAsync;
  565. } else if(string_cmp_str(preset, preset_gfs99_97_kb_async) == 0) {
  566. preset_value = FuriHalSubGhzPresetMSK99_97KbAsync;
  567. } else {
  568. preset_value = FuriHalSubGhzPresetCustom;
  569. }
  570. string_clear(preset);
  571. return preset_value;
  572. }