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];
231 const char *format, ...) {
234 size_t start = *offset;
236 assert(buf_size > 0 && start < buf_size);
237 if (buf_size == 0 || start >= buf_size - 1)
240 va_start(ap, format);
241 ret = vsnprintf(&buffer[start], buf_size - start, format, ap);
244 buffer[start] =
'\000';
246 }
else if ((
size_t)ret >= buf_size - start) {
247 *offset = buf_size - 1;
249 *offset = start + (size_t)ret;
251 return (
int)(*offset - start);
255#define min(a,b) ((a) < (b) ? (a) : (b))
258#ifndef INET6_ADDRSTRLEN
259#define INET6_ADDRSTRLEN 46
267#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
274 switch (addr->
addr.
sa.sa_family) {
277 snprintf((
char *)buf, len,
"%s:%d",
284 snprintf((
char *)buf, len,
"[%s]:%d",
289#if COAP_AF_UNIX_SUPPORT
294#if COAP_AF_LLC_SUPPORT
296 snprintf((
char *)buf, len,
"%s:%02x",
303 memcpy(buf,
"(unknown address type)",
min(22+1, len));
307 return strlen((
char *)buf);
311# if defined(RIOT_VERSION)
318 switch (addr->riot.family) {
321 snprintf((
char *)buf, len,
"%s:%d",
328 snprintf((
char *)buf, len,
"[%s]:%d",
335 memcpy(buf,
"(unknown address type)",
min(22+1, len));
339 return strlen((
char *)buf);
346 snprintf((
char *)buf, len,
"[%s]:%d",
349 return strlen((
char *)buf);
351 unsigned char *p = buf;
352# if NETSTACK_CONF_WITH_IPV6
357 if (len < 40 + 2 + 6)
365# warning "IPv4 network addresses will not be included in debug output"
381 return strlen((
char *)buf);
389 snprintf((
char *)buf, len,
"[%s]:%d",
392 return strlen((
char *)buf);
394 unsigned char *p = buf;
400 switch (IP_GET_TYPE(addr->
addr)) {
402 if (len < IP4ADDR_STRLEN_MAX + 6)
405 p += strlen((
char *)buf);
409 case IPADDR_TYPE_ANY:
410 if (len < 40 + 2 + 6)
414 p += strlen((
char *)buf);
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;
428 return strlen((
char *)buf);
437# warning "inet_ntop() not available, network addresses will not be included in debug output"
450#if (defined( HAVE_ARPA_INET_H ) || defined( HAVE_WS2TCPIP_H )) && !defined(RIOT_VERSION) || defined(__ZEPHYR__)
451 const void *addrptr =
NULL;
457 switch (addr->
addr.
sa.sa_family) {
460 if (len < INET_ADDRSTRLEN)
462 addrptr = &addr->
addr.
sin.sin_addr;
469 addrptr = &addr->
addr.
sin6.sin6_addr;
472#if COAP_AF_UNIX_SUPPORT
477#if COAP_AF_LLC_SUPPORT
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]);
490 memcpy(buf,
"(unknown address type)",
min(22+1, len));
496 if (inet_ntop(addr->
addr.
sa.sa_family, addrptr, (
char *)buf, len) == 0) {
505# if defined(RIOT_VERSION)
510 switch (addr->riot.family) {
513 if (ipv4_addr_to_str(buf, (ipv4_addr_t *)&addr->riot.
addr.ipv4, (
size_t)len) ==
NULL) {
520 if (ipv6_addr_to_str(buf, (ipv6_addr_t *)&addr->riot.
addr.ipv6, (
size_t)len) ==
NULL) {
538# if NETSTACK_CONF_WITH_IPV6
539 const char hex[] =
"0123456789ABCDEF";
547 for (i=0; i < 16; i += 2) {
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)];
558# warning "IPv4 network addresses will not be included in debug output"
572 switch (IP_GET_TYPE(&addr->
addr)) {
575 if (len < IP4ADDR_STRLEN_MAX)
577 memcpy(buf, ip4addr_ntoa(ip_2_ip4(&addr->
addr)), IP4ADDR_STRLEN_MAX);
582 case IPADDR_TYPE_ANY:
586 memcpy(buf, ip6addr_ntoa(&addr->
addr.u_addr.ip6), 40);
588 memcpy(buf, ip6addr_ntoa(&addr->
addr), 40);
601# warning "inet_ntop() not available, network addresses will not be included in debug output"
611 static const char *types[] = {
"CON",
"NON",
"ACK",
"RST",
"???" };
613 return types[
min(t,
sizeof(types)/
sizeof(
char *) - 1)];
619 static const char *methods[] = {
"0.00",
"GET",
"POST",
"PUT",
"DELETE",
620 "FETCH",
"PATCH",
"iPATCH"
622 static const char *signals[] = {
"7.00",
"CSM",
"Ping",
"Pong",
"Release",
627 if (c <
sizeof(methods)/
sizeof(
const char *)) {
629 }
else if (c >= 224 && c - 224 < (
int)(
sizeof(signals)/
sizeof(
const char *))) {
630 return signals[c-224];
632 snprintf(buf,
sizeof(buf),
"%u.%02u", (
unsigned)((c >> 5) & 0x7),
633 (
unsigned)(c & 0x1f));
641 struct option_desc_t {
646 static struct option_desc_t options[] = {
676 static struct option_desc_t options_csm[] = {
682 static struct option_desc_t options_pingpong[] = {
686 static struct option_desc_t options_release[] = {
691 static struct option_desc_t options_abort[] = {
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;
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;
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;
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;
724 for (i = 0; i <
sizeof(options)/
sizeof(
struct option_desc_t); i++) {
725 if (number == options[i].value) {
726 return options[i].name;
731 snprintf(buf,
sizeof(buf),
"%u", number);
737 unsigned char *result,
unsigned int buflen) {
743 static struct desc_t formats[] = {
780 { 75,
"application/dcaf+cbor" }
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);
794 return coap_snprintf((
char *)result, buflen, &len,
"%u", format_type);
804 return !(content_format == -1 ||
811#define COAP_DO_SHOW_OUTPUT_LINE \
813 if (use_fprintf_for_show_pdu) { \
814 fprintf(COAP_DEBUG_FD, "%s", outbuf); \
817 coap_log(level, "%s", outbuf); \
833#if COAP_DEBUG_BUF_SIZE < 5
834#error "COAP_DEBUG_BUF_SIZE must be at least 5, should be >= 32 to be useful"
838#if COAP_DEBUG_BUF_SIZE < 1035
839#define USE_BUF_SIZE COAP_DEBUG_BUF_SIZE
841#define USE_BUF_SIZE 1035
846#if COAP_CONSTRAINED_STACK
857 int have_options = 0;
861 int content_format = -1;
865 const uint8_t *opt_val;
866 size_t outbuflen = 0;
867 int is_oscore_payload = 0;
879 snprintf(outbuf,
sizeof(outbuf),
"v:%d t:%s c:%s i:%04x {",
886 snprintf(outbuf,
sizeof(outbuf),
"v:WebSocket c:%s {",
891 snprintf(outbuf,
sizeof(outbuf),
"v:Reliable c:%s {",
895 outbuflen = strlen(outbuf);
939 buf,
sizeof(buf), 0);
982 coap_snprintf((
char *)buf,
sizeof(buf), &buf_len,
"%u/%c/BERT",
986 coap_snprintf((
char *)buf,
sizeof(buf), &buf_len,
"%u/%c/%u",
1002 if (opt_val[0] & 0x20) {
1004 snprintf((
char *)buf,
sizeof(buf),
"grp");
1006 if (opt_val[0] & 0x07) {
1008 cnt = opt_val[0] & 0x07;
1009 if (cnt > opt_len - ofs)
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++) {
1016 "%02x", opt_val[ofs + i]);
1020 if (opt_val[0] & 0x10) {
1025 if (cnt > opt_len - ofs - 1)
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++) {
1033 "%02x", opt_val[ofs + i]);
1037 if (opt_val[0] & 0x08) {
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++) {
1047 "%02x", opt_val[ofs + i]);
1052 buf_len = strlen((
char *)buf);
1053 is_oscore_payload = 1;
1077 snprintf((
char *)buf,
sizeof(buf),
"0x");
1078 buf_len = strlen((
char *)buf);
1079 for (i = 0; (uint32_t)i < opt_len; i++) {
1081 "%02x", opt_val[i]);
1092 snprintf((
char *)&buf,
sizeof(buf),
"%s", exp);
1094 snprintf((
char *)&buf,
sizeof(buf),
"(%" PRIu32 ")", value);
1096 buf_len = strlen((
char *)buf);
1107 buf,
sizeof(buf), 0);
1114 buf,
sizeof(buf), 1);
1129 "data length %"PRIuS " (data suppressed)\n", data_len);
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;
1144 "binary data length %"PRIuS "\n", data_len);
1150 snprintf(outbuf,
sizeof(outbuf),
"<<");
1151 outbuflen = strlen(outbuf);
1152 while (data_len--) {
1153 coap_snprintf(outbuf,
sizeof(outbuf), &outbuflen,
"%02x", *data++);
1156 data_len = keep_data_len;
1158 if (outbuflen ==
sizeof(outbuf)-1)
1167 snprintf(outbuf,
sizeof(outbuf),
"<<");
1168 outbuflen = strlen(outbuf);
1169 while (data_len--) {
1171 "%c ", isprint(*data) ? *data :
'.');
1178 outbuflen = strlen(outbuf);
1179 max_length =
sizeof(outbuf)-outbuflen;
1180 if (max_length > 1) {
1181 outbuf[outbuflen++] =
'\'';
1182 outbuf[outbuflen] =
'\000';
1185 if (max_length > 1) {
1187 (
unsigned char *)&outbuf[outbuflen],
1191 if (outbuflen <
sizeof(outbuf)-4-1) {
1192 outbuf[outbuflen++] =
'\'';
1193 outbuf[outbuflen] =
'\000';
1198 if (outbuflen ==
sizeof(outbuf)-1)
1223 switch (tls_version->
type) {
1225 snprintf(buffer, bufsize,
"TLS Library: None");
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),
1238 switch (tls_version->
version &0xf) {
1240 strcpy(beta,
"-dev");
1246 strcpy(beta,
"-beta");
1247 beta[5] = (tls_version->
version &0xf) +
'0';
1251 sub[0] = ((tls_version->
version >> 4) & 0xff) ?
1252 ((tls_version->
version >> 4) & 0xff) +
'a' -1 :
'\000';
1256 strcpy(b_beta,
"-dev");
1262 strcpy(b_beta,
"-beta");
1268 ((tls_version->
built_version >> 4) & 0xff) +
'a' -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,
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),
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),
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),
1307 (
unsigned long)((tls_version->
built_version >> 12) & 0xfff),
1308 (
unsigned long)((tls_version->
built_version >> 0) & 0xfff));
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),
1318 (
unsigned long)((tls_version->
built_version >> 16) & 0x0f));
1321 snprintf(buffer, bufsize,
"Library type %d unknown", tls_version->
type);
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 ");
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 ");
1366#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1370extern uint32_t max_thread_no;
1381#if COAP_CONSTRAINED_STACK
1388 va_start(ap, format);
1391 flash_vsnprintf(message,
sizeof(message), format, ap);
1393 vsnprintf(message,
sizeof(message), format, ap);
1411 fprintf(log_fd,
"%.*s ", (
int)len, timebuf);
1414#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
1415 if (thread_no == 0) {
1421 thread_no = ++max_thread_no;
1424 fprintf(log_fd,
"%2d ", thread_no);
1429 va_start(ap, format);
1431 flash_vfprintf(log_fd, format, ap);
1433 vfprintf(log_fd, format, ap);
1444#ifndef COAP_DEBUG_INTERVAL_COUNT
1445#define COAP_DEBUG_INTERVAL_COUNT 10
1465 int *num_intervals, uint16_t *level,
size_t *count) {
1466 const char *p = loss_level;
1468 int n = (int)strtol(p, &
end, 10), i = 0;
1473 if (
end == p || n < 0)
1478 *level = n * 0xffff / 100;
1484 intervals[i].
start = n;
1487 n = (int)strtol(p, &
end, 10);
1488 if (
end == p || n <= 0)
1491 intervals[i++].
end = n;
1497 n = (int)strtol(p, &
end, 10);
1498 if (
end == p || n <= 0)
1542 errno = ECONNREFUSED;
1552 errno = ECONNREFUSED;
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
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
const char * coap_option_string(coap_pdu_code_t code, coap_option_num_t number)
Returns a textual description of the option name.
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.
static int enable_data_for_show_pdu
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...
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 uint16_t packet_drop_level
static size_t strnlen(const char *s, size_t maxlen)
A length-safe strlen() fake.
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 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.
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)
#define COAP_DEBUG_INTERVAL_COUNT
Library specific build wrapper for coap_internal.h.
#define coap_mutex_unlock(a)
#define coap_mutex_lock(a)
uint16_t coap_option_num_t
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_OPT_BLOCK_WISE_TRANSFER
@ COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH
@ COAP_SIG_OPT_MAX_MESSAGE_SIZE
@ COAP_SIG_OPT_ALTERNATIVE_ADDRESS
@ COAP_OPTION_IF_NONE_MATCH
@ COAP_OPTION_PROXY_SCHEME
@ COAP_OPTION_CONTENT_FORMAT
@ COAP_OPTION_LOCATION_QUERY
@ COAP_OPTION_LOCATION_PATH
@ COAP_OPTION_URI_PATH_ABB
@ COAP_SIG_OPT_BAD_CSM_OPTION
#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_OPENHITLS
Using openHiTLS 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_MEDIATYPE_APPLICATION_COSE_MAC
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI
#define COAP_MEDIATYPE_APPLICATION_CWT
#define COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT
#define COAP_MEDIATYPE_APPLICATION_RDF_XML
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET
#define COAP_MEDIATYPE_APPLICATION_OSCORE
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI
coap_pdu_code_t
Set of codes available for a PDU.
#define COAP_MEDIATYPE_APPLICATION_CBOR
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0
#define COAP_MEDIATYPE_TEXT_PLAIN
#define COAP_MEDIATYPE_APPLICATION_JSON
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0
#define COAP_MEDIATYPE_APPLICATION_ACE_CBOR
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON
#define COAP_MEDIATYPE_APPLICATION_EXI
#define COAP_MEDIATYPE_APPLICATION_PKCS7_CERTS
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_MEDIATYPE_APPLICATION_COAP_GROUP_JSON
#define COAP_MEDIATYPE_APPLICATION_SENML_XML
#define COAP_MEDIATYPE_APPLICATION_CSRATTRS
#define COAP_MEDIATYPE_APPLICATION_PKCS8
#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR
#define COAP_MEDIATYPE_APPLICATION_PKCS7_SKG
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON
#define COAP_MEDIATYPE_APPLICATION_PKIX_CERT
#define COAP_MEDIATYPE_APPLICATION_PKCS10
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
#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::@307311212233272211314135073342070105261231004120 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