Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
sn_coap_protocol_internal.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 2011-2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /** 00018 * \file sn_coap_protocol_internal.h 00019 * 00020 * \brief Header file for CoAP Protocol part 00021 * 00022 */ 00023 00024 #ifndef SN_COAP_PROTOCOL_INTERNAL_H_ 00025 #define SN_COAP_PROTOCOL_INTERNAL_H_ 00026 00027 #include "ns_list.h" 00028 #include "sn_coap_header_internal.h" 00029 #include "mbed-coap/sn_config.h" 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 struct sn_coap_hdr_; 00036 00037 /* * * * * * * * * * * */ 00038 /* * * * DEFINES * * * */ 00039 /* * * * * * * * * * * */ 00040 00041 /* * For Message resending * */ 00042 #define ENABLE_RESENDINGS 1 /**< Enable / Disable resending from library in building */ 00043 00044 #define SN_COAP_RESENDING_MAX_COUNT 3 /**< Default number of re-sendings */ 00045 00046 #ifdef YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_MSGS 00047 #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_MSGS 00048 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_MSGS 00049 #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_MSGS 00050 #endif 00051 00052 #ifndef SN_COAP_RESENDING_QUEUE_SIZE_MSGS 00053 #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 */ 00054 #endif 00055 00056 #ifdef YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_BYTES 00057 #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES YOTTA_CFG_COAP_RESENDING_QUEUE_SIZE_BYTES 00058 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_BYTES 00059 #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES MBED_CONF_MBED_CLIENT_SN_COAP_RESENDING_QUEUE_SIZE_BYTES 00060 #endif 00061 00062 #ifndef SN_COAP_RESENDING_QUEUE_SIZE_BYTES 00063 #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 */ 00064 #endif 00065 00066 #define DEFAULT_RESPONSE_TIMEOUT 10 /**< Default re-sending timeout as seconds */ 00067 00068 /* These parameters sets maximum values application can set with API */ 00069 #define SN_COAP_MAX_ALLOWED_RESENDING_COUNT 6 /**< Maximum allowed count of re-sending */ 00070 #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_MSGS 6 /**< Maximum allowed number of saved re-sending messages */ 00071 #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_BYTES 512 /**< Maximum allowed size of re-sending buffer */ 00072 #define SN_COAP_MAX_ALLOWED_RESPONSE_TIMEOUT 40 /**< Maximum allowed re-sending timeout */ 00073 00074 #define RESPONSE_RANDOM_FACTOR 1.5 /**< Resending random factor, value is specified in IETF CoAP specification */ 00075 00076 /* * For Message duplication detecting * */ 00077 00078 /* Init value for the maximum count of messages to be stored for duplication detection */ 00079 /* Setting of this value to 0 will disable duplication check, also reduce use of ROM memory */ 00080 00081 // Keep the old flag to maintain backward compatibility 00082 #ifndef SN_COAP_DUPLICATION_MAX_MSGS_COUNT 00083 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT 0 00084 #endif 00085 00086 #ifdef YOTTA_CFG_COAP_DUPLICATION_MAX_MSGS_COUNT 00087 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT YOTTA_CFG_COAP_DUPLICATION_MAX_MSGS_COUNT 00088 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_MSGS_COUNT 00089 #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT MBED_CONF_MBED_CLIENT_SN_COAP_DUPLICATION_MAX_MSGS_COUNT 00090 #endif 00091 00092 00093 00094 /* Maximum allowed number of saved messages for duplicate searching */ 00095 #define SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT 6 00096 00097 /* Maximum time in seconds of messages to be stored for duplication detection */ 00098 #define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 60 /* RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time */ 00099 00100 /* * For Message blockwising * */ 00101 00102 /* Init value for the maximum payload size to be sent and received at one blockwise message */ 00103 /* Setting of this value to 0 will disable this feature, and also reduce use of ROM memory */ 00104 /* Note: This define is common for both received and sent Blockwise messages */ 00105 00106 #ifdef YOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 00107 #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE YOTTA_CFG_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 00108 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 00109 #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE MBED_CONF_MBED_CLIENT_SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 00110 #endif 00111 00112 #ifndef SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 00113 #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 */ 00114 #endif 00115 00116 #ifdef MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 00117 #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED MBED_CONF_MBED_CLIENT_SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 00118 #endif 00119 00120 #ifndef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 00121 #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 60 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */ 00122 #endif 00123 00124 #ifdef YOTTA_CFG_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE 00125 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE YOTTA_CFG_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE 00126 #elif defined MBED_CONF_MBED_CLIENT_SN_COAP_MAX_INCOMING_MESSAGE_SIZE 00127 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE MBED_CONF_MBED_CLIENT_SN_COAP_MAX_INCOMING_MESSAGE_SIZE 00128 #endif 00129 00130 #ifndef SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE 00131 #define SN_COAP_MAX_INCOMING_BLOCK_MESSAGE_SIZE UINT16_MAX 00132 #endif 00133 00134 /* * For Option handling * */ 00135 #define COAP_OPTION_MAX_AGE_DEFAULT 60 /**< Default value of Max-Age if option not present */ 00136 #define COAP_OPTION_URI_PORT_NONE (-1) /**< Internal value to represent no Uri-Port option */ 00137 #define COAP_OPTION_BLOCK_NONE (-1) /**< Internal value to represent no Block1/2 option */ 00138 00139 00140 #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwising is not used at all, this part of code will not be compiled */ 00141 int8_t prepare_blockwise_message(struct coap_s *handle, struct sn_coap_hdr_ *coap_hdr_ptr); 00142 #endif 00143 00144 /* Structure which is stored to Linked list for message sending purposes */ 00145 typedef struct coap_send_msg_ { 00146 uint8_t resending_counter; /* Tells how many times message is still tried to resend */ 00147 uint32_t resending_time; /* Tells next resending time */ 00148 00149 sn_nsdl_transmit_s *send_msg_ptr; 00150 00151 struct coap_s *coap; /* CoAP library handle */ 00152 void *param; /* Extra parameter that will be passed to TX/RX callback functions */ 00153 00154 ns_list_link_t link; 00155 } coap_send_msg_s; 00156 00157 typedef NS_LIST_HEAD(coap_send_msg_s, link) coap_send_msg_list_t; 00158 00159 /* Structure which is stored to Linked list for message duplication detection purposes */ 00160 typedef struct coap_duplication_info_ { 00161 uint32_t timestamp; /* Tells when duplication information is stored to Linked list */ 00162 uint16_t msg_id; 00163 uint16_t packet_len; 00164 uint8_t *packet_ptr; 00165 struct coap_s *coap; /* CoAP library handle */ 00166 sn_nsdl_addr_s *address; 00167 void *param; 00168 ns_list_link_t link; 00169 } coap_duplication_info_s; 00170 00171 typedef NS_LIST_HEAD(coap_duplication_info_s, link) coap_duplication_info_list_t; 00172 00173 /* Structure which is stored to Linked list for blockwise messages sending purposes */ 00174 typedef struct coap_blockwise_msg_ { 00175 uint32_t timestamp; /* Tells when Blockwise message is stored to Linked list */ 00176 00177 sn_coap_hdr_s *coap_msg_ptr; 00178 struct coap_s *coap; /* CoAP library handle */ 00179 00180 ns_list_link_t link; 00181 } coap_blockwise_msg_s; 00182 00183 typedef NS_LIST_HEAD(coap_blockwise_msg_s, link) coap_blockwise_msg_list_t; 00184 00185 /* Structure which is stored to Linked list for blockwise messages receiving purposes */ 00186 typedef struct coap_blockwise_payload_ { 00187 uint32_t timestamp; /* Tells when Payload is stored to Linked list */ 00188 00189 uint8_t addr_len; 00190 uint8_t *addr_ptr; 00191 uint16_t port; 00192 uint32_t block_number; 00193 00194 uint16_t payload_len; 00195 uint8_t *payload_ptr; 00196 struct coap_s *coap; /* CoAP library handle */ 00197 00198 ns_list_link_t link; 00199 } coap_blockwise_payload_s; 00200 00201 typedef NS_LIST_HEAD(coap_blockwise_payload_s, link) coap_blockwise_payload_list_t; 00202 00203 struct coap_s { 00204 void *(*sn_coap_protocol_malloc)(uint16_t); 00205 void (*sn_coap_protocol_free)(void *); 00206 00207 uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); 00208 int8_t (*sn_coap_rx_callback)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *); 00209 00210 #if ENABLE_RESENDINGS /* If Message resending is not used at all, this part of code will not be compiled */ 00211 coap_send_msg_list_t linked_list_resent_msgs; /* Active resending messages are stored to this Linked list */ 00212 uint16_t count_resent_msgs; 00213 #endif 00214 00215 #if SN_COAP_DUPLICATION_MAX_MSGS_COUNT /* If Message duplication detection is not used at all, this part of code will not be compiled */ 00216 coap_duplication_info_list_t linked_list_duplication_msgs; /* Messages for duplicated messages detection is stored to this Linked list */ 00217 uint16_t count_duplication_msgs; 00218 #endif 00219 00220 #if SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE /* If Message blockwise is not used at all, this part of code will not be compiled */ 00221 coap_blockwise_msg_list_t linked_list_blockwise_sent_msgs; /* Blockwise message to to be sent is stored to this Linked list */ 00222 coap_blockwise_payload_list_t linked_list_blockwise_received_payloads; /* Blockwise payload to to be received is stored to this Linked list */ 00223 #endif 00224 00225 uint32_t system_time; /* System time seconds */ 00226 uint16_t sn_coap_block_data_size; 00227 uint8_t sn_coap_resending_queue_msgs; 00228 uint32_t sn_coap_resending_queue_bytes; 00229 uint8_t sn_coap_resending_count; 00230 uint8_t sn_coap_resending_intervall; 00231 uint8_t sn_coap_duplication_buffer_size; 00232 }; 00233 00234 #ifdef __cplusplus 00235 } 00236 #endif 00237 00238 #endif /* SN_COAP_PROTOCOL_INTERNAL_H_ */ 00239
Generated on Sun Jul 17 2022 08:25:30 by 1.7.2