config.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. scene_manager_previous_scene(ctx->scene_manager);
  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. // Add item to be used as attack name header
  40. //variable_item_list_add(list, ctx->attack->title, 0, NULL, NULL);
  41. //variable_item_list_set_header(list, ctx->attack->title);
  42. config_bool(list, "Random MAC", &ctx->attack->payload.random_mac);
  43. variable_item_list_set_enter_callback(list, config_callback, ctx);
  44. if(!ctx->attack->protocol) {
  45. variable_item_list_add(list, "None shall escape the SINK", 0, NULL, NULL);
  46. } else if(ctx->attack->protocol->extra_config) {
  47. ctx->fallback_config_enter = config_callback;
  48. ctx->attack->protocol->extra_config(ctx);
  49. }
  50. config_bool(list, "LED Indicator", &ctx->led_indicator);
  51. variable_item_list_add(list, "Lock Keyboard", 0, NULL, NULL);
  52. variable_item_list_set_selected_item(
  53. list, scene_manager_get_scene_state(ctx->scene_manager, SceneConfig));
  54. view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewVariableItemList);
  55. }
  56. bool scene_config_on_event(void* _ctx, SceneManagerEvent event) {
  57. UNUSED(_ctx);
  58. UNUSED(event);
  59. return false;
  60. }
  61. void scene_config_on_exit(void* _ctx) {
  62. Ctx* ctx = _ctx;
  63. variable_item_list_reset(ctx->variable_item_list);
  64. }