subbrute_device.c 22 KB

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