nfc_magic_scene_key_input.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../nfc_magic_app_i.h"
  2. #include "protocols/gen4/gen4.h"
  3. #include <bit_lib.h>
  4. #include <string.h>
  5. void nfc_magic_scene_key_input_byte_input_callback(void* context) {
  6. NfcMagicApp* instance = context;
  7. view_dispatcher_send_custom_event(
  8. instance->view_dispatcher, NfcMagicAppCustomEventByteInputDone);
  9. }
  10. void nfc_magic_scene_key_input_on_enter(void* context) {
  11. NfcMagicApp* instance = context;
  12. // Setup view
  13. ByteInput* byte_input = instance->byte_input;
  14. byte_input_set_header_text(byte_input, "Enter the password in hex");
  15. byte_input_set_result_callback(
  16. byte_input,
  17. nfc_magic_scene_key_input_byte_input_callback,
  18. NULL,
  19. instance,
  20. instance->byte_input_store,
  21. NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
  22. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewByteInput);
  23. }
  24. bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event) {
  25. NfcMagicApp* instance = context;
  26. bool consumed = false;
  27. if(event.type == SceneManagerEventTypeCustom) {
  28. if(event.event == NfcMagicAppCustomEventByteInputDone) {
  29. // TODO: NEED TEST
  30. if(scene_manager_has_previous_scene(instance->scene_manager, NfcMagicSceneGen4Menu)) {
  31. memcpy(
  32. instance->gen4_password_new.bytes,
  33. instance->byte_input_store,
  34. GEN4_PASSWORD_LEN);
  35. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
  36. } else {
  37. memcpy(
  38. instance->gen4_password.bytes, instance->byte_input_store, GEN4_PASSWORD_LEN);
  39. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
  40. }
  41. consumed = true;
  42. }
  43. }
  44. return consumed;
  45. }
  46. void nfc_magic_scene_key_input_on_exit(void* context) {
  47. NfcMagicApp* instance = context;
  48. // Clear view
  49. byte_input_set_result_callback(instance->byte_input, NULL, NULL, NULL, NULL, 0);
  50. byte_input_set_header_text(instance->byte_input, "");
  51. }