coap_block.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Copyright (c) 2015 - 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 coap_block.h
  41. *
  42. * @defgroup iot_sdk_coap_block CoAP Block transfer
  43. * @ingroup iot_sdk_coap
  44. * @{
  45. * @brief CoAP block transfer options encoding and decoding interface and definitions.
  46. *
  47. */
  48. #ifndef COAP_BLOCK_H__
  49. #define COAP_BLOCK_H__
  50. #include <stdint.h>
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. #define COAP_BLOCK_OPT_BLOCK_MORE_BIT_UNSET 0 /**< Value when more flag is set. */
  55. #define COAP_BLOCK_OPT_BLOCK_MORE_BIT_SET 1 /**< Value when more flag is not set. */
  56. typedef struct
  57. {
  58. uint8_t more; /**< More bit value. */
  59. uint16_t size; /**< Size of the block in bytes. */
  60. uint32_t number; /**< Block number. */
  61. } coap_block_opt_block1_t;
  62. typedef coap_block_opt_block1_t coap_block_opt_block2_t;
  63. /**@brief Encode block1 option into its uint binary counter part.
  64. *
  65. * @param[out] p_encoded Encoded version of the coap block1 option value. Must not be NULL.
  66. * @param[in] p_opt Pointer to block1 option structure to be decoded into uint format. Must
  67. * not be NULL.
  68. *
  69. * @retval NRF_SUCCESS If encoding of option was successful.
  70. * @retval NRF_ERROR_NULL If one of the parameters supplied is a null pointer.
  71. * @retval NRF_ERROR_INVALID_PARAM If one of the fields in the option structure has an illegal
  72. * value.
  73. */
  74. uint32_t coap_block_opt_block1_encode(uint32_t * p_encoded, coap_block_opt_block1_t * p_opt);
  75. /**@brief Decode block1 option from a uint to its structure counter part.
  76. *
  77. * @param[out] p_opt Pointer to block1 option structure to be filled by the function. Must not
  78. * be NULL.
  79. * @param[in] encoded Encoded version of the coap block1 option value.
  80. *
  81. * @retval NRF_SUCCESS If decoding of the option was successful.
  82. * @retval NRF_ERROR_NULL If p_opt parameter is NULL.
  83. * @retval NRF_ERROR_INVALID_PARAM If the block number is higher then allowed by spec (more than
  84. 20 bits).
  85. * @retval NRF_ERROR_INVALID_DATA If the size has the value of the reserved 2048 value (7).
  86. */
  87. uint32_t coap_block_opt_block1_decode(coap_block_opt_block1_t * p_opt, uint32_t encoded);
  88. /**@brief Encode block2 option into its uint binary counter part.
  89. *
  90. * @param[out] p_encoded Encoded version of the coap block2 option value. Must not be NULL.
  91. * @param[in] p_opt Pointer to block2 option structure to be decoded into uint format. Must
  92. * not be NULL.
  93. *
  94. * @retval NRF_SUCCESS If encoding of option was successful.
  95. * @retval NRF_ERROR_NULL If one of the parameters supplied is a null pointer.
  96. * @retval NRF_ERROR_INVALID_PARAM If one of the fields in the option structure has an illegal
  97. * value.
  98. */
  99. uint32_t coap_block_opt_block2_encode(uint32_t * p_encoded, coap_block_opt_block2_t * p_opt);
  100. /**@brief Decode block2 option from a uint to its structure counter part.
  101. *
  102. * @param[out] p_opt Pointer to block2 option structure to be filled by the function. Must not
  103. * be NULL.
  104. * @param[in] encoded Encoded version of the coap block2 option value.
  105. *
  106. * @retval NRF_SUCCESS If decoding of the option was successful.
  107. * @retval NRF_ERROR_NULL If p_opt parameter is NULL.
  108. * @retval NRF_ERROR_INVALID_PARAM If the block number is higher then allowed by spec (more than
  109. 20 bits).
  110. * @retval NRF_ERROR_INVALID_DATA If the size has the value of the reserved 2048 value (7).
  111. */
  112. uint32_t coap_block_opt_block2_decode(coap_block_opt_block2_t * p_opt, uint32_t encoded);
  113. #endif // COAP_BLOCK_H__
  114. /** @} */