joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sn_coap_protocol.h Source File

sn_coap_protocol.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.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)
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\ŋ
00087  *         If there is not enough memory (or User given limit exceeded) for storing
00088  *         resending messages, situation is ignored.
00089  */
00090 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);
00091 
00092 /**
00093  * \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)
00094  *
00095  * \brief Parses received CoAP message from given Packet data
00096  *
00097  * \param *src_addr_ptr is pointer to source address of received CoAP message
00098  *        (CoAP parser needs that information for Message acknowledgement)
00099  *
00100  * \param *handle Pointer to CoAP library handle
00101  *
00102  * \param packet_data_len is length of given Packet data to be parsed to CoAP message
00103  *
00104  * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message
00105  *
00106  * \param param void pointer that will be passed to tx/rx function callback when those are called.
00107  *
00108  * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n
00109  *         In following failure cases NULL is returned:\n
00110  *          -Given NULL pointer\n
00111  *          -Failure in parsed header of non-confirmable message\ŋ
00112  *          -Out of memory (malloc() returns NULL)
00113  */
00114 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 *);
00115 
00116 /**
00117  * \fn int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)
00118  *
00119  * \brief Sends CoAP messages from re-sending queue, if there is any.
00120  *        Cleans also old messages from the duplication list and from block receiving list
00121  *
00122  *        This function can be called e.g. once in a second but also more frequently.
00123  *
00124  * \param *handle Pointer to CoAP library handle
00125  *
00126  * \param current_time is System time in seconds. This time is
00127  *        used for message re-sending timing and to identify old saved data.
00128  *
00129  * \return  0 if success
00130  *          -1 if failed
00131  */
00132 
00133 extern int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time);
00134 
00135 /**
00136  * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size)
00137  *
00138  * \brief If block transfer is enabled, this function changes the block size.
00139  *
00140  * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes
00141  * \return  0 = success
00142  *          -1 = failure
00143  */
00144 extern int8_t sn_coap_protocol_set_block_size(struct coap_s *handle, uint16_t block_size);
00145 
00146 /**
00147  * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count)
00148  *
00149  * \brief If dublicate message detection is enabled, this function changes buffer size.
00150  *
00151  * \param uint8_t message_count max number of messages saved for duplicate control
00152  * \return  0 = success
00153  *          -1 = failure
00154  */
00155 extern int8_t sn_coap_protocol_set_duplicate_buffer_size(struct coap_s *handle, uint8_t message_count);
00156 
00157 /**
00158  * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall)
00159  *
00160  * \brief  If re-transmissions are enabled, this function changes resending count and interval.
00161  *
00162  * \param uint8_t resending_count max number of resendings for message
00163  * \param uint8_t resending_intervall message resending intervall in seconds
00164  * \return  0 = success, -1 = failure
00165  */
00166 extern int8_t sn_coap_protocol_set_retransmission_parameters(struct coap_s *handle,
00167         uint8_t resending_count, uint8_t resending_interval);
00168 
00169 /**
00170  * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes)
00171  *
00172  * \brief If re-transmissions are enabled, this function changes message retransmission queue size.
00173  *  Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled.
00174  *
00175  * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue
00176  * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue
00177  * \return  0 = success, -1 = failure
00178  */
00179 extern int8_t sn_coap_protocol_set_retransmission_buffer(struct coap_s *handle,
00180         uint8_t buffer_size_messages, uint16_t buffer_size_bytes);
00181 
00182 /**
00183  * \fn void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle)
00184  *
00185  * \param *handle Pointer to CoAP library handle
00186  *
00187  * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue.
00188  */
00189 extern void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle);
00190 
00191 #endif /* SN_COAP_PROTOCOL_H_ */
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif