18#if defined(HAVE_STRNLEN) && defined(__GNUC__) && !defined(_GNU_SOURCE)
27#ifdef HAVE_ARPA_INET_H
41# define fprintf(fd, ...) LWIP_PLATFORM_DIAG((__VA_ARGS__))
46# define fprintf(fd, ...) { (void)fd; printf(__VA_ARGS__); }
48# define vfprintf(fd, ...) { (void)fd; printf(__VA_ARGS__); }
50# ifndef LOG_CONF_LEVEL_COAP
51# define LOG_CONF_LEVEL_COAP 2
55 (LOG_CONF_LEVEL_COAP == 1 ?
57 (LOG_CONF_LEVEL_COAP == 2 ?
59 (LOG_CONF_LEVEL_COAP == 3 ?
67#include "flash_utils.h"
80 return PACKAGE_STRING;
85#ifdef LIBCOAP_PACKAGE_BUILD
86 return LIBCOAP_PACKAGE_BUILD;
88 return PACKAGE_STRING;
118 "EMRG",
"ALRT",
"CRIT",
"ERR ",
"WARN",
"NOTE",
"INFO",
"DEBG",
"OSC ",
120 "Emrg",
"Alrt",
"Crit",
"Err ",
"Warn",
"Note",
"Info",
"Debg"
127 snprintf(bad,
sizeof(bad),
"%4d", level);
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",
162 return snprintf(s, len,
"%u.%03u",
173#if !defined(HAVE_STRNLEN) && !defined(__MINGW32__) && !defined(__ZEPHYR__)
185 while (*s++ && n < maxlen)
193 unsigned char *result,
size_t buflen,
int encode_always) {
194 const uint8_t hex[] =
"0123456789ABCDEF";
196 assert(data || len == 0);
203 if (!encode_always && isprint(*data)) {
204 if (cnt+1 < buflen) {
211 if (cnt+4 < buflen) {
214 *result++ = hex[(*data & 0xf0) >> 4];
215 *result++ = hex[*data & 0x0f];
230#define min(a,b) ((a) < (b) ? (a) : (b))
233#ifndef INET6_ADDRSTRLEN
234#define INET6_ADDRSTRLEN 46
242#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
249 switch (addr->
addr.
sa.sa_family) {
252 snprintf((
char *)buf, len,
"%s:%d",
259 snprintf((
char *)buf, len,
"[%s]:%d",
264#if COAP_AF_UNIX_SUPPORT
269#if COAP_AF_LLC_SUPPORT
271 snprintf((
char *)buf, len,
"%s:%02x",
278 memcpy(buf,
"(unknown address type)",
min(22+1, len));
282 return strlen((
char *)buf);
286# if defined(RIOT_VERSION)
293 switch (addr->riot.family) {
296 snprintf((
char *)buf, len,
"%s:%d",
303 snprintf((
char *)buf, len,
"[%s]:%d",
310 memcpy(buf,
"(unknown address type)",
min(22+1, len));
314 return strlen((
char *)buf);
321 snprintf((
char *)buf, len,
"[%s]:%d",
324 return strlen((
char *)buf);
326 unsigned char *p = buf;
327# if NETSTACK_CONF_WITH_IPV6
332 if (len < 40 + 2 + 6)
340# warning "IPv4 network addresses will not be included in debug output"
356 return strlen((
char *)buf);
364 snprintf((
char *)buf, len,
"[%s]:%d",
367 return strlen((
char *)buf);
369 unsigned char *p = buf;
375 switch (IP_GET_TYPE(addr->
addr)) {
377 if (len < IP4ADDR_STRLEN_MAX + 6)
380 p += strlen((
char *)buf);
384 case IPADDR_TYPE_ANY:
385 if (len < 40 + 2 + 6)
389 p += strlen((
char *)buf);
396 *p++ =
'0' + (addr->port / 10000) % 10;
397 *p++ =
'0' + (addr->port / 1000) % 10;
398 *p++ =
'0' + (addr->port / 100) % 10;
399 *p++ =
'0' + (addr->port / 10) % 10;
400 *p++ =
'0' + addr->port % 10;
403 return strlen((
char *)buf);
412# warning "inet_ntop() not available, network addresses will not be included in debug output"
425#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
426 const void *addrptr =
NULL;
432 switch (addr->
addr.
sa.sa_family) {
435 if (len < INET_ADDRSTRLEN)
437 addrptr = &addr->
addr.
sin.sin_addr;
444 addrptr = &addr->
addr.
sin6.sin6_addr;
447#if COAP_AF_UNIX_SUPPORT
452#if COAP_AF_LLC_SUPPORT
454 snprintf((
char *)buf, len,
"llc[%02x:%02x:%02x:%02x:%02x:%02x]",
455 addr->
addr.llc.sllc_mac[0],
456 addr->
addr.llc.sllc_mac[1],
457 addr->
addr.llc.sllc_mac[2],
458 addr->
addr.llc.sllc_mac[3],
459 addr->
addr.llc.sllc_mac[4],
460 addr->
addr.llc.sllc_mac[5]);
465 memcpy(buf,
"(unknown address type)",
min(22+1, len));
471 if (inet_ntop(addr->
addr.
sa.sa_family, addrptr, (
char *)buf, len) == 0) {
480# if defined(RIOT_VERSION)
485 switch (addr->riot.family) {
488 if (ipv4_addr_to_str(buf, (ipv4_addr_t *)&addr->riot.
addr.ipv4, (
size_t)len) ==
NULL) {
495 if (ipv6_addr_to_str(buf, (ipv6_addr_t *)&addr->riot.
addr.ipv6, (
size_t)len) ==
NULL) {
513# if NETSTACK_CONF_WITH_IPV6
514 const char hex[] =
"0123456789ABCDEF";
522 for (i=0; i < 16; i += 2) {
526 *p++ = hex[(addr->
addr.u8[i] & 0xf0) >> 4];
527 *p++ = hex[(addr->
addr.u8[i] & 0x0f)];
528 *p++ = hex[(addr->
addr.u8[i+1] & 0xf0) >> 4];
529 *p++ = hex[(addr->
addr.u8[i+1] & 0x0f)];
533# warning "IPv4 network addresses will not be included in debug output"
547 switch (IP_GET_TYPE(&addr->
addr)) {
550 if (len < IP4ADDR_STRLEN_MAX)
552 memcpy(buf, ip4addr_ntoa(ip_2_ip4(&addr->
addr)), IP4ADDR_STRLEN_MAX);
557 case IPADDR_TYPE_ANY:
561 memcpy(buf, ip6addr_ntoa(&addr->
addr.u_addr.ip6), 40);
563 memcpy(buf, ip6addr_ntoa(&addr->
addr), 40);
576# warning "inet_ntop() not available, network addresses will not be included in debug output"
586 static const char *types[] = {
"CON",
"NON",
"ACK",
"RST",
"???" };
588 return types[
min(t,
sizeof(types)/
sizeof(
char *) - 1)];
594 static const char *methods[] = {
"0.00",
"GET",
"POST",
"PUT",
"DELETE",
595 "FETCH",
"PATCH",
"iPATCH"
597 static const char *signals[] = {
"7.00",
"CSM",
"Ping",
"Pong",
"Release",
602 if (c <
sizeof(methods)/
sizeof(
const char *)) {
604 }
else if (c >= 224 && c - 224 < (
int)(
sizeof(signals)/
sizeof(
const char *))) {
605 return signals[c-224];
607 snprintf(buf,
sizeof(buf),
"%u.%02u", (c >> 5) & 0x7, c & 0x1f);
615 struct option_desc_t {
620 static struct option_desc_t options[] = {
650 static struct option_desc_t options_csm[] = {
656 static struct option_desc_t options_pingpong[] = {
660 static struct option_desc_t options_release[] = {
665 static struct option_desc_t options_abort[] = {
673 for (i = 0; i <
sizeof(options_csm)/
sizeof(
struct option_desc_t); i++) {
674 if (option_type == options_csm[i].type) {
675 return options_csm[i].name;
679 for (i = 0; i <
sizeof(options_pingpong)/
sizeof(
struct option_desc_t); i++) {
680 if (option_type == options_pingpong[i].type) {
681 return options_pingpong[i].name;
685 for (i = 0; i <
sizeof(options_release)/
sizeof(
struct option_desc_t); i++) {
686 if (option_type == options_release[i].type) {
687 return options_release[i].name;
691 for (i = 0; i <
sizeof(options_abort)/
sizeof(
struct option_desc_t); i++) {
692 if (option_type == options_abort[i].type) {
693 return options_abort[i].name;
698 for (i = 0; i <
sizeof(options)/
sizeof(
struct option_desc_t); i++) {
699 if (option_type == options[i].type) {
700 return options[i].name;
705 snprintf(buf,
sizeof(buf),
"%u", option_type);
711 unsigned char *result,
unsigned int buflen) {
717 static struct desc_t formats[] = {
748 { 75,
"application/dcaf+cbor" }
754 for (i = 0; i <
sizeof(formats)/
sizeof(
struct desc_t); i++) {
755 if (format_type == formats[i].type) {
756 return snprintf((
char *)result, buflen,
"%s", formats[i].name);
761 return snprintf((
char *)result, buflen,
"%d", format_type);
771 return !(content_format == -1 ||
778#define COAP_DO_SHOW_OUTPUT_LINE \
780 if (use_fprintf_for_show_pdu) { \
781 fprintf(COAP_DEBUG_FD, "%s", outbuf); \
784 coap_log(level, "%s", outbuf); \
800#if COAP_DEBUG_BUF_SIZE < 5
801#error "COAP_DEBUG_BUF_SIZE must be at least 5, should be >= 32 to be useful"
805#if COAP_DEBUG_BUF_SIZE < 1035
806#define USE_BUF_SIZE COAP_DEBUG_BUF_SIZE
808#define USE_BUF_SIZE 1035
813#if COAP_CONSTRAINED_STACK
824 int encode = 0, have_options = 0;
828 int content_format = -1;
832 const uint8_t *opt_val;
833 size_t outbuflen = 0;
834 int is_oscore_payload = 0;
846 snprintf(outbuf,
sizeof(outbuf),
"v:%d t:%s c:%s i:%04x {",
853 snprintf(outbuf,
sizeof(outbuf),
"v:WebSocket c:%s {",
858 snprintf(outbuf,
sizeof(outbuf),
"v:Reliable c:%s {",
863 outbuflen = strlen(outbuf);
864 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
867 outbuflen = strlen(outbuf);
868 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
"}");
873 outbuflen = strlen(outbuf);
874 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
" [");
880 outbuflen = strlen(outbuf);
881 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
",");
885 switch (opt_iter.
number) {
888 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u",
900 switch (opt_iter.
number) {
904 buf,
sizeof(buf), 0);
907 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u",
916 switch (opt_iter.
number) {
918 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u",
927 switch (opt_iter.
number) {
944 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u/%c/BERT(%" PRIuS ")",
949 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u/%c/BERT",
953 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u/%c/%u",
969 if (opt_val[0] & 0x20) {
971 snprintf((
char *)buf,
sizeof(buf),
"grp");
973 if (opt_val[0] & 0x07) {
975 cnt = opt_val[0] & 0x07;
976 if (cnt > opt_len - ofs)
978 buf_len = strlen((
char *)buf);
979 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
"%spIV=0x",
981 for (i = 0; (uint32_t)i < cnt; i++) {
982 buf_len = strlen((
char *)buf);
983 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
984 "%02x", opt_val[ofs + i]);
988 if (opt_val[0] & 0x10) {
993 if (cnt > opt_len - ofs - 1)
996 buf_len = strlen((
char *)buf);
997 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
"%skc=0x",
999 for (i = 0; (uint32_t)i < cnt; i++) {
1000 buf_len = strlen((
char *)buf);
1001 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
1002 "%02x", opt_val[ofs + i]);
1006 if (opt_val[0] & 0x08) {
1010 cnt = opt_len - ofs;
1011 buf_len = strlen((
char *)buf);
1012 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
"%skid=0x",
1013 buf_len ?
"," :
"");
1014 for (i = 0; (uint32_t)i < cnt; i++) {
1015 buf_len = strlen((
char *)buf);
1016 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
1017 "%02x", opt_val[ofs + i]);
1022 buf_len = strlen((
char *)buf);
1023 is_oscore_payload = 1;
1034 buf_len = snprintf((
char *)buf,
sizeof(buf),
"%u",
1047 snprintf((
char *)buf,
sizeof(buf),
"0x");
1048 for (i = 0; (uint32_t)i < opt_len; i++) {
1049 buf_len = strlen((
char *)buf);
1050 snprintf((
char *)&buf[buf_len],
sizeof(buf)-buf_len,
1051 "%02x", opt_val[i]);
1053 buf_len = strlen((
char *)buf);
1063 snprintf((
char *)&buf,
sizeof(buf),
"%s", exp);
1065 snprintf((
char *)&buf,
sizeof(buf),
"(%u)", value);
1067 buf_len = strlen((
char *)buf);
1084 buf,
sizeof(buf), encode);
1087 outbuflen = strlen(outbuf);
1088 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
1093 outbuflen = strlen(outbuf);
1094 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
" ]");
1099 outbuflen = strlen(outbuf);
1100 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
" :: ");
1101 outbuflen = strlen(outbuf);
1102 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
1103 "data length %"PRIuS " (data suppressed)\n", data_len);
1111 outbuflen = strlen(outbuf);
1112 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
" :: ");
1114 if (
is_binary(content_format) || !isprint(data[0]) || is_oscore_payload) {
1115 size_t keep_data_len = data_len;
1116 const uint8_t *keep_data = data;
1118 outbuflen = strlen(outbuf);
1119 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
1120 "binary data length %"PRIuS "\n", data_len);
1126 snprintf(outbuf,
sizeof(outbuf),
"<<");
1127 while (data_len--) {
1128 outbuflen = strlen(outbuf);
1129 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
1132 outbuflen = strlen(outbuf);
1133 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
">>");
1134 data_len = keep_data_len;
1136 outbuflen = strlen(outbuf);
1137 if (outbuflen ==
sizeof(outbuf)-1)
1139 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
"\n");
1146 snprintf(outbuf,
sizeof(outbuf),
"<<");
1147 while (data_len--) {
1148 outbuflen = strlen(outbuf);
1149 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
1150 "%c ", isprint(*data) ? *data :
'.');
1153 outbuflen = strlen(outbuf);
1154 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
">>");
1158 outbuflen = strlen(outbuf);
1159 max_length =
sizeof(outbuf)-outbuflen;
1160 if (max_length > 1) {
1161 outbuf[outbuflen++] =
'\'';
1162 outbuf[outbuflen] =
'\000';
1165 if (max_length > 1) {
1167 (
unsigned char *)&outbuf[outbuflen],
1171 if (outbuflen <
sizeof(outbuf)-4-1) {
1172 outbuf[outbuflen++] =
'\'';
1173 outbuf[outbuflen] =
'\000';
1178 outbuflen = strlen(outbuf);
1179 if (outbuflen ==
sizeof(outbuf)-1)
1181 snprintf(&outbuf[outbuflen],
sizeof(outbuf)-outbuflen,
"\n");
1204 switch (tls_version->
type) {
1206 snprintf(buffer, bufsize,
"TLS Library: None");
1209 snprintf(buffer, bufsize,
"TLS Library: TinyDTLS - runtime %lu.%lu.%lu, "
1210 "libcoap built for %lu.%lu.%lu",
1211 (
unsigned long)(tls_version->
version >> 16),
1212 (
unsigned long)((tls_version->
version >> 8) & 0xff),
1213 (
unsigned long)(tls_version->
version & 0xff),
1219 switch (tls_version->
version &0xf) {
1221 strcpy(beta,
"-dev");
1227 strcpy(beta,
"-beta");
1228 beta[5] = (tls_version->
version &0xf) +
'0';
1232 sub[0] = ((tls_version->
version >> 4) & 0xff) ?
1233 ((tls_version->
version >> 4) & 0xff) +
'a' -1 :
'\000';
1237 strcpy(b_beta,
"-dev");
1243 strcpy(b_beta,
"-beta");
1249 ((tls_version->
built_version >> 4) & 0xff) +
'a' -1 :
'\000';
1251 snprintf(buffer, bufsize,
"TLS Library: OpenSSL - runtime "
1252 "%lu.%lu.%lu%s%s, libcoap built for %lu.%lu.%lu%s%s",
1253 (
unsigned long)(tls_version->
version >> 28),
1254 (
unsigned long)((tls_version->
version >> 20) & 0xff),
1255 (
unsigned long)((tls_version->
version >> 12) & 0xff), sub, beta,
1262 snprintf(buffer, bufsize,
"TLS Library: GnuTLS - runtime %lu.%lu.%lu, "
1263 "libcoap built for %lu.%lu.%lu",
1264 (
unsigned long)(tls_version->
version >> 16),
1265 (
unsigned long)((tls_version->
version >> 8) & 0xff),
1266 (
unsigned long)(tls_version->
version & 0xff),
1272 snprintf(buffer, bufsize,
"TLS Library: Mbed TLS - runtime %lu.%lu.%lu, "
1273 "libcoap built for %lu.%lu.%lu",
1274 (
unsigned long)(tls_version->
version >> 24),
1275 (
unsigned long)((tls_version->
version >> 16) & 0xff),
1276 (
unsigned long)((tls_version->
version >> 8) & 0xff),
1282 snprintf(buffer, bufsize,
"TLS Library: wolfSSL - runtime %lu.%lu.%lu, "
1283 "libcoap built for %lu.%lu.%lu",
1284 (
unsigned long)(tls_version->
version >> 24),
1285 (
unsigned long)((tls_version->
version >> 12) & 0xfff),
1286 (
unsigned long)((tls_version->
version >> 0) & 0xfff),
1288 (
unsigned long)((tls_version->
built_version >> 12) & 0xfff),
1289 (
unsigned long)((tls_version->
built_version >> 0) & 0xfff));
1292 snprintf(buffer, bufsize,
"Library type %d unknown", tls_version->
type);
1310 if (have_dtls == 0 && have_tls == 0) {
1311 snprintf(buffer, bufsize,
"(No DTLS or TLS support)");
1314 snprintf(buffer, bufsize,
1315 "(%sDTLS and %sTLS support; %sPSK, %sPKI, %sPKCS11, %sRPK and %sCID support)\n(%sOSCORE)\n(%sWebSockets)",
1316 have_dtls ?
"" :
"No ",
1317 have_tls ?
"" :
"no ",
1318 have_psk ?
"" :
"no ",
1319 have_pki ?
"" :
"no ",
1320 have_pkcs11 ?
"" :
"no ",
1321 have_rpk ?
"" :
"no ",
1322 have_cid ?
"" :
"no ",
1323 have_oscore ?
"Have " :
"No ",
1324 have_ws ?
"Have " :
"No ");
1335#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1339extern uint32_t max_thread_no;
1350#if COAP_CONSTRAINED_STACK
1357 va_start(ap, format);
1360 flash_vsnprintf(message,
sizeof(message), format, ap);
1362 vsnprintf(message,
sizeof(message), format, ap);
1378 fprintf(log_fd,
"%.*s ", (
int)len, timebuf);
1380#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1381 if (thread_no == 0) {
1387 thread_no = ++max_thread_no;
1390 fprintf(log_fd,
"%2d ", thread_no);
1395 va_start(ap, format);
1397 flash_vfprintf(log_fd, format, ap);
1399 vfprintf(log_fd, format, ap);
1423 const char *p = loss_level;
1425 int n = (int)strtol(p, &
end, 10), i = 0;
1426 if (
end == p || n < 0)
1440 n = (int)strtol(p, &
end, 10);
1441 if (
end == p || n <= 0)
1450 n = (int)strtol(p, &
end, 10);
1451 if (
end == p || n <= 0)
1489 errno = ECONNREFUSED;
1499 errno = ECONNREFUSED;
1508 const char *p = fail_level;
1510 int n = (int)strtol(p, &
end, 10), i = 0;
1511 if (
end == p || n < 0)
1525 n = (int)strtol(p, &
end, 10);
1526 if (
end == p || n <= 0)
1535 n = (int)strtol(p, &
end, 10);
1536 if (
end == p || n <= 0)
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 struct packet_num_interval packet_loss_intervals[10]
static int send_packet_count
int coap_debug_set_packet_loss(const char *loss_level)
Set the packet loss level for testing.
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.
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.
static int enable_data_for_show_pdu
static const char * msg_code_string(uint16_t c)
Returns a textual description of the method or response code.
#define COAP_DO_SHOW_OUTPUT_LINE
static size_t print_readable(const uint8_t *data, size_t len, unsigned char *result, size_t buflen, int encode_always)
static const char * msg_option_string(uint8_t code, uint16_t option_type)
Returns a textual description of the option name.
static size_t strnlen(const char *s, size_t maxlen)
A length-safe strlen() fake.
struct packet_num_interval packet_fail_intervals[10]
static uint16_t packet_fail_level
static const char * loglevels[]
COAP_STATIC_INLINE size_t print_timestamp(char *s, size_t len, coap_tick_t t)
static int num_packet_fail_intervals
static const char * msg_type_string(uint16_t t)
Returns a textual description of the message type t.
static int use_fprintf_for_show_pdu
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)
Library specific build wrapper for coap_internal.h.
#define coap_mutex_unlock(a)
#define coap_mutex_lock(a)
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt.
#define COAP_OPT_BLOCK_MORE(opt)
Returns the value of the More-bit of a Block option opt.
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.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
coap_time_t coap_ticks_to_rt(coap_tick_t t)
Helper function that converts coap ticks to wallclock time.
uint64_t coap_ticks_to_rt_us(coap_tick_t t)
Helper function that converts coap ticks to POSIX wallclock time in us.
int coap_prng_lkd(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
coap_tls_version_t * coap_get_tls_library_version(void)
Determine the type and version of the underlying (D)TLS library.
@ COAP_TLS_LIBRARY_WOLFSSL
Using wolfSSL library.
@ COAP_TLS_LIBRARY_GNUTLS
Using GnuTLS library.
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
@ COAP_TLS_LIBRARY_OPENSSL
Using OpenSSL library.
@ COAP_TLS_LIBRARY_MBEDTLS
Using Mbed TLS library.
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
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.
#define coap_log_debug(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
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(...)
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
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.
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
#define COAP_ERR_FD
Used for output for COAP_LOG_CRIT to COAP_LOG_EMERG.
const char * coap_package_version(void)
Get the library package version.
void coap_set_log_level(coap_log_t level)
Sets the log level to the specified value.
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.
#define COAP_DEBUG_FD
Used for output for COAP_LOG_OSCORE to COAP_LOG_ERR.
const char * coap_package_build(void)
Get the library package build.
const char * coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len)
Print the IP address into the defined buffer.
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.
#define coap_log_err(...)
const char * coap_package_name(void)
Get the library package name.
void(* coap_log_handler_t)(coap_log_t level, const char *message)
Logging callback handler definition.
#define coap_log(level,...)
Logging function.
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_OPTION_HOP_LIMIT
#define COAP_OPTION_NORESPONSE
#define COAP_OPTION_URI_HOST
#define COAP_OPTION_IF_MATCH
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI
#define COAP_MEDIATYPE_APPLICATION_CWT
#define COAP_OPTION_BLOCK2
#define COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT
#define COAP_MEDIATYPE_APPLICATION_RDF_XML
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS
#define COAP_OPTION_SIZE2
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN
#define COAP_OPTION_BLOCK1
#define COAP_OPTION_Q_BLOCK1
#define COAP_OPTION_PROXY_SCHEME
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET
#define COAP_MEDIATYPE_APPLICATION_OSCORE
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR
#define COAP_OPTION_URI_QUERY
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1
#define COAP_OPTION_IF_NONE_MATCH
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM
#define COAP_OPTION_LOCATION_PATH
#define COAP_OPTION_URI_PATH
#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI
#define COAP_OPTION_OSCORE
#define COAP_MEDIATYPE_APPLICATION_CBOR
#define COAP_OPTION_SIZE1
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER
#define COAP_MEDIATYPE_TEXT_PLAIN
#define COAP_MEDIATYPE_APPLICATION_JSON
#define COAP_OPTION_LOCATION_QUERY
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0
#define COAP_MEDIATYPE_APPLICATION_ACE_CBOR
#define COAP_OPTION_Q_BLOCK2
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON
#define COAP_MEDIATYPE_APPLICATION_EXI
#define COAP_SIGNALING_OPTION_CUSTODY
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.
#define COAP_OPTION_URI_PATH_ABB
#define COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON
#define COAP_OPTION_URI_PORT
#define COAP_MEDIATYPE_APPLICATION_SENML_XML
#define COAP_OPTION_ACCEPT
#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR
#define COAP_OPTION_MAXAGE
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON
#define COAP_OPTION_PROXY_URI
#define COAP_OPTION_OBSERVE
#define COAP_SIGNALING_OPTION_HOLD_OFF
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE
#define COAP_MEDIATYPE_APPLICATION_XML
#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR
@ COAP_SIGNALING_CODE_ABORT
@ COAP_SIGNALING_CODE_CSM
@ COAP_SIGNALING_CODE_PING
@ COAP_SIGNALING_CODE_PONG
@ COAP_SIGNALING_CODE_RELEASE
#define COAP_PROTO_NOT_RELIABLE(p)
int coap_dtls_cid_is_supported(void)
Check whether (D)TLS CID is available.
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
int coap_tls_is_supported(void)
Check whether TLS is available.
int coap_ws_is_supported(void)
Check whether WebSockets is available.
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
coap_upa_chain_t * coap_upa_server_mapping_chain
const char * coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value)
Determine the expanded Uri-Path-Abbrev option value.
coap_upa_chain_t * coap_upa_client_fallback_chain
#define COAP_STATIC_INLINE
#define COAP_THREAD_LOCAL_VAR
Multi-purpose address abstraction.
struct coap_sockaddr_un cun
union coap_address_t::@0 addr
size_t length
length of binary data
const uint8_t * s
read-only binary data
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
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.
uint64_t built_version
(D)TLS Built against Library Version
coap_tls_library_t type
Library type.
uint64_t version
(D)TLS runtime Library Version