nfc_emulate.c 2.2 KB

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