![](/media/cache/profiles/debfdc81854eac26ec993b55a659c6e1.jpg.50x50_q85.jpg)
mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client-c/nsdl-c/sn_coap_protocol.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2011-2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | |
mbedAustin | 11:cada08fc8a70 | 17 | /** |
mbedAustin | 11:cada08fc8a70 | 18 | * \file sn_coap_protocol.h |
mbedAustin | 11:cada08fc8a70 | 19 | * |
mbedAustin | 11:cada08fc8a70 | 20 | * \brief CoAP C-library User protocol interface header file |
mbedAustin | 11:cada08fc8a70 | 21 | */ |
mbedAustin | 11:cada08fc8a70 | 22 | |
mbedAustin | 11:cada08fc8a70 | 23 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 24 | extern "C" { |
mbedAustin | 11:cada08fc8a70 | 25 | #endif |
mbedAustin | 11:cada08fc8a70 | 26 | |
mbedAustin | 11:cada08fc8a70 | 27 | #ifndef SN_COAP_PROTOCOL_H_ |
mbedAustin | 11:cada08fc8a70 | 28 | #define SN_COAP_PROTOCOL_H_ |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | #include "sn_coap_header.h" |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | /** |
mbedAustin | 11:cada08fc8a70 | 33 | * \fn struct coap_s *sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*), |
mbedAustin | 11:cada08fc8a70 | 34 | uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *), |
mbedAustin | 11:cada08fc8a70 | 35 | int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *) |
mbedAustin | 11:cada08fc8a70 | 36 | * |
mbedAustin | 11:cada08fc8a70 | 37 | * \brief Initializes CoAP Protocol part. When using libNsdl, sn_nsdl_init() calls this function. |
mbedAustin | 11:cada08fc8a70 | 38 | * |
mbedAustin | 11:cada08fc8a70 | 39 | * \param *used_malloc_func_ptr is function pointer for used memory allocation function. |
mbedAustin | 11:cada08fc8a70 | 40 | * |
mbedAustin | 11:cada08fc8a70 | 41 | * \param *used_free_func_ptr is function pointer for used memory free function. |
mbedAustin | 11:cada08fc8a70 | 42 | * |
mbedAustin | 11:cada08fc8a70 | 43 | * \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages |
mbedAustin | 11:cada08fc8a70 | 44 | * |
mbedAustin | 11:cada08fc8a70 | 45 | * \param *used_rx_callback_ptr used to return CoAP header struct with status COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED |
mbedAustin | 11:cada08fc8a70 | 46 | * when re-sendings exceeded. If set to NULL, no error message is returned. |
mbedAustin | 11:cada08fc8a70 | 47 | * |
mbedAustin | 11:cada08fc8a70 | 48 | * \return Pointer to handle when success |
mbedAustin | 11:cada08fc8a70 | 49 | * Null if failed |
mbedAustin | 11:cada08fc8a70 | 50 | */ |
mbedAustin | 11:cada08fc8a70 | 51 | |
mbedAustin | 11:cada08fc8a70 | 52 | extern struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), |
mbedAustin | 11:cada08fc8a70 | 53 | uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *), |
mbedAustin | 11:cada08fc8a70 | 54 | int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *)); |
mbedAustin | 11:cada08fc8a70 | 55 | |
mbedAustin | 11:cada08fc8a70 | 56 | /** |
mbedAustin | 11:cada08fc8a70 | 57 | * \fn int8_t sn_coap_protocol_destroy(void) |
mbedAustin | 11:cada08fc8a70 | 58 | * |
mbedAustin | 11:cada08fc8a70 | 59 | * \brief Frees all memory from CoAP protocol part |
mbedAustin | 11:cada08fc8a70 | 60 | * |
mbedAustin | 11:cada08fc8a70 | 61 | * \param *handle Pointer to CoAP library handle |
mbedAustin | 11:cada08fc8a70 | 62 | * |
mbedAustin | 11:cada08fc8a70 | 63 | * \return Return value is always 0 |
mbedAustin | 11:cada08fc8a70 | 64 | */ |
mbedAustin | 11:cada08fc8a70 | 65 | extern int8_t sn_coap_protocol_destroy(struct coap_s *handle); |
mbedAustin | 11:cada08fc8a70 | 66 | |
mbedAustin | 11:cada08fc8a70 | 67 | /** |
mbedAustin | 11:cada08fc8a70 | 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) |
mbedAustin | 11:cada08fc8a70 | 69 | * |
mbedAustin | 11:cada08fc8a70 | 70 | * \brief Builds Packet data from given CoAP header structure to be sent |
mbedAustin | 11:cada08fc8a70 | 71 | * |
mbedAustin | 11:cada08fc8a70 | 72 | * \param *dst_addr_ptr is pointer to destination address where CoAP message |
mbedAustin | 11:cada08fc8a70 | 73 | * will be sent (CoAP builder needs that information for message resending purposes) |
mbedAustin | 11:cada08fc8a70 | 74 | * |
mbedAustin | 11:cada08fc8a70 | 75 | * \param *dst_packet_data_ptr is pointer to destination of built Packet data |
mbedAustin | 11:cada08fc8a70 | 76 | * |
mbedAustin | 11:cada08fc8a70 | 77 | * \param *src_coap_msg_ptr is pointer to source of built Packet data |
mbedAustin | 11:cada08fc8a70 | 78 | * |
mbedAustin | 11:cada08fc8a70 | 79 | * \param param void pointer that will be passed to tx/rx function callback when those are called. |
mbedAustin | 11:cada08fc8a70 | 80 | * |
mbedAustin | 11:cada08fc8a70 | 81 | * \return Return value is byte count of built Packet data.\n |
mbedAustin | 11:cada08fc8a70 | 82 | * Note: If message is blockwised, all payload is not sent at the same time\n |
mbedAustin | 11:cada08fc8a70 | 83 | * In failure cases:\n |
mbedAustin | 11:cada08fc8a70 | 84 | * -1 = Failure in CoAP header structure\n |
mbedAustin | 11:cada08fc8a70 | 85 | * -2 = Failure in given pointer (= NULL)\n |
mbedAustin | 11:cada08fc8a70 | 86 | * -3 = Failure in Reset message\ŋ |
mbedAustin | 11:cada08fc8a70 | 87 | * If there is not enough memory (or User given limit exceeded) for storing |
mbedAustin | 11:cada08fc8a70 | 88 | * resending messages, situation is ignored. |
mbedAustin | 11:cada08fc8a70 | 89 | */ |
mbedAustin | 11:cada08fc8a70 | 90 | 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); |
mbedAustin | 11:cada08fc8a70 | 91 | |
mbedAustin | 11:cada08fc8a70 | 92 | /** |
mbedAustin | 11:cada08fc8a70 | 93 | * \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) |
mbedAustin | 11:cada08fc8a70 | 94 | * |
mbedAustin | 11:cada08fc8a70 | 95 | * \brief Parses received CoAP message from given Packet data |
mbedAustin | 11:cada08fc8a70 | 96 | * |
mbedAustin | 11:cada08fc8a70 | 97 | * \param *src_addr_ptr is pointer to source address of received CoAP message |
mbedAustin | 11:cada08fc8a70 | 98 | * (CoAP parser needs that information for Message acknowledgement) |
mbedAustin | 11:cada08fc8a70 | 99 | * |
mbedAustin | 11:cada08fc8a70 | 100 | * \param *handle Pointer to CoAP library handle |
mbedAustin | 11:cada08fc8a70 | 101 | * |
mbedAustin | 11:cada08fc8a70 | 102 | * \param packet_data_len is length of given Packet data to be parsed to CoAP message |
mbedAustin | 11:cada08fc8a70 | 103 | * |
mbedAustin | 11:cada08fc8a70 | 104 | * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message |
mbedAustin | 11:cada08fc8a70 | 105 | * |
mbedAustin | 11:cada08fc8a70 | 106 | * \param param void pointer that will be passed to tx/rx function callback when those are called. |
mbedAustin | 11:cada08fc8a70 | 107 | * |
mbedAustin | 11:cada08fc8a70 | 108 | * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n |
mbedAustin | 11:cada08fc8a70 | 109 | * In following failure cases NULL is returned:\n |
mbedAustin | 11:cada08fc8a70 | 110 | * -Given NULL pointer\n |
mbedAustin | 11:cada08fc8a70 | 111 | * -Failure in parsed header of non-confirmable message\ŋ |
mbedAustin | 11:cada08fc8a70 | 112 | * -Out of memory (malloc() returns NULL) |
mbedAustin | 11:cada08fc8a70 | 113 | */ |
mbedAustin | 11:cada08fc8a70 | 114 | 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 *); |
mbedAustin | 11:cada08fc8a70 | 115 | |
mbedAustin | 11:cada08fc8a70 | 116 | /** |
mbedAustin | 11:cada08fc8a70 | 117 | * \fn int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) |
mbedAustin | 11:cada08fc8a70 | 118 | * |
mbedAustin | 11:cada08fc8a70 | 119 | * \brief Sends CoAP messages from re-sending queue, if there is any. |
mbedAustin | 11:cada08fc8a70 | 120 | * Cleans also old messages from the duplication list and from block receiving list |
mbedAustin | 11:cada08fc8a70 | 121 | * |
mbedAustin | 11:cada08fc8a70 | 122 | * This function can be called e.g. once in a second but also more frequently. |
mbedAustin | 11:cada08fc8a70 | 123 | * |
mbedAustin | 11:cada08fc8a70 | 124 | * \param *handle Pointer to CoAP library handle |
mbedAustin | 11:cada08fc8a70 | 125 | * |
mbedAustin | 11:cada08fc8a70 | 126 | * \param current_time is System time in seconds. This time is |
mbedAustin | 11:cada08fc8a70 | 127 | * used for message re-sending timing and to identify old saved data. |
mbedAustin | 11:cada08fc8a70 | 128 | * |
mbedAustin | 11:cada08fc8a70 | 129 | * \return 0 if success |
mbedAustin | 11:cada08fc8a70 | 130 | * -1 if failed |
mbedAustin | 11:cada08fc8a70 | 131 | */ |
mbedAustin | 11:cada08fc8a70 | 132 | |
mbedAustin | 11:cada08fc8a70 | 133 | extern int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time); |
mbedAustin | 11:cada08fc8a70 | 134 | |
mbedAustin | 11:cada08fc8a70 | 135 | /** |
mbedAustin | 11:cada08fc8a70 | 136 | * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size) |
mbedAustin | 11:cada08fc8a70 | 137 | * |
mbedAustin | 11:cada08fc8a70 | 138 | * \brief If block transfer is enabled, this function changes the block size. |
mbedAustin | 11:cada08fc8a70 | 139 | * |
mbedAustin | 11:cada08fc8a70 | 140 | * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes |
mbedAustin | 11:cada08fc8a70 | 141 | * \return 0 = success |
mbedAustin | 11:cada08fc8a70 | 142 | * -1 = failure |
mbedAustin | 11:cada08fc8a70 | 143 | */ |
mbedAustin | 11:cada08fc8a70 | 144 | extern int8_t sn_coap_protocol_set_block_size(uint16_t block_size); |
mbedAustin | 11:cada08fc8a70 | 145 | |
mbedAustin | 11:cada08fc8a70 | 146 | /** |
mbedAustin | 11:cada08fc8a70 | 147 | * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count) |
mbedAustin | 11:cada08fc8a70 | 148 | * |
mbedAustin | 11:cada08fc8a70 | 149 | * \brief If dublicate message detection is enabled, this function changes buffer size. |
mbedAustin | 11:cada08fc8a70 | 150 | * |
mbedAustin | 11:cada08fc8a70 | 151 | * \param uint8_t message_count max number of messages saved for duplicate control |
mbedAustin | 11:cada08fc8a70 | 152 | * \return 0 = success |
mbedAustin | 11:cada08fc8a70 | 153 | * -1 = failure |
mbedAustin | 11:cada08fc8a70 | 154 | */ |
mbedAustin | 11:cada08fc8a70 | 155 | extern int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count); |
mbedAustin | 11:cada08fc8a70 | 156 | |
mbedAustin | 11:cada08fc8a70 | 157 | /** |
mbedAustin | 11:cada08fc8a70 | 158 | * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall) |
mbedAustin | 11:cada08fc8a70 | 159 | * |
mbedAustin | 11:cada08fc8a70 | 160 | * \brief If re-transmissions are enabled, this function changes resending count and interval. |
mbedAustin | 11:cada08fc8a70 | 161 | * |
mbedAustin | 11:cada08fc8a70 | 162 | * \param uint8_t resending_count max number of resendings for message |
mbedAustin | 11:cada08fc8a70 | 163 | * \param uint8_t resending_intervall message resending intervall in seconds |
mbedAustin | 11:cada08fc8a70 | 164 | * \return 0 = success |
mbedAustin | 11:cada08fc8a70 | 165 | * -1 = failure |
mbedAustin | 11:cada08fc8a70 | 166 | */ |
mbedAustin | 11:cada08fc8a70 | 167 | extern int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_interval); |
mbedAustin | 11:cada08fc8a70 | 168 | |
mbedAustin | 11:cada08fc8a70 | 169 | /** |
mbedAustin | 11:cada08fc8a70 | 170 | * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes) |
mbedAustin | 11:cada08fc8a70 | 171 | * |
mbedAustin | 11:cada08fc8a70 | 172 | * \brief If re-transmissions are enabled, this function changes message retransmission queue size. |
mbedAustin | 11:cada08fc8a70 | 173 | * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled. |
mbedAustin | 11:cada08fc8a70 | 174 | * |
mbedAustin | 11:cada08fc8a70 | 175 | * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue |
mbedAustin | 11:cada08fc8a70 | 176 | * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue |
mbedAustin | 11:cada08fc8a70 | 177 | * \return 0 = success |
mbedAustin | 11:cada08fc8a70 | 178 | * -1 = failure |
mbedAustin | 11:cada08fc8a70 | 179 | */ |
mbedAustin | 11:cada08fc8a70 | 180 | extern int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes); |
mbedAustin | 11:cada08fc8a70 | 181 | |
mbedAustin | 11:cada08fc8a70 | 182 | /** |
mbedAustin | 11:cada08fc8a70 | 183 | * \fn void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle) |
mbedAustin | 11:cada08fc8a70 | 184 | * |
mbedAustin | 11:cada08fc8a70 | 185 | * \param *handle Pointer to CoAP library handle |
mbedAustin | 11:cada08fc8a70 | 186 | * |
mbedAustin | 11:cada08fc8a70 | 187 | * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue. |
mbedAustin | 11:cada08fc8a70 | 188 | */ |
mbedAustin | 11:cada08fc8a70 | 189 | extern void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle); |
mbedAustin | 11:cada08fc8a70 | 190 | |
mbedAustin | 11:cada08fc8a70 | 191 | #endif /* SN_COAP_PROTOCOL_H_ */ |
mbedAustin | 11:cada08fc8a70 | 192 | |
mbedAustin | 11:cada08fc8a70 | 193 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 194 | } |
mbedAustin | 11:cada08fc8a70 | 195 | #endif |
mbedAustin | 11:cada08fc8a70 | 196 |