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

Commit 91af549

Browse files
author
Antti Yli-Tokola
committed
Revert 3b172c6 Notify client when observation is cancelled with RESET message
Reset message is now passed into application and mbed-client will use the token to match request to right object. With this change we get rid of unnecessary uri_path() API in mbed-client side.
1 parent fd987a9 commit 91af549

File tree

5 files changed

+21
-116
lines changed

5 files changed

+21
-116
lines changed

nsdl-c/sn_nsdl_lib.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -311,39 +311,6 @@ extern uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uin
311311
sn_coap_msg_type_e message_type,
312312
sn_coap_content_format_e content_format);
313313

314-
/**
315-
* \fn extern uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
316-
* uint8_t *payload_ptr, uint16_t payload_len,
317-
* sn_coap_observe_e observe,
318-
* sn_coap_msg_type_e message_type, uint8_t content_type,
319-
* uint8_t *uri_path_ptr,
320-
* uint16_t uri_path_len)
321-
*
322-
*
323-
* \brief Sends observation message to mbed Device Server with uri path
324-
*
325-
* \param *handle Pointer to nsdl-library handle
326-
* \param *token_ptr Pointer to token to be used
327-
* \param token_len Token length
328-
* \param *payload_ptr Pointer to payload to be sent
329-
* \param payload_len Payload length
330-
* \param observe Observe option value to be sent
331-
* \param message_type Observation message type (confirmable or non-confirmable)
332-
* \param content_type Observation message payload contetnt type
333-
* \param uri_path_ptr Pointer to uri path to be sent
334-
* \param uri_path_len Uri path len
335-
*
336-
* \return !0 Success, observation messages message ID
337-
* \return 0 Failure
338-
*/
339-
extern uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
340-
uint8_t *payload_ptr, uint16_t payload_len,
341-
sn_coap_observe_e observe,
342-
sn_coap_msg_type_e message_type,
343-
uint8_t content_type,
344-
uint8_t *uri_path_ptr,
345-
uint16_t uri_path_len);
346-
347314
/**
348315
* \fn extern uint32_t sn_nsdl_get_version(void)
349316
*

source/libCoap/src/include/sn_coap_header_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ typedef struct sn_nsdl_transmit_ {
6464

6565
uint16_t packet_len;
6666
uint8_t *packet_ptr;
67-
uint8_t *uri_path_ptr;
68-
uint8_t uri_path_len;
6967
} sn_nsdl_transmit_s;
7068

7169
/* * * * * * * * * * * * * * * * * * * * * * */

source/libCoap/src/sn_coap_builder.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,16 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
175175
returned_byte_count += src_coap_msg_ptr->token_len;
176176
}
177177
/* URI PATH - Repeatable option. Length of one option is 0-255 */
178-
/* Do not add uri-path for notification message.
179-
* Uri-path is needed for cancelling observation with RESET message */
180-
if (!src_coap_msg_ptr->options_list_ptr ||
181-
(src_coap_msg_ptr->options_list_ptr &&
182-
COAP_OBSERVE_NONE == src_coap_msg_ptr->options_list_ptr->observe)) {
183-
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
184-
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
185-
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
186-
if (repeatable_option_size) {
187-
returned_byte_count += repeatable_option_size;
188-
} else {
189-
return 0;
190-
}
178+
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
179+
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
180+
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
181+
if (repeatable_option_size) {
182+
returned_byte_count += repeatable_option_size;
183+
} else {
184+
return 0;
191185
}
192186
}
187+
193188
uint16_t tempInt = 0;
194189
/* CONTENT FORMAT - An integer option, up to 2 bytes */
195190
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {
@@ -575,13 +570,8 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
575570
&src_coap_msg_ptr->options_list_ptr->location_path_len, COAP_OPTION_LOCATION_PATH, &previous_option_number);
576571
}
577572
/* * * * Build Uri-Path option * * * */
578-
/* Do not add uri-path for notification message.
579-
* Uri-path is needed for cancelling observation with RESET message */
580-
if (!src_coap_msg_ptr->options_list_ptr ||
581-
(src_coap_msg_ptr->options_list_ptr &&
582-
COAP_OBSERVE_NONE == src_coap_msg_ptr->options_list_ptr->observe))
583-
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
584-
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);
573+
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
574+
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);
585575

586576
/* * * * Build Content-Type option * * * */
587577
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {

source/libCoap/src/sn_coap_protocol.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int8_t sn_coap_convert_block_size(uint16_t block_size);
6868
static sn_coap_hdr_s *sn_coap_protocol_copy_header(struct coap_s *handle, sn_coap_hdr_s *source_header_ptr);
6969
#endif
7070
#if ENABLE_RESENDINGS
71-
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);
71+
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);
7272
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);
7373
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);
7474
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);
@@ -314,10 +314,6 @@ void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle)
314314
handle->sn_coap_protocol_free(tmp->send_msg_ptr->packet_ptr);
315315
tmp->send_msg_ptr->packet_ptr = 0;
316316
}
317-
if (tmp->send_msg_ptr->uri_path_ptr) {
318-
handle->sn_coap_protocol_free(tmp->send_msg_ptr->uri_path_ptr);
319-
tmp->send_msg_ptr->uri_path_ptr = 0;
320-
}
321317
handle->sn_coap_protocol_free(tmp->send_msg_ptr);
322318
tmp->send_msg_ptr = 0;
323319
}
@@ -448,7 +444,7 @@ int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_p
448444
/* Store message to Linked list for resending purposes */
449445
sn_coap_protocol_linked_list_send_msg_store(handle, dst_addr_ptr, byte_count_built, dst_packet_data_ptr,
450446
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR),
451-
param, src_coap_msg_ptr->uri_path_ptr, src_coap_msg_ptr->uri_path_len);
447+
param);
452448
}
453449

454450
#endif /* ENABLE_RESENDINGS */
@@ -703,15 +699,6 @@ sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src
703699
removed_msg_ptr = sn_coap_protocol_linked_list_send_msg_search(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);
704700

705701
if (removed_msg_ptr != NULL) {
706-
if (returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_RESET) {
707-
if(removed_msg_ptr->uri_path_len) {
708-
returned_dst_coap_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(removed_msg_ptr->uri_path_len);
709-
if (returned_dst_coap_msg_ptr->uri_path_ptr != NULL) {
710-
memcpy(returned_dst_coap_msg_ptr->uri_path_ptr, removed_msg_ptr->uri_path_ptr, removed_msg_ptr->uri_path_len);
711-
returned_dst_coap_msg_ptr->uri_path_len = removed_msg_ptr->uri_path_len;
712-
}
713-
}
714-
}
715702
/* Remove resending message from active message resending Linked list */
716703
sn_coap_protocol_linked_list_send_msg_remove(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id);
717704
}
@@ -814,7 +801,7 @@ int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time)
814801
*****************************************************************************/
815802

816803
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,
817-
uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param, uint8_t *uri_path_ptr, uint8_t uri_path_len)
804+
uint8_t *send_packet_data_ptr, uint32_t sending_time, void *param)
818805
{
819806

820807
coap_send_msg_s *stored_msg_ptr = NULL;
@@ -862,16 +849,6 @@ static void sn_coap_protocol_linked_list_send_msg_store(struct coap_s *handle, s
862849
stored_msg_ptr->coap = handle;
863850
stored_msg_ptr->param = param;
864851

865-
if (uri_path_len) {
866-
stored_msg_ptr->send_msg_ptr->uri_path_ptr = handle->sn_coap_protocol_malloc(uri_path_len);
867-
if (stored_msg_ptr->send_msg_ptr->uri_path_ptr == NULL){
868-
return;
869-
}
870-
stored_msg_ptr->send_msg_ptr->uri_path_len = uri_path_len;
871-
memcpy(stored_msg_ptr->send_msg_ptr->uri_path_ptr, uri_path_ptr, uri_path_len);
872-
}
873-
874-
875852
/* Storing Resending message to Linked list */
876853
ns_list_add_to_end(&handle->linked_list_resent_msgs, stored_msg_ptr);
877854
++handle->count_resent_msgs;
@@ -1448,11 +1425,6 @@ static void sn_coap_protocol_release_allocated_send_msg_mem(struct coap_s *handl
14481425
freed_send_msg_ptr->send_msg_ptr->packet_ptr = 0;
14491426
}
14501427

1451-
if (freed_send_msg_ptr->send_msg_ptr->uri_path_ptr != NULL) {
1452-
handle->sn_coap_protocol_free(freed_send_msg_ptr->send_msg_ptr->uri_path_ptr);
1453-
freed_send_msg_ptr->send_msg_ptr->uri_path_ptr = 0;
1454-
}
1455-
14561428
handle->sn_coap_protocol_free(freed_send_msg_ptr->send_msg_ptr);
14571429
freed_send_msg_ptr->send_msg_ptr = 0;
14581430
}
@@ -1878,7 +1850,7 @@ static sn_coap_hdr_s *sn_coap_handle_blockwise_message(struct coap_s *handle, sn
18781850
sn_coap_protocol_linked_list_send_msg_store(handle, src_addr_ptr,
18791851
dst_packed_data_needed_mem,
18801852
dst_ack_packet_data_ptr,
1881-
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR), param, NULL, 0);
1853+
handle->system_time + (uint32_t)(handle->sn_coap_resending_intervall * RESPONSE_RANDOM_FACTOR), param);
18821854
#endif
18831855
handle->sn_coap_protocol_free(dst_ack_packet_data_ptr);
18841856
dst_ack_packet_data_ptr = 0;

source/libNsdl/src/sn_nsdl.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -507,27 +507,8 @@ int8_t sn_nsdl_is_ep_registered(struct nsdl_s *handle)
507507
}
508508

509509
uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
510-
uint8_t *payload_ptr, uint16_t payload_len,
511-
sn_coap_observe_e observe,
512-
sn_coap_msg_type_e message_type, sn_coap_content_format_e content_format)
513-
{
514-
return sn_nsdl_send_observation_notification_with_uri_path(handle,
515-
token_ptr,
516-
token_len,
517-
payload_ptr,
518-
payload_len,
519-
observe,
520-
message_type,
521-
content_format,
522-
NULL,
523-
0);
524-
}
525-
526-
uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *handle, uint8_t *token_ptr, uint8_t token_len,
527-
uint8_t *payload_ptr, uint16_t payload_len,
528-
sn_coap_observe_e observe,
529-
sn_coap_msg_type_e message_type, uint8_t content_format,
530-
uint8_t *uri_path_ptr, uint16_t uri_path_len)
510+
uint8_t *payload_ptr, uint16_t payload_len, sn_coap_observe_e observe, sn_coap_msg_type_e message_type,
511+
sn_coap_content_format_e content_format)
531512
{
532513
sn_coap_hdr_s *notification_message_ptr;
533514
uint16_t return_msg_id = 0;
@@ -560,10 +541,6 @@ uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *hand
560541
notification_message_ptr->payload_len = payload_len;
561542
notification_message_ptr->payload_ptr = payload_ptr;
562543

563-
/* Fill uri path */
564-
notification_message_ptr->uri_path_len = uri_path_len;
565-
notification_message_ptr->uri_path_ptr = uri_path_ptr;
566-
567544
/* Fill observe */
568545
notification_message_ptr->options_list_ptr->observe = observe;
569546

@@ -578,7 +555,6 @@ uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *hand
578555
}
579556

580557
/* Free memory */
581-
notification_message_ptr->uri_path_ptr = NULL;
582558
notification_message_ptr->payload_ptr = NULL;
583559
notification_message_ptr->token_ptr = NULL;
584560

@@ -730,9 +706,12 @@ int8_t sn_nsdl_process_coap(struct nsdl_s *handle, uint8_t *packet_ptr, uint16_t
730706
/* * * * * * * * * * * * * * * * * * * * * * * * * * */
731707
/* If message is response message, call RX callback */
732708
/* * * * * * * * * * * * * * * * * * * * * * * * * * */
733-
if ((coap_packet_ptr->msg_code > COAP_MSG_CODE_REQUEST_DELETE) || (coap_packet_ptr->msg_type == COAP_MSG_TYPE_ACKNOWLEDGEMENT)) {
709+
710+
if ((coap_packet_ptr->msg_code > COAP_MSG_CODE_REQUEST_DELETE) ||
711+
(coap_packet_ptr->msg_type >= COAP_MSG_TYPE_ACKNOWLEDGEMENT)) {
734712
int8_t retval = sn_nsdl_local_rx_function(handle, coap_packet_ptr, src_ptr);
735-
if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED && coap_packet_ptr->payload_ptr) {
713+
if (coap_packet_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED &&
714+
coap_packet_ptr->payload_ptr) {
736715
handle->sn_nsdl_free(coap_packet_ptr->payload_ptr);
737716
coap_packet_ptr->payload_ptr = 0;
738717
}
@@ -1026,7 +1005,6 @@ static uint16_t sn_nsdl_calculate_registration_body_size(struct nsdl_s *handle,
10261005
resource_temp_ptr = sn_grs_get_next_resource(handle->grs, resource_temp_ptr);
10271006
continue;
10281007
}
1029-
10301008
/* If not first resource, then '.' will be added */
10311009
if (return_value) {
10321010
if (sn_nsdl_check_uint_overflow(return_value, 1, 0)) {

0 commit comments

Comments
 (0)