nfc_hs_rec.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * Copyright (c) 2015 - 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_HS_REC_H__
  41. #define NFC_HS_REC_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_hs_rec Hs (Handover Select) records
  45. * @{
  46. * @ingroup nfc_ble_pair_msg
  47. *
  48. * @brief Generation of NFC NDEF Handover Select records for NDEF messages.
  49. *
  50. */
  51. #include <stdint.h>
  52. #include "nfc_ndef_record.h"
  53. #include "nfc_ndef_msg.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /**
  58. * @brief Handover Select record payload descriptor.
  59. */
  60. typedef struct
  61. {
  62. uint8_t major_version; ///< Major version number of the supported Connection Handover specification.
  63. uint8_t minor_version; ///< Minor version number of the supported Connection Handover specification.
  64. nfc_ndef_msg_desc_t * p_local_records; ///< Pointer to a message encapsulating local records.
  65. } nfc_hs_rec_payload_desc_t;
  66. /**
  67. * @brief Constructor for an NFC NDEF Handover Select record payload.
  68. *
  69. * This function encodes the payload of a Handover Select record as specified in the Connection
  70. * Handover standard. It implements an API compatible with @ref p_payload_constructor_t.
  71. */
  72. ret_code_t nfc_hs_rec_payload_constructor(nfc_hs_rec_payload_desc_t * p_nfc_hs_rec_payload_desc,
  73. uint8_t * p_buff,
  74. uint32_t * p_len);
  75. /**
  76. * @brief An external reference to the type field of the Handover Select record, defined in the
  77. * file @c nfc_hs_rec.c. It is used in the @ref NFC_NDEF_HS_RECORD_DESC_DEF macro.
  78. */
  79. extern const uint8_t nfc_hs_rec_type_field[];
  80. /**
  81. * @brief Size of the type field of the Handover Select record, defined in the
  82. * file @c nfc_hs_rec.c. It is used in the @ref NFC_NDEF_HS_RECORD_DESC_DEF macro.
  83. */
  84. #define NFC_HS_REC_TYPE_LENGTH 2
  85. /**
  86. * @brief Macro for creating and initializing an NFC NDEF record descriptor for a Handover Select record.
  87. *
  88. * This macro creates and initializes an instance of type @ref nfc_ndef_record_desc_t and
  89. * an instance of type @ref nfc_hs_rec_payload_desc_t, which together constitute an instance of a Handover Select record.
  90. *
  91. * Use the macro @ref NFC_NDEF_HS_RECORD_DESC to access the NDEF Handover Select record descriptor instance.
  92. *
  93. * @note The record descriptor is declared as automatic variable, which implies that
  94. * the NDEF message encoding (see @ref nfc_ble_full_handover_select_msg_encode)
  95. * must be done in the same variable scope.
  96. *
  97. * @param[in] NAME Name of the created record descriptor instance.
  98. * @param[in] MAJOR_VERSION Major version number of the supported Connection Handover specification.
  99. * @param[in] MINOR_VERSION Minor version number of the supported Connection Handover specification.
  100. * @param[in] MAX_RECORDS Maximum number of local records (ac records plus optional err record).
  101. */
  102. #define NFC_NDEF_HS_RECORD_DESC_DEF(NAME, \
  103. MAJOR_VERSION, \
  104. MINOR_VERSION, \
  105. MAX_RECORDS) \
  106. NFC_NDEF_MSG_DEF(NAME, MAX_RECORDS); \
  107. nfc_hs_rec_payload_desc_t NAME##_nfc_hs_rec_payload_desc = \
  108. { \
  109. .major_version = MAJOR_VERSION, \
  110. .minor_version = MINOR_VERSION, \
  111. .p_local_records = &NFC_NDEF_MSG(NAME) \
  112. }; \
  113. NFC_NDEF_GENERIC_RECORD_DESC_DEF(NAME, \
  114. TNF_WELL_KNOWN, \
  115. 0, \
  116. 0, \
  117. nfc_hs_rec_type_field, \
  118. NFC_HS_REC_TYPE_LENGTH, \
  119. nfc_hs_rec_payload_constructor, \
  120. &(NAME##_nfc_hs_rec_payload_desc))
  121. /**
  122. * @brief Macro for accessing the NFC NDEF Handover Select record descriptor
  123. * instance that was created with @ref NFC_NDEF_HS_RECORD_DESC_DEF.
  124. */
  125. #define NFC_NDEF_HS_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
  126. /**
  127. * @brief Function for clearing local records in the NFC NDEF Handover Select record.
  128. *
  129. * This function clears local records from the Handover Select record.
  130. *
  131. * @param[in, out] p_hs_rec Pointer to the Handover Select record descriptor.
  132. */
  133. void nfc_hs_rec_local_record_clear(nfc_ndef_record_desc_t * p_hs_rec);
  134. /**
  135. * @brief Function for adding a local record to an NFC NDEF Handover Select record.
  136. *
  137. * @param[in, out] p_hs_rec Pointer to a Handover Select record.
  138. * @param[in] p_local_rec Pointer to a local record to add.
  139. *
  140. * @retval NRF_SUCCESS If the local record was added successfully.
  141. * @retval NRF_ERROR_NO_MEM If the Handover Select record already contains the maximum number of local records.
  142. */
  143. ret_code_t nfc_hs_rec_local_record_add(nfc_ndef_record_desc_t * p_hs_rec,
  144. nfc_ndef_record_desc_t * p_local_rec);
  145. /** @} */
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif // NFC_HS_REC_H__