nfc_scene_mf_ultralight_emulate.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../nfc_i.h"
  2. #define NFC_MF_UL_DATA_NOT_CHANGED (0UL)
  3. #define NFC_MF_UL_DATA_CHANGED (1UL)
  4. bool nfc_mf_ultralight_emulate_worker_callback(NfcWorkerEvent event, void* context) {
  5. UNUSED(event);
  6. Nfc* nfc = context;
  7. scene_manager_set_scene_state(
  8. nfc->scene_manager, NfcSceneMfUltralightEmulate, NFC_MF_UL_DATA_CHANGED);
  9. return true;
  10. }
  11. void nfc_scene_mf_ultralight_emulate_on_enter(void* context) {
  12. Nfc* nfc = context;
  13. // Setup view
  14. MfUltralightType type = nfc->dev->dev_data.mf_ul_data.type;
  15. bool is_ultralight = (type == MfUltralightTypeUL11) || (type == MfUltralightTypeUL21) ||
  16. (type == MfUltralightTypeUnknown);
  17. Popup* popup = nfc->popup;
  18. popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop);
  19. if(strcmp(nfc->dev->dev_name, "") != 0) {
  20. nfc_text_store_set(nfc, "%s", nfc->dev->dev_name);
  21. } else if(is_ultralight) {
  22. nfc_text_store_set(nfc, "MIFARE\nUltralight");
  23. } else {
  24. nfc_text_store_set(nfc, "MIFARE\nNTAG");
  25. }
  26. popup_set_icon(popup, 0, 3, &I_NFC_dolphin_emulation_47x61);
  27. popup_set_text(popup, nfc->text_store, 90, 28, AlignCenter, AlignTop);
  28. // Setup and start worker
  29. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
  30. nfc_worker_start(
  31. nfc->worker,
  32. NfcWorkerStateMfUltralightEmulate,
  33. &nfc->dev->dev_data,
  34. nfc_mf_ultralight_emulate_worker_callback,
  35. nfc);
  36. nfc_blink_emulate_start(nfc);
  37. }
  38. bool nfc_scene_mf_ultralight_emulate_on_event(void* context, SceneManagerEvent event) {
  39. Nfc* nfc = context;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeBack) {
  42. // Stop worker
  43. nfc_worker_stop(nfc->worker);
  44. // Check if data changed and save in shadow file
  45. if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfUltralightEmulate) ==
  46. NFC_MF_UL_DATA_CHANGED) {
  47. scene_manager_set_scene_state(
  48. nfc->scene_manager, NfcSceneMfUltralightEmulate, NFC_MF_UL_DATA_NOT_CHANGED);
  49. // Save shadow file
  50. if(furi_string_size(nfc->dev->load_path)) {
  51. nfc_device_save_shadow(nfc->dev, furi_string_get_cstr(nfc->dev->load_path));
  52. }
  53. }
  54. consumed = false;
  55. }
  56. return consumed;
  57. }
  58. void nfc_scene_mf_ultralight_emulate_on_exit(void* context) {
  59. Nfc* nfc = context;
  60. // Clear view
  61. popup_reset(nfc->popup);
  62. nfc_blink_stop(nfc);
  63. }