ipv6_medium.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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
  41. *
  42. * @defgroup ipv6_medium IPv6 Medium
  43. * @{
  44. * @ingroup iot_sdk_common
  45. * @brief IPv6 Medium Interface.
  46. *
  47. * @details Implementation-agnostic interface of the physical transport that
  48. * facilitates IPv6 traffic.
  49. */
  50. #ifndef IPV6_MEDIUM_H__
  51. #define IPV6_MEDIUM_H__
  52. #include <stdint.h>
  53. #include <stdbool.h>
  54. #include "ipv6_medium_platform.h"
  55. #include "iot_defines.h"
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. #define EUI_48_SIZE 6 /**< Size of a 48-bit Extended Unique Identifier in bytes. */
  60. #define IPV6_MEDIUM_ID_ANY 0x00 /**< Indicates invalid physical transport type. */
  61. #define IPV6_MEDIUM_ID_BLE 0x01 /**< Indicates that the physical transport is BLE. */
  62. #define IPV6_MEDIUM_ID_802154 0x02 /**< Indicates that the physical transport is 802.15.4. */
  63. #define IPV6_MEDIUM_EVT_CONN_DOWN 0x01 /**< Indicates that a connection is established. */
  64. #define IPV6_MEDIUM_EVT_CONN_UP 0x02 /**< Indicates that a connection is torn down. */
  65. #define IPV6_MEDIUM_EVT_CONNECTABLE_MODE_ENTER 0x01 /**< Indicates that the medium entered connectable mode. */
  66. #define IPV6_MEDIUM_EVT_CONNECTABLE_MODE_EXIT 0x02 /**< Indicates that the medium exited connectable mode. */
  67. #define IPV6_MEDIUM_EVT_MAC_ADDRESS_CHANGED 0x03 /**< Indicates that the device has a new MAC address. */
  68. #define IPV6_MEDIUM_EVT_PHY_SPECIFIC 0xFF /**< Indicates miscellaneous event from the physical layer. */
  69. /**@brief IPv6 medium instance identifier type. */
  70. typedef uint32_t ipv6_medium_instance_id_t;
  71. /**@brief Type of IPv6 medium type. */
  72. typedef uint8_t ipv6_medium_type_t;
  73. /**@brief IPv6 medium instance type. */
  74. typedef struct
  75. {
  76. ipv6_medium_instance_id_t ipv6_medium_instance_id;
  77. ipv6_medium_type_t ipv6_medium_instance_type;
  78. } ipv6_medium_instance_t;
  79. /**@brief EUI-48 value type. */
  80. typedef struct
  81. {
  82. uint8_t identifier[EUI_48_SIZE]; /**< 48-bit identifier. */
  83. } eui48_t;
  84. /**@brief Type of IPv6 medium event parameters. */
  85. typedef struct
  86. {
  87. ipv6_medium_instance_t ipv6_medium_instance_id;
  88. uint8_t ipv6_medium_evt_id;
  89. ipv6_medium_cb_params_union_t medium_specific;
  90. } ipv6_medium_evt_t;
  91. /**@brief Type of IPv6 medium error parameters. */
  92. typedef struct
  93. {
  94. ipv6_medium_instance_t ipv6_medium_instance_id;
  95. uint32_t error_label;
  96. ipv6_medium_err_params_union_t medium_specific;
  97. } ipv6_medium_error_t;
  98. /**@brief IPv6 medium event handler type. */
  99. typedef void (*ipv6_medium_evt_handler_t)(ipv6_medium_evt_t * p_ipv6_medium_evt);
  100. /**@brief IPv6 medium error handler type. */
  101. typedef void (*ipv6_medium_error_handler_t)(ipv6_medium_error_t * p_ipv6_medium_error);
  102. #ifdef COMMISSIONING_ENABLED
  103. /**@brief Commissioning mode control commands. */
  104. typedef enum
  105. {
  106. CMD_IDENTITY_MODE_EXIT = 0x00,
  107. CMD_IDENTITY_MODE_ENTER = 0x01
  108. } mode_control_cmd_t;
  109. /**@brief Commissioning: Identity mode control callback function type. */
  110. typedef void (*commissioning_id_mode_cb_t)(mode_control_cmd_t control_command);
  111. /**@brief Commissioning: Power off on failure control callback function type. */
  112. typedef void (*commissioning_poweroff_cb_t)(bool do_poweroff_on_failure);
  113. #endif // COMMISSIONING_ENABLED
  114. /**@brief Structure for initialization parameters of the IPv6 medium. */
  115. typedef struct
  116. {
  117. ipv6_medium_evt_handler_t ipv6_medium_evt_handler;
  118. ipv6_medium_error_handler_t ipv6_medium_error_handler;
  119. #ifdef COMMISSIONING_ENABLED
  120. commissioning_id_mode_cb_t commissioning_id_mode_cb;
  121. commissioning_poweroff_cb_t commissioning_power_off_cb;
  122. #endif // COMMISSIONING_ENABLED
  123. } ipv6_medium_init_params_t;
  124. /**@brief Function for initializing the IPv6 medium.
  125. *
  126. * @details Initializes the IPv6 medium module.
  127. * Performs all setup necessary that is specific to the implementation.
  128. *
  129. * @param[in] p_init_param Pointer to the initialization parameters.
  130. * @param[in] desired_medium_type Value of the desired medium type.
  131. * @param[out] p_new_medium_instance Pointer to the new medium instance initialized.
  132. *
  133. * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated
  134. * error code is returned.
  135. *
  136. */
  137. uint32_t ipv6_medium_init(ipv6_medium_init_params_t * p_init_param,
  138. ipv6_medium_type_t desired_medium_type,
  139. ipv6_medium_instance_t * p_new_medium_instance);
  140. /**@brief Function for entering connectible mode.
  141. *
  142. * @details Requests the IPv6 medium to enter connectible mode.
  143. *
  144. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  145. *
  146. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  147. * error code is returned.
  148. *
  149. */
  150. uint32_t ipv6_medium_connectable_mode_enter(ipv6_medium_instance_id_t ipv6_medium_instance_id);
  151. /**@brief Function for exiting connectible mode.
  152. *
  153. * @details Requests the IPv6 medium to exit connectible mode.
  154. *
  155. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  156. *
  157. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  158. * error code is returned.
  159. *
  160. */
  161. uint32_t ipv6_medium_connectable_mode_exit(ipv6_medium_instance_id_t ipv6_medium_instance_id);
  162. /**@brief Function for getting the 48-bit Extended Unique Identifier.
  163. *
  164. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  165. * @param[out] p_ipv6_medium_eui48 Pointer to the EUI-48 value.
  166. *
  167. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  168. * error code is returned.
  169. *
  170. */
  171. uint32_t ipv6_medium_eui48_get(ipv6_medium_instance_id_t ipv6_medium_instance_id,
  172. eui48_t * p_ipv6_medium_eui48);
  173. /**@brief Function for setting the 48-bit Extended Unique Identifier.
  174. *
  175. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  176. * @param[in] p_ipv6_medium_eui48 Pointer to the EUI-48 value.
  177. *
  178. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  179. * error code is returned.
  180. *
  181. */
  182. uint32_t ipv6_medium_eui48_set(ipv6_medium_instance_id_t ipv6_medium_instance_id,
  183. eui48_t * p_ipv6_medium_eui48);
  184. /**@brief Function for getting the 64-bit Extended Unique Identifier.
  185. *
  186. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  187. * @param[out] p_ipv6_medium_eui64 Pointer to the EUI-64 value.
  188. *
  189. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  190. * error code is returned.
  191. *
  192. */
  193. uint32_t ipv6_medium_eui64_get(ipv6_medium_instance_id_t ipv6_medium_instance_id,
  194. eui64_t * p_ipv6_medium_eui64);
  195. /**@brief Function for setting the 64-bit Extended Unique Identifier.
  196. *
  197. * @param[in] ipv6_medium_instance_id Specifies the IPv6 medium instance.
  198. * @param[in] p_ipv6_medium_eui64 Pointer to the EUI-64 value.
  199. *
  200. * @retval NRF_SUCCESS If the procedure was successful. Otherwise, a propagated
  201. * error code is returned.
  202. *
  203. */
  204. uint32_t ipv6_medium_eui64_set(ipv6_medium_instance_id_t ipv6_medium_instance_id,
  205. eui64_t * p_ipv6_medium_eui64);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif // IPV6_MEDIUM_H__
  210. /** @} */