nfc_device.h 2.3 KB

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