Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
simple-mbed-cloud-client/mbed-cloud-client/mbed-coap/mbed-coap/sn_coap_header.h@4:e518dde96e59, 2018-10-25 (annotated)
- Committer:
- JimCarver
- Date:
- Thu Oct 25 14:00:12 2018 +0000
- Revision:
- 4:e518dde96e59
- Parent:
- 0:6b753f761943
Simulated dispenser
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimCarver | 0:6b753f761943 | 1 | /* |
JimCarver | 0:6b753f761943 | 2 | * Copyright (c) 2011-2015 ARM Limited. All rights reserved. |
JimCarver | 0:6b753f761943 | 3 | * SPDX-License-Identifier: Apache-2.0 |
JimCarver | 0:6b753f761943 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
JimCarver | 0:6b753f761943 | 5 | * not use this file except in compliance with the License. |
JimCarver | 0:6b753f761943 | 6 | * You may obtain a copy of the License at |
JimCarver | 0:6b753f761943 | 7 | * |
JimCarver | 0:6b753f761943 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
JimCarver | 0:6b753f761943 | 9 | * |
JimCarver | 0:6b753f761943 | 10 | * Unless required by applicable law or agreed to in writing, software |
JimCarver | 0:6b753f761943 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
JimCarver | 0:6b753f761943 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JimCarver | 0:6b753f761943 | 13 | * See the License for the specific language governing permissions and |
JimCarver | 0:6b753f761943 | 14 | * limitations under the License. |
JimCarver | 0:6b753f761943 | 15 | */ |
JimCarver | 0:6b753f761943 | 16 | |
JimCarver | 0:6b753f761943 | 17 | /** |
JimCarver | 0:6b753f761943 | 18 | * \file sn_coap_header.h |
JimCarver | 0:6b753f761943 | 19 | * |
JimCarver | 0:6b753f761943 | 20 | * \brief CoAP C-library User header interface header file |
JimCarver | 0:6b753f761943 | 21 | */ |
JimCarver | 0:6b753f761943 | 22 | |
JimCarver | 0:6b753f761943 | 23 | #ifndef SN_COAP_HEADER_H_ |
JimCarver | 0:6b753f761943 | 24 | #define SN_COAP_HEADER_H_ |
JimCarver | 0:6b753f761943 | 25 | |
JimCarver | 0:6b753f761943 | 26 | #ifdef __cplusplus |
JimCarver | 0:6b753f761943 | 27 | extern "C" { |
JimCarver | 0:6b753f761943 | 28 | #endif |
JimCarver | 0:6b753f761943 | 29 | |
JimCarver | 0:6b753f761943 | 30 | /* Handle structure */ |
JimCarver | 0:6b753f761943 | 31 | struct coap_s; |
JimCarver | 0:6b753f761943 | 32 | |
JimCarver | 0:6b753f761943 | 33 | /* * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 34 | /* * * * ENUMERATIONS * * * */ |
JimCarver | 0:6b753f761943 | 35 | /* * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 36 | |
JimCarver | 0:6b753f761943 | 37 | /** |
JimCarver | 0:6b753f761943 | 38 | * \brief Enumeration for CoAP Version |
JimCarver | 0:6b753f761943 | 39 | */ |
JimCarver | 0:6b753f761943 | 40 | typedef enum coap_version_ { |
JimCarver | 0:6b753f761943 | 41 | COAP_VERSION_1 = 0x40, |
JimCarver | 0:6b753f761943 | 42 | COAP_VERSION_UNKNOWN = 0xFF |
JimCarver | 0:6b753f761943 | 43 | } coap_version_e; |
JimCarver | 0:6b753f761943 | 44 | |
JimCarver | 0:6b753f761943 | 45 | /** |
JimCarver | 0:6b753f761943 | 46 | * \brief Enumeration for CoAP Message type, used in CoAP Header |
JimCarver | 0:6b753f761943 | 47 | */ |
JimCarver | 0:6b753f761943 | 48 | typedef enum sn_coap_msg_type_ { |
JimCarver | 0:6b753f761943 | 49 | COAP_MSG_TYPE_CONFIRMABLE = 0x00, /**< Reliable Request messages */ |
JimCarver | 0:6b753f761943 | 50 | COAP_MSG_TYPE_NON_CONFIRMABLE = 0x10, /**< Non-reliable Request and Response messages */ |
JimCarver | 0:6b753f761943 | 51 | COAP_MSG_TYPE_ACKNOWLEDGEMENT = 0x20, /**< Response to a Confirmable Request */ |
JimCarver | 0:6b753f761943 | 52 | COAP_MSG_TYPE_RESET = 0x30 /**< Answer a Bad Request */ |
JimCarver | 0:6b753f761943 | 53 | } sn_coap_msg_type_e; |
JimCarver | 0:6b753f761943 | 54 | |
JimCarver | 0:6b753f761943 | 55 | /** |
JimCarver | 0:6b753f761943 | 56 | * \brief Enumeration for CoAP Message code, used in CoAP Header |
JimCarver | 0:6b753f761943 | 57 | */ |
JimCarver | 0:6b753f761943 | 58 | typedef enum sn_coap_msg_code_ { |
JimCarver | 0:6b753f761943 | 59 | COAP_MSG_CODE_EMPTY = 0, |
JimCarver | 0:6b753f761943 | 60 | COAP_MSG_CODE_REQUEST_GET = 1, |
JimCarver | 0:6b753f761943 | 61 | COAP_MSG_CODE_REQUEST_POST = 2, |
JimCarver | 0:6b753f761943 | 62 | COAP_MSG_CODE_REQUEST_PUT = 3, |
JimCarver | 0:6b753f761943 | 63 | COAP_MSG_CODE_REQUEST_DELETE = 4, |
JimCarver | 0:6b753f761943 | 64 | |
JimCarver | 0:6b753f761943 | 65 | COAP_MSG_CODE_RESPONSE_CREATED = 65, |
JimCarver | 0:6b753f761943 | 66 | COAP_MSG_CODE_RESPONSE_DELETED = 66, |
JimCarver | 0:6b753f761943 | 67 | COAP_MSG_CODE_RESPONSE_VALID = 67, |
JimCarver | 0:6b753f761943 | 68 | COAP_MSG_CODE_RESPONSE_CHANGED = 68, |
JimCarver | 0:6b753f761943 | 69 | COAP_MSG_CODE_RESPONSE_CONTENT = 69, |
JimCarver | 0:6b753f761943 | 70 | COAP_MSG_CODE_RESPONSE_CONTINUE = 95, |
JimCarver | 0:6b753f761943 | 71 | COAP_MSG_CODE_RESPONSE_BAD_REQUEST = 128, |
JimCarver | 0:6b753f761943 | 72 | COAP_MSG_CODE_RESPONSE_UNAUTHORIZED = 129, |
JimCarver | 0:6b753f761943 | 73 | COAP_MSG_CODE_RESPONSE_BAD_OPTION = 130, |
JimCarver | 0:6b753f761943 | 74 | COAP_MSG_CODE_RESPONSE_FORBIDDEN = 131, |
JimCarver | 0:6b753f761943 | 75 | COAP_MSG_CODE_RESPONSE_NOT_FOUND = 132, |
JimCarver | 0:6b753f761943 | 76 | COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED = 133, |
JimCarver | 0:6b753f761943 | 77 | COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE = 134, |
JimCarver | 0:6b753f761943 | 78 | COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE = 136, |
JimCarver | 0:6b753f761943 | 79 | COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED = 140, |
JimCarver | 0:6b753f761943 | 80 | COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE = 141, |
JimCarver | 0:6b753f761943 | 81 | COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT = 143, |
JimCarver | 0:6b753f761943 | 82 | COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR = 160, |
JimCarver | 0:6b753f761943 | 83 | COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED = 161, |
JimCarver | 0:6b753f761943 | 84 | COAP_MSG_CODE_RESPONSE_BAD_GATEWAY = 162, |
JimCarver | 0:6b753f761943 | 85 | COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE = 163, |
JimCarver | 0:6b753f761943 | 86 | COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT = 164, |
JimCarver | 0:6b753f761943 | 87 | COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED = 165 |
JimCarver | 0:6b753f761943 | 88 | } sn_coap_msg_code_e; |
JimCarver | 0:6b753f761943 | 89 | |
JimCarver | 0:6b753f761943 | 90 | /** |
JimCarver | 0:6b753f761943 | 91 | * \brief Enumeration for CoAP Option number, used in CoAP Header |
JimCarver | 0:6b753f761943 | 92 | */ |
JimCarver | 0:6b753f761943 | 93 | typedef enum sn_coap_option_numbers_ { |
JimCarver | 0:6b753f761943 | 94 | COAP_OPTION_IF_MATCH = 1, |
JimCarver | 0:6b753f761943 | 95 | COAP_OPTION_URI_HOST = 3, |
JimCarver | 0:6b753f761943 | 96 | COAP_OPTION_ETAG = 4, |
JimCarver | 0:6b753f761943 | 97 | COAP_OPTION_IF_NONE_MATCH = 5, |
JimCarver | 0:6b753f761943 | 98 | COAP_OPTION_OBSERVE = 6, |
JimCarver | 0:6b753f761943 | 99 | COAP_OPTION_URI_PORT = 7, |
JimCarver | 0:6b753f761943 | 100 | COAP_OPTION_LOCATION_PATH = 8, |
JimCarver | 0:6b753f761943 | 101 | COAP_OPTION_URI_PATH = 11, |
JimCarver | 0:6b753f761943 | 102 | COAP_OPTION_CONTENT_FORMAT = 12, |
JimCarver | 0:6b753f761943 | 103 | COAP_OPTION_MAX_AGE = 14, |
JimCarver | 0:6b753f761943 | 104 | COAP_OPTION_URI_QUERY = 15, |
JimCarver | 0:6b753f761943 | 105 | COAP_OPTION_ACCEPT = 17, |
JimCarver | 0:6b753f761943 | 106 | COAP_OPTION_LOCATION_QUERY = 20, |
JimCarver | 0:6b753f761943 | 107 | COAP_OPTION_BLOCK2 = 23, |
JimCarver | 0:6b753f761943 | 108 | COAP_OPTION_BLOCK1 = 27, |
JimCarver | 0:6b753f761943 | 109 | COAP_OPTION_SIZE2 = 28, |
JimCarver | 0:6b753f761943 | 110 | COAP_OPTION_PROXY_URI = 35, |
JimCarver | 0:6b753f761943 | 111 | COAP_OPTION_PROXY_SCHEME = 39, |
JimCarver | 0:6b753f761943 | 112 | COAP_OPTION_SIZE1 = 60 |
JimCarver | 0:6b753f761943 | 113 | // 128 = (Reserved) |
JimCarver | 0:6b753f761943 | 114 | // 132 = (Reserved) |
JimCarver | 0:6b753f761943 | 115 | // 136 = (Reserved) |
JimCarver | 0:6b753f761943 | 116 | } sn_coap_option_numbers_e; |
JimCarver | 0:6b753f761943 | 117 | |
JimCarver | 0:6b753f761943 | 118 | /** |
JimCarver | 0:6b753f761943 | 119 | * \brief Enumeration for CoAP Content Format codes |
JimCarver | 0:6b753f761943 | 120 | */ |
JimCarver | 0:6b753f761943 | 121 | typedef enum sn_coap_content_format_ { |
JimCarver | 0:6b753f761943 | 122 | COAP_CT_NONE = -1, // internal |
JimCarver | 0:6b753f761943 | 123 | COAP_CT_TEXT_PLAIN = 0, |
JimCarver | 0:6b753f761943 | 124 | COAP_CT_LINK_FORMAT = 40, |
JimCarver | 0:6b753f761943 | 125 | COAP_CT_XML = 41, |
JimCarver | 0:6b753f761943 | 126 | COAP_CT_OCTET_STREAM = 42, |
JimCarver | 0:6b753f761943 | 127 | COAP_CT_EXI = 47, |
JimCarver | 0:6b753f761943 | 128 | COAP_CT_JSON = 50, |
JimCarver | 0:6b753f761943 | 129 | COAP_CT__MAX = 0xffff |
JimCarver | 0:6b753f761943 | 130 | } sn_coap_content_format_e; |
JimCarver | 0:6b753f761943 | 131 | |
JimCarver | 0:6b753f761943 | 132 | /** |
JimCarver | 0:6b753f761943 | 133 | * \brief Enumeration for CoAP Observe option values |
JimCarver | 0:6b753f761943 | 134 | * |
JimCarver | 0:6b753f761943 | 135 | * draft-ietf-core-observe-16 |
JimCarver | 0:6b753f761943 | 136 | */ |
JimCarver | 0:6b753f761943 | 137 | typedef enum sn_coap_observe_ { |
JimCarver | 0:6b753f761943 | 138 | COAP_OBSERVE_NONE = -1, // internal |
JimCarver | 0:6b753f761943 | 139 | |
JimCarver | 0:6b753f761943 | 140 | // Values for GET requests |
JimCarver | 0:6b753f761943 | 141 | COAP_OBSERVE_REGISTER = 0, |
JimCarver | 0:6b753f761943 | 142 | COAP_OBSERVE_DEREGISTER = 1, |
JimCarver | 0:6b753f761943 | 143 | |
JimCarver | 0:6b753f761943 | 144 | // In responses, value is a 24-bit opaque sequence number |
JimCarver | 0:6b753f761943 | 145 | COAP_OBSERVE__MAX = 0xffffff |
JimCarver | 0:6b753f761943 | 146 | } sn_coap_observe_e; |
JimCarver | 0:6b753f761943 | 147 | |
JimCarver | 0:6b753f761943 | 148 | /** |
JimCarver | 0:6b753f761943 | 149 | * \brief Enumeration for CoAP status, used in CoAP Header |
JimCarver | 0:6b753f761943 | 150 | */ |
JimCarver | 0:6b753f761943 | 151 | typedef enum sn_coap_status_ { |
JimCarver | 0:6b753f761943 | 152 | COAP_STATUS_OK = 0, /**< Default value is OK */ |
JimCarver | 0:6b753f761943 | 153 | COAP_STATUS_PARSER_ERROR_IN_HEADER = 1, /**< CoAP will send Reset message to invalid message sender */ |
JimCarver | 0:6b753f761943 | 154 | COAP_STATUS_PARSER_DUPLICATED_MSG = 2, /**< CoAP will send Acknowledgement message to duplicated message sender */ |
JimCarver | 0:6b753f761943 | 155 | COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING = 3, /**< User will get whole message after all message blocks received. |
JimCarver | 0:6b753f761943 | 156 | User must release messages with this status. */ |
JimCarver | 0:6b753f761943 | 157 | COAP_STATUS_PARSER_BLOCKWISE_ACK = 4, /**< Acknowledgement for sent Blockwise message received */ |
JimCarver | 0:6b753f761943 | 158 | COAP_STATUS_PARSER_BLOCKWISE_MSG_REJECTED = 5, /**< Blockwise message received but not supported by compiling switch */ |
JimCarver | 0:6b753f761943 | 159 | COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED = 6, /**< Blockwise message fully received and returned to app. |
JimCarver | 0:6b753f761943 | 160 | User must take care of releasing whole payload of the blockwise messages */ |
JimCarver | 0:6b753f761943 | 161 | COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED = 7, /**< When re-transmissions have been done and ACK not received, CoAP library calls |
JimCarver | 0:6b753f761943 | 162 | RX callback with this status */ |
JimCarver | 0:6b753f761943 | 163 | |
JimCarver | 0:6b753f761943 | 164 | COAP_STATUS_BUILDER_BLOCK_SENDING_FAILED = 8, /**< Blockwise message sending timeout. |
JimCarver | 0:6b753f761943 | 165 | The msg_id in sn_coap_hdr_s* parameter of RX callback is set to the same value |
JimCarver | 0:6b753f761943 | 166 | as in the first block sent, and parameter sn_nsdl_addr_s* is set as NULL. */ |
JimCarver | 0:6b753f761943 | 167 | COAP_STATUS_BUILDER_BLOCK_SENDING_DONE = 9 /**< Blockwise message sending, last block sent. |
JimCarver | 0:6b753f761943 | 168 | The msg_id in sn_coap_hdr_s* parameter of RX callback is set to the same value |
JimCarver | 0:6b753f761943 | 169 | as in the first block sent, and parameter sn_nsdl_addr_s* is set as NULL. */ |
JimCarver | 0:6b753f761943 | 170 | |
JimCarver | 0:6b753f761943 | 171 | } sn_coap_status_e; |
JimCarver | 0:6b753f761943 | 172 | |
JimCarver | 0:6b753f761943 | 173 | |
JimCarver | 0:6b753f761943 | 174 | /* * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 175 | /* * * * STRUCTURES * * * */ |
JimCarver | 0:6b753f761943 | 176 | /* * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 177 | |
JimCarver | 0:6b753f761943 | 178 | /** |
JimCarver | 0:6b753f761943 | 179 | * \brief Structure for CoAP Options |
JimCarver | 0:6b753f761943 | 180 | */ |
JimCarver | 0:6b753f761943 | 181 | typedef struct sn_coap_options_list_ { |
JimCarver | 0:6b753f761943 | 182 | uint8_t etag_len; /**< 1-8 bytes. Repeatable */ |
JimCarver | 0:6b753f761943 | 183 | unsigned int use_size1:1; |
JimCarver | 0:6b753f761943 | 184 | unsigned int use_size2:1; |
JimCarver | 0:6b753f761943 | 185 | |
JimCarver | 0:6b753f761943 | 186 | uint16_t proxy_uri_len; /**< 1-1034 bytes. */ |
JimCarver | 0:6b753f761943 | 187 | uint16_t uri_host_len; /**< 1-255 bytes. */ |
JimCarver | 0:6b753f761943 | 188 | uint16_t location_path_len; /**< 0-255 bytes. Repeatable */ |
JimCarver | 0:6b753f761943 | 189 | uint16_t location_query_len; /**< 0-255 bytes. Repeatable */ |
JimCarver | 0:6b753f761943 | 190 | uint16_t uri_query_len; /**< 1-255 bytes. Repeatable */ |
JimCarver | 0:6b753f761943 | 191 | |
JimCarver | 0:6b753f761943 | 192 | sn_coap_content_format_e accept; /**< Value 0-65535. COAP_CT_NONE if not used */ |
JimCarver | 0:6b753f761943 | 193 | |
JimCarver | 0:6b753f761943 | 194 | uint32_t max_age; /**< Value in seconds (default is 60) */ |
JimCarver | 0:6b753f761943 | 195 | uint32_t size1; /**< 0-4 bytes. */ |
JimCarver | 0:6b753f761943 | 196 | uint32_t size2; /**< 0-4 bytes. */ |
JimCarver | 0:6b753f761943 | 197 | int32_t uri_port; /**< Value 0-65535. -1 if not used */ |
JimCarver | 0:6b753f761943 | 198 | int32_t observe; /**< Value 0-0xffffff. -1 if not used */ |
JimCarver | 0:6b753f761943 | 199 | int32_t block1; /**< Value 0-0xffffff. -1 if not used. Not for user */ |
JimCarver | 0:6b753f761943 | 200 | int32_t block2; /**< Value 0-0xffffff. -1 if not used. Not for user */ |
JimCarver | 0:6b753f761943 | 201 | |
JimCarver | 0:6b753f761943 | 202 | uint8_t *proxy_uri_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 203 | uint8_t *etag_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 204 | uint8_t *uri_host_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 205 | uint8_t *location_path_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 206 | uint8_t *location_query_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 207 | uint8_t *uri_query_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 208 | } sn_coap_options_list_s; |
JimCarver | 0:6b753f761943 | 209 | |
JimCarver | 0:6b753f761943 | 210 | /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
JimCarver | 0:6b753f761943 | 211 | /* !!! Main CoAP message struct !!! */ |
JimCarver | 0:6b753f761943 | 212 | /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
JimCarver | 0:6b753f761943 | 213 | |
JimCarver | 0:6b753f761943 | 214 | /** |
JimCarver | 0:6b753f761943 | 215 | * \brief Main CoAP message struct |
JimCarver | 0:6b753f761943 | 216 | */ |
JimCarver | 0:6b753f761943 | 217 | typedef struct sn_coap_hdr_ { |
JimCarver | 0:6b753f761943 | 218 | uint8_t token_len; /**< 1-8 bytes. */ |
JimCarver | 0:6b753f761943 | 219 | |
JimCarver | 0:6b753f761943 | 220 | sn_coap_status_e coap_status; /**< Used for telling to User special cases when parsing message */ |
JimCarver | 0:6b753f761943 | 221 | sn_coap_msg_code_e msg_code; /**< Empty: 0; Requests: 1-31; Responses: 64-191 */ |
JimCarver | 0:6b753f761943 | 222 | |
JimCarver | 0:6b753f761943 | 223 | sn_coap_msg_type_e msg_type; /**< Confirmable, Non-Confirmable, Acknowledgement or Reset */ |
JimCarver | 0:6b753f761943 | 224 | sn_coap_content_format_e content_format; /**< Set to COAP_CT_NONE if not used */ |
JimCarver | 0:6b753f761943 | 225 | |
JimCarver | 0:6b753f761943 | 226 | uint16_t msg_id; /**< Message ID. Parser sets parsed message ID, builder sets message ID of built coap message */ |
JimCarver | 0:6b753f761943 | 227 | uint16_t uri_path_len; /**< 0-255 bytes. Repeatable. */ |
JimCarver | 0:6b753f761943 | 228 | uint16_t payload_len; /**< Must be set to zero if not used */ |
JimCarver | 0:6b753f761943 | 229 | |
JimCarver | 0:6b753f761943 | 230 | uint8_t *token_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 231 | uint8_t *uri_path_ptr; /**< Must be set to NULL if not used. E.g: temp1/temp2 */ |
JimCarver | 0:6b753f761943 | 232 | uint8_t *payload_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 233 | |
JimCarver | 0:6b753f761943 | 234 | /* Here are not so often used Options */ |
JimCarver | 0:6b753f761943 | 235 | sn_coap_options_list_s *options_list_ptr; /**< Must be set to NULL if not used */ |
JimCarver | 0:6b753f761943 | 236 | } sn_coap_hdr_s; |
JimCarver | 0:6b753f761943 | 237 | |
JimCarver | 0:6b753f761943 | 238 | /* * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 239 | /* * * * ENUMERATIONS * * * */ |
JimCarver | 0:6b753f761943 | 240 | /* * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 241 | |
JimCarver | 0:6b753f761943 | 242 | |
JimCarver | 0:6b753f761943 | 243 | /** |
JimCarver | 0:6b753f761943 | 244 | * \brief Used protocol |
JimCarver | 0:6b753f761943 | 245 | */ |
JimCarver | 0:6b753f761943 | 246 | typedef enum sn_nsdl_capab_ { |
JimCarver | 0:6b753f761943 | 247 | SN_NSDL_PROTOCOL_HTTP = 0x01, /**< Unsupported */ |
JimCarver | 0:6b753f761943 | 248 | SN_NSDL_PROTOCOL_HTTPS = 0x02, /**< Unsupported */ |
JimCarver | 0:6b753f761943 | 249 | SN_NSDL_PROTOCOL_COAP = 0x04 /**< Supported */ |
JimCarver | 0:6b753f761943 | 250 | } sn_nsdl_capab_e; |
JimCarver | 0:6b753f761943 | 251 | |
JimCarver | 0:6b753f761943 | 252 | /* * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 253 | /* * * * STRUCTURES * * * */ |
JimCarver | 0:6b753f761943 | 254 | /* * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 255 | |
JimCarver | 0:6b753f761943 | 256 | |
JimCarver | 0:6b753f761943 | 257 | /** |
JimCarver | 0:6b753f761943 | 258 | * \brief Used for creating manually registration message with sn_coap_register() |
JimCarver | 0:6b753f761943 | 259 | */ |
JimCarver | 0:6b753f761943 | 260 | typedef struct registration_info_ { |
JimCarver | 0:6b753f761943 | 261 | uint8_t endpoint_len; |
JimCarver | 0:6b753f761943 | 262 | uint8_t endpoint_type_len; |
JimCarver | 0:6b753f761943 | 263 | uint16_t links_len; |
JimCarver | 0:6b753f761943 | 264 | |
JimCarver | 0:6b753f761943 | 265 | uint8_t *endpoint_ptr; /**< Endpoint name */ |
JimCarver | 0:6b753f761943 | 266 | uint8_t *endpoint_type_ptr; /**< Endpoint type */ |
JimCarver | 0:6b753f761943 | 267 | uint8_t *links_ptr; /**< Resource registration string */ |
JimCarver | 0:6b753f761943 | 268 | } registration_info_t; |
JimCarver | 0:6b753f761943 | 269 | |
JimCarver | 0:6b753f761943 | 270 | |
JimCarver | 0:6b753f761943 | 271 | /** |
JimCarver | 0:6b753f761943 | 272 | * \brief Address type of given address |
JimCarver | 0:6b753f761943 | 273 | */ |
JimCarver | 0:6b753f761943 | 274 | typedef enum sn_nsdl_addr_type_ { |
JimCarver | 0:6b753f761943 | 275 | SN_NSDL_ADDRESS_TYPE_IPV6 = 0x01, /**< Supported */ |
JimCarver | 0:6b753f761943 | 276 | SN_NSDL_ADDRESS_TYPE_IPV4 = 0x02, /**< Supported */ |
JimCarver | 0:6b753f761943 | 277 | SN_NSDL_ADDRESS_TYPE_HOSTNAME = 0x03, /**< Unsupported */ |
JimCarver | 0:6b753f761943 | 278 | SN_NSDL_ADDRESS_TYPE_NONE = 0xFF |
JimCarver | 0:6b753f761943 | 279 | } sn_nsdl_addr_type_e; |
JimCarver | 0:6b753f761943 | 280 | |
JimCarver | 0:6b753f761943 | 281 | /** |
JimCarver | 0:6b753f761943 | 282 | * \brief Address structure of Packet data |
JimCarver | 0:6b753f761943 | 283 | */ |
JimCarver | 0:6b753f761943 | 284 | typedef struct sn_nsdl_addr_ { |
JimCarver | 0:6b753f761943 | 285 | uint8_t addr_len; |
JimCarver | 0:6b753f761943 | 286 | sn_nsdl_addr_type_e type; |
JimCarver | 0:6b753f761943 | 287 | uint16_t port; |
JimCarver | 0:6b753f761943 | 288 | uint8_t *addr_ptr; |
JimCarver | 0:6b753f761943 | 289 | } sn_nsdl_addr_s; |
JimCarver | 0:6b753f761943 | 290 | |
JimCarver | 0:6b753f761943 | 291 | |
JimCarver | 0:6b753f761943 | 292 | /* * * * * * * * * * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 293 | /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */ |
JimCarver | 0:6b753f761943 | 294 | /* * * * * * * * * * * * * * * * * * * * * * */ |
JimCarver | 0:6b753f761943 | 295 | /** |
JimCarver | 0:6b753f761943 | 296 | * \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) |
JimCarver | 0:6b753f761943 | 297 | * |
JimCarver | 0:6b753f761943 | 298 | * \brief Parses CoAP message from given Packet data |
JimCarver | 0:6b753f761943 | 299 | * |
JimCarver | 0:6b753f761943 | 300 | * \param *handle Pointer to CoAP library handle |
JimCarver | 0:6b753f761943 | 301 | * |
JimCarver | 0:6b753f761943 | 302 | * \param packet_data_len is length of given Packet data to be parsed to CoAP message |
JimCarver | 0:6b753f761943 | 303 | * |
JimCarver | 0:6b753f761943 | 304 | * \param *packet_data_ptr is source for Packet data to be parsed to CoAP message |
JimCarver | 0:6b753f761943 | 305 | * |
JimCarver | 0:6b753f761943 | 306 | * \param *coap_version_ptr is destination for parsed CoAP specification version |
JimCarver | 0:6b753f761943 | 307 | * |
JimCarver | 0:6b753f761943 | 308 | * \return Return value is pointer to parsed CoAP message.\n |
JimCarver | 0:6b753f761943 | 309 | * In following failure cases NULL is returned:\n |
JimCarver | 0:6b753f761943 | 310 | * -Failure in given pointer (= NULL)\n |
JimCarver | 0:6b753f761943 | 311 | * -Failure in memory allocation (malloc() returns NULL) |
JimCarver | 0:6b753f761943 | 312 | */ |
JimCarver | 0:6b753f761943 | 313 | 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); |
JimCarver | 0:6b753f761943 | 314 | |
JimCarver | 0:6b753f761943 | 315 | /** |
JimCarver | 0:6b753f761943 | 316 | * \fn void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) |
JimCarver | 0:6b753f761943 | 317 | * |
JimCarver | 0:6b753f761943 | 318 | * \brief Releases memory of given CoAP message |
JimCarver | 0:6b753f761943 | 319 | * |
JimCarver | 0:6b753f761943 | 320 | * Note!!! Does not release Payload part |
JimCarver | 0:6b753f761943 | 321 | * |
JimCarver | 0:6b753f761943 | 322 | * \param *handle Pointer to CoAP library handle |
JimCarver | 0:6b753f761943 | 323 | * |
JimCarver | 0:6b753f761943 | 324 | * \param *freed_coap_msg_ptr is pointer to released CoAP message |
JimCarver | 0:6b753f761943 | 325 | */ |
JimCarver | 0:6b753f761943 | 326 | extern void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr); |
JimCarver | 0:6b753f761943 | 327 | |
JimCarver | 0:6b753f761943 | 328 | /** |
JimCarver | 0:6b753f761943 | 329 | * \fn int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr) |
JimCarver | 0:6b753f761943 | 330 | * |
JimCarver | 0:6b753f761943 | 331 | * \brief Builds an outgoing message buffer from a CoAP header structure. |
JimCarver | 0:6b753f761943 | 332 | * |
JimCarver | 0:6b753f761943 | 333 | * \param *dst_packet_data_ptr is pointer to allocated destination to built CoAP packet |
JimCarver | 0:6b753f761943 | 334 | * |
JimCarver | 0:6b753f761943 | 335 | * \param *src_coap_msg_ptr is pointer to source structure for building Packet data |
JimCarver | 0:6b753f761943 | 336 | * |
JimCarver | 0:6b753f761943 | 337 | * \return Return value is byte count of built Packet data. In failure cases:\n |
JimCarver | 0:6b753f761943 | 338 | * -1 = Failure in given CoAP header structure\n |
JimCarver | 0:6b753f761943 | 339 | * -2 = Failure in given pointer (= NULL) |
JimCarver | 0:6b753f761943 | 340 | */ |
JimCarver | 0:6b753f761943 | 341 | extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr); |
JimCarver | 0:6b753f761943 | 342 | |
JimCarver | 0:6b753f761943 | 343 | /** |
JimCarver | 0:6b753f761943 | 344 | * \fn uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr) |
JimCarver | 0:6b753f761943 | 345 | * |
JimCarver | 0:6b753f761943 | 346 | * \brief Calculates needed Packet data memory size for given CoAP message |
JimCarver | 0:6b753f761943 | 347 | * |
JimCarver | 0:6b753f761943 | 348 | * \param *src_coap_msg_ptr is pointer to data which needed Packet |
JimCarver | 0:6b753f761943 | 349 | * data length is calculated |
JimCarver | 0:6b753f761943 | 350 | * |
JimCarver | 0:6b753f761943 | 351 | * \return Return value is count of needed memory as bytes for build Packet data |
JimCarver | 0:6b753f761943 | 352 | * Null if failed |
JimCarver | 0:6b753f761943 | 353 | */ |
JimCarver | 0:6b753f761943 | 354 | extern uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr); |
JimCarver | 0:6b753f761943 | 355 | |
JimCarver | 0:6b753f761943 | 356 | /** |
JimCarver | 0:6b753f761943 | 357 | * \fn int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_size) |
JimCarver | 0:6b753f761943 | 358 | * |
JimCarver | 0:6b753f761943 | 359 | * \brief Builds an outgoing message buffer from a CoAP header structure. |
JimCarver | 0:6b753f761943 | 360 | * |
JimCarver | 0:6b753f761943 | 361 | * \param *dst_packet_data_ptr is pointer to allocated destination to built CoAP packet |
JimCarver | 0:6b753f761943 | 362 | * |
JimCarver | 0:6b753f761943 | 363 | * \param *src_coap_msg_ptr is pointer to source structure for building Packet data |
JimCarver | 0:6b753f761943 | 364 | * |
JimCarver | 0:6b753f761943 | 365 | * \param blockwise_payload_size Blockwise message maximum payload size |
JimCarver | 0:6b753f761943 | 366 | * |
JimCarver | 0:6b753f761943 | 367 | * \return Return value is byte count of built Packet data. In failure cases:\n |
JimCarver | 0:6b753f761943 | 368 | * -1 = Failure in given CoAP header structure\n |
JimCarver | 0:6b753f761943 | 369 | * -2 = Failure in given pointer (= NULL) |
JimCarver | 0:6b753f761943 | 370 | */ |
JimCarver | 0:6b753f761943 | 371 | extern int16_t sn_coap_builder_2(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size); |
JimCarver | 0:6b753f761943 | 372 | |
JimCarver | 0:6b753f761943 | 373 | /** |
JimCarver | 0:6b753f761943 | 374 | * \fn uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size) |
JimCarver | 0:6b753f761943 | 375 | * |
JimCarver | 0:6b753f761943 | 376 | * \brief Calculates needed Packet data memory size for given CoAP message |
JimCarver | 0:6b753f761943 | 377 | * |
JimCarver | 0:6b753f761943 | 378 | * \param *src_coap_msg_ptr is pointer to data which needed Packet |
JimCarver | 0:6b753f761943 | 379 | * data length is calculated |
JimCarver | 0:6b753f761943 | 380 | * \param blockwise_payload_size Blockwise message maximum payload size |
JimCarver | 0:6b753f761943 | 381 | * |
JimCarver | 0:6b753f761943 | 382 | * \return Return value is count of needed memory as bytes for build Packet data |
JimCarver | 0:6b753f761943 | 383 | * Null if failed |
JimCarver | 0:6b753f761943 | 384 | */ |
JimCarver | 0:6b753f761943 | 385 | extern uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size); |
JimCarver | 0:6b753f761943 | 386 | |
JimCarver | 0:6b753f761943 | 387 | /** |
JimCarver | 0:6b753f761943 | 388 | * \fn sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) |
JimCarver | 0:6b753f761943 | 389 | * |
JimCarver | 0:6b753f761943 | 390 | * \brief Prepares generic response packet from a request packet. This function allocates memory for the resulting sn_coap_hdr_s |
JimCarver | 0:6b753f761943 | 391 | * |
JimCarver | 0:6b753f761943 | 392 | * \param *handle Pointer to CoAP library handle |
JimCarver | 0:6b753f761943 | 393 | * \param *coap_packet_ptr The request packet pointer |
JimCarver | 0:6b753f761943 | 394 | * \param msg_code response messages code |
JimCarver | 0:6b753f761943 | 395 | * |
JimCarver | 0:6b753f761943 | 396 | * \return *coap_packet_ptr The allocated and pre-filled response packet pointer |
JimCarver | 0:6b753f761943 | 397 | * NULL Error in parsing the request |
JimCarver | 0:6b753f761943 | 398 | * |
JimCarver | 0:6b753f761943 | 399 | */ |
JimCarver | 0:6b753f761943 | 400 | extern sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code); |
JimCarver | 0:6b753f761943 | 401 | |
JimCarver | 0:6b753f761943 | 402 | /** |
JimCarver | 0:6b753f761943 | 403 | * \brief Initialise a message structure to empty |
JimCarver | 0:6b753f761943 | 404 | * |
JimCarver | 0:6b753f761943 | 405 | * \param *coap_msg_ptr is pointer to CoAP message to initialise |
JimCarver | 0:6b753f761943 | 406 | * |
JimCarver | 0:6b753f761943 | 407 | * \return Return value is pointer passed in |
JimCarver | 0:6b753f761943 | 408 | */ |
JimCarver | 0:6b753f761943 | 409 | extern sn_coap_hdr_s *sn_coap_parser_init_message(sn_coap_hdr_s *coap_msg_ptr); |
JimCarver | 0:6b753f761943 | 410 | |
JimCarver | 0:6b753f761943 | 411 | /** |
JimCarver | 0:6b753f761943 | 412 | * \brief Allocate an empty message structure |
JimCarver | 0:6b753f761943 | 413 | * |
JimCarver | 0:6b753f761943 | 414 | * \param *handle Pointer to CoAP library handle |
JimCarver | 0:6b753f761943 | 415 | * |
JimCarver | 0:6b753f761943 | 416 | * \return Return value is pointer to an empty CoAP message.\n |
JimCarver | 0:6b753f761943 | 417 | * In following failure cases NULL is returned:\n |
JimCarver | 0:6b753f761943 | 418 | * -Failure in given pointer (= NULL)\n |
JimCarver | 0:6b753f761943 | 419 | * -Failure in memory allocation (malloc() returns NULL) |
JimCarver | 0:6b753f761943 | 420 | */ |
JimCarver | 0:6b753f761943 | 421 | extern sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle); |
JimCarver | 0:6b753f761943 | 422 | |
JimCarver | 0:6b753f761943 | 423 | /** |
JimCarver | 0:6b753f761943 | 424 | * \brief Allocates and initializes options list structure |
JimCarver | 0:6b753f761943 | 425 | * |
JimCarver | 0:6b753f761943 | 426 | * \param *handle Pointer to CoAP library handle |
JimCarver | 0:6b753f761943 | 427 | * \param *coap_msg_ptr is pointer to CoAP message that will contain the options |
JimCarver | 0:6b753f761943 | 428 | * |
JimCarver | 0:6b753f761943 | 429 | * If the message already has a pointer to an option structure, that pointer |
JimCarver | 0:6b753f761943 | 430 | * is returned, rather than a new structure being allocated. |
JimCarver | 0:6b753f761943 | 431 | * |
JimCarver | 0:6b753f761943 | 432 | * \return Return value is pointer to the CoAP options structure.\n |
JimCarver | 0:6b753f761943 | 433 | * In following failure cases NULL is returned:\n |
JimCarver | 0:6b753f761943 | 434 | * -Failure in given pointer (= NULL)\n |
JimCarver | 0:6b753f761943 | 435 | * -Failure in memory allocation (malloc() returns NULL) |
JimCarver | 0:6b753f761943 | 436 | */ |
JimCarver | 0:6b753f761943 | 437 | extern sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_coap_hdr_s *coap_msg_ptr); |
JimCarver | 0:6b753f761943 | 438 | |
JimCarver | 0:6b753f761943 | 439 | #ifdef __cplusplus |
JimCarver | 0:6b753f761943 | 440 | } |
JimCarver | 0:6b753f761943 | 441 | #endif |
JimCarver | 0:6b753f761943 | 442 | |
JimCarver | 0:6b753f761943 | 443 | #endif /* SN_COAP_HEADER_H_ */ |