NSDL C library
Dependents: NSDL_HelloWorld_WiFi UbloxModemNanoServiceClient IOT-NSDL_HelloWorld LWM2M_NanoService_Ethernet ... more
Fork of nsdl_lib by
Note that use of this software requires acceptance of the Sensinode EULA: http://mbed.org/teams/Sensinode/code/nsdl_lib/wiki/EULA
sn_coap_protocol.h@2:ab50a2ab6ec9, 2013-10-09 (annotated)
- Committer:
- screamer
- Date:
- Wed Oct 09 14:57:33 2013 +0000
- Revision:
- 2:ab50a2ab6ec9
- Parent:
- 1:01d723824294
- Child:
- 3:d8cb1afd7285
Added doxygen markup #2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
terohoo | 0:58c4f13c4b9a | 1 | /** |
terohoo | 0:58c4f13c4b9a | 2 | * \file sn_coap_protocol.h |
terohoo | 0:58c4f13c4b9a | 3 | * |
terohoo | 0:58c4f13c4b9a | 4 | * \brief CoAP C-library User protocol interface header file |
terohoo | 0:58c4f13c4b9a | 5 | * |
terohoo | 0:58c4f13c4b9a | 6 | * Created on: Jun 30, 2011 |
terohoo | 0:58c4f13c4b9a | 7 | * Author: tero |
terohoo | 0:58c4f13c4b9a | 8 | * |
terohoo | 0:58c4f13c4b9a | 9 | */ |
terohoo | 0:58c4f13c4b9a | 10 | |
terohoo | 0:58c4f13c4b9a | 11 | #ifdef __cplusplus |
terohoo | 0:58c4f13c4b9a | 12 | extern "C" { |
terohoo | 0:58c4f13c4b9a | 13 | #endif |
terohoo | 0:58c4f13c4b9a | 14 | |
terohoo | 0:58c4f13c4b9a | 15 | #ifndef SN_COAP_PROTOCOL_H_ |
terohoo | 0:58c4f13c4b9a | 16 | #define SN_COAP_PROTOCOL_H_ |
terohoo | 0:58c4f13c4b9a | 17 | |
terohoo | 0:58c4f13c4b9a | 18 | /* * * * * * * * * * * */ |
terohoo | 0:58c4f13c4b9a | 19 | /* * * * DEFINES * * * */ |
terohoo | 0:58c4f13c4b9a | 20 | /* * * * * * * * * * * */ |
terohoo | 0:58c4f13c4b9a | 21 | |
terohoo | 0:58c4f13c4b9a | 22 | /* Maximum time in seconds of messages to be stored for Acknowledging. This time tells */ |
terohoo | 0:58c4f13c4b9a | 23 | /* how long time User of CoAP C-library have time to send Piggy-backed acknowledgement */ |
terohoo | 0:58c4f13c4b9a | 24 | /* message to Request sender. */ |
terohoo | 0:58c4f13c4b9a | 25 | #define SN_COAP_ACK_INFO_MAX_TIME_MSGS_STORED 20 |
terohoo | 0:58c4f13c4b9a | 26 | #define SN_COAP_ACK_INFO_MAX_COUNT_MESSAGES_SAVED 10 |
terohoo | 0:58c4f13c4b9a | 27 | |
terohoo | 0:58c4f13c4b9a | 28 | /* * For Message resending * */ |
terohoo | 0:58c4f13c4b9a | 29 | |
terohoo | 0:58c4f13c4b9a | 30 | /* Init value for maximum count of ongoing active resending messages */ |
terohoo | 0:58c4f13c4b9a | 31 | /* This value depends on available memory: If there is restricted count of memory, use little value e.g. 1 */ |
terohoo | 0:58c4f13c4b9a | 32 | /* Setting of this value to 0 will disable re-sending and also reduce use of ROM memory */ |
terohoo | 0:58c4f13c4b9a | 33 | #define SN_COAP_RESENDING_MAX_COUNT 0 |
terohoo | 0:58c4f13c4b9a | 34 | /* Default value for re-sending buffer size */ |
terohoo | 0:58c4f13c4b9a | 35 | #define SN_COAP_RESENDING_BUFFER_MAX_SIZE 0 |
terohoo | 0:58c4f13c4b9a | 36 | |
terohoo | 0:58c4f13c4b9a | 37 | /* These parameters sets maximum values application can set with API */ |
screamer | 1:01d723824294 | 38 | #define SN_COAP_MAX_ALLOWED_RESENDING_COUNT 6 /**< Maximum allowed count of re-sending */ |
screamer | 1:01d723824294 | 39 | #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE 6 /**< Maximum allowed number of saved re-sending messages */ |
terohoo | 0:58c4f13c4b9a | 40 | |
terohoo | 0:58c4f13c4b9a | 41 | /* * For Message duplication detecting * */ |
terohoo | 0:58c4f13c4b9a | 42 | |
terohoo | 0:58c4f13c4b9a | 43 | /* Init value for the maximum count of messages to be stored for duplication detection */ |
terohoo | 0:58c4f13c4b9a | 44 | /* Setting of this value to 0 will disable duplication check, also reduce use of ROM memory */ |
terohoo | 0:58c4f13c4b9a | 45 | #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT 0 |
terohoo | 0:58c4f13c4b9a | 46 | /* Maximum allowed number of saved messages for duplicate searching */ |
terohoo | 0:58c4f13c4b9a | 47 | #define SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT 6 |
terohoo | 0:58c4f13c4b9a | 48 | |
terohoo | 0:58c4f13c4b9a | 49 | /* Maximum time in seconds of messages to be stored for duplication detection */ |
terohoo | 0:58c4f13c4b9a | 50 | #define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 60 /* RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time */ |
terohoo | 0:58c4f13c4b9a | 51 | |
terohoo | 0:58c4f13c4b9a | 52 | /* * For Message blockwising * */ |
terohoo | 0:58c4f13c4b9a | 53 | |
terohoo | 0:58c4f13c4b9a | 54 | /* Init value for the maximum payload size to be sent and received at one blockwise message */ |
terohoo | 0:58c4f13c4b9a | 55 | /* Setting of this value to 0 will disable this feature, and also reduce use of ROM memory */ |
terohoo | 0:58c4f13c4b9a | 56 | /* Note: Current Coap implementation supports Blockwise transfers specification version draft-ietf-core-block-03 */ |
terohoo | 0:58c4f13c4b9a | 57 | /* Note: This define is common for both received and sent Blockwise messages */ |
terohoo | 0:58c4f13c4b9a | 58 | #ifndef SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE |
screamer | 1:01d723824294 | 59 | #define SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE 0 /**< Must be 2^x and x is at least 4. Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024 */ |
terohoo | 0:58c4f13c4b9a | 60 | #endif |
terohoo | 0:58c4f13c4b9a | 61 | |
terohoo | 0:58c4f13c4b9a | 62 | |
terohoo | 0:58c4f13c4b9a | 63 | #ifndef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED |
screamer | 1:01d723824294 | 64 | #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 10 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */ |
terohoo | 0:58c4f13c4b9a | 65 | #endif |
terohoo | 0:58c4f13c4b9a | 66 | |
terohoo | 0:58c4f13c4b9a | 67 | |
terohoo | 0:58c4f13c4b9a | 68 | /* * * * * * * * * * * * * * * * * * * * * * */ |
terohoo | 0:58c4f13c4b9a | 69 | /* * * * EXTERNAL FUNCTION PROTOTYPES * * * */ |
terohoo | 0:58c4f13c4b9a | 70 | /* * * * * * * * * * * * * * * * * * * * * * */ |
terohoo | 0:58c4f13c4b9a | 71 | |
screamer | 2:ab50a2ab6ec9 | 72 | /** |
screamer | 2:ab50a2ab6ec9 | 73 | * This function sets the memory allocation and deallocation functions the library will use, and must be called first. |
screamer | 2:ab50a2ab6ec9 | 74 | */ |
terohoo | 0:58c4f13c4b9a | 75 | extern int8_t sn_coap_protocol_init(void* (*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void*), |
terohoo | 0:58c4f13c4b9a | 76 | uint8_t (*used_tx_callback_ptr)(sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *)); |
screamer | 2:ab50a2ab6ec9 | 77 | |
screamer | 2:ab50a2ab6ec9 | 78 | /** |
screamer | 2:ab50a2ab6ec9 | 79 | * Frees all allocated memory in libCoap protocol part. |
screamer | 2:ab50a2ab6ec9 | 80 | */ |
terohoo | 0:58c4f13c4b9a | 81 | extern int8_t sn_coap_protocol_destroy(void); |
screamer | 2:ab50a2ab6ec9 | 82 | |
screamer | 2:ab50a2ab6ec9 | 83 | /** |
screamer | 2:ab50a2ab6ec9 | 84 | * Use to build an outgoing message buffer from a CoAP header structure. |
screamer | 2:ab50a2ab6ec9 | 85 | */ |
terohoo | 0:58c4f13c4b9a | 86 | 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); |
screamer | 2:ab50a2ab6ec9 | 87 | |
screamer | 2:ab50a2ab6ec9 | 88 | /** |
screamer | 2:ab50a2ab6ec9 | 89 | * Use to parse an incoming message buffer to a CoAP header structure. |
screamer | 2:ab50a2ab6ec9 | 90 | */ |
terohoo | 0:58c4f13c4b9a | 91 | 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); |
screamer | 2:ab50a2ab6ec9 | 92 | |
screamer | 2:ab50a2ab6ec9 | 93 | /** |
screamer | 2:ab50a2ab6ec9 | 94 | * Called periodically to allow the protocol to update retransmission timers and destroy unneeded data. |
screamer | 2:ab50a2ab6ec9 | 95 | */ |
terohoo | 0:58c4f13c4b9a | 96 | extern int8_t sn_coap_protocol_exec(uint32_t current_time); |
screamer | 2:ab50a2ab6ec9 | 97 | |
screamer | 2:ab50a2ab6ec9 | 98 | /** |
screamer | 2:ab50a2ab6ec9 | 99 | * If block transfer is enabled, this function changes the block size. |
screamer | 2:ab50a2ab6ec9 | 100 | */ |
terohoo | 0:58c4f13c4b9a | 101 | extern int8_t sn_coap_protocol_set_block_size(uint16_t block_size); |
screamer | 2:ab50a2ab6ec9 | 102 | |
screamer | 2:ab50a2ab6ec9 | 103 | /** |
screamer | 2:ab50a2ab6ec9 | 104 | * If dublicate message detection is enabled, this function changes buffer size. |
screamer | 2:ab50a2ab6ec9 | 105 | */ |
terohoo | 0:58c4f13c4b9a | 106 | extern int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count); |
screamer | 2:ab50a2ab6ec9 | 107 | |
screamer | 2:ab50a2ab6ec9 | 108 | /** |
screamer | 2:ab50a2ab6ec9 | 109 | * If re-transmissions are enabled, this function changes resending count and buffer size. |
screamer | 2:ab50a2ab6ec9 | 110 | */ |
terohoo | 0:58c4f13c4b9a | 111 | extern int8_t sn_coap_protocol_set_retransmission(uint8_t resending_count, uint8_t buffer_size); |
terohoo | 0:58c4f13c4b9a | 112 | |
terohoo | 0:58c4f13c4b9a | 113 | /* NSP registration functions */ |
screamer | 2:ab50a2ab6ec9 | 114 | /** |
screamer | 2:ab50a2ab6ec9 | 115 | * Create an NSP registration message. |
screamer | 2:ab50a2ab6ec9 | 116 | */ |
terohoo | 0:58c4f13c4b9a | 117 | extern int8_t sn_coap_register(sn_coap_hdr_s *coap_hdr_ptr, registration_info_t *endpoint_info_ptr); |
screamer | 2:ab50a2ab6ec9 | 118 | |
screamer | 2:ab50a2ab6ec9 | 119 | /** |
screamer | 2:ab50a2ab6ec9 | 120 | * Create an NSP update message. |
screamer | 2:ab50a2ab6ec9 | 121 | */ |
terohoo | 0:58c4f13c4b9a | 122 | extern int8_t sn_coap_register_update(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length); |
screamer | 2:ab50a2ab6ec9 | 123 | |
screamer | 2:ab50a2ab6ec9 | 124 | /** |
screamer | 2:ab50a2ab6ec9 | 125 | * Create an NSP de-registration message. |
screamer | 2:ab50a2ab6ec9 | 126 | */ |
terohoo | 0:58c4f13c4b9a | 127 | extern int8_t sn_coap_deregister(sn_coap_hdr_s *coap_hdr_ptr, uint8_t *location, uint8_t length); |
terohoo | 0:58c4f13c4b9a | 128 | |
terohoo | 0:58c4f13c4b9a | 129 | #endif /* SN_COAP_PROTOCOL_H_ */ |
terohoo | 0:58c4f13c4b9a | 130 | |
terohoo | 0:58c4f13c4b9a | 131 | #ifdef __cplusplus |
terohoo | 0:58c4f13c4b9a | 132 | } |
terohoo | 0:58c4f13c4b9a | 133 | #endif |