NT3H.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2021 Huawei Device Co., Ltd.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef NT3H_H_
  16. #define NT3H_H_
  17. #include "stdbool.h"
  18. #include <stdint.h>
  19. #define NT3H1X_SLAVE_ADDRESS 0x55
  20. #define MANUFACTORING_DATA_REG 0x0
  21. #define USER_START_REG 0x1
  22. #define USER_END_REG 0x77
  23. #define CONFIG_REG 0x7A
  24. #define SRAM_START_REG 0xF8
  25. #define SRAM_END_REG 0xFB // just the first 8 bytes
  26. #define SESSION_REG 0xFE
  27. #define NFC_PAGE_SIZE 16
  28. typedef enum {
  29. NT3HERROR_NO_ERROR,
  30. NT3HERROR_READ_HEADER,
  31. NT3HERROR_WRITE_HEADER,
  32. NT3HERROR_INVALID_USER_MEMORY_PAGE,
  33. NT3HERROR_READ_USER_MEMORY_PAGE,
  34. NT3HERROR_WRITE_USER_MEMORY_PAGE,
  35. NT3HERROR_ERASE_USER_MEMORY_PAGE,
  36. NT3HERROR_READ_NDEF_TEXT,
  37. NT3HERROR_WRITE_NDEF_TEXT,
  38. NT3HERROR_TYPE_NOT_SUPPORTED
  39. }NT3HerrNo;
  40. extern uint8_t nfcPageBuffer[NFC_PAGE_SIZE];
  41. extern NT3HerrNo errNo;
  42. typedef enum {
  43. NDEFFirstPos,
  44. NDEFMiddlePos,
  45. NDEFLastPos
  46. } RecordPosEnu;
  47. /*
  48. * This strucure is used in the ADD record functionality
  49. * to store the last nfc page information, in order to continue from that point.
  50. */
  51. typedef struct {
  52. uint8_t page;
  53. uint16_t usedBytes;
  54. } UncompletePageStr;
  55. typedef struct {
  56. RecordPosEnu ndefPosition;
  57. uint8_t rtdType;
  58. uint8_t *rtdPayload;
  59. uint16_t rtdPayloadlength;
  60. void *specificRtdData;
  61. }NDEFDataStr;
  62. void NT3HGetNxpSerialNumber(uint8_t *buffer);
  63. /*
  64. * read the user data from the requested page
  65. * first page is 0
  66. *
  67. * the NT3H1201 has 119 PAges
  68. * the NT3H1101 has 56 PAges (but the 56th page has only 8 Bytes)
  69. */
  70. bool NT3HReadUserData(uint8_t page);
  71. /*
  72. * Write data information from the starting requested page.
  73. * If the dataLen is bigger of NFC_PAGE_SIZE, the consecuiteve needed
  74. * pages will be automatically used.
  75. *
  76. * The functions stops to the latest available page.
  77. *
  78. first page is 0
  79. * the NT3H1201 has 119 PAges
  80. * the NT3H1101 has 56 PAges (but the 56th page has only 8 Bytes)
  81. */
  82. bool NT3HWriteUserData(uint8_t page, const uint8_t* data);
  83. /*
  84. * The function read the first page of user data where is stored the NFC Header.
  85. * It is important because it contains the total size of all the stored records.
  86. *
  87. * param endRecordsPtr return the value of the total size excluding the NDEF_END_BYTE
  88. * param ndefHeader Store the NDEF Header of the first record
  89. */
  90. bool NT3HReadHeaderNfc(uint8_t *endRecordsPtr, uint8_t *ndefHeader);
  91. /*
  92. * The function write the first page of user data where is stored the NFC Header.
  93. * update the bytes that contains the payload Length and the first NDEF Header
  94. *
  95. * param endRecordsPtr The value of the total size excluding the NDEF_END_BYTE
  96. * param ndefHeader The NDEF Header of the first record
  97. */
  98. bool NT3HWriteHeaderNfc(uint8_t endRecordsPtr, uint8_t ndefHeader);
  99. bool getSessionReg(void);
  100. bool getNxpUserData(char* buffer);
  101. bool NT3HReadSram(void);
  102. bool NT3HReadSession(void);
  103. bool NT3HReadConfiguration(uint8_t *configuration);
  104. bool NT3HEraseAllTag(void);
  105. bool NT3HReaddManufactoringData(uint8_t *manuf) ;
  106. bool NT3HResetUserData(void);
  107. void NT3H1101_Read_Userpages(uint8_t pagenumber,uint8_t *outbuf);
  108. #endif /* NFC_H_ */