29#ifdef HAVE_SYS_UNISTD_H
30#include <sys/unistd.h>
33#ifdef HAVE_SYS_TYPES_H
36#ifdef HAVE_SYS_SOCKET_H
37#include <sys/socket.h>
39#ifdef HAVE_SYS_IOCTL_H
42#ifdef HAVE_NETINET_IN_H
43#include <netinet/in.h>
45#ifdef HAVE_ARPA_INET_H
51#ifdef COAP_EPOLL_SUPPORT
53#include <sys/timerfd.h>
67#include <lwip/timeouts.h>
68#include <lwip/tcpip.h>
71#ifndef INET6_ADDRSTRLEN
72#define INET6_ADDRSTRLEN 40
76#define min(a,b) ((a) < (b) ? (a) : (b))
92#error FRAC_BITS must be less or equal 8
96#define Q(frac,fval) ((uint16_t)(((1 << (frac)) * fval.integer_part) + \
97 ((1 << (frac)) * fval.fractional_part + 500)/1000))
100#define ACK_RANDOM_FACTOR \
101 Q(FRAC_BITS, session->ack_random_factor)
104#define ACK_TIMEOUT Q(FRAC_BITS, session->ack_timeout)
120 unsigned int result = 0;
169 if (node->
t < q->
t) {
181 }
while (q && q->
t <= node->
t);
244 memset(node, 0,
sizeof(*node));
272#if COAP_CLIENT_SUPPORT
300#if COAP_SERVER_SUPPORT
307 if (session->
context->spsk_setup_data.psk_info.key.length)
308 return &session->
context->spsk_setup_data.psk_info.key;
320 if (session->
context->spsk_setup_data.psk_info.hint.length)
321 return &session->
context->spsk_setup_data.psk_info.hint;
348 memset(&setup_data, 0,
sizeof(setup_data));
354 if (key && key_len > 0) {
378 ctx->spsk_setup_data = *setup_data;
381 return coap_dtls_context_set_spsk(ctx, setup_data);
404 coap_log_err(
"coap_context_set_pki: Wrong version of setup_data\n");
417 const char *ca_dir) {
429 const char *ca_dir) {
462#if COAP_CLIENT_SUPPORT
473 uint64_t rate_limit_ppm) {
474 if (rate_limit_ppm) {
483 uint32_t max_body_size) {
484 assert(max_body_size == 0 || max_body_size > 1024);
485 if (max_body_size == 0 || max_body_size > 1024) {
492 size_t max_token_size) {
503 unsigned int max_idle_sessions) {
514 unsigned int max_handshake_sessions) {
527 unsigned int csm_timeout) {
540 unsigned int csm_timeout_ms) {
541 if (csm_timeout_ms < 10)
543 if (csm_timeout_ms > 10000)
544 csm_timeout_ms = 10000;
555 uint32_t csm_max_message_size) {
556 assert(csm_max_message_size >= 64);
560 csm_max_message_size);
573 unsigned int session_timeout) {
579 unsigned int reconnect_time) {
585 unsigned int reconnect_time,
586 uint8_t retry_count) {
587#if COAP_CLIENT_SUPPORT
588 context->reconnect_time = reconnect_time;
589 context->retry_count = retry_count;
592 (void)reconnect_time;
604#if COAP_SERVER_SUPPORT
605 context->shutdown_no_send_observe = 1;
613#if COAP_EPOLL_SUPPORT
614 return context->epfd;
623#if COAP_EPOLL_SUPPORT
659#if COAP_CLIENT_SUPPORT
668#if COAP_SERVER_SUPPORT
677#if COAP_AF_UNIX_SUPPORT
723#if ! COAP_SERVER_SUPPORT
729 coap_log_warn(
"coap_startup() should be called before any other "
730 "coap_*() functions are called\n");
741#ifdef COAP_EPOLL_SUPPORT
742 c->epfd = epoll_create1(0);
744 coap_log_err(
"coap_new_context: Unable to epoll_create: %s (%d)\n",
750 c->eptimerfd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK);
751 if (c->eptimerfd == -1) {
752 coap_log_err(
"coap_new_context: Unable to timerfd_create: %s (%d)\n",
758 struct epoll_event event;
761 memset(&event, 0,
sizeof(event));
762 event.events = EPOLLIN;
764 event.data.ptr =
NULL;
766 ret = epoll_ctl(c->epfd, EPOLL_CTL_ADD, c->eptimerfd, &event);
789#if COAP_SERVER_SUPPORT
792 if (endpoint ==
NULL) {
800#if defined(WITH_LWIP)
802 if (sys_sem_new(&c->coap_io_timeout_sem, 0) != ERR_OK)
803 coap_log_warn(
"coap_new_context: Failed to set up semaphore\n");
844#if COAP_SERVER_SUPPORT
846 context->context_going_away = 1;
847 if (context->shutdown_no_send_observe)
848 context->observe_no_clear = 1;
849 coap_delete_all_resources(context);
851#if COAP_CLIENT_SUPPORT
853 context->reconnect_time = 0;
860 if (context->timer_configured) {
862 sys_untimeout(coap_io_process_timeout, (
void *)context);
864 context->timer_configured = 0;
868#if COAP_ASYNC_SUPPORT
869 coap_delete_all_async(context);
872#if COAP_SERVER_SUPPORT
876 HASH_ITER(hh, context->cache, cp, ctmp) {
879 if (context->cache_ignore_count) {
883 LL_FOREACH_SAFE(context->endpoint, ep, tmp) {
884 coap_free_endpoint_lkd(ep);
888#if COAP_CLIENT_SUPPORT
896#if COAP_OSCORE_SUPPORT
902#ifdef COAP_EPOLL_SUPPORT
903 if (context->eptimerfd != -1) {
905 struct epoll_event event;
908 ret = epoll_ctl(context->epfd, EPOLL_CTL_DEL, context->eptimerfd, &event);
914 close(context->eptimerfd);
915 context->eptimerfd = -1;
917 if (context->epfd != -1) {
918 close(context->epfd);
922#if COAP_SERVER_SUPPORT
923#if COAP_WITH_OBSERVE_PERSIST
924 coap_persist_cleanup(context);
927#if COAP_PROXY_SUPPORT
928 coap_proxy_cleanup(context);
934#if defined(WITH_LWIP)
936 sys_sem_free(&context->coap_io_timeout_sem);
939#if COAP_THREAD_SAFE && !WITH_LWIP
948#if COAP_SERVER_SUPPORT
956 session->
context->unknown_resource->is_reverse_proxy) {
961 if (proxy_uri || proxy_scheme) {
974 memset(&uri, 0,
sizeof(uri));
983 resource = session->
context->proxy_uri_resource;
984 if (uri.
host.
length && resource->proxy_name_count &&
985 resource->proxy_name_list) {
988 if (resource->proxy_name_count == 1 &&
989 resource->proxy_name_list[0]->length == 0) {
993 for (i = 0; i < resource->proxy_name_count; i++) {
999 if (i != resource->proxy_name_count) {
1030 switch (opt_iter.
number) {
1051 if (opt_iter.
number & 0x01) {
1053 switch (opt_iter.
number) {
1054#if COAP_Q_BLOCK_SUPPORT
1058 coap_log_debug(
"Critical option '%s' (%d) disabled - not supported\n",
1085#if COAP_OSCORE_SUPPORT
1087 if (ctx->p_osc_ctx || ctx->oscore_find_cb)
1093#if COAP_SERVER_SUPPORT
1094 if ((opt_iter.
number & 0x02) == 0) {
1117 if (opt_iter.
number & 0x02) {
1123 switch (opt_iter.
number) {
1138 coap_log_debug(
"Not Safe option %u cannot be forwarded - dropped\n",
1151 if (last_number == opt_iter.
number) {
1169 unsigned char buf[4];
1171 coap_log_debug(
"Option Block2 has invalid set M bit - cleared\n");
1188 last_number = opt_iter.
number;
1236 ssize_t bytes_written = -1;
1244 return bytes_written;
1249 ssize_t bytes_written;
1252#if ! COAP_CLIENT_SUPPORT
1264 coap_log_err(
"Multicast requests cannot be Confirmable (RFC7252 8.1)\n");
1283 return bytes_written;
1359 unsigned int result;
1362#define FP1 Q(FRAC_BITS, ((coap_fixed_point_t){1,0}))
1365#define SHR_FP(val,frac) (((val) + (1 << ((frac) - 1))) >> (frac))
1411 coap_log_debug(
"** %s: mid=0x%04x: added to retransmit queue (%ums)\n",
1421#if COAP_CLIENT_SUPPORT
1442 if (token ==
NULL) {
1447 token->
s[i] = (uint8_t)(i + 1);
1461 lg_crcv = coap_block_new_lg_crcv(session, pdu,
NULL);
1463 LL_PREPEND(session->lg_crcv, lg_crcv);
1479#if COAP_CLIENT_SUPPORT
1481 int timeout_ms = 5000;
1494 while (session->doing_first != 0) {
1513 if (result < timeout_ms) {
1514 timeout_ms -= result;
1516 if (session->doing_first == 1) {
1568#if COAP_CLIENT_SUPPORT
1583#
if COAP_OSCORE_SUPPORT
1584 session->oscore_encryption ||
1589#
if COAP_Q_BLOCK_SUPPORT
1612#if COAP_CLIENT_SUPPORT
1616 int observe_action = -1;
1617 int have_block1 = 0;
1627 coap_log_err(
"coap_send: Invalid PDU code (%d.%02d)\n",
1633#if COAP_CLIENT_SUPPORT
1640 if (session->doing_first) {
1641 LL_APPEND(session->doing_first_pdu, pdu);
1666 session->doing_first = 1;
1668 LL_PREPEND(session->doing_first_pdu, pdu);
1682#if COAP_Q_BLOCK_SUPPORT
1690 session->doing_first = 1;
1692 LL_PREPEND(session->doing_first_pdu, pdu);
1722#if COAP_OSCORE_SUPPORT
1723 if (session->oscore_encryption) {
1724 if (session->recipient_ctx->initial_state == 1 &&
1725 !session->recipient_ctx->silent_server) {
1731 session->doing_first = 1;
1750 const uint8_t *data;
1758 coap_log_debug(
"* Retransmitting PDU with Uri-Path-Abbrev replaced (3)\n");
1776 (block.
m == 1 || block.
bert == 1)) {
1779#if COAP_Q_BLOCK_SUPPORT
1781 (block.
m == 1 || block.
bert == 1)) {
1783 coap_log_warn(
"Block1 and Q-Block1 cannot be in the same request\n");
1798 scratch[0] =
'\000';
1800 size = strlen(scratch);
1801 snprintf(&scratch[size],
sizeof(scratch)-size,
1804 coap_log_debug(
"Token {%s} reused - see https://rfc-editor.org/rfc/rfc9175.html#section-4.2\n",
1816 coap_log_debug(
"coap_send: Using coap_cancel_observe() to do OBSERVE cancellation\n");
1820 ret = coap_cancel_observe_lkd(session, &tmp, pdu->
type);
1837 memset(&block, 0,
sizeof(block));
1840#if COAP_Q_BLOCK_SUPPORT
1841 if (!(session->
block_mode & COAP_BLOCK_HAS_Q_BLOCK))
1851 (block.
num << 4) | (0 << 3) | block.
szx),
1857 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1865 (block.
num << 4) | (0 << 3) | block.
szx),
1875 (block.
num << 4) | (block.
m << 3) | block.
szx),
1881 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1901#if COAP_Q_BLOCK_SUPPORT
1904 if (block.
num == 0 && block.
m == 0) {
1910 (0 << 4) | (1 << 3) | block.
szx),
1922 if (coap_check_send_need_lg_crcv(session, pdu)) {
1925 if (!session->
lg_xmit && have_block1) {
1930 LL_FOREACH(session->lg_crcv, lg_crcv) {
1933 LL_DELETE(session->lg_crcv, lg_crcv);
1934 coap_block_delete_lg_crcv(session, lg_crcv);
1939 if (have_block1 && session->
lg_xmit) {
1940 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1948 lg_crcv = coap_block_new_lg_crcv(session, pdu, lg_xmit);
1949 if (lg_crcv ==
NULL) {
1960#if COAP_Q_BLOCK_SUPPORT
1963 mid = coap_send_q_block1(session, block, pdu, COAP_SEND_INC_PDU);
1970#if COAP_CLIENT_SUPPORT
1973 LL_PREPEND(session->lg_crcv, lg_crcv);
1975 coap_block_delete_lg_crcv(session, lg_crcv);
1993 addr_str[
sizeof(addr_str)-1] =
'\000';
1995 sizeof(addr_str) - 1)) {
1999 if (addr_str[0] ==
'[') {
2000 cp = strchr(addr_str,
']');
2003 if (memcmp(&addr_str[1],
"::ffff:", 7) == 0) {
2010 cp = strchr(addr_str,
':');
2024 if (hop_limit == 1) {
2029 }
else if (hop_limit < 1 || hop_limit > 255) {
2058 pdu->
data[data_len] =
'\000';
2059 a_match = strstr((
char *)pdu->
data, cp);
2060 if (a_match && (a_match == (
char *)pdu->
data || a_match[-1] ==
' ') &&
2061 ((
size_t)(a_match - (
char *)pdu->
data + len) == data_len ||
2062 a_match[len] ==
' ')) {
2080 (uint8_t *)&hop_limit);
2084 memmove(pdu->
data + len + 1, pdu->
data,
2086 memcpy(pdu->
data, cp, len);
2087 pdu->
data[len] =
' ';
2099 ssize_t bytes_written;
2101#if ! COAP_SERVER_SUPPORT
2105#if COAP_CLIENT_SUPPORT
2106 if (session->session_failed) {
2108 if (session->session_failed)
2117#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG)
2121 coap_log_debug(
"** %s: mid 0x%04x: delaying transmission (%d.%03ds)\n",
2127 uint32_t timeout_ms;
2139 if (timeout_ms == 0) {
2153#if COAP_PROXY_SUPPORT
2154 if (session->server_list) {
2156 return coap_proxy_local_write(session, pdu);
2169 if (session->
echo) {
2176#if COAP_OSCORE_SUPPORT
2177 if (session->oscore_encryption) {
2188#if !COAP_DISABLE_TCP
2201 coap_log_debug(
"Remote end did not indicate CSM support for Block1 enabled\n");
2204 coap_log_debug(
"Remote end did not indicate CSM support for Block2 enabled\n");
2211 coap_log_debug(
"Remote end did not indicate CSM support for BERT Block1\n");
2215 coap_log_debug(
"Remote end did not indicate CSM support for BERT Block2\n");
2221#if COAP_OSCORE_SUPPORT
2222 if (session->oscore_encryption &&
2229 if (osc_pdu ==
NULL) {
2242#if COAP_SERVER_SUPPORT
2243 if (session->last_resp_pdu != pdu &&
2248 session->last_resp_pdu = pdu;
2257 if (bytes_written < 0) {
2263#if !COAP_DISABLE_TCP
2265 (
size_t)bytes_written < pdu->used_size + pdu->
hdr_size) {
2289 node->
id = pdu->
mid;
2307 coap_pdu_t **response_pdu, uint32_t timeout_ms) {
2328 coap_pdu_t **response_pdu, uint32_t timeout_ms) {
2329#if COAP_CLIENT_SUPPORT
2331 uint32_t rem_timeout = timeout_ms;
2337 uint32_t time_so_far_ms;
2340 assert(request_pdu);
2344 session->resp_pdu =
NULL;
2361 session->doing_send_recv = 1;
2366 if (!session->doing_send_recv)
2374 while (rem_timeout > 0 && session->doing_send_recv && !session->resp_pdu) {
2388 if (time_so_far_ms >= timeout_ms) {
2391 rem_timeout = timeout_ms - time_so_far_ms;
2396 ticks_so_far = now - start;
2398 if (time_so_far_ms >= timeout_ms) {
2401 rem_timeout = timeout_ms - time_so_far_ms;
2408 ticks_so_far = now - start;
2410 ret = time_so_far_ms;
2412 *response_pdu = session->resp_pdu;
2413 session->resp_pdu =
NULL;
2414 if (*response_pdu ==
NULL) {
2424 session->doing_send_recv = 0;
2427 session->resp_pdu =
NULL;
2429 session->req_token =
NULL;
2437 coap_log_warn(
"coap_send_recv: Client mode not supported\n");
2438 *response_pdu =
NULL;
2446 if (!context || !node || !node->
session)
2449#if COAP_CLIENT_SUPPORT
2450 if (node->
session->session_failed) {
2458 ssize_t bytes_written;
2478 node->
t = next_delay;
2489 coap_log_debug(
"** %s: mid=0x%04x: mcast delayed transmission\n",
2492 coap_log_debug(
"** %s: mid=0x%04x: retransmission #%d (next %ums)\n",
2515 if (bytes_written < 0)
2516 return (
int)bytes_written;
2521#if COAP_CLIENT_SUPPORT
2522 if (node->
session->session_failed) {
2523 coap_log_info(
"** %s: mid=0x%04x: deleted due to reconnection issue\n",
2528 coap_log_warn(
"** %s: mid=0x%04x: give up after %d attempts\n",
2530#if COAP_CLIENT_SUPPORT
2534#if COAP_SERVER_SUPPORT
2538 (node->
session->ref_subscriptions || node->
session->ref_proxy_subs)) {
2544 if (node->
session->ref_subscriptions)
2546#if COAP_PROXY_SUPPORT
2548 if (node->
session->ref_proxy_subs)
2550 0, COAP_PROXY_SUBS_TOKEN);
2574#if COAP_CLIENT_SUPPORT
2575 node->
session->doing_send_recv = 0;
2590#if COAP_SERVER_SUPPORT
2592 result = coap_dtls_hello(session, data, data_len);
2603#if COAP_CLIENT_SUPPORT
2629 ssize_t bytes_written;
2633 coap_log_debug(
"** %s: mid=0x%04x: transmitted after delay (1)\n",
2639 if (bytes_written > 0)
2641 if (bytes_written <= 0 ||
2643 if (bytes_written > 0)
2655#if COAP_CONSTRAINED_STACK
2667 packet->
length =
sizeof(payload);
2678 if (bytes_read < 0) {
2679 if (bytes_read == -2) {
2684 }
else if (bytes_read > 0) {
2686#if COAP_CLIENT_SUPPORT
2687 if (session->session_failed) {
2688 session->session_failed = 0;
2697#if !COAP_DISABLE_TCP
2700 ssize_t bytes_read = 0;
2706 if (bytes_read < 0) {
2708 }
else if (bytes_read > 2) {
2730 ssize_t bytes_read = 0;
2738 if (bytes_read > 0) {
2742 retry = bytes_read == (ssize_t)packet->
length;
2743 while (bytes_read > 0) {
2748 size_t n =
min(len, (
size_t)bytes_read);
2764 }
else if (error_opts.
mask) {
2769 coap_log_warn(
"coap_read_session: cannot create error response\n");
2772 coap_log_warn(
"coap_read_session: error sending response\n");
2785 size_t len = hdr_size + tok_ext_bytes - session->
partial_read;
2786 size_t n =
min(len, (
size_t)bytes_read);
2793 hdr_size + tok_ext_bytes);
2842 }
while (bytes_read == 0 && retry);
2849#if COAP_SERVER_SUPPORT
2852 ssize_t bytes_read = -1;
2854#if COAP_CONSTRAINED_STACK
2869 packet->
length =
sizeof(payload);
2875 if (bytes_read < 0) {
2876 if (errno != EAGAIN) {
2879 }
else if (bytes_read > 0) {
2880 coap_session_t *session = coap_endpoint_get_session(endpoint, packet, now);
2902#if !COAP_DISABLE_TCP
2906 coap_session_t *session = coap_new_server_session(ctx, endpoint, extra);
2909 return session !=
NULL;
2923#ifdef COAP_EPOLL_SUPPORT
2926 coap_log_emerg(
"coap_io_do_io() requires libcoap not compiled for using epoll\n");
2931#if COAP_SERVER_SUPPORT
2933 LL_FOREACH_SAFE(ctx->endpoint, ep, tmp) {
2935 coap_read_endpoint(ctx, ep, now);
2937 coap_write_endpoint(ctx, ep, now);
2938#if !COAP_DISABLE_TCP
2940 coap_accept_endpoint(ctx, ep, now,
NULL);
2945#if COAP_CLIENT_SUPPORT
2961#if COAP_CLIENT_SUPPORT
2993#ifndef COAP_EPOLL_SUPPORT
2997 coap_log_emerg(
"coap_io_do_epoll() requires libcoap compiled for using epoll\n");
3004 for (j = 0; j < nevents; j++) {
3009#if COAP_SERVER_SUPPORT
3010 if (sock->endpoint) {
3013 (events[j].events & EPOLLIN)) {
3015 coap_read_endpoint(endpoint->context, endpoint, now);
3019 (events[j].events & EPOLLOUT)) {
3026 coap_write_endpoint(endpoint->context, endpoint, now);
3029#if !COAP_DISABLE_TCP
3031 (events[j].events & EPOLLIN)) {
3033 coap_accept_endpoint(endpoint->context, endpoint, now,
NULL);
3045#if COAP_CLIENT_SUPPORT
3047 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
3058 (events[j].events & (EPOLLIN|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
3064 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
3076 }
else if (ctx->eptimerfd != -1) {
3085 if (read(ctx->eptimerfd, &count,
sizeof(count)) == -1) {
3098 uint8_t *msg,
size_t msg_len) {
3113 coap_log_debug(
"coap_handle_dgram: UDP version not supported\n");
3131 coap_log_warn(
"coap_handle_dgram: cannot create error response\n");
3134 coap_log_warn(
"coap_handle_dgram: error sending response\n");
3162 if (!queue || !*queue) {
3169 if (session == (*queue)->session && mid == (*queue)->id &&
3172 *queue = (*queue)->
next;
3174 (*queue)->t += (*node)->t;
3187 }
while (q && (session != q->
session || mid != q->
id ||
3212 if (!queue || !*queue)
3217 if (session == (*queue)->session &&
3220 *queue = (*queue)->
next;
3222 (*queue)->t += (*node)->t;
3241 }
while (q && (session != q->
session ||
3345#if COAP_ERROR_PHRASE_LENGTH > 0
3379#if COAP_ERROR_PHRASE_LENGTH > 0
3380 snprintf(buf,
sizeof(buf),
"%s", phrase ? phrase :
"");
3388 snprintf(&buf[len],
sizeof(buf) - len,
"%s%d", first ?
" " :
",",
3394 if (opts->
mask & (1 << i)) {
3396 snprintf(&buf[len],
sizeof(buf) - len,
"%s%d", first ?
" " :
",",
3401 coap_add_data(response, (
size_t)strlen(buf), (
const uint8_t *)buf);
3402 }
else if (opts && opts->
mask) {
3412#if COAP_ERROR_PHRASE_LENGTH > 0
3414 coap_add_data(response, (
size_t)strlen(phrase), (
const uint8_t *)phrase);
3418 coap_add_data(response, (
size_t)strlen(phrase), (
const uint8_t *)phrase);
3426#if COAP_SERVER_SUPPORT
3427#define SZX_TO_BYTES(SZX) ((size_t)(1 << ((SZX) + 4)))
3454 result = coap_print_wellknown_lkd(session->
context, buf, &wkc_len, UINT_MAX, query);
3456 coap_log_warn(
"cannot determine length of /.well-known/core\n");
3466 result = coap_print_wellknown_lkd(session->
context, data_string->
s, &len, 0, query);
3471 assert(len <= (
size_t)wkc_len);
3472 data_string->
length = len;
3492 free_wellknown_response(session, data_string);
3493 }
else if (!coap_add_data_large_response_lkd(resource, session, request,
3496 -1, 0, data_string->
length,
3498 free_wellknown_response,
3500 goto error_released;
3513 free_wellknown_response(session, data_string);
3515 if (response->
code == 0) {
3536 int num_cancelled = 0;
3538#ifndef COAP_SERVER_SUPPORT
3543#if COAP_SERVER_SUPPORT
3547 RESOURCES_ITER(context->resources, r) {
3553 return num_cancelled;
3556#if COAP_SERVER_SUPPORT
3561enum respond_t { RESPONSE_DEFAULT, RESPONSE_DROP, RESPONSE_SEND };
3608static enum respond_t
3613 unsigned int val = 0;
3640 return RESPONSE_SEND;
3642 return RESPONSE_DROP;
3646 return RESPONSE_SEND;
3648 }
else if (resource && session->
context->mcast_per_resource &&
3651 if ((resource->flags &
3654 return RESPONSE_DROP;
3655 }
else if ((resource->flags &
3659 return RESPONSE_DROP;
3660 }
else if ((resource->flags &
3663 return RESPONSE_DROP;
3664 }
else if ((resource->flags &
3667 return RESPONSE_DROP;
3674 return RESPONSE_DROP;
3685 return RESPONSE_DROP;
3687 if ((!resource || session->
context->mcast_per_resource == 0) &&
3689 return RESPONSE_DROP;
3695 return RESPONSE_DEFAULT;
3717 enum respond_t respond = RESPONSE_DEFAULT;
3720 int is_proxy_uri = 0;
3721 int is_proxy_scheme = 0;
3722 int skip_hop_limit_check = 0;
3729 int added_block = 0;
3731#if COAP_Q_BLOCK_SUPPORT
3732 int lg_xmit_ctrl = 0;
3734#if COAP_ASYNC_SUPPORT
3738#if COAP_ASYNC_SUPPORT
3739 async = coap_find_async_lkd(session, pdu->
actual_token);
3744 if (async->delay == 0 || async->delay > now) {
3755 if (!(context->unknown_resource && context->unknown_resource->is_reverse_proxy)) {
3764 is_proxy_scheme = 1;
3772 if (is_proxy_scheme || is_proxy_uri) {
3775 if (!context->proxy_uri_resource) {
3778 is_proxy_scheme ?
"Scheme" :
"Uri");
3782 if (((
size_t)pdu->
code - 1 <
3783 (
sizeof(resource->handler) /
sizeof(resource->handler[0]))) &&
3784 !(context->proxy_uri_resource->handler[pdu->
code - 1])) {
3787 is_proxy_scheme ?
"Scheme" :
"Uri",
3803 memset(&uri, 0,
sizeof(uri));
3812 resource = context->proxy_uri_resource;
3813 if (uri.
host.
length && resource->proxy_name_count &&
3814 resource->proxy_name_list) {
3817 if (resource->proxy_name_count == 1 &&
3818 resource->proxy_name_list[0]->length == 0) {
3822 for (i = 0; i < resource->proxy_name_count; i++) {
3828 if (i != resource->proxy_name_count) {
3838 is_proxy_scheme = 0;
3839 skip_hop_limit_check = 1;
3844 assert(resource ==
NULL);
3846 if (!skip_hop_limit_check) {
3854 if (hop_limit == 1) {
3858 }
else if (hop_limit < 1 || hop_limit > 255) {
3877 if (!is_proxy_uri && !is_proxy_scheme) {
3880 resource = coap_get_resource_from_uri_path_lkd(context, &uri_path_c);
3883 if ((resource ==
NULL) || (resource->is_unknown == 1) ||
3884 (resource->is_proxy_uri == 1)) {
3888 if (resource !=
NULL)
3914 if (is_proxy_uri || is_proxy_scheme) {
3915 resource = context->proxy_uri_resource;
3916 }
else if (context->unknown_resource !=
NULL &&
3918 ((
size_t)pdu->
code - 1 <
3920 (context->unknown_resource->handler[pdu->
code - 1])) {
3921 resource = context->unknown_resource;
3924 resource = &resource_uri_wellknown;
3925 }
else if ((context->unknown_resource !=
NULL) &&
3926 ((
size_t)pdu->
code - 1 <
3928 (context->unknown_resource->handler[pdu->
code - 1])) {
3947 resource = context->unknown_resource;
3960 resource = coap_add_dynamic_resource(session, pdu);
3967 coap_log_debug(
"request for unknown resource '%*.*s', return 4.04\n",
3975 coap_resource_reference_lkd(resource);
3977#if COAP_OSCORE_SUPPORT
3979 coap_log_debug(
"request for OSCORE only resource '%*.*s', return 4.04\n",
3985 if (resource->is_unknown == 0 && resource->is_proxy_uri == 0) {
3995 if ((
size_t)pdu->
code - 1 <
3997 h = resource->handler[pdu->
code - 1];
4013 if (context->mcast_per_resource &&
4033#if COAP_ASYNC_SUPPORT
4051 if (resource->observable &&
4067 if (coap_handle_request_put_block(context, session, pdu, response,
4068 resource, uri_path, observe,
4069 &added_block, &free_lg_srcv)) {
4075 if (coap_handle_request_send_block(session, pdu, response, resource,
4077#if COAP_Q_BLOCK_SUPPORT
4093 if (block.
num != 0) {
4097#if COAP_Q_BLOCK_SUPPORT
4100 if (block.
num != 0) {
4106 subscription = coap_add_observer(resource, session, &pdu->
actual_token,
4111 coap_touch_observer(context, session, &pdu->
actual_token);
4118 coap_delete_observer_request(resource, session, &pdu->
actual_token, pdu);
4120 coap_log_info(
"observe: unexpected action %d\n", observe_action);
4124#if COAP_WITH_OBSERVE_PERSIST
4126 if (resource == context->unknown_resource) {
4127 context->unknown_pdu = pdu;
4128 context->unknown_session = session;
4130 context->unknown_pdu =
NULL;
4136 if (resource == &resource_uri_wellknown) {
4139 (
int)resource->uri_path->length, (
int)resource->uri_path->length,
4140 resource->uri_path->s);
4141 h(resource, session, pdu, query, response);
4144 (
int)resource->uri_path->length, (
int)resource->uri_path->length,
4145 resource->uri_path->s);
4152 h(resource, session, pdu, query, response),
4160 coap_log_warn(
"handle_request: Invalid PDU response code (%d.%02d)\n",
4162 response->
code & 0x1f);
4163 goto drop_it_no_debug;
4179 LL_FOREACH(session->lg_srcv, lg_srcv) {
4180 if (lg_srcv == free_lg_srcv) {
4181#if COAP_Q_BLOCK_SUPPORT
4191 coap_ticks(&free_lg_srcv->rec_blocks.last_seen);
4192 if (free_lg_srcv->rec_blocks.last_seen > adjust) {
4193 free_lg_srcv->rec_blocks.last_seen -= adjust;
4195 free_lg_srcv->dont_timeout = 0;
4199 LL_DELETE(session->lg_srcv, free_lg_srcv);
4200 coap_block_delete_lg_srcv(session, free_lg_srcv);
4212 respond = no_response(pdu, response, session, resource);
4213 if (respond != RESPONSE_DROP) {
4214#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG)
4224 coap_delete_observer(resource, session, &pdu->
actual_token);
4234 && (response->
code == 0)) {
4243 (context->mcast_per_resource &&
4247#if COAP_Q_BLOCK_SUPPORT
4252 if (coap_send_q_block2(session, resource, query, pdu->
code, block,
4272 goto drop_it_no_debug;
4276 goto drop_it_no_debug;
4279 node->
id = response->
mid;
4280 node->
pdu = response;
4284 coap_log_debug(
" %s: mid=0x%04x: mcast response delayed for %u.%03u secs\n",
4290 node->
timeout = (
unsigned int)delay;
4306#if COAP_Q_BLOCK_SUPPORT
4326 coap_resource_release_lkd(resource);
4338 coap_resource_release_lkd(resource);
4343#if COAP_CLIENT_SUPPORT
4352#if COAP_PROXY_SUPPORT
4353 if (context->proxy_response_cb) {
4355 coap_proxy_req_t *proxy_req = coap_proxy_map_outgoing_request(session,
4359 if (proxy_req && proxy_req->incoming && !proxy_req->incoming->server_list) {
4360 coap_proxy_process_incoming(session, rcvd, body_data, proxy_req,
4366 if (session->doing_send_recv && session->req_token &&
4369 session->resp_pdu = rcvd;
4376 }
else if (context->response_cb) {
4378 context->response_cb(session,
4432 coap_log_debug(
"Extended Token requested size support not available\n");
4439 lg_crcv = coap_find_lg_crcv(session, rcvd);
4441 LL_DELETE(session->lg_crcv, lg_crcv);
4442 coap_block_delete_lg_crcv(session, lg_crcv);
4448#if COAP_Q_BLOCK_SUPPORT
4450 if (session->
block_mode & COAP_BLOCK_PROBE_Q_BLOCK) {
4476 if (coap_handle_response_send_block(session, sent, rcvd)) {
4483 if (coap_handle_response_get_block(context, session, sent, rcvd,
4496#if !COAP_DISABLE_TCP
4514 coap_log_warn(
"***%s: Increase timeout in coap_context_set_csm_timeout_ms() to > %d\n",
4529 coap_log_debug(
"* %s: Restricting CSM Max-Message-Size size to %u\n",
4600 coap_log_warn(
"coap_dispatch: cannot create error response\n");
4626 int packet_is_bad = 0;
4627#if COAP_OSCORE_SUPPORT
4631 int is_ext_token_rst = 0;
4632 int oscore_invalid = 0;
4633 int is_local_mcast = 0;
4643 coap_log_info(
"Invalid multicast packet received RFC7252 8.1\n");
4650 coap_log_info(
"coap_dispatch: Received invalid PDU code (%d.%02d)\n",
4664#if COAP_SERVER_SUPPORT
4667 pdu->
mid == session->last_resp_pdu->mid) {
4668#if COAP_OSCORE_SUPPORT
4669 uint8_t oscore_encryption = session->oscore_encryption;
4671 session->oscore_encryption = 0;
4678#if COAP_OSCORE_SUPPORT
4679 session->oscore_encryption = oscore_encryption;
4683#if COAP_OSCORE_SUPPORT
4684 session->oscore_encryption = oscore_encryption;
4693#if COAP_OSCORE_SUPPORT
4702 coap_log_warn(
"coap_dispatch: cannot create error response\n");
4716#if COAP_SERVER_SUPPORT
4725#if COAP_SERVER_SUPPORT
4731 memset(&uri, 0,
sizeof(uri));
4734 resource = context->proxy_uri_resource;
4735 if (uri.
host.
length && resource && resource->proxy_name_count &&
4736 resource->proxy_name_list) {
4738 for (i = 0; i < resource->proxy_name_count; i++) {
4743 if (i == resource->proxy_name_count) {
4757 if (session->recipient_ctx ==
NULL ||
4758 (session->recipient_ctx->initial_state == 0 &&
4766 session->oscore_encryption = 1;
4775 session->oscore_encryption &&
4779 coap_log_err(
"received an invalid response to the OSCORE request\n");
4785 switch (pdu->
type) {
4799 if (oscore_invalid ||
4805#if COAP_SERVER_SUPPORT
4814#if COAP_Q_BLOCK_SUPPORT
4816 !(session->
block_mode & COAP_BLOCK_PROBE_Q_BLOCK)) {
4817 int doing_q_block = 0;
4820 LL_FOREACH(session->
lg_xmit, lg_xmit) {
4827 if (doing_q_block && lg_xmit) {
4830 memset(&block, 0,
sizeof(block));
4842 coap_send_q_blocks(session, lg_xmit, block,
4843 lg_xmit->
sent_pdu, COAP_SEND_SKIP_PDU);
4847 if (pdu->
code == 0) {
4848#if COAP_CLIENT_SUPPORT
4862 !coap_check_send_need_lg_crcv(session, sent->
pdu) &&
4870 uint64_t token_match =
4874 LL_FOREACH(session->lg_crcv, lg_crcv) {
4885 lg_crcv = coap_block_new_lg_crcv(session, sent->
pdu,
NULL);
4887 LL_PREPEND(session->lg_crcv, lg_crcv);
4914#if COAP_CLIENT_SUPPORT
4915#if COAP_Q_BLOCK_SUPPORT
4917 if (session->
block_mode & COAP_BLOCK_PROBE_Q_BLOCK &&
4932 is_ext_token_rst = 1;
4936 if (!is_ping_rst && !is_ext_token_rst)
4953 if (!is_ping_rst && !is_ext_token_rst) {
4957 }
else if (is_ping_rst) {
4966#if COAP_SERVER_SUPPORT
4968 RESOURCES_ITER(context->resources, r) {
4970 LL_FOREACH_SAFE(r->subscribers, obs, tmp) {
4971 if (obs->pdu->mid == pdu->
mid && obs->session == session) {
4974 coap_delete_observer(r, session, &obs->pdu->actual_token);
4984#if COAP_PROXY_SUPPORT
4987 coap_delete_proxy_subscriber(session,
NULL, pdu->
mid, COAP_PROXY_SUBS_MID);
4994 if (oscore_invalid ||
5002 coap_log_warn(
"coap_dispatch: cannot create error response\n");
5024 if (oscore_invalid ||
5033 coap_log_warn(
"coap_dispatch: cannot create error response\n");
5050#if !COAP_DISABLE_TCP
5055#if COAP_SERVER_SUPPORT
5057 handle_request(context, session, pdu, orig_pdu);
5060#if COAP_CLIENT_SUPPORT
5062 handle_response(context, session, sent ? sent->
pdu :
NULL, pdu);
5095 if (packet_is_bad) {
5104#if COAP_OSCORE_SUPPORT
5108#if COAP_SERVER_SUPPORT || COAP_OSCORE_SUPPORT
5114#if COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG
5119 return "COAP_EVENT_DTLS_CLOSED";
5121 return "COAP_EVENT_DTLS_CONNECTED";
5123 return "COAP_EVENT_DTLS_RENEGOTIATE";
5125 return "COAP_EVENT_DTLS_ERROR";
5127 return "COAP_EVENT_TCP_CONNECTED";
5129 return "COAP_EVENT_TCP_CLOSED";
5131 return "COAP_EVENT_TCP_FAILED";
5133 return "COAP_EVENT_SESSION_CONNECTED";
5135 return "COAP_EVENT_SESSION_CLOSED";
5137 return "COAP_EVENT_SESSION_FAILED";
5139 return "COAP_EVENT_PARTIAL_BLOCK";
5141 return "COAP_EVENT_XMIT_BLOCK_FAIL";
5143 return "COAP_EVENT_BLOCK_ISSUE";
5145 return "COAP_EVENT_SERVER_SESSION_NEW";
5147 return "COAP_EVENT_SERVER_SESSION_DEL";
5149 return "COAP_EVENT_SERVER_SESSION_CONNECTED";
5151 return "COAP_EVENT_BAD_PACKET";
5153 return "COAP_EVENT_MSG_RETRANSMITTED";
5155 return "COAP_EVENT_FIRST_PDU_FAIL";
5157 return "COAP_EVENT_OSCORE_DECRYPTION_FAILURE";
5159 return "COAP_EVENT_OSCORE_NOT_ENABLED";
5161 return "COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD";
5163 return "COAP_EVENT_OSCORE_NO_SECURITY";
5165 return "COAP_EVENT_OSCORE_INTERNAL_ERROR";
5167 return "COAP_EVENT_OSCORE_DECODE_ERROR";
5169 return "COAP_EVENT_WS_PACKET_SIZE";
5171 return "COAP_EVENT_WS_CONNECTED";
5173 return "COAP_EVENT_WS_CLOSED";
5175 return "COAP_EVENT_KEEPALIVE_FAILURE";
5177 return "COAP_EVENT_RECONNECT_FAILED";
5179 return "COAP_EVENT_RECONNECT_SUCCESS";
5181 return "COAP_EVENT_RECONNECT_NO_MORE";
5183 return "COAP_EVENT_RECONNECT_STARTED";
5208#if COAP_PROXY_SUPPORT
5210 coap_proxy_remove_association(session, 0);
5215#if COAP_CLIENT_SUPPORT
5232 session->doing_send_recv = 0;
5300#if COAP_SERVER_SUPPORT
5303 LL_FOREACH(context->endpoint, ep) {
5312#if COAP_CLIENT_SUPPORT
5322#if COAP_SERVER_SUPPORT
5323#if COAP_ASYNC_SUPPORT
5334 if (context->async_state_traversing)
5336 context->async_state_traversing = 1;
5337 LL_FOREACH_SAFE(context->async_state, async, tmp) {
5338 if (async->delay != 0 && !async->session->is_rate_limiting) {
5339 if (async->delay <= now) {
5343 handle_request(context, async->session, async->pdu,
NULL);
5346 coap_free_async_lkd(async->session, async);
5348 next_due = async->delay - now;
5354 *tim_rem = next_due;
5355 context->async_state_traversing = 0;
5395#if defined(HAVE_WINSOCK2_H)
5396 WORD wVersionRequested = MAKEWORD(2, 2);
5398 WSAStartup(wVersionRequested, &wsaData);
5407 coap_start_io_process();
5412 coap_io_lwip_init();
5414#if COAP_SERVER_SUPPORT
5416 (
const uint8_t *)
".well-known/core"
5418 memset(&resource_uri_wellknown, 0,
sizeof(resource_uri_wellknown));
5419 resource_uri_wellknown.ref = 1;
5420 resource_uri_wellknown.handler[
COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
5422 resource_uri_wellknown.uri_path = &well_known;
5433#if defined(HAVE_WINSOCK2_H)
5435#elif defined(WITH_CONTIKI)
5436 coap_stop_io_process();
5439 coap_io_lwip_cleanup();
5459#if COAP_CLIENT_SUPPORT
5460 context->response_cb = handler;
5470#if COAP_PROXY_SUPPORT
5471 context->proxy_response_cb = handler;
5499 uint32_t dynamic_max) {
5517#if ! defined WITH_CONTIKI && ! defined WITH_LWIP && ! defined RIOT_VERSION && !defined(__ZEPHYR__)
5518#if COAP_SERVER_SUPPORT
5521 const char *ifname) {
5533 const char *group_name,
5534 const char *ifname) {
5535#if COAP_IPV4_SUPPORT
5536 struct ip_mreq mreq4;
5538#if COAP_IPV6_SUPPORT
5539 struct ipv6_mreq mreq6;
5541 struct addrinfo *resmulti =
NULL, hints, *ainfo;
5544#if !defined(ESPIDF_VERSION) && COAP_IPV6_SUPPORT && !defined(HAVE_IF_NAMETOINDEX) && !defined(__QNXNTO__)
5547 int mgroup_setup = 0;
5549 if (single_endpoint) {
5552#if !defined(ESPIDF_VERSION) && COAP_IPV6_SUPPORT && !defined(HAVE_IF_NAMETOINDEX) && !defined(__QNXNTO__)
5553 lookup_endpoint = single_endpoint;
5557 assert(ctx->endpoint);
5560#if !defined(ESPIDF_VERSION) && COAP_IPV6_SUPPORT && !defined(HAVE_IF_NAMETOINDEX) && !defined(__QNXNTO__)
5561 lookup_endpoint = ctx->endpoint;
5566#if COAP_IPV6_SUPPORT
5567 mreq6.ipv6mr_interface = 0;
5569#if COAP_IPV4_SUPPORT
5570 mreq4.imr_interface.s_addr = INADDR_ANY;
5573 memset(&hints, 0,
sizeof(hints));
5574 hints.ai_socktype = SOCK_DGRAM;
5577 result = getaddrinfo(group_name,
NULL, &hints, &resmulti);
5581 "Cannot resolve multicast address: %s\n",
5582 group_name, gai_strerror(result));
5592#if defined(ESPIDF_VERSION)
5593 struct netif *netif;
5595#if COAP_IPV4_SUPPORT
5602 for (ainfo = resmulti; ainfo !=
NULL && !(done_ip4 == 1 && done_ip6 == 1);
5603 ainfo = ainfo->ai_next) {
5604 switch (ainfo->ai_family) {
5605#if COAP_IPV6_SUPPORT
5610#if defined(ESPIDF_VERSION)
5611 netif = netif_find(ifname);
5613 mreq6.ipv6mr_interface = netif_get_index(netif);
5616 "Cannot get IPv4 address: %s\n",
5619 memset(&ifr, 0,
sizeof(ifr));
5620 strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
5621 ifr.ifr_name[IFNAMSIZ - 1] =
'\000';
5623#ifdef HAVE_IF_NAMETOINDEX
5624 mreq6.ipv6mr_interface = if_nametoindex(ifr.ifr_name);
5625 if (mreq6.ipv6mr_interface == 0) {
5627 "cannot get interface index for '%s'\n",
5630#elif defined(__QNXNTO__)
5632 result = ioctl(lookup_endpoint->sock.fd, SIOCGIFINDEX, &ifr);
5635 "cannot get interface index for '%s': %s\n",
5639 mreq6.ipv6mr_interface = ifr.ifr_ifindex;
5645#if COAP_IPV4_SUPPORT
5650#if defined(ESPIDF_VERSION)
5651 netif = netif_find(ifname);
5653 mreq4.imr_interface.s_addr = netif_ip4_addr(netif)->addr;
5656 "Cannot get IPv4 address: %s\n",
5663 ip4fd = socket(AF_INET, SOCK_DGRAM, 0);
5665 coap_log_err(
"coap_join_mcast_group_intf: %s: socket: %s\n",
5669 memset(&ifr, 0,
sizeof(ifr));
5670 strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
5671 ifr.ifr_name[IFNAMSIZ - 1] =
'\000';
5672 result = ioctl(ip4fd, SIOCGIFADDR, &ifr);
5675 "Cannot get IPv4 address: %s\n",
5679 mreq4.imr_interface = ((
struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
5700 for (ainfo = resmulti; ainfo !=
NULL; ainfo = ainfo->ai_next) {
5701 for (endpoint = single_endpoint ? single_endpoint : ctx->endpoint;
5703 endpoint = single_endpoint ?
NULL : endpoint->next) {
5709#if COAP_IPV6_SUPPORT
5710 if (ainfo->ai_family == AF_INET6) {
5712 if (endpoint->bind_addr.addr.sa.sa_family == AF_INET6) {
5717 mreq6.ipv6mr_interface =
5718 endpoint->bind_addr.addr.sin6.sin6_scope_id;
5720 mreq6.ipv6mr_interface = 0;
5723 gaddr.
addr.
sin6.sin6_family = AF_INET6;
5724 gaddr.
addr.
sin6.sin6_port = endpoint->bind_addr.addr.sin6.sin6_port;
5725 gaddr.
addr.
sin6.sin6_addr = mreq6.ipv6mr_multiaddr =
5726 ((
struct sockaddr_in6 *)ainfo->ai_addr)->sin6_addr;
5727 result = setsockopt(endpoint->sock.fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
5728 (
char *)&mreq6,
sizeof(mreq6));
5731#if COAP_IPV4_SUPPORT && COAP_IPV6_SUPPORT
5734#if COAP_IPV4_SUPPORT
5735 if (ainfo->ai_family == AF_INET) {
5737 if (endpoint->bind_addr.addr.sa.sa_family == AF_INET) {
5742 mreq4.imr_interface = endpoint->bind_addr.addr.sin.sin_addr;
5744 mreq4.imr_interface.s_addr = INADDR_ANY;
5747 gaddr.
addr.
sin.sin_family = AF_INET;
5748 gaddr.
addr.
sin.sin_port = endpoint->bind_addr.addr.sin.sin_port;
5749 gaddr.
addr.
sin.sin_addr.s_addr = mreq4.imr_multiaddr.s_addr =
5750 ((
struct sockaddr_in *)ainfo->ai_addr)->sin_addr.s_addr;
5751 result = setsockopt(endpoint->sock.fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
5752 (
char *)&mreq4,
sizeof(mreq4));
5760 coap_log_err(
"coap_join_mcast_group_intf: %s: setsockopt: %s\n",
5765 addr_str[
sizeof(addr_str)-1] =
'\000';
5767 sizeof(addr_str) - 1)) {
5779 if (!mgroup_setup) {
5784 freeaddrinfo(resmulti);
5791 const char *group_name,
5792 const char *ifname) {
5795 if (!endpoint || !endpoint->context)
5806 context->mcast_per_resource = 1;
5811#if COAP_CLIENT_SUPPORT
5816#if COAP_IPV4_SUPPORT
5818 if (setsockopt(session->
sock.
fd, IPPROTO_IP, IP_MULTICAST_TTL,
5819 (
const char *)&hops,
sizeof(hops)) < 0) {
5826#if COAP_IPV6_SUPPORT
5828 if (setsockopt(session->
sock.
fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
5829 (
const char *)&hops,
sizeof(hops)) < 0) {
void coap_address_init(coap_address_t *addr)
Resets the given coap_address_t object addr to its default values.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast address.
void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
const char * coap_option_string(coap_pdu_code_t code, coap_option_num_t number)
Returns a textual description of the option name.
void coap_debug_reset(void)
Reset all the defined logging parameters.
struct coap_lg_crcv_t coap_lg_crcv_t
struct coap_endpoint_t coap_endpoint_t
struct coap_async_t coap_async_t
Async Entry information.
struct coap_cache_entry_t coap_cache_entry_t
struct coap_proxy_entry_t coap_proxy_entry_t
Proxy information.
struct coap_subscription_t coap_subscription_t
struct coap_resource_t coap_resource_t
struct coap_lg_srcv_t coap_lg_srcv_t
const char * coap_socket_strerror(void)
void coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t *length)
Given a packet, set msg and msg_len to an address and length of the packet's data in memory.
void coap_update_io_timer(coap_context_t *context, coap_tick_t delay)
Update when to continue with I/O processing, unless packets come in in the meantime.
#define COAP_RXBUFFER_SIZE
#define COAP_SOCKET_ERROR
@ COAP_NACK_NOT_DELIVERABLE
@ COAP_NACK_TOO_MANY_RETRIES
#define COAP_SOCKET_MULTICAST
socket is used for multicast communication
#define COAP_SOCKET_WANT_ACCEPT
non blocking server socket is waiting for accept
#define COAP_SOCKET_NOT_EMPTY
the socket is not empty
#define COAP_SOCKET_CAN_WRITE
non blocking socket can now write without blocking
#define COAP_SOCKET_BOUND
the socket is bound
#define COAP_SOCKET_WANT_READ
non blocking socket is waiting for reading
#define COAP_SOCKET_CAN_ACCEPT
non blocking server socket can now accept without blocking
#define COAP_SOCKET_WANT_WRITE
non blocking socket is waiting for writing
#define COAP_SOCKET_CAN_CONNECT
non blocking client socket can now connect without blocking
void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func)
Epoll specific function to modify the state of events that epoll is tracking on the appropriate file ...
#define COAP_SOCKET_WANT_CONNECT
non blocking client socket is waiting for connect
#define COAP_SOCKET_CAN_READ
non blocking socket can now read without blocking
#define COAP_SOCKET_CONNECTED
the socket is connected
Library specific build wrapper for coap_internal.h.
void coap_dump_memory_type_counts(coap_log_t level)
Dumps the current usage of malloc'd memory types.
void coap_memory_init(void)
Initializes libcoap's memory management.
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
CoAP mutex mechanism wrapper.
#define coap_mutex_init(a)
#define coap_mutex_destroy(a)
#define FRAC_BITS
The number of bits for the fractional part of ACK_TIMEOUT and ACK_RANDOM_FACTOR.
static ssize_t coap_send_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
static int send_recv_terminate
static coap_crit_type_t coap_is_session_proxy(coap_session_t *session, coap_pdu_t *pdu)
static int coap_remove_from_queue_token(coap_queue_t **queue, coap_session_t *session, coap_bin_const_t *token, coap_queue_t **node)
static int check_token_size(coap_session_t *session, const coap_pdu_t *pdu, int is_local_mcast)
#define MAX_BITS
The maximum number of bits for fixed point integers that are used for retransmission time calculation...
#define ACK_TIMEOUT
creates a Qx.FRAC_BITS from session's 'ack_timeout'
static const char * coap_event_name(coap_event_t event)
static int coap_cancel(coap_context_t *context, const coap_queue_t *sent)
This function cancels outstanding messages for the session and token specified in sent.
static int coap_handle_dgram_for_proto(coap_context_t *ctx, coap_session_t *session, coap_packet_t *packet)
static void coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
COAP_STATIC_INLINE void coap_free_node(coap_queue_t *node)
#define SHR_FP(val, frac)
static void handle_signaling(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
static int prepend_508_ip(coap_session_t *session, coap_pdu_t *pdu)
static unsigned int s_csm_timeout
COAP_STATIC_INLINE coap_queue_t * coap_malloc_node(void)
uint8_t coap_unique_id[8]
#define ACK_RANDOM_FACTOR
creates a Qx.FRAC_BITS from session's 'ack_random_factor'
int coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED, const coap_dtls_pki_t *setup_data COAP_UNUSED, const coap_dtls_role_t role COAP_UNUSED)
int coap_dtls_receive(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
int coap_dtls_context_load_pki_trust_store(coap_context_t *ctx COAP_UNUSED)
int coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED, const char *ca_file COAP_UNUSED, const char *ca_path COAP_UNUSED)
void coap_dtls_free_context(void *handle COAP_UNUSED)
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
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_OPTION_IF_NONE_MATCH
@ COAP_OPTION_PROXY_SCHEME
@ COAP_OPTION_CONTENT_FORMAT
@ COAP_OPTION_URI_PATH_ABB
#define SESSIONS_ITER_SAFE(e, el, rtmp)
#define SESSIONS_ITER(e, el, rtmp)
void coap_io_do_epoll_lkd(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
void coap_reset_doing_first(coap_session_t *session)
Reset doing the first packet state when testing for optional functionality.
coap_mid_t coap_send_rst_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
coap_mid_t coap_send_message_type_lkd(coap_session_t *session, const coap_pdu_t *request, coap_pdu_type_t type)
Helper function to create and send a message with type (usually ACK or RST).
coap_mid_t coap_send_error_lkd(coap_session_t *session, const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
Sends an error response with code code for request request to dst.
void coap_io_do_io_lkd(coap_context_t *ctx, coap_tick_t now)
Processes any outstanding read, write, accept or connect I/O as indicated in the coap_socket_t struct...
int coap_send_recv_lkd(coap_session_t *session, coap_pdu_t *request_pdu, coap_pdu_t **response_pdu, uint32_t timeout_ms)
void coap_io_process_remove_threads_lkd(coap_context_t *context)
Release the coap_io_process() worker threads.
int coap_io_process_lkd(coap_context_t *ctx, uint32_t timeout_ms)
The main I/O processing function.
void coap_call_response_handler(coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd, void *body_free)
unsigned int coap_io_prepare_epoll_lkd(coap_context_t *ctx, coap_tick_t now)
Any now timed out delayed packet is transmitted, along with any packets associated with requested obs...
coap_mid_t coap_send_lkd(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
coap_mid_t coap_send_ack_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
COAP_API void coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
COAP_API void coap_io_do_io(coap_context_t *ctx, coap_tick_t now)
Processes any outstanding read, write, accept or connect I/O as indicated in the coap_socket_t struct...
void coap_check_code_lg_xmit(const coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_resource_t *resource, const coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response_l...
#define STATE_TOKEN_BASE(t)
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt.
#define COAP_BLOCK_TRY_Q_BLOCK
#define COAP_BLOCK_SINGLE_BODY
int coap_get_block_b(const coap_session_t *session, const coap_pdu_t *pdu, coap_option_num_t number, coap_block_b_t *block)
Initializes block from pdu.
#define COAP_BLOCK_NO_PREEMPTIVE_RTAG
#define COAP_BLOCK_USE_LIBCOAP
void coap_delete_cache_entry(coap_context_t *context, coap_cache_entry_t *cache_entry)
Remove a cache-entry from the hash list and free off all the appropriate contents apart from app_data...
int64_t coap_tick_diff_t
This data type is used to represent the difference between two clock_tick_t values.
void coap_clock_init(void)
Initializes the internal clock.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
#define COAP_MAX_DELAY_TICKS
uint64_t coap_ticks_to_rt_us(coap_tick_t t)
Helper function that converts coap ticks to POSIX wallclock time in us.
void coap_prng_init_lkd(unsigned int seed)
Seeds the default random number generation function with the given seed.
int coap_prng_lkd(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
#define COAP_RESOURCE_HANDLE_WELLKNOWN_CORE
Define this when invoking coap_resource_unknown_init2() if .well-known/core is to be passed to the un...
#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT
This resource has support for multicast requests.
#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_4_XX
Disable libcoap library suppressing 4.xx multicast responses (overridden by RFC7969 No-Response optio...
#define COAP_RESOURCE_SAFE_REQUEST_HANDLER
Don't lock this resource when calling app call-back handler for requests as handler will not be manip...
#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_DELAYS
Disable libcoap library from adding in delays to multicast requests before releasing the response bac...
void(* coap_method_handler_t)(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, const coap_string_t *query, coap_pdu_t *response)
Definition of message handler function.
#define COAP_RESOURCE_FLAGS_OSCORE_ONLY
Define this resource as an OSCORE enabled access only.
#define COAP_RESOURCE_FLAGS_LIB_DIS_MCAST_SUPPRESS_5_XX
Disable libcoap library suppressing 5.xx multicast responses (overridden by RFC7969 No-Response optio...
uint32_t coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
#define COAP_PRINT_STATUS_ERROR
#define COAP_RESOURCE_FLAGS_FORCE_SINGLE_BODY
Force all large traffic to this resource to be presented as a single body to the request handler.
#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_05
Enable libcoap library suppression of 205 multicast responses that are empty (overridden by RFC7969 N...
#define COAP_RESOURCE_FLAGS_LIB_ENA_MCAST_SUPPRESS_2_XX
Enable libcoap library suppressing 2.xx multicast responses (overridden by RFC7969 No-Response option...
int coap_handle_event_lkd(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now)
Set sendqueue_basetime in the given context object ctx to now.
int coap_delete_node_lkd(coap_queue_t *node)
Destroys specified node.
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
int coap_context_set_psk2_lkd(coap_context_t *context, coap_dtls_spsk_t *setup_data)
Set the context's default PSK hint and/or key for a server.
void coap_register_option_lkd(coap_context_t *ctx, coap_option_num_t type)
Registers the option number number with the given context object context.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
COAP_API int coap_delete_node(coap_queue_t *node)
Destroys specified node.
int coap_client_delay_first(coap_session_t *session)
Delay the sending of the first client request until some other negotiation has completed.
int coap_context_set_psk_lkd(coap_context_t *context, const char *hint, const uint8_t *key, size_t key_len)
Set the context's default PSK hint and/or key for a server.
int coap_option_check_critical(coap_session_t *session, coap_pdu_t *pdu, coap_opt_filter_t *unknown, coap_crit_type_t is_proxy)
Verifies that pdu contains no unknown critical options, duplicate options or the options defined as R...
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
void coap_dispatch(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
Dispatches the PDUs from the receive queue in given context.
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by variable t in node.
unsigned int coap_calc_timeout(coap_session_t *session, unsigned char r)
Calculates the initial timeout based on the session CoAP transmission parameters 'ack_timeout',...
void coap_free_context_lkd(coap_context_t *context)
CoAP stack context must be released with coap_free_context_lkd().
int coap_context_load_pki_trust_store_lkd(coap_context_t *ctx)
Load the context's default trusted CAs for a client or server.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *request_pdu)
Sends a CoAP message to given peer.
void * coap_context_set_app_data2_lkd(coap_context_t *context, void *app_data, coap_app_data_free_callback_t callback)
Stores data with the given context, returning the previously stored value or NULL.
int coap_can_exit_lkd(coap_context_t *context)
Returns 1 if there are no messages to send or to dispatch in the context's queues.
coap_mid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
int coap_check_code_class(coap_session_t *session, coap_pdu_t *pdu)
Check whether the pdu contains a valid code class.
int coap_context_set_pki_root_cas_lkd(coap_context_t *ctx, const char *ca_file, const char *ca_dir)
Set the context's default Root CA information for a client or server.
int coap_join_mcast_group_intf_lkd(coap_context_t *ctx, coap_endpoint_t *endpoint, const char *groupname, const char *ifname)
Function interface for joining a multicast group for listening for the currently defined endpoints th...
coap_mid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
void coap_cancel_session_messages(coap_context_t *context, coap_session_t *session, coap_nack_reason_t reason)
Cancels all outstanding messages for session session.
int coap_context_set_pki_lkd(coap_context_t *context, const coap_dtls_pki_t *setup_data)
Set the context's default PKI information for a server.
int coap_handle_dgram(coap_context_t *ctx, coap_session_t *session, uint8_t *msg, size_t msg_len)
Parses and interprets a CoAP datagram with context ctx.
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, coap_mid_t mid, coap_bin_const_t *token, coap_queue_t **node)
This function removes the element with given id from the list given list.
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, coap_bin_const_t *token)
Cancels all outstanding messages for session session that have the specified token.
void coap_context_set_session_timeout(coap_context_t *context, unsigned int session_timeout)
Set the session timeout value.
unsigned int coap_context_get_max_handshake_sessions(const coap_context_t *context)
Get the session timeout value.
COAP_API int coap_join_mcast_group_intf(coap_context_t *ctx, const char *groupname, const char *ifname)
Function interface for joining a multicast group for listening for the currently defined endpoints th...
void(* coap_pong_handler_t)(coap_session_t *session, const coap_pdu_t *received, const coap_mid_t mid)
Received Pong handler that is used as callback in coap_context_t.
unsigned int coap_context_get_max_idle_sessions(const coap_context_t *context)
Get the maximum idle sessions count.
COAP_API int coap_send_recv(coap_session_t *session, coap_pdu_t *request_pdu, coap_pdu_t **response_pdu, uint32_t timeout_ms)
coap_context_t * coap_new_context(const coap_address_t *listen_addr)
Creates a new coap_context_t object that will hold the CoAP stack status.
COAP_API coap_mid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
COAP_API int coap_context_set_pki(coap_context_t *context, const coap_dtls_pki_t *setup_data)
Set the context's default PKI information for a server.
void coap_mcast_per_resource(coap_context_t *context)
Function interface to enable processing mcast requests on a per resource basis.
coap_response_t(* coap_response_handler_t)(coap_session_t *session, const coap_pdu_t *sent, const coap_pdu_t *received, const coap_mid_t mid)
Response handler that is used as callback in coap_context_t.
void coap_context_set_max_body_size(coap_context_t *context, uint32_t max_body_size)
Set the maximum supported body size.
COAP_API coap_mid_t coap_send_error(coap_session_t *session, const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
Sends an error response with code code for request request to dst.
void coap_context_rate_limit_ppm(coap_context_t *context, uint64_t rate_limit_ppm)
Set the ratelimit for packets per minute.
void coap_context_set_csm_max_message_size(coap_context_t *context, uint32_t csm_max_message_size)
Set the CSM max session size value.
void coap_context_set_csm_timeout(coap_context_t *context, unsigned int csm_timeout)
Set the CSM timeout value.
void coap_send_recv_terminate(void)
Terminate any active coap_send_recv() sessions.
coap_resource_t *(* coap_resource_dynamic_create_t)(coap_session_t *session, const coap_pdu_t *request)
Definition of resource dynamic creation handler function.
void coap_register_response_handler(coap_context_t *context, coap_response_handler_t handler)
Registers a new message handler that is called whenever a response is received.
COAP_API void * coap_context_set_app_data2(coap_context_t *context, void *app_data, coap_app_data_free_callback_t callback)
Stores data with the given context, returning the previously stored value or NULL.
coap_pdu_t * coap_new_error_response(const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
Creates a new ACK PDU with specified error code.
void coap_context_set_max_handshake_sessions(coap_context_t *context, unsigned int max_handshake_sessions)
Set the maximum number of sessions in (D)TLS handshake value.
int coap_context_get_coap_fd(const coap_context_t *context)
Get the libcoap internal file descriptor for using in an application's select() or returned as an eve...
void coap_register_dynamic_resource_handler(coap_context_t *context, coap_resource_dynamic_create_t dyn_create_handler, uint32_t dynamic_max)
Sets up a handler for calling when an unknown resource is requested.
COAP_API void coap_set_app_data(coap_context_t *context, void *app_data)
int coap_mcast_set_hops(coap_session_t *session, size_t hops)
Function interface for defining the hop count (ttl) for sending multicast traffic.
void(* coap_ping_handler_t)(coap_session_t *session, const coap_pdu_t *received, const coap_mid_t mid)
Received Ping handler that is used as callback in coap_context_t.
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
COAP_API void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
void(* coap_nack_handler_t)(coap_session_t *session, const coap_pdu_t *sent, const coap_nack_reason_t reason, const coap_mid_t mid)
Negative Acknowedge handler that is used as callback in coap_context_t.
void coap_context_set_shutdown_no_observe(coap_context_t *context)
void * coap_context_get_app_data(const coap_context_t *context)
Returns any application-specific data that has been stored with context using the function coap_conte...
COAP_API int coap_context_set_pki_root_cas(coap_context_t *ctx, const char *ca_file, const char *ca_dir)
Set the context's default Root CA information for a client or server.
COAP_API void coap_context_set_app_data(coap_context_t *context, void *app_data)
Stores data with the given context.
uint32_t coap_context_get_csm_max_message_size(const coap_context_t *context)
Get the CSM max session size value.
unsigned int coap_context_get_session_timeout(const coap_context_t *context)
Get the session timeout value.
COAP_API int coap_endpoint_join_mcast_group_intf(coap_endpoint_t *endpoint, const char *groupname, const char *ifname)
Function interface for joining a multicast group for listening on a single UDP endpoint.
COAP_API int coap_context_set_psk(coap_context_t *context, const char *hint, const uint8_t *key, size_t key_len)
Set the context's default PSK hint and/or key for a server.
COAP_API coap_mid_t coap_send_ack(coap_session_t *session, const coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
unsigned int coap_context_get_csm_timeout_ms(const coap_context_t *context)
Get the CSM timeout value.
void coap_register_ping_handler(coap_context_t *context, coap_ping_handler_t handler)
Registers a new message handler that is called whenever a CoAP Ping message is received.
COAP_API int coap_context_set_psk2(coap_context_t *context, coap_dtls_spsk_t *setup_data)
Set the context's default PSK hint and/or key for a server.
void * coap_get_app_data(const coap_context_t *ctx)
int coap_context_set_cid_tuple_change(coap_context_t *context, uint8_t every)
Set the Connection ID client tuple frequency change for testing CIDs.
void coap_context_set_max_idle_sessions(coap_context_t *context, unsigned int max_idle_sessions)
Set the maximum idle sessions count.
COAP_API coap_mid_t coap_send_message_type(coap_session_t *session, const coap_pdu_t *request, coap_pdu_type_t type)
Helper function to create and send a message with type (usually ACK or RST).
COAP_API coap_mid_t coap_send_rst(coap_session_t *session, const coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
void coap_context_set_session_reconnect_time2(coap_context_t *context, unsigned int reconnect_time, uint8_t retry_count)
Set the session reconnect delay time after a working client session has failed.
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds)
Set the context keepalive timer for sessions.
COAP_API int coap_can_exit(coap_context_t *context)
Returns 1 if there are no messages to send or to dispatch in the context's queues.
COAP_API void coap_register_option(coap_context_t *ctx, coap_option_num_t type)
Registers the option number number with the given context object context.
unsigned int coap_context_get_csm_timeout(const coap_context_t *context)
Get the CSM timeout value.
COAP_API int coap_context_load_pki_trust_store(coap_context_t *ctx)
Load the hosts's default trusted CAs for a client or server.
void coap_context_set_session_reconnect_time(coap_context_t *context, unsigned int reconnect_time)
Set the session reconnect delay time after a working client session has failed.
void coap_register_pong_handler(coap_context_t *context, coap_pong_handler_t handler)
Registers a new message handler that is called whenever a CoAP Pong message is received.
void coap_context_set_max_token_size(coap_context_t *context, size_t max_token_size)
Set the maximum token size (RFC8974).
COAP_API int coap_handle_event(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
void coap_register_nack_handler(coap_context_t *context, coap_nack_handler_t handler)
Registers a new message handler that is called whenever a confirmable message (request or response) i...
void coap_context_set_csm_timeout_ms(coap_context_t *context, unsigned int csm_timeout_ms)
Set the CSM timeout value.
@ COAP_RESPONSE_FAIL
Response not liked - send CoAP RST packet.
@ COAP_RESPONSE_OK
Response is fine.
const coap_bin_const_t * coap_get_session_client_psk_identity(const coap_session_t *coap_session)
Get the current client's PSK identity.
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
coap_session_t * coap_session_new_dtls_session(coap_session_t *session, coap_tick_t now)
Create a new DTLS session for the session.
int coap_dtls_set_cid_tuple_change(coap_context_t *context, uint8_t every)
Set the Connection ID client tuple frequency change for testing CIDs.
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
const coap_bin_const_t * coap_get_session_client_psk_key(const coap_session_t *coap_session)
Get the current client's PSK key.
const coap_bin_const_t * coap_get_session_server_psk_key(const coap_session_t *coap_session)
Get the current server's PSK key.
const coap_bin_const_t * coap_get_session_server_psk_hint(const coap_session_t *coap_session)
Get the current server's PSK identity hint.
#define COAP_DTLS_PKI_SETUP_VERSION
Latest PKI setup version.
@ COAP_DTLS_ROLE_SERVER
Internal function invoked for server.
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
unsigned int coap_encode_var_safe8(uint8_t *buf, size_t length, uint64_t val)
Encodes multiple-length byte sequences.
coap_event_t
Scalar type to represent different events, e.g.
@ COAP_EVENT_OSCORE_DECODE_ERROR
Triggered when there is an OSCORE decode of OSCORE option failure.
@ COAP_EVENT_SESSION_CONNECTED
Triggered when TCP layer completes exchange of CSM information.
@ COAP_EVENT_RECONNECT_FAILED
Triggered when a session failed, and a reconnect is going to be attempted.
@ COAP_EVENT_OSCORE_INTERNAL_ERROR
Triggered when there is an OSCORE internal error i.e malloc failed.
@ COAP_EVENT_DTLS_CLOSED
Triggerred when (D)TLS session closed.
@ COAP_EVENT_TCP_FAILED
Triggered when TCP layer fails for some reason.
@ COAP_EVENT_WS_CONNECTED
Triggered when the WebSockets layer is up.
@ COAP_EVENT_DTLS_CONNECTED
Triggered when (D)TLS session connected.
@ COAP_EVENT_BLOCK_ISSUE
Triggered when a block transfer could not be handled.
@ COAP_EVENT_SESSION_FAILED
Triggered when TCP layer fails following exchange of CSM information.
@ COAP_EVENT_PARTIAL_BLOCK
Triggered when not all of a large body has been received.
@ COAP_EVENT_XMIT_BLOCK_FAIL
Triggered when not all of a large body has been transmitted.
@ COAP_EVENT_SERVER_SESSION_NEW
Called in the CoAP IO loop if a new server-side session is created due to an incoming connection.
@ COAP_EVENT_OSCORE_NOT_ENABLED
Triggered when trying to use OSCORE to decrypt, but it is not enabled.
@ COAP_EVENT_RECONNECT_STARTED
Triggered when a session starts to reconnect.
@ COAP_EVENT_WS_CLOSED
Triggered when the WebSockets layer is closed.
@ COAP_EVENT_RECONNECT_NO_MORE
Triggered when a session failed, and retry reconnect attempts failed.
@ COAP_EVENT_SESSION_CLOSED
Triggered when TCP layer closes following exchange of CSM information.
@ COAP_EVENT_FIRST_PDU_FAIL
Triggered when the initial app PDU cannot be transmitted.
@ COAP_EVENT_SERVER_SESSION_DEL
Called in the CoAP IO loop if a server session is deleted (e.g., due to inactivity or because the max...
@ COAP_EVENT_OSCORE_NO_SECURITY
Triggered when there is no OSCORE security definition found.
@ COAP_EVENT_DTLS_RENEGOTIATE
Triggered when (D)TLS session renegotiated.
@ COAP_EVENT_BAD_PACKET
Triggered when badly formatted packet received.
@ COAP_EVENT_SERVER_SESSION_CONNECTED
Called in the CoAP IO loop once a server session is active and (D)TLS (if any) is established.
@ COAP_EVENT_MSG_RETRANSMITTED
Triggered when a message is retransmitted.
@ COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD
Triggered when there is no OSCORE encrypted payload provided.
@ COAP_EVENT_RECONNECT_SUCCESS
Triggered when a session failed, and a reconnect is successful.
@ COAP_EVENT_TCP_CLOSED
Triggered when TCP layer is closed.
@ COAP_EVENT_WS_PACKET_SIZE
Triggered when there is an oversize WebSockets packet.
@ COAP_EVENT_TCP_CONNECTED
Triggered when TCP layer connects.
@ COAP_EVENT_OSCORE_DECRYPTION_FAILURE
Triggered when there is an OSCORE decryption failure.
@ COAP_EVENT_KEEPALIVE_FAILURE
Triggered when no response to a keep alive (ping) packet.
@ COAP_EVENT_DTLS_ERROR
Triggered when (D)TLS error occurs.
#define coap_lock_specific_callback_release(lock, func, failed)
Dummy for no thread-safe code.
#define coap_lock_callback(func)
Dummy for no thread-safe code.
#define coap_lock_init(lock)
Dummy for no thread-safe code.
#define coap_lock_callback_ret(r, func)
Dummy for no thread-safe code.
#define coap_lock_callback_ret_release(r, func, failed)
Dummy for no thread-safe code.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_callback_release(func, failed)
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
#define coap_log_alert(...)
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
#define coap_log_emerg(...)
size_t coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
const char * coap_endpoint_str(const coap_endpoint_t *endpoint)
Get endpoint description.
const char * coap_session_str(const coap_session_t *session)
Get session description.
#define coap_log_info(...)
#define coap_log_warn(...)
#define coap_log_err(...)
int coap_netif_strm_connect2(coap_session_t *session)
Layer function interface for Netif stream connect (tcp).
ssize_t coap_netif_dgrm_read(coap_session_t *session, coap_packet_t *packet)
Function interface for layer data datagram receiving for sessions.
ssize_t coap_netif_dgrm_read_ep(coap_endpoint_t *endpoint, coap_packet_t *packet)
Function interface for layer data datagram receiving for endpoints.
int coap_netif_available(coap_session_t *session)
Function interface to check whether netif for session is still available.
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET/FETCH request option COAP_OPTION_OBSERVE indicates that the ob...
#define COAP_OBSERVE_ESTABLISH
The value COAP_OBSERVE_ESTABLISH in a GET/FETCH request option COAP_OPTION_OBSERVE indicates a new ob...
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_FILTER_SHORT
The number of option types below 256 that can be stored in an option filter.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
#define COAP_OPT_FILTER_LONG
The number of option types above 255 that can be stored in an option filter.
void coap_option_filter_clear(coap_opt_filter_t *filter)
Clears filter filter.
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
int coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option)
Checks if number is contained in filter.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option)
Sets the corresponding entry for number in filter.
coap_pdu_t * coap_oscore_new_pdu_encrypted_lkd(coap_session_t *session, coap_pdu_t *pdu, coap_bin_const_t *kid_context, oscore_partial_iv_t send_partial_iv)
Encrypts the specified pdu when OSCORE encryption is required on session.
struct coap_pdu_t * coap_oscore_decrypt_pdu(coap_session_t *session, coap_pdu_t *pdu)
Decrypts the OSCORE-encrypted parts of pdu when OSCORE is used.
int coap_rebuild_pdu_for_proxy(coap_pdu_t *pdu)
Convert PDU to use Proxy-Scheme option if Proxy-Uri option is present.
void coap_delete_all_oscore(coap_context_t *context)
Cleanup all allocated OSCORE information.
#define COAP_PDU_IS_RESPONSE(pdu)
coap_pdu_t * coap_pdu_reference_lkd(coap_pdu_t *pdu)
Increment reference counter on a pdu to stop it prematurely getting freed off when coap_delete_pdu() ...
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
#define COAP_TOKEN_EXT_2B_TKL
size_t coap_insert_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Inserts option of given number in the pdu with the appropriate data.
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
int coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts)
Verify consistency in the given CoAP PDU structure and locate the data.
#define COAP_DROPPED_RESPONSE
Indicates that a response is suppressed.
int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto)
Decode the protocol specific header for the specified PDU.
size_t coap_pdu_parse_header_size(coap_proto_t proto, const uint8_t *data)
Interprets data to determine the number of bytes in the header.
#define COAP_PDU_IS_EMPTY(pdu)
#define COAP_DEFAULT_MAX_PDU_RX_SIZE
#define COAP_PDU_IS_SIGNALING(pdu)
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options, coap_bool_t expand_opt_abb)
Duplicate an existing PDU.
int coap_option_check_repeatable(coap_pdu_t *pdu, coap_option_num_t number)
Check whether the option is allowed to be repeated or not.
size_t coap_update_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Updates existing first option of given number in the pdu with the new data.
#define COAP_TOKEN_EXT_1B_TKL
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
#define COAP_DEFAULT_VERSION
int coap_pdu_parse2(coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu, coap_opt_filter_t *error_opts)
Parses data into the CoAP PDU structure given in result.
size_t coap_pdu_parse_size(coap_proto_t proto, const uint8_t *data, size_t length)
Parses data to extract the message size.
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size)
Dynamically grows the size of pdu to new_size.
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
#define COAP_PDU_IS_REQUEST(pdu)
size_t coap_add_option_internal(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
#define COAP_TOKEN_DEFAULT_MAX
#define COAP_TOKEN_EXT_MAX
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
coap_pdu_code_t
Set of codes available for a PDU.
coap_pdu_type_t
CoAP PDU message type definitions.
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
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.
int coap_pdu_parse(coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu)
Parses data into the CoAP PDU structure given in result.
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
#define COAP_INVALID_MID
Indicates an invalid message id.
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
@ COAP_SIGNALING_CODE_ABORT
@ COAP_SIGNALING_CODE_CSM
@ COAP_SIGNALING_CODE_PING
@ COAP_REQUEST_CODE_DELETE
@ COAP_SIGNALING_CODE_PONG
@ COAP_SIGNALING_CODE_RELEASE
@ COAP_REQUEST_CODE_FETCH
void coap_register_proxy_response_handler(coap_context_t *context, coap_proxy_response_handler_t handler)
Registers a new message handler that is called whenever a response is received by the proxy logic.
coap_pdu_t *(* coap_proxy_response_handler_t)(coap_session_t *session, const coap_pdu_t *sent, coap_pdu_t *received, coap_cache_key_t *cache_key)
Proxy response handler that is used as callback held in coap_context_t.
#define COAP_NON_RECEIVE_TIMEOUT_TICKS(s)
The NON_RECEIVE_TIMEOUT definition for the session (s).
void coap_connect_session(coap_session_t *session, coap_tick_t now)
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
#define COAP_DEFAULT_LEISURE_TICKS(s)
The DEFAULT_LEISURE definition for the session (s).
void coap_handle_nack(coap_session_t *session, coap_pdu_t *sent, const coap_nack_reason_t reason, const coap_mid_t mid)
size_t coap_session_max_pdu_rcv_size(const coap_session_t *session)
Get maximum acceptable receive PDU size.
void coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
int coap_session_reconnect(coap_session_t *session)
Close the current session (if not already closed) and reconnect to server (client session only).
void coap_session_server_keepalive_failed(coap_session_t *session)
Clear down a session following a keepalive failure.
#define COAP_MAX_PAYLOADS(s)
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
coap_session_t * coap_session_reference_lkd(coap_session_t *session)
Increment reference counter on a session.
void coap_session_disconnected_lkd(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
@ COAP_EXT_T_NOT_CHECKED
Not checked.
@ COAP_EXT_T_CHECKING
Token size check request sent.
@ COAP_EXT_T_CHECKED
Token size valid.
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
coap_session_state_t
coap_session_state_t values
#define COAP_PROTO_NOT_RELIABLE(p)
#define COAP_PROTO_RELIABLE(p)
void(* coap_app_data_free_callback_t)(void *data)
Callback to free off the app data when the entry is being deleted / freed off.
@ COAP_SESSION_TYPE_HELLO
server-side ephemeral session for responding to a client hello
@ COAP_SESSION_TYPE_SERVER
server-side
@ COAP_SESSION_TYPE_CLIENT
client-side
@ COAP_SESSION_STATE_ESTABLISHED
@ COAP_SESSION_STATE_NONE
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
int coap_epoll_is_supported(void)
Determine whether epoll is supported or not.
int coap_tls_is_supported(void)
Check whether TLS is available.
int coap_af_unix_is_supported(void)
Check whether socket type AF_UNIX is available.
int coap_ipv6_is_supported(void)
Check whether IPv6 is available.
int coap_threadsafe_is_supported(void)
Determine whether libcoap is threadsafe or not.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
int coap_server_is_supported(void)
Check whether Server code is available.
int coap_client_is_supported(void)
Check whether Client code is available.
int coap_ipv4_is_supported(void)
Check whether IPv4 is available.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
void coap_delete_upa_chain(coap_upa_chain_t *chain)
Clean up a UPA chain.
coap_upa_chain_t * coap_upa_server_mapping_chain
coap_upa_chain_t * coap_upa_client_fallback_chain
#define COAP_STATIC_INLINE
coap_address_t remote
remote address and port
coap_address_t local
local address and port
Multi-purpose address abstraction.
union coap_address_t::@250171263277076317333044054015357360100234370325 addr
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
CoAP binary data definition.
size_t length
length of binary data
Structure of Block options with BERT support.
unsigned int num
block number
unsigned int bert
Operating as BERT.
unsigned int aszx
block size (0-7 including BERT
unsigned int defined
Set if block found.
unsigned int m
1 if more blocks follow, 0 otherwise
unsigned int szx
block size (0-6)
The CoAP stack's global state is stored in a coap_context_t object.
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
uint64_t rl_ticks_per_packet
If not 0, rate limit NON to ticks per packet.
coap_app_data_free_callback_t app_cb
call-back to release app_data
coap_pong_handler_t pong_cb
Called when a ping response is received.
coap_nack_handler_t nack_cb
Called when a response issue has occurred.
coap_resource_dynamic_create_t dyn_create_handler
Dynamc resource create handler.
uint32_t max_body_size
Max supported body size or 0 is unlimited.
void * app_data
application-specific data
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
uint32_t dynamic_max
Max number of dynamic resources or 0 is unlimited.
coap_event_handler_t event_cb
Callback function that is used to signal events to the application.
coap_opt_filter_t known_options
uint32_t csm_max_message_size
Value for CSM Max-Message-Size.
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
coap_ping_handler_t ping_cb
Called when a CoAP ping is received.
uint32_t max_token_size
Largest token size supported RFC8974.
uint32_t csm_timeout_ms
Timeout for waiting for a CSM from the remote side.
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.
uint32_t block_mode
Zero or more COAP_BLOCK_ or'd options.
unsigned int max_idle_sessions
Maximum number of simultaneous unused sessions per endpoint.
coap_bin_const_t identity
coap_dtls_cpsk_info_t psk_info
Client PSK definition.
The structure used for defining the PKI setup data to be used.
The structure used for defining the Server PSK setup data to be used.
coap_dtls_spsk_info_t psk_info
Server PSK definition.
uint64_t state_token
state token
uint32_t count
the number of packets sent for payload
coap_binary_t * app_token
original PDU token
coap_layer_write_t l_write
coap_layer_establish_t l_establish
Structure to hold large body (many blocks) transmission information.
coap_tick_t last_all_sent
Last time all data sent or 0.
uint8_t blk_size
large block transmission size
union coap_lg_xmit_t::@222250243137322076370063262364242303040003336106 b
int last_block
last acknowledged block number Block1 last transmitted Q-Block2
coap_pdu_t * sent_pdu
The sent pdu with all the data.
uint16_t option
large block transmisson CoAP option
uint8_t short_opts[COAP_OPT_FILTER_SHORT]
uint16_t long_opts[COAP_OPT_FILTER_LONG]
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
size_t length
length of payload
coap_addr_tuple_t addr_info
local and remote addresses
unsigned char * payload
payload
uint8_t * token
first byte of token (or extended length bytes prefix), if any, or options
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
uint8_t hdr_size
actual size used for protocol-specific header (0 until header is encoded)
coap_bin_const_t actual_token
Actual token in pdu.
uint8_t * data
first byte of payload, if any
coap_mid_t mid
message id, if any, in regular host byte order
uint32_t e_token_length
length of Token space (includes leading extended bytes
size_t used_size
used bytes of storage for token, options and payload
uint8_t crit_opt
Set if unknown critical option for proxy.
coap_binary_t * data_free
Data to be freed off by coap_delete_pdu().
size_t alloc_size
allocated storage for token, options and payload
coap_session_t * session
Session responsible for PDU or NULL.
coap_pdu_type_t type
message type
coap_address_t remote
For re-transmission - where the node is going.
coap_session_t * session
the CoAP session
coap_pdu_t * pdu
the CoAP PDU to send
unsigned int timeout
the randomized timeout value
uint8_t is_mcast
Set if this is a queued mcast response.
struct coap_queue_t * next
coap_mid_t id
CoAP message id.
coap_tick_t t
when to send PDU for the next time
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_lg_xmit_t * lg_xmit
list of large transmissions
volatile uint8_t max_token_checked
Check for max token size coap_ext_token_check_t.
uint8_t csm_not_seen
Set if timeout waiting for CSM.
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
uint32_t block_mode
Zero or more COAP_BLOCK_ or'd options.
uint8_t delay_recursive
Set if in coap_client_delay_first().
coap_socket_t sock
socket object for the session, if any
coap_pdu_t * partial_pdu
incomplete incoming pdu
uint32_t max_token_size
Largest token size supported RFC8974.
uint32_t ping_failed
Ping failure count.
coap_bin_const_t * psk_identity
If client, this field contains the current identity for server; When this field is NULL,...
coap_session_state_t state
current state of relationship with peer
uint8_t csm_bert_rem_support
CSM TCP BERT blocks supported (remote).
coap_mid_t last_resp_mid
The last response mid that has been been processed.
uint8_t is_rate_limiting
Currently NON rate limiting.
coap_mid_t remote_test_mid
mid used for checking remote support
uint8_t read_header[8]
storage space for header of incoming message header
coap_addr_tuple_t addr_info
remote/local address info
coap_proto_t proto
protocol used
unsigned ref
reference count from queues
coap_response_t last_con_handler_res
The result of calling the response handler of the last CON.
coap_tick_t last_tx
Last time a ratelimited packet is sent.
coap_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
coap_bin_const_t * last_token
uint8_t no_path_abbrev
Set is remote does not support Uri-Path-Abbrev.
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
size_t mtu
path or CSM mtu (xmt)
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
void * tls
security parameters
uint16_t max_retransmit
maximum re-transmit count (default 4)
uint8_t csm_block_supported
CSM TCP blocks supported.
uint8_t proxy_session
Set if this is an ongoing proxy session.
uint8_t con_active
Active CON request sent.
coap_queue_t * delayqueue
list of delayed messages waiting to be sent
uint32_t tx_rtag
Next Request-Tag number to use.
coap_mid_t last_ping_mid
the last keepalive message id that was used in this session
uint64_t rl_ticks_per_packet
If not 0, rate limit NON to ticks per packet.
coap_session_type_t type
client or server side socket
coap_context_t * context
session's context
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
coap_bin_const_t * echo
last token used to make a request
coap_layer_func_t lfunc[COAP_LAYER_LAST]
Layer functions to use.
coap_session_t * session
Used to determine session owner.
coap_socket_flags_t flags
1 or more of COAP_SOCKET* flag values
CoAP string data definition with const data.
const uint8_t * s
read-only string data
size_t length
length of string
CoAP string data definition.
size_t length
length of string
Representation of parsed URI.
coap_str_const_t host
The host part of the URI.