Skip to content

Commit bc69b8b

Browse files
author
Tero Heinonen
authored
Disable CoAP duplicate message detection (ARMmbed#69)
* 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
1 parent ccb65f8 commit bc69b8b

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

coap-service/coap_service_api.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
282282
*- 0 For success
283283
*/
284284
extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);
285+
285286
/**
286287
* \brief Set DTLS handshake timeout values
287288
*
@@ -295,6 +296,19 @@ extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);
295296
*- 0 For success
296297
*/
297298
extern int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max);
299+
300+
/**
301+
* \brief Set CoAP duplication message buffer size
302+
*
303+
* Configures the CoAP duplication message buffer size.
304+
*
305+
* \param service_id Id number of the current service.
306+
* \param size Buffer size (messages)
307+
*
308+
* \return -1 For failure
309+
*- 0 For success
310+
*/
311+
extern int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size);
298312
#ifdef __cplusplus
299313
}
300314
#endif

source/coap_message_handler.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
180180
used_free_func_ptr(handle);
181181
return NULL;
182182
}
183+
184+
/* Set default buffer size for CoAP duplicate message detection */
185+
sn_coap_protocol_set_duplicate_buffer_size(handle->coap, DUPLICATE_MESSAGE_BUFFER_SIZE);
186+
183187
return handle;
184188
}
185189

source/coap_service_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "net_interface.h"
2222
#include "coap_service_api_internal.h"
2323
#include "coap_message_handler.h"
24+
#include "mbed-coap/sn_coap_protocol.h"
2425

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

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

512+
int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size)
513+
{
514+
(void) service_id;
515+
516+
if (!coap_service_handle) {
517+
return -1;
518+
}
519+
520+
return sn_coap_protocol_set_duplicate_buffer_size(coap_service_handle->coap, size);
521+
}
522+
511523
uint32_t coap_service_get_internal_timer_ticks(void)
512524
{
513525
return coap_ticks;

source/include/coap_message_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "ns_list.h"
2525

2626
#define TRANSACTION_LIFETIME 180
27+
/* Default value for CoAP duplicate message buffer (0 = disabled) */
28+
#define DUPLICATE_MESSAGE_BUFFER_SIZE 0
2729

2830
/**
2931
* \brief Service message response receive callback.

test/coap-service/unittest/coap_service_api/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ TEST_SRC_FILES = \
1717
../stub/eventOS_event_stub.c \
1818
../stub/coap_connection_handler_stub.c \
1919
../stub/coap_message_handler_stub.c \
20-
../stub/common_functions_stub.c
20+
../stub/common_functions_stub.c \
21+
../stub/sn_coap_protocol_stub.c
2122

2223
include ../MakefileWorker.mk
2324

0 commit comments

Comments
 (0)