nfc_ndef_msg_parser.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_NDEF_MSG_PARSER_H__
  41. #define NFC_NDEF_MSG_PARSER_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_ndef_parser NDEF message parser
  45. * @{
  46. * @ingroup nfc_modules
  47. *
  48. * @brief Parser for NFC NDEF messages and records.
  49. *
  50. * @defgroup nfc_ndef_msg_parser Parser for NDEF messages
  51. * @{
  52. * @ingroup nfc_ndef_parser
  53. *
  54. * @brief Parser for NFC NDEF messages.
  55. *
  56. */
  57. #include <stdint.h>
  58. #include "nfc_ndef_msg_parser_local.h"
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /**
  63. * @brief Macro for calculating the memory size required for holding the
  64. * description of a message that consists of a certain number of NDEF records.
  65. *
  66. * @param[in] max_count_of_records Maximum number of records to hold.
  67. */
  68. #define NFC_NDEF_PARSER_REQIRED_MEMO_SIZE_CALC(max_count_of_records) \
  69. ((uint32_t)(max_count_of_records) <= 1) ? \
  70. (sizeof(parsed_ndef_msg_1_t) * (uint32_t)(max_count_of_records)) : \
  71. (sizeof(parsed_ndef_msg_1_t) + ((NFC_PARSER_M_DELTA) *((uint32_t)(max_count_of_records) - 1)))
  72. /**
  73. * @brief Function for parsing NFC NDEF messages.
  74. *
  75. * This function parses NDEF messages using NDEF binary record descriptors.
  76. *
  77. * @param[out] p_result_buf Pointer to the buffer that will be used to hold
  78. * the NDEF message descriptor. After parsing is completed successfully, the first address
  79. * in the buffer is filled by the NDEF message descriptor
  80. * (@ref nfc_ndef_msg_desc_t), which provides a full description of
  81. * the parsed NDEF message.
  82. * @param[in,out] p_result_buf_len As input: size of the buffer specified by @p p_result_buf.
  83. * As output: size of the reserved (used) part of the buffer specified by
  84. * @p p_result_buf.
  85. * @param[in] p_nfc_data Pointer to the data to be parsed.
  86. * @param[in,out] p_nfc_data_len As input: size of the NFC data in the @p p_nfc_data buffer. As output: size of the parsed message.
  87. *
  88. * @retval NRF_SUCCESS If the function completed successfully.
  89. * @retval NRF_ERROR_NO_MEM If the provided buffer is too small to hold a one-record message or
  90. * the buffer is too small to hold the actual result of the parsing.
  91. * @retval NRF_ERROR_INVALID_LENGTH If the expected message length is bigger than the amount of the provided input data.
  92. * @retval NRF_ERROR_INVALID_DATA If the message is not a valid NDEF message.
  93. */
  94. ret_code_t ndef_msg_parser(uint8_t * const p_result_buf,
  95. uint32_t * const p_result_buf_len,
  96. uint8_t * const p_nfc_data,
  97. uint32_t * const p_nfc_data_len);
  98. /**
  99. * @brief Function for printing the parsed contents of an NDEF message.
  100. *
  101. * @param[in] p_msg_desc Pointer to the descriptor of the message that should be printed.
  102. */
  103. void ndef_msg_printout(nfc_ndef_msg_desc_t * const p_msg_desc);
  104. /**
  105. * @}
  106. * @}
  107. */
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif // NFC_NDEF_MSG_PARSER_H__