mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

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