iot_context_manager.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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
  41. *
  42. * @defgroup iot_context_manager Context Manager
  43. * @{
  44. * @ingroup iot_sdk_common
  45. * @brief Manages context identifiers and prefixes related to the identifiers.
  46. *
  47. * @details This module allows to handle context information throughout the IoT application.
  48. * The module is used in the compression and decompression procedures of IPv6 addresses.
  49. * It allows more efficient communication between two nodes using global addresses.
  50. * The Context Manager contains tables of context, which can be accessed through API functions.
  51. * The table is maintained by the IPv6 stack while is referenced by 6LoWPAN module to be able to
  52. * compress and decompress packets.
  53. *
  54. * You can configure the module by changing the @c sdk_config.h configuration file.
  55. */
  56. #ifndef IOT_CONTEXT_MANAGER__
  57. #define IOT_CONTEXT_MANAGER__
  58. #include <stdint.h>
  59. #include <stdbool.h>
  60. #include "iot_common.h"
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. /**@brief Function for initializing the module.
  65. *
  66. * @retval NRF_SUCCESS If the module was successfully initialized. Otherwise, an error code that indicates the reason for the failure is returned.
  67. */
  68. uint32_t iot_context_manager_init(void);
  69. /**@brief Function for allocating the table for the specific interface.
  70. *
  71. * @param[in] p_interface Pointer to the IoT interface.
  72. *
  73. * @retval NRF_SUCCESS If the table was successfully allocated. Otherwise, an error code that indicates the reason for the failure is returned.
  74. */
  75. uint32_t iot_context_manager_table_alloc(const iot_interface_t * p_interface);
  76. /**@brief Function for freeing the table for the specific interface.
  77. *
  78. * @param[in] p_interface Pointer to the IoT interface.
  79. *
  80. * @retval NRF_SUCCESS If the table was successfully freed. Otherwise, an error code that indicates the reason for the failure is returned.
  81. */
  82. uint32_t iot_context_manager_table_free(const iot_interface_t * p_interface);
  83. /**@brief Function for updating the context table.
  84. *
  85. * Update requests are treated as follows:
  86. * - If the context identifier already exists in the context table, the context
  87. * is updated.
  88. * - If the context identifier does not exist yet, a new entry is generated. If
  89. * no memory is available, NRF_ERROR_NO_MEMORY is returned.
  90. *
  91. * The compression flag indicates if a context can be used for compression.
  92. * The context table can hold up to 16 context's information.
  93. *
  94. * @param[in] p_interface Pointer to the IoT interface.
  95. * @param[in] p_context Pointer to the context entry that shall be modified or added.
  96. *
  97. * @retval NRF_SUCCESS If the table was successfully updated. Otherwise, an error code that indicates the reason for the failure is returned.
  98. */
  99. uint32_t iot_context_manager_update(const iot_interface_t * p_interface, iot_context_t * p_context);
  100. /**@brief Function for removing context from the context table.
  101. *
  102. * @param[in] p_interface Pointer to the IoT interface.
  103. * @param[in] p_context Pointer to the context entry, retrieved from @ref iot_context_manager_get_by_addr or
  104. * @ref iot_context_manager_get_by_cid.
  105. *
  106. * @retval NRF_SUCCESS If the context was successfully removed. Otherwise, an error code that indicates the reason for the failure is returned.
  107. */
  108. uint32_t iot_context_manager_remove(const iot_interface_t * p_interface, iot_context_t * p_context);
  109. /**@brief Function for searching the proper entry in the context table by IPv6 address.
  110. * Only contexts with compression flag set to true, may be returned.
  111. *
  112. * @param[in] p_interface Pointer to the IoT interface.
  113. * @param[in] p_addr Pointer to IPv6 address to be compared with records in the context table.
  114. * @param[out] pp_context Pointer to the context in the context table.
  115. *
  116. * @retval NRF_SUCCESS If the procedure succeeded. Otherwise, an error code that indicates the reason for the failure is returned.
  117. */
  118. uint32_t iot_context_manager_get_by_addr(const iot_interface_t * p_interface,
  119. const ipv6_addr_t * p_addr,
  120. iot_context_t ** pp_context);
  121. /**@brief Function for searching the proper entry in the context table by context identifier.
  122. *
  123. * @param[in] p_interface Pointer to the IoT interface.
  124. * @param[in] context_id Context identifier to be compared with records in the context table.
  125. * @param[out] pp_context Pointer to the context in the context table.
  126. *
  127. * @retval NRF_SUCCESS If the procedure succeeded. Otherwise, an error code that indicates the reason for the failure is returned.
  128. */
  129. uint32_t iot_context_manager_get_by_cid(const iot_interface_t * p_interface,
  130. uint8_t context_id,
  131. iot_context_t ** pp_context);
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif // IOT_CONTEXT_MANAGER__
  136. /**@} */