nfc_text_rec.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /**
  2. * Copyright (c) 2015 - 2019, 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_TEXT_REC_H__
  41. #define NFC_TEXT_REC_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_text_rec Text records
  45. * @{
  46. * @ingroup nfc_ndef_messages
  47. *
  48. * @brief Generation of NFC NDEF Text record descriptions.
  49. *
  50. */
  51. #include "nfc_ndef_record.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**
  56. * @brief Type of the Unicode Transformation Format.
  57. *
  58. * Values to specify the type of UTF for an NFC NDEF Text record.
  59. */
  60. typedef enum
  61. {
  62. UTF_8 = 0, ///< Unicode Transformation Format 8.
  63. UTF_16 = 1, ///< Unicode Transformation Format 16.
  64. } nfc_text_rec_utf_type_t;
  65. /**
  66. * @brief Text record payload descriptor.
  67. */
  68. typedef struct
  69. {
  70. nfc_text_rec_utf_type_t utf; ///< Type of the Unicode Transformation Format.
  71. uint8_t const * p_lang_code; ///< Pointer to the IANA language code.
  72. uint8_t lang_code_len; ///< Length of the IANA language code.
  73. uint8_t const * p_data; ///< Pointer to the user text.
  74. uint32_t data_len; ///< Length of the user text.
  75. } nfc_text_rec_payload_desc_t;
  76. /**
  77. * @brief Constructor for an NFC NDEF Text record payload.
  78. *
  79. * @param[in] p_nfc_rec_text_payload_desc Pointer to the Text record description.
  80. * @param[out] p_buff Pointer to the payload destination. If NULL, function will
  81. * calculate the expected size of the Text record payload.
  82. *
  83. * @param[in,out] p_len Size of the available memory to write as input.
  84. * Size of the generated record payload as output.
  85. */
  86. ret_code_t nfc_text_rec_payload_constructor(nfc_text_rec_payload_desc_t * p_nfc_rec_text_payload_desc,
  87. uint8_t * p_buff,
  88. uint32_t * p_len);
  89. /**
  90. * @brief External reference to the type field of the Text record, defined in the
  91. * file @c nfc_text_rec.c. It is used in the @ref NFC_NDEF_TEXT_RECORD_DESC_DEF macro.
  92. */
  93. extern const uint8_t nfc_text_rec_type_field[];
  94. /**
  95. * @brief Size of the type field of the Text record, defined in the
  96. * file @c nfc_text_rec.c. It is used in the @ref NFC_NDEF_TEXT_RECORD_DESC_DEF macro.
  97. */
  98. #define NFC_TEXT_REC_TYPE_LENGTH 1
  99. /**
  100. *@brief Macro for creating and initializing an NFC NDEF record descriptor for a Text record.
  101. *
  102. * This macro creates and initializes an instance of type @ref nfc_ndef_record_desc_t and
  103. * an instance of type @ref nfc_text_rec_payload_desc_t, which together constitute
  104. * an instance of a Text record.
  105. *
  106. * Use the macro @ref NFC_NDEF_TEXT_RECORD_DESC to access the NDEF Text record descriptor instance.
  107. *
  108. * @param[in] NAME Name of the created record descriptor instance.
  109. * @param[in] UTF Unicode Transformation Format.
  110. * @param[in] P_LANG_CODE Pointer to the IANA language code.
  111. * @param[in] LANG_CODE_LEN Length of the IANA language code.
  112. * @param[in] P_DATA Pointer to the user text.
  113. * @param[in] DATA_LEN Length of the user text.
  114. */
  115. #define NFC_NDEF_TEXT_RECORD_DESC_DEF(NAME, \
  116. UTF, \
  117. P_LANG_CODE, \
  118. LANG_CODE_LEN, \
  119. P_DATA, \
  120. DATA_LEN) \
  121. nfc_text_rec_payload_desc_t NAME##_nfc_text_rec_payload_desc = \
  122. { \
  123. .utf = UTF, \
  124. .p_lang_code = P_LANG_CODE, \
  125. .lang_code_len = LANG_CODE_LEN, \
  126. .p_data = P_DATA, \
  127. .data_len = DATA_LEN, \
  128. }; \
  129. NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME, \
  130. TNF_WELL_KNOWN, \
  131. 0, \
  132. 0, \
  133. nfc_text_rec_type_field, \
  134. NFC_TEXT_REC_TYPE_LENGTH, \
  135. nfc_text_rec_payload_constructor, \
  136. &(NAME##_nfc_text_rec_payload_desc))
  137. /**
  138. * @brief Macro for accessing the NFC NDEF Text record descriptor
  139. * instance that was created with @ref NFC_NDEF_TEXT_RECORD_DESC_DEF.
  140. */
  141. #define NFC_NDEF_TEXT_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
  142. /** @} */
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif // NFC_TEXT_REC_H__