libcoap 4.3.5-develop-5347a62
Loading...
Searching...
No Matches
coap_resource.c
Go to the documentation of this file.
1/* coap_resource.c -- generic resource handling
2 *
3 * Copyright (C) 2010--2026 Olaf Bergmann <bergmann@tzi.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
15
17
18#if COAP_SERVER_SUPPORT
19#include <stdio.h>
20
21#ifdef COAP_EPOLL_SUPPORT
22#include <sys/epoll.h>
23#include <sys/timerfd.h>
24#endif /* COAP_EPOLL_SUPPORT */
25
26#ifndef min
27#define min(a,b) ((a) < (b) ? (a) : (b))
28#endif
29
30/* Helper functions for conditional output of character sequences into
31 * a given buffer. The first Offset characters are skipped.
32 */
33
38#define PRINT_WITH_OFFSET(Buf,Offset,Char) \
39 if ((Offset) == 0) { \
40 (*(Buf)++) = (Char); \
41 } else { \
42 (Offset)--; \
43 } \
44
48#define PRINT_COND_WITH_OFFSET(Buf,Bufend,Offset,Char,Result) { \
49 if ((Buf) < (Bufend)) { \
50 PRINT_WITH_OFFSET(Buf,Offset,Char); \
51 } \
52 (Result)++; \
53 }
54
60#define COPY_COND_WITH_OFFSET(Buf,Bufend,Offset,Str,Length,Result) { \
61 size_t i; \
62 for (i = 0; i < (Length); i++) { \
63 PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
64 } \
65 }
66
67#ifndef WITHOUT_QUERY_FILTER
68static int
69match(const coap_str_const_t *text, const coap_str_const_t *pattern,
70 int match_prefix) {
71 const uint8_t *next_token = text->s;
72 size_t remaining_length = text->length;
73 assert(text);
74 assert(pattern);
75
76 if (text->length < pattern->length || !pattern->s)
77 return 0;
78
79 while (remaining_length) {
80 size_t token_length;
81 const uint8_t *token = next_token;
82 next_token = (const unsigned char *)memchr(token, ' ', remaining_length);
83
84 if (next_token) {
85 token_length = next_token - token;
86 remaining_length -= (token_length + 1);
87 next_token++;
88 } else {
89 token_length = remaining_length;
90 remaining_length = 0;
91 }
92
93 if (token_length >= pattern->length &&
94 (match_prefix || pattern->length == token_length) &&
95 memcmp(token, pattern->s, pattern->length) == 0)
96 return 1;
97 }
98 return 0;
99}
100#endif /* WITHOUT_QUERY_FILTER */
101
103coap_print_wellknown(coap_context_t *context, unsigned char *buf,
104 size_t *buflen, size_t offset,
105 const coap_string_t *query_filter) {
106 coap_print_status_t result;
108 result = coap_print_wellknown_lkd(context, buf, buflen, offset, query_filter);
110 return result;
111}
112
113static coap_str_const_t coap_default_uri_wellknown = {
115 (const uint8_t *)COAP_DEFAULT_URI_WELLKNOWN
116};
117
119coap_print_wellknown_lkd(coap_context_t *context, unsigned char *buf,
120 size_t *buflen, size_t offset,
121 const coap_string_t *query_filterm) {
122 coap_print_status_t output_length = 0;
123 unsigned char *p = buf;
124 const uint8_t *bufend = buf + *buflen;
125 size_t left, written = 0;
126 coap_print_status_t result;
127 const size_t old_offset = offset;
128 int subsequent_resource = 0;
129#ifdef WITHOUT_QUERY_FILTER
130 (void)query_filterm;
131#endif /* WITHOUT_QUERY_FILTER */
132
134#ifndef WITHOUT_QUERY_FILTER
135 /* split query filter, if any */
136 if (query_filterm) {
137 unsigned char *next_query = (unsigned char *)memchr(query_filterm->s, '&', query_filterm->length);
138 size_t query_filterm_rem;
139 coap_string_t query_filter;
140
141 /* There could be multiple queries */
142 query_filter.s = query_filterm->s;
143 if (next_query) {
144 query_filter.length = next_query - query_filter.s;
145 next_query++;
146 query_filterm_rem = query_filterm->length - query_filter.length - 1;
147 } else {
148 query_filter.length = query_filterm->length;
149 query_filterm_rem = 0;
150 }
151
152 while (query_filter.length) {
153 coap_str_const_t resource_param = { 0, NULL }, query_pattern = { 0, NULL };
154 /*
155 * If query starts with href=, then MATCH_URI is set in flags.
156 * If query value contains a '*', then MATCH_PREFIX is set in flags to
157 * match up to the *.
158 */
159 int flags = 0; /* MATCH_PREFIX, MATCH_URI */
160#define MATCH_URI 0x01
161#define MATCH_PREFIX 0x02
162
163 resource_param.s = query_filter.s;
164 while (resource_param.length < query_filter.length &&
165 resource_param.s[resource_param.length] != '=')
166 resource_param.length++;
167
168 if (resource_param.length < query_filter.length) {
169 if (resource_param.length == 4 &&
170 memcmp(resource_param.s, "href", 4) == 0)
171 flags |= MATCH_URI;
172
173 /* rest is query-pattern (resource may have multiple values to match */
174 query_pattern.s =
175 query_filter.s + resource_param.length + 1;
176
177 assert((resource_param.length + 1) <= query_filter.length);
178 query_pattern.length =
179 query_filter.length - (resource_param.length + 1);
180
181 if (query_pattern.length &&
182 (query_pattern.s[0] == '/') && ((flags & MATCH_URI) == MATCH_URI)) {
183 query_pattern.s++;
184 query_pattern.length--;
185 }
186
187 if (query_pattern.length &&
188 query_pattern.s[query_pattern.length-1] == '*') {
189 query_pattern.length--;
190 flags |= MATCH_PREFIX;
191 }
192 }
193
194 RESOURCES_ITER(context->resources, r) {
195
196 if (coap_string_equal(r->uri_path, &coap_default_uri_wellknown)) {
197 /* server app has defined a resource for .well-known/core - ignore */
198 continue;
199 }
200 if (r->flags & COAP_RESOURCE_HIDE_WELLKNOWN_CORE) {
201 continue;
202 }
203 if (resource_param.length) { /* there is a query filter */
204
205 if ((flags & MATCH_PREFIX) && query_pattern.length == 0) {
206 int present = (flags & MATCH_URI) ||
207 (r->observable && resource_param.length == 3 &&
208 memcmp(resource_param.s, "obs", 3) == 0) ||
209#if COAP_OSCORE_SUPPORT
210 ((r->flags & COAP_RESOURCE_FLAGS_OSCORE_ONLY) &&
211 resource_param.length == 3 && memcmp(resource_param.s, "osc", 3) == 0) ||
212#if COAP_OSCORE_GROUP_SUPPORT
213 ((r->flags & COAP_RESOURCE_FLAGS_OSCORE_ONLY) &&
214 resource_param.length == 4 && memcmp(resource_param.s, "gosc", 4) == 0) ||
215#endif /* COAP_OSCORE_GROUP_SUPPORT */
216#endif /* COAP_OSCORE_SUPPORT */
217 coap_find_attr(r, &resource_param);
218 if (!present)
219 continue;
220 } else if (flags & MATCH_URI) { /* match resource URI */
221 if (!match(r->uri_path, &query_pattern, (flags & MATCH_PREFIX) != 0))
222 continue;
223 } else { /* match attribute */
224 coap_attr_t *attr;
225 coap_str_const_t unquoted_val;
226 attr = coap_find_attr(r, &resource_param);
227 if (!attr || !attr->value)
228 continue;
229 unquoted_val = *attr->value;
230 /* if attribute has a quoted value, remove double quotes */
231 if (attr->value->length >= 2 && attr->value->s[0] == '"') {
232 unquoted_val.length -= 2;
233 unquoted_val.s += 1;
234 }
235 if (!match(&unquoted_val, &query_pattern, (flags & MATCH_PREFIX) != 0))
236 continue;
237 }
238 }
239
240 if (!subsequent_resource) { /* this is the first resource */
241 subsequent_resource = 1;
242 } else {
243 PRINT_COND_WITH_OFFSET(p, bufend, offset, ',', written);
244 }
245
246 left = bufend - p; /* calculate available space */
247 result = coap_print_link(r, p, &left, &offset);
248
249 if (result & COAP_PRINT_STATUS_ERROR) {
250 break;
251 }
252
253 /* coap_print_link() returns the number of characters that
254 * where actually written to p. Now advance to its end. */
255 p += COAP_PRINT_OUTPUT_LENGTH(result);
256 written += left;
257 }
258 query_filter.s = next_query;
259 if (next_query) {
260 next_query = (unsigned char *)memchr(next_query, '&', query_filterm_rem);
261 if (next_query) {
262 query_filter.length = next_query - query_filter.s;
263 next_query++;
264 query_filterm_rem = query_filterm_rem - query_filter.length - 1;
265 } else {
266 query_filter.length = query_filterm_rem;
267 query_filterm_rem = 0;
268 }
269 } else {
270 query_filter.length = query_filterm_rem;
271 query_filterm_rem = 0;
272 }
273 }
274 } else {
275#endif /* WITHOUT_QUERY_FILTER */
276 RESOURCES_ITER(context->resources, r) {
277
278 if (coap_string_equal(r->uri_path, &coap_default_uri_wellknown)) {
279 /* server app has defined a resource for .well-known/core - ignore */
280 continue;
281 }
282 if (r->flags & COAP_RESOURCE_HIDE_WELLKNOWN_CORE) {
283 continue;
284 }
285
286 if (!subsequent_resource) { /* this is the first resource */
287 subsequent_resource = 1;
288 } else {
289 PRINT_COND_WITH_OFFSET(p, bufend, offset, ',', written);
290 }
291
292 left = bufend - p; /* calculate available space */
293 result = coap_print_link(r, p, &left, &offset);
294
295 if (result & COAP_PRINT_STATUS_ERROR) {
296 break;
297 }
298
299 /* coap_print_link() returns the number of characters that
300 * where actually written to p. Now advance to its end. */
301 p += COAP_PRINT_OUTPUT_LENGTH(result);
302 written += left;
303 }
304#ifndef WITHOUT_QUERY_FILTER
305 }
306#endif /* WITHOUT_QUERY_FILTER */
307
308 *buflen = written;
309 output_length = (coap_print_status_t)(p - buf);
310
311 if (output_length > COAP_PRINT_STATUS_MAX) {
313 }
314
315 result = (coap_print_status_t)output_length;
316
317 if (result + old_offset - offset < *buflen) {
318 result |= COAP_PRINT_STATUS_TRUNC;
319 }
320 return result;
321}
322
323static coap_str_const_t null_path_value = {0, (const uint8_t *)""};
324static coap_str_const_t *null_path = &null_path_value;
325
327coap_resource_init(coap_str_const_t *uri_path, int flags) {
329
331 if (r) {
332 memset(r, 0, sizeof(coap_resource_t));
333#if COAP_THREAD_SAFE
334 coap_lock_init(&r->lock);
335#endif /* COAP_THREAD_SAFE */
336
337 if (!(flags & COAP_RESOURCE_FLAGS_RELEASE_URI)) {
338 /* Need to take a copy if caller is not providing a release request */
339 if (uri_path)
340 uri_path = coap_new_str_const(uri_path->s, uri_path->length);
341 else
342 uri_path = coap_new_str_const(null_path->s, null_path->length);
343 } else if (!uri_path) {
344 /* Do not expect this, but ... */
345 uri_path = coap_new_str_const(null_path->s, null_path->length);
346 }
347
348 if (uri_path)
349 r->uri_path = uri_path;
350
351 r->flags = flags;
352 r->observe = 2;
353 } else {
354 coap_log_debug("coap_resource_init: no memory left\n");
355 }
356
357 return r;
358}
359
360static const uint8_t coap_unknown_resource_uri[] =
361 "- Unknown -";
362
366
368 if (r) {
369 memset(r, 0, sizeof(coap_resource_t));
370#if COAP_THREAD_SAFE
371 coap_lock_init(&r->lock);
372#endif /* COAP_THREAD_SAFE */
373 r->is_unknown = 1;
374 /* Something unlikely to be used, but it shows up in the logs */
375 r->uri_path = coap_new_str_const(coap_unknown_resource_uri, sizeof(coap_unknown_resource_uri)-1);
376 r->flags = flags & ~COAP_RESOURCE_FLAGS_RELEASE_URI;
378 } else {
379 coap_log_debug("coap_resource_unknown_init2: no memory left\n");
380 }
381
382 return r;
383}
384
387 return coap_resource_unknown_init2(put_handler, 0);
388}
389
390static const uint8_t coap_proxy_resource_uri[] =
391 "- Proxy URI -";
392
395 size_t host_name_count,
396 const char *host_name_list[], int flags) {
398
400 if (r) {
401 size_t i;
402 memset(r, 0, sizeof(coap_resource_t));
403#if COAP_THREAD_SAFE
404 coap_lock_init(&r->lock);
405#endif /* COAP_THREAD_SAFE */
406 r->is_proxy_uri = 1;
407 /* Something unlikely to be used, but it shows up in the logs */
408 r->uri_path = coap_new_str_const(coap_proxy_resource_uri, sizeof(coap_proxy_resource_uri)-1);
409 /* Preset all the handlers */
410 for (i = 0; i < (sizeof(r->handler) / sizeof(r->handler[0])); i++) {
411 r->handler[i] = handler;
412 }
413 if (host_name_count) {
414 r->proxy_name_list = coap_malloc_type(COAP_STRING, host_name_count *
415 sizeof(coap_str_const_t *));
416 if (r->proxy_name_list) {
417 for (i = 0; i < host_name_count; i++) {
418 r->proxy_name_list[i] =
419 coap_new_str_const((const uint8_t *)host_name_list[i],
420 strlen(host_name_list[i]));
421 if (!r->proxy_name_list[i]) {
422 coap_log_err("coap_resource_proxy_uri_init: unable to add host name\n");
423 if (i == 0) {
424 coap_free_type(COAP_STRING, r->proxy_name_list);
425 r->proxy_name_list = NULL;
426 }
427 break;
428 }
429 }
430 r->proxy_name_count = i;
431 }
432 }
433 r->flags = flags & ~COAP_RESOURCE_FLAGS_RELEASE_URI;
434 } else {
435 coap_log_debug("coap_resource_proxy_uri_init2: no memory left\n");
436 }
437
438 return r;
439}
440
443 size_t host_name_count, const char *host_name_list[]) {
444 return coap_resource_proxy_uri_init2(handler, host_name_count,
445 host_name_list, 0);
446}
447
448static const uint8_t coap_rev_proxy_resource_uri[] =
449 "- Rev Proxy -";
450
454
456 if (r) {
457 memset(r, 0, sizeof(coap_resource_t));
458#if COAP_THREAD_SAFE
459 coap_lock_init(&r->lock);
460#endif /* COAP_THREAD_SAFE */
461 r->is_unknown = 1;
462 r->is_reverse_proxy = 1;
463 /* Something unlikely to be used, but it shows up in the logs */
464 r->uri_path = coap_new_str_const(coap_rev_proxy_resource_uri,
465 sizeof(coap_rev_proxy_resource_uri)-1);
466 r->flags = flags & ~COAP_RESOURCE_FLAGS_RELEASE_URI;
475 } else {
476 coap_log_debug("coap_resource_rev_proxy_init: no memory left\n");
477 }
478
479 return r;
480}
481
484 coap_str_const_t *name,
485 coap_str_const_t *val,
486 int flags) {
487 coap_attr_t *attr;
488
489 if (!resource || !name)
490 return NULL;
492
493 if (attr) {
494 if (!(flags & COAP_ATTR_FLAGS_RELEASE_NAME)) {
495 /* Need to take a copy if caller is not providing a release request */
496 name = coap_new_str_const(name->s, name->length);
497 }
498 attr->name = name;
499 if (val) {
500 if (!(flags & COAP_ATTR_FLAGS_RELEASE_VALUE)) {
501 /* Need to take a copy if caller is not providing a release request */
502 val = coap_new_str_const(val->s, val->length);
503 }
504 }
505 attr->value = val;
506
507 attr->flags = flags;
508
509 /* add attribute to resource list */
510 LL_PREPEND(resource->link_attr, attr);
511 } else {
512 coap_log_debug("coap_add_attr: no memory left\n");
513 }
514
515 return attr;
516}
517
520 coap_str_const_t *name) {
521 coap_attr_t *attr;
522
523 if (!resource || !name)
524 return NULL;
525
526 LL_FOREACH(resource->link_attr, attr) {
527 if (attr->name->length == name->length &&
528 memcmp(attr->name->s, name->s, name->length) == 0)
529 return attr;
530 }
531
532 return NULL;
533}
534
537 if (attr)
538 return attr->value;
539 return NULL;
540}
541
542void
543coap_delete_attr(coap_attr_t *attr) {
544 if (!attr)
545 return;
546 coap_delete_str_const(attr->name);
547 if (attr->value) {
548 coap_delete_str_const(attr->value);
549 }
550
552}
553
554static void coap_notify_observers(coap_context_t *context, coap_resource_t *r,
555 coap_deleting_resource_t deleting);
556
557static void
558coap_free_resource(coap_resource_t *resource, coap_deleting_resource_t deleting) {
559 coap_attr_t *attr, *tmp;
560 coap_subscription_t *obs, *otmp;
561 coap_context_t *context;
562
563 assert(resource);
564
565 context = resource->context;
566 if (context) {
567 if (!context->observe_no_clear) {
568 coap_resource_notify_observers_lkd(resource, deleting);
569 coap_notify_observers(context, resource, deleting);
570 }
571
572 if (context->resource_deleted_cb)
573 coap_lock_callback(context->resource_deleted_cb(context,
574 resource->uri_path,
575 context->observe_user_data));
576
577 if (context->release_userdata_cb && resource->user_data) {
578 coap_lock_callback(context->release_userdata_cb(resource->user_data));
579 }
580 }
581
582 /* delete registered attributes */
583 LL_FOREACH_SAFE(resource->link_attr, attr, tmp) coap_delete_attr(attr);
584
585 /* Either the application provided or libcoap copied - need to delete it */
586 coap_delete_str_const(resource->uri_path);
587
588 /* free all elements from resource->subscribers */
589 LL_FOREACH_SAFE(resource->subscribers, obs, otmp) {
590 coap_delete_observer_internal(resource, obs->session, obs);
591 }
592 if (resource->proxy_name_count && resource->proxy_name_list) {
593 size_t i;
594
595 for (i = 0; i < resource->proxy_name_count; i++) {
596 coap_delete_str_const(resource->proxy_name_list[i]);
597 }
598 coap_free_type(COAP_STRING, resource->proxy_name_list);
599 }
600
601 coap_free_type(COAP_RESOURCE, resource);
602}
603
604COAP_API void
606 coap_lock_lock(return);
607 coap_add_resource_lkd(context, resource);
609}
610
611void
612coap_add_resource_lkd(coap_context_t *context, coap_resource_t *resource) {
614 if (resource->is_unknown) {
615 if (context->unknown_resource)
616 coap_free_resource(context->unknown_resource, COAP_DELETING_RESOURCE);
617 context->unknown_resource = resource;
618 } else if (resource->is_proxy_uri) {
619 if (context->proxy_uri_resource)
620 coap_free_resource(context->proxy_uri_resource, COAP_DELETING_RESOURCE);
621 context->proxy_uri_resource = resource;
622 } else {
623 coap_resource_t *r = coap_get_resource_from_uri_path_lkd(context,
624 resource->uri_path);
625
626 if (r) {
627 coap_log_warn("coap_add_resource: Duplicate uri_path '%*.*s', old resource deleted\n",
628 (int)resource->uri_path->length, (int)resource->uri_path->length,
629 resource->uri_path->s);
630 coap_delete_resource_lkd(r);
631 }
632 RESOURCES_ADD(context->resources, resource);
633#if COAP_WITH_OBSERVE_PERSIST
634 if (context->unknown_pdu && context->dyn_resource_save_file &&
635 context->dyn_resource_added_cb && resource->observable) {
636 coap_bin_const_t raw_packet;
637
638 raw_packet.s = context->unknown_pdu->token -
639 context->unknown_pdu->hdr_size;
640 raw_packet.length = context->unknown_pdu->used_size +
641 context->unknown_pdu->hdr_size;
642 coap_lock_callback(context->dyn_resource_added_cb(context->unknown_session,
643 resource->uri_path,
644 &raw_packet,
645 context->observe_user_data));
646 }
647#endif /* COAP_WITH_OBSERVE_PERSIST */
648 }
649 assert(resource->context == NULL);
650 resource->context = context;
651}
652
653COAP_API int
655 int ret;
656
657 (void)context;
658 if (!resource)
659 return 0;
660
661 coap_lock_lock(return 0);
662 ret = coap_delete_resource_lkd(resource);
664 return ret;
665}
666
667/*
668 * Input context is ignored, but param left there to keep API consistent
669 */
670int
671coap_delete_resource_lkd(coap_resource_t *resource) {
672 coap_context_t *context;
673 coap_deleting_resource_t deleting;
674
675 if (!resource)
676 return 0;
677
678 context = resource->context;
680
681 if (resource->ref) {
682 resource->ref--;
683 return 1;
684 }
685 if (context && context->context_going_away) {
686 deleting = COAP_DELETING_RESOURCE_ON_EXIT;
687 } else {
688 deleting = COAP_DELETING_RESOURCE;
689 }
690 if (resource->is_unknown) {
691 if (context && context->unknown_resource == resource) {
692 context->unknown_resource = NULL;
693 }
694 } else if (resource->is_proxy_uri) {
695 if (context && context->proxy_uri_resource == resource) {
696 context->proxy_uri_resource = NULL;
697 }
698 } else if (context) {
699 /* remove resource from list */
700 RESOURCES_DELETE(context->resources, resource);
701 }
702 if (resource->is_dynamic) {
703 if (context) {
704 assert(context->dynamic_cur);
705 context->dynamic_cur--;
706 }
707 }
708
709 /* and free its allocated memory */
710 coap_free_resource(resource, deleting);
711
712 return 1;
713}
714
715int
716coap_resource_release_lkd(coap_resource_t *resource) {
717 return coap_delete_resource_lkd(resource);
718}
719
720void
721coap_delete_all_resources(coap_context_t *context) {
723 coap_resource_t *tmp;
724
725 RESOURCE_ITER_SAFE(context->resources, r, tmp) {
726 coap_delete_resource_lkd(r);
727 }
728
729 context->resources = NULL;
730
731 if (context->unknown_resource) {
732 coap_delete_resource_lkd(context->unknown_resource);
733 context->unknown_resource = NULL;
734 }
735 if (context->proxy_uri_resource) {
736 coap_delete_resource_lkd(context->proxy_uri_resource);
737 context->proxy_uri_resource = NULL;
738 }
739}
740
743 coap_resource_t *result;
744
745 coap_lock_lock(return NULL);
746 result = coap_get_resource_from_uri_path_lkd(context, uri_path);
748
749 return result;
750}
751
753coap_get_resource_from_uri_path_lkd(coap_context_t *context,
754 coap_str_const_t *uri_path) {
755 coap_resource_t *result;
756
758
759 RESOURCES_FIND(context->resources, uri_path, result);
760
761 return result;
762}
763
765coap_print_link(const coap_resource_t *resource,
766 unsigned char *buf, size_t *len, size_t *offset) {
767 unsigned char *p = buf;
768 const uint8_t *bufend = buf + *len;
769 coap_attr_t *attr;
770 coap_print_status_t result = 0;
771 coap_print_status_t output_length = 0;
772 const size_t old_offset = *offset;
773
774 *len = 0;
775 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '<', *len);
776 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '/', *len);
777
778 COPY_COND_WITH_OFFSET(p, bufend, *offset,
779 resource->uri_path->s, resource->uri_path->length, *len);
780
781 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '>', *len);
782
783 LL_FOREACH(resource->link_attr, attr) {
784
785 PRINT_COND_WITH_OFFSET(p, bufend, *offset, ';', *len);
786
787 COPY_COND_WITH_OFFSET(p, bufend, *offset,
788 attr->name->s, attr->name->length, *len);
789
790 if (attr->value && attr->value->s) {
791 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '=', *len);
792
793 COPY_COND_WITH_OFFSET(p, bufend, *offset,
794 attr->value->s, attr->value->length, *len);
795 }
796
797 }
798 /* Keep implicit attributes in sync with coap_print_wellknown_lkd(). */
799 if (resource->observable) {
800 COPY_COND_WITH_OFFSET(p, bufend, *offset, ";obs", 4, *len);
801 }
802
803#if COAP_OSCORE_SUPPORT
804 if (resource->flags & COAP_RESOURCE_FLAGS_OSCORE_ONLY) {
805#if COAP_OSCORE_GROUP_SUPPORT
806 COPY_COND_WITH_OFFSET(p, bufend, *offset, ";gosc;osc", 9, *len);
807#else /* ! COAP_OSCORE_GROUP_SUPPORT */
808 COPY_COND_WITH_OFFSET(p, bufend, *offset, ";osc", 4, *len);
809#endif /* ! COAP_OSCORE_GROUP_SUPPORT */
810 }
811#endif /* COAP_OSCORE_SUPPORT */
812
813 output_length = (coap_print_status_t)(p - buf);
814
815 if (output_length > COAP_PRINT_STATUS_MAX) {
817 }
818
819 result = (coap_print_status_t)output_length;
820
821 if (result + old_offset - *offset < *len) {
822 result |= COAP_PRINT_STATUS_TRUNC;
823 }
824
825 return result;
826}
827
828void
830 coap_request_t method,
831 coap_method_handler_t handler) {
832 coap_register_request_handler(resource, method, handler);
833}
834
835void
837 coap_request_t method,
838 coap_method_handler_t handler) {
839 assert(resource);
840 assert(method > 0 && (size_t)(method-1) <
841 sizeof(resource->handler)/sizeof(coap_method_handler_t));
842 resource->handler[method-1] = handler;
843}
844
846coap_find_observer(coap_resource_t *resource, coap_session_t *session,
847 const coap_bin_const_t *token) {
849
850 assert(resource);
851 assert(session);
852
853 LL_FOREACH(resource->subscribers, s) {
854 if (s->session == session &&
855 (!token || coap_binary_equal(token, &s->pdu->actual_token)))
856 return s;
857 }
858
859 return NULL;
860}
861
862static coap_subscription_t *
863coap_find_observer_cache_key(coap_resource_t *resource, coap_session_t *session,
864 const coap_cache_key_t *cache_key) {
866
867 assert(resource);
868 assert(session);
869
870 LL_FOREACH(resource->subscribers, s) {
871 if (s->session == session
872 && (memcmp(cache_key, s->cache_key, sizeof(coap_cache_key_t)) == 0))
873 return s;
874 }
875
876 return NULL;
877}
878
879/* https://rfc-editor.org/rfc/rfc7641#section-3.6 */
880static const uint16_t cache_ignore_options[] = { COAP_OPTION_ETAG,
882 };
884coap_add_observer(coap_resource_t *resource,
885 coap_session_t *session,
886 const coap_bin_const_t *token,
887 const coap_pdu_t *request) {
889 coap_cache_key_t *cache_key = NULL;
890 size_t len;
891 const uint8_t *data;
892
893 assert(session);
894
895 /* Check if there is already a subscription for this peer. */
896 s = coap_find_observer(resource, session, token);
897 if (!s) {
898 /*
899 * Cannot allow a duplicate to be created for the same query as application
900 * may not be cleaning up duplicates. If duplicate found, then original
901 * observer is deleted and a new one created with the new token
902 */
903 cache_key = coap_cache_derive_key_w_ignore(session, request,
905 cache_ignore_options,
906 sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));
907 if (cache_key) {
908 s = coap_find_observer_cache_key(resource, session, cache_key);
909 if (s) {
910 /* Delete old entry with old token */
911 coap_delete_observer(resource, session, &s->pdu->actual_token);
912 s = NULL;
913 }
914 }
915 }
916
917 /* Refresh the destination when an existing observation is renewed. */
918 if (s) {
919 coap_address_copy(&s->local_if, &session->addr_info.local);
920 return s;
921 }
922
923 /* Check if there is already maximum number of subscribers present */
924#if (COAP_RESOURCE_MAX_SUBSCRIBER > 0)
925 uint32_t subscriber_count = 0;
926 LL_COUNT(resource->subscribers, s, subscriber_count);
927 if (subscriber_count >= COAP_RESOURCE_MAX_SUBSCRIBER) {
928 return NULL; /* Signal error */
929 }
930#endif /* COAP_RESOURCE_MAX_SUBSCRIBER */
931
932 /* Create a new subscription */
934
935 if (!s) {
936 coap_delete_cache_key(cache_key);
937 return NULL;
938 }
939
940 coap_subscription_init(s);
941 s->pdu = coap_pdu_duplicate_lkd(request, session, token->length,
942 token->s, NULL, COAP_BOOL_FALSE);
943 if (s->pdu == NULL) {
944 coap_delete_cache_key(cache_key);
946 return NULL;
947 }
948 if (coap_get_data(request, &len, &data)) {
949 /* This could be a large bodied FETCH */
950 s->pdu->max_size = 0;
951 coap_add_data(s->pdu, len, data);
952 }
953 if (cache_key == NULL) {
954 cache_key = coap_cache_derive_key_w_ignore(session, request,
956 cache_ignore_options,
957 sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));
958 if (cache_key == NULL) {
959 coap_delete_pdu_lkd(s->pdu);
960 coap_delete_cache_key(cache_key);
962 return NULL;
963 }
964 }
965 s->cache_key = cache_key;
966 s->session = coap_session_reference_lkd(session);
967 coap_address_copy(&s->local_if, &session->addr_info.local);
968 session->ref_subscriptions++;
969
970 /* add subscriber to resource */
971 LL_PREPEND(resource->subscribers, s);
972
973 coap_log_debug("create new subscription %p key 0x%02x%02x%02x%02x\n",
974 (void *)s, s->cache_key->key[0], s->cache_key->key[1],
975 s->cache_key->key[2], s->cache_key->key[3]);
976
977 if (session->context->observe_added_cb && session->proto == COAP_PROTO_UDP &&
978 !coap_is_af_unix(&session->addr_info.local)) {
979 coap_bin_const_t raw_packet;
980 coap_bin_const_t *oscore_info = NULL;
981#if COAP_OSCORE_SUPPORT
982 oscore_association_t *association;
983
984 if (session->recipient_ctx && session->recipient_ctx->recipient_id) {
985 /*
986 * Need to track the association used for tracking this observe, done as
987 * a CBOR array. Read in coap_persist_observe_add().
988 *
989 * If an entry is null, then use nil, else a set of bytes
990 *
991 * Currently tracking 5 items
992 * recipient_id
993 * id_context
994 * aad (from oscore_association_t)
995 * partial_iv (from oscore_association_t)
996 * nonce (from oscore_association_t)
997 */
998 uint8_t info_buffer[60];
999 uint8_t *info_buf = info_buffer;
1000 size_t info_len = sizeof(info_buffer);
1001 size_t ret = 0;
1002 coap_bin_const_t ctoken = { token->length, token->s };
1003
1004 ret += oscore_cbor_put_array(&info_buf, &info_len, 5);
1005 ret += oscore_cbor_put_bytes(&info_buf,
1006 &info_len,
1007 session->recipient_ctx->recipient_id->s,
1008 session->recipient_ctx->recipient_id->length);
1009 if (session->recipient_ctx->osc_ctx &&
1010 session->recipient_ctx->osc_ctx->id_context) {
1011 ret += oscore_cbor_put_bytes(&info_buf,
1012 &info_len,
1013 session->recipient_ctx->osc_ctx->id_context->s,
1014 session->recipient_ctx->osc_ctx->id_context->length);
1015 } else {
1016 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1017 }
1018 association = oscore_find_association(session, &ctoken);
1019 if (association) {
1020 if (association->aad) {
1021 ret += oscore_cbor_put_bytes(&info_buf,
1022 &info_len,
1023 association->aad->s,
1024 association->aad->length);
1025 } else {
1026 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1027 }
1028 if (association->partial_iv) {
1029 ret += oscore_cbor_put_bytes(&info_buf,
1030 &info_len,
1031 association->partial_iv->s,
1032 association->partial_iv->length);
1033 } else {
1034 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1035 }
1036 if (association->nonce) {
1037 ret += oscore_cbor_put_bytes(&info_buf,
1038 &info_len,
1039 association->nonce->s,
1040 association->nonce->length);
1041 } else {
1042 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1043 }
1044 } else {
1045 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1046 ret += oscore_cbor_put_nil(&info_buf, &info_len);
1047 }
1048 if (ret > sizeof(info_buffer)) {
1049 /* Should have been caught by assert() inoscborput_* functions */
1050 coap_log_warn("coap_add_observer overrun of info_buffer (%" PRIuS ")\n", ret);
1051 ret = sizeof(info_buffer);
1052 }
1053 oscore_info = coap_new_bin_const(info_buffer, ret);
1054 }
1055#endif /* COAP_OSCORE_SUPPORT */
1056
1057 /* s->pdu header is not currently encoded */
1058 memcpy(s->pdu->token - request->hdr_size,
1059 request->token - request->hdr_size, request->hdr_size);
1060 raw_packet.s = s->pdu->token - request->hdr_size;
1061 raw_packet.length = s->pdu->used_size + request->hdr_size;
1062 coap_lock_callback(session->context->observe_added_cb(session, s, session->proto,
1063 &session->endpoint->bind_addr,
1064 &session->addr_info,
1065 &raw_packet,
1066 oscore_info,
1067 session->context->observe_user_data));
1068#if COAP_OSCORE_SUPPORT
1069 coap_delete_bin_const(oscore_info);
1070#endif /* COAP_OSCORE_SUPPORT */
1071 }
1072 if (resource->context->track_observe_value_cb) {
1073 /* Track last used observe value (as app handler is called) */
1074 coap_lock_callback(resource->context->track_observe_value_cb(resource->context,resource->uri_path,
1075 resource->observe,
1076 resource->context->observe_user_data));
1077 }
1078
1079 return s;
1080}
1081
1082void
1083coap_touch_observer(coap_context_t *context, coap_session_t *session,
1084 const coap_bin_const_t *token) {
1086
1087 RESOURCES_ITER(context->resources, r) {
1088 s = coap_find_observer(r, session, token);
1089 if (s) {
1090 s->fail_cnt = 0;
1091 }
1092 }
1093}
1094
1095void
1096coap_delete_observer_internal(coap_resource_t *resource, coap_session_t *session,
1098 if (!s)
1099 return;
1100
1102 char outbuf[2 * 8 + 1] = "";
1103 unsigned int i;
1104 coap_string_t *uri_path;
1105 coap_string_t *uri_query;
1106
1107 for (i = 0; i < s->pdu->actual_token.length; i++) {
1108 size_t size = strlen(outbuf);
1109
1110 snprintf(&outbuf[size], sizeof(outbuf)-size, "%02x",
1111 s->pdu->actual_token.s[i]);
1112 }
1113 uri_path = coap_get_uri_path(s->pdu);
1114 uri_query = coap_get_query(s->pdu);
1115 coap_log_debug("removed subscription '/%*.*s%s%*.*s' (%p) with token '%s' key 0x%02x%02x%02x%02x\n",
1116 uri_path ? (int)uri_path->length : 0, uri_path ? (int)uri_path->length : 0,
1117 uri_path ? (char *)uri_path->s : "",
1118 uri_query ? "?" : "",
1119 uri_query ? (int)uri_query->length : 0, uri_query ? (int)uri_query->length : 0,
1120 uri_query ? (char *)uri_query->s : "",
1121 (void *)s, outbuf, s->cache_key->key[0], s->cache_key->key[1],
1122 s->cache_key->key[2], s-> cache_key->key[3]);
1123 coap_delete_string(uri_path);
1124 coap_delete_string(uri_query);
1125 }
1126 if (session->context->observe_deleted_cb)
1127 coap_lock_callback(session->context->observe_deleted_cb(session, s,
1128 session->context->observe_user_data));
1129
1130 if (resource->subscribers) {
1131 LL_DELETE(resource->subscribers, s);
1132 assert(session->ref_subscriptions > 0);
1133 session->ref_subscriptions--;
1134 coap_session_release_lkd(session);
1135 coap_delete_pdu_lkd(s->pdu);
1136 coap_delete_cache_key(s->cache_key);
1138 }
1139
1140 return;
1141}
1142
1143int
1144coap_delete_observer(coap_resource_t *resource, coap_session_t *session,
1145 const coap_bin_const_t *token) {
1147
1148 s = coap_find_observer(resource, session, token);
1149 if (s)
1150 coap_delete_observer_internal(resource, session, s);
1151
1152 return s != NULL;
1153}
1154
1155int
1156coap_delete_observer_request(coap_resource_t *resource, coap_session_t *session,
1157 const coap_bin_const_t *token, coap_pdu_t *request, int large_fetch) {
1159 int ret = 0;
1160
1161 s = coap_find_observer(resource, session, token);
1162 if (!s && large_fetch) {
1163 /*
1164 * It is possible that the client is using the wrong token.
1165 * An example being a large FETCH spanning multiple blocks.
1166 */
1167 coap_cache_key_t *cache_key;
1168
1169 cache_key = coap_cache_derive_key_w_ignore(session, request,
1171 cache_ignore_options,
1172 sizeof(cache_ignore_options)/sizeof(cache_ignore_options[0]));
1173 if (cache_key) {
1174 s = coap_find_observer_cache_key(resource, session, cache_key);
1175 if (s) {
1176 /* Delete entry with setup token */
1177 ret = coap_delete_observer(resource, session, &s->pdu->actual_token);
1178 }
1179 coap_delete_cache_key(cache_key);
1180 }
1181 } else {
1182 coap_delete_observer_internal(resource, session, s);
1183 ret = 1;
1184 }
1185 return ret;
1186}
1187
1188void
1189coap_delete_observers(coap_context_t *context, coap_session_t *session) {
1190 RESOURCES_ITER(context->resources, resource) {
1191 coap_subscription_t *s, *tmp;
1192 LL_FOREACH_SAFE(resource->subscribers, s, tmp) {
1193 if (s->session == session) {
1194 if (context->observe_deleted_cb)
1195 coap_lock_callback(context->observe_deleted_cb(session, s, context->observe_user_data));
1196 assert(resource->subscribers);
1197 LL_DELETE(resource->subscribers, s);
1198 coap_session_release_lkd(session);
1199 coap_delete_pdu_lkd(s->pdu);
1200 coap_delete_cache_key(s->cache_key);
1202 }
1203 }
1204 }
1205}
1206
1207static void
1208coap_notify_observers(coap_context_t *context, coap_resource_t *r,
1209 coap_deleting_resource_t deleting) {
1212 coap_pdu_t *response;
1213 uint8_t buf[4];
1214 coap_string_t *query;
1215 coap_block_b_t block;
1216 coap_tick_t now;
1217
1219
1220 if (r->observable && (r->dirty || r->partiallydirty)) {
1221 if (r->list_being_traversed)
1222 return;
1223 r->list_being_traversed = 1;
1224
1225 coap_resource_reference_lkd(r);
1226
1227 r->partiallydirty = 0;
1228
1229 /*
1230 * Any subscription (not just the one being notified) may get deleted
1231 * in the callback, by another running thread when executing the
1232 * callback, or when sending a response (e.g. the session fails and all
1233 * of its subscriptions are deleted). So no pointer into the list is kept
1234 * over a notification: the next subscription to visit is looked up again
1235 * from the head of the list each time.
1236 */
1237 LL_FOREACH(r->subscribers, obs) {
1238 obs->to_visit = 1;
1239 }
1240 for (;;) {
1241 coap_session_t *obs_session;
1242 coap_pdu_t *obs_pdu;
1244
1245 LL_FOREACH(r->subscribers, obs) {
1246 if (obs->to_visit)
1247 break;
1248 }
1249 if (obs == NULL)
1250 break;
1251 obs->to_visit = 0;
1252
1253 if ((r->dirty == 0 && obs->dirty == 0) || obs->session->is_rate_limiting) {
1254 /*
1255 * running this resource due to partiallydirty, but this observation's
1256 * notification was already enqueued
1257 */
1258 context->observe_pending = 1;
1259 continue;
1260 }
1261
1262 /*
1263 * obs may get deleted in the callback, or by another running
1264 * thread when executing the callback or when sending a response.
1265 */
1266 obs_session = obs->session;
1267 obs_pdu = obs->pdu;
1268 coap_session_hold_lkd(obs_session);
1269 coap_pdu_reference_lkd(obs_pdu);
1270
1271 if (obs->session->con_active >= COAP_NSTART(obs->session) &&
1272 ((r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) ||
1273 (obs->non_cnt >= COAP_OBS_MAX_NON))) {
1274 /* Waiting for the previous unsolicited response to finish */
1275 goto next_one_fail;
1276 }
1277 coap_ticks(&now);
1278 if (obs->session->lg_xmit && obs->session->lg_xmit->last_all_sent == 0 &&
1279 obs->session->lg_xmit->last_obs &&
1280 (obs->session->lg_xmit->last_obs + 2*COAP_TICKS_PER_SECOND) > now) {
1281 /* Waiting for the previous blocked unsolicited response to finish */
1282 goto next_one_fail;
1283 }
1284
1285 /* Other packets on this session may have changed the local address,
1286 * including multicast requests from the same peer and source port.
1287 * Restore it before the handler can register an async response. */
1288 coap_address_copy(&obs_session->addr_info.local, &obs->local_if);
1289
1290 obs->dirty = 0;
1291 /* initialize response */
1292 response = coap_pdu_init(COAP_MESSAGE_CON, 0, 0,
1293 coap_session_max_pdu_size_lkd(obs->session));
1294 if (!response) {
1295 coap_log_debug("coap_check_notify: pdu init failed, resource stays "
1296 "partially dirty\n");
1297 goto next_one_fail_no_pending;
1298 }
1299
1300 if (!coap_add_token(response, obs->pdu->actual_token.length,
1301 obs->pdu->actual_token.s)) {
1302 coap_log_debug("coap_check_notify: cannot add token, resource stays "
1303 "partially dirty\n");
1304 coap_delete_pdu_lkd(response);
1305 goto next_one_fail_no_pending;
1306 }
1307
1308 obs->pdu->mid = response->mid = coap_new_message_id_lkd(obs->session);
1309 /* A lot of the reliable code assumes type is CON */
1310 if (COAP_PROTO_NOT_RELIABLE(obs->session->proto) &&
1311 (r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) == 0 &&
1313 obs->non_cnt < COAP_OBS_MAX_NON)) {
1314 response->type = COAP_MESSAGE_NON;
1315 } else {
1316 response->type = COAP_MESSAGE_CON;
1317 }
1318 switch (deleting) {
1319 case COAP_NOT_DELETING_RESOURCE:
1320 /* fill with observer-specific data */
1322 coap_encode_var_safe(buf, sizeof(buf),
1323 r->observe),
1324 buf);
1325 if (coap_get_block_b(obs->session, obs->pdu, COAP_OPTION_BLOCK2,
1326 &block)) {
1327 /* Will get updated later (e.g. M bit) if appropriate */
1329 coap_encode_var_safe(buf, sizeof(buf),
1330 ((0 << 4) |
1331 (0 << 3) |
1332 block.aszx)),
1333 buf);
1334 }
1335#if COAP_Q_BLOCK_SUPPORT
1336 else if (coap_get_block_b(obs->session, obs->pdu, COAP_OPTION_Q_BLOCK2,
1337 &block)) {
1338 /* Will get updated later (e.g. M bit) if appropriate */
1340 coap_encode_var_safe(buf, sizeof(buf),
1341 ((0 << 4) |
1342 (0 << 3) |
1343 block.szx)),
1344 buf);
1345 }
1346#endif /* COAP_Q_BLOCK_SUPPORT */
1347
1348 h = r->handler[obs->pdu->code - 1];
1349 assert(h); /* we do not allow subscriptions if no
1350 * GET/FETCH handler is defined */
1351 query = coap_get_query(obs->pdu);
1352 coap_log_debug("Observe PDU presented to app.\n");
1353 coap_show_pdu(COAP_LOG_DEBUG, obs->pdu);
1354 coap_log_debug("call custom handler for resource '%*.*s' (4)\n",
1355 (int)r->uri_path->length, (int)r->uri_path->length,
1356 r->uri_path->s);
1357
1358 /* obs may get deleted during callback (potentially by another thread) */
1359 if (r->flags & COAP_RESOURCE_SAFE_REQUEST_HANDLER) {
1360 coap_lock_callback_release(h(r, obs->session, obs->pdu, query, response),
1361 /* context is being freed off */
1362 coap_delete_string(query);
1363 coap_delete_pdu_lkd(response);
1364 coap_session_release_lkd(obs_session);
1365 coap_pdu_release_lkd(obs_pdu);
1366 r->list_being_traversed = 0;
1367 coap_resource_release_lkd(r);
1368 return);
1369 } else {
1371 h(r, obs->session, obs->pdu, query, response),
1372 /* context is being freed off */
1373 coap_delete_string(query);
1374 coap_delete_pdu_lkd(response);
1375 coap_session_release_lkd(obs_session);
1376 coap_pdu_release_lkd(obs_pdu);
1377 r->list_being_traversed = 0;
1378 coap_resource_release_lkd(r);
1379 return);
1380 }
1381
1382 /* Check validity of response code */
1383 if (!coap_check_code_class(obs_session, response)) {
1384 coap_log_warn("handle_request: Invalid PDU response code (%d.%02d)\n",
1385 COAP_RESPONSE_CLASS(response->code),
1386 response->code & 0x1f);
1387 coap_delete_string(query);
1388 coap_delete_pdu_lkd(response);
1389 coap_session_unhold_lkd(obs_session);
1390 coap_pdu_release_lkd(obs_pdu);
1391 r->list_being_traversed = 0;
1392 coap_resource_release_lkd(r);
1393 return;
1394 }
1395
1396 /* Check if lg_xmit generated and update PDU code if so */
1397 coap_check_code_lg_xmit(obs_session, obs_pdu, response, r, query);
1398 coap_delete_string(query);
1399 if (COAP_RESPONSE_CLASS(response->code) != 2) {
1401 }
1402 if (COAP_RESPONSE_CLASS(response->code) > 2) {
1403 coap_delete_observer(r, obs_session, &obs_pdu->actual_token);
1404 obs = NULL;
1405 }
1406 break;
1407 case COAP_DELETING_RESOURCE_ON_EXIT:
1408 /* Don't worry if it does not get there */
1409 response->type = COAP_MESSAGE_NON;
1410 response->code = COAP_RESPONSE_CODE(503);
1412 coap_encode_var_safe(buf, sizeof(buf),
1413 30),
1414 buf);
1415 break;
1416 case COAP_DELETING_RESOURCE:
1417 default:
1418 /* Don't worry if it does not get there */
1419 response->type = COAP_MESSAGE_NON;
1420 response->code = COAP_RESPONSE_CODE(404);
1421 break;
1422 }
1423
1424 if (obs) {
1426 /*
1427 * obs may have been deleted in the callback, or by another running
1428 * thread when executing the callback.
1429 */
1430 LL_FOREACH(r->subscribers, s) {
1431 if (s == obs) {
1432 break;
1433 }
1434 }
1435 if (s == NULL)
1436 obs = NULL;
1437 }
1438 if (obs) {
1439 if (response->type == COAP_MESSAGE_CON ||
1441 obs->non_cnt = 0;
1442 } else {
1443 obs->non_cnt++;
1444 }
1445
1446#if COAP_Q_BLOCK_SUPPORT
1447 if (response->code == COAP_RESPONSE_CODE(205) &&
1448 coap_get_block_b(obs_session, response, COAP_OPTION_Q_BLOCK2,
1449 &block) &&
1450 block.m) {
1451 query = coap_get_query(obs_pdu);
1452 mid = coap_send_q_block2(obs_session, r, query, obs_pdu->code,
1453 block, response, 1);
1454 coap_delete_string(query);
1455 goto finish;
1456 }
1457#endif /* COAP_Q_BLOCK_SUPPORT */
1458 }
1459 if (response->code == COAP_EMPTY_CODE &&
1460 (response->type == COAP_MESSAGE_NON ||
1461 response->type == COAP_MESSAGE_CON) &&
1462 response->actual_token.length != 0) {
1463 /*
1464 * If a resource has been updated, triggering the sending of an
1465 * observer response and the request handler does not set a response
1466 * code (a coding error condition), then this PDU must be dropped as
1467 * it is illegally formatted.
1468 */
1469 coap_delete_pdu_lkd(response);
1471 } else {
1472 mid = coap_send_internal(obs_session, response, NULL);
1473 }
1474
1475#if COAP_Q_BLOCK_SUPPORT
1476finish:
1477#endif /* COAP_Q_BLOCK_SUPPORT */
1478 if (COAP_INVALID_MID == mid) {
1479 coap_log_debug("* %s: coap_check_notify: sending failed, resource stays "
1480 "partially dirty\n", coap_session_str(obs_session));
1481 if (obs) {
1483 /*
1484 * obs may have been deleted in coap_send_internal() or
1485 * coap_send_q_block2().
1486 */
1487 LL_FOREACH(r->subscribers, s) {
1488 if (s == obs) {
1489 break;
1490 }
1491 }
1492 if (s == NULL)
1493 obs = NULL;
1494 }
1495 if (obs)
1496 obs->dirty = 1;
1497 r->partiallydirty = 1;
1498 }
1499 goto cleanup;
1500
1501next_one_fail:
1502 context->observe_pending = 1;
1503next_one_fail_no_pending:
1504 r->partiallydirty = 1;
1505 if (obs)
1506 obs->dirty = 1;
1507cleanup:
1508 coap_session_unhold_lkd(obs_session);
1509 coap_pdu_release_lkd(obs_pdu);
1510 }
1511 r->list_being_traversed = 0;
1512 r->dirty = 0;
1513 coap_resource_release_lkd(r);
1514 /* r may be no more if elsewhere coap_free_resource() has been called */
1515 } else {
1516 r->dirty = 0;
1517 }
1518}
1519
1520COAP_API int
1522 int ret;
1523 (void)query;
1524
1525 coap_lock_lock(return 0);
1526 ret = coap_resource_notify_observers_lkd(r, COAP_NOT_DELETING_RESOURCE);
1528 return ret;
1529}
1530
1531COAP_API int
1533 const coap_string_t *query) {
1534 int ret;
1535
1536 (void)query;
1537 coap_lock_lock(return 0);
1538 ret = coap_resource_notify_observers_lkd(r, COAP_NOT_DELETING_RESOURCE);
1540 return ret;
1541}
1542
1543int
1544coap_resource_notify_observers_lkd(coap_resource_t *r,
1545 coap_deleting_resource_t deleting) {
1547 if (!r->observable)
1548 return 0;
1549 if (!r->subscribers)
1550 return 0;
1551 r->dirty = 1;
1552
1553 /* Increment value for next Observe use. Observe value must be < 2^24 */
1554 r->observe = (r->observe + 1) & 0xFFFFFF;
1555
1556 assert(r->context);
1557
1558 if (r->context->track_observe_value_cb) {
1559 /* Track last used observe value */
1560 if ((r->observe % r->context->observe_save_freq) == 0)
1561 coap_lock_callback(r->context->track_observe_value_cb(r->context, r->uri_path,
1562 r->observe,
1563 r->context->observe_user_data));
1564 }
1565
1566 coap_notify_observers(r->context, r, deleting);
1567 return 1;
1568}
1569
1570void
1571coap_resource_set_mode(coap_resource_t *resource, int mode) {
1572 resource->flags = (resource->flags &
1575}
1576
1577void
1578coap_resource_set_userdata(coap_resource_t *resource, void *data) {
1579 resource->user_data = data;
1580}
1581
1582void *
1584 return resource->user_data;
1585}
1586
1587void
1590 context->release_userdata_cb = callback;
1591}
1592
1593void
1595 if (resource->is_unknown || resource->is_proxy_uri) {
1596 /* We cannot observe these */
1597 coap_log_debug("coap_resource_set_get_observable: Not supported for Unknown or Proxy URIs\n");
1598 resource->observable = 0;
1599 } else {
1600 resource->observable = mode ? 1 : 0;
1601 }
1602}
1603
1606 if (resource)
1607 return resource->uri_path;
1608 return NULL;
1609}
1610
1611COAP_API void
1613 coap_lock_lock(return);
1614 coap_check_notify_lkd(context);
1616}
1617
1618void
1619coap_check_notify_lkd(coap_context_t *context) {
1620
1622 if (context->observe_pending) {
1623 context->observe_pending = 0;
1624 RESOURCES_ITER(context->resources, r) {
1625 coap_notify_observers(context, r, COAP_NOT_DELETING_RESOURCE);
1626 }
1627 }
1628}
1629
1630void
1632 uint32_t start_observe_no) {
1633 if (!resource)
1634 return;
1635
1636 resource->observe = start_observe_no & 0xffffff;
1637}
1638
1649static void
1650coap_remove_failed_observers(coap_context_t *context,
1651 coap_resource_t *resource,
1652 coap_session_t *session,
1653 const coap_bin_const_t *token) {
1654 coap_subscription_t *obs, *otmp;
1655
1656 LL_FOREACH_SAFE(resource->subscribers, obs, otmp) {
1657 if (obs->session == session &&
1658 coap_binary_equal(token, &obs->pdu->actual_token)) {
1659 /* count failed notifies and remove when
1660 * COAP_OBS_MAX_FAIL is reached */
1661 obs->fail_cnt++;
1662 if (obs->fail_cnt >= COAP_OBS_MAX_FAIL) {
1663 coap_cancel_all_messages(context, obs->session,
1664 &obs->pdu->actual_token);
1665 coap_delete_observer(resource, session, token);
1666 }
1667 break; /* break loop if observer was found */
1668 }
1669 }
1670}
1671
1672void
1673coap_handle_failed_notify(coap_context_t *context,
1674 coap_session_t *session,
1675 const coap_bin_const_t *token) {
1676
1677 RESOURCES_ITER(context->resources, r) {
1678 coap_remove_failed_observers(context, r, session, token);
1679 }
1680}
1681
1682void
1683coap_resource_reference_lkd(coap_resource_t *resource) {
1684 resource->ref++;
1685}
1686
1688coap_add_dynamic_resource(coap_session_t *session, coap_pdu_t *pdu) {
1689 coap_context_t *context = session->context;
1690 coap_resource_t *resource;
1691
1692 if ((context->dyn_create_handler != NULL) &&
1694 /* Above test must be the same as in coap_op_dyn_resource_load_disk() */
1695 if (context->dynamic_cur < context->dynamic_max || context->dynamic_max == 0) {
1696#if COAP_WITH_OBSERVE_PERSIST
1697 /* If we are maintaining Observe persist */
1698 context->unknown_pdu = pdu;
1699 context->unknown_session = session;
1700#endif /* COAP_WITH_OBSERVE_PERSIST */
1701 coap_lock_callback_ret(resource, context->dyn_create_handler(session, pdu));
1702#if COAP_WITH_OBSERVE_PERSIST
1703 /* If we are maintaining Observe persist */
1704 context->unknown_pdu = NULL;
1705 context->unknown_session = NULL;
1706#endif /* COAP_WITH_OBSERVE_PERSIST */
1707 if (resource) {
1708 context->dynamic_cur++;
1709 resource->is_dynamic = 1;
1710 }
1711 return resource;
1712 }
1713 }
1714 return NULL;
1715}
1716
1717#endif /* COAP_SERVER_SUPPORT */
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
struct coap_cache_key_t coap_cache_key_t
struct coap_attr_t coap_attr_t
struct coap_subscription_t coap_subscription_t
struct coap_resource_t coap_resource_t
#define PRIuS
Library specific build wrapper for coap_internal.h.
#define COAP_API
@ COAP_RESOURCE
Definition coap_mem.h:42
@ COAP_RESOURCEATTR
Definition coap_mem.h:43
@ COAP_SUBSCRIPTION
Definition coap_mem.h:53
@ COAP_STRING
Definition coap_mem.h:33
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
#define NULL
Definition coap_option.h:30
@ COAP_OPTION_OBSERVE
Definition coap_option.h:75
@ COAP_OPTION_ETAG
Definition coap_option.h:73
@ COAP_OPTION_MAXAGE
Definition coap_option.h:83
@ COAP_OPTION_Q_BLOCK2
Definition coap_option.h:93
@ COAP_OPTION_BLOCK2
Definition coap_option.h:90
@ COAP_OPTION_OSCORE
Definition coap_option.h:78
COAP_DEPRECATED COAP_API int coap_resource_set_dirty(coap_resource_t *r, const coap_string_t *query)
void coap_check_code_lg_xmit(const coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_resource_t *resource, const coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response_l...
int coap_get_block_b(const coap_session_t *session, const coap_pdu_t *pdu, coap_option_num_t number, coap_block_b_t *block)
Initializes block from pdu.
Definition coap_block.c:71
void coap_delete_cache_key(coap_cache_key_t *cache_key)
Delete the cache-key.
coap_cache_key_t * coap_cache_derive_key_w_ignore(const coap_session_t *session, const coap_pdu_t *pdu, coap_cache_session_based_t session_based, const uint16_t *ignore_options, size_t ignore_count)
Calculates a cache-key for the given CoAP PDU.
@ COAP_CACHE_IS_SESSION_BASED
Definition coap_cache.h:41
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:149
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
Definition coap_time.h:164
COAP_API coap_resource_t * coap_get_resource_from_uri_path(coap_context_t *context, coap_str_const_t *uri_path)
Returns the resource identified by the unique string uri_path.
#define COAP_RESOURCE_FLAGS_NOTIFY_NON
Observe Notifications will be sent non-confirmable by default.
coap_resource_t * coap_resource_proxy_uri_init(coap_method_handler_t handler, size_t host_name_count, const char *host_name_list[])
Creates a new resource object for handling proxy URIs.
coap_attr_t * coap_add_attr(coap_resource_t *resource, coap_str_const_t *name, coap_str_const_t *value, int flags)
Registers a new attribute with the given resource.
#define COAP_ATTR_FLAGS_RELEASE_VALUE
coap_print_status_t coap_print_link(const coap_resource_t *resource, unsigned char *buf, size_t *len, size_t *offset)
Writes a description of this resource in link-format to given text buffer.
coap_resource_t * coap_resource_proxy_uri_init2(coap_method_handler_t handler, size_t host_name_count, const char *host_name_list[], int flags)
Creates a new resource object for handling proxy URIs with configurable control over multicast reques...
#define COAP_RESOURCE_FLAGS_NOTIFY_NON_ALWAYS
Observe Notifications will always be sent non-confirmable.
#define COAP_RESOURCE_HANDLE_WELLKNOWN_CORE
Define this when invoking coap_resource_unknown_init2() if .well-known/core is to be passed to the un...
#define COAP_ATTR_FLAGS_RELEASE_NAME
void coap_resource_set_mode(coap_resource_t *resource, int mode)
Sets the notification message type of resource resource to given mode.
#define COAP_RESOURCE_SAFE_REQUEST_HANDLER
Don't lock this resource when calling app call-back handler for requests as handler will not be manip...
#define COAP_PRINT_STATUS_TRUNC
void(* coap_method_handler_t)(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response)
Definition of message handler function.
void coap_resource_release_userdata_handler(coap_context_t *context, coap_resource_release_userdata_handler_t callback)
Defines the context wide callback to use to when the resource is deleted to release the data held in ...
#define COAP_RESOURCE_FLAGS_OSCORE_ONLY
Define this resource as an OSCORE enabled access only.
COAP_API coap_print_status_t coap_print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen, size_t offset, const coap_string_t *query_filter)
Prints the names of all known resources for context to buf.
#define COAP_RESOURCE_FLAGS_NOTIFY_CON
Observe Notifications will be sent confirmable.
coap_resource_t * coap_resource_reverse_proxy_init(coap_method_handler_t handler, int flags)
Creates a new resource object for the reverse-proxy resource handler with control over multicast requ...
COAP_API int coap_delete_resource(coap_context_t *context, coap_resource_t *resource)
Deletes a resource identified by resource.
void coap_register_handler(coap_resource_t *resource, coap_request_t method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
#define COAP_PRINT_STATUS_MAX
void(* coap_resource_release_userdata_handler_t)(void *user_data)
Definition of release resource user_data callback function.
void coap_register_request_handler(coap_resource_t *resource, coap_request_t method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
coap_resource_t * coap_resource_init(coap_str_const_t *uri_path, int flags)
Creates a new resource object and initializes the link field to the string uri_path.
void coap_resource_set_userdata(coap_resource_t *resource, void *data)
Sets the user_data.
uint32_t coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
#define COAP_PRINT_STATUS_ERROR
coap_str_const_t * coap_resource_get_uri_path(coap_resource_t *resource)
Get the uri_path from a resource.
coap_resource_t * coap_resource_unknown_init2(coap_method_handler_t put_handler, int flags)
Creates a new resource object for the unknown resource handler with support for PUT and configurable ...
coap_str_const_t * coap_attr_get_value(coap_attr_t *attribute)
Returns attribute's value.
#define COAP_PRINT_OUTPUT_LENGTH(v)
coap_attr_t * coap_find_attr(coap_resource_t *resource, coap_str_const_t *name)
Returns resource's coap_attr_t object with given name if found, NULL otherwise.
void * coap_resource_get_userdata(coap_resource_t *resource)
Gets the user_data.
COAP_API void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
#define COAP_RESOURCE_FLAGS_RELEASE_URI
The URI passed to coap_resource_init() is free'd by coap_delete_resource().
coap_resource_t * coap_resource_unknown_init(coap_method_handler_t put_handler)
Creates a new resource object for the unknown resource handler with support for PUT.
#define COAP_RESOURCE_HIDE_WELLKNOWN_CORE
Hide this resource from .well-known/core.
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *request_pdu)
Sends a CoAP message to given peer.
Definition coap_net.c:2170
int coap_check_code_class(coap_session_t *session, coap_pdu_t *pdu)
Check whether the pdu contains a valid code class.
Definition coap_net.c:1584
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, coap_bin_const_t *token)
Cancels all outstanding messages for session session that have the specified token.
Definition coap_net.c:3485
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
Definition coap_time.c:90
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
Definition coap_encode.c:47
#define coap_lock_specific_callback_release(lock, func, failed)
Dummy for no thread-safe code.
#define coap_lock_callback(func)
Dummy for no thread-safe code.
#define coap_lock_init(lock)
Dummy for no thread-safe code.
#define coap_lock_callback_ret(r, func)
Dummy for no thread-safe code.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_callback_release(func, failed)
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
Definition coap_debug.h:126
coap_log_t coap_get_log_level(void)
Get the current logging level.
Definition coap_debug.c:103
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
Definition coap_debug.c:845
const char * coap_session_str(const coap_session_t *session)
Get session description.
#define coap_log_warn(...)
Definition coap_debug.h:108
#define coap_log_err(...)
Definition coap_debug.h:102
@ COAP_LOG_DEBUG
Definition coap_debug.h:64
void coap_persist_set_observe_num(coap_resource_t *resource, uint32_t observe_num)
Sets the current observe number value.
void coap_resource_set_get_observable(coap_resource_t *resource, int mode)
Set whether a resource is observable.
COAP_API void coap_check_notify(coap_context_t *context)
Checks all known resources to see if they are dirty and then notifies subscribed observers.
COAP_API int coap_resource_notify_observers(coap_resource_t *resource, const coap_string_t *query)
Initiate the sending of an Observe packet for all observers of resource, optionally matching query if...
size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size)
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
coap_pdu_t * coap_pdu_reference_lkd(coap_pdu_t *pdu)
Increment reference counter on a pdu to stop it prematurely getting freed off when coap_delete_pdu() ...
Definition coap_pdu.c:1768
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
Definition coap_pdu.c:192
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
Definition coap_pdu.c:545
#define COAP_DROPPED_RESPONSE
Indicates that a response is suppressed.
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options, coap_bool_t expand_opt_abb)
Duplicate an existing PDU.
Definition coap_pdu.c:232
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
size_t coap_add_option_internal(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
Definition coap_pdu.c:858
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:195
coap_request_t
CoAP PDU Request methods.
Definition coap_pdu.h:80
#define COAP_RESPONSE_CODE(N)
Definition coap_pdu.h:96
#define COAP_RESPONSE_CLASS(C)
Definition coap_pdu.h:99
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
Definition coap_pdu.c:412
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
Definition coap_pdu.c:961
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
Definition coap_pdu.c:104
#define COAP_INVALID_MID
Indicates an invalid message id.
Definition coap_pdu.h:198
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
Definition coap_pdu.h:55
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
Definition coap_pdu.c:930
@ COAP_BOOL_FALSE
Definition coap_pdu.h:306
@ COAP_REQUEST_PUT
Definition coap_pdu.h:83
@ COAP_REQUEST_DELETE
Definition coap_pdu.h:84
@ COAP_REQUEST_GET
Definition coap_pdu.h:81
@ COAP_REQUEST_FETCH
Definition coap_pdu.h:85
@ COAP_REQUEST_PATCH
Definition coap_pdu.h:86
@ COAP_REQUEST_IPATCH
Definition coap_pdu.h:87
@ COAP_REQUEST_POST
Definition coap_pdu.h:82
@ COAP_PROTO_UDP
Definition coap_pdu.h:247
@ COAP_REQUEST_CODE_PUT
Definition coap_pdu.h:264
@ COAP_REQUEST_CODE_POST
Definition coap_pdu.h:263
@ COAP_EMPTY_CODE
Definition coap_pdu.h:260
@ COAP_MESSAGE_NON
Definition coap_pdu.h:72
@ COAP_MESSAGE_CON
Definition coap_pdu.h:71
void coap_session_hold_lkd(coap_session_t *session)
Mark the session as in use for a unit of work (reading and dispatching received data,...
void coap_session_unhold_lkd(coap_session_t *session)
End a unit of work started by coap_session_hold_lkd().
#define COAP_NSTART(s)
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
coap_session_t * coap_session_reference_lkd(coap_session_t *session)
Increment reference counter on a session.
#define COAP_PROTO_NOT_RELIABLE(p)
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
Definition coap_str.c:130
void coap_delete_str_const(coap_str_const_t *s)
Deletes the given const string and releases any memory allocated.
Definition coap_str.c:65
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
Definition coap_str.c:119
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
Definition coap_str.h:222
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
Definition coap_str.h:208
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
Definition coap_str.c:55
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
Definition coap_str.c:50
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition coap_uri.c:1202
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Definition coap_uri.c:1108
coap_address_t local
local address and port
Definition coap_io.h:59
CoAP binary data definition with const data.
Definition coap_str.h:65
size_t length
length of binary data
Definition coap_str.h:66
const uint8_t * s
read-only binary data
Definition coap_str.h:67
Structure of Block options with BERT support.
Definition coap_block.h:55
unsigned int aszx
block size (0-7 including BERT
Definition coap_block.h:59
unsigned int m
1 if more blocks follow, 0 otherwise
Definition coap_block.h:57
unsigned int szx
block size (0-6)
Definition coap_block.h:58
The CoAP stack's global state is stored in a coap_context_t object.
uint32_t dynamic_cur
Current number of dynamic resources.
coap_resource_dynamic_create_t dyn_create_handler
Dynamic resource create handler.
uint32_t dynamic_max
Max number of dynamic resources or 0 is unlimited.
structure for CoAP PDUs
uint8_t * token
first byte of token (or extended length bytes prefix), if any, or options
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
uint8_t hdr_size
actual size used for protocol-specific header (0 until header is encoded)
coap_bin_const_t actual_token
Actual token in pdu.
coap_mid_t mid
message id, if any, in regular host byte order
coap_pdu_type_t type
message type
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_addr_tuple_t addr_info
remote/local address info
coap_proto_t proto
protocol used
coap_context_t * context
session's context
CoAP string data definition with const data.
Definition coap_str.h:47
const uint8_t * s
read-only string data
Definition coap_str.h:49
size_t length
length of string
Definition coap_str.h:48
CoAP string data definition.
Definition coap_str.h:39
uint8_t * s
string data
Definition coap_str.h:41
size_t length
length of string
Definition coap_str.h:40
coap_bin_const_t * partial_iv
coap_bin_const_t * aad
coap_bin_const_t * nonce