sandbox / mbed-client-c

Fork of mbed-client-c by Christopher Haster

Committer:
Christopher Haster
Date:
Fri Jan 22 16:31:54 2016 -0600
Revision:
1:43f5c94c6771
Child:
4:5d91b0f5038c
Initial move of mbed-client-c to mercurial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:43f5c94c6771 1 /*
Christopher Haster 1:43f5c94c6771 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
Christopher Haster 1:43f5c94c6771 3 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:43f5c94c6771 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Christopher Haster 1:43f5c94c6771 5 * not use this file except in compliance with the License.
Christopher Haster 1:43f5c94c6771 6 * You may obtain a copy of the License at
Christopher Haster 1:43f5c94c6771 7 *
Christopher Haster 1:43f5c94c6771 8 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:43f5c94c6771 9 *
Christopher Haster 1:43f5c94c6771 10 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:43f5c94c6771 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Christopher Haster 1:43f5c94c6771 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:43f5c94c6771 13 * See the License for the specific language governing permissions and
Christopher Haster 1:43f5c94c6771 14 * limitations under the License.
Christopher Haster 1:43f5c94c6771 15 */
Christopher Haster 1:43f5c94c6771 16
Christopher Haster 1:43f5c94c6771 17 /**
Christopher Haster 1:43f5c94c6771 18 * \file sn_coap_header.h
Christopher Haster 1:43f5c94c6771 19 *
Christopher Haster 1:43f5c94c6771 20 * \brief CoAP C-library User header interface header file
Christopher Haster 1:43f5c94c6771 21 */
Christopher Haster 1:43f5c94c6771 22
Christopher Haster 1:43f5c94c6771 23 #ifndef SN_COAP_HEADER_H_
Christopher Haster 1:43f5c94c6771 24 #define SN_COAP_HEADER_H_
Christopher Haster 1:43f5c94c6771 25
Christopher Haster 1:43f5c94c6771 26 #ifdef __cplusplus
Christopher Haster 1:43f5c94c6771 27 extern "C" {
Christopher Haster 1:43f5c94c6771 28 #endif
Christopher Haster 1:43f5c94c6771 29
Christopher Haster 1:43f5c94c6771 30 /* Handle structure */
Christopher Haster 1:43f5c94c6771 31 struct coap_s;
Christopher Haster 1:43f5c94c6771 32
Christopher Haster 1:43f5c94c6771 33 /* * * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 34 /* * * * ENUMERATIONS * * * */
Christopher Haster 1:43f5c94c6771 35 /* * * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 36
Christopher Haster 1:43f5c94c6771 37 /**
Christopher Haster 1:43f5c94c6771 38 * \brief Enumeration for CoAP Version
Christopher Haster 1:43f5c94c6771 39 */
Christopher Haster 1:43f5c94c6771 40 typedef enum coap_version_ {
Christopher Haster 1:43f5c94c6771 41 COAP_VERSION_1 = 0x40,
Christopher Haster 1:43f5c94c6771 42 COAP_VERSION_UNKNOWN = 0xFF
Christopher Haster 1:43f5c94c6771 43 } coap_version_e;
Christopher Haster 1:43f5c94c6771 44
Christopher Haster 1:43f5c94c6771 45 /**
Christopher Haster 1:43f5c94c6771 46 * \brief Enumeration for CoAP Message type, used in CoAP Header
Christopher Haster 1:43f5c94c6771 47 */
Christopher Haster 1:43f5c94c6771 48 typedef enum sn_coap_msg_type_ {
Christopher Haster 1:43f5c94c6771 49 COAP_MSG_TYPE_CONFIRMABLE = 0x00, /**< Reliable Request messages */
Christopher Haster 1:43f5c94c6771 50 COAP_MSG_TYPE_NON_CONFIRMABLE = 0x10, /**< Non-reliable Request and Response messages */
Christopher Haster 1:43f5c94c6771 51 COAP_MSG_TYPE_ACKNOWLEDGEMENT = 0x20, /**< Response to a Confirmable Request */
Christopher Haster 1:43f5c94c6771 52 COAP_MSG_TYPE_RESET = 0x30 /**< Answer a Bad Request */
Christopher Haster 1:43f5c94c6771 53 } sn_coap_msg_type_e;
Christopher Haster 1:43f5c94c6771 54
Christopher Haster 1:43f5c94c6771 55 /**
Christopher Haster 1:43f5c94c6771 56 * \brief Enumeration for CoAP Message code, used in CoAP Header
Christopher Haster 1:43f5c94c6771 57 */
Christopher Haster 1:43f5c94c6771 58 typedef enum sn_coap_msg_code_ {
Christopher Haster 1:43f5c94c6771 59 COAP_MSG_CODE_EMPTY = 0,
Christopher Haster 1:43f5c94c6771 60 COAP_MSG_CODE_REQUEST_GET = 1,
Christopher Haster 1:43f5c94c6771 61 COAP_MSG_CODE_REQUEST_POST = 2,
Christopher Haster 1:43f5c94c6771 62 COAP_MSG_CODE_REQUEST_PUT = 3,
Christopher Haster 1:43f5c94c6771 63 COAP_MSG_CODE_REQUEST_DELETE = 4,
Christopher Haster 1:43f5c94c6771 64
Christopher Haster 1:43f5c94c6771 65 COAP_MSG_CODE_RESPONSE_CREATED = 65,
Christopher Haster 1:43f5c94c6771 66 COAP_MSG_CODE_RESPONSE_DELETED = 66,
Christopher Haster 1:43f5c94c6771 67 COAP_MSG_CODE_RESPONSE_VALID = 67,
Christopher Haster 1:43f5c94c6771 68 COAP_MSG_CODE_RESPONSE_CHANGED = 68,
Christopher Haster 1:43f5c94c6771 69 COAP_MSG_CODE_RESPONSE_CONTENT = 69,
Christopher Haster 1:43f5c94c6771 70 COAP_MSG_CODE_RESPONSE_BAD_REQUEST = 128,
Christopher Haster 1:43f5c94c6771 71 COAP_MSG_CODE_RESPONSE_UNAUTHORIZED = 129,
Christopher Haster 1:43f5c94c6771 72 COAP_MSG_CODE_RESPONSE_BAD_OPTION = 130,
Christopher Haster 1:43f5c94c6771 73 COAP_MSG_CODE_RESPONSE_FORBIDDEN = 131,
Christopher Haster 1:43f5c94c6771 74 COAP_MSG_CODE_RESPONSE_NOT_FOUND = 132,
Christopher Haster 1:43f5c94c6771 75 COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED = 133,
Christopher Haster 1:43f5c94c6771 76 COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE = 134,
Christopher Haster 1:43f5c94c6771 77 COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE = 136,
Christopher Haster 1:43f5c94c6771 78 COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED = 140,
Christopher Haster 1:43f5c94c6771 79 COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE = 141,
Christopher Haster 1:43f5c94c6771 80 COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT = 143,
Christopher Haster 1:43f5c94c6771 81 COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR = 160,
Christopher Haster 1:43f5c94c6771 82 COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED = 161,
Christopher Haster 1:43f5c94c6771 83 COAP_MSG_CODE_RESPONSE_BAD_GATEWAY = 162,
Christopher Haster 1:43f5c94c6771 84 COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE = 163,
Christopher Haster 1:43f5c94c6771 85 COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT = 164,
Christopher Haster 1:43f5c94c6771 86 COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED = 165
Christopher Haster 1:43f5c94c6771 87 } sn_coap_msg_code_e;
Christopher Haster 1:43f5c94c6771 88
Christopher Haster 1:43f5c94c6771 89 /**
Christopher Haster 1:43f5c94c6771 90 * \brief Enumeration for CoAP Option number, used in CoAP Header
Christopher Haster 1:43f5c94c6771 91 */
Christopher Haster 1:43f5c94c6771 92 typedef enum sn_coap_option_numbers_ {
Christopher Haster 1:43f5c94c6771 93 COAP_OPTION_IF_MATCH = 1,
Christopher Haster 1:43f5c94c6771 94 COAP_OPTION_URI_HOST = 3,
Christopher Haster 1:43f5c94c6771 95 COAP_OPTION_ETAG = 4,
Christopher Haster 1:43f5c94c6771 96 COAP_OPTION_IF_NONE_MATCH = 5,
Christopher Haster 1:43f5c94c6771 97 COAP_OPTION_OBSERVE = 6,
Christopher Haster 1:43f5c94c6771 98 COAP_OPTION_URI_PORT = 7,
Christopher Haster 1:43f5c94c6771 99 COAP_OPTION_LOCATION_PATH = 8,
Christopher Haster 1:43f5c94c6771 100 COAP_OPTION_URI_PATH = 11,
Christopher Haster 1:43f5c94c6771 101 COAP_OPTION_CONTENT_FORMAT = 12,
Christopher Haster 1:43f5c94c6771 102 COAP_OPTION_MAX_AGE = 14,
Christopher Haster 1:43f5c94c6771 103 COAP_OPTION_URI_QUERY = 15,
Christopher Haster 1:43f5c94c6771 104 COAP_OPTION_ACCEPT = 17,
Christopher Haster 1:43f5c94c6771 105 COAP_OPTION_LOCATION_QUERY = 20,
Christopher Haster 1:43f5c94c6771 106 COAP_OPTION_BLOCK2 = 23,
Christopher Haster 1:43f5c94c6771 107 COAP_OPTION_BLOCK1 = 27,
Christopher Haster 1:43f5c94c6771 108 COAP_OPTION_PROXY_URI = 35,
Christopher Haster 1:43f5c94c6771 109 COAP_OPTION_PROXY_SCHEME = 39,
Christopher Haster 1:43f5c94c6771 110 COAP_OPTION_SIZE1 = 60
Christopher Haster 1:43f5c94c6771 111 // 128 = (Reserved)
Christopher Haster 1:43f5c94c6771 112 // 132 = (Reserved)
Christopher Haster 1:43f5c94c6771 113 // 136 = (Reserved)
Christopher Haster 1:43f5c94c6771 114 } sn_coap_option_numbers_e;
Christopher Haster 1:43f5c94c6771 115
Christopher Haster 1:43f5c94c6771 116 /**
Christopher Haster 1:43f5c94c6771 117 * \brief Enumeration for CoAP Content Format codes
Christopher Haster 1:43f5c94c6771 118 */
Christopher Haster 1:43f5c94c6771 119 typedef enum sn_coap_content_format_ {
Christopher Haster 1:43f5c94c6771 120 COAP_CT_NONE = -1,
Christopher Haster 1:43f5c94c6771 121 COAP_CT_TEXT_PLAIN = 0,
Christopher Haster 1:43f5c94c6771 122 COAP_CT_LINK_FORMAT = 40,
Christopher Haster 1:43f5c94c6771 123 COAP_CT_XML = 41,
Christopher Haster 1:43f5c94c6771 124 COAP_CT_OCTET_STREAM = 42,
Christopher Haster 1:43f5c94c6771 125 COAP_CT_EXI = 47,
Christopher Haster 1:43f5c94c6771 126 COAP_CT_JSON = 50
Christopher Haster 1:43f5c94c6771 127 } sn_coap_content_format_e;
Christopher Haster 1:43f5c94c6771 128
Christopher Haster 1:43f5c94c6771 129 /**
Christopher Haster 1:43f5c94c6771 130 * \brief Enumeration for CoAP status, used in CoAP Header
Christopher Haster 1:43f5c94c6771 131 */
Christopher Haster 1:43f5c94c6771 132 typedef enum sn_coap_status_ {
Christopher Haster 1:43f5c94c6771 133 COAP_STATUS_OK = 0, /**< Default value is OK */
Christopher Haster 1:43f5c94c6771 134 COAP_STATUS_PARSER_ERROR_IN_HEADER = 1, /**< CoAP will send Reset message to invalid message sender */
Christopher Haster 1:43f5c94c6771 135 COAP_STATUS_PARSER_DUPLICATED_MSG = 2, /**< CoAP will send Acknowledgement message to duplicated message sender */
Christopher Haster 1:43f5c94c6771 136 COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING = 3, /**< User will get whole message after all message blocks received.
Christopher Haster 1:43f5c94c6771 137 User must release messages with this status. */
Christopher Haster 1:43f5c94c6771 138 COAP_STATUS_PARSER_BLOCKWISE_ACK = 4, /**< Acknowledgement for sent Blockwise message received */
Christopher Haster 1:43f5c94c6771 139 COAP_STATUS_PARSER_BLOCKWISE_MSG_REJECTED = 5, /**< Blockwise message received but not supported by compiling switch */
Christopher Haster 1:43f5c94c6771 140 COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED = 6, /**< Blockwise message fully received and returned to app.
Christopher Haster 1:43f5c94c6771 141 User must take care of releasing whole payload of the blockwise messages */
Christopher Haster 1:43f5c94c6771 142 COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED = 7 /**< When re-transmissions have been done and ACK not received, CoAP library calls
Christopher Haster 1:43f5c94c6771 143 RX callback with this status */
Christopher Haster 1:43f5c94c6771 144 } sn_coap_status_e;
Christopher Haster 1:43f5c94c6771 145
Christopher Haster 1:43f5c94c6771 146
Christopher Haster 1:43f5c94c6771 147 /* * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 148 /* * * * STRUCTURES * * * */
Christopher Haster 1:43f5c94c6771 149 /* * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 150
Christopher Haster 1:43f5c94c6771 151 /**
Christopher Haster 1:43f5c94c6771 152 * \brief Structure for CoAP Options
Christopher Haster 1:43f5c94c6771 153 */
Christopher Haster 1:43f5c94c6771 154 typedef struct sn_coap_options_list_ {
Christopher Haster 1:43f5c94c6771 155
Christopher Haster 1:43f5c94c6771 156 uint8_t max_age_len; /**< 0-4 bytes. */
Christopher Haster 1:43f5c94c6771 157 uint8_t *max_age_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 158
Christopher Haster 1:43f5c94c6771 159 uint16_t proxy_uri_len; /**< 1-1034 bytes. */
Christopher Haster 1:43f5c94c6771 160 uint8_t *proxy_uri_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 161
Christopher Haster 1:43f5c94c6771 162 uint8_t etag_len; /**< 1-8 bytes. Repeatable */
Christopher Haster 1:43f5c94c6771 163 uint8_t *etag_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 164
Christopher Haster 1:43f5c94c6771 165 uint16_t uri_host_len; /**< 1-255 bytes. */
Christopher Haster 1:43f5c94c6771 166 uint8_t *uri_host_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 167
Christopher Haster 1:43f5c94c6771 168 uint16_t location_path_len; /**< 0-255 bytes. Repeatable */
Christopher Haster 1:43f5c94c6771 169 uint8_t *location_path_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 170
Christopher Haster 1:43f5c94c6771 171 uint8_t uri_port_len; /**< 0-2 bytes. */
Christopher Haster 1:43f5c94c6771 172 uint8_t *uri_port_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 173
Christopher Haster 1:43f5c94c6771 174 uint16_t location_query_len; /**< 0-255 bytes. Repeatable */
Christopher Haster 1:43f5c94c6771 175 uint8_t *location_query_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 176
Christopher Haster 1:43f5c94c6771 177 uint8_t observe;
Christopher Haster 1:43f5c94c6771 178 uint8_t observe_len; /**< 0-2 bytes. */
Christopher Haster 1:43f5c94c6771 179 uint8_t *observe_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 180
Christopher Haster 1:43f5c94c6771 181 uint8_t accept_len; /**< 0-2 bytes. Repeatable */
Christopher Haster 1:43f5c94c6771 182 uint8_t *accept_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 183
Christopher Haster 1:43f5c94c6771 184 uint16_t uri_query_len; /**< 1-255 bytes. Repeatable */
Christopher Haster 1:43f5c94c6771 185 uint8_t *uri_query_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 186
Christopher Haster 1:43f5c94c6771 187 uint8_t block1_len; /**< 0-3 bytes. */
Christopher Haster 1:43f5c94c6771 188 uint8_t *block1_ptr; /**< Not for User */
Christopher Haster 1:43f5c94c6771 189
Christopher Haster 1:43f5c94c6771 190 uint8_t block2_len; /**< 0-3 bytes. */
Christopher Haster 1:43f5c94c6771 191 uint8_t *block2_ptr; /**< Not for User */
Christopher Haster 1:43f5c94c6771 192 } sn_coap_options_list_s;
Christopher Haster 1:43f5c94c6771 193
Christopher Haster 1:43f5c94c6771 194
Christopher Haster 1:43f5c94c6771 195 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
Christopher Haster 1:43f5c94c6771 196 /* !!! Main CoAP message struct !!! */
Christopher Haster 1:43f5c94c6771 197 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
Christopher Haster 1:43f5c94c6771 198
Christopher Haster 1:43f5c94c6771 199 /**
Christopher Haster 1:43f5c94c6771 200 * \brief Main CoAP message struct
Christopher Haster 1:43f5c94c6771 201 */
Christopher Haster 1:43f5c94c6771 202 typedef struct sn_coap_hdr_ {
Christopher Haster 1:43f5c94c6771 203 sn_coap_status_e coap_status; /**< Used for telling to User special cases when parsing message */
Christopher Haster 1:43f5c94c6771 204
Christopher Haster 1:43f5c94c6771 205 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 206 /* * * * Header * * * */
Christopher Haster 1:43f5c94c6771 207 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 208
Christopher Haster 1:43f5c94c6771 209 sn_coap_msg_type_e msg_type; /**< Confirmable, Non-Confirmable, Acknowledgement or Reset */
Christopher Haster 1:43f5c94c6771 210 sn_coap_msg_code_e msg_code; /**< Empty: 0; Requests: 1-31; Responses: 64-191 */
Christopher Haster 1:43f5c94c6771 211 uint16_t msg_id; /**< Message ID. Parser sets parsed message ID, builder sets message ID of built coap message */
Christopher Haster 1:43f5c94c6771 212
Christopher Haster 1:43f5c94c6771 213 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 214 /* * * * Options * * * */
Christopher Haster 1:43f5c94c6771 215 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 216
Christopher Haster 1:43f5c94c6771 217 /* Here are most often used Options */
Christopher Haster 1:43f5c94c6771 218
Christopher Haster 1:43f5c94c6771 219 uint16_t uri_path_len; /**< 0-255 bytes. Repeatable. */
Christopher Haster 1:43f5c94c6771 220 uint8_t *uri_path_ptr; /**< Must be set to NULL if not used. E.g: temp1/temp2 */
Christopher Haster 1:43f5c94c6771 221
Christopher Haster 1:43f5c94c6771 222 uint8_t token_len; /**< 1-8 bytes. */
Christopher Haster 1:43f5c94c6771 223 uint8_t *token_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 224
Christopher Haster 1:43f5c94c6771 225 uint8_t content_type_len; /**< 0-2 bytes. */
Christopher Haster 1:43f5c94c6771 226 uint8_t *content_type_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 227
Christopher Haster 1:43f5c94c6771 228 /* Here are not so often used Options */
Christopher Haster 1:43f5c94c6771 229 sn_coap_options_list_s *options_list_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 230
Christopher Haster 1:43f5c94c6771 231 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 232 /* * * * Payload * * * */
Christopher Haster 1:43f5c94c6771 233 /* * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 234
Christopher Haster 1:43f5c94c6771 235 uint16_t payload_len; /**< Must be set to zero if not used */
Christopher Haster 1:43f5c94c6771 236 uint8_t *payload_ptr; /**< Must be set to NULL if not used */
Christopher Haster 1:43f5c94c6771 237 } sn_coap_hdr_s;
Christopher Haster 1:43f5c94c6771 238
Christopher Haster 1:43f5c94c6771 239 /* * * * * * * * * * * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 240 /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */
Christopher Haster 1:43f5c94c6771 241 /* * * * * * * * * * * * * * * * * * * * * * */
Christopher Haster 1:43f5c94c6771 242 /**
Christopher Haster 1:43f5c94c6771 243 * \fn sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr)
Christopher Haster 1:43f5c94c6771 244 *
Christopher Haster 1:43f5c94c6771 245 * \brief Parses CoAP message from given Packet data
Christopher Haster 1:43f5c94c6771 246 *
Christopher Haster 1:43f5c94c6771 247 * \param *handle Pointer to CoAP library handle
Christopher Haster 1:43f5c94c6771 248 *
Christopher Haster 1:43f5c94c6771 249 * \param packet_data_len is length of given Packet data to be parsed to CoAP message
Christopher Haster 1:43f5c94c6771 250 *
Christopher Haster 1:43f5c94c6771 251 * \param *packet_data_ptr is source for Packet data to be parsed to CoAP message
Christopher Haster 1:43f5c94c6771 252 *
Christopher Haster 1:43f5c94c6771 253 * \param *coap_version_ptr is destination for parsed CoAP specification version
Christopher Haster 1:43f5c94c6771 254 *
Christopher Haster 1:43f5c94c6771 255 * \return Return value is pointer to parsed CoAP message.\n
Christopher Haster 1:43f5c94c6771 256 * In following failure cases NULL is returned:\n
Christopher Haster 1:43f5c94c6771 257 * -Failure in given pointer (= NULL)\n
Christopher Haster 1:43f5c94c6771 258 * -Failure in memory allocation (malloc() returns NULL)
Christopher Haster 1:43f5c94c6771 259 */
Christopher Haster 1:43f5c94c6771 260 extern sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr);
Christopher Haster 1:43f5c94c6771 261
Christopher Haster 1:43f5c94c6771 262 /**
Christopher Haster 1:43f5c94c6771 263 * \fn void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr)
Christopher Haster 1:43f5c94c6771 264 *
Christopher Haster 1:43f5c94c6771 265 * \brief Releases memory of given CoAP message
Christopher Haster 1:43f5c94c6771 266 *
Christopher Haster 1:43f5c94c6771 267 * Note!!! Does not release Payload part
Christopher Haster 1:43f5c94c6771 268 *
Christopher Haster 1:43f5c94c6771 269 * \param *handle Pointer to CoAP library handle
Christopher Haster 1:43f5c94c6771 270 *
Christopher Haster 1:43f5c94c6771 271 * \param *freed_coap_msg_ptr is pointer to released CoAP message
Christopher Haster 1:43f5c94c6771 272 */
Christopher Haster 1:43f5c94c6771 273 extern void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr);
Christopher Haster 1:43f5c94c6771 274
Christopher Haster 1:43f5c94c6771 275 /**
Christopher Haster 1:43f5c94c6771 276 * \fn int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr)
Christopher Haster 1:43f5c94c6771 277 *
Christopher Haster 1:43f5c94c6771 278 * \brief Builds an outgoing message buffer from a CoAP header structure.
Christopher Haster 1:43f5c94c6771 279 *
Christopher Haster 1:43f5c94c6771 280 * \param *dst_packet_data_ptr is pointer to allocated destination to built CoAP packet
Christopher Haster 1:43f5c94c6771 281 *
Christopher Haster 1:43f5c94c6771 282 * \param *src_coap_msg_ptr is pointer to source structure for building Packet data
Christopher Haster 1:43f5c94c6771 283 *
Christopher Haster 1:43f5c94c6771 284 * \return Return value is byte count of built Packet data. In failure cases:\n
Christopher Haster 1:43f5c94c6771 285 * -1 = Failure in given CoAP header structure\n
Christopher Haster 1:43f5c94c6771 286 * -2 = Failure in given pointer (= NULL)
Christopher Haster 1:43f5c94c6771 287 */
Christopher Haster 1:43f5c94c6771 288 extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr);
Christopher Haster 1:43f5c94c6771 289
Christopher Haster 1:43f5c94c6771 290 /**
Christopher Haster 1:43f5c94c6771 291 * \fn uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr)
Christopher Haster 1:43f5c94c6771 292 *
Christopher Haster 1:43f5c94c6771 293 * \brief Calculates needed Packet data memory size for given CoAP message
Christopher Haster 1:43f5c94c6771 294 *
Christopher Haster 1:43f5c94c6771 295 * \param *src_coap_msg_ptr is pointer to data which needed Packet
Christopher Haster 1:43f5c94c6771 296 * data length is calculated
Christopher Haster 1:43f5c94c6771 297 *
Christopher Haster 1:43f5c94c6771 298 * \return Return value is count of needed memory as bytes for build Packet data
Christopher Haster 1:43f5c94c6771 299 * Null if failed
Christopher Haster 1:43f5c94c6771 300 */
Christopher Haster 1:43f5c94c6771 301 extern uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr);
Christopher Haster 1:43f5c94c6771 302
Christopher Haster 1:43f5c94c6771 303 /**
Christopher Haster 1:43f5c94c6771 304 * \fn sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code)
Christopher Haster 1:43f5c94c6771 305 *
Christopher Haster 1:43f5c94c6771 306 * \brief Prepares generic response packet from a request packet. This function allocates memory for the resulting sn_coap_hdr_s
Christopher Haster 1:43f5c94c6771 307 *
Christopher Haster 1:43f5c94c6771 308 * \param *handle Pointer to CoAP library handle
Christopher Haster 1:43f5c94c6771 309 * \param *coap_packet_ptr The request packet pointer
Christopher Haster 1:43f5c94c6771 310 * \param msg_code response messages code
Christopher Haster 1:43f5c94c6771 311 *
Christopher Haster 1:43f5c94c6771 312 * \return *coap_packet_ptr The allocated and pre-filled response packet pointer
Christopher Haster 1:43f5c94c6771 313 * NULL Error in parsing the request
Christopher Haster 1:43f5c94c6771 314 *
Christopher Haster 1:43f5c94c6771 315 */
Christopher Haster 1:43f5c94c6771 316 extern sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code);
Christopher Haster 1:43f5c94c6771 317
Christopher Haster 1:43f5c94c6771 318 #ifdef __cplusplus
Christopher Haster 1:43f5c94c6771 319 }
Christopher Haster 1:43f5c94c6771 320 #endif
Christopher Haster 1:43f5c94c6771 321
Christopher Haster 1:43f5c94c6771 322 #endif /* SN_COAP_HEADER_H_ */
Christopher Haster 1:43f5c94c6771 323