nfc_device.h 1.6 KB

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