nfc_scene_emulate_uid.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <nfc/scenes/nfc_scene_emulate_uid.h>
  2. #include <furi.h>
  3. #include "../nfc_i.h"
  4. const void nfc_scene_emulate_uid_on_enter(void* context) {
  5. Nfc* nfc = (Nfc*)context;
  6. // Setup view
  7. Popup* popup = nfc->popup;
  8. NfcDeviceData* data = &nfc->device.data;
  9. if(strcmp(nfc->device.dev_name, "")) {
  10. nfc_set_text_store(nfc, "%s", nfc->device.dev_name);
  11. } else if(data->uid_len == 4) {
  12. nfc_set_text_store(
  13. nfc, "%02X %02X %02X %02X", data->uid[0], data->uid[1], data->uid[2], data->uid[3]);
  14. } else if(data->uid_len == 7) {
  15. nfc_set_text_store(
  16. nfc,
  17. "%02X %02X %02X %02X\n%02X %02X %02X",
  18. data->uid[0],
  19. data->uid[1],
  20. data->uid[2],
  21. data->uid[3],
  22. data->uid[4],
  23. data->uid[5],
  24. data->uid[6]);
  25. }
  26. popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
  27. popup_set_header(popup, "Emulating UID", 56, 31, AlignLeft, AlignTop);
  28. popup_set_text(popup, nfc->text_store, 56, 43, AlignLeft, AlignTop);
  29. // Setup and start worker
  30. nfc_worker_set_emulation_params(nfc->nfc_common.worker, data);
  31. nfc_worker_start(
  32. nfc->nfc_common.worker, NfcWorkerStateEmulate, &nfc->nfc_common.worker_result, NULL, nfc);
  33. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewPopup);
  34. }
  35. const bool nfc_scene_emulate_uid_on_event(void* context, uint32_t event) {
  36. return false;
  37. }
  38. const void nfc_scene_emulate_uid_on_exit(void* context) {
  39. Nfc* nfc = (Nfc*)context;
  40. // Stop worker
  41. nfc_worker_stop(nfc->nfc_common.worker);
  42. // Clear view
  43. Popup* popup = nfc->popup;
  44. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  45. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  46. popup_set_icon(popup, 0, 0, NULL);
  47. }
  48. AppScene* nfc_scene_emulate_uid_alloc() {
  49. AppScene* scene = furi_alloc(sizeof(AppScene));
  50. scene->id = NfcSceneEmulateUID;
  51. scene->on_enter = nfc_scene_emulate_uid_on_enter;
  52. scene->on_event = nfc_scene_emulate_uid_on_event;
  53. scene->on_exit = nfc_scene_emulate_uid_on_exit;
  54. return scene;
  55. }
  56. void nfc_scene_emulate_uid_free(AppScene* scene) {
  57. free(scene);
  58. }