hello

Dependents:   nespresso_demo nespresso_endpoint EnvoyNespressoEndpointColorDetectorV2

Fork of nsdl by Robert Taylor

Committer:
GeofferyOmlette
Date:
Wed Jun 04 15:38:26 2014 +0000
Revision:
0:f6e4e1bbb3fe
hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GeofferyOmlette 0:f6e4e1bbb3fe 1 /**
GeofferyOmlette 0:f6e4e1bbb3fe 2 * \file sn_coap_protocol.h
GeofferyOmlette 0:f6e4e1bbb3fe 3 *
GeofferyOmlette 0:f6e4e1bbb3fe 4 * \brief CoAP C-library User protocol interface header file
GeofferyOmlette 0:f6e4e1bbb3fe 5 *
GeofferyOmlette 0:f6e4e1bbb3fe 6 * Created on: Jun 30, 2011
GeofferyOmlette 0:f6e4e1bbb3fe 7 * Author: tero
GeofferyOmlette 0:f6e4e1bbb3fe 8 *
GeofferyOmlette 0:f6e4e1bbb3fe 9 */
GeofferyOmlette 0:f6e4e1bbb3fe 10
GeofferyOmlette 0:f6e4e1bbb3fe 11 #ifdef __cplusplus
GeofferyOmlette 0:f6e4e1bbb3fe 12 extern "C" {
GeofferyOmlette 0:f6e4e1bbb3fe 13 #endif
GeofferyOmlette 0:f6e4e1bbb3fe 14
GeofferyOmlette 0:f6e4e1bbb3fe 15 #ifndef SN_COAP_PROTOCOL_H_
GeofferyOmlette 0:f6e4e1bbb3fe 16 #define SN_COAP_PROTOCOL_H_
GeofferyOmlette 0:f6e4e1bbb3fe 17
GeofferyOmlette 0:f6e4e1bbb3fe 18
GeofferyOmlette 0:f6e4e1bbb3fe 19 /* * * * * * * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 20 /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 21 /* * * * * * * * * * * * * * * * * * * * * * */
GeofferyOmlette 0:f6e4e1bbb3fe 22
GeofferyOmlette 0:f6e4e1bbb3fe 23 /**
GeofferyOmlette 0:f6e4e1bbb3fe 24 * \fn int8_t sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*),
GeofferyOmlette 0:f6e4e1bbb3fe 25 uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
GeofferyOmlette 0:f6e4e1bbb3fe 26 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *)
GeofferyOmlette 0:f6e4e1bbb3fe 27 *
GeofferyOmlette 0:f6e4e1bbb3fe 28 * \brief Initializes CoAP Protocol part. When using libNsdl, sn_nsdl_init() calls this function.
GeofferyOmlette 0:f6e4e1bbb3fe 29 *
GeofferyOmlette 0:f6e4e1bbb3fe 30 * \param *used_malloc_func_ptr is function pointer for used malloc() function.
GeofferyOmlette 0:f6e4e1bbb3fe 31 * If set to NULL, CoAP Protocol part uses standard C-library malloc() function.
GeofferyOmlette 0:f6e4e1bbb3fe 32 *
GeofferyOmlette 0:f6e4e1bbb3fe 33 * \param *used_free_func_ptr is function pointer for used free() function.
GeofferyOmlette 0:f6e4e1bbb3fe 34 * If set to NULL, CoAP Protocol part uses standard C-library free() function.
GeofferyOmlette 0:f6e4e1bbb3fe 35 *
GeofferyOmlette 0:f6e4e1bbb3fe 36 * \param *used_tx_callback_ptr function callback pointer to tx function for sending coap messages
GeofferyOmlette 0:f6e4e1bbb3fe 37 *
GeofferyOmlette 0:f6e4e1bbb3fe 38 * \param *used_rx_callback_ptr used to return CoAP header struct with status COAP_STATUS_BUILDER_MESSAGE_SENDING_FAILED
GeofferyOmlette 0:f6e4e1bbb3fe 39 * when re-sendings exceeded. If set to NULL, no error message is returned.
GeofferyOmlette 0:f6e4e1bbb3fe 40 */
GeofferyOmlette 0:f6e4e1bbb3fe 41
GeofferyOmlette 0:f6e4e1bbb3fe 42 extern int8_t sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*),
GeofferyOmlette 0:f6e4e1bbb3fe 43 uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
GeofferyOmlette 0:f6e4e1bbb3fe 44 int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *));
GeofferyOmlette 0:f6e4e1bbb3fe 45
GeofferyOmlette 0:f6e4e1bbb3fe 46 /**
GeofferyOmlette 0:f6e4e1bbb3fe 47 * \fn int8_t sn_coap_protocol_destroy(void)
GeofferyOmlette 0:f6e4e1bbb3fe 48 *
GeofferyOmlette 0:f6e4e1bbb3fe 49 * \brief Frees all memory from CoAP protocol part
GeofferyOmlette 0:f6e4e1bbb3fe 50 *
GeofferyOmlette 0:f6e4e1bbb3fe 51 * \return Return value is always 0
GeofferyOmlette 0:f6e4e1bbb3fe 52 */
GeofferyOmlette 0:f6e4e1bbb3fe 53 extern int8_t sn_coap_protocol_destroy(void);
GeofferyOmlette 0:f6e4e1bbb3fe 54
GeofferyOmlette 0:f6e4e1bbb3fe 55 /**
GeofferyOmlette 0:f6e4e1bbb3fe 56 * \fn int16_t sn_coap_protocol_build(sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 57 *
GeofferyOmlette 0:f6e4e1bbb3fe 58 * \brief Builds Packet data from given CoAP header structure to be sent
GeofferyOmlette 0:f6e4e1bbb3fe 59 *
GeofferyOmlette 0:f6e4e1bbb3fe 60 * \param *dst_addr_ptr is pointer to destination address where CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 61 * will be sent (CoAP builder needs that information for message resending purposes)
GeofferyOmlette 0:f6e4e1bbb3fe 62 *
GeofferyOmlette 0:f6e4e1bbb3fe 63 * \param *dst_packet_data_ptr is pointer to destination of built Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 64 *
GeofferyOmlette 0:f6e4e1bbb3fe 65 * \param *src_coap_msg_ptr is pointer to source of built Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 66 *
GeofferyOmlette 0:f6e4e1bbb3fe 67 * \return Return value is byte count of built Packet data.\n
GeofferyOmlette 0:f6e4e1bbb3fe 68 * Note: If message is blockwised, all payload is not sent at the same time\n
GeofferyOmlette 0:f6e4e1bbb3fe 69 * In failure cases:\n
GeofferyOmlette 0:f6e4e1bbb3fe 70 * -1 = Failure in CoAP header structure\n
GeofferyOmlette 0:f6e4e1bbb3fe 71 * -2 = Failure in given pointer (= NULL)\n
GeofferyOmlette 0:f6e4e1bbb3fe 72 * -3 = Failure in Reset message\ŋ
GeofferyOmlette 0:f6e4e1bbb3fe 73 * If there is not enough memory (or User given limit exceeded) for storing
GeofferyOmlette 0:f6e4e1bbb3fe 74 * resending messages, situation is ignored.
GeofferyOmlette 0:f6e4e1bbb3fe 75 */
GeofferyOmlette 0:f6e4e1bbb3fe 76 extern int16_t sn_coap_protocol_build(sn_nsdl_addr_s *dst_addr_ptr, uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 77
GeofferyOmlette 0:f6e4e1bbb3fe 78 /**
GeofferyOmlette 0:f6e4e1bbb3fe 79 * \fn sn_coap_hdr_s *sn_coap_protocol_parse(sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 80 *
GeofferyOmlette 0:f6e4e1bbb3fe 81 * \brief Parses received CoAP message from given Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 82 *
GeofferyOmlette 0:f6e4e1bbb3fe 83 * \param *src_addr_ptr is pointer to source address of received CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 84 * (CoAP parser needs that information for Message acknowledgement)
GeofferyOmlette 0:f6e4e1bbb3fe 85 *
GeofferyOmlette 0:f6e4e1bbb3fe 86 * \param packet_data_len is length of given Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 87 *
GeofferyOmlette 0:f6e4e1bbb3fe 88 * \param *packet_data_ptr is pointer to source of Packet data to be parsed to CoAP message
GeofferyOmlette 0:f6e4e1bbb3fe 89 *
GeofferyOmlette 0:f6e4e1bbb3fe 90 * \return Return value is pointer to parsed CoAP message structure. This structure includes also coap_status field.\n
GeofferyOmlette 0:f6e4e1bbb3fe 91 * In following failure cases NULL is returned:\n
GeofferyOmlette 0:f6e4e1bbb3fe 92 * -Given NULL pointer\n
GeofferyOmlette 0:f6e4e1bbb3fe 93 * -Failure in parsed header of non-confirmable message\ŋ
GeofferyOmlette 0:f6e4e1bbb3fe 94 * -Out of memory (malloc() returns NULL)
GeofferyOmlette 0:f6e4e1bbb3fe 95 */
GeofferyOmlette 0:f6e4e1bbb3fe 96 extern sn_coap_hdr_s *sn_coap_protocol_parse(sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 97
GeofferyOmlette 0:f6e4e1bbb3fe 98 /**
GeofferyOmlette 0:f6e4e1bbb3fe 99 * \fn int8_t sn_coap_protocol_exec(uint32_t current_time)
GeofferyOmlette 0:f6e4e1bbb3fe 100 *
GeofferyOmlette 0:f6e4e1bbb3fe 101 * \brief Sends CoAP messages from re-sending queue, if there is any.
GeofferyOmlette 0:f6e4e1bbb3fe 102 * Cleans also old messages from the duplication list and from block receiving list
GeofferyOmlette 0:f6e4e1bbb3fe 103 *
GeofferyOmlette 0:f6e4e1bbb3fe 104 * This function can be called e.g. once in a second but also more frequently.
GeofferyOmlette 0:f6e4e1bbb3fe 105 *
GeofferyOmlette 0:f6e4e1bbb3fe 106 * \param current_time is System time in seconds. This time is
GeofferyOmlette 0:f6e4e1bbb3fe 107 * used for message re-sending timing and to identify old saved data.
GeofferyOmlette 0:f6e4e1bbb3fe 108 *
GeofferyOmlette 0:f6e4e1bbb3fe 109 * \return 0 if success
GeofferyOmlette 0:f6e4e1bbb3fe 110 * -1 if failed
GeofferyOmlette 0:f6e4e1bbb3fe 111 */
GeofferyOmlette 0:f6e4e1bbb3fe 112
GeofferyOmlette 0:f6e4e1bbb3fe 113 extern int8_t sn_coap_protocol_exec(uint32_t current_time);
GeofferyOmlette 0:f6e4e1bbb3fe 114
GeofferyOmlette 0:f6e4e1bbb3fe 115 /**
GeofferyOmlette 0:f6e4e1bbb3fe 116 * \fn int8_t sn_coap_protocol_set_block_size(uint16_t block_size)
GeofferyOmlette 0:f6e4e1bbb3fe 117 *
GeofferyOmlette 0:f6e4e1bbb3fe 118 * \brief If block transfer is enabled, this function changes the block size.
GeofferyOmlette 0:f6e4e1bbb3fe 119 *
GeofferyOmlette 0:f6e4e1bbb3fe 120 * \param uint16_t block_size maximum size of CoAP payload. Valid sizes are 16, 32, 64, 128, 256, 512 and 1024 bytes
GeofferyOmlette 0:f6e4e1bbb3fe 121 * \return 0 = success
GeofferyOmlette 0:f6e4e1bbb3fe 122 * -1 = failure
GeofferyOmlette 0:f6e4e1bbb3fe 123 */
GeofferyOmlette 0:f6e4e1bbb3fe 124 extern int8_t sn_coap_protocol_set_block_size(uint16_t block_size);
GeofferyOmlette 0:f6e4e1bbb3fe 125
GeofferyOmlette 0:f6e4e1bbb3fe 126 /**
GeofferyOmlette 0:f6e4e1bbb3fe 127 * \fn int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count)
GeofferyOmlette 0:f6e4e1bbb3fe 128 *
GeofferyOmlette 0:f6e4e1bbb3fe 129 * \brief If dublicate message detection is enabled, this function changes buffer size.
GeofferyOmlette 0:f6e4e1bbb3fe 130 *
GeofferyOmlette 0:f6e4e1bbb3fe 131 * \param uint8_t message_count max number of messages saved for duplicate control
GeofferyOmlette 0:f6e4e1bbb3fe 132 * \return 0 = success
GeofferyOmlette 0:f6e4e1bbb3fe 133 * -1 = failure
GeofferyOmlette 0:f6e4e1bbb3fe 134 */
GeofferyOmlette 0:f6e4e1bbb3fe 135 extern int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count);
GeofferyOmlette 0:f6e4e1bbb3fe 136
GeofferyOmlette 0:f6e4e1bbb3fe 137 /**
GeofferyOmlette 0:f6e4e1bbb3fe 138 * \fn int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall)
GeofferyOmlette 0:f6e4e1bbb3fe 139 *
GeofferyOmlette 0:f6e4e1bbb3fe 140 * \brief If re-transmissions are enabled, this function changes resending count and interval.
GeofferyOmlette 0:f6e4e1bbb3fe 141 *
GeofferyOmlette 0:f6e4e1bbb3fe 142 * \param uint8_t resending_count max number of resendings for message
GeofferyOmlette 0:f6e4e1bbb3fe 143 * \param uint8_t resending_intervall message resending intervall in seconds
GeofferyOmlette 0:f6e4e1bbb3fe 144 * \return 0 = success
GeofferyOmlette 0:f6e4e1bbb3fe 145 * -1 = failure
GeofferyOmlette 0:f6e4e1bbb3fe 146 */
GeofferyOmlette 0:f6e4e1bbb3fe 147 extern int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_interval);
GeofferyOmlette 0:f6e4e1bbb3fe 148
GeofferyOmlette 0:f6e4e1bbb3fe 149 /**
GeofferyOmlette 0:f6e4e1bbb3fe 150 * \fn int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes)
GeofferyOmlette 0:f6e4e1bbb3fe 151 *
GeofferyOmlette 0:f6e4e1bbb3fe 152 * \brief If re-transmissions are enabled, this function changes message retransmission queue size.
GeofferyOmlette 0:f6e4e1bbb3fe 153 * Set size to '0' to disable feature. If both are set to '0', then re-sendings are disabled.
GeofferyOmlette 0:f6e4e1bbb3fe 154 *
GeofferyOmlette 0:f6e4e1bbb3fe 155 * \param uint8_t buffer_size_messages queue size - maximum number of messages to be saved to queue
GeofferyOmlette 0:f6e4e1bbb3fe 156 * \param uint8_t buffer_size_bytes queue size - maximum size of messages saved to queue
GeofferyOmlette 0:f6e4e1bbb3fe 157 * \return 0 = success
GeofferyOmlette 0:f6e4e1bbb3fe 158 * -1 = failure
GeofferyOmlette 0:f6e4e1bbb3fe 159 */
GeofferyOmlette 0:f6e4e1bbb3fe 160 extern int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes);
GeofferyOmlette 0:f6e4e1bbb3fe 161
GeofferyOmlette 0:f6e4e1bbb3fe 162 /**
GeofferyOmlette 0:f6e4e1bbb3fe 163 * \fn void sn_coap_protocol_reset_retransmission_buffer(void)
GeofferyOmlette 0:f6e4e1bbb3fe 164 *
GeofferyOmlette 0:f6e4e1bbb3fe 165 * \brief If re-transmissions are enabled, this function removes all messages from the retransmission queue.
GeofferyOmlette 0:f6e4e1bbb3fe 166 */
GeofferyOmlette 0:f6e4e1bbb3fe 167 extern void sn_coap_protocol_clear_retransmission_buffer(void);
GeofferyOmlette 0:f6e4e1bbb3fe 168
GeofferyOmlette 0:f6e4e1bbb3fe 169
GeofferyOmlette 0:f6e4e1bbb3fe 170 /* * * NSP manual registration functions * * */
GeofferyOmlette 0:f6e4e1bbb3fe 171
GeofferyOmlette 0:f6e4e1bbb3fe 172
GeofferyOmlette 0:f6e4e1bbb3fe 173 /**
GeofferyOmlette 0:f6e4e1bbb3fe 174 * \fn int8_t sn_coap_register(sn_coap_hdr_s *coap_hdr_ptr, registration_info_t *endpoint_info_ptr)
GeofferyOmlette 0:f6e4e1bbb3fe 175 *
GeofferyOmlette 0:f6e4e1bbb3fe 176 * \brief Builds RD registrtion request packet
GeofferyOmlette 0:f6e4e1bbb3fe 177 *
GeofferyOmlette 0:f6e4e1bbb3fe 178 * \param *coap_hdr_ptr is destination for built Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 179 * \param *endpoint_info_ptr pointer to struct that contains endpoint info parameters
GeofferyOmlette 0:f6e4e1bbb3fe 180 *
GeofferyOmlette 0:f6e4e1bbb3fe 181 * \return Return value 0 given on success. In failure cases:\n
GeofferyOmlette 0:f6e4e1bbb3fe 182 * -1 = Failure
GeofferyOmlette 0:f6e4e1bbb3fe 183 */
GeofferyOmlette 0:f6e4e1bbb3fe 184 extern int8_t sn_coap_register(sn_coap_hdr_s *coap_hdr_ptr, registration_info_t *endpoint_info_ptr);
GeofferyOmlette 0:f6e4e1bbb3fe 185
GeofferyOmlette 0:f6e4e1bbb3fe 186 /**
GeofferyOmlette 0:f6e4e1bbb3fe 187 * \fn int8_t sn_coap_register_update(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length)
GeofferyOmlette 0:f6e4e1bbb3fe 188 *
GeofferyOmlette 0:f6e4e1bbb3fe 189 * \brief Builds RD update request packet
GeofferyOmlette 0:f6e4e1bbb3fe 190 *
GeofferyOmlette 0:f6e4e1bbb3fe 191 * \param *coap_hdr_ptr is destination for built Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 192 * \param *location The location returned when registering with the RD
GeofferyOmlette 0:f6e4e1bbb3fe 193 * \param length length of the location
GeofferyOmlette 0:f6e4e1bbb3fe 194 *
GeofferyOmlette 0:f6e4e1bbb3fe 195 * \return Return value 0 given on success. In failure cases:\n
GeofferyOmlette 0:f6e4e1bbb3fe 196 * -1 = Failure
GeofferyOmlette 0:f6e4e1bbb3fe 197 */
GeofferyOmlette 0:f6e4e1bbb3fe 198 extern int8_t sn_coap_register_update(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length);
GeofferyOmlette 0:f6e4e1bbb3fe 199
GeofferyOmlette 0:f6e4e1bbb3fe 200 /**
GeofferyOmlette 0:f6e4e1bbb3fe 201 * \fn int8_t sn_coap_deregister(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length)
GeofferyOmlette 0:f6e4e1bbb3fe 202 *
GeofferyOmlette 0:f6e4e1bbb3fe 203 * \brief Builds RD de-registrtion request packet
GeofferyOmlette 0:f6e4e1bbb3fe 204 *
GeofferyOmlette 0:f6e4e1bbb3fe 205 * \param *coap_hdr_ptr is destination for built Packet data
GeofferyOmlette 0:f6e4e1bbb3fe 206 * \param *location The location returned when registering with the RD
GeofferyOmlette 0:f6e4e1bbb3fe 207 * \param length length of the location
GeofferyOmlette 0:f6e4e1bbb3fe 208 *
GeofferyOmlette 0:f6e4e1bbb3fe 209 * \return Return value 0 given on success. In failure cases:\n
GeofferyOmlette 0:f6e4e1bbb3fe 210 * -1 = Failure
GeofferyOmlette 0:f6e4e1bbb3fe 211 */
GeofferyOmlette 0:f6e4e1bbb3fe 212 extern int8_t sn_coap_deregister(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length);
GeofferyOmlette 0:f6e4e1bbb3fe 213
GeofferyOmlette 0:f6e4e1bbb3fe 214 #endif /* SN_COAP_PROTOCOL_H_ */
GeofferyOmlette 0:f6e4e1bbb3fe 215
GeofferyOmlette 0:f6e4e1bbb3fe 216 #ifdef __cplusplus
GeofferyOmlette 0:f6e4e1bbb3fe 217 }
GeofferyOmlette 0:f6e4e1bbb3fe 218 #endif