nfc_scene_emulate_uid.c 2.1 KB

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