nfc_t4t_tlv_block.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NFC_T4T_TLV_BLOCK_H__
  41. #define NFC_T4T_TLV_BLOCK_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_t4t_tlv_block File Control TLV block parser for Type 4 Tag.
  45. * @{
  46. * @ingroup nfc_t4t_cc_file
  47. *
  48. * @brief File Control TLV block parser for Type 4 Tag (T4T).
  49. *
  50. */
  51. #include <stdint.h>
  52. #include "sdk_errors.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. #define CONTROL_FILE_READ_ACCESS_GRANTED 0x00 ///< Read access granted without any security.
  57. /**
  58. * @name Possible values of file write access condition field.
  59. * @{
  60. */
  61. #define CONTROL_FILE_WRITE_ACCESS_GRANTED 0x00 ///< Write access granted without any security.
  62. #define CONTROL_FILE_WRITE_ACCESS_DISABLED 0xFF ///< No write access granted without any security (read-only).
  63. /** @} */
  64. /**
  65. * @brief Possible types of File Control TLV for Type 4 Tag.
  66. */
  67. typedef enum
  68. {
  69. NDEF_FILE_CONTROL_TLV = 0x04, ///< Control information concerning the EF file with short NDEF message.
  70. PROPRIETARY_FILE_CONTROL_TLV = 0x05, ///< Control information concerning the Proprietary file with proprietary data.
  71. EXTENDED_NDEF_FILE_CONTROL_TLV = 0x06 ///< Control information concerning the EF file with long NDEF message.
  72. } nfc_t4t_tlv_block_types_t;
  73. /**
  74. * @brief File content descriptor.
  75. */
  76. typedef struct
  77. {
  78. uint8_t * p_content; ///< Pointer to the file content.
  79. uint16_t len; ///< Length of file content.
  80. } nfc_t4t_file_t;
  81. /**
  82. * @brief Extended NDEF/NDEF/Proprietary File Control Value descriptor.
  83. */
  84. typedef struct
  85. {
  86. nfc_t4t_file_t file; ///< Pointer to the described file content.
  87. uint32_t max_file_size; ///< Maximum size (in bytes) of the file.
  88. uint16_t file_id; ///< File identifier.
  89. uint8_t read_access; ///< File read access condition.
  90. uint8_t write_access; ///< File write access condition.
  91. } nfc_t4t_file_control_val_t;
  92. /**
  93. * @brief File Control TLV block descriptor.
  94. */
  95. typedef struct
  96. {
  97. nfc_t4t_file_control_val_t value; ///< Value field descriptor.
  98. uint16_t length; ///< Length of the value field.
  99. uint8_t type; ///< Type of the TLV block.
  100. } nfc_t4t_tlv_block_t;
  101. /**
  102. * @brief Function for parsing raw data of File Control TLV, read from a Type 4 Tag.
  103. *
  104. * This function parses raw data of File Control TLV and stores the results in its
  105. * descriptor.
  106. *
  107. * @param[in,out] p_file_control_tlv Pointer to the File Control TLV that will be filled with
  108. * parsed data.
  109. * @param[in] p_raw_data Pointer to the buffer with raw TLV data.
  110. * @param[in,out] p_len In: Buffer length with TLV blocks.
  111. * Out: Total length of first identified TLV within the buffer.
  112. *
  113. * @retval NRF_SUCCESS If operation was successful.
  114. * @retval NRF_ERROR_INVALID_LENGTH If provided buffer length is too small for TLV block.
  115. * @retval NRF_ERROR_INVALID_DATA If any TLV block field contains invalid data.
  116. */
  117. ret_code_t nfc_t4t_file_control_tlv_parse(nfc_t4t_tlv_block_t * p_file_control_tlv,
  118. uint8_t * p_raw_data,
  119. uint16_t * p_len);
  120. /**
  121. * @brief Function for printing TLV block descriptor.
  122. *
  123. * This function prints TLV block descriptor.
  124. *
  125. * @param[in] num TLV block number.
  126. * @param[in] p_t4t_tlv_block Pointer to the TLV block descriptor.
  127. */
  128. void nfc_t4t_file_control_tlv_printout(uint8_t num, nfc_t4t_tlv_block_t * p_t4t_tlv_block);
  129. /** @} */
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* NFC_T4T_TLV_BLOCK_H__ */