Skip to content

Commit

Permalink
Disable CoAP duplicate message detection (ARMmbed#69)
Browse files Browse the repository at this point in the history
* Disable CoAP duplicate message detection

To save some memory, CoAP duplicate message detection is disabled by
default.

* Added API to set duplicate message buffer size

Added API to set duplicate message buffer size. Default value is '0'

* Review changes

Review changes:
- Fixed unittests
- Improved comments
  • Loading branch information
Tero Heinonen committed Jun 6, 2017
1 parent ccb65f8 commit bc69b8b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions coap-service/coap_service_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
*- 0 For success
*/
extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);

/**
* \brief Set DTLS handshake timeout values
*
Expand All @@ -295,6 +296,19 @@ extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);
*- 0 For success
*/
extern int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max);

/**
* \brief Set CoAP duplication message buffer size
*
* Configures the CoAP duplication message buffer size.
*
* \param service_id Id number of the current service.
* \param size Buffer size (messages)
*
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size);
#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions source/coap_message_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
used_free_func_ptr(handle);
return NULL;
}

/* Set default buffer size for CoAP duplicate message detection */
sn_coap_protocol_set_duplicate_buffer_size(handle->coap, DUPLICATE_MESSAGE_BUFFER_SIZE);

return handle;
}

Expand Down
12 changes: 12 additions & 0 deletions source/coap_service_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "net_interface.h"
#include "coap_service_api_internal.h"
#include "coap_message_handler.h"
#include "mbed-coap/sn_coap_protocol.h"

static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr);

Expand Down Expand Up @@ -508,6 +509,17 @@ int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint3
return coap_connection_handler_set_timeout(this->conn_handler, min, max);
}

int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size)
{
(void) service_id;

if (!coap_service_handle) {
return -1;
}

return sn_coap_protocol_set_duplicate_buffer_size(coap_service_handle->coap, size);
}

uint32_t coap_service_get_internal_timer_ticks(void)
{
return coap_ticks;
Expand Down
2 changes: 2 additions & 0 deletions source/include/coap_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "ns_list.h"

#define TRANSACTION_LIFETIME 180
/* Default value for CoAP duplicate message buffer (0 = disabled) */
#define DUPLICATE_MESSAGE_BUFFER_SIZE 0

/**
* \brief Service message response receive callback.
Expand Down
3 changes: 2 additions & 1 deletion test/coap-service/unittest/coap_service_api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TEST_SRC_FILES = \
../stub/eventOS_event_stub.c \
../stub/coap_connection_handler_stub.c \
../stub/coap_message_handler_stub.c \
../stub/common_functions_stub.c
../stub/common_functions_stub.c \
../stub/sn_coap_protocol_stub.c

include ../MakefileWorker.mk

Expand Down

0 comments on commit bc69b8b

Please sign in to comment.