nfc_emulate.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "nfc_emulate.h"
  2. #include <furi.h>
  3. #include <api-hal.h>
  4. #include <input/input.h>
  5. #include "../nfc_i.h"
  6. struct NfcEmulate {
  7. NfcCommon* nfc_common;
  8. View* view;
  9. };
  10. void nfc_emulate_draw(Canvas* canvas, void* model) {
  11. canvas_clear(canvas);
  12. canvas_set_font(canvas, FontPrimary);
  13. canvas_draw_str(canvas, 0, 12, "Emulating NFC-A");
  14. canvas_set_font(canvas, FontSecondary);
  15. canvas_draw_str(canvas, 2, 22, "Type: T2T");
  16. canvas_draw_str(canvas, 2, 32, "UID length: 7");
  17. canvas_draw_str(canvas, 2, 42, "UID: 36 9C E7 B1 0A C1 34");
  18. canvas_draw_str(canvas, 2, 52, "SAK: 00 ATQA: 00/44");
  19. }
  20. bool nfc_emulate_input(InputEvent* event, void* context) {
  21. if(event->key == InputKeyBack) {
  22. return false;
  23. }
  24. return true;
  25. }
  26. void nfc_emulate_enter(void* context) {
  27. furi_assert(context);
  28. NfcEmulate* nfc_emulate = (NfcEmulate*)context;
  29. nfc_worker_start(
  30. nfc_emulate->nfc_common->worker,
  31. NfcWorkerStateEmulate,
  32. &nfc_emulate->nfc_common->worker_result,
  33. NULL,
  34. NULL);
  35. }
  36. void nfc_emulate_exit(void* context) {
  37. furi_assert(context);
  38. NfcEmulate* nfc_emulate = (NfcEmulate*)context;
  39. nfc_worker_stop(nfc_emulate->nfc_common->worker);
  40. }
  41. NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common) {
  42. furi_assert(nfc_common);
  43. NfcEmulate* nfc_emulate = furi_alloc(sizeof(NfcEmulate));
  44. nfc_emulate->nfc_common = nfc_common;
  45. // View allocation and configuration
  46. nfc_emulate->view = view_alloc();
  47. view_set_context(nfc_emulate->view, nfc_emulate);
  48. view_set_draw_callback(nfc_emulate->view, (ViewDrawCallback)nfc_emulate_draw);
  49. view_set_input_callback(nfc_emulate->view, nfc_emulate_input);
  50. view_set_enter_callback(nfc_emulate->view, nfc_emulate_enter);
  51. view_set_exit_callback(nfc_emulate->view, nfc_emulate_exit);
  52. return nfc_emulate;
  53. }
  54. void nfc_emulate_free(NfcEmulate* nfc_emulate) {
  55. furi_assert(nfc_emulate);
  56. view_free(nfc_emulate->view);
  57. free(nfc_emulate);
  58. }
  59. View* nfc_emulate_get_view(NfcEmulate* nfc_emulate) {
  60. furi_assert(nfc_emulate);
  61. return nfc_emulate->view;
  62. }