Toyomasa Watarai / simple-mbed-cloud-client

Dependents:  

Committer:
MACRUM
Date:
Mon Jul 02 06:30:39 2018 +0000
Revision:
0:276e7a263c35
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:276e7a263c35 1 /*
MACRUM 0:276e7a263c35 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
MACRUM 0:276e7a263c35 3 * SPDX-License-Identifier: Apache-2.0
MACRUM 0:276e7a263c35 4 * Licensed under the Apache License, Version 2.0 (the License); you may
MACRUM 0:276e7a263c35 5 * not use this file except in compliance with the License.
MACRUM 0:276e7a263c35 6 * You may obtain a copy of the License at
MACRUM 0:276e7a263c35 7 *
MACRUM 0:276e7a263c35 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:276e7a263c35 9 *
MACRUM 0:276e7a263c35 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:276e7a263c35 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
MACRUM 0:276e7a263c35 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:276e7a263c35 13 * See the License for the specific language governing permissions and
MACRUM 0:276e7a263c35 14 * limitations under the License.
MACRUM 0:276e7a263c35 15 */
MACRUM 0:276e7a263c35 16
MACRUM 0:276e7a263c35 17 /**
MACRUM 0:276e7a263c35 18 * \file sn_coap_protocol_internal.h
MACRUM 0:276e7a263c35 19 *
MACRUM 0:276e7a263c35 20 * \brief Header file for CoAP Protocol part
MACRUM 0:276e7a263c35 21 *
MACRUM 0:276e7a263c35 22 */
MACRUM 0:276e7a263c35 23
MACRUM 0:276e7a263c35 24 #ifndef SN_COAP_PROTOCOL_INTERNAL_H_
MACRUM 0:276e7a263c35 25 #define SN_COAP_PROTOCOL_INTERNAL_H_
MACRUM 0:276e7a263c35 26
MACRUM 0:276e7a263c35 27 #include "ns_list.h"
MACRUM 0:276e7a263c35 28 #include "sn_coap_header_internal.h"
MACRUM 0:276e7a263c35 29 #include "mbed-coap/sn_config.h"
MACRUM 0:276e7a263c35 30
MACRUM 0:276e7a263c35 31 #ifdef __cplusplus
MACRUM 0:276e7a263c35 32 extern "C" {
MACRUM 0:276e7a263c35 33 #endif
MACRUM 0:276e7a263c35 34
MACRUM 0:276e7a263c35 35 struct sn_coap_hdr_;
MACRUM 0:276e7a263c35 36
MACRUM 0:276e7a263c35 37 /* * * * * * * * * * * */
MACRUM 0:276e7a263c35 38 /* * * * DEFINES * * * */
MACRUM 0:276e7a263c35 39 /* * * * * * * * * * * */
MACRUM 0:276e7a263c35 40
MACRUM 0:276e7a263c35 41 /* * For Message resending * */
MACRUM 0:276e7a263c35 42 #define ENABLE_RESENDINGS 1 /**< Enable / Disable resending from library in building */
MACRUM 0:276e7a263c35 43
MACRUM 0:276e7a263c35 44 #define SN_COAP_RESENDING_MAX_COUNT 3 /**< Default number of re-sendings */
MACRUM 0:276e7a263c35 45
MACRUM 0:276e7a263c35 46 #ifdef YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_MSGS
MACRUM 0:276e7a263c35 47 #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_MSGS
MACRUM 0:276e7a263c35 48 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_MSGS
MACRUM 0:276e7a263c35 49 #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_MSGS
MACRUM 0:276e7a263c35 50 #endif
MACRUM 0:276e7a263c35 51
MACRUM 0:276e7a263c35 52 #ifndef SN_COAP_RESENDING_QUEUE_SIZE_MSGS
MACRUM 0:276e7a263c35 53 #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS 2 /**< Default re-sending queue size - defines how many messages can be stored. Setting this to 0 disables feature */
MACRUM 0:276e7a263c35 54 #endif
MACRUM 0:276e7a263c35 55
MACRUM 0:276e7a263c35 56 #ifdef YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_BYTES
MACRUM 0:276e7a263c35 57 #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_BYTES
MACRUM 0:276e7a263c35 58 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_BYTES
MACRUM 0:276e7a263c35 59 #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_BYTES
MACRUM 0:276e7a263c35 60 #endif
MACRUM 0:276e7a263c35 61
MACRUM 0:276e7a263c35 62 #ifndef SN_COAP_RESENDING_QUEUE_SIZE_BYTES
MACRUM 0:276e7a263c35 63 #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES 0 /**< Default re-sending queue size - defines size of the re-sending buffer. Setting this to 0 disables feature */
MACRUM 0:276e7a263c35 64 #endif
MACRUM 0:276e7a263c35 65
MACRUM 0:276e7a263c35 66 #define DEFAULT_RESPONSE_TIMEOUT 10 /**< Default re-sending timeout as seconds */
MACRUM 0:276e7a263c35 67
MACRUM 0:276e7a263c35 68 /* These parameters sets maximum values application can set with API */
MACRUM 0:276e7a263c35 69 #define SN_COAP_MAX_ALLOWED_RESENDING_COUNT 6 /**< Maximum allowed count of re-sending */
MACRUM 0:276e7a263c35 70 #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_MSGS 6 /**< Maximum allowed number of saved re-sending messages */
MACRUM 0:276e7a263c35 71 #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_BYTES 512 /**< Maximum allowed size of re-sending buffer */
MACRUM 0:276e7a263c35 72 #define SN_COAP_MAX_ALLOWED_RESPONSE_TIMEOUT 40 /**< Maximum allowed re-sending timeout */
MACRUM 0:276e7a263c35 73
MACRUM 0:276e7a263c35 74 #define RESPONSE_RANDOM_FACTOR 1.5 /**< Resending random factor, value is specified in IETF CoAP specification */
MACRUM 0:276e7a263c35 75
MACRUM 0:276e7a263c35 76 /* * For Message duplication detecting * */
MACRUM 0:276e7a263c35 77
MACRUM 0:276e7a263c35 78 /* Init value for the maximum count of messages to be stored for duplication detection */
MACRUM 0:276e7a263c35 79 /* Setting of this value to 0 will disable duplication check, also reduce use of ROM memory */
MACRUM 0:276e7a263c35 80
MACRUM 0:276e7a263c35 81 // Keep the old flag to maintain backward compatibility
MACRUM 0:276e7a263c35 82 #ifndef SN_COAP_DUPLICATION_MAX_MSGS_COUNT
MACRUM 0:276e7a263c35 83 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT 0
MACRUM 0:276e7a263c35 84 #endif
MACRUM 0:276e7a263c35 85
MACRUM 0:276e7a263c35 86 #ifdef YOTTA_CFG_COAP_DUPLICATION_MAX_MSGS_COUNT
MACRUM 0:276e7a263c35 87 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT YOTTA_CFG_COAP_DUPLICATION_MAX_MSGS_COUNT
MACRUM 0:276e7a263c35 88 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_MSGS_COUNT
MACRUM 0:276e7a263c35 89 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_MSGS_COUNT
MACRUM 0:276e7a263c35 90 #endif
MACRUM 0:276e7a263c35 91
MACRUM 0:276e7a263c35 92
MACRUM 0:276e7a263c35 93
MACRUM 0:276e7a263c35 94 /* Maximum allowed number of saved messages for duplicate searching */
MACRUM 0:276e7a263c35 95 #define SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT 6
MACRUM 0:276e7a263c35 96
MACRUM 0:276e7a263c35 97 /* Maximum time in seconds of messages to be stored for duplication detection */
MACRUM 0:276e7a263c35 98 #define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 60 /* RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time */
MACRUM 0:276e7a263c35 99
MACRUM 0:276e7a263c35 100 /* * For Message blockwising * */
MACRUM 0:276e7a263c35 101
MACRUM 0:276e7a263c35 102 /* Init value for the maximum payload size to be sent and received at one blockwise message */
MACRUM 0:276e7a263c35 103 /* Setting of this value to 0 will disable this feature, and also reduce use of ROM memory */
MACRUM 0:276e7a263c35 104 /* Note: This define is common for both received and sent Blockwise messages */
MACRUM 0:276e7a263c35 105
MACRUM 0:276e7a263c35 106 #ifdef YOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
MACRUM 0:276e7a263c35 107 #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE YOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
MACRUM 0:276e7a263c35 108 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
MACRUM 0:276e7a263c35 109 #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE MBED_CONF_MBED_CLIENT_SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
MACRUM 0:276e7a263c35 110 #endif
MACRUM 0:276e7a263c35 111
MACRUM 0:276e7a263c35 112 #ifndef SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE
MACRUM 0:276e7a263c35 113 #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 0 /**< Must be 2^x and x is at least 4. Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024 */
MACRUM 0:276e7a263c35 114 #endif
MACRUM 0:276e7a263c35 115
MACRUM 0:276e7a263c35 116 #ifdef MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED
MACRUM 0:276e7a263c35 117 #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED
MACRUM 0:276e7a263c35 118 #endif
MACRUM 0:276e7a263c35 119
MACRUM 0:276e7a263c35 120 #ifndef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED
MACRUM 0:276e7a263c35 121 #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 60 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */
MACRUM 0:276e7a263c35 122 #endif
MACRUM 0:276e7a263c35 123
MACRUM 0:276e7a263c35 124 #ifdef YOTTA_CFG_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE
MACRUM 0:276e7a263c35 125 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE YOTTA_CFG_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE
MACRUM 0:276e7a263c35 126 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_MAX_INCOMING_MESSAGE_SIZE
MACRUM 0:276e7a263c35 127 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE MBED_CONF_MBED_CLIENT_SN_COAP_MAX_INCOMING_MESSAGE_SIZE
MACRUM 0:276e7a263c35 128 #endif
MACRUM 0:276e7a263c35 129
MACRUM 0:276e7a263c35 130 #ifndef SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE
MACRUM 0:276e7a263c35 131 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE UINT16_MAX
MACRUM 0:276e7a263c35 132 #endif
MACRUM 0:276e7a263c35 133
MACRUM 0:276e7a263c35 134 /* * For Option handling * */
MACRUM 0:276e7a263c35 135 #define COAP_OPTION_MAX_AGE_DEFAULT 60 /**< Default value of Max-Age if option not present */
MACRUM 0:276e7a263c35 136 #define COAP_OPTION_URI_PORT_NONE (-1) /**< Internal value to represent no Uri-Port option */
MACRUM 0:276e7a263c35 137 #define COAP_OPTION_BLOCK_NONE (-1) /**< Internal value to represent no Block1/2 option */
MACRUM 0:276e7a263c35 138
MACRUM 0:276e7a263c35 139
MACRUM 0:276e7a263c35 140 #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */
MACRUM 0:276e7a263c35 141 int8_t prepare_blockwise_message(struct coap_s *handle, struct sn_coap_hdr_ *coap_hdr_ptr);
MACRUM 0:276e7a263c35 142 #endif
MACRUM 0:276e7a263c35 143
MACRUM 0:276e7a263c35 144 /* Structure which is stored to Linked list for message sending purposes */
MACRUM 0:276e7a263c35 145 typedef struct coap_send_msg_ {
MACRUM 0:276e7a263c35 146 uint8_t resending_counter; /* Tells how many times message is still tried to resend */
MACRUM 0:276e7a263c35 147 uint32_t resending_time; /* Tells next resending time */
MACRUM 0:276e7a263c35 148
MACRUM 0:276e7a263c35 149 sn_nsdl_transmit_s *send_msg_ptr;
MACRUM 0:276e7a263c35 150
MACRUM 0:276e7a263c35 151 struct coap_s *coap; /* CoAP library handle */
MACRUM 0:276e7a263c35 152 void *param; /* Extra parameter that will be passed to TX/RX callback functions */
MACRUM 0:276e7a263c35 153
MACRUM 0:276e7a263c35 154 ns_list_link_t link;
MACRUM 0:276e7a263c35 155 } coap_send_msg_s;
MACRUM 0:276e7a263c35 156
MACRUM 0:276e7a263c35 157 typedef NS_LIST_HEAD(coap_send_msg_s, link) coap_send_msg_list_t;
MACRUM 0:276e7a263c35 158
MACRUM 0:276e7a263c35 159 /* Structure which is stored to Linked list for message duplication detection purposes */
MACRUM 0:276e7a263c35 160 typedef struct coap_duplication_info_ {
MACRUM 0:276e7a263c35 161 uint32_t timestamp; /* Tells when duplication information is stored to Linked list */
MACRUM 0:276e7a263c35 162 uint16_t msg_id;
MACRUM 0:276e7a263c35 163 uint16_t packet_len;
MACRUM 0:276e7a263c35 164 uint8_t *packet_ptr;
MACRUM 0:276e7a263c35 165 struct coap_s *coap; /* CoAP library handle */
MACRUM 0:276e7a263c35 166 sn_nsdl_addr_s *address;
MACRUM 0:276e7a263c35 167 void *param;
MACRUM 0:276e7a263c35 168 ns_list_link_t link;
MACRUM 0:276e7a263c35 169 } coap_duplication_info_s;
MACRUM 0:276e7a263c35 170
MACRUM 0:276e7a263c35 171 typedef NS_LIST_HEAD(coap_duplication_info_s, link) coap_duplication_info_list_t;
MACRUM 0:276e7a263c35 172
MACRUM 0:276e7a263c35 173 /* Structure which is stored to Linked list for blockwise messages sending purposes */
MACRUM 0:276e7a263c35 174 typedef struct coap_blockwise_msg_ {
MACRUM 0:276e7a263c35 175 uint32_t timestamp; /* Tells when Blockwise message is stored to Linked list */
MACRUM 0:276e7a263c35 176
MACRUM 0:276e7a263c35 177 sn_coap_hdr_s *coap_msg_ptr;
MACRUM 0:276e7a263c35 178 struct coap_s *coap; /* CoAP library handle */
MACRUM 0:276e7a263c35 179
MACRUM 0:276e7a263c35 180 ns_list_link_t link;
MACRUM 0:276e7a263c35 181 } coap_blockwise_msg_s;
MACRUM 0:276e7a263c35 182
MACRUM 0:276e7a263c35 183 typedef NS_LIST_HEAD(coap_blockwise_msg_s, link) coap_blockwise_msg_list_t;
MACRUM 0:276e7a263c35 184
MACRUM 0:276e7a263c35 185 /* Structure which is stored to Linked list for blockwise messages receiving purposes */
MACRUM 0:276e7a263c35 186 typedef struct coap_blockwise_payload_ {
MACRUM 0:276e7a263c35 187 uint32_t timestamp; /* Tells when Payload is stored to Linked list */
MACRUM 0:276e7a263c35 188
MACRUM 0:276e7a263c35 189 uint8_t addr_len;
MACRUM 0:276e7a263c35 190 uint8_t *addr_ptr;
MACRUM 0:276e7a263c35 191 uint16_t port;
MACRUM 0:276e7a263c35 192 uint32_t block_number;
MACRUM 0:276e7a263c35 193
MACRUM 0:276e7a263c35 194 uint16_t payload_len;
MACRUM 0:276e7a263c35 195 uint8_t *payload_ptr;
MACRUM 0:276e7a263c35 196 struct coap_s *coap; /* CoAP library handle */
MACRUM 0:276e7a263c35 197
MACRUM 0:276e7a263c35 198 ns_list_link_t link;
MACRUM 0:276e7a263c35 199 } coap_blockwise_payload_s;
MACRUM 0:276e7a263c35 200
MACRUM 0:276e7a263c35 201 typedef NS_LIST_HEAD(coap_blockwise_payload_s, link) coap_blockwise_payload_list_t;
MACRUM 0:276e7a263c35 202
MACRUM 0:276e7a263c35 203 struct coap_s {
MACRUM 0:276e7a263c35 204 void *(*sn_coap_protocol_malloc)(uint16_t);
MACRUM 0:276e7a263c35 205 void (*sn_coap_protocol_free)(void *);
MACRUM 0:276e7a263c35 206
MACRUM 0:276e7a263c35 207 uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *);
MACRUM 0:276e7a263c35 208 int8_t (*sn_coap_rx_callback)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *);
MACRUM 0:276e7a263c35 209
MACRUM 0:276e7a263c35 210 #if ENABLE_RESENDINGS /* If Message resending is not used at all, this part of code will not be compiled */
MACRUM 0:276e7a263c35 211 coap_send_msg_list_t linked_list_resent_msgs; /* Active resending messages are stored to this Linked list */
MACRUM 0:276e7a263c35 212 uint16_t count_resent_msgs;
MACRUM 0:276e7a263c35 213 #endif
MACRUM 0:276e7a263c35 214
MACRUM 0:276e7a263c35 215 #if SN_COAP_DUPLICATION_MAX_MSGS_COUNT /* If Message duplication detection is not used at all, this part of code will not be compiled */
MACRUM 0:276e7a263c35 216 coap_duplication_info_list_t linked_list_duplication_msgs; /* Messages for duplicated messages detection is stored to this Linked list */
MACRUM 0:276e7a263c35 217 uint16_t count_duplication_msgs;
MACRUM 0:276e7a263c35 218 #endif
MACRUM 0:276e7a263c35 219
MACRUM 0:276e7a263c35 220 #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwise is not used at all, this part of code will not be compiled */
MACRUM 0:276e7a263c35 221 coap_blockwise_msg_list_t linked_list_blockwise_sent_msgs; /* Blockwise message to to be sent is stored to this Linked list */
MACRUM 0:276e7a263c35 222 coap_blockwise_payload_list_t linked_list_blockwise_received_payloads; /* Blockwise payload to to be received is stored to this Linked list */
MACRUM 0:276e7a263c35 223 #endif
MACRUM 0:276e7a263c35 224
MACRUM 0:276e7a263c35 225 uint32_t system_time; /* System time seconds */
MACRUM 0:276e7a263c35 226 uint16_t sn_coap_block_data_size;
MACRUM 0:276e7a263c35 227 uint8_t sn_coap_resending_queue_msgs;
MACRUM 0:276e7a263c35 228 uint32_t sn_coap_resending_queue_bytes;
MACRUM 0:276e7a263c35 229 uint8_t sn_coap_resending_count;
MACRUM 0:276e7a263c35 230 uint8_t sn_coap_resending_intervall;
MACRUM 0:276e7a263c35 231 uint8_t sn_coap_duplication_buffer_size;
MACRUM 0:276e7a263c35 232 uint8_t sn_coap_internal_block2_resp_handling; /* If this is set then coap itself sends a next GET request automatically */
MACRUM 0:276e7a263c35 233 };
MACRUM 0:276e7a263c35 234
MACRUM 0:276e7a263c35 235 #ifdef __cplusplus
MACRUM 0:276e7a263c35 236 }
MACRUM 0:276e7a263c35 237 #endif
MACRUM 0:276e7a263c35 238
MACRUM 0:276e7a263c35 239 #endif /* SN_COAP_PROTOCOL_INTERNAL_H_ */
MACRUM 0:276e7a263c35 240