Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:119624335925 1 /*
MACRUM 0:119624335925 2 * Copyright (c) 2011-2015 ARM Limited. All rights reserved.
MACRUM 0:119624335925 3 * SPDX-License-Identifier: Apache-2.0
MACRUM 0:119624335925 4 * Licensed under the Apache License, Version 2.0 (the License); you may
MACRUM 0:119624335925 5 * not use this file except in compliance with the License.
MACRUM 0:119624335925 6 * You may obtain a copy of the License at
MACRUM 0:119624335925 7 *
MACRUM 0:119624335925 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:119624335925 9 *
MACRUM 0:119624335925 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:119624335925 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
MACRUM 0:119624335925 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:119624335925 13 * See the License for the specific language governing permissions and
MACRUM 0:119624335925 14 * limitations under the License.
MACRUM 0:119624335925 15 */
MACRUM 0:119624335925 16
MACRUM 0:119624335925 17 /**
MACRUM 0:119624335925 18 * \file sn_coap_protocol.h
MACRUM 0:119624335925 19 *
MACRUM 0:119624335925 20 * \brief CoAP C-library User protocol interface header file
MACRUM 0:119624335925 21 */
MACRUM 0:119624335925 22
MACRUM 0:119624335925 23 #ifdef __cplusplus
MACRUM 0:119624335925 24 extern "C" {
MACRUM 0:119624335925 25 #endif
MACRUM 0:119624335925 26
MACRUM 0:119624335925 27 #ifndef SN_COAP_PROTOCOL_H_
MACRUM 0:119624335925 28 #define SN_COAP_PROTOCOL_H_
MACRUM 0:119624335925 29
MACRUM 0:119624335925 30 #include "sn_coap_header.h"
MACRUM 0:119624335925 31
MACRUM 0:119624335925 32 /**
MACRUM 0:119624335925 33 * \fn struct coap_s *sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*),
MACRUM 0:119624335925 34 uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
MACRUM 0:119624335925 35 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *)
MACRUM 0:119624335925 36 *
MACRUM 0:119624335925 37 * \brief Initializes CoAP Protocol part. When using libNsdl, sn_nsdl_init() calls this function.
MACRUM 0:119624335925 38 *
MACRUM 0:119624335925 39 * \param *used_malloc_func_ptr is function pointer for used memory allocation function.
MACRUM 0:119624335925 40 *
MACRUM 0:119624335925 41 * \param *used_free_func_ptr is function pointer for used memory free function.
MACRUM 0:119624335925 42 *
MACRUM 0:119624335925 43 * \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages
MACRUM 0:119624335925 44 *
MACRUM 0:119624335925 45 * \param *used_rx_callback_ptr used to return CoAP header struct with status COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED
MACRUM 0:119624335925 46 * when re-sendings exceeded. If set to NULL, no error message is returned.
MACRUM 0:119624335925 47 *
MACRUM 0:119624335925 48 * \return Pointer to handle when success
MACRUM 0:119624335925 49 * Null if failed
MACRUM 0:119624335925 50 */
MACRUM 0:119624335925 51
MACRUM 0:119624335925 52 extern struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
MACRUM 0:119624335925 53 uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *),
MACRUM 0:119624335925 54 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *));
MACRUM 0:119624335925 55
MACRUM 0:119624335925 56 /**
MACRUM 0:119624335925 57 * \fn int8_t sn_coap_protocol_destroy(void)
MACRUM 0:119624335925 58 *
MACRUM 0:119624335925 59 * \brief Frees all memory from CoAP protocol part
MACRUM 0:119624335925 60 *
MACRUM 0:119624335925 61 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 62 *
MACRUM 0:119624335925 63 * \return Return value is always 0
MACRUM 0:119624335925 64 */
MACRUM 0:119624335925 65 extern int8_t sn_coap_protocol_destroy(struct coap_s *handle);
MACRUM 0:119624335925 66
MACRUM 0:119624335925 67 /**
MACRUM 0:119624335925 68 * \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)
MACRUM 0:119624335925 69 *
MACRUM 0:119624335925 70 * \brief Builds Packet data from given CoAP header structure to be sent
MACRUM 0:119624335925 71 *
MACRUM 0:119624335925 72 * \param *dst_addr_ptr is pointer to destination address where CoAP message
MACRUM 0:119624335925 73 * will be sent (CoAP builder needs that information for message resending purposes)
MACRUM 0:119624335925 74 *
MACRUM 0:119624335925 75 * \param *dst_packet_data_ptr is pointer to destination of built Packet data
MACRUM 0:119624335925 76 *
MACRUM 0:119624335925 77 * \param *src_coap_msg_ptr is pointer to source of built Packet data
MACRUM 0:119624335925 78 *
MACRUM 0:119624335925 79 * \param param void pointer that will be passed to tx/rx function callback when those are called.
MACRUM 0:119624335925 80 *
MACRUM 0:119624335925 81 * \return Return value is byte count of built Packet data.\n
MACRUM 0:119624335925 82 * Note: If message is blockwised, all payload is not sent at the same time\n
MACRUM 0:119624335925 83 * In failure cases:\n
MACRUM 0:119624335925 84 * -1 = Failure in CoAP header structure\n
MACRUM 0:119624335925 85 * -2 = Failure in given pointer (= NULL)\n
MACRUM 0:119624335925 86 * -3 = Failure in Reset message\n
MACRUM 0:119624335925 87 * -4 = Failure in Resending message store\n
MACRUM 0:119624335925 88 * If there is not enough memory (or User given limit exceeded) for storing
MACRUM 0:119624335925 89 * resending messages, situation is ignored.
MACRUM 0:119624335925 90 */
MACRUM 0:119624335925 91 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);
MACRUM 0:119624335925 92
MACRUM 0:119624335925 93 /**
MACRUM 0:119624335925 94 * \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)
MACRUM 0:119624335925 95 *
MACRUM 0:119624335925 96 * \brief Parses received CoAP message from given Packet data
MACRUM 0:119624335925 97 *
MACRUM 0:119624335925 98 * \param *src_addr_ptr is pointer to source address of received CoAP message
MACRUM 0:119624335925 99 * (CoAP parser needs that information for Message acknowledgement)
MACRUM 0:119624335925 100 *
MACRUM 0:119624335925 101 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 102 *
MACRUM 0:119624335925 103 * \param packet_data_len is length of given Packet data to be parsed to CoAP message
MACRUM 0:119624335925 104 *
MACRUM 0:119624335925 105 * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message
MACRUM 0:119624335925 106 *
MACRUM 0:119624335925 107 * \param param void pointer that will be passed to tx/rx function callback when those are called.
MACRUM 0:119624335925 108 *
MACRUM 0:119624335925 109 * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n
MACRUM 0:119624335925 110 * In following failure cases NULL is returned:\n
MACRUM 0:119624335925 111 * -Given NULL pointer\n
MACRUM 0:119624335925 112 * -Failure in parsed header of non-confirmable message\ŋ
MACRUM 0:119624335925 113 * -Out of memory (malloc() returns NULL)
MACRUM 0:119624335925 114 */
MACRUM 0:119624335925 115 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 *);
MACRUM 0:119624335925 116
MACRUM 0:119624335925 117 /**
MACRUM 0:119624335925 118 * \fn int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)
MACRUM 0:119624335925 119 *
MACRUM 0:119624335925 120 * \brief Sends CoAP messages from re-sending queue, if there is any.
MACRUM 0:119624335925 121 * Cleans also old messages from the duplication list and from block receiving list
MACRUM 0:119624335925 122 *
MACRUM 0:119624335925 123 * This function can be called e.g. once in a second but also more frequently.
MACRUM 0:119624335925 124 *
MACRUM 0:119624335925 125 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 126 *
MACRUM 0:119624335925 127 * \param current_time is System time in seconds. This time is
MACRUM 0:119624335925 128 * used for message re-sending timing and to identify old saved data.
MACRUM 0:119624335925 129 *
MACRUM 0:119624335925 130 * \return 0 if success
MACRUM 0:119624335925 131 * -1 if failed
MACRUM 0:119624335925 132 */
MACRUM 0:119624335925 133
MACRUM 0:119624335925 134 extern int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time);
MACRUM 0:119624335925 135
MACRUM 0:119624335925 136 /**
MACRUM 0:119624335925 137 * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size)
MACRUM 0:119624335925 138 *
MACRUM 0:119624335925 139 * \brief If block transfer is enabled, this function changes the block size.
MACRUM 0:119624335925 140 *
MACRUM 0:119624335925 141 * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes
MACRUM 0:119624335925 142 * \return 0 = success
MACRUM 0:119624335925 143 * -1 = failure
MACRUM 0:119624335925 144 */
MACRUM 0:119624335925 145 extern int8_t sn_coap_protocol_set_block_size(struct coap_s *handle, uint16_t block_size);
MACRUM 0:119624335925 146
MACRUM 0:119624335925 147 /**
MACRUM 0:119624335925 148 * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count)
MACRUM 0:119624335925 149 *
MACRUM 0:119624335925 150 * \brief If dublicate message detection is enabled, this function changes buffer size.
MACRUM 0:119624335925 151 *
MACRUM 0:119624335925 152 * \param uint8_t message_count max number of messages saved for duplicate control
MACRUM 0:119624335925 153 * \return 0 = success
MACRUM 0:119624335925 154 * -1 = failure
MACRUM 0:119624335925 155 */
MACRUM 0:119624335925 156 extern int8_t sn_coap_protocol_set_duplicate_buffer_size(struct coap_s *handle, uint8_t message_count);
MACRUM 0:119624335925 157
MACRUM 0:119624335925 158 /**
MACRUM 0:119624335925 159 * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall)
MACRUM 0:119624335925 160 *
MACRUM 0:119624335925 161 * \brief If re-transmissions are enabled, this function changes resending count and interval.
MACRUM 0:119624335925 162 *
MACRUM 0:119624335925 163 * \param uint8_t resending_count max number of resendings for message
MACRUM 0:119624335925 164 * \param uint8_t resending_intervall message resending intervall in seconds
MACRUM 0:119624335925 165 * \return 0 = success, -1 = failure
MACRUM 0:119624335925 166 */
MACRUM 0:119624335925 167 extern int8_t sn_coap_protocol_set_retransmission_parameters(struct coap_s *handle,
MACRUM 0:119624335925 168 uint8_t resending_count, uint8_t resending_interval);
MACRUM 0:119624335925 169
MACRUM 0:119624335925 170 /**
MACRUM 0:119624335925 171 * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes)
MACRUM 0:119624335925 172 *
MACRUM 0:119624335925 173 * \brief If re-transmissions are enabled, this function changes message retransmission queue size.
MACRUM 0:119624335925 174 * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled.
MACRUM 0:119624335925 175 *
MACRUM 0:119624335925 176 * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue
MACRUM 0:119624335925 177 * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue
MACRUM 0:119624335925 178 * \return 0 = success, -1 = failure
MACRUM 0:119624335925 179 */
MACRUM 0:119624335925 180 extern int8_t sn_coap_protocol_set_retransmission_buffer(struct coap_s *handle,
MACRUM 0:119624335925 181 uint8_t buffer_size_messages, uint16_t buffer_size_bytes);
MACRUM 0:119624335925 182
MACRUM 0:119624335925 183 /**
MACRUM 0:119624335925 184 * \fn void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle)
MACRUM 0:119624335925 185 *
MACRUM 0:119624335925 186 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 187 *
MACRUM 0:119624335925 188 * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue.
MACRUM 0:119624335925 189 */
MACRUM 0:119624335925 190 extern void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle);
MACRUM 0:119624335925 191
MACRUM 0:119624335925 192 /**
MACRUM 0:119624335925 193 * \fn sn_coap_protocol_block_remove
MACRUM 0:119624335925 194 *
MACRUM 0:119624335925 195 * \brief Remove saved block data. Can be used to remove the data from RAM to enable storing it to other place.
MACRUM 0:119624335925 196 *
MACRUM 0:119624335925 197 * \param handle Pointer to CoAP library handle
MACRUM 0:119624335925 198 * \param source_address Addres from where the block has been received.
MACRUM 0:119624335925 199 * \param payload_length Length of the coap payload of the block.
MACRUM 0:119624335925 200 * \param payload Coap payload of the block.
MACRUM 0:119624335925 201 *
MACRUM 0:119624335925 202 */
MACRUM 0:119624335925 203 extern void sn_coap_protocol_block_remove(struct coap_s *handle, sn_nsdl_addr_s *source_address, uint16_t payload_length, void *payload);
MACRUM 0:119624335925 204
MACRUM 0:119624335925 205 /**
MACRUM 0:119624335925 206 * \fn void sn_coap_protocol_delete_retransmission(struct coap_s *handle)
MACRUM 0:119624335925 207 *
MACRUM 0:119624335925 208 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 209 * \msg_id message ID to be removed
MACRUM 0:119624335925 210 * \return returns 0 when success, -1 for invalid parameter, -2 if message was not found
MACRUM 0:119624335925 211 *
MACRUM 0:119624335925 212 * \brief If re-transmissions are enabled, this function removes message from retransmission buffer.
MACRUM 0:119624335925 213 */
MACRUM 0:119624335925 214 extern int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint16_t msg_id);
MACRUM 0:119624335925 215
MACRUM 0:119624335925 216 /**
MACRUM 0:119624335925 217 * \fn int8_t sn_coap_convert_block_size(uint16_t block_size)
MACRUM 0:119624335925 218 *
MACRUM 0:119624335925 219 * \brief Utility function to convert block size.
MACRUM 0:119624335925 220 *
MACRUM 0:119624335925 221 * \param block_size Block size to convert.
MACRUM 0:119624335925 222 *
MACRUM 0:119624335925 223 * \return Value of range 0 - 6
MACRUM 0:119624335925 224 */
MACRUM 0:119624335925 225 extern int8_t sn_coap_convert_block_size(uint16_t block_size);
MACRUM 0:119624335925 226
MACRUM 0:119624335925 227 /**
MACRUM 0:119624335925 228 * \fn int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response)
MACRUM 0:119624335925 229 *
MACRUM 0:119624335925 230 * \brief This function change the state whether CoAP library sends the block 2 response automatically or not.
MACRUM 0:119624335925 231 *
MACRUM 0:119624335925 232 * \param *handle Pointer to CoAP library handle
MACRUM 0:119624335925 233 * \param handle_response 1 if CoAP library handles the response sending otherwise 0.
MACRUM 0:119624335925 234 *
MACRUM 0:119624335925 235 * \return 0 = success, -1 = failure
MACRUM 0:119624335925 236 */
MACRUM 0:119624335925 237 extern int8_t sn_coap_protocol_handle_block2_response_internally(struct coap_s *handle, uint8_t handle_response);
MACRUM 0:119624335925 238
MACRUM 0:119624335925 239 #endif /* SN_COAP_PROTOCOL_H_ */
MACRUM 0:119624335925 240
MACRUM 0:119624335925 241 #ifdef __cplusplus
MACRUM 0:119624335925 242 }
MACRUM 0:119624335925 243 #endif