libcoap 4.3.5-develop-ff11f1b
Loading...
Searching...
No Matches
coap_debug.c
Go to the documentation of this file.
1/* coap_debug.c -- debug utilities
2 *
3 * Copyright (C) 2010--2012,2014--2026 Olaf Bergmann <bergmann@tzi.org> and others
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 defined(HAVE_STRNLEN) && defined(__GNUC__) && !defined(_GNU_SOURCE)
19#define _GNU_SOURCE 1
20#endif
21
22#include <stdarg.h>
23#include <stdio.h>
24#include <string.h>
25#include <ctype.h>
26
27#ifdef HAVE_ARPA_INET_H
28#include <arpa/inet.h>
29#endif
30#ifndef __ZEPHYR__
31#ifdef HAVE_WS2TCPIP_H
32#include <ws2tcpip.h>
33#endif
34#endif /* !__ZEPHYR__ */
35
36#ifdef HAVE_TIME_H
37#include <time.h>
38#endif
39
40#ifdef WITH_LWIP
41# define fprintf(fd, ...) LWIP_PLATFORM_DIAG((__VA_ARGS__))
42# define fflush(...)
43#endif
44
45#ifdef WITH_CONTIKI
46# define fprintf(fd, ...) { (void)fd; printf(__VA_ARGS__); }
47# define fflush(...)
48# define vfprintf(fd, ...) { (void)fd; printf(__VA_ARGS__); }
49
50# ifndef LOG_CONF_LEVEL_COAP
51# define LOG_CONF_LEVEL_COAP 2 /* = LOG_LEVEL_WARN */
52# endif
53static coap_log_t maxlog = LOG_CONF_LEVEL_COAP == 0 ? /* = LOG_LEVEL_NONE */
55 (LOG_CONF_LEVEL_COAP == 1 ? /* = LOG_LEVEL_ERR */
57 (LOG_CONF_LEVEL_COAP == 2 ? /* = LOG_LEVEL_WARN */
59 (LOG_CONF_LEVEL_COAP == 3 ? /* = LOG_LEVEL_INFO */
62#else /* !WITH_CONTIKI */
63static coap_log_t maxlog = COAP_LOG_WARN; /* default maximum CoAP log level */
64#endif /* !WITH_CONTIKI */
65
66#ifdef RIOT_VERSION
67#include "flash_utils.h"
68#endif /* RIOT_VERSION */
69
70static int use_fprintf_for_show_pdu = 1; /* non zero to output with fprintf */
71static int enable_data_for_show_pdu = 1; /* By default show PDU data for coap_show_pdu() */
72
73const char *
75 return PACKAGE_NAME;
76}
77
78const char *
80 return PACKAGE_STRING;
81}
82
83const char *
85#ifdef LIBCOAP_PACKAGE_BUILD
86 return LIBCOAP_PACKAGE_BUILD;
87#else /* !LIBCOAP_PACKAGE_BUILD */
88 return PACKAGE_STRING;
89#endif /* !LIBCOAP_PACKAGE_BUILD */
90}
91
92void
93coap_set_show_pdu_output(int use_fprintf) {
94 use_fprintf_for_show_pdu = use_fprintf;
95}
96
97void
99 enable_data_for_show_pdu = enable_data;
100}
101
104 return maxlog;
105}
106
107void
109 if (level > COAP_MAX_LOGGING_LEVEL)
111 maxlog = level;
112}
113
114/* this array has the same order as the type coap_log_t with the (D)TLS
115 entries added to the list with a COAP_LOG_DTLS_BASE offset */
116static const char *loglevels[] = {
117 /* General logging */
118 "EMRG", "ALRT", "CRIT", "ERR ", "WARN", "NOTE", "INFO", "DEBG", "OSC ",
119 /* (D)TLS logging */
120 "Emrg", "Alrt", "Crit", "Err ", "Warn", "Note", "Info", "Debg"
121};
122
123const char *
125 static char bad[8];
126 if (level >= sizeof(loglevels)/sizeof(loglevels[0])) {
127 snprintf(bad, sizeof(bad), "%4d", level);
128 return bad;
129 } else {
130 return loglevels[level];
131 }
132}
133
134#ifdef WITH_CONTIKI
135void
136coap_print_contiki_prefix(coap_log_t level) {
137 printf("[%s: COAP ] ", coap_log_level_desc(level));
138}
139#endif /* WITH_CONTIKI */
140
141#ifdef HAVE_TIME_H
142
144print_timestamp(char *s, size_t len, coap_tick_t t) {
145 struct tm *tmp;
146 size_t lensofar;
147 time_t now = coap_ticks_to_rt(t);
148 tmp = localtime(&now);
149 lensofar = strftime(s, len, "%b %d %H:%M:%S", tmp);
150 if (len > lensofar + 4) {
151 lensofar += snprintf(&s[lensofar], len-lensofar, ".%03u",
152 (unsigned int)((coap_ticks_to_rt_us(t) % 1000000)/1000));
153 }
154 return lensofar;
155}
156
157#else /* alternative implementation: just print the timestamp */
158
160print_timestamp(char *s, size_t len, coap_tick_t t) {
161#ifdef HAVE_SNPRINTF
162 return snprintf(s, len, "%u.%03u",
163 (unsigned int)coap_ticks_to_rt(t),
164 (unsigned int)((coap_ticks_to_rt_us(t) % 1000000)/1000));
165#else /* HAVE_SNPRINTF */
166 /* @todo do manual conversion of timestamp */
167 return 0;
168#endif /* HAVE_SNPRINTF */
169}
170
171#endif /* HAVE_TIME_H */
172
173#if !defined(HAVE_STRNLEN) && !defined(__MINGW32__) && !defined(__ZEPHYR__)
182static inline size_t
183strnlen(const char *s, size_t maxlen) {
184 size_t n = 0;
185 while (*s++ && n < maxlen)
186 ++n;
187 return n;
188}
189#endif /* HAVE_STRNLEN && !__MINGW32__ && !__ZEPHYR__*/
190
191static size_t
192print_readable(const uint8_t *data, size_t len,
193 unsigned char *result, size_t buflen, int encode_always) {
194 const uint8_t hex[] = "0123456789ABCDEF";
195 size_t cnt = 0;
196 assert(data || len == 0);
197
198 if (buflen == 0) { /* there is nothing we can do here but return */
199 return 0;
200 }
201
202 while (len) {
203 if (!encode_always && isprint(*data)) {
204 if (cnt+1 < buflen) { /* keep one byte for terminating zero */
205 *result++ = *data;
206 ++cnt;
207 } else {
208 break;
209 }
210 } else {
211 if (cnt+4 < buflen) { /* keep one byte for terminating zero */
212 *result++ = '\\';
213 *result++ = 'x';
214 *result++ = hex[(*data & 0xf0) >> 4];
215 *result++ = hex[*data & 0x0f];
216 cnt += 4;
217 } else
218 break;
219 }
220
221 ++data;
222 --len;
223 }
224
225 *result = '\0'; /* add a terminating zero */
226 return cnt;
227}
228
229int
230coap_snprintf(char *buffer, size_t buf_size, size_t *offset,
231 const char *format, ...) {
232 va_list ap;
233 int ret;
234 size_t start = *offset;
235
236 assert(buf_size > 0 && start < buf_size);
237 if (buf_size == 0 || start >= buf_size - 1)
238 return 0;
239
240 va_start(ap, format);
241 ret = vsnprintf(&buffer[start], buf_size - start, format, ap);
242 va_end(ap);
243 if (ret < 0) {
244 buffer[start] = '\000';
245 return 0;
246 } else if ((size_t)ret >= buf_size - start) {
247 *offset = buf_size - 1;
248 } else {
249 *offset = start + (size_t)ret;
250 }
251 return (int)(*offset - start);
252}
253
254#ifndef min
255#define min(a,b) ((a) < (b) ? (a) : (b))
256#endif
257
258#ifndef INET6_ADDRSTRLEN
259#define INET6_ADDRSTRLEN 46
260#endif
261/*
262 * Returned buf is always NULL terminated.
263 * Returned size is number of characters, not including NULL terminator.
264 */
265size_t
266coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len) {
267#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
268 char scratch[INET6_ADDRSTRLEN];
269
270 assert(buf);
271 assert(len);
272 buf[0] = '\000';
273
274 switch (addr->addr.sa.sa_family) {
275#if COAP_IPV4_SUPPORT
276 case AF_INET:
277 snprintf((char *)buf, len, "%s:%d",
278 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
280 break;
281#endif /* COAP_IPV4_SUPPORT */
282#if COAP_IPV6_SUPPORT
283 case AF_INET6:
284 snprintf((char *)buf, len, "[%s]:%d",
285 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
287 break;
288#endif /* COAP_IPV6_SUPPORT */
289#if COAP_AF_UNIX_SUPPORT
290 case AF_UNIX:
291 snprintf((char *)buf, len, "%s", addr->addr.cun.sun_path);
292 break;
293#endif /* COAP_AF_UNIX_SUPPORT */
294#if COAP_AF_LLC_SUPPORT
295 case AF_LLC:
296 snprintf((char *)buf, len, "%s:%02x",
297 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
299 break;
300#endif /* COAP_AF_LLC_SUPPORT */
301 default:
302 /* Include trailing NULL if possible */
303 memcpy(buf, "(unknown address type)", min(22+1, len));
304 buf[len-1] = '\000';
305 break;
306 }
307 return strlen((char *)buf);
308
309#else /* HAVE_ARPA_INET_H */
310
311# if defined(RIOT_VERSION)
312 char scratch[INET6_ADDRSTRLEN];
313
314 assert(buf);
315 assert(len);
316 buf[0] = '\000';
317
318 switch (addr->riot.family) {
319#if COAP_IPV4_SUPPORT
320 case AF_INET:
321 snprintf((char *)buf, len, "%s:%d",
322 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
324 break;
325#endif /* COAP_IPV4_SUPPORT */
326#if COAP_IPV6_SUPPORT
327 case AF_INET6:
328 snprintf((char *)buf, len, "[%s]:%d",
329 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
331 break;
332#endif /* COAP_IPV6_SUPPORT */
333 default:
334 /* Include trailing NULL if possible */
335 memcpy(buf, "(unknown address type)", min(22+1, len));
336 buf[len-1] = '\000';
337 break;
338 }
339 return strlen((char *)buf);
340
341# elif WITH_CONTIKI
342
343 char scratch[INET6_ADDRSTRLEN];
344#ifdef HAVE_SNPRINTF
345
346 snprintf((char *)buf, len, "[%s]:%d",
347 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
349 return strlen((char *)buf);
350#else /* HAVE_SNPRINTF */
351 unsigned char *p = buf;
352# if NETSTACK_CONF_WITH_IPV6
353
354 assert(buf);
355 assert(len);
356 buf[0] = '\000';
357 if (len < 40 + 2 + 6)
358 return 0;
359
360 *p++ = '[';
361 memcpy(p, coap_print_ip_addr(addr, scratch, sizeof(scratch)), 40);
362 p += 40 - 1;
363 *p++ = ']';
364# else /* WITH_UIP6 */
365# warning "IPv4 network addresses will not be included in debug output"
366
367 if (len < 21) {
368 *p = '\000';
369 return 0;
370 }
371# endif /* WITH_UIP6 */
372
373 *p++ = ':';
374 *p++ = '0' + (coap_address_get_port(addr) / 10000) % 10;
375 *p++ = '0' + (coap_address_get_port(addr) / 1000) % 10;
376 *p++ = '0' + (coap_address_get_port(addr) / 100) % 10;
377 *p++ = '0' + (coap_address_get_port(addr) / 10) % 10;
378 *p++ = '0' + coap_address_get_port(addr) % 10;
379 *p = '\000';
380
381 return strlen((char *)buf);
382#endif /* HAVE_SNPRINTF */
383
384# elif WITH_LWIP
385
386 char scratch[INET6_ADDRSTRLEN];
387#ifdef HAVE_SNPRINTF
388
389 snprintf((char *)buf, len, "[%s]:%d",
390 coap_print_ip_addr(addr, scratch, sizeof(scratch)),
391 addr->port);
392 return strlen((char *)buf);
393#else /* HAVE_SNPRINTF */
394 unsigned char *p = buf;
395
396 assert(buf);
397 assert(len);
398 buf[0] = '\000';
399
400 switch (IP_GET_TYPE(addr->addr)) {
401 case IPADDR_TYPE_V4:
402 if (len < IP4ADDR_STRLEN_MAX + 6)
403 return 0;
404 memcpy(buf, coap_print_ip_addr(addr, scratch, sizeof(scratch)), IP4ADDR_STRLEN_MAX);
405 p += strlen((char *)buf);
406 break;
407#if LWIP_IPV6
408 case IPADDR_TYPE_V6:
409 case IPADDR_TYPE_ANY:
410 if (len < 40 + 2 + 6)
411 return 0;
412 *p++ = '[';
413 memcpy(p, coap_print_ip_addr(addr, scratch, sizeof(scratch)), 40);
414 p += strlen((char *)buf);
415 *p++ = ']';
416 break;
417#endif /* LWIP_IPV6 */
418 }
419
420 *p++ = ':';
421 *p++ = '0' + (addr->port / 10000) % 10;
422 *p++ = '0' + (addr->port / 1000) % 10;
423 *p++ = '0' + (addr->port / 100) % 10;
424 *p++ = '0' + (addr->port / 10) % 10;
425 *p++ = '0' + addr->port % 10;
426 *p = '\000';
427
428 return strlen((char *)buf);
429#endif /* HAVE_SNPRINTF */
430
431# else /* ! WITH_CONTIKI && ! WITH_LWIP */
432
433 (void)addr;
434 (void)len;
435
436 /* TODO: output addresses manually */
437# warning "inet_ntop() not available, network addresses will not be included in debug output"
438# endif /* ! WITH_CONTIKI && ! WITH_LWIP */
439 buf[0] = '\000';
440 return 0;
441#endif
442}
443
444/*
445 * Returned buf is always NULL terminated with as much as possible of the
446 * IP address filled in.
447 */
448const char *
449coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len) {
450#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
451 const void *addrptr = NULL;
452
453 assert(buf);
454 assert(len);
455 buf[0] = '\000';
456
457 switch (addr->addr.sa.sa_family) {
458#if COAP_IPV4_SUPPORT
459 case AF_INET:
460 if (len < INET_ADDRSTRLEN)
461 return buf;
462 addrptr = &addr->addr.sin.sin_addr;
463 break;
464#endif /* COAP_IPV4_SUPPORT */
465#if COAP_IPV6_SUPPORT
466 case AF_INET6:
467 if (len < INET6_ADDRSTRLEN)
468 return buf;
469 addrptr = &addr->addr.sin6.sin6_addr;
470 break;
471#endif /* COAP_IPV6_SUPPORT */
472#if COAP_AF_UNIX_SUPPORT
473 case AF_UNIX:
474 snprintf(buf, len, "%s", addr->addr.cun.sun_path);
475 return buf;
476#endif /* COAP_AF_UNIX_SUPPORT */
477#if COAP_AF_LLC_SUPPORT
478 case AF_LLC:
479 snprintf((char *)buf, len, "llc[%02x:%02x:%02x:%02x:%02x:%02x]",
480 addr->addr.llc.sllc_mac[0],
481 addr->addr.llc.sllc_mac[1],
482 addr->addr.llc.sllc_mac[2],
483 addr->addr.llc.sllc_mac[3],
484 addr->addr.llc.sllc_mac[4],
485 addr->addr.llc.sllc_mac[5]);
486 return buf;
487#endif /* COAP_AF_LLC_SUPPORT */
488 default:
489 /* Include trailing NULL if possible */
490 memcpy(buf, "(unknown address type)", min(22+1, len));
491 buf[len-1] = '\000';
492 return buf;
493 }
494
495 /* Cast needed for Windows, since it doesn't have the correct API signature. */
496 if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)buf, len) == 0) {
497 coap_log_err("coap_print_ip_addr: inet_ntop\n");
498 buf[0] = '\000';
499 return buf;
500 }
501 return buf;
502
503#else /* HAVE_ARPA_INET_H */
504
505# if defined(RIOT_VERSION)
506 assert(buf);
507 assert(len);
508 buf[0] = '\000';
509
510 switch (addr->riot.family) {
511#if COAP_IPV4_SUPPORT
512 case AF_INET:
513 if (ipv4_addr_to_str(buf, (ipv4_addr_t *)&addr->riot.addr.ipv4, (size_t)len) == NULL) {
514 goto error;
515 }
516 break;
517#endif /* COAP_IPV4_SUPPORT */
518#if COAP_IPV6_SUPPORT
519 case AF_INET6:
520 if (ipv6_addr_to_str(buf, (ipv6_addr_t *)&addr->riot.addr.ipv6, (size_t)len) == NULL) {
521 goto error;
522 }
523 break;
524#endif /* COAP_IPV6_SUPPORT */
525 default:
526 goto error;
527 }
528 return buf;
529
530error:
531 coap_log_err("coap_print_ip_addr: inet_ntop\n");
532 buf[0] = '\000';
533 return buf;
534
535# elif WITH_CONTIKI
536 char *p = buf;
537 uint8_t i;
538# if NETSTACK_CONF_WITH_IPV6
539 const char hex[] = "0123456789ABCDEF";
540
541 assert(buf);
542 assert(len);
543 buf[0] = '\000';
544 if (len < 40)
545 return 0;
546
547 for (i=0; i < 16; i += 2) {
548 if (i) {
549 *p++ = ':';
550 }
551 *p++ = hex[(addr->addr.u8[i] & 0xf0) >> 4];
552 *p++ = hex[(addr->addr.u8[i] & 0x0f)];
553 *p++ = hex[(addr->addr.u8[i+1] & 0xf0) >> 4];
554 *p++ = hex[(addr->addr.u8[i+1] & 0x0f)];
555 }
556 *p = '\000';
557# else /* WITH_UIP6 */
558# warning "IPv4 network addresses will not be included in debug output"
559
560 if (len < 21) {
561 return buf;
562 }
563# endif /* WITH_UIP6 */
564 return buf;
565
566# elif WITH_LWIP
567
568 assert(buf);
569 assert(len);
570 buf[0] = '\000';
571
572 switch (IP_GET_TYPE(&addr->addr)) {
573#if LWIP_IPV4
574 case IPADDR_TYPE_V4:
575 if (len < IP4ADDR_STRLEN_MAX)
576 return buf;
577 memcpy(buf, ip4addr_ntoa(ip_2_ip4(&addr->addr)), IP4ADDR_STRLEN_MAX);
578 break;
579#endif /* LWIP_IPV4 */
580#if LWIP_IPV6
581 case IPADDR_TYPE_V6:
582 case IPADDR_TYPE_ANY:
583 if (len < 40)
584 return buf;
585#if LWIP_IPV4
586 memcpy(buf, ip6addr_ntoa(&addr->addr.u_addr.ip6), 40);
587#else /* LWIP_IPV4 */
588 memcpy(buf, ip6addr_ntoa(&addr->addr), 40);
589#endif /* LWIP_IPV4 */
590 break;
591#endif /* LWIP_IPV6 */
592 }
593 return buf;
594
595# else /* ! WITH_CONTIKI && ! WITH_LWIP */
596
597 (void)addr;
598 (void)len;
599
600 /* TODO: output addresses manually */
601# warning "inet_ntop() not available, network addresses will not be included in debug output"
602# endif /* WITH_CONTIKI */
603 buf[0] = '\000';
604 return buf;
605#endif
606}
607
609static const char *
610msg_type_string(uint16_t t) {
611 static const char *types[] = { "CON", "NON", "ACK", "RST", "???" };
612
613 return types[min(t, sizeof(types)/sizeof(char *) - 1)];
614}
615
617static const char *
618msg_code_string(uint16_t c) {
619 static const char *methods[] = { "0.00", "GET", "POST", "PUT", "DELETE",
620 "FETCH", "PATCH", "iPATCH"
621 };
622 static const char *signals[] = { "7.00", "CSM", "Ping", "Pong", "Release",
623 "Abort"
624 };
625 static char buf[5];
626
627 if (c < sizeof(methods)/sizeof(const char *)) {
628 return methods[c];
629 } else if (c >= 224 && c - 224 < (int)(sizeof(signals)/sizeof(const char *))) {
630 return signals[c-224];
631 } else {
632 snprintf(buf, sizeof(buf), "%u.%02u", (unsigned)((c >> 5) & 0x7),
633 (unsigned)(c & 0x1f));
634 return buf;
635 }
636}
637
639const char *
641 struct option_desc_t {
642 uint16_t value;
643 const char *name;
644 };
645
646 static struct option_desc_t options[] = {
647 { COAP_OPTION_IF_MATCH, "If-Match" },
648 { COAP_OPTION_URI_HOST, "Uri-Host" },
649 { COAP_OPTION_ETAG, "ETag" },
650 { COAP_OPTION_IF_NONE_MATCH, "If-None-Match" },
651 { COAP_OPTION_OBSERVE, "Observe" },
652 { COAP_OPTION_URI_PORT, "Uri-Port" },
653 { COAP_OPTION_LOCATION_PATH, "Location-Path" },
654 { COAP_OPTION_OSCORE, "Oscore" },
655 { COAP_OPTION_URI_PATH, "Uri-Path" },
656 { COAP_OPTION_CONTENT_FORMAT, "Content-Format" },
657 { COAP_OPTION_URI_PATH_ABB, "Uri-Path-Abbrev" },
658 { COAP_OPTION_MAXAGE, "Max-Age" },
659 { COAP_OPTION_URI_QUERY, "Uri-Query" },
660 { COAP_OPTION_HOP_LIMIT, "Hop-Limit" },
661 { COAP_OPTION_ACCEPT, "Accept" },
662 { COAP_OPTION_LOCATION_QUERY, "Location-Query" },
663 { COAP_OPTION_BLOCK2, "Block2" },
664 { COAP_OPTION_BLOCK1, "Block1" },
665 { COAP_OPTION_SIZE2, "Size2" },
666 { COAP_OPTION_PROXY_URI, "Proxy-Uri" },
667 { COAP_OPTION_PROXY_SCHEME, "Proxy-Scheme" },
668 { COAP_OPTION_SIZE1, "Size1" },
669 { COAP_OPTION_ECHO, "Echo" },
670 { COAP_OPTION_NORESPONSE, "No-Response" },
671 { COAP_OPTION_RTAG, "Request-Tag" },
672 { COAP_OPTION_Q_BLOCK1, "Q-Block1" },
673 { COAP_OPTION_Q_BLOCK2, "Q-Block2" }
674 };
675
676 static struct option_desc_t options_csm[] = {
677 { COAP_SIG_OPT_MAX_MESSAGE_SIZE, "Max-Message-Size" },
678 { COAP_SIG_OPT_BLOCK_WISE_TRANSFER, "Block-Wise-Transfer" },
679 { COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH, "Extended-Token-Length" }
680 };
681
682 static struct option_desc_t options_pingpong[] = {
683 { COAP_SIG_OPT_CUSTODY, "Custody" }
684 };
685
686 static struct option_desc_t options_release[] = {
687 { COAP_SIG_OPT_ALTERNATIVE_ADDRESS, "Alternative-Address" },
688 { COAP_SIG_OPT_HOLD_OFF, "Hold-Off" }
689 };
690
691 static struct option_desc_t options_abort[] = {
692 { COAP_SIG_OPT_BAD_CSM_OPTION, "Bad-CSM-Option" }
693 };
694
695 static char buf[6];
696 size_t i;
697
698 if (code == COAP_SIGNALING_CODE_CSM) {
699 for (i = 0; i < sizeof(options_csm)/sizeof(struct option_desc_t); i++) {
700 if (number == options_csm[i].value) {
701 return options_csm[i].name;
702 }
703 }
704 } else if (code == COAP_SIGNALING_CODE_PING || code == COAP_SIGNALING_CODE_PONG) {
705 for (i = 0; i < sizeof(options_pingpong)/sizeof(struct option_desc_t); i++) {
706 if (number == options_pingpong[i].value) {
707 return options_pingpong[i].name;
708 }
709 }
710 } else if (code == COAP_SIGNALING_CODE_RELEASE) {
711 for (i = 0; i < sizeof(options_release)/sizeof(struct option_desc_t); i++) {
712 if (number == options_release[i].value) {
713 return options_release[i].name;
714 }
715 }
716 } else if (code == COAP_SIGNALING_CODE_ABORT) {
717 for (i = 0; i < sizeof(options_abort)/sizeof(struct option_desc_t); i++) {
718 if (number == options_abort[i].value) {
719 return options_abort[i].name;
720 }
721 }
722 } else {
723 /* search option_type in list of known options */
724 for (i = 0; i < sizeof(options)/sizeof(struct option_desc_t); i++) {
725 if (number == options[i].value) {
726 return options[i].name;
727 }
728 }
729 }
730 /* unknown option type, just print to buf */
731 snprintf(buf, sizeof(buf), "%u", number);
732 return buf;
733}
734
735static unsigned int
736print_content_format(unsigned int format_type,
737 unsigned char *result, unsigned int buflen) {
738 struct desc_t {
739 unsigned int type;
740 const char *name;
741 };
742
743 static struct desc_t formats[] = {
744 { COAP_MEDIATYPE_TEXT_PLAIN, "text/plain" },
745 { COAP_MEDIATYPE_APPLICATION_LINK_FORMAT, "application/link-format" },
746 { COAP_MEDIATYPE_APPLICATION_XML, "application/xml" },
747 { COAP_MEDIATYPE_APPLICATION_OCTET_STREAM, "application/octet-stream" },
748 { COAP_MEDIATYPE_APPLICATION_RDF_XML, "application/rdf+xml" },
749 { COAP_MEDIATYPE_APPLICATION_EXI, "application/exi" },
750 { COAP_MEDIATYPE_APPLICATION_JSON, "application/json" },
751 { COAP_MEDIATYPE_APPLICATION_CBOR, "application/cbor" },
752 { COAP_MEDIATYPE_APPLICATION_CWT, "application/cwt" },
753 { COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON, "application/coap-group+json" },
754 { COAP_MEDIATYPE_APPLICATION_COSE_SIGN, "application/cose; cose-type=\"cose-sign\"" },
755 { COAP_MEDIATYPE_APPLICATION_COSE_SIGN1, "application/cose; cose-type=\"cose-sign1\"" },
756 { COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT, "application/cose; cose-type=\"cose-encrypt\"" },
757 { COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0, "application/cose; cose-type=\"cose-encrypt0\"" },
758 { COAP_MEDIATYPE_APPLICATION_COSE_MAC, "application/cose; cose-type=\"cose-mac\"" },
759 { COAP_MEDIATYPE_APPLICATION_COSE_MAC0, "application/cose; cose-type=\"cose-mac0\"" },
760 { COAP_MEDIATYPE_APPLICATION_COSE_KEY, "application/cose-key" },
761 { COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET, "application/cose-key-set" },
762 { COAP_MEDIATYPE_APPLICATION_SENML_JSON, "application/senml+json" },
763 { COAP_MEDIATYPE_APPLICATION_SENSML_JSON, "application/sensml+json" },
764 { COAP_MEDIATYPE_APPLICATION_SENML_CBOR, "application/senml+cbor" },
765 { COAP_MEDIATYPE_APPLICATION_SENSML_CBOR, "application/sensml+cbor" },
766 { COAP_MEDIATYPE_APPLICATION_SENML_EXI, "application/senml-exi" },
767 { COAP_MEDIATYPE_APPLICATION_SENSML_EXI, "application/sensml-exi" },
768 { COAP_MEDIATYPE_APPLICATION_SENML_XML, "application/senml+xml" },
769 { COAP_MEDIATYPE_APPLICATION_SENSML_XML, "application/sensml+xml" },
770 { COAP_MEDIATYPE_APPLICATION_DOTS_CBOR, "application/dots+cbor" },
771 { COAP_MEDIATYPE_APPLICATION_ACE_CBOR, "application/ace+cbor" },
772 { COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ, "application/missing-blocks+cbor-seq" },
773 { COAP_MEDIATYPE_APPLICATION_OSCORE, "application/oscore" },
774 { COAP_MEDIATYPE_APPLICATION_PKCS7_SKG, "application/pkcs7-mime; smime-type=server-generated-key" },
775 { COAP_MEDIATYPE_APPLICATION_PKCS7_CERTS, "application/pkcs7-mime; smime-type=certs-only" },
776 { COAP_MEDIATYPE_APPLICATION_PKCS8, "application/pkcs8" },
777 { COAP_MEDIATYPE_APPLICATION_CSRATTRS, "application/csrattrs" },
778 { COAP_MEDIATYPE_APPLICATION_PKCS10, "application/pkcs10" },
779 { COAP_MEDIATYPE_APPLICATION_PKIX_CERT, "application/pkix-cert" },
780 { 75, "application/dcaf+cbor" }
781 };
782
783 size_t i;
784 size_t len = 0;
785
786 /* search format_type in list of known content formats */
787 for (i = 0; i < sizeof(formats)/sizeof(struct desc_t); i++) {
788 if (format_type == formats[i].type) {
789 return coap_snprintf((char *)result, buflen, &len, "%s", formats[i].name);
790 }
791 }
792
793 /* unknown content format, just print numeric value to buf */
794 return coap_snprintf((char *)result, buflen, &len, "%u", format_type);
795}
796
803is_binary(int content_format) {
804 return !(content_format == -1 ||
805 content_format == COAP_MEDIATYPE_TEXT_PLAIN ||
806 content_format == COAP_MEDIATYPE_APPLICATION_LINK_FORMAT ||
807 content_format == COAP_MEDIATYPE_APPLICATION_XML ||
808 content_format == COAP_MEDIATYPE_APPLICATION_JSON);
809}
810
811#define COAP_DO_SHOW_OUTPUT_LINE \
812 do { \
813 if (use_fprintf_for_show_pdu) { \
814 fprintf(COAP_DEBUG_FD, "%s", outbuf); \
815 } \
816 else { \
817 coap_log(level, "%s", outbuf); \
818 } \
819 } while (0)
820
821/*
822 * It is possible to override the output debug buffer size and hence control
823 * the amount of information printed out about a CoAP PDU.
824 * Note: Adding a byte may be insufficient to output the next byte of the PDU.
825 *
826 * This is done by the adding of a -DCOAP_DEBUG_BUF_SIZE=nnnn option to the
827 * CPPFLAGS parameter that is optionally used on the ./configure command line.
828 *
829 * E.g. ./configure CPPFLAGS="-DCOAP_DEBUG_BUF_SIZE=4096"
830 *
831 */
832
833#if COAP_DEBUG_BUF_SIZE < 5
834#error "COAP_DEBUG_BUF_SIZE must be at least 5, should be >= 32 to be useful"
835#endif /* COAP_DEBUG_BUF_SIZE < 5 */
836
837/* Proxy-Uri: can be 1034 bytes long */
838#if COAP_DEBUG_BUF_SIZE < 1035
839#define USE_BUF_SIZE COAP_DEBUG_BUF_SIZE
840#else
841#define USE_BUF_SIZE 1035
842#endif
843
844void
846#if COAP_CONSTRAINED_STACK
847 /* Proxy-Uri: can be 1034 bytes long */
848 /* buf and outbuf can be protected by m_show_pdu if needed */
849 static unsigned char buf[USE_BUF_SIZE];
850 static char outbuf[COAP_DEBUG_BUF_SIZE];
851#else /* ! COAP_CONSTRAINED_STACK */
852 /* Proxy-Uri: can be 1034 bytes long */
853 unsigned char buf[USE_BUF_SIZE];
854 char outbuf[COAP_DEBUG_BUF_SIZE];
855#endif /* ! COAP_CONSTRAINED_STACK */
856 size_t buf_len = 0; /* takes the number of bytes written to buf */
857 int have_options = 0;
858 uint32_t i;
859 coap_opt_iterator_t opt_iter;
860 coap_opt_t *option;
861 int content_format = -1;
862 size_t data_len;
863 const uint8_t *data;
864 uint32_t opt_len;
865 const uint8_t *opt_val;
866 size_t outbuflen = 0;
867 int is_oscore_payload = 0;
868 const char *exp;
869 uint32_t value;
870
871 /* Save time if not needed */
872 if (level > coap_get_log_level())
873 return;
874
875#if COAP_THREAD_SAFE
876 coap_mutex_lock(&m_show_pdu);
877#endif /* COAP_THREAD_SAFE */
878 if (!pdu->session || COAP_PROTO_NOT_RELIABLE(pdu->session->proto)) {
879 snprintf(outbuf, sizeof(outbuf), "v:%d t:%s c:%s i:%04x {",
881 msg_code_string(pdu->code), pdu->mid);
882 } else if (pdu->session->proto == COAP_PROTO_WS ||
883 pdu->session->proto == COAP_PROTO_WSS) {
884 if (pdu->type != COAP_MESSAGE_CON)
885 coap_log_alert("WebSocket: type != CON\n");
886 snprintf(outbuf, sizeof(outbuf), "v:WebSocket c:%s {",
887 msg_code_string(pdu->code));
888 } else {
889 if (pdu->type != COAP_MESSAGE_CON)
890 coap_log_alert("Reliable: type != CON\n");
891 snprintf(outbuf, sizeof(outbuf), "v:Reliable c:%s {",
892 msg_code_string(pdu->code));
893 }
894
895 outbuflen = strlen(outbuf);
896 for (i = 0; i < pdu->actual_token.length; i++) {
897 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen,
898 "%02x", pdu->actual_token.s[i]);
899 }
900 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, "}");
901
902 /* show options, if any */
904
905 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, " [");
906 while ((option = coap_option_next(&opt_iter))) {
907 buf[0] = '\000';
908 buf_len = 0;
909 if (!have_options) {
910 have_options = 1;
911 } else {
912 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, ",");
913 }
914
915 if (pdu->code == COAP_SIGNALING_CODE_CSM) {
916 switch ((coap_sig_csm_opt_t)opt_iter.number) {
919 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u",
921 coap_opt_length(option)));
922 break;
924 default:
925 break;
926 }
927 } else if (pdu->code == COAP_SIGNALING_CODE_PING ||
929 switch ((coap_sig_ping_opt_t)opt_iter.number) {
931 default:
932 break;
933 }
934 } else if (pdu->code == COAP_SIGNALING_CODE_RELEASE) {
935 switch ((coap_sig_release_opt_t)opt_iter.number) {
937 buf_len = print_readable(coap_opt_value(option),
938 coap_opt_length(option),
939 buf, sizeof(buf), 0);
940 break;
942 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u",
944 coap_opt_length(option)));
945 break;
946 default:
947 break;
948 }
949 } else if (pdu->code == COAP_SIGNALING_CODE_ABORT) {
950 switch ((coap_sig_abort_opt_t)opt_iter.number) {
952 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u",
954 coap_opt_length(option)));
955 break;
956 default:
957 break;
958 }
959 } else {
960 switch ((coap_code_opt_num_t)opt_iter.number) {
963 content_format = (int)coap_decode_var_bytes(coap_opt_value(option),
964 coap_opt_length(option));
965
966 buf_len = print_content_format(content_format, buf, sizeof(buf));
967 break;
968
973 /* split block option into number/more/size where more is the
974 * letter M if set, the _ otherwise */
975 if (COAP_OPT_BLOCK_SZX(option) == 7) {
976 if (coap_get_data(pdu, &data_len, &data))
977 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u/%c/BERT(%" PRIuS ")",
978 coap_opt_block_num(option), /* block number */
979 COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
980 data_len);
981 else
982 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u/%c/BERT",
983 coap_opt_block_num(option), /* block number */
984 COAP_OPT_BLOCK_MORE(option) ? 'M' : '_'); /* M bit */
985 } else {
986 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u/%c/%u",
987 coap_opt_block_num(option), /* block number */
988 COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
989 (unsigned)(1u << (COAP_OPT_BLOCK_SZX(option) + 4))); /* block size */
990 }
991
992 break;
993
995 opt_len = coap_opt_length(option);
996 buf[0] = '\000';
997 if (opt_len) {
998 size_t ofs = 1;
999 size_t cnt;
1000
1001 opt_val = coap_opt_value(option);
1002 if (opt_val[0] & 0x20) {
1003 /* Group Flag */
1004 snprintf((char *)buf, sizeof(buf), "grp");
1005 }
1006 if (opt_val[0] & 0x07) {
1007 /* Partial IV */
1008 cnt = opt_val[0] & 0x07;
1009 if (cnt > opt_len - ofs)
1010 goto no_more;
1011 buf_len = strlen((char *)buf);
1012 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%spIV=0x",
1013 buf_len ? "," : "");
1014 for (i = 0; (uint32_t)i < cnt; i++) {
1015 coap_snprintf((char *)buf, sizeof(buf), &buf_len,
1016 "%02x", opt_val[ofs + i]);
1017 }
1018 ofs += cnt;
1019 }
1020 if (opt_val[0] & 0x10) {
1021 /* kid context */
1022 if (ofs >= opt_len)
1023 goto no_more;
1024 cnt = opt_val[ofs];
1025 if (cnt > opt_len - ofs - 1)
1026 goto no_more;
1027 ofs++;
1028 buf_len = strlen((char *)buf);
1029 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%skc=0x",
1030 buf_len ? "," : "");
1031 for (i = 0; (uint32_t)i < cnt; i++) {
1032 coap_snprintf((char *)buf, sizeof(buf), &buf_len,
1033 "%02x", opt_val[ofs + i]);
1034 }
1035 ofs += cnt;
1036 }
1037 if (opt_val[0] & 0x08) {
1038 /* kid */
1039 if (ofs >= opt_len)
1040 goto no_more;
1041 cnt = opt_len - ofs;
1042 buf_len = strlen((char *)buf);
1043 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%skid=0x",
1044 buf_len ? "," : "");
1045 for (i = 0; (uint32_t)i < cnt; i++) {
1046 coap_snprintf((char *)buf, sizeof(buf), &buf_len,
1047 "%02x", opt_val[ofs + i]);
1048 }
1049 }
1050 }
1051no_more:
1052 buf_len = strlen((char *)buf);
1053 is_oscore_payload = 1;
1054 break;
1055
1057 case COAP_OPTION_MAXAGE:
1059 case COAP_OPTION_SIZE1:
1060 case COAP_OPTION_SIZE2:
1062 if (coap_opt_length(option)) {
1063 /* show values as unsigned decimal value */
1064 coap_snprintf((char *)buf, sizeof(buf), &buf_len, "%u",
1066 coap_opt_length(option)));
1067 }
1068 break;
1069
1071 case COAP_OPTION_ETAG:
1072 case COAP_OPTION_ECHO:
1074 case COAP_OPTION_RTAG:
1075 opt_len = coap_opt_length(option);
1076 opt_val = coap_opt_value(option);
1077 snprintf((char *)buf, sizeof(buf), "0x");
1078 buf_len = strlen((char *)buf);
1079 for (i = 0; (uint32_t)i < opt_len; i++) {
1080 coap_snprintf((char *)buf, sizeof(buf), &buf_len,
1081 "%02x", opt_val[i]);
1082 }
1083 break;
1085 value = coap_decode_var_bytes(coap_opt_value(option),
1086 coap_opt_length(option));
1088 if (!exp) {
1090 }
1091 if (exp) {
1092 snprintf((char *)&buf, sizeof(buf), "%s", exp);
1093 } else {
1094 snprintf((char *)&buf, sizeof(buf), "(%" PRIu32 ")", value);
1095 }
1096 buf_len = strlen((char *)buf);
1097 break;
1105 buf_len = print_readable(coap_opt_value(option),
1106 coap_opt_length(option),
1107 buf, sizeof(buf), 0);
1108 break;
1110 case COAP_OPTION_EDHOC:
1111 default:
1112 buf_len = print_readable(coap_opt_value(option),
1113 coap_opt_length(option),
1114 buf, sizeof(buf), 1);
1115 }
1116 }
1117 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen,
1118 " %s:%.*s", coap_option_string(pdu->code, opt_iter.number),
1119 (int)buf_len, buf);
1120 }
1121
1122 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, " ]");
1123
1124 if (coap_get_data(pdu, &data_len, &data)) {
1126 /* Only output data if wanted */
1127 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, " :: ");
1128 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen,
1129 "data length %"PRIuS " (data suppressed)\n", data_len);
1131#if COAP_THREAD_SAFE
1132 coap_mutex_unlock(&m_show_pdu);
1133#endif /* COAP_THREAD_SAFE */
1134 return;
1135 }
1136
1137 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, " :: ");
1138
1139 if (is_binary(content_format) || !isprint(data[0]) || is_oscore_payload) {
1140 size_t keep_data_len = data_len;
1141 const uint8_t *keep_data = data;
1142
1143 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen,
1144 "binary data length %"PRIuS "\n", data_len);
1146 /*
1147 * Output hex dump of binary data as a continuous entry
1148 */
1149 outbuf[0] = '\000';
1150 snprintf(outbuf, sizeof(outbuf), "<<");
1151 outbuflen = strlen(outbuf);
1152 while (data_len--) {
1153 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, "%02x", *data++);
1154 }
1155 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, ">>");
1156 data_len = keep_data_len;
1157 data = keep_data;
1158 if (outbuflen == sizeof(outbuf)-1)
1159 outbuflen--;
1160 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, "\n");
1162 /*
1163 * Output ascii readable (if possible), immediately under the
1164 * hex value of the character output above to help binary debugging
1165 */
1166 outbuf[0] = '\000';
1167 snprintf(outbuf, sizeof(outbuf), "<<");
1168 outbuflen = strlen(outbuf);
1169 while (data_len--) {
1170 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen,
1171 "%c ", isprint(*data) ? *data : '.');
1172 data++;
1173 }
1174 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, ">>");
1175 } else {
1176 size_t max_length;
1177
1178 outbuflen = strlen(outbuf);
1179 max_length = sizeof(outbuf)-outbuflen;
1180 if (max_length > 1) {
1181 outbuf[outbuflen++] = '\'';
1182 outbuf[outbuflen] = '\000';
1183 max_length--;
1184 }
1185 if (max_length > 1) {
1186 outbuflen += print_readable(data, data_len,
1187 (unsigned char *)&outbuf[outbuflen],
1188 max_length, 0);
1189 }
1190 /* print_readable may be handling unprintables - hence headroom of 4 */
1191 if (outbuflen < sizeof(outbuf)-4-1) {
1192 outbuf[outbuflen++] = '\'';
1193 outbuf[outbuflen] = '\000';
1194 }
1195 }
1196 }
1197
1198 if (outbuflen == sizeof(outbuf)-1)
1199 outbuflen--;
1200 coap_snprintf(outbuf, sizeof(outbuf), &outbuflen, "\n");
1202
1203#if COAP_THREAD_SAFE
1204 coap_mutex_unlock(&m_show_pdu);
1205#endif /* COAP_THREAD_SAFE */
1206}
1207
1208void
1210 char buffer[128];
1211 coap_string_tls_version(buffer, sizeof(buffer));
1212 coap_log(level, "%s\n", buffer);
1213}
1214
1215char *
1216coap_string_tls_version(char *buffer, size_t bufsize) {
1218 char beta[8];
1219 char sub[2];
1220 char b_beta[8];
1221 char b_sub[2];
1222
1223 switch (tls_version->type) {
1225 snprintf(buffer, bufsize, "TLS Library: None");
1226 break;
1228 snprintf(buffer, bufsize, "TLS Library: TinyDTLS - runtime %lu.%lu.%lu, "
1229 "libcoap built for %lu.%lu.%lu",
1230 (unsigned long)(tls_version->version >> 16),
1231 (unsigned long)((tls_version->version >> 8) & 0xff),
1232 (unsigned long)(tls_version->version & 0xff),
1233 (unsigned long)(tls_version->built_version >> 16),
1234 (unsigned long)((tls_version->built_version >> 8) & 0xff),
1235 (unsigned long)(tls_version->built_version & 0xff));
1236 break;
1238 switch (tls_version->version &0xf) {
1239 case 0:
1240 strcpy(beta, "-dev");
1241 break;
1242 case 0xf:
1243 strcpy(beta, "");
1244 break;
1245 default:
1246 strcpy(beta, "-beta");
1247 beta[5] = (tls_version->version &0xf) + '0';
1248 beta[6] = '\000';
1249 break;
1250 }
1251 sub[0] = ((tls_version->version >> 4) & 0xff) ?
1252 ((tls_version->version >> 4) & 0xff) + 'a' -1 : '\000';
1253 sub[1] = '\000';
1254 switch (tls_version->built_version &0xf) {
1255 case 0:
1256 strcpy(b_beta, "-dev");
1257 break;
1258 case 0xf:
1259 strcpy(b_beta, "");
1260 break;
1261 default:
1262 strcpy(b_beta, "-beta");
1263 b_beta[5] = (tls_version->built_version &0xf) + '0';
1264 b_beta[6] = '\000';
1265 break;
1266 }
1267 b_sub[0] = ((tls_version->built_version >> 4) & 0xff) ?
1268 ((tls_version->built_version >> 4) & 0xff) + 'a' -1 : '\000';
1269 b_sub[1] = '\000';
1270 snprintf(buffer, bufsize, "TLS Library: OpenSSL - runtime "
1271 "%lu.%lu.%lu%s%s, libcoap built for %lu.%lu.%lu%s%s",
1272 (unsigned long)(tls_version->version >> 28),
1273 (unsigned long)((tls_version->version >> 20) & 0xff),
1274 (unsigned long)((tls_version->version >> 12) & 0xff), sub, beta,
1275 (unsigned long)(tls_version->built_version >> 28),
1276 (unsigned long)((tls_version->built_version >> 20) & 0xff),
1277 (unsigned long)((tls_version->built_version >> 12) & 0xff),
1278 b_sub, b_beta);
1279 break;
1281 snprintf(buffer, bufsize, "TLS Library: GnuTLS - runtime %lu.%lu.%lu, "
1282 "libcoap built for %lu.%lu.%lu",
1283 (unsigned long)(tls_version->version >> 16),
1284 (unsigned long)((tls_version->version >> 8) & 0xff),
1285 (unsigned long)(tls_version->version & 0xff),
1286 (unsigned long)(tls_version->built_version >> 16),
1287 (unsigned long)((tls_version->built_version >> 8) & 0xff),
1288 (unsigned long)(tls_version->built_version & 0xff));
1289 break;
1291 snprintf(buffer, bufsize, "TLS Library: Mbed TLS - runtime %lu.%lu.%lu, "
1292 "libcoap built for %lu.%lu.%lu",
1293 (unsigned long)(tls_version->version >> 24),
1294 (unsigned long)((tls_version->version >> 16) & 0xff),
1295 (unsigned long)((tls_version->version >> 8) & 0xff),
1296 (unsigned long)(tls_version->built_version >> 24),
1297 (unsigned long)((tls_version->built_version >> 16) & 0xff),
1298 (unsigned long)((tls_version->built_version >> 8) & 0xff));
1299 break;
1301 snprintf(buffer, bufsize, "TLS Library: wolfSSL - runtime %lu.%lu.%lu, "
1302 "libcoap built for %lu.%lu.%lu",
1303 (unsigned long)(tls_version->version >> 24),
1304 (unsigned long)((tls_version->version >> 12) & 0xfff),
1305 (unsigned long)((tls_version->version >> 0) & 0xfff),
1306 (unsigned long)(tls_version->built_version >> 24),
1307 (unsigned long)((tls_version->built_version >> 12) & 0xfff),
1308 (unsigned long)((tls_version->built_version >> 0) & 0xfff));
1309 break;
1311 snprintf(buffer, bufsize, "TLS Library: openHiTLS - runtime %lu.%lu.%lu, "
1312 "libcoap built for %lu.%lu.%lu",
1313 (unsigned long)((tls_version->version >> 28) & 0x0f),
1314 (unsigned long)((tls_version->version >> 20) & 0xff),
1315 (unsigned long)((tls_version->version >> 16) & 0x0f),
1316 (unsigned long)((tls_version->built_version >> 28) & 0x0f),
1317 (unsigned long)((tls_version->built_version >> 20) & 0xff),
1318 (unsigned long)((tls_version->built_version >> 16) & 0x0f));
1319 break;
1320 default:
1321 snprintf(buffer, bufsize, "Library type %d unknown", tls_version->type);
1322 break;
1323 }
1324 return buffer;
1325}
1326
1327char *
1328coap_string_tls_support(char *buffer, size_t bufsize) {
1329 const int have_tls = coap_tls_is_supported();
1330 const int have_dtls = coap_dtls_is_supported();
1331 const int have_psk = coap_dtls_psk_is_supported();
1332 const int have_pki = coap_dtls_pki_is_supported();
1333 const int have_pkcs11 = coap_dtls_pkcs11_is_supported();
1334 const int have_rpk = coap_dtls_rpk_is_supported();
1335 const int have_cid = coap_dtls_cid_is_supported();
1336 const int have_oscore = coap_oscore_is_supported();
1337 const int have_ws = coap_ws_is_supported();
1338
1339 if (have_dtls == 0 && have_tls == 0) {
1340 snprintf(buffer, bufsize, "(No DTLS or TLS support)\n(%sOSCORE)\n(%sWebSockets)",
1341 have_oscore ? "Have " : "No ",
1342 have_ws ? "Have " : "No ");
1343 return buffer;
1344 }
1345 snprintf(buffer, bufsize,
1346 "(%sDTLS and %sTLS support; %sPSK, %sPKI, %sPKCS11, %sRPK and %sCID support)\n(%sOSCORE)\n(%sWebSockets)",
1347 have_dtls ? "" : "No ",
1348 have_tls ? "" : "no ",
1349 have_psk ? "" : "no ",
1350 have_pki ? "" : "no ",
1351 have_pkcs11 ? "" : "no ",
1352 have_rpk ? "" : "no ",
1353 have_cid ? "" : "no ",
1354 have_oscore ? "Have " : "No ",
1355 have_ws ? "Have " : "No ");
1356 return buffer;
1357}
1358
1360
1361void
1363 log_handler = handler;
1364}
1365
1366#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1367/* Visible to only this thread */
1368extern COAP_THREAD_LOCAL_VAR uint32_t thread_no;
1369/* Visible across all threads */
1370extern uint32_t max_thread_no;
1371#endif /* COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING */
1372
1373void
1374coap_log_impl(coap_log_t level, const char *format, ...) {
1375
1376#if COAP_THREAD_SAFE
1377 coap_mutex_lock(&m_log_impl);
1378#endif /* COAP_THREAD_SAFE */
1379
1380 if (log_handler) {
1381#if COAP_CONSTRAINED_STACK
1382 /* message can be protected by m_log_impl if needed */
1383 static char message[COAP_DEBUG_BUF_SIZE];
1384#else /* ! COAP_CONSTRAINED_STACK */
1385 char message[COAP_DEBUG_BUF_SIZE];
1386#endif /* ! COAP_CONSTRAINED_STACK */
1387 va_list ap;
1388 va_start(ap, format);
1389
1390#ifdef RIOT_VERSION
1391 flash_vsnprintf(message, sizeof(message), format, ap);
1392#else /* !RIOT_VERSION */
1393 vsnprintf(message, sizeof(message), format, ap);
1394#endif /* !RIOT_VERSION */
1395 va_end(ap);
1396 log_handler(level, message);
1397 } else {
1398 va_list ap;
1399 FILE *log_fd;
1400
1401 log_fd = level <= COAP_LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
1402
1403#ifndef RIOT_VERSION
1404 char timebuf[32];
1405 coap_tick_t now;
1406 size_t len;
1407
1408 coap_ticks(&now);
1409 len = print_timestamp(timebuf,sizeof(timebuf), now);
1410 if (len)
1411 fprintf(log_fd, "%.*s ", (int)len, timebuf);
1412#endif /* ! RIOT_VERSION */
1413
1414#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1415 if (thread_no == 0) {
1416 /*
1417 * All other call to coap_mutex_lock(&m_io_threads) immediately
1418 * by setting thread_no if 0. So deadlock should never occur.
1419 */
1420 coap_mutex_lock(&m_io_threads);
1421 thread_no = ++max_thread_no;
1422 coap_mutex_unlock(&m_io_threads);
1423 }
1424 fprintf(log_fd, "%2d ", thread_no);
1425#endif /* COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING */
1426
1427 fprintf(log_fd, "%s ", coap_log_level_desc(level));
1428
1429 va_start(ap, format);
1430#ifdef RIOT_VERSION
1431 flash_vfprintf(log_fd, format, ap);
1432#else /* !RIOT_VERSION */
1433 vfprintf(log_fd, format, ap);
1434#endif /* !RIOT_VERSION */
1435 va_end(ap);
1436 fflush(log_fd);
1437 }
1438
1439#if COAP_THREAD_SAFE
1440 coap_mutex_unlock(&m_log_impl);
1441#endif /* COAP_THREAD_SAFE */
1442}
1443
1444#ifndef COAP_DEBUG_INTERVAL_COUNT
1445#define COAP_DEBUG_INTERVAL_COUNT 10
1446#endif
1447
1453static uint16_t packet_loss_level = 0;
1454static size_t send_packet_count = 0;
1457static uint16_t packet_fail_level = 0;
1458static size_t recv_packet_count = 0;
1461static uint16_t packet_drop_level = 0;
1462
1463static int
1464coap_debug_set_packet_common(const char *loss_level, struct packet_num_interval *intervals,
1465 int *num_intervals, uint16_t *level, size_t *count) {
1466 const char *p = loss_level;
1467 char *end = NULL;
1468 int n = (int)strtol(p, &end, 10), i = 0;
1469
1470 *level = 0;
1471 *num_intervals = 0;
1472
1473 if (end == p || n < 0)
1474 return 0;
1475 if (*end == '%') {
1476 if (n > 100)
1477 n = 100;
1478 *level = n * 0xffff / 100;
1479 coap_log_debug("packet loss level set to %d%%\n", n);
1480 } else {
1481 if (n <= 0)
1482 return 0;
1483 while (i < COAP_DEBUG_INTERVAL_COUNT) {
1484 intervals[i].start = n;
1485 if (*end == '-') {
1486 p = end + 1;
1487 n = (int)strtol(p, &end, 10);
1488 if (end == p || n <= 0)
1489 return 0;
1490 }
1491 intervals[i++].end = n;
1492 if (*end == 0)
1493 break;
1494 if (*end != ',')
1495 return 0;
1496 p = end + 1;
1497 n = (int)strtol(p, &end, 10);
1498 if (end == p || n <= 0)
1499 return 0;
1500 }
1502 return 0;
1503 *num_intervals = i;
1504 }
1505 *count = 0;
1506 return 1;
1507}
1508
1509int
1514
1515int
1518 if (num_packet_loss_intervals > 0) {
1519 int i;
1520 for (i = 0; i < num_packet_loss_intervals; i++) {
1523 coap_log_debug("Following packet no %" PRIuS " dropped\n", send_packet_count);
1524 return 0;
1525 }
1526 }
1527 }
1528 if (packet_loss_level > 0) {
1529 uint16_t r = 0;
1530 coap_prng_lkd((uint8_t *)&r, 2);
1531 if (r < packet_loss_level) {
1532 coap_log_debug("Following packet no %"PRIuS " dropped\n", send_packet_count);
1533 return 0;
1534 }
1535 }
1536 if (num_packet_fail_intervals > 0) {
1537 int i;
1538 for (i = 0; i < num_packet_fail_intervals; i++) {
1541 coap_log_debug("Following packet no %"PRIuS " failed\n", send_packet_count);
1542 errno = ECONNREFUSED;
1543 return -1;
1544 }
1545 }
1546 }
1547 if (packet_fail_level > 0) {
1548 uint16_t r = 0;
1549 coap_prng_lkd((uint8_t *)&r, 2);
1550 if (r < packet_fail_level) {
1551 coap_log_debug("Following packet no %"PRIuS " failed\n", send_packet_count);
1552 errno = ECONNREFUSED;
1553 return -1;
1554 }
1555 }
1556 return 1;
1557}
1558
1559int
1564
1565int
1570
1571int
1574 if (num_packet_drop_intervals > 0) {
1575 int i;
1576 for (i = 0; i < num_packet_drop_intervals; i++) {
1579 coap_log_debug("Incoming packet no %" PRIuS " dropped\n", recv_packet_count);
1580 return 0;
1581 }
1582 }
1583 }
1584 if (packet_drop_level > 0) {
1585 uint16_t r = 0;
1586 coap_prng_lkd((uint8_t *)&r, 2);
1587 if (r < packet_drop_level) {
1588 coap_log_debug("Incoming packet no %"PRIuS " dropped\n", recv_packet_count);
1589 return 0;
1590 }
1591 }
1592 return 1;
1593}
1594
1595
1596void
uint16_t coap_address_get_port(const coap_address_t *addr)
Returns the port from addr in host byte order.
static uint16_t packet_loss_level
static int num_packet_drop_intervals
#define USE_BUF_SIZE
Definition coap_debug.c:839
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
int coap_debug_set_packet_drop(const char *drop_level)
Set the packet receive fail level for testing.
static int coap_debug_set_packet_common(const char *loss_level, struct packet_num_interval *intervals, int *num_intervals, uint16_t *level, size_t *count)
int coap_debug_recv_packet(void)
Check to see whether an incoming packet should be dropped or not.
static size_t send_packet_count
static coap_log_t maxlog
Definition coap_debug.c:63
const char * coap_option_string(coap_pdu_code_t code, coap_option_num_t number)
Returns a textual description of the option name.
Definition coap_debug.c:640
static coap_log_handler_t log_handler
int coap_debug_set_packet_fail(const char *fail_level)
Set the packet transmit fail level for testing.
struct packet_num_interval packet_fail_intervals[COAP_DEBUG_INTERVAL_COUNT]
COAP_STATIC_INLINE int is_binary(int content_format)
Returns 1 if the given content_format is either unknown or known to carry binary data.
Definition coap_debug.c:803
static int enable_data_for_show_pdu
Definition coap_debug.c:71
static struct packet_num_interval packet_loss_intervals[COAP_DEBUG_INTERVAL_COUNT]
int coap_snprintf(char *buffer, size_t buf_size, size_t *offset, const char *format,...)
The equivalent to snprintf() functionality, but returning the actual characters added and defining th...
Definition coap_debug.c:230
static const char * msg_code_string(uint16_t c)
Returns a textual description of the method or response code.
Definition coap_debug.c:618
#define COAP_DO_SHOW_OUTPUT_LINE
Definition coap_debug.c:811
static size_t print_readable(const uint8_t *data, size_t len, unsigned char *result, size_t buflen, int encode_always)
Definition coap_debug.c:192
static uint16_t packet_drop_level
static size_t strnlen(const char *s, size_t maxlen)
A length-safe strlen() fake.
Definition coap_debug.c:183
static uint16_t packet_fail_level
static const char * loglevels[]
Definition coap_debug.c:116
COAP_STATIC_INLINE size_t print_timestamp(char *s, size_t len, coap_tick_t t)
Definition coap_debug.c:160
#define min(a, b)
Definition coap_debug.c:255
static int num_packet_fail_intervals
static size_t recv_packet_count
struct packet_num_interval packet_drop_intervals[COAP_DEBUG_INTERVAL_COUNT]
static const char * msg_type_string(uint16_t t)
Returns a textual description of the message type t.
Definition coap_debug.c:610
static int use_fprintf_for_show_pdu
Definition coap_debug.c:70
static int num_packet_loss_intervals
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
void coap_debug_reset(void)
Reset all the defined logging parameters.
static unsigned int print_content_format(unsigned int format_type, unsigned char *result, unsigned int buflen)
Definition coap_debug.c:736
#define COAP_DEBUG_INTERVAL_COUNT
#define INET6_ADDRSTRLEN
Definition coap_debug.c:259
#define PRIuS
#define PRIu32
Library specific build wrapper for coap_internal.h.
#define coap_mutex_unlock(a)
#define coap_mutex_lock(a)
#define NULL
Definition coap_option.h:30
uint16_t coap_option_num_t
Definition coap_option.h:37
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
coap_sig_ping_opt_t
@ COAP_SIG_OPT_CUSTODY
coap_sig_csm_opt_t
@ COAP_SIG_OPT_BLOCK_WISE_TRANSFER
@ COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH
@ COAP_SIG_OPT_MAX_MESSAGE_SIZE
coap_sig_release_opt_t
@ COAP_SIG_OPT_ALTERNATIVE_ADDRESS
@ COAP_SIG_OPT_HOLD_OFF
coap_code_opt_num_t
Definition coap_option.h:70
@ COAP_OPTION_OBSERVE
Definition coap_option.h:75
@ COAP_OPTION_IF_NONE_MATCH
Definition coap_option.h:74
@ COAP_OPTION_ETAG
Definition coap_option.h:73
@ COAP_OPTION_EDHOC
Definition coap_option.h:89
@ COAP_OPTION_NORESPONSE
Definition coap_option.h:98
@ COAP_OPTION_MAXAGE
Definition coap_option.h:83
@ COAP_OPTION_SIZE2
Definition coap_option.h:92
@ COAP_OPTION_Q_BLOCK2
Definition coap_option.h:93
@ COAP_OPTION_PROXY_SCHEME
Definition coap_option.h:95
@ COAP_OPTION_HOP_LIMIT
Definition coap_option.h:85
@ COAP_OPTION_URI_PORT
Definition coap_option.h:76
@ COAP_OPTION_URI_HOST
Definition coap_option.h:72
@ COAP_OPTION_BLOCK2
Definition coap_option.h:90
@ COAP_OPTION_IF_MATCH
Definition coap_option.h:71
@ COAP_OPTION_SIZE1
Definition coap_option.h:96
@ COAP_OPTION_ECHO
Definition coap_option.h:97
@ COAP_OPTION_RTAG
Definition coap_option.h:99
@ COAP_OPTION_BLOCK1
Definition coap_option.h:91
@ COAP_OPTION_URI_PATH
Definition coap_option.h:79
@ COAP_OPTION_Q_BLOCK1
Definition coap_option.h:87
@ COAP_OPTION_OSCORE
Definition coap_option.h:78
@ COAP_OPTION_CONTENT_FORMAT
Definition coap_option.h:80
@ COAP_OPTION_LOCATION_QUERY
Definition coap_option.h:88
@ COAP_OPTION_URI_QUERY
Definition coap_option.h:84
@ COAP_OPTION_PROXY_URI
Definition coap_option.h:94
@ COAP_OPTION_LOCATION_PATH
Definition coap_option.h:77
@ COAP_OPTION_URI_PATH_ABB
Definition coap_option.h:81
@ COAP_OPTION_ACCEPT
Definition coap_option.h:86
coap_sig_abort_opt_t
@ COAP_SIG_OPT_BAD_CSM_OPTION
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt.
Definition coap_block.h:94
#define COAP_OPT_BLOCK_MORE(opt)
Returns the value of the More-bit of a Block option opt.
Definition coap_block.h:90
unsigned int coap_opt_block_num(const coap_opt_t *block_opt)
Returns the value of field num in the given block option block_opt.
Definition coap_block.c:52
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:149
coap_time_t coap_ticks_to_rt(coap_tick_t t)
Helper function that converts coap ticks to wallclock time.
Definition coap_time.c:123
uint64_t coap_ticks_to_rt_us(coap_tick_t t)
Helper function that converts coap ticks to POSIX wallclock time in us.
Definition coap_time.c:128
int coap_prng_lkd(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
Definition coap_prng.c:198
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
Definition coap_time.c:90
coap_tls_version_t * coap_get_tls_library_version(void)
Determine the type and version of the underlying (D)TLS library.
Definition coap_notls.c:101
@ COAP_TLS_LIBRARY_OPENHITLS
Using openHiTLS library.
Definition coap_dtls.h:81
@ COAP_TLS_LIBRARY_WOLFSSL
Using wolfSSL library.
Definition coap_dtls.h:80
@ COAP_TLS_LIBRARY_GNUTLS
Using GnuTLS library.
Definition coap_dtls.h:78
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
Definition coap_dtls.h:76
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition coap_dtls.h:75
@ COAP_TLS_LIBRARY_OPENSSL
Using OpenSSL library.
Definition coap_dtls.h:77
@ COAP_TLS_LIBRARY_MBEDTLS
Using Mbed TLS library.
Definition coap_dtls.h:79
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
Definition coap_encode.c:38
void coap_set_log_handler(coap_log_handler_t handler)
Add a custom log callback handler.
const char * coap_log_level_desc(coap_log_t level)
Get the current logging description.
Definition coap_debug.c:124
#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
char * coap_string_tls_version(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library linked with and built for version.
#define coap_log_alert(...)
Definition coap_debug.h:90
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
void coap_enable_pdu_data_output(int enable_data)
Defines whether the data is to be output or not for the coap_show_pdu() function.
Definition coap_debug.c:98
char * coap_string_tls_support(char *buffer, size_t bufsize)
Build a string containing the current (D)TLS library support.
#define COAP_MAX_LOGGING_LEVEL
Definition coap_debug.h:48
#define COAP_ERR_FD
Used for output for COAP_LOG_CRIT to COAP_LOG_EMERG.
Definition coap_debug.h:44
coap_log_t
Logging type.
Definition coap_debug.h:56
const char * coap_package_version(void)
Get the library package version.
Definition coap_debug.c:79
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
Definition coap_debug.c:108
void coap_log_impl(coap_log_t level, const char *format,...)
Writes the given text to COAP_ERR_FD (for level <= COAP_LOG_CRIT) or COAP_DEBUG_FD (for level >= COAP...
size_t coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
Definition coap_debug.c:266
#define COAP_DEBUG_FD
Used for output for COAP_LOG_OSCORE to COAP_LOG_ERR.
Definition coap_debug.h:37
const char * coap_package_build(void)
Get the library package build.
Definition coap_debug.c:84
const char * coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len)
Print the IP address into the defined buffer.
Definition coap_debug.c:449
void coap_show_tls_version(coap_log_t level)
Display the current (D)TLS library linked with and built for version.
void coap_set_show_pdu_output(int use_fprintf)
Defines the output mode for the coap_show_pdu() function.
Definition coap_debug.c:93
#define coap_log_err(...)
Definition coap_debug.h:102
const char * coap_package_name(void)
Get the library package name.
Definition coap_debug.c:74
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
Definition coap_debug.h:215
#define coap_log(level,...)
Logging function.
Definition coap_debug.h:290
@ COAP_LOG_INFO
Definition coap_debug.h:63
@ COAP_LOG_EMERG
Definition coap_debug.h:57
@ COAP_LOG_DEBUG
Definition coap_debug.h:64
@ COAP_LOG_CRIT
Definition coap_debug.h:59
@ COAP_LOG_ERR
Definition coap_debug.h:60
@ COAP_LOG_WARN
Definition coap_debug.h:61
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
#define COAP_DEBUG_BUF_SIZE
#define COAP_DEFAULT_VERSION
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC
Definition coap_pdu.h:152
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI
Definition coap_pdu.h:164
#define COAP_MEDIATYPE_APPLICATION_CWT
Definition coap_pdu.h:142
#define COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ
Definition coap_pdu.h:175
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT
Definition coap_pdu.h:150
#define COAP_MEDIATYPE_APPLICATION_RDF_XML
Definition coap_pdu.h:138
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML
Definition coap_pdu.h:166
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN
Definition coap_pdu.h:148
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET
Definition coap_pdu.h:156
#define COAP_MEDIATYPE_APPLICATION_OSCORE
Definition coap_pdu.h:178
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR
Definition coap_pdu.h:161
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY
Definition coap_pdu.h:155
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1
Definition coap_pdu.h:149
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM
Definition coap_pdu.h:137
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI
Definition coap_pdu.h:163
coap_pdu_code_t
Set of codes available for a PDU.
Definition coap_pdu.h:256
#define COAP_MEDIATYPE_APPLICATION_CBOR
Definition coap_pdu.h:141
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0
Definition coap_pdu.h:151
#define COAP_MEDIATYPE_TEXT_PLAIN
Definition coap_pdu.h:134
#define COAP_MEDIATYPE_APPLICATION_JSON
Definition coap_pdu.h:140
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0
Definition coap_pdu.h:153
#define COAP_MEDIATYPE_APPLICATION_ACE_CBOR
Definition coap_pdu.h:172
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON
Definition coap_pdu.h:159
#define COAP_MEDIATYPE_APPLICATION_EXI
Definition coap_pdu.h:139
#define COAP_MEDIATYPE_APPLICATION_PKCS7_CERTS
Definition coap_pdu.h:182
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:966
#define COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON
Definition coap_pdu.h:145
#define COAP_MEDIATYPE_APPLICATION_SENML_XML
Definition coap_pdu.h:165
#define COAP_MEDIATYPE_APPLICATION_CSRATTRS
Definition coap_pdu.h:184
#define COAP_MEDIATYPE_APPLICATION_PKCS8
Definition coap_pdu.h:183
#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR
Definition coap_pdu.h:169
#define COAP_MEDIATYPE_APPLICATION_PKCS7_SKG
Definition coap_pdu.h:181
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON
Definition coap_pdu.h:160
#define COAP_MEDIATYPE_APPLICATION_PKIX_CERT
Definition coap_pdu.h:186
#define COAP_MEDIATYPE_APPLICATION_PKCS10
Definition coap_pdu.h:185
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
Definition coap_pdu.h:135
#define COAP_MEDIATYPE_APPLICATION_XML
Definition coap_pdu.h:136
#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR
Definition coap_pdu.h:162
@ COAP_PROTO_WS
Definition coap_pdu.h:248
@ COAP_PROTO_WSS
Definition coap_pdu.h:249
@ COAP_SIGNALING_CODE_ABORT
Definition coap_pdu.h:299
@ COAP_SIGNALING_CODE_CSM
Definition coap_pdu.h:295
@ COAP_SIGNALING_CODE_PING
Definition coap_pdu.h:296
@ COAP_SIGNALING_CODE_PONG
Definition coap_pdu.h:297
@ COAP_SIGNALING_CODE_RELEASE
Definition coap_pdu.h:298
@ COAP_MESSAGE_CON
Definition coap_pdu.h:71
#define COAP_PROTO_NOT_RELIABLE(p)
int coap_dtls_cid_is_supported(void)
Check whether (D)TLS CID is available.
Definition coap_notls.c:86
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
Definition coap_notls.c:50
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition coap_notls.c:41
int coap_ws_is_supported(void)
Check whether WebSockets is available.
Definition coap_ws.c:956
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition coap_notls.c:36
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
Definition coap_notls.c:59
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
Definition coap_notls.c:77
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
Definition coap_notls.c:68
coap_upa_chain_t * coap_upa_server_mapping_chain
Definition coap_uri.c:33
const char * coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value)
Determine the expanded Uri-Path-Abbrev option value.
Definition coap_uri.c:1177
coap_upa_chain_t * coap_upa_client_fallback_chain
Definition coap_uri.c:32
#define COAP_STATIC_INLINE
Definition libcoap.h:57
#define COAP_THREAD_LOCAL_VAR
Definition libcoap.h:84
Multi-purpose address abstraction.
struct sockaddr_in sin
struct coap_sockaddr_un cun
struct sockaddr_in6 sin6
struct sockaddr sa
union coap_address_t::@307311212233272211314135073342070105261231004120 addr
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
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
structure for CoAP PDUs
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
coap_bin_const_t actual_token
Actual token in pdu.
coap_mid_t mid
message id, if any, in regular host byte order
coap_session_t * session
Session responsible for PDU or NULL.
coap_pdu_type_t type
message type
coap_proto_t proto
protocol used
char sun_path[COAP_UNIX_PATH_MAX]
The structure used for returning the underlying (D)TLS library information.
Definition coap_dtls.h:88
uint64_t built_version
(D)TLS Built against Library Version
Definition coap_dtls.h:91
coap_tls_library_t type
Library type.
Definition coap_dtls.h:90
uint64_t version
(D)TLS runtime Library Version
Definition coap_dtls.h:89