config.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "../ble_spam.h"
  2. #include "protocols/_protocols.h"
  3. static void _config_bool(VariableItem* item) {
  4. bool* value = variable_item_get_context(item);
  5. *value = variable_item_get_current_value_index(item);
  6. variable_item_set_current_value_text(item, *value ? "ON" : "OFF");
  7. }
  8. static void config_bool(VariableItemList* list, const char* name, bool* value) {
  9. VariableItem* item = variable_item_list_add(list, name, 2, _config_bool, value);
  10. variable_item_set_current_value_index(item, *value);
  11. variable_item_set_current_value_text(item, *value ? "ON" : "OFF");
  12. }
  13. static void config_callback(void* _ctx, uint32_t index) {
  14. Ctx* ctx = _ctx;
  15. scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
  16. if(!ctx->attack->protocol) {
  17. index--;
  18. } else if(ctx->attack->protocol->config_count) {
  19. uint8_t extra = ctx->attack->protocol->config_count(&ctx->attack->payload);
  20. if(index > extra) index -= extra;
  21. }
  22. switch(index) {
  23. case ConfigRandomMac:
  24. break;
  25. case ConfigLedIndicator:
  26. break;
  27. case ConfigLockKeyboard:
  28. ctx->lock_keyboard = true;
  29. view_dispatcher_send_custom_event(ctx->view_dispatcher, 0);
  30. notification_message_block(ctx->notification, &sequence_display_backlight_off);
  31. break;
  32. default:
  33. break;
  34. }
  35. }
  36. void scene_config_on_enter(void* _ctx) {
  37. Ctx* ctx = _ctx;
  38. VariableItemList* list = ctx->variable_item_list;
  39. variable_item_list_set_header(list, ctx->attack->title);
  40. config_bool(list, "Random MAC", &ctx->attack->payload.random_mac);
  41. variable_item_list_set_enter_callback(list, config_callback, ctx);
  42. if(!ctx->attack->protocol) {
  43. variable_item_list_add(list, "None shall escape the SINK", 0, NULL, NULL);
  44. } else if(ctx->attack->protocol->extra_config) {
  45. ctx->fallback_config_enter = config_callback;
  46. ctx->attack->protocol->extra_config(ctx);
  47. }
  48. config_bool(list, "LED Indicator", &ctx->led_indicator);
  49. variable_item_list_add(list, "Lock Keyboard", 0, NULL, NULL);
  50. variable_item_list_set_selected_item(
  51. list, scene_manager_get_scene_state(ctx->scene_manager, SceneConfig));
  52. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewVariableItemList);
  53. }
  54. bool scene_config_on_event(void* _ctx, SceneManagerEvent event) {
  55. Ctx* ctx = _ctx;
  56. if(event.type == SceneManagerEventTypeCustom) {
  57. scene_manager_previous_scene(ctx->scene_manager);
  58. return true;
  59. }
  60. return false;
  61. }
  62. void scene_config_on_exit(void* _ctx) {
  63. Ctx* ctx = _ctx;
  64. variable_item_list_reset(ctx->variable_item_list);
  65. }