nfc_device.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <storage/storage.h>
  5. #include <dialogs/dialogs.h>
  6. #include "mifare_ultralight.h"
  7. #define NFC_DEV_NAME_MAX_LEN 22
  8. #define NFC_FILE_NAME_MAX_LEN 120
  9. typedef enum {
  10. NfcDeviceNfca,
  11. NfcDeviceNfcb,
  12. NfcDeviceNfcf,
  13. NfcDeviceNfcv,
  14. } NfcDeviceType;
  15. typedef enum {
  16. NfcDeviceProtocolUnknown,
  17. NfcDeviceProtocolEMV,
  18. NfcDeviceProtocolMifareUl,
  19. } NfcProtocol;
  20. typedef enum {
  21. NfcDeviceSaveFormatUid,
  22. NfcDeviceSaveFormatBankCard,
  23. NfcDeviceSaveFormatMifareUl,
  24. } NfcDeviceSaveFormat;
  25. typedef struct {
  26. uint8_t uid_len;
  27. uint8_t uid[10];
  28. uint8_t atqa[2];
  29. uint8_t sak;
  30. NfcDeviceType device;
  31. NfcProtocol protocol;
  32. } NfcDeviceCommonData;
  33. typedef struct {
  34. char name[32];
  35. uint8_t aid[16];
  36. uint16_t aid_len;
  37. uint8_t number[10];
  38. uint8_t number_len;
  39. uint8_t exp_mon;
  40. uint8_t exp_year;
  41. uint16_t country_code;
  42. uint16_t currency_code;
  43. } NfcEmvData;
  44. typedef struct {
  45. NfcDeviceCommonData nfc_data;
  46. union {
  47. NfcEmvData emv_data;
  48. MifareUlData mf_ul_data;
  49. };
  50. } NfcDeviceData;
  51. typedef struct {
  52. Storage* storage;
  53. DialogsApp* dialogs;
  54. NfcDeviceData dev_data;
  55. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  56. char file_name[NFC_FILE_NAME_MAX_LEN];
  57. NfcDeviceSaveFormat format;
  58. bool shadow_file_exist;
  59. } NfcDevice;
  60. NfcDevice* nfc_device_alloc();
  61. void nfc_device_free(NfcDevice* nfc_dev);
  62. void nfc_device_set_name(NfcDevice* dev, const char* name);
  63. bool nfc_device_save(NfcDevice* dev, const char* dev_name);
  64. bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name);
  65. bool nfc_device_load(NfcDevice* dev, const char* file_path);
  66. bool nfc_file_select(NfcDevice* dev);
  67. void nfc_device_clear(NfcDevice* dev);
  68. bool nfc_device_delete(NfcDevice* dev);
  69. bool nfc_device_restore(NfcDevice* dev);