From 22e131bc6d8717fe88be56572c0f0fe615c669e5 Mon Sep 17 00:00:00 2001 From: Johan Liseborn Date: Fri, 23 Feb 2018 09:36:35 +0100 Subject: [PATCH 1/2] Remove unused list of periodic services The coap_resource_periodic_services list is no longer used, but it still breaks the the observer functionality, so it should be removed. --- os/net/app-layer/coap/coap-engine.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/os/net/app-layer/coap/coap-engine.c b/os/net/app-layer/coap/coap-engine.c index 1327cb3e6..0db9c2a39 100644 --- a/os/net/app-layer/coap/coap-engine.c +++ b/os/net/app-layer/coap/coap-engine.c @@ -70,7 +70,6 @@ static int invoke_coap_resource_service(coap_message_t *request, /*---------------------------------------------------------------------------*/ LIST(coap_handlers); LIST(coap_resource_services); -LIST(coap_resource_periodic_services); static uint8_t is_initialized = 0; /*---------------------------------------------------------------------------*/ @@ -373,7 +372,6 @@ coap_engine_init(void) list_init(coap_handlers); list_init(coap_resource_services); - list_init(coap_resource_periodic_services); coap_activate_resource(&res_well_known_core, ".well-known/core"); @@ -404,7 +402,6 @@ coap_activate_resource(coap_resource_t *resource, const char *path) && resource->periodic->periodic_handler && resource->periodic->period) { LOG_DBG("Periodic resource: %p (%s)\n", resource->periodic, path); - list_add(coap_resource_periodic_services, resource->periodic); periodic = resource->periodic; coap_timer_set_callback(&periodic->periodic_timer, process_callback); coap_timer_set_user_data(&periodic->periodic_timer, resource); From 9aaba942e1d61a8c5544ae7b509c25dbb6ff159f Mon Sep 17 00:00:00 2001 From: Johan Liseborn Date: Fri, 23 Feb 2018 09:41:30 +0100 Subject: [PATCH 2/2] Handle block-wise transfer in observer notifications --- os/net/app-layer/coap/coap-observe.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/os/net/app-layer/coap/coap-observe.c b/os/net/app-layer/coap/coap-observe.c index ac336fbd8..676c4d1b3 100644 --- a/os/net/app-layer/coap/coap-observe.c +++ b/os/net/app-layer/coap/coap-observe.c @@ -259,16 +259,18 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath) /* prepare response */ notification->mid = transaction->mid; + int32_t new_offset = 0; + /* Either old style get_handler or the full handler */ if(coap_call_handlers(request, notification, transaction->message + COAP_MAX_HEADER_SIZE, COAP_MAX_CHUNK_SIZE, - NULL) > 0) { + &new_offset) > 0) { LOG_DBG("Notification on new handlers\n"); } else { if(resource != NULL) { resource->get_handler(request, notification, transaction->message + COAP_MAX_HEADER_SIZE, - COAP_MAX_CHUNK_SIZE, NULL); + COAP_MAX_CHUNK_SIZE, &new_offset); } else { /* What to do here? */ notification->code = BAD_REQUEST_4_00; @@ -282,6 +284,17 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath) } coap_set_token(notification, obs->token, obs->token_len); + if(new_offset != 0) { + coap_set_header_block2(notification, + 0, + new_offset != -1, + COAP_MAX_BLOCK_SIZE); + coap_set_payload(notification, + notification->payload, + MIN(notification->payload_len, + COAP_MAX_BLOCK_SIZE)); + } + transaction->message_len = coap_serialize_message(notification, transaction->message);