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