dns6_api.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * Copyright (c) 2015 - 2018, 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. /** @file dns6_api.h
  41. *
  42. * @defgroup iot_dns6 DNS Application Interface for Nordic's IPv6 stack
  43. * @ingroup iot_sdk_stack
  44. * @{
  45. * @brief Domain Name System module provides implementation of DNS6 service.
  46. *
  47. */
  48. #ifndef DNS6_H__
  49. #define DNS6_H__
  50. #include "sdk_config.h"
  51. #include "sdk_common.h"
  52. #include "ipv6_api.h"
  53. #include "iot_timer.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /** @brief DNS Server parameter. */
  58. typedef struct
  59. {
  60. ipv6_addr_t addr; /**< The IPv6 address of the DNS Server. */
  61. uint16_t port; /**< The default UDP port of the DNS Server. */
  62. } dns6_server_param_t;
  63. /**@brief Initialization parameters type. */
  64. typedef struct
  65. {
  66. uint16_t local_src_port; /**< The local UDP port for reception the DNS responses. */
  67. dns6_server_param_t dns_server; /**< Parameters of the DNS Server. */
  68. } dns6_init_t;
  69. /**
  70. * @brief DNS event receive callback.
  71. *
  72. * @details API used to notify the application of DNS Response on specific hostname or of an error
  73. * during resolving process. The process_result parameter indicates whether the DNS module
  74. * was successfully processed. If the received DNS Response is malformed in a way that
  75. * allow to assign response with specific callback (e.g. timeout occurs or hostname is not
  76. * found), information about error is still notified to the application. The application
  77. * should check process_result and number of IPv6 address before reading them.
  78. *
  79. * @param[in] process_result Notifies the application if the DNS module was processed successfully
  80. * or if an error occurred, for example DNS server is unreachable.
  81. * @param[in] p_hostname Identifies hostname (URL string) that was requested to bee resolved,
  82. * e.g. "example.com".
  83. * @param[in] p_addr Pointer to the IPv6 addresses being resolved for given hostname. In
  84. * case addr_count variable is 0, p_addr gets NULL value and should not
  85. * be used.
  86. * @param[in] addr_count Number of IPv6 addresses being successfully resolved.
  87. *
  88. * @retval None.
  89. */
  90. typedef void (* dns6_evt_handler_t) (uint32_t process_result,
  91. const char * p_hostname,
  92. ipv6_addr_t * p_addr,
  93. uint16_t addr_count);
  94. /**
  95. * @brief Function for initializing DNS6 module.
  96. *
  97. * @param[in] p_dns_init Initialization structure for DNS client. Should not be NULL.
  98. *
  99. * @note DNS protocol module uses UDP transport layer, therefore one UDP socket is allocated
  100. * inside function and uses for further communication.
  101. *
  102. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  103. * for failure.
  104. */
  105. uint32_t dns6_init(const dns6_init_t * p_dns_init);
  106. /**
  107. * @brief Function for uninitializing DNS6 module.
  108. *
  109. * @note Apart of DNS specific functionality, function frees previously allocated UDP socket.
  110. * Function removes any pending queries from the sending queue, so registered user
  111. * callbacks will not be executed.
  112. *
  113. * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
  114. * for failure.
  115. */
  116. uint32_t dns6_uninit(void);
  117. /**
  118. * @brief Function for querying given URL string to DNS server, in order to get IPv6 address of
  119. * given hostname.
  120. *
  121. * @param[in] p_hostname Identifies hostname (URL string) to be find, e.g. "example.com". Should
  122. * not be NULL.
  123. * @param[in] evt_handler Callback that is called once response is received, timeout occurred or
  124. * internal error was detected. Should not be NULL.
  125. *
  126. * @note Function sends DNS Query to DNS Server to obtain all AAAA records (with IPv6 address)
  127. * assigned to given hostname. In case DNS Server replies with more that one AAAA records
  128. * DNS module call user defined evt_handler with addr_count indicates number of addresses.
  129. *
  130. * @retval NRF_SUCCESS on successful execution of procedure.
  131. * @retval IOT_DNS6_ERR_BASE | NRF_ERROR_NO_MEM if there is no place in pending queries' queue.
  132. * @retval IOT_PBUFFER_ERR_BASE | NRF_ERROR_NO_MEM if there is no memory for hostname allocation.
  133. * @retval NRF_ERROR_MEMORY_MANAGER_ERR_BASE | NRF_ERROR_NO_MEM if there is no memory for packet allocation.
  134. * @retval UDP_INTERFACE_NOT_READY if interface is not ready for sending packets e.g. interface is
  135. * down.
  136. * @retval Other errors indicates reason of failure.
  137. */
  138. uint32_t dns6_query(const char * p_hostname, dns6_evt_handler_t evt_handler);
  139. /**@brief Function for performing retransmissions of DNS queries.
  140. *
  141. * @note DNS module implements the retransmission mechanism by invoking this function periodically.
  142. * So that method has to be added to IoT Timer client list and has to be called with minimum of
  143. * DNS6_RETRANSMISSION_INTERVAL resolution.
  144. *
  145. * @param[in] wall_clock_value The value of the wall clock that triggered the callback.
  146. *
  147. * @retval None.
  148. */
  149. void dns6_timeout_process(iot_timer_time_in_ms_t wall_clock_value);
  150. #ifdef __cplusplus
  151. }
  152. #endif
  153. #endif //DNS6_H__
  154. /**@} */