nfc_device.h 1.9 KB

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