nfc_device.h 2.1 KB

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