coap_queue.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * Copyright (c) 2014 - 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 coap_queue.h
  41. *
  42. * @defgroup iot_sdk_coap_queue CoAP Message Queue
  43. * @ingroup iot_sdk_coap
  44. * @{
  45. * @brief TODO.
  46. */
  47. #ifndef COAP_QUEUE_H__
  48. #define COAP_QUEUE_H__
  49. #include <stdint.h>
  50. #include "coap_transport.h"
  51. #include "coap_message.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. typedef struct
  56. {
  57. void * p_arg; /**< Miscellaneous pointer to application provided data that is associated with the message. Copied from the coap_message_t when creating the item. */
  58. uint32_t handle; /**< Quick reference to the handle value of the current item. */
  59. uint16_t mid; /**< Message ID. */
  60. uint8_t token_len; /**< Message Token length. */
  61. uint8_t token[8]; /**< Message Token value up to 8 bytes. */
  62. uint8_t retrans_count; /**< Re-transmission attempt count. */
  63. uint16_t timeout; /**< Time until new re-transmission attempt. */
  64. uint16_t timeout_val; /**< Last timeout value used. */
  65. coap_port_t port; /**< Source port to use when re-transmitting. */
  66. uint8_t * p_buffer; /**< Pointer to the data buffer containing the encoded CoAP message. */
  67. uint32_t buffer_len; /**< Size of the data buffer containing the encoded CoAP message. */
  68. coap_remote_t remote; /**< Destination address and port number to the remote. */
  69. coap_response_callback_t callback; /**< Callback function to be called upon response or transmission timeout. */
  70. } coap_queue_item_t;
  71. /**@brief Initilize the CoAP message queue.
  72. *
  73. * @retval NRF_SUCCESS If initialization completed successfully.
  74. */
  75. uint32_t coap_queue_init(void);
  76. /**@brief Add item to the queue.
  77. *
  78. * @param[in] p_item Pointer to an item which to add to the queue. The function will copy all
  79. * data provided.
  80. *
  81. * @retval NRF_SUCCESS If adding the item was successful.
  82. * @retval NRF_ERROR_NO_MEM If max number of queued elements has been reached. This is
  83. * configured by COAP_MESSAGE_QUEUE_SIZE in sdk_config.h.
  84. * @retval NRF_ERROR_DATA_SIZE If the element could not be added.
  85. */
  86. uint32_t coap_queue_add(coap_queue_item_t * p_item);
  87. /**@brief Remove item from the queue.
  88. *
  89. * @param[in] p_item Pointer to an item which to remove from the queue. Should not be NULL.
  90. *
  91. * @retval NRF_SUCCESS If the item was successfully removed from the queue.
  92. * @retval NRF_ERROR_NULL If p_item pointer is NULL.
  93. * @retval NRF_ERROR_NOT_FOUND If the item was not located in the queue.
  94. */
  95. uint32_t coap_queue_remove(coap_queue_item_t * p_item);
  96. /**@brief Search for item by token.
  97. *
  98. * @details Search the items for any item matching the token.
  99. *
  100. * @param[out] pp_item Pointer to be filled by the function if item matching the token
  101. * has been found. Should not be NULL.
  102. * @param[in] p_token Pointer to token array to be matched.
  103. * @param[in] token_len Length of the token to be matched.
  104. *
  105. * @retval NRF_SUCCESS If an item was successfully located.
  106. * @retval NRF_ERROR_NULL If pp_item pointer is NULL.
  107. * @retval NRF_ERROR_NOT_FOUND If no item was found.
  108. */
  109. uint32_t coap_queue_item_by_token_get(coap_queue_item_t ** pp_item, uint8_t * p_token, uint8_t token_len);
  110. /**@brief Search for item by message id.
  111. *
  112. * @details Search the items for any item matching the message id.
  113. *
  114. * @param[out] pp_item Pointer to be filled by the funciton if item matching the message id
  115. * has been found. Should not be NULL.
  116. * @param[in] message_id Message id to be matched.
  117. *
  118. * @retval NRF_SUCCESS If an item was successfully located.
  119. * @retval NRF_ERROR_NULL If pp_item pointer is NULL.
  120. * @retval NRF_ERROR_NOT_FOUND If no item was found.
  121. */
  122. uint32_t coap_queue_item_by_mid_get(coap_queue_item_t ** pp_item, uint16_t message_id);
  123. /**@brief Iterate through items.
  124. *
  125. * @param[out] pp_item Pointer to be filled by the search function upon finding the next
  126. * queued item starting from the p_item pointer provided. Should
  127. * not be NULL.
  128. * @param[in] p_item Pointer to the item where to start the search.
  129. *
  130. * @retval NRF_SUCCESS If item was found.
  131. * @retval NRF_ERROR_NULL If pp_item pointer is NULL.
  132. * @retval NRF_ERROR_NOT_FOUND If next item was not found.
  133. */
  134. uint32_t coap_queue_item_next_get(coap_queue_item_t ** pp_item, coap_queue_item_t * p_item);
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif // COAP_QUEUE_H__
  139. /** @} */