hello

Dependents:   nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2

Fork of nsdl by Robert Taylor

Committer:
GeofferyOmlette
Date:
Wed Jun 04 15:38:26 2014 +0000
Revision:
0:f6e4e1bbb3fe
hello

Who changed what in which revision?

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