nfc_device.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <storage/storage.h>
  5. #include <dialogs/dialogs.h>
  6. #include <lib/nfc_protocols/mifare_ultralight.h>
  7. #include <lib/nfc_protocols/mifare_classic.h>
  8. #include <lib/nfc_protocols/mifare_desfire.h>
  9. #define NFC_DEV_NAME_MAX_LEN 22
  10. #define NFC_FILE_NAME_MAX_LEN 120
  11. #define NFC_READER_DATA_MAX_SIZE 64
  12. #define NFC_APP_FOLDER "/any/nfc"
  13. #define NFC_APP_EXTENSION ".nfc"
  14. #define NFC_APP_SHADOW_EXTENSION ".shd"
  15. typedef enum {
  16. NfcDeviceNfca,
  17. NfcDeviceNfcb,
  18. NfcDeviceNfcf,
  19. NfcDeviceNfcv,
  20. } NfcDeviceType;
  21. typedef enum {
  22. NfcDeviceProtocolUnknown,
  23. NfcDeviceProtocolEMV,
  24. NfcDeviceProtocolMifareUl,
  25. NfcDeviceProtocolMifareClassic,
  26. NfcDeviceProtocolMifareDesfire,
  27. } NfcProtocol;
  28. typedef enum {
  29. NfcDeviceSaveFormatUid,
  30. NfcDeviceSaveFormatBankCard,
  31. NfcDeviceSaveFormatMifareUl,
  32. NfcDeviceSaveFormatMifareClassic,
  33. NfcDeviceSaveFormatMifareDesfire,
  34. } NfcDeviceSaveFormat;
  35. typedef struct {
  36. uint8_t uid_len;
  37. uint8_t uid[10];
  38. uint8_t atqa[2];
  39. uint8_t sak;
  40. NfcDeviceType device;
  41. NfcProtocol protocol;
  42. } NfcDeviceCommonData;
  43. typedef struct {
  44. char name[32];
  45. uint8_t aid[16];
  46. uint16_t aid_len;
  47. uint8_t number[10];
  48. uint8_t number_len;
  49. uint8_t exp_mon;
  50. uint8_t exp_year;
  51. uint16_t country_code;
  52. uint16_t currency_code;
  53. } NfcEmvData;
  54. typedef struct {
  55. uint8_t data[NFC_READER_DATA_MAX_SIZE];
  56. uint16_t size;
  57. } NfcReaderRequestData;
  58. typedef struct {
  59. NfcDeviceCommonData nfc_data;
  60. NfcReaderRequestData reader_data;
  61. union {
  62. NfcEmvData emv_data;
  63. MifareUlData mf_ul_data;
  64. MfClassicData mf_classic_data;
  65. MifareDesfireData mf_df_data;
  66. };
  67. } NfcDeviceData;
  68. typedef struct {
  69. Storage* storage;
  70. DialogsApp* dialogs;
  71. NfcDeviceData dev_data;
  72. char dev_name[NFC_DEV_NAME_MAX_LEN + 1];
  73. char file_name[NFC_FILE_NAME_MAX_LEN];
  74. NfcDeviceSaveFormat format;
  75. bool shadow_file_exist;
  76. } NfcDevice;
  77. NfcDevice* nfc_device_alloc();
  78. void nfc_device_free(NfcDevice* nfc_dev);
  79. void nfc_device_set_name(NfcDevice* dev, const char* name);
  80. bool nfc_device_save(NfcDevice* dev, const char* dev_name);
  81. bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name);
  82. bool nfc_device_load(NfcDevice* dev, const char* file_path);
  83. bool nfc_file_select(NfcDevice* dev);
  84. void nfc_device_data_clear(NfcDeviceData* dev);
  85. void nfc_device_clear(NfcDevice* dev);
  86. bool nfc_device_delete(NfcDevice* dev);
  87. bool nfc_device_restore(NfcDevice* dev);