Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Revert "Reset message handling" #18

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions nsdl-c/sn_nsdl_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,15 @@ extern void sn_nsdl_nsp_lost(struct nsdl_s *handle);
* \param *observe_ptr Pointer to observe number to be sent
* \param observe_len Observe number len
* \param message_type Observation message type (confirmable or non-confirmable)
* \param content_type Observation message payload contetnt type
* \param uri_path_ptr Pointer to uri path to bee sent
* \param uri_path_len Uri path len
* \param contetnt_type Observation message payload contetnt type
*
* \return !0 Success, observation messages message ID
* \return 0 Failure
*/
extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
uint8_t *payload_ptr, uint16_t payload_len,
uint8_t *observe_ptr, uint8_t observe_len,
sn_coap_msg_type_e message_type,
uint8_t content_type,
uint8_t *uri_path_ptr,
uint16_t uri_path_len);
sn_coap_msg_type_e message_type, uint8_t content_type);

/**
* \fn extern uint32_t sn_nsdl_get_version(void)
Expand Down
2 changes: 0 additions & 2 deletions source/libCoap/src/include/sn_coap_header_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ typedef struct sn_nsdl_transmit_ {

uint16_t packet_len;
uint8_t *packet_ptr;
uint8_t *uri_path_ptr;
uint8_t uri_path_len;
} sn_nsdl_transmit_s;

/* * * * * * * * * * * * * * * * * * * * * * */
Expand Down
26 changes: 9 additions & 17 deletions source/libCoap/src/sn_coap_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,16 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_ms
}

/* URI PATH - Repeatable option. Length of one option is 0-255 */
/* Do not add uri-path for notification message.
* Uri-path is needed for cancelling observation with RESET message */
if (!src_coap_msg_ptr->options_list_ptr ||
(src_coap_msg_ptr->options_list_ptr && !src_coap_msg_ptr->options_list_ptr->observe_len && !src_coap_msg_ptr->options_list_ptr->observe_ptr)) {
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
if (repeatable_option_size) {
returned_byte_count += repeatable_option_size;
} else {
return 0;
}
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
if (repeatable_option_size) {
returned_byte_count += repeatable_option_size;
} else {
return 0;
}
}

/* CONTENT TYPE - Length of this option is 0-2 bytes */
if (src_coap_msg_ptr->content_type_ptr != NULL) {
returned_byte_count++;
Expand Down Expand Up @@ -614,11 +610,7 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
&src_coap_msg_ptr->options_list_ptr->location_path_len, COAP_OPTION_LOCATION_PATH);
}
/* * * * Build Uri-Path option * * * */
/* Do not add uri-path for notification message.
* Uri-path is needed for cancelling observation with RESET message */
if (!src_coap_msg_ptr->options_list_ptr ||
(src_coap_msg_ptr->options_list_ptr && !src_coap_msg_ptr->options_list_ptr->observe_len && !src_coap_msg_ptr->options_list_ptr->observe_ptr))
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH);

/* * * * Build Content-Type option * * * */
Expand Down
37 changes: 5 additions & 32 deletions source/libCoap/src/sn_coap_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int8_t sn_coap_convert_block_size(uint16_t block_size);
static sn_coap_hdr_s *sn_coap_protocol_copy_header(struct coap_s *handle, sn_coap_hdr_s *source_header_ptr);
#endif
#if ENABLE_RESENDINGS
static void sn_coap_protocol_linked_list_send_msg_store(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t send_packet_data_len, uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param, uint8_t *uri_path_ptr, uint8_t uri_path_len);
static void sn_coap_protocol_linked_list_send_msg_store(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t send_packet_data_len, uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param);
static sn_nsdl_transmit_s *sn_coap_protocol_linked_list_send_msg_search(struct coap_s *handle,sn_nsdl_addr_s *src_addr_ptr, uint16_t msg_id);
static void sn_coap_protocol_linked_list_send_msg_remove(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t msg_id);
static coap_send_msg_s *sn_coap_protocol_allocate_mem_for_msg(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t packet_data_len);
Expand Down Expand Up @@ -311,10 +311,6 @@ void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle)
handle->sn_coap_protocol_free(tmp->send_msg_ptr->packet_ptr);
tmp->send_msg_ptr->packet_ptr = 0;
}
if (tmp->send_msg_ptr->uri_path_ptr) {
handle->sn_coap_protocol_free(tmp->send_msg_ptr->uri_path_ptr);
tmp->send_msg_ptr->uri_path_ptr = 0;
}
handle->sn_coap_protocol_free(tmp->send_msg_ptr);
tmp->send_msg_ptr = 0;
}
Expand Down Expand Up @@ -438,7 +434,7 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p
/* Store message to Linked list for resending purposes */
sn_coap_protocol_linked_list_send_msg_store(handle, dst_addr_ptr, byte_count_built, dst_packet_data_ptr,
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR),
param, src_coap_msg_ptr->uri_path_ptr, src_coap_msg_ptr->uri_path_len);
param);
}

#endif /* ENABLE_RESENDINGS */
Expand Down Expand Up @@ -675,18 +671,10 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
sn_nsdl_transmit_s *removed_msg_ptr = NULL;

/* Check if received message was confirmation for some active resending message */

removed_msg_ptr = sn_coap_protocol_linked_list_send_msg_search(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);

if (removed_msg_ptr != NULL) {
if (returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_RESET) {
if(removed_msg_ptr->uri_path_len) {
returned_dst_coap_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(removed_msg_ptr->uri_path_len);
if (returned_dst_coap_msg_ptr->uri_path_ptr != NULL) {
memcpy(returned_dst_coap_msg_ptr->uri_path_ptr, removed_msg_ptr->uri_path_ptr, removed_msg_ptr->uri_path_len);
returned_dst_coap_msg_ptr->uri_path_len = removed_msg_ptr->uri_path_len;
}
}
}
/* Remove resending message from active message resending Linked list */
sn_coap_protocol_linked_list_send_msg_remove(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);
}
Expand Down Expand Up @@ -789,7 +777,7 @@ int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)
*****************************************************************************/

static void sn_coap_protocol_linked_list_send_msg_store(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t send_packet_data_len,
uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param, uint8_t *uri_path_ptr, uint8_t uri_path_len)
uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param)
{

coap_send_msg_s *stored_msg_ptr = NULL;
Expand Down Expand Up @@ -837,16 +825,6 @@ static void sn_coap_protocol_linked_list_send_msg_store(struct coap_s *handle, s
stored_msg_ptr->coap = handle;
stored_msg_ptr->param = param;

if (uri_path_len) {
stored_msg_ptr->send_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(uri_path_len);
if (stored_msg_ptr->send_msg_ptr->uri_path_ptr == NULL){
return;
}
stored_msg_ptr->send_msg_ptr->uri_path_len = uri_path_len;
memcpy(stored_msg_ptr->send_msg_ptr->uri_path_ptr, uri_path_ptr, uri_path_len);
}


/* Storing Resending message to Linked list */
ns_list_add_to_end(&handle->linked_list_resent_msgs, stored_msg_ptr);
++handle->count_resent_msgs;
Expand Down Expand Up @@ -1423,11 +1401,6 @@ static void sn_coap_protocol_release_allocated_send_msg_mem(struct coap_s *handl
freed_send_msg_ptr->send_msg_ptr->packet_ptr = 0;
}

if (freed_send_msg_ptr->send_msg_ptr->uri_path_ptr != NULL) {
handle->sn_coap_protocol_free(freed_send_msg_ptr->send_msg_ptr->uri_path_ptr);
freed_send_msg_ptr->send_msg_ptr->uri_path_ptr = 0;
}

handle->sn_coap_protocol_free(freed_send_msg_ptr->send_msg_ptr);
freed_send_msg_ptr->send_msg_ptr = 0;
}
Expand Down Expand Up @@ -1943,7 +1916,7 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
sn_coap_protocol_linked_list_send_msg_store(handle, src_addr_ptr,
dst_packed_data_needed_mem,
dst_ack_packet_data_ptr,
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR), param, NULL, 0);
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR), param);
#endif
handle->sn_coap_protocol_free(dst_ack_packet_data_ptr);
dst_ack_packet_data_ptr = 0;
Expand Down
9 changes: 2 additions & 7 deletions source/libNsdl/src/sn_nsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle)
uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
uint8_t *payload_ptr, uint16_t payload_len,
uint8_t *observe_ptr, uint8_t observe_len,
sn_coap_msg_type_e message_type, uint8_t content_type,
uint8_t *uri_path_ptr, uint16_t uri_path_len)
sn_coap_msg_type_e message_type, uint8_t content_type)
{
sn_coap_hdr_s *notification_message_ptr;
uint16_t return_msg_id = 0;
Expand Down Expand Up @@ -541,10 +540,6 @@ uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *t
notification_message_ptr->payload_len = payload_len;
notification_message_ptr->payload_ptr = payload_ptr;

/* Fill uri path */
notification_message_ptr->uri_path_len = uri_path_len;
notification_message_ptr->uri_path_ptr = uri_path_ptr;

/* Fill observe */
notification_message_ptr->options_list_ptr->observe_len = observe_len;
notification_message_ptr->options_list_ptr->observe_ptr = observe_ptr;
Expand All @@ -563,7 +558,7 @@ uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *t
}

/* Free memory */
notification_message_ptr->uri_path_ptr = NULL;

notification_message_ptr->payload_ptr = NULL;
notification_message_ptr->options_list_ptr->observe_ptr = NULL;
notification_message_ptr->token_ptr = NULL;
Expand Down
10 changes: 2 additions & 8 deletions test/nsdl-c/unittest/sn_coap_builder/libCoap_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
header.options_list_ptr->uri_query_len = 0;
CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);

free(header.options_list_ptr->observe_ptr);
header.options_list_ptr->observe_ptr = NULL;
header.options_list_ptr->observe = 1;

header.options_list_ptr->uri_query_len = 4;
Expand All @@ -368,17 +370,9 @@ TEST(libCoap_builder, sn_coap_builder_calc_needed_packet_data_size)
header.options_list_ptr->block1_len = 0;
CHECK(sn_coap_builder_calc_needed_packet_data_size(&header) == 0);

header.options_list_ptr->block1_len = 2;
header.payload_len = 1;
CHECK(431 == sn_coap_builder_calc_needed_packet_data_size(&header));

free(header.options_list_ptr->observe_ptr);
header.options_list_ptr->observe_ptr = NULL;
header.options_list_ptr->observe_len = 0;
header.options_list_ptr->block1_len = 2;
header.payload_len = 1;
CHECK(722 == sn_coap_builder_calc_needed_packet_data_size(&header));

// <--

free(header.options_list_ptr->block1_ptr);
Expand Down
53 changes: 2 additions & 51 deletions test/nsdl-c/unittest/sn_coap_protocol/libCoap_protocol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1957,52 +1957,6 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
sn_coap_parser_release_allocated_coap_msg_mem(handle, ret);

sn_coap_protocol_destroy(handle);

retCounter = 1;
handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL);

sn_coap_parser_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(sn_coap_parser_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
sn_coap_parser_stub.expectedHeader->msg_type = COAP_MSG_TYPE_RESET;
sn_coap_parser_stub.expectedHeader->msg_id = 18;

memset(&tmp_addr, 0, sizeof(sn_nsdl_addr_s));
memset(&tmp_hdr, 0, sizeof(sn_coap_hdr_s));

dst_packet_data_ptr = (uint8_t*)malloc(5);
memset(dst_packet_data_ptr, '1', 5);
dst_packet_data_ptr[2]=0;
dst_packet_data_ptr[3]=18;

tmp_addr.addr_ptr = (uint8_t*)malloc(5);
memset(tmp_addr.addr_ptr, '1', 5);
tmp_addr.port = 0;

retCounter = 21;
sn_coap_builder_stub.expectedInt16 = 5;
tmp_hdr.payload_ptr = (uint8_t*)malloc(3);
tmp_hdr.msg_id = 18;
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
tmp_hdr.payload_len = SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE + 20;
tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7);
snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1");
tmp_hdr.uri_path_len = 7;

sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);

free(tmp_hdr.uri_path_ptr);
free(tmp_hdr.options_list_ptr->block2_ptr);
free(tmp_hdr.options_list_ptr);
free(tmp_hdr.payload_ptr);
free(tmp_addr.addr_ptr);
free(dst_packet_data_ptr);

ret = sn_coap_protocol_parse(handle, addr, packet_data_len, packet_data_ptr, NULL);
CHECK( ret != NULL );
sn_coap_parser_release_allocated_coap_msg_mem(handle, ret);

sn_coap_protocol_destroy(handle);

retCounter = 1;
handle = sn_coap_protocol_init(myMalloc, myFree, null_tx_cb, NULL);

Expand All @@ -2029,9 +1983,6 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
tmp_hdr.msg_id = 18;
tmp_hdr.msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
tmp_hdr.payload_len = SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE + 20;
tmp_hdr.uri_path_ptr = (uint8_t*)malloc(7);
snprintf((char *)tmp_hdr.uri_path_ptr, 7, "13/0/1");
tmp_hdr.uri_path_len = 7;
sn_coap_protocol_build(handle, &tmp_addr, dst_packet_data_ptr, &tmp_hdr, NULL);

free(tmp_hdr.options_list_ptr->block2_ptr);
Expand All @@ -2044,11 +1995,11 @@ TEST(libCoap_protocol, sn_coap_protocol_parse)
CHECK( ret != NULL );
sn_coap_parser_release_allocated_coap_msg_mem(handle, ret);

free(tmp_hdr.uri_path_ptr);

free(packet_data_ptr);
free(addr->addr_ptr);
free(addr);
sn_coap_protocol_destroy(handle);
sn_coap_protocol_destroy(handle);
}

TEST(libCoap_protocol, sn_coap_protocol_exec)
Expand Down
21 changes: 6 additions & 15 deletions test/nsdl-c/unittest/sn_nsdl/test_sn_nsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,46 +693,37 @@ bool test_sn_nsdl_is_ep_registered()

bool test_sn_nsdl_send_observation_notification()
{
if( 0 != sn_nsdl_send_observation_notification(NULL, NULL, 0,NULL,0,NULL,0,0,0, NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(NULL, NULL, 0,NULL,0,NULL,0,0,0) ){
return false;
}
sn_grs_stub.retNull = false;
retCounter = 4;
sn_grs_stub.expectedGrs = (struct grs_s *)malloc(sizeof(struct grs_s));
struct nsdl_s* handle = sn_nsdl_init(&nsdl_tx_callback, &nsdl_rx_callback, &myMalloc, &myFree);

if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,0,NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,0) ){
return false;
}

retCounter = 1;
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,0,NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,0) ){
return false;
}

retCounter = 2;
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1,NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1) ){
return false;
}

retCounter = 2;
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1,NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1) ){
return false;
}

u_int8_t path[] = {"13/0/1"};
uint8_t* uri_path_ptr = (uint8_t*)malloc(sizeof(path));
uint8_t uri_path_len = (uint8_t)sizeof(path);
retCounter = 2;
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1,uri_path_ptr,uri_path_len) ){
return false;
}
free(uri_path_ptr);

retCounter = 2;
sn_grs_stub.int8SuccessCounter = 0;
sn_grs_stub.expectedInt8 = SN_NSDL_FAILURE;
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1,NULL,0) ){
if( 0 != sn_nsdl_send_observation_notification(handle, NULL, 0,NULL,0,NULL,0,0,1) ){
return false;
}

Expand Down
9 changes: 3 additions & 6 deletions test/nsdl-c/unittest/stubs/sn_nsdl_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle)
}

uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
uint8_t *payload_ptr, uint16_t payload_len,
uint8_t *observe_ptr, uint8_t observe_len,
sn_coap_msg_type_e message_type,
uint8_t content_type,
uint8_t *uri_path_ptr,
uint16_t uri_path_len)
uint8_t *payload_ptr, uint16_t payload_len,
uint8_t *observe_ptr, uint8_t observe_len,
sn_coap_msg_type_e message_type, uint8_t content_type)
{
return sn_nsdl_stub.expectedUint16;
}
Expand Down