NSDL C library

Dependents:   NSDL_HelloWorld_WiFi UbloxModemNanoServiceClient IOT-NSDL_HelloWorld LWM2M_NanoService_Ethernet ... more

Fork of nsdl_lib by Tero Heinonen

Note that use of this software requires acceptance of the Sensinode EULA: http://mbed.org/teams/Sensinode/code/nsdl_lib/wiki/EULA

Committer:
terohoo
Date:
Wed Oct 09 09:20:29 2013 +0000
Revision:
0:58c4f13c4b9a
Child:
1:01d723824294
Child:
5:da1db64e7fb9
Adding nsdl_lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terohoo 0:58c4f13c4b9a 1 /**
terohoo 0:58c4f13c4b9a 2 * \file sn_coap_header.h
terohoo 0:58c4f13c4b9a 3 *
terohoo 0:58c4f13c4b9a 4 * \brief CoAP C-library User header interface header file
terohoo 0:58c4f13c4b9a 5 *
terohoo 0:58c4f13c4b9a 6 * Created on: Jun 30, 2011
terohoo 0:58c4f13c4b9a 7 * Author: tero
terohoo 0:58c4f13c4b9a 8 *
terohoo 0:58c4f13c4b9a 9 * \note Supports draft-ietf-core-coap-18
terohoo 0:58c4f13c4b9a 10 */
terohoo 0:58c4f13c4b9a 11
terohoo 0:58c4f13c4b9a 12 #ifndef SN_COAP_HEADER_H_
terohoo 0:58c4f13c4b9a 13 #define SN_COAP_HEADER_H_
terohoo 0:58c4f13c4b9a 14
terohoo 0:58c4f13c4b9a 15 #ifdef __cplusplus
terohoo 0:58c4f13c4b9a 16 extern "C" {
terohoo 0:58c4f13c4b9a 17 #endif
terohoo 0:58c4f13c4b9a 18
terohoo 0:58c4f13c4b9a 19 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 20 /* * * * DEFINES * * * */
terohoo 0:58c4f13c4b9a 21 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 22
terohoo 0:58c4f13c4b9a 23 /* * * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 24 /* * * * ENUMERATIONS * * * */
terohoo 0:58c4f13c4b9a 25 /* * * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 26
terohoo 0:58c4f13c4b9a 27 /* Enumeration for CoAP Version */
terohoo 0:58c4f13c4b9a 28 typedef enum coap_version_
terohoo 0:58c4f13c4b9a 29 {
terohoo 0:58c4f13c4b9a 30 COAP_VERSION_1 = 0x40,
terohoo 0:58c4f13c4b9a 31 COAP_VERSION_UNKNOWN = 0xFF
terohoo 0:58c4f13c4b9a 32 } coap_version_e;
terohoo 0:58c4f13c4b9a 33
terohoo 0:58c4f13c4b9a 34 /* Enumeration for CoAP Message type, used in CoAP Header */
terohoo 0:58c4f13c4b9a 35 typedef enum sn_coap_msg_type_
terohoo 0:58c4f13c4b9a 36 {
terohoo 0:58c4f13c4b9a 37 COAP_MSG_TYPE_CONFIRMABLE = 0x00, /* User uses this for Reliable Request messages */
terohoo 0:58c4f13c4b9a 38 COAP_MSG_TYPE_NON_CONFIRMABLE = 0x10, /* User uses this for Non-reliable Request and Response messages */
terohoo 0:58c4f13c4b9a 39 COAP_MSG_TYPE_ACKNOWLEDGEMENT = 0x20, /* User uses this for Response to a Confirmable Request */
terohoo 0:58c4f13c4b9a 40 COAP_MSG_TYPE_RESET = 0x30 /* User uses this to answer a Bad Request */
terohoo 0:58c4f13c4b9a 41 } sn_coap_msg_type_e;
terohoo 0:58c4f13c4b9a 42
terohoo 0:58c4f13c4b9a 43 /* Enumeration for CoAP Message code, used in CoAP Header */
terohoo 0:58c4f13c4b9a 44 typedef enum sn_coap_msg_code_
terohoo 0:58c4f13c4b9a 45 {
terohoo 0:58c4f13c4b9a 46 COAP_MSG_CODE_EMPTY = 0,
terohoo 0:58c4f13c4b9a 47 COAP_MSG_CODE_REQUEST_GET = 1,
terohoo 0:58c4f13c4b9a 48 COAP_MSG_CODE_REQUEST_POST = 2,
terohoo 0:58c4f13c4b9a 49 COAP_MSG_CODE_REQUEST_PUT = 3,
terohoo 0:58c4f13c4b9a 50 COAP_MSG_CODE_REQUEST_DELETE = 4,
terohoo 0:58c4f13c4b9a 51
terohoo 0:58c4f13c4b9a 52 COAP_MSG_CODE_RESPONSE_CREATED = 65,
terohoo 0:58c4f13c4b9a 53 COAP_MSG_CODE_RESPONSE_DELETED = 66,
terohoo 0:58c4f13c4b9a 54 COAP_MSG_CODE_RESPONSE_VALID = 67,
terohoo 0:58c4f13c4b9a 55 COAP_MSG_CODE_RESPONSE_CHANGED = 68,
terohoo 0:58c4f13c4b9a 56 COAP_MSG_CODE_RESPONSE_CONTENT = 69,
terohoo 0:58c4f13c4b9a 57 COAP_MSG_CODE_RESPONSE_BAD_REQUEST = 128,
terohoo 0:58c4f13c4b9a 58 COAP_MSG_CODE_RESPONSE_UNAUTHORIZED = 129,
terohoo 0:58c4f13c4b9a 59 COAP_MSG_CODE_RESPONSE_BAD_OPTION = 130,
terohoo 0:58c4f13c4b9a 60 COAP_MSG_CODE_RESPONSE_FORBIDDEN = 131,
terohoo 0:58c4f13c4b9a 61 COAP_MSG_CODE_RESPONSE_NOT_FOUND = 132,
terohoo 0:58c4f13c4b9a 62 COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED = 133,
terohoo 0:58c4f13c4b9a 63 COAP_MSG_CODE_RESPONSE_NOT_ACCEPTABLE = 134,
terohoo 0:58c4f13c4b9a 64 COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_INCOMPLETE = 136, /* Block */
terohoo 0:58c4f13c4b9a 65 COAP_MSG_CODE_RESPONSE_PRECONDITION_FAILED = 140,
terohoo 0:58c4f13c4b9a 66 COAP_MSG_CODE_RESPONSE_REQUEST_ENTITY_TOO_LARGE = 141,
terohoo 0:58c4f13c4b9a 67 COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT = 143,
terohoo 0:58c4f13c4b9a 68 COAP_MSG_CODE_RESPONSE_INTERNAL_SERVER_ERROR = 160,
terohoo 0:58c4f13c4b9a 69 COAP_MSG_CODE_RESPONSE_NOT_IMPLEMENTED = 161,
terohoo 0:58c4f13c4b9a 70 COAP_MSG_CODE_RESPONSE_BAD_GATEWAY = 162,
terohoo 0:58c4f13c4b9a 71 COAP_MSG_CODE_RESPONSE_SERVICE_UNAVAILABLE = 163,
terohoo 0:58c4f13c4b9a 72 COAP_MSG_CODE_RESPONSE_GATEWAY_TIMEOUT = 164,
terohoo 0:58c4f13c4b9a 73 COAP_MSG_CODE_RESPONSE_PROXYING_NOT_SUPPORTED = 165
terohoo 0:58c4f13c4b9a 74 } sn_coap_msg_code_e;
terohoo 0:58c4f13c4b9a 75
terohoo 0:58c4f13c4b9a 76 /* Enumeration for CoAP Option number, used in CoAP Header */
terohoo 0:58c4f13c4b9a 77 typedef enum sn_coap_option_numbers_
terohoo 0:58c4f13c4b9a 78 {
terohoo 0:58c4f13c4b9a 79 COAP_OPTION_IF_MATCH = 1,
terohoo 0:58c4f13c4b9a 80 COAP_OPTION_URI_HOST = 3,
terohoo 0:58c4f13c4b9a 81 COAP_OPTION_ETAG = 4,
terohoo 0:58c4f13c4b9a 82 COAP_OPTION_IF_NONE_MATCH = 5,
terohoo 0:58c4f13c4b9a 83 COAP_OPTION_OBSERVE = 6,
terohoo 0:58c4f13c4b9a 84 COAP_OPTION_URI_PORT = 7,
terohoo 0:58c4f13c4b9a 85 COAP_OPTION_LOCATION_PATH = 8,
terohoo 0:58c4f13c4b9a 86 COAP_OPTION_URI_PATH = 11,
terohoo 0:58c4f13c4b9a 87 COAP_OPTION_CONTENT_FORMAT = 12,
terohoo 0:58c4f13c4b9a 88 COAP_OPTION_MAX_AGE = 14,
terohoo 0:58c4f13c4b9a 89 COAP_OPTION_URI_QUERY = 15,
terohoo 0:58c4f13c4b9a 90 COAP_OPTION_ACCEPT = 17,
terohoo 0:58c4f13c4b9a 91 COAP_OPTION_LOCATION_QUERY = 20,
terohoo 0:58c4f13c4b9a 92 COAP_OPTION_BLOCK2 = 23,
terohoo 0:58c4f13c4b9a 93 COAP_OPTION_BLOCK1 = 27,
terohoo 0:58c4f13c4b9a 94 COAP_OPTION_PROXY_URI = 35,
terohoo 0:58c4f13c4b9a 95 COAP_OPTION_PROXY_SCHEME = 39,
terohoo 0:58c4f13c4b9a 96 COAP_OPTION_SIZE1 = 60
terohoo 0:58c4f13c4b9a 97 // 128 = (Reserved)
terohoo 0:58c4f13c4b9a 98 // 132 = (Reserved)
terohoo 0:58c4f13c4b9a 99 // 136 = (Reserved)
terohoo 0:58c4f13c4b9a 100 } sn_coap_option_numbers_e;
terohoo 0:58c4f13c4b9a 101
terohoo 0:58c4f13c4b9a 102 /* Enumeration for CoAP Content Format codes */
terohoo 0:58c4f13c4b9a 103 typedef enum sn_coap_content_format_
terohoo 0:58c4f13c4b9a 104 {
terohoo 0:58c4f13c4b9a 105 COAP_CT_NONE = -1,
terohoo 0:58c4f13c4b9a 106 COAP_CT_TEXT_PLAIN = 0,
terohoo 0:58c4f13c4b9a 107 COAP_CT_LINK_FORMAT = 40,
terohoo 0:58c4f13c4b9a 108 COAP_CT_XML = 41,
terohoo 0:58c4f13c4b9a 109 COAP_CT_OCTET_STREAM = 42,
terohoo 0:58c4f13c4b9a 110 COAP_CT_EXI = 47,
terohoo 0:58c4f13c4b9a 111 COAP_CT_JSON = 50,
terohoo 0:58c4f13c4b9a 112 } sn_coap_content_format_e;
terohoo 0:58c4f13c4b9a 113
terohoo 0:58c4f13c4b9a 114 /* Enumeration for CoAP status, used in CoAP Header */
terohoo 0:58c4f13c4b9a 115 typedef enum sn_coap_status_
terohoo 0:58c4f13c4b9a 116 {
terohoo 0:58c4f13c4b9a 117 COAP_STATUS_OK = 0, /* Default value is OK */
terohoo 0:58c4f13c4b9a 118 COAP_STATUS_PARSER_ERROR_IN_HEADER = 1, /* CoAP will send Reset message to invalid message sender */
terohoo 0:58c4f13c4b9a 119 COAP_STATUS_PARSER_DUPLICATED_MSG = 2, /* CoAP will send Acknowledgement message to duplicated message sender */
terohoo 0:58c4f13c4b9a 120 COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVING = 3, /* User will get whole message after all message blocks received.
terohoo 0:58c4f13c4b9a 121 User must release messages with this status. */
terohoo 0:58c4f13c4b9a 122 COAP_STATUS_PARSER_BLOCKWISE_ACK = 4, /* Acknowledgement for sent Blockwise message received */
terohoo 0:58c4f13c4b9a 123 COAP_STATUS_PARSER_BLOCKWISE_MSG_REJECTED = 5, /* Blockwise message received but not supported by compiling switch */
terohoo 0:58c4f13c4b9a 124 COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED = 6 /* Blockwise message fully received and returned to app. */
terohoo 0:58c4f13c4b9a 125 /* User must take care of releasing whole payload of the blockwise messages */
terohoo 0:58c4f13c4b9a 126 } sn_coap_status_e;
terohoo 0:58c4f13c4b9a 127
terohoo 0:58c4f13c4b9a 128
terohoo 0:58c4f13c4b9a 129 /* * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 130 /* * * * STRUCTURES * * * */
terohoo 0:58c4f13c4b9a 131 /* * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 132
terohoo 0:58c4f13c4b9a 133 /* Structure for CoAP Options */
terohoo 0:58c4f13c4b9a 134 typedef struct sn_coap_options_list_
terohoo 0:58c4f13c4b9a 135 {
terohoo 0:58c4f13c4b9a 136
terohoo 0:58c4f13c4b9a 137 /* If-Match */
terohoo 0:58c4f13c4b9a 138 /* If-None-Match */
terohoo 0:58c4f13c4b9a 139 /* Size */
terohoo 0:58c4f13c4b9a 140 /* Proxy-Scheme */
terohoo 0:58c4f13c4b9a 141
terohoo 0:58c4f13c4b9a 142 uint8_t max_age_len; /* 0-4 bytes. */
terohoo 0:58c4f13c4b9a 143 uint8_t *max_age_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 144
terohoo 0:58c4f13c4b9a 145 uint16_t proxy_uri_len; /* 1-1034 bytes. */
terohoo 0:58c4f13c4b9a 146 uint8_t *proxy_uri_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 147
terohoo 0:58c4f13c4b9a 148 uint8_t etag_len; /* 1-8 bytes. Repeatable */
terohoo 0:58c4f13c4b9a 149 uint8_t *etag_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 150
terohoo 0:58c4f13c4b9a 151 uint16_t uri_host_len; /* 1-255 bytes. */
terohoo 0:58c4f13c4b9a 152 uint8_t *uri_host_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 153
terohoo 0:58c4f13c4b9a 154 uint16_t location_path_len; /* 0-255 bytes. Repeatable */
terohoo 0:58c4f13c4b9a 155 uint8_t *location_path_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 156
terohoo 0:58c4f13c4b9a 157 uint8_t uri_port_len; /* 0-2 bytes. */
terohoo 0:58c4f13c4b9a 158 uint8_t *uri_port_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 159
terohoo 0:58c4f13c4b9a 160 uint16_t location_query_len; /* 0-255 bytes. Repeatable */
terohoo 0:58c4f13c4b9a 161 uint8_t *location_query_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 162
terohoo 0:58c4f13c4b9a 163 uint8_t observe;
terohoo 0:58c4f13c4b9a 164 uint8_t observe_len; /* 0-2 bytes. */
terohoo 0:58c4f13c4b9a 165 uint8_t *observe_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 166
terohoo 0:58c4f13c4b9a 167 uint8_t accept_len; /* 0-2 bytes. Repeatable */
terohoo 0:58c4f13c4b9a 168 uint8_t *accept_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 169
terohoo 0:58c4f13c4b9a 170 uint16_t uri_query_len; /* 1-255 bytes. Repeatable */
terohoo 0:58c4f13c4b9a 171 uint8_t *uri_query_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 172
terohoo 0:58c4f13c4b9a 173 uint8_t block1_len; /* 0-3 bytes. */
terohoo 0:58c4f13c4b9a 174 uint8_t *block1_ptr; /* Not for User */
terohoo 0:58c4f13c4b9a 175
terohoo 0:58c4f13c4b9a 176 uint8_t block2_len; /* 0-3 bytes. */
terohoo 0:58c4f13c4b9a 177 uint8_t *block2_ptr; /* Not for User */
terohoo 0:58c4f13c4b9a 178 } sn_coap_options_list_s;
terohoo 0:58c4f13c4b9a 179
terohoo 0:58c4f13c4b9a 180 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
terohoo 0:58c4f13c4b9a 181 /* !!! Main CoAP message struct !!! */
terohoo 0:58c4f13c4b9a 182 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
terohoo 0:58c4f13c4b9a 183 typedef struct sn_coap_hdr_
terohoo 0:58c4f13c4b9a 184 {
terohoo 0:58c4f13c4b9a 185 sn_coap_status_e coap_status; /* Used for telling to User special cases when parsing message */
terohoo 0:58c4f13c4b9a 186
terohoo 0:58c4f13c4b9a 187 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 188 /* * * * Header * * * */
terohoo 0:58c4f13c4b9a 189 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 190
terohoo 0:58c4f13c4b9a 191 sn_coap_msg_type_e msg_type; /* Confirmable, Non-Confirmable, Acknowledgement or Reset */
terohoo 0:58c4f13c4b9a 192 sn_coap_msg_code_e msg_code; /* Empty: 0; Requests: 1-31; Responses: 64-191 */
terohoo 0:58c4f13c4b9a 193 uint16_t msg_id; /* Message ID. Parser sets parsed message ID, builder sets message ID of built coap message */
terohoo 0:58c4f13c4b9a 194
terohoo 0:58c4f13c4b9a 195 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 196 /* * * * Options * * * */
terohoo 0:58c4f13c4b9a 197 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 198
terohoo 0:58c4f13c4b9a 199 /* Here are most often used Options */
terohoo 0:58c4f13c4b9a 200
terohoo 0:58c4f13c4b9a 201 uint16_t uri_path_len; /* 0-255 bytes. Repeatable. */
terohoo 0:58c4f13c4b9a 202 uint8_t *uri_path_ptr; /* Must be set to NULL if not used. E.g: temp1/temp2 */
terohoo 0:58c4f13c4b9a 203
terohoo 0:58c4f13c4b9a 204 uint8_t token_len; /* 1-8 bytes. */
terohoo 0:58c4f13c4b9a 205 uint8_t *token_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 206
terohoo 0:58c4f13c4b9a 207 /* todo: COAP12 - content type ptr as a content_type_e */
terohoo 0:58c4f13c4b9a 208 uint8_t content_type_len; /* 0-2 bytes. */
terohoo 0:58c4f13c4b9a 209 uint8_t *content_type_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 210
terohoo 0:58c4f13c4b9a 211 /* Here are not so often used Options */
terohoo 0:58c4f13c4b9a 212 sn_coap_options_list_s *options_list_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 213
terohoo 0:58c4f13c4b9a 214 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 215 /* * * * Payload * * * */
terohoo 0:58c4f13c4b9a 216 /* * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 217
terohoo 0:58c4f13c4b9a 218 uint16_t payload_len; /* Must be set to zero if not used */
terohoo 0:58c4f13c4b9a 219 uint8_t *payload_ptr; /* Must be set to NULL if not used */
terohoo 0:58c4f13c4b9a 220 } sn_coap_hdr_s;
terohoo 0:58c4f13c4b9a 221
terohoo 0:58c4f13c4b9a 222 /* * * * * * * * * * * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 223 /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */
terohoo 0:58c4f13c4b9a 224 /* * * * * * * * * * * * * * * * * * * * * * */
terohoo 0:58c4f13c4b9a 225
terohoo 0:58c4f13c4b9a 226 extern void sn_coap_builder_and_parser_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*));
terohoo 0:58c4f13c4b9a 227 extern sn_coap_hdr_s *sn_coap_parser(uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr);
terohoo 0:58c4f13c4b9a 228 extern int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr);
terohoo 0:58c4f13c4b9a 229 extern uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr);
terohoo 0:58c4f13c4b9a 230 extern void sn_coap_builder_release_allocated_send_msg_mem(sn_nsdl_transmit_s *freed_send_msg_ptr);
terohoo 0:58c4f13c4b9a 231 extern sn_coap_hdr_s *sn_coap_build_response(sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code);
terohoo 0:58c4f13c4b9a 232 extern void sn_coap_parser_release_allocated_coap_msg_mem(sn_coap_hdr_s *freed_coap_msg_ptr);
terohoo 0:58c4f13c4b9a 233 extern void sn_coap_packet_debug(sn_coap_hdr_s *coap_packet_ptr);
terohoo 0:58c4f13c4b9a 234
terohoo 0:58c4f13c4b9a 235 #endif /* SN_COAP_HEADER_H_ */
terohoo 0:58c4f13c4b9a 236
terohoo 0:58c4f13c4b9a 237 #ifdef __cplusplus
terohoo 0:58c4f13c4b9a 238 }
terohoo 0:58c4f13c4b9a 239 #endif