coap.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.h
  41. *
  42. * @defgroup iot_sdk_coap_api CoAP interface
  43. * @ingroup iot_sdk_coap
  44. * @{
  45. * @brief Interface for the CoAP protocol.
  46. */
  47. #ifndef COAP_H__
  48. #define COAP_H__
  49. #include "iot_errors.h"
  50. #include "coap_api.h"
  51. #include "sdk_os.h"
  52. /**
  53. * @defgroup iot_coap_log Module's Log Macros
  54. * @details Macros used for creating module logs which can be useful in understanding handling
  55. * of events or actions on API requests. These are intended for debugging purposes and
  56. * can be enabled by defining the COAP_ENABLE_LOGS to 1.
  57. * @note If NRF_LOG_ENABLED is disabled, having COAP_ENABLE_LOGS has no effect.
  58. * @{
  59. */
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. #if (COAP_DISABLE_API_PARAM_CHECK == 0)
  64. /**@brief Verify NULL parameters are not passed to API by application. */
  65. #define NULL_PARAM_CHECK(PARAM) \
  66. if ((PARAM) == NULL) \
  67. { \
  68. return (NRF_ERROR_NULL | IOT_COAP_ERR_BASE); \
  69. }
  70. /**@brief Verify that parameter members has been set by the application. */
  71. #define NULL_PARAM_MEMBER_CHECK(PARAM) \
  72. if ((PARAM) == NULL) \
  73. { \
  74. return (NRF_ERROR_INVALID_PARAM | IOT_COAP_ERR_BASE); \
  75. }
  76. #else
  77. #define NULL_PARAM_CHECK(PARAM)
  78. #define NULL_PARAM_MEMBER_CHECK(PARAM)
  79. #endif // COAP_DISABLE_API_PARAM_CHECK
  80. /**
  81. * @defgroup iot_coap_mutex_lock_unlock Module's Mutex Lock/Unlock Macros.
  82. *
  83. * @details Macros used to lock and unlock modules. Currently, SDK does not use mutexes but
  84. * framework is provided in case the need to use an alternative architecture arises.
  85. * @{
  86. */
  87. #define COAP_MUTEX_LOCK() SDK_MUTEX_LOCK(m_coap_mutex) /**< Lock module using mutex */
  88. #define COAP_MUTEX_UNLOCK() SDK_MUTEX_UNLOCK(m_coap_mutex) /**< Unlock module using mutex */
  89. SDK_MUTEX_DEFINE(m_coap_mutex)
  90. /** @} */
  91. /**@brief Sends a CoAP message.
  92. *
  93. * @details Sends out a request using the underlying transport layer. Before sending, the
  94. * \ref coap_message_t structure is serialized and added to an internal message queue
  95. * in the library. The handle returned can be used to abort the message from being
  96. * retransmitted at any time.
  97. *
  98. * @param[out] p_handle Handle to the message if CoAP CON/ACK messages has been used. Returned
  99. * by reference.
  100. * @param[in] p_message Message to be sent.
  101. *
  102. * @retval NRF_SUCCESS If the message was successfully encoded and scheduled for transmission.
  103. */
  104. uint32_t internal_coap_message_send(uint32_t * p_handle, coap_message_t * p_message);
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif // COAP_H__
  109. /** @} */