ipv6_api.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * Copyright (c) 2014 - 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. /** @file ipv6_api.h
  41. *
  42. * @defgroup iot_ipv6 IPv6 Core Application Interface for Nordic's IPv6 stack
  43. * @ingroup iot_sdk_stack
  44. * @{
  45. * @brief Nordic's IPv6 stack. Currently, only a Host role is supported.
  46. *
  47. * @details Nordic's IPv6 stack provides minimal implementations of ICMP, UDP for a Host, and
  48. * IPv6 Neighbor Discovery for Host.
  49. * Router, neighbor, and prefix cache are not maintained across BLE link disconnections or
  50. * power cycles.
  51. */
  52. #ifndef IPV6_API_H_
  53. #define IPV6_API_H_
  54. #include <stdint.h>
  55. #include "sdk_config.h"
  56. #include "iot_common.h"
  57. #include "iot_pbuffer.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /**@brief Asynchronous event identifiers type. */
  62. typedef enum
  63. {
  64. IPV6_EVT_INTERFACE_ADD, /**< Notification of a new IPv6 interface added. */
  65. IPV6_EVT_INTERFACE_DELETE, /**< Notification of IPv6 interface deleted. */
  66. IPV6_EVT_INTERFACE_RX_DATA /**< Notification of IPv6 data, depending on configuration. For example, IPV6_ENABLE_USNUPORTED_PROTOCOLS_TO_APPLICATION. */
  67. } ipv6_event_id_t;
  68. /**@brief IPv6 address configuration. */
  69. typedef struct
  70. {
  71. ipv6_addr_t addr;
  72. ipv6_addr_state_t state;
  73. } ipv6_addr_conf_t;
  74. /**@brief Event parameters associated with the IPV6_EVT_INTERFACE_RX_DATA event. */
  75. typedef struct
  76. {
  77. ipv6_header_t * p_ip_header; /**< IPv6 header of the packet. */
  78. iot_pbuffer_t * p_rx_packet; /**< Packet buffer contains received data. */
  79. } ipv6_data_rx_t;
  80. /**@brief Asynchronous event parameter type. */
  81. typedef union
  82. {
  83. ipv6_data_rx_t rx_event_param; /**< Parameters notified with the received IPv6 packet. */
  84. } ipv6_event_param_t;
  85. /**@brief Asynchronous event type. */
  86. typedef struct
  87. {
  88. ipv6_event_id_t event_id; /**< Event identifier. */
  89. ipv6_event_param_t event_param; /**< Event parameters. */
  90. } ipv6_event_t;
  91. /**@brief Asynchronous event notification callback type. */
  92. typedef void (* ipv6_evt_handler_t)(iot_interface_t * p_interface,
  93. ipv6_event_t * p_event);
  94. /**@brief Initialization parameters type. */
  95. typedef struct
  96. {
  97. eui64_t * p_eui64; /**< Global identifiers EUI-64 address of device. */
  98. ipv6_evt_handler_t event_handler; /**< Asynchronous event notification callback registered to receive IPv6 events. */
  99. } ipv6_init_t;
  100. /**@brief Initializes the IPv6 stack module.
  101. *
  102. * @param[in] p_init Initialization parameters.
  103. *
  104. * @retval NRF_SUCCESS If initialization was successful. Otherwise, an error code is returned.
  105. */
  106. uint32_t ipv6_init(const ipv6_init_t * p_init);
  107. /**@brief Sets address to specific interface.
  108. *
  109. * @details API used to add or update an IPv6 address on an interface. The address can have three specific
  110. * states that determine transmitting capabilities.
  111. *
  112. * @param[in] p_interface The interface on which the address must be assigned.
  113. * @param[in] p_addr IPv6 address and state to be assigned/updated.
  114. *
  115. * @retval NRF_SUCCESS If the operation was successful.
  116. * @retval NRF_ERROR_NO_MEM If no memory was available.
  117. */
  118. uint32_t ipv6_address_set(const iot_interface_t * p_interface,
  119. const ipv6_addr_conf_t * p_addr);
  120. /**@brief Removes address from specific interface.
  121. *
  122. * @details API used to remove an IPv6 address from an interface.
  123. *
  124. * @param[in] p_interface The interface from which the address must be removed.
  125. * @param[in] p_addr IPv6 address to remove.
  126. *
  127. * @retval NRF_SUCCESS If the operation was successful.
  128. * @retval NRF_ERROR_NOT_FOUND If no address was found.
  129. */
  130. uint32_t ipv6_address_remove(const iot_interface_t * p_interface,
  131. const ipv6_addr_t * p_addr);
  132. /**@brief Checks if given unicast address has been registered.
  133. *
  134. * @param[in] p_interface The interface on which IPv6 address wil be checked.
  135. * @param[in] p_addr IPv6 address to be checked.
  136. *
  137. * @retval NRF_SUCCESS If the operation was successful.
  138. * @retval NRF_ERROR_NOT_FOUND If no address was found.
  139. */
  140. uint32_t ipv6_address_check(const iot_interface_t * p_interface,
  141. const ipv6_addr_t * p_addr);
  142. /**@brief Finds the best matched address and interface.
  143. *
  144. * @details API used to find the most suitable interface and address to a given destination address.
  145. *
  146. * To look only for the interface, set p_addr_r to NULL.
  147. *
  148. * To find the best matched address, IPV6_ADDR_STATE_PREFERRED state of address is required.
  149. *
  150. * @param[out] pp_interface Interface to be found.
  151. * @param[out] p_addr_r Best matching address if procedure succeeded and this value was not NULL.
  152. * @param[inout] p_addr_f IPv6 address for which best matching interface and/or address are requested.
  153. *
  154. * @retval NRF_SUCCESS If the operation was successful.
  155. * @retval NRF_ERROR_NOT_FOUND If no interface was found.
  156. * @retval NRF_ERROR_NOT_SUPPORTED If the operation was not supported.
  157. */
  158. uint32_t ipv6_address_find_best_match(iot_interface_t ** pp_interface,
  159. ipv6_addr_t * p_addr_r,
  160. const ipv6_addr_t * p_addr_f);
  161. /**@brief Sends IPv6 packet.
  162. *
  163. * @details API used to send an IPv6 packet. Which interface that packet must be sent to is determined
  164. * by analyzing the destination address.
  165. *
  166. * @param[in] p_interface The interface to which the packet is to be sent.
  167. * @param[in] p_packet IPv6 packet to send. The packet should be allocated using
  168. * @ref iot_pbuffer_allocate, to give stack control and to release
  169. * the memory buffer.
  170. *
  171. * @retval NRF_SUCCESS If the send request was successful.
  172. * @retval NRF_ERROR_NOT_FOUND If there was a failure while looking for the interface.
  173. * @retval NRF_ERROR_INVALID_PARAM If there was an error in processing the IPv6 packet.
  174. * @retval NRF_ERROR_NO_MEM If no memory was available in the transport
  175. * interface.
  176. */
  177. uint32_t ipv6_send(const iot_interface_t * p_interface, iot_pbuffer_t * p_packet);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif //IPV6_API_H_
  182. /** @} */