26#ifdef HAVE_SYS_UNISTD_H
27#include <sys/unistd.h>
30#ifdef HAVE_SYS_TYPES_H
33#ifdef HAVE_SYS_SOCKET_H
34#include <sys/socket.h>
36#ifdef HAVE_SYS_IOCTL_H
39#ifdef HAVE_NETINET_IN_H
40#include <netinet/in.h>
42#ifdef HAVE_ARPA_INET_H
48#ifdef COAP_EPOLL_SUPPORT
50#include <sys/timerfd.h>
63#include <lwip/timeouts.h>
64#include <lwip/tcpip.h>
67#ifndef INET6_ADDRSTRLEN
68#define INET6_ADDRSTRLEN 40
72#define min(a,b) ((a) < (b) ? (a) : (b))
88#error FRAC_BITS must be less or equal 8
92#define Q(frac,fval) ((uint16_t)(((1 << (frac)) * fval.integer_part) + \
93 ((1 << (frac)) * fval.fractional_part + 500)/1000))
96#define ACK_RANDOM_FACTOR \
97 Q(FRAC_BITS, session->ack_random_factor)
100#define ACK_TIMEOUT Q(FRAC_BITS, session->ack_timeout)
115#include <lwip/memp.h>
124 memp_free(MEMP_COAP_NODE, node);
130 unsigned int result = 0;
179 if (node->
t < q->
t) {
191 }
while (q && q->
t <= node->
t);
241 memset(node, 0,
sizeof(*node));
269#if COAP_CLIENT_SUPPORT
297#if COAP_SERVER_SUPPORT
331 memset(&setup_data, 0,
sizeof(setup_data));
337 if (key && key_len > 0) {
364 coap_log_err(
"coap_context_set_pki: Wrong version of setup_data\n");
377 const char *ca_dir) {
391 size_t max_token_size) {
399 unsigned int max_idle_sessions) {
410 unsigned int max_handshake_sessions) {
421 unsigned int csm_timeout) {
432 uint32_t csm_max_message_size) {
433 assert(csm_max_message_size >= 64);
444 unsigned int session_timeout) {
455#ifdef COAP_EPOLL_SUPPORT
456 return context->epfd;
467#if ! COAP_SERVER_SUPPORT
473 coap_log_warn(
"coap_startup() should be called before any other "
474 "coap_*() functions are called\n");
484#ifdef COAP_EPOLL_SUPPORT
485 c->epfd = epoll_create1(0);
487 coap_log_err(
"coap_new_context: Unable to epoll_create: %s (%d)\n",
493 c->eptimerfd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK);
494 if (c->eptimerfd == -1) {
495 coap_log_err(
"coap_new_context: Unable to timerfd_create: %s (%d)\n",
501 struct epoll_event event;
504 memset(&event, 0,
sizeof(event));
505 event.events = EPOLLIN;
507 event.data.ptr = NULL;
509 ret = epoll_ctl(c->epfd, EPOLL_CTL_ADD, c->eptimerfd, &event);
533#if COAP_SERVER_SUPPORT
536 if (endpoint == NULL) {
546#if defined(COAP_EPOLL_SUPPORT) || COAP_SERVER_SUPPORT
570#if COAP_SERVER_SUPPORT
579 if (context->timer_configured) {
581 sys_untimeout(coap_io_process_timeout, (
void *)context);
583 context->timer_configured = 0;
587#if COAP_ASYNC_SUPPORT
588 coap_delete_all_async(context);
591#if COAP_OSCORE_SUPPORT
595#if COAP_SERVER_SUPPORT
598 HASH_ITER(hh, context->
cache, cp, ctmp) {
607 LL_FOREACH_SAFE(context->
endpoint, ep, tmp) {
612#if COAP_CLIENT_SUPPORT
622#ifdef COAP_EPOLL_SUPPORT
623 if (context->eptimerfd != -1) {
625 struct epoll_event event;
628 ret = epoll_ctl(context->epfd, EPOLL_CTL_DEL, context->eptimerfd, &event);
634 close(context->eptimerfd);
635 context->eptimerfd = -1;
637 if (context->epfd != -1) {
638 close(context->epfd);
642#if COAP_SERVER_SUPPORT
643#if COAP_WITH_OBSERVE_PERSIST
666 if (opt_iter.
number & 0x01) {
668 switch (opt_iter.
number) {
669#if COAP_Q_BLOCK_SUPPORT
694#if COAP_OSCORE_SUPPORT
701#if COAP_SERVER_SUPPORT
702 if ((opt_iter.
number & 0x02) == 0) {
728 if (last_number == opt_iter.
number) {
744 unsigned char buf[4];
746 coap_log_debug(
"Option Block2 has invalid set M bit - cleared\n");
763 last_number = opt_iter.
number;
785 ssize_t bytes_written = -1;
793 return bytes_written;
798 ssize_t bytes_written;
801#if ! COAP_CLIENT_SUPPORT
813 coap_log_err(
"Multicast requests cannot be Confirmable (RFC7252 8.1)\n");
832 return bytes_written;
885#define FP1 Q(FRAC_BITS, ((coap_fixed_point_t){1,0}))
888#define SHR_FP(val,frac) (((val) + (1 << ((frac) - 1))) >> (frac))
933 coap_log_debug(
"** %s: mid=0x%04x: added to retransmit queue (%ums)\n",
938#ifdef COAP_EPOLL_SUPPORT
945#if COAP_CLIENT_SUPPORT
970 token->
s[i] = (uint8_t)(i + 1);
987#if COAP_CLIENT_SUPPORT
989 int timeout_ms = 5000;
1011 if (result <= timeout_ms) {
1012 timeout_ms -= result;
1034#if COAP_CLIENT_SUPPORT
1038 int observe_action = -1;
1039 int have_block1 = 0;
1046#if COAP_CLIENT_SUPPORT
1104#if COAP_OSCORE_SUPPORT
1105 if (session->oscore_encryption) {
1106 if (session->recipient_ctx->initial_state == 1) {
1137 (block.
m == 1 || block.
bert == 1)) {
1140#if COAP_Q_BLOCK_SUPPORT
1142 (block.
m == 1 || block.
bert == 1)) {
1144 coap_log_warn(
"Block1 and Q-Block1 cannot be in the same request\n");
1154 coap_log_debug(
"Token reused - see https://rfc-editor.org/rfc/rfc9175.html#section-4.2\n");
1169 memset(&block, 0,
sizeof(block));
1172#if COAP_Q_BLOCK_SUPPORT
1191#if COAP_Q_BLOCK_SUPPORT
1192 if (!(session->
block_mode & COAP_BLOCK_HAS_Q_BLOCK))
1202 (block.
num << 4) | (0 << 3) | block.
szx),
1208 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1216 (block.
num << 4) | (0 << 3) | block.
szx),
1226 (block.
num << 4) | (block.
m << 3) | block.
szx),
1232 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1252#if COAP_Q_BLOCK_SUPPORT
1255 if (block.
num == 0 && block.
m == 0) {
1261 (0 << 4) | (1 << 3) | block.
szx),
1274 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1292 if (observe_action != -1 || have_block1 ||
1293#
if COAP_OSCORE_SUPPORT
1294 session->oscore_encryption ||
1300 if (!session->
lg_xmit && have_block1) {
1305 LL_FOREACH(session->
lg_crcv, lg_crcv) {
1324 LL_DELETE(session->
lg_crcv, lg_crcv);
1329 LL_DELETE(session->
lg_crcv, lg_crcv);
1335 if (have_block1 && session->
lg_xmit) {
1336 LL_FOREACH(session->
lg_xmit, lg_xmit) {
1345 if (lg_crcv == NULL) {
1358#if COAP_Q_BLOCK_SUPPORT
1361 mid = coap_send_q_block1(session, block, pdu, COAP_SEND_INC_PDU);
1368#if COAP_CLIENT_SUPPORT
1371 LL_PREPEND(session->
lg_crcv, lg_crcv);
1383 ssize_t bytes_written;
1396 addr_str[
sizeof(addr_str)-1] =
'\000';
1398 sizeof(addr_str) - 1)) {
1402 if (addr_str[0] ==
'[') {
1403 cp = strchr(addr_str,
']');
1406 if (memcmp(&addr_str[1],
"::ffff:", 7) == 0) {
1413 cp = strchr(addr_str,
':');
1427 if (hop_limit == 1) {
1432 }
else if (hop_limit < 1 || hop_limit > 255) {
1434 coap_log_warn(
"Proxy return has bad hop limit count '%zu'\n",
1446 if (pdu->
data && opt == NULL) {
1459 pdu->
data[data_len] =
'\000';
1460 a_match = strstr((
char *)pdu->
data, cp);
1461 if (a_match && (a_match == (
char *)pdu->
data || a_match[-1] ==
' ') &&
1462 ((
size_t)(a_match - (
char *)pdu->
data + len) == data_len ||
1463 a_match[len] ==
' ')) {
1473 if (pdu->
data == NULL) {
1481 (uint8_t *)&hop_limit);
1485 memmove(pdu->
data + len + 1, pdu->
data,
1487 memcpy(pdu->
data, cp, len);
1488 pdu->
data[len] =
' ';
1496 if (session->
echo) {
1501 session->
echo = NULL;
1503#if COAP_OSCORE_SUPPORT
1504 if (session->oscore_encryption) {
1515#if !COAP_DISABLE_TCP
1526 coap_log_debug(
"Remote end did not indicate CSM support for Block1 enabled\n");
1529 coap_log_debug(
"Remote end did not indicate CSM support for Block2 enabled\n");
1536 coap_log_debug(
"Remote end did not indicate CSM support for BERT Block1\n");
1540 coap_log_debug(
"Remote end did not indicate CSM support for BERT Block2\n");
1546#if COAP_OSCORE_SUPPORT
1547 if (session->oscore_encryption &&
1553 if (osc_pdu == NULL) {
1568 if (bytes_written < 0) {
1572#if !COAP_DISABLE_TCP
1574 (
size_t)bytes_written < pdu->used_size + pdu->
hdr_size) {
1598 node->
id = pdu->
mid;
1611 if (!context || !node)
1616 ssize_t bytes_written;
1635 node->
t = next_delay;
1644 coap_log_debug(
"** %s: mid=0x%04x: mcast delayed transmission\n",
1647 coap_log_debug(
"** %s: mid=0x%04x: retransmission #%d (next %ums)\n",
1668 if (bytes_written < 0)
1669 return (
int)bytes_written;
1675 coap_log_warn(
"** %s: mid=0x%04x: give up after %d attempts\n",
1678#if COAP_SERVER_SUPPORT
1717#if COAP_SERVER_SUPPORT
1730#if COAP_CLIENT_SUPPORT
1756 ssize_t bytes_written;
1764 if (bytes_written > 0)
1766 if (bytes_written <= 0 ||
1768 if (bytes_written > 0)
1780#if COAP_CONSTRAINED_STACK
1790#if COAP_CONSTRAINED_STACK
1791 coap_mutex_lock(&m_read_session);
1796 packet->
length =
sizeof(payload);
1804 if (bytes_read < 0) {
1805 if (bytes_read == -2)
1808 }
else if (bytes_read > 0) {
1814#if !COAP_DISABLE_TCP
1817 ssize_t bytes_read = 0;
1823 if (bytes_read < 0) {
1825 }
else if (bytes_read > 2) {
1832#if COAP_CONSTRAINED_STACK
1833 coap_mutex_unlock(&m_read_session);
1842#if COAP_CONSTRAINED_STACK
1843 coap_mutex_unlock(&m_read_session);
1848#if COAP_CONSTRAINED_STACK
1849 coap_mutex_unlock(&m_read_session);
1856 ssize_t bytes_read = 0;
1864 if (bytes_read > 0) {
1868 retry = bytes_read == (ssize_t)packet->
length;
1869 while (bytes_read > 0) {
1874 size_t n =
min(len, (
size_t)bytes_read);
1882#if COAP_CONSTRAINED_STACK
1883 coap_mutex_unlock(&m_read_session);
1886#if COAP_CONSTRAINED_STACK
1887 coap_mutex_lock(&m_read_session);
1902 size_t len = hdr_size + tok_ext_bytes - session->
partial_read;
1903 size_t n =
min(len, (
size_t)bytes_read);
1909 hdr_size + tok_ext_bytes);
1910 if (size > COAP_DEFAULT_MAX_PDU_RX_SIZE) {
1911 coap_log_warn(
"** %s: incoming PDU length too large (%zu > %lu)\n",
1913 size, COAP_DEFAULT_MAX_PDU_RX_SIZE);
1934#if COAP_CONSTRAINED_STACK
1935 coap_mutex_unlock(&m_read_session);
1938#if COAP_CONSTRAINED_STACK
1939 coap_mutex_lock(&m_read_session);
1960 }
while (bytes_read == 0 && retry);
1965#if COAP_CONSTRAINED_STACK
1966 coap_mutex_unlock(&m_read_session);
1970#if COAP_SERVER_SUPPORT
1973 ssize_t bytes_read = -1;
1975#if COAP_CONSTRAINED_STACK
1988#if COAP_CONSTRAINED_STACK
1989 coap_mutex_lock(&m_read_endpoint);
1994 packet->
length =
sizeof(payload);
2000 if (bytes_read < 0) {
2002 }
else if (bytes_read > 0) {
2012#if COAP_CONSTRAINED_STACK
2013 coap_mutex_unlock(&m_read_endpoint);
2026#if !COAP_DISABLE_TCP
2033 return session != NULL;
2040#ifdef COAP_EPOLL_SUPPORT
2043 coap_log_emerg(
"coap_io_do_io() requires libcoap not compiled for using epoll\n");
2047#if COAP_SERVER_SUPPORT
2049 LL_FOREACH_SAFE(ctx->
endpoint, ep, tmp) {
2051 coap_read_endpoint(ctx, ep, now);
2053 coap_write_endpoint(ctx, ep, now);
2054#if !COAP_DISABLE_TCP
2056 coap_accept_endpoint(ctx, ep, now);
2072#if COAP_CLIENT_SUPPORT
2077 coap_connect_session(s, now);
2097#ifndef COAP_EPOLL_SUPPORT
2101 coap_log_emerg(
"coap_io_do_epoll() requires libcoap compiled for using epoll\n");
2107 for (j = 0; j < nevents; j++) {
2112#if COAP_SERVER_SUPPORT
2116 (events[j].events & EPOLLIN)) {
2118 coap_read_endpoint(endpoint->
context, endpoint, now);
2122 (events[j].events & EPOLLOUT)) {
2129 coap_write_endpoint(endpoint->
context, endpoint, now);
2132#if !COAP_DISABLE_TCP
2134 (events[j].events & EPOLLIN)) {
2136 coap_accept_endpoint(endpoint->
context, endpoint, now);
2148#if COAP_CLIENT_SUPPORT
2150 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
2152 coap_connect_session(session, now);
2161 (events[j].events & (EPOLLIN|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
2167 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
2179 }
else if (ctx->eptimerfd != -1) {
2188 if (read(ctx->eptimerfd, &count,
sizeof(count)) == -1) {
2201 uint8_t *msg,
size_t msg_len) {
2241 if (!queue || !*queue)
2246 if (session == (*queue)->session &&
id == (*queue)->id) {
2248 *queue = (*queue)->
next;
2250 (*queue)->
t += (*node)->t;
2252 (*node)->next = NULL;
2263 }
while (q && (session != q->
session ||
id != q->
id));
2365#if COAP_ERROR_PHRASE_LENGTH > 0
2372 size += strlen(phrase) + 1;
2407 uint16_t delta = opt_iter.
number - opt_num;
2411 }
else if (delta < 269) {
2421 switch (*option & 0x0f) {
2432 opt_num = opt_iter.
number;
2454#if COAP_ERROR_PHRASE_LENGTH > 0
2457 coap_add_data(response, (
size_t)strlen(phrase), (
const uint8_t *)phrase);
2464#if COAP_SERVER_SUPPORT
2471 unsigned char buf[1];
2476 coap_log_warn(
"cannot determine length of /.well-known/core\n");
2483#define SZX_TO_BYTES(SZX) ((size_t)(1 << ((SZX) + 4)))
2499 ssize_t wkc_len = get_wkc_len(session->
context, query);
2515 assert(len <= (
size_t)wkc_len);
2516 data_string->
length = len;
2531 coap_log_debug(
".well-known/core: truncating data length to %zu from %zu\n",
2538 free_wellknown_response(session, data_string);
2542 -1, 0, data_string->
length,
2544 free_wellknown_response,
2546 goto error_released;
2553 free_wellknown_response(session, data_string);
2555 if (response->
code == 0) {
2559 response->
data = NULL;
2576 int num_cancelled = 0;
2578#ifndef COAP_SERVER_SUPPORT
2583#if COAP_SERVER_SUPPORT
2593 return num_cancelled;
2596#if COAP_SERVER_SUPPORT
2601enum respond_t { RESPONSE_DEFAULT, RESPONSE_DROP, RESPONSE_SEND };
2648static enum respond_t
2653 unsigned int val = 0;
2679 response->
data = NULL;
2680 return RESPONSE_SEND;
2682 return RESPONSE_DROP;
2686 return RESPONSE_SEND;
2691 if ((resource->
flags &
2694 return RESPONSE_DROP;
2695 }
else if ((resource->
flags &
2698 if (response->
data == NULL)
2699 return RESPONSE_DROP;
2700 }
else if ((resource->
flags &
2703 return RESPONSE_DROP;
2704 }
else if ((resource->
flags &
2707 return RESPONSE_DROP;
2714 return RESPONSE_DROP;
2725 return RESPONSE_DROP;
2729 return RESPONSE_DROP;
2735 return RESPONSE_DEFAULT;
2756 enum respond_t respond = RESPONSE_DEFAULT;
2759 int is_proxy_uri = 0;
2760 int is_proxy_scheme = 0;
2761 int skip_hop_limit_check = 0;
2763 int send_early_empty_ack = 0;
2769 int added_block = 0;
2771#if COAP_Q_BLOCK_SUPPORT
2772 int lg_xmit_ctrl = 0;
2774#if COAP_ASYNC_SUPPORT
2780 coap_log_info(
"Invalid multicast packet received RFC7252 8.1\n");
2784#if COAP_ASYNC_SUPPORT
2790 if (async->delay == 0 || async->delay > now) {
2809 is_proxy_scheme = 1;
2816 if (is_proxy_scheme || is_proxy_uri) {
2822 is_proxy_scheme ?
"Scheme" :
"Uri");
2826 if (((
size_t)pdu->
code - 1 <
2831 is_proxy_scheme ?
"Scheme" :
"Uri",
2847 memset(&uri, 0,
sizeof(uri));
2881 is_proxy_scheme = 0;
2882 skip_hop_limit_check = 1;
2888 if (!skip_hop_limit_check) {
2896 if (hop_limit == 1) {
2900 }
else if (hop_limit < 1 || hop_limit > 255) {
2917 if (!is_proxy_uri && !is_proxy_scheme) {
2923 if ((resource == NULL) || (resource->
is_unknown == 1) ||
2928 if (resource != NULL)
2949 if (is_proxy_uri || is_proxy_scheme) {
2953 resource = &resource_uri_wellknown;
2955 ((
size_t)pdu->
code - 1 <
2990 coap_log_debug(
"request for unknown resource '%*.*s', return 4.04\n",
2998#if COAP_OSCORE_SUPPORT
3000 coap_log_debug(
"request for OSCORE only resource '%*.*s', return 4.04\n",
3016 if ((
size_t)pdu->
code - 1 <
3048#if COAP_ASYNC_SUPPORT
3080 resource, uri_path, observe,
3081 &added_block, &free_lg_srcv)) {
3089#if COAP_Q_BLOCK_SUPPORT
3105 if (block.
num != 0) {
3109#if COAP_Q_BLOCK_SUPPORT
3112 if (block.
num != 0) {
3132 coap_log_info(
"observe: unexpected action %d\n", observe_action);
3141 send_early_empty_ack = 1;
3143 if (send_early_empty_ack) {
3147 coap_log_debug(
"Duplicate request with mid=0x%04x - not processed\n",
3149 goto drop_it_no_debug;
3153#if COAP_WITH_OBSERVE_PERSIST
3156 context->unknown_pdu = pdu;
3157 context->unknown_session = session;
3159 context->unknown_pdu = NULL;
3168 h(resource, session, pdu, query, response);
3179 LL_DELETE(session->
lg_srcv, free_lg_srcv);
3189 if (send_early_empty_ack &&
3194 if (response->
code == 0) {
3195 goto drop_it_no_debug;
3198 respond = no_response(pdu, response, session, resource);
3199 if (respond != RESPONSE_DROP) {
3200#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG)
3220 && (response->
code == 0)) {
3225 response->
data = NULL;
3233#if COAP_Q_BLOCK_SUPPORT
3238 if (coap_send_q_block2(session, resource, query, pdu->
code, block,
3259 goto drop_it_no_debug;
3263 goto drop_it_no_debug;
3266 node->
id = response->
mid;
3267 node->
pdu = response;
3271 coap_log_debug(
" %s: mid=0x%04x: mcast response delayed for %u.%03u secs\n",
3277 node->
timeout = (
unsigned int)delay;
3291#if COAP_Q_BLOCK_SUPPORT
3307#if COAP_Q_BLOCK_SUPPORT
3324#if COAP_CLIENT_SUPPORT
3359 coap_log_debug(
"Extended Token requested size support not available\n");
3368#if COAP_Q_BLOCK_SUPPORT
3370 if (session->
block_mode & COAP_BLOCK_PROBE_Q_BLOCK &&
3422#if !COAP_DISABLE_TCP
3498 coap_log_warn(
"coap_dispatch: cannot create error response\n");
3523 int packet_is_bad = 0;
3524#if COAP_OSCORE_SUPPORT
3528 int is_ext_token_rst;
3535#if COAP_OSCORE_SUPPORT
3547 coap_log_warn(
"coap_dispatch: cannot create error response\n");
3561#if COAP_SERVER_SUPPORT
3570#if COAP_SERVER_SUPPORT
3576 memset(&uri, 0,
sizeof(uri));
3599 if (session->recipient_ctx == NULL ||
3600 session->recipient_ctx->initial_state == 0) {
3606 session->oscore_encryption = 1;
3615 switch (pdu->
type) {
3631#if COAP_SERVER_SUPPORT
3640 if (pdu->
code == 0) {
3641#if COAP_Q_BLOCK_SUPPORT
3652#if COAP_CLIENT_SUPPORT
3654 coap_send_q_block1(session, block, sent->
pdu,
3655 COAP_SEND_SKIP_PDU);
3658 coap_send_q_blocks(session, sent->
pdu->
lg_xmit, block,
3659 sent->
pdu, COAP_SEND_SKIP_PDU);
3679#if COAP_Q_BLOCK_SUPPORT
3681 if (session->
block_mode & COAP_BLOCK_PROBE_Q_BLOCK &&
3689 is_ext_token_rst = 0;
3696 is_ext_token_rst = 1;
3699 if (!is_ping_rst && !is_ext_token_rst)
3715 if (!is_ping_rst && !is_ext_token_rst) {
3721 }
else if (is_ping_rst) {
3729#if COAP_SERVER_SUPPORT
3733 LL_FOREACH_SAFE(r->subscribers, obs, tmp) {
3774 coap_log_warn(
"coap_dispatch: cannot create error response\n");
3794#if !COAP_DISABLE_TCP
3799#if COAP_SERVER_SUPPORT
3801 handle_request(context, session, pdu);
3804#if COAP_CLIENT_SUPPORT
3806 handle_response(context, session, sent ? sent->
pdu : NULL, pdu);
3838 if (packet_is_bad) {
3849#if COAP_OSCORE_SUPPORT
3854#if COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_DEBUG
3859 return "COAP_EVENT_DTLS_CLOSED";
3861 return "COAP_EVENT_DTLS_CONNECTED";
3863 return "COAP_EVENT_DTLS_RENEGOTIATE";
3865 return "COAP_EVENT_DTLS_ERROR";
3867 return "COAP_EVENT_TCP_CONNECTED";
3869 return "COAP_EVENT_TCP_CLOSED";
3871 return "COAP_EVENT_TCP_FAILED";
3873 return "COAP_EVENT_SESSION_CONNECTED";
3875 return "COAP_EVENT_SESSION_CLOSED";
3877 return "COAP_EVENT_SESSION_FAILED";
3879 return "COAP_EVENT_PARTIAL_BLOCK";
3881 return "COAP_EVENT_XMIT_BLOCK_FAIL";
3883 return "COAP_EVENT_SERVER_SESSION_NEW";
3885 return "COAP_EVENT_SERVER_SESSION_DEL";
3887 return "COAP_EVENT_BAD_PACKET";
3889 return "COAP_EVENT_MSG_RETRANSMITTED";
3891 return "COAP_EVENT_OSCORE_DECRYPTION_FAILURE";
3893 return "COAP_EVENT_OSCORE_NOT_ENABLED";
3895 return "COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD";
3897 return "COAP_EVENT_OSCORE_NO_SECURITY";
3899 return "COAP_EVENT_OSCORE_INTERNAL_ERROR";
3901 return "COAP_EVENT_OSCORE_DECODE_ERROR";
3903 return "COAP_EVENT_WS_PACKET_SIZE";
3905 return "COAP_EVENT_WS_CONNECTED";
3907 return "COAP_EVENT_WS_CLOSED";
3909 return "COAP_EVENT_KEEPALIVE_FAILURE";
3934#if COAP_SERVER_SUPPORT
3937 LL_FOREACH(context->
endpoint, ep) {
3946#if COAP_CLIENT_SUPPORT
3956#if COAP_SERVER_SUPPORT
3957#if COAP_ASYNC_SUPPORT
3963 LL_FOREACH_SAFE(context->async_state, async, tmp) {
3964 if (async->delay != 0 && async->delay <= now) {
3966 handle_request(context, async->session, async->pdu);
3971 if (next_due == 0 || next_due > async->delay - now)
3972 next_due = async->delay - now;
3982#if COAP_CONSTRAINED_STACK
3983coap_mutex_t m_show_pdu;
3984coap_mutex_t m_log_impl;
3985coap_mutex_t m_dtls_recv;
3986coap_mutex_t m_read_session;
3987coap_mutex_t m_read_endpoint;
3988coap_mutex_t m_persist_add;
4002#if COAP_CONSTRAINED_STACK
4003 coap_mutex_init(&m_show_pdu);
4004 coap_mutex_init(&m_log_impl);
4005 coap_mutex_init(&m_dtls_recv);
4006 coap_mutex_init(&m_read_session);
4007 coap_mutex_init(&m_read_endpoint);
4008 coap_mutex_init(&m_persist_add);
4011#if defined(HAVE_WINSOCK2_H)
4012 WORD wVersionRequested = MAKEWORD(2, 2);
4014 WSAStartup(wVersionRequested, &wsaData);
4023 coap_start_io_process();
4027#if COAP_SERVER_SUPPORT
4029 (
const uint8_t *)
".well-known/core"
4031 memset(&resource_uri_wellknown, 0,
sizeof(resource_uri_wellknown));
4034 resource_uri_wellknown.
uri_path = &well_known;
4040#if defined(HAVE_WINSOCK2_H)
4042#elif defined(WITH_CONTIKI)
4043 coap_stop_io_process();
4047#if COAP_CONSTRAINED_STACK
4048 coap_mutex_destroy(&m_show_pdu);
4049 coap_mutex_destroy(&m_log_impl);
4050 coap_mutex_destroy(&m_dtls_recv);
4051 coap_mutex_destroy(&m_read_session);
4052 coap_mutex_destroy(&m_read_endpoint);
4053 coap_mutex_destroy(&m_persist_add);
4062#if COAP_CLIENT_SUPPORT
4093#if ! defined WITH_CONTIKI && ! defined WITH_LWIP && ! defined RIOT_VERSION
4094#if COAP_SERVER_SUPPORT
4097 const char *ifname) {
4098#if COAP_IPV4_SUPPORT
4099 struct ip_mreq mreq4;
4101#if COAP_IPV6_SUPPORT
4102 struct ipv6_mreq mreq6;
4104 struct addrinfo *resmulti = NULL, hints, *ainfo;
4107 int mgroup_setup = 0;
4115#if COAP_IPV6_SUPPORT
4116 mreq6.ipv6mr_interface = 0;
4118#if COAP_IPV4_SUPPORT
4119 mreq4.imr_interface.s_addr = INADDR_ANY;
4122 memset(&hints, 0,
sizeof(hints));
4123 hints.ai_socktype = SOCK_DGRAM;
4126 result = getaddrinfo(group_name, NULL, &hints, &resmulti);
4130 "Cannot resolve multicast address: %s\n",
4131 group_name, gai_strerror(result));
4141#if defined(ESPIDF_VERSION)
4142 struct netif *netif;
4144#if COAP_IPV4_SUPPORT
4151 for (ainfo = resmulti; ainfo != NULL && !(done_ip4 == 1 && done_ip6 == 1);
4152 ainfo = ainfo->ai_next) {
4153 switch (ainfo->ai_family) {
4154#if COAP_IPV6_SUPPORT
4159#if defined(ESPIDF_VERSION)
4160 netif = netif_find(ifname);
4162 mreq6.ipv6mr_interface = netif_get_index(netif);
4165 "Cannot get IPv4 address: %s\n",
4168 memset(&ifr, 0,
sizeof(ifr));
4169 strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
4170 ifr.ifr_name[IFNAMSIZ - 1] =
'\000';
4172#ifdef HAVE_IF_NAMETOINDEX
4173 mreq6.ipv6mr_interface = if_nametoindex(ifr.ifr_name);
4174 if (mreq6.ipv6mr_interface == 0) {
4176 "cannot get interface index for '%s'\n",
4183 "cannot get interface index for '%s': %s\n",
4187 mreq6.ipv6mr_interface = ifr.ifr_ifindex;
4193#if COAP_IPV4_SUPPORT
4198#if defined(ESPIDF_VERSION)
4199 netif = netif_find(ifname);
4201 mreq4.imr_interface.s_addr = netif_ip4_addr(netif)->addr;
4204 "Cannot get IPv4 address: %s\n",
4211 ip4fd = socket(AF_INET, SOCK_DGRAM, 0);
4213 coap_log_err(
"coap_join_mcast_group_intf: %s: socket: %s\n",
4217 memset(&ifr, 0,
sizeof(ifr));
4218 strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
4219 ifr.ifr_name[IFNAMSIZ - 1] =
'\000';
4220 result = ioctl(ip4fd, SIOCGIFADDR, &ifr);
4223 "Cannot get IPv4 address: %s\n",
4227 mreq4.imr_interface = ((
struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
4241 for (ainfo = resmulti; ainfo != NULL; ainfo = ainfo->ai_next) {
4242 LL_FOREACH(ctx->
endpoint, endpoint) {
4248#if COAP_IPV6_SUPPORT
4249 if (ainfo->ai_family == AF_INET6) {
4256 mreq6.ipv6mr_interface =
4259 mreq6.ipv6mr_interface = 0;
4262 gaddr.
addr.
sin6.sin6_family = AF_INET6;
4264 gaddr.
addr.
sin6.sin6_addr = mreq6.ipv6mr_multiaddr =
4265 ((
struct sockaddr_in6 *)ainfo->ai_addr)->sin6_addr;
4266 result = setsockopt(endpoint->
sock.
fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
4267 (
char *)&mreq6,
sizeof(mreq6));
4270#if COAP_IPV4_SUPPORT && COAP_IPV6_SUPPORT
4273#if COAP_IPV4_SUPPORT
4274 if (ainfo->ai_family == AF_INET) {
4283 mreq4.imr_interface.s_addr = INADDR_ANY;
4286 gaddr.
addr.
sin.sin_family = AF_INET;
4288 gaddr.
addr.
sin.sin_addr.s_addr = mreq4.imr_multiaddr.s_addr =
4289 ((
struct sockaddr_in *)ainfo->ai_addr)->sin_addr.s_addr;
4290 result = setsockopt(endpoint->
sock.
fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
4291 (
char *)&mreq4,
sizeof(mreq4));
4299 coap_log_err(
"coap_join_mcast_group_intf: %s: setsockopt: %s\n",
4304 addr_str[
sizeof(addr_str)-1] =
'\000';
4306 sizeof(addr_str) - 1)) {
4318 if (!mgroup_setup) {
4323 freeaddrinfo(resmulti);
4335#if COAP_CLIENT_SUPPORT
4340#if COAP_IPV4_SUPPORT
4342 if (setsockopt(session->
sock.
fd, IPPROTO_IP, IP_MULTICAST_TTL,
4343 (
const char *)&hops,
sizeof(hops)) < 0) {
4350#if COAP_IPV6_SUPPORT
4352 if (setsockopt(session->
sock.
fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
4353 (
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)
void coap_debug_reset(void)
Reset all the defined logging parameters.
struct coap_async_t coap_async_t
Async Entry information.
Pulls together all the internal only header files.
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.
#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
void coap_update_epoll_timer(coap_context_t *context, coap_tick_t delay)
Update the epoll timer fd as to when it is to trigger.
#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
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().
#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)
#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 void coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
static int check_token_size(coap_session_t *session, const coap_pdu_t *pdu)
COAP_STATIC_INLINE coap_queue_t * coap_malloc_node(void)
#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_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...
#define SESSIONS_ITER_SAFE(e, el, rtmp)
#define SESSIONS_ITER(e, el, rtmp)
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...
unsigned int coap_io_prepare_epoll(coap_context_t *ctx, coap_tick_t now)
Any now timed out delayed packet is transmitted, along with any packets associated with requested obs...
void coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms)
The main I/O processing function.
void coap_block_delete_lg_srcv(coap_session_t *session, coap_lg_srcv_t *lg_srcv)
void coap_block_delete_lg_crcv(coap_session_t *session, coap_lg_crcv_t *lg_crcv)
int coap_handle_response_get_block(coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd, coap_recurse_t recursive)
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()...
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd)
void coap_check_update_token(coap_session_t *session, coap_pdu_t *pdu)
The function checks if the token needs to be updated before PDU is presented to the application (only...
int coap_handle_request_put_block(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *uri_path, coap_opt_t *observe, int *added_block, coap_lg_srcv_t **free_lg_srcv)
coap_lg_crcv_t * coap_block_new_lg_crcv(coap_session_t *session, coap_pdu_t *pdu, coap_lg_xmit_t *lg_xmit)
int coap_handle_request_send_block(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *query)
#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
int coap_add_data_large_response(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_string_t *query, uint16_t media_type, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the response pdu that is passed as fourth parameter.
#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.
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_free_async(coap_session_t *session, coap_async_t *async)
Releases the memory that was allocated by coap_register_async() for the object async.
coap_async_t * coap_find_async(coap_session_t *session, coap_bin_const_t token)
Retrieves the object identified by token from the list of asynchronous transactions that are register...
int coap_prng(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
void coap_prng_init(unsigned int seed)
Seeds the default random number generation function with the given seed.
coap_print_status_t coap_print_wellknown(coap_context_t *, unsigned char *, size_t *, size_t, const coap_string_t *)
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
#define RESOURCES_ITER(r, tmp)
coap_resource_t * coap_get_resource_from_uri_path(coap_context_t *context, coap_str_const_t *uri_path)
Returns the resource identified by the unique string uri_path.
#define COAP_RESOURCE_FLAGS_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_FLAGS_LIB_DIS_MCAST_DELAYS
Disable libcoap library from adding in delays to multicast requests before releasing the response bac...
#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...
void(* coap_method_handler_t)(coap_resource_t *, coap_session_t *, const coap_pdu_t *, const coap_string_t *, coap_pdu_t *)
Definition of message handler function.
#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...
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now)
Set sendqueue_basetime in the given context object ctx to now.
void coap_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, coap_mid_t id, coap_queue_t **node)
This function removes the element with given id from the list given list.
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
int coap_client_delay_first(coap_session_t *session)
Delay the sending of the first client request until some other negotiation has completed.
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.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
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',...
coap_mid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
int coap_option_check_critical(coap_session_t *session, coap_pdu_t *pdu, coap_opt_filter_t *unknown)
Verifies that pdu contains no unknown critical options.
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_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.
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.
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.
void coap_context_set_session_timeout(coap_context_t *context, unsigned int session_timeout)
Set the session timeout value.
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.
unsigned int coap_context_get_max_handshake_sessions(const coap_context_t *context)
Get the session timeout value.
uint16_t coap_new_message_id(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
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_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.
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.
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_csm_max_message_size(coap_context_t *context, uint32_t csm_max_message_size)
Set the CSM max session size value.
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_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_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
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...
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.
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.
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 *)
Returns the current value of an internal tick counter.
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.
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.
COAP_STATIC_INLINE 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.
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).
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_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.
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_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.
void coap_register_option(coap_context_t *ctx, uint16_t type)
Registers the option type type with the given context object ctx.
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_get_app_data(const coap_context_t *ctx)
Returns any application-specific data that has been stored with context using the function coap_set_a...
void coap_context_set_max_idle_sessions(coap_context_t *context, unsigned int max_idle_sessions)
Set the maximum idle sessions count.
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds)
Set the context keepalive timer for sessions.
void coap_set_app_data(coap_context_t *ctx, void *app_data)
Stores data with the given CoAP context.
unsigned int coap_context_get_csm_timeout(const coap_context_t *context)
Get the CSM timeout value.
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_mid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
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(coap_context_t *context, unsigned int csm_timeout)
Set the CSM timeout value.
@ COAP_RESPONSE_FAIL
Response not liked - send CoAP RST packet.
const coap_bin_const_t * coap_get_session_client_psk_identity(const coap_session_t *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_hello(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling client HELLO messages from a new candiate peer.
int coap_dtls_context_set_spsk(coap_context_t *coap_context, coap_dtls_spsk_t *setup_data)
Set the DTLS context's default server PSK information.
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.
int coap_tls_is_supported(void)
Check whether TLS is available.
#define COAP_DTLS_PKI_SETUP_VERSION
Latest PKI setup version.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
@ 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.
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_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_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_WS_CLOSED
Triggered when the WebSockets layer is closed.
@ COAP_EVENT_SESSION_CLOSED
Triggered when TCP layer closes following exchange of CSM information.
@ 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_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_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_log_debug(...)
#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(...)
void coap_lwip_dump_memory_pools(coap_log_t log_level)
Dump the current state of the LwIP memory pools.
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_ALL
Pre-defined filter that includes all options.
int coap_option_filter_unset(coap_opt_filter_t *filter, coap_option_num_t option)
Clears the corresponding entry for number in 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(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)
#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_update_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Updates token in pdu with length len and 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_PDU_IS_SIGNALING(pdu)
int coap_option_check_repeatable(coap_option_num_t number)
Check whether the option is allowed to be repeated or not.
int coap_pdu_parse_opt(coap_pdu_t *pdu)
Verify consistency in the given CoAP PDU structure and locate the data.
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.
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.
#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.
#define COAP_OPTION_HOP_LIMIT
#define COAP_OPTION_NORESPONSE
#define COAP_OPTION_URI_HOST
#define COAP_OPTION_IF_MATCH
#define COAP_OPTION_BLOCK2
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_BLOCK1
#define COAP_OPTION_Q_BLOCK1
#define COAP_OPTION_PROXY_SCHEME
#define COAP_OPTION_URI_QUERY
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
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_OPTION_IF_NONE_MATCH
#define COAP_TOKEN_EXT_MAX
#define COAP_OPTION_URI_PATH
#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
coap_pdu_code_t
Set of codes available for a PDU.
#define COAP_OPTION_OSCORE
coap_pdu_type_t
CoAP PDU message type definitions.
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
#define COAP_OPTION_Q_BLOCK2
#define COAP_SIGNALING_OPTION_CUSTODY
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.
#define COAP_OPTION_URI_PORT
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_OPTION_ACCEPT
#define COAP_INVALID_MID
Indicates an invalid message id.
#define COAP_OPTION_PROXY_URI
#define COAP_OPTION_OBSERVE
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE
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
coap_session_t * coap_new_server_session(coap_context_t *ctx, coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
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).
size_t coap_session_max_pdu_rcv_size(const coap_session_t *session)
Get maximum acceptable receive PDU size.
coap_session_t * coap_endpoint_get_session(coap_endpoint_t *endpoint, const coap_packet_t *packet, coap_tick_t now)
Lookup the server session for the packet received on an endpoint, or create a new one.
#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.
@ 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.
size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_free_endpoint(coap_endpoint_t *endpoint)
Release an endpoint and all the structures associated with it.
coap_endpoint_t * coap_new_endpoint(coap_context_t *context, const coap_address_t *listen_addr, coap_proto_t proto)
Create a new endpoint for communicating with peers.
#define COAP_PROTO_NOT_RELIABLE(p)
#define COAP_PROTO_RELIABLE(p)
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
@ COAP_SESSION_TYPE_HELLO
server-side ephemeral session for responding to a client hello
@ 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.
void coap_persist_cleanup(coap_context_t *context)
Close down persist tracking, releasing any memory used.
int coap_delete_observer(coap_resource_t *resource, coap_session_t *session, const coap_bin_const_t *token)
Removes any subscription for observer from resource and releases the allocated storage.
void coap_handle_failed_notify(coap_context_t *context, coap_session_t *session, const coap_bin_const_t *token)
Handles a failed observe notify.
coap_subscription_t * coap_add_observer(coap_resource_t *resource, coap_session_t *session, const coap_bin_const_t *token, const coap_pdu_t *pdu)
Adds the specified peer as observer for resource.
void coap_touch_observer(coap_context_t *context, coap_session_t *session, const coap_bin_const_t *token)
Flags that data is ready to be sent to observers.
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.
#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::@0 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.
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 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.
coap_pong_handler_t pong_handler
Called when a ping response is received.
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
void * app
application-specific data
coap_session_t * sessions
client sessions
coap_nack_handler_t nack_handler
Called when a response issue has occurred.
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
coap_resource_t * resources
hash table or list of known resources
uint16_t * cache_ignore_options
CoAP options to ignore when creating a cache-key.
coap_opt_filter_t known_options
coap_ping_handler_t ping_handler
Called when a CoAP ping is received.
uint32_t csm_max_message_size
Value for CSM Max-Message-Size.
size_t cache_ignore_count
The number of CoAP options to ignore when creating a cache-key.
unsigned int max_handshake_sessions
Maximum number of simultaneous negotating sessions per endpoint.
uint32_t max_token_size
Largest token size supported RFC8974.
coap_response_handler_t response_handler
Called when a response is received.
coap_cache_entry_t * cache
CoAP cache-entry cache.
uint8_t mcast_per_resource
Mcast controlled on a per resource basis.
coap_endpoint_t * endpoint
the endpoints used for listening
coap_event_handler_t handle_event
Callback function that is used to signal events to the application.
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.
coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
coap_dtls_spsk_t spsk_setup_data
Contains the initial PSK server setup data.
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
coap_resource_t * unknown_resource
can be used for handling unknown resources
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.
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_context_t * context
endpoint's context
coap_session_t * sessions
hash table or list of active sessions
coap_address_t bind_addr
local interface address
coap_socket_t sock
socket object for the interface, if any
coap_proto_t proto
protocol used on this interface
uint64_t state_token
state token
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) client receive information.
uint8_t initial
If set, has not been used yet.
coap_bin_const_t ** obs_token
Tokens used in setting up Observe (to handle large FETCH)
uint64_t state_token
state token
coap_binary_t * app_token
app requesting PDU token
uint8_t observe_set
Set if this is an observe receive PDU.
Structure to hold large body (many blocks) server receive information.
Structure to hold large body (many blocks) transmission information.
union coap_lg_xmit_t::@1 b
coap_pdu_t pdu
skeletal PDU
uint16_t option
large block transmisson CoAP option
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
coap_lg_xmit_t * lg_xmit
Holds ptr to lg_xmit if sending a set of blocks.
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.
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_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 resource that can be attached to coap_context_t.
coap_str_const_t ** proxy_name_list
Array valid names this host is known by (proxy support)
coap_str_const_t * uri_path
Request URI Path for this resource.
unsigned int observe
The next value for the Observe option.
coap_method_handler_t handler[7]
Used to store handlers for the seven coap methods GET, POST, PUT, DELETE, FETCH, PATCH and IPATCH.
unsigned int is_proxy_uri
resource created for proxy URI handler
unsigned int is_unknown
resource created for unknown handler
unsigned int observable
can be observed
size_t proxy_name_count
Count of valid names this host is known by (proxy support)
int flags
zero or more COAP_RESOURCE_FLAGS_* or'd together
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.
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
uint8_t doing_first
Set if doing client's first request.
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.
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)
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
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_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
coap_bin_const_t * last_token
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
size_t mtu
path or CSM mtu (xmt)
uint16_t remote_test_mid
mid used for checking remote support
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
coap_lg_srcv_t * lg_srcv
Server list of expected large receives.
coap_lg_crcv_t * lg_crcv
Client list of expected large receives.
coap_mid_t last_con_mid
The last CON mid that has been been processed.
coap_session_type_t type
client or server side socket
coap_mid_t last_ack_mid
The last ACK mid that has been been processed.
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_endpoint_t * endpoint
Used by the epoll logic for a listening endpoint.
coap_address_t mcast_addr
remote address and port (multicast track)
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
Number of notifications that may be sent non-confirmable before a confirmable message is sent to dete...
struct coap_session_t * session
subscriber session
coap_pdu_t * pdu
cache_key to identify requester
Representation of parsed URI.
coap_str_const_t host
The host part of the URI.