subbrute_device.c 22 KB

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