Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
sn_coap_protocol.h
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.h 00019 * 00020 * \brief CoAP C-library User protocol interface header file 00021 */ 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 #ifndef SN_COAP_PROTOCOL_H_ 00028 #define SN_COAP_PROTOCOL_H_ 00029 00030 #include "sn_coap_header.h" 00031 00032 /** 00033 * \fn struct coap_s *sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*), 00034 uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), 00035 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *) 00036 * 00037 * \brief Initializes CoAP Protocol part. When using libNsdl, sn_nsdl_init() calls this function. 00038 * 00039 * \param *used_malloc_func_ptr is function pointer for used memory allocation function. 00040 * 00041 * \param *used_free_func_ptr is function pointer for used memory free function. 00042 * 00043 * \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages 00044 * 00045 * \param *used_rx_callback_ptr used to return CoAP header struct with status COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED 00046 * when re-sendings exceeded. If set to NULL, no error message is returned. 00047 * 00048 * \return Pointer to handle when success 00049 * Null if failed 00050 */ 00051 00052 extern struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), 00053 uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *), 00054 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *)); 00055 00056 /** 00057 * \fn int8_t sn_coap_protocol_destroy(void) 00058 * 00059 * \brief Frees all memory from CoAP protocol part 00060 * 00061 * \param *handle Pointer to CoAP library handle 00062 * 00063 * \return Return value is always 0 00064 */ 00065 extern int8_t sn_coap_protocol_destroy(struct coap_s *handle); 00066 00067 /** 00068 * \fn int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param) 00069 * 00070 * \brief Builds Packet data from given CoAP header structure to be sent 00071 * 00072 * \param *dst_addr_ptr is pointer to destination address where CoAP message 00073 * will be sent (CoAP builder needs that information for message resending purposes) 00074 * 00075 * \param *dst_packet_data_ptr is pointer to destination of built Packet data 00076 * 00077 * \param *src_coap_msg_ptr is pointer to source of built Packet data 00078 * 00079 * \param param void pointer that will be passed to tx/rx function callback when those are called. 00080 * 00081 * \return Return value is byte count of built Packet data.\n 00082 * Note: If message is blockwised, all payload is not sent at the same time\n 00083 * In failure cases:\n 00084 * -1 = Failure in CoAP header structure\n 00085 * -2 = Failure in given pointer (= NULL)\n 00086 * -3 = Failure in Reset message\n 00087 * -4 = Failure in Resending message store\n 00088 * If there is not enough memory (or User given limit exceeded) for storing 00089 * resending messages, situation is ignored. 00090 */ 00091 extern int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param); 00092 00093 /** 00094 * \fn sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr) 00095 * 00096 * \brief Parses received CoAP message from given Packet data 00097 * 00098 * \param *src_addr_ptr is pointer to source address of received CoAP message 00099 * (CoAP parser needs that information for Message acknowledgement) 00100 * 00101 * \param *handle Pointer to CoAP library handle 00102 * 00103 * \param packet_data_len is length of given Packet data to be parsed to CoAP message 00104 * 00105 * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message 00106 * 00107 * \param param void pointer that will be passed to tx/rx function callback when those are called. 00108 * 00109 * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n 00110 * In following failure cases NULL is returned:\n 00111 * -Given NULL pointer\n 00112 * -Failure in parsed header of non-confirmable message\ŋ 00113 * -Out of memory (malloc() returns NULL) 00114 */ 00115 extern sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr, void *); 00116 00117 /** 00118 * \fn int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) 00119 * 00120 * \brief Sends CoAP messages from re-sending queue, if there is any. 00121 * Cleans also old messages from the duplication list and from block receiving list 00122 * 00123 * This function can be called e.g. once in a second but also more frequently. 00124 * 00125 * \param *handle Pointer to CoAP library handle 00126 * 00127 * \param current_time is System time in seconds. This time is 00128 * used for message re-sending timing and to identify old saved data. 00129 * 00130 * \return 0 if success 00131 * -1 if failed 00132 */ 00133 00134 extern int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time); 00135 00136 /** 00137 * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size) 00138 * 00139 * \brief If block transfer is enabled, this function changes the block size. 00140 * 00141 * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes 00142 * \return 0 = success 00143 * -1 = failure 00144 */ 00145 extern int8_t sn_coap_protocol_set_block_size(struct coap_s *handle, uint16_t block_size); 00146 00147 /** 00148 * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count) 00149 * 00150 * \brief If dublicate message detection is enabled, this function changes buffer size. 00151 * 00152 * \param uint8_t message_count max number of messages saved for duplicate control 00153 * \return 0 = success 00154 * -1 = failure 00155 */ 00156 extern int8_t sn_coap_protocol_set_duplicate_buffer_size(struct coap_s *handle, uint8_t message_count); 00157 00158 /** 00159 * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall) 00160 * 00161 * \brief If re-transmissions are enabled, this function changes resending count and interval. 00162 * 00163 * \param uint8_t resending_count max number of resendings for message 00164 * \param uint8_t resending_intervall message resending intervall in seconds 00165 * \return 0 = success, -1 = failure 00166 */ 00167 extern int8_t sn_coap_protocol_set_retransmission_parameters(struct coap_s *handle, 00168 uint8_t resending_count, uint8_t resending_interval); 00169 00170 /** 00171 * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes) 00172 * 00173 * \brief If re-transmissions are enabled, this function changes message retransmission queue size. 00174 * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled. 00175 * 00176 * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue 00177 * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue 00178 * \return 0 = success, -1 = failure 00179 */ 00180 extern int8_t sn_coap_protocol_set_retransmission_buffer(struct coap_s *handle, 00181 uint8_t buffer_size_messages, uint16_t buffer_size_bytes); 00182 00183 /** 00184 * \fn void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle) 00185 * 00186 * \param *handle Pointer to CoAP library handle 00187 * 00188 * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue. 00189 */ 00190 extern void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle); 00191 00192 /** 00193 * \fn sn_coap_protocol_block_remove 00194 * 00195 * \brief Remove saved block data. Can be used to remove the data from RAM to enable storing it to other place. 00196 * 00197 * \param handle Pointer to CoAP library handle 00198 * \param source_address Addres from where the block has been received. 00199 * \param payload_length Length of the coap payload of the block. 00200 * \param payload Coap payload of the block. 00201 * 00202 */ 00203 extern void sn_coap_protocol_block_remove(struct coap_s *handle, sn_nsdl_addr_s *source_address, uint16_t payload_length, void *payload); 00204 00205 /** 00206 * \fn sn_coap_protocol_remove_sent_blockwise_message 00207 * 00208 * \brief Remove sent blockwise message from the linked list. 00209 * 00210 * \param handle Pointer to CoAP library handle 00211 * \param message_id Message id to be removed. 00212 * 00213 */ 00214 extern void sn_coap_protocol_remove_sent_blockwise_message(struct coap_s *handle, uint16_t message_id); 00215 00216 /** 00217 * \fn void sn_coap_protocol_delete_retransmission(struct coap_s *handle) 00218 * 00219 * \param *handle Pointer to CoAP library handle 00220 * \msg_id message ID to be removed 00221 * \return returns 0 when success, -1 for invalid parameter, -2 if message was not found 00222 * 00223 * \brief If re-transmissions are enabled, this function removes message from retransmission buffer. 00224 */ 00225 extern int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint16_t msg_id); 00226 00227 /** 00228 * \fn int8_t sn_coap_convert_block_size(uint16_t block_size) 00229 * 00230 * \brief Utility function to convert block size. 00231 * 00232 * \param block_size Block size to convert. 00233 * 00234 * \return Value of range 0 - 6 00235 */ 00236 extern int8_t sn_coap_convert_block_size(uint16_t block_size); 00237 00238 /** 00239 * \fn int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response) 00240 * 00241 * \brief This function change the state whether CoAP library sends the block 2 response automatically or not. 00242 * 00243 * \param *handle Pointer to CoAP library handle 00244 * \param handle_response 1 if CoAP library handles the response sending otherwise 0. 00245 * 00246 * \return 0 = success, -1 = failure 00247 */ 00248 extern int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response); 00249 00250 /** 00251 * \fn void sn_coap_protocol_clear_sent_blockwise_messages(struct coap_s *handle) 00252 * 00253 * \brief This function clears all the sent blockwise messages from the linked list. 00254 * 00255 * \param *handle Pointer to CoAP library handle 00256 */ 00257 extern void sn_coap_protocol_clear_sent_blockwise_messages(struct coap_s *handle); 00258 00259 /** 00260 * \fn void sn_coap_protocol_send_rst(struct coap_s *handle, uint16_t msg_id, sn_nsdl_addr_s *addr_ptr, void *param) 00261 * 00262 * \brief This function sends a RESET message. 00263 * 00264 * \param *handle Pointer to CoAP library handle 00265 * \param msg_id Message id. 00266 * \param addr_ptr Pointer to destination address where CoAP message will be sent 00267 * \param param Pointer that will be passed to tx function callback 00268 */ 00269 extern void sn_coap_protocol_send_rst(struct coap_s *handle, uint16_t msg_id, sn_nsdl_addr_s *addr_ptr, void *param); 00270 00271 /** 00272 * \fn uint16_t sn_coap_protocol_get_configured_blockwise_size(struct coap_s *handle) 00273 * 00274 * \brief Get configured CoAP payload blockwise size 00275 * 00276 * \param *handle Pointer to CoAP library handle 00277 */ 00278 extern uint16_t sn_coap_protocol_get_configured_blockwise_size(struct coap_s *handle); 00279 00280 #endif /* SN_COAP_PROTOCOL_H_ */ 00281 00282 #ifdef __cplusplus 00283 } 00284 #endif
Generated on Tue Jul 12 2022 19:12:15 by 1.7.2