nfc_uri_rec.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_URI_REC_H__
  41. #define NFC_URI_REC_H__
  42. /**@file
  43. *
  44. * @defgroup nfc_uri_rec URI records
  45. * @{
  46. * @ingroup nfc_uri_msg
  47. *
  48. * @brief Generation of NFC NDEF URI record descriptions.
  49. *
  50. */
  51. #include "nfc_ndef_record.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**
  56. * @enum nfc_uri_id_t
  57. * @brief URI identifier codes according to "URI Record Type Definition"
  58. * (denotation "NFCForum-TS-RTD_URI_1.0" published on 2006-07-24) chapter 3.2.2.
  59. */
  60. typedef enum
  61. {
  62. NFC_URI_NONE = 0x00, /**< No prepending is done. */
  63. NFC_URI_HTTP_WWW = 0x01, /**< "http://www." */
  64. NFC_URI_HTTPS_WWW = 0x02, /**< "https://www." */
  65. NFC_URI_HTTP = 0x03, /**< "http:" */
  66. NFC_URI_HTTPS = 0x04, /**< "https:" */
  67. NFC_URI_TEL = 0x05, /**< "tel:" */
  68. NFC_URI_MAILTO = 0x06, /**< "mailto:" */
  69. NFC_URI_FTP_ANONYMOUS = 0x07, /**< "ftp://anonymous:anonymous@" */
  70. NFC_URI_FTP_FTP = 0x08, /**< "ftp://ftp." */
  71. NFC_URI_FTPS = 0x09, /**< "ftps://" */
  72. NFC_URI_SFTP = 0x0A, /**< "sftp://" */
  73. NFC_URI_SMB = 0x0B, /**< "smb://" */
  74. NFC_URI_NFS = 0x0C, /**< "nfs://" */
  75. NFC_URI_FTP = 0x0D, /**< "ftp://" */
  76. NFC_URI_DAV = 0x0E, /**< "dav://" */
  77. NFC_URI_NEWS = 0x0F, /**< "news:" */
  78. NFC_URI_TELNET = 0x10, /**< "telnet://" */
  79. NFC_URI_IMAP = 0x11, /**< "imap:" */
  80. NFC_URI_RTSP = 0x12, /**< "rtsp://" */
  81. NFC_URI_URN = 0x13, /**< "urn:" */
  82. NFC_URI_POP = 0x14, /**< "pop:" */
  83. NFC_URI_SIP = 0x15, /**< "sip:" */
  84. NFC_URI_SIPS = 0x16, /**< "sips:" */
  85. NFC_URI_TFTP = 0x17, /**< "tftp:" */
  86. NFC_URI_BTSPP = 0x18, /**< "btspp://" */
  87. NFC_URI_BTL2CAP = 0x19, /**< "btl2cap://" */
  88. NFC_URI_BTGOEP = 0x1A, /**< "btgoep://" */
  89. NFC_URI_TCPOBEX = 0x1B, /**< "tcpobex://" */
  90. NFC_URI_IRDAOBEX = 0x1C, /**< "irdaobex://" */
  91. NFC_URI_FILE = 0x1D, /**< "file://" */
  92. NFC_URI_URN_EPC_ID = 0x1E, /**< "urn:epc:id:" */
  93. NFC_URI_URN_EPC_TAG = 0x1F, /**< "urn:epc:tag:" */
  94. NFC_URI_URN_EPC_PAT = 0x20, /**< "urn:epc:pat:" */
  95. NFC_URI_URN_EPC_RAW = 0x21, /**< "urn:epc:raw:" */
  96. NFC_URI_URN_EPC = 0x22, /**< "urn:epc:" */
  97. NFC_URI_URN_NFC = 0x23, /**< "urn:nfc:" */
  98. NFC_URI_RFU = 0xFF /**< No prepending is done. Reserved for future use. */
  99. } nfc_uri_id_t;
  100. /**
  101. * @brief Type of description of the payload of a URI record.
  102. */
  103. typedef struct
  104. {
  105. nfc_uri_id_t uri_id_code; /**< URI identifier code. */
  106. uint8_t const * p_uri_data; /**< Pointer to a URI string. */
  107. uint8_t uri_data_len; /**< Length of the URI string. */
  108. } uri_payload_desc_t;
  109. /**
  110. * @brief External reference to the type field of the URI record, defined in the
  111. * file @c nfc_uri_rec.c. It is used in the @ref NFC_NDEF_URI_RECORD_DESC_DEF macro.
  112. */
  113. extern const uint8_t ndef_uri_record_type;
  114. /**
  115. * @brief Function for constructing the payload for a URI record.
  116. *
  117. * This function encodes the payload according to the URI record definition. It implements an API
  118. * compatible with @ref p_payload_constructor_t.
  119. *
  120. * @param[in] p_input Pointer to the description of the payload.
  121. * @param[out] p_buff Pointer to payload destination. If NULL, function will
  122. * calculate the expected size of the URI record payload.
  123. *
  124. * @param[in,out] p_len Size of available memory to write as input. Size of generated
  125. * payload as output.
  126. *
  127. * @retval NRF_SUCCESS If the payload was encoded successfully.
  128. * @retval NRF_ERROR_NO_MEM If the predicted payload size is bigger than the provided buffer space.
  129. */
  130. ret_code_t nfc_uri_payload_constructor( uri_payload_desc_t * p_input,
  131. uint8_t * p_buff,
  132. uint32_t * p_len);
  133. /** @brief Macro for generating a description of a URI record.
  134. *
  135. * This macro initializes an instance of an NFC NDEF record description of a URI record.
  136. *
  137. * @note The record descriptor is declared as automatic variable, which implies that
  138. * the NDEF message encoding (see @ref nfc_uri_msg_encode) must be done
  139. * in the same variable scope.
  140. *
  141. * @param[in] NAME Name for accessing record descriptor.
  142. * @param[in] URI_ID_CODE URI identifier code that defines the protocol field of the URI.
  143. * @param[in] P_URI_DATA Pointer to the URI string.
  144. * The string should not contain the protocol field if the protocol
  145. * was specified in @p uri_id_code.
  146. * @param[in] URI_DATA_LEN Length of the URI string.
  147. */
  148. #define NFC_NDEF_URI_RECORD_DESC_DEF(NAME, \
  149. URI_ID_CODE, \
  150. P_URI_DATA, \
  151. URI_DATA_LEN) \
  152. uri_payload_desc_t NAME##_ndef_uri_record_payload_desc = \
  153. { \
  154. .uri_id_code = (URI_ID_CODE), \
  155. .p_uri_data = (P_URI_DATA), \
  156. .uri_data_len = (URI_DATA_LEN) \
  157. }; \
  158. \
  159. NFC_NDEF_GENERIC_RECORD_DESC_DEF( NAME, \
  160. TNF_WELL_KNOWN, \
  161. NULL, \
  162. 0, \
  163. &ndef_uri_record_type, \
  164. sizeof(ndef_uri_record_type), \
  165. nfc_uri_payload_constructor, \
  166. &NAME##_ndef_uri_record_payload_desc) \
  167. /**
  168. * @brief Macro for accessing the NFC NDEF URI record descriptor instance that
  169. * was created with @ref NFC_NDEF_URI_RECORD_DESC_DEF.
  170. */
  171. #define NFC_NDEF_URI_RECORD_DESC(NAME) NFC_NDEF_GENERIC_RECORD_DESC(NAME)
  172. /** @} */
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif // NFC_URI_REC_H__