20 #ifdef HAVE_SYS_UNISTD_H
21 #include <sys/unistd.h>
24 #ifdef HAVE_SYS_TYPES_H
25 #include <sys/types.h>
27 #ifdef HAVE_SYS_SOCKET_H
28 #include <sys/socket.h>
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
33 #ifdef HAVE_ARPA_INET_H
34 #include <arpa/inet.h>
36 #ifdef COAP_EPOLL_SUPPORT
37 #include <sys/epoll.h>
38 #include <sys/timerfd.h>
40 #ifdef HAVE_WS2TCPIP_H
49 #include <lwip/pbuf.h>
51 #include <lwip/timeouts.h>
54 #ifndef INET6_ADDRSTRLEN
55 #define INET6_ADDRSTRLEN 40
59 #define min(a,b) ((a) < (b) ? (a) : (b))
75 #error FRAC_BITS must be less or equal 8
79 #define Q(frac,fval) ((uint16_t)(((1 << (frac)) * fval.integer_part) + \
80 ((1 << (frac)) * fval.fractional_part + 500)/1000))
83 #define ACK_RANDOM_FACTOR \
84 Q(FRAC_BITS, session->ack_random_factor)
87 #define ACK_TIMEOUT Q(FRAC_BITS, session->ack_timeout)
89 #if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
104 #include <lwip/memp.h>
106 static void coap_retransmittimer_execute(
void *arg);
116 memp_free(MEMP_COAP_NODE, node);
122 # define DEBUG DEBUG_PRINT
125 #include "net/ip/uip-debug.h"
127 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
128 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN])
130 void coap_resources_init();
132 unsigned char initialized = 0;
135 PROCESS(coap_retransmit_process,
"message retransmit process");
150 unsigned int result = 0;
199 if (node->
t < q->
t) {
211 }
while (q && q->
t <= node->
t);
261 memset(node, 0,
sizeof(*node));
292 const uint8_t *hint,
size_t hint_len,
293 uint8_t *identity,
size_t *identity_len,
size_t max_identity_len,
294 uint8_t *psk,
size_t max_psk_len
328 const uint8_t *identity,
size_t identity_len,
329 uint8_t *psk,
size_t max_psk_len
356 uint8_t *hint,
size_t max_hint_len
370 if (psk_info->
hint.
s &&
382 const uint8_t *key,
size_t key_len
386 memset (&setup_data, 0,
sizeof(setup_data));
392 if (key && key_len > 0) {
420 coap_log(
LOG_ERR,
"coap_context_set_pki: Wrong version of setup_data\n");
444 #ifdef COAP_EPOLL_SUPPORT
445 return context->epfd;
475 coap_resources_init();
477 c = &the_coap_context;
483 #ifdef COAP_EPOLL_SUPPORT
484 c->epfd = epoll_create1(0);
486 coap_log(
LOG_ERR,
"coap_new_context: Unable to epoll_create: %s (%d)\n",
492 c->eptimerfd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK);
493 if (c->eptimerfd == -1) {
494 coap_log(
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);
512 "%s: epoll_ctl ADD failed: %s (%d)\n",
535 if (endpoint == NULL) {
540 #if !defined(WITH_LWIP)
550 process_start(&coap_retransmit_process, (
char *)c);
552 PROCESS_CONTEXT_BEGIN(&coap_retransmit_process);
553 #ifndef WITHOUT_OBSERVE
557 etimer_set(&the_coap_context.retransmit_timer, 0xFFFF);
558 PROCESS_CONTEXT_END(&coap_retransmit_process);
593 coap_retransmittimer_restart(context);
598 #ifndef WITHOUT_ASYNC
618 #ifdef COAP_EPOLL_SUPPORT
619 if (context->eptimerfd != -1) {
621 struct epoll_event event;
624 ret = epoll_ctl(context->epfd, EPOLL_CTL_DEL, context->eptimerfd, &event);
627 "%s: epoll_ctl DEL failed: %s (%d)\n",
631 close(context->eptimerfd);
632 context->eptimerfd = -1;
634 if (context->epfd != -1) {
635 close(context->epfd);
666 if (opt_iter.
type & 0x01) {
668 switch (opt_iter.
type) {
716 ssize_t bytes_written = -1;
718 switch(session->
proto) {
728 #if !COAP_DISABLE_TCP
734 #if !COAP_DISABLE_TCP
743 return bytes_written;
748 ssize_t bytes_written;
758 bytes_written = coap_socket_send_pdu(sock, session, pdu);
788 #if !COAP_DISABLE_TCP
834 coap_log(
LOG_ERR,
"Multicast requests cannot be Confirmable (RFC7252 8.1)\n");
854 return bytes_written;
906 #define FP1 Q(FRAC_BITS, ((coap_fixed_point_t){1,0}))
909 #define SHR_FP(val,frac) (((val) + (1 << ((frac) - 1))) >> (frac))
956 coap_retransmittimer_restart(context);
967 PROCESS_CONTEXT_BEGIN(&coap_retransmit_process);
968 etimer_set(&context->retransmit_timer, nextpdu->
t);
969 PROCESS_CONTEXT_END(&coap_retransmit_process);
977 #ifdef COAP_EPOLL_SUPPORT
978 if (context->eptimerfd != -1) {
980 if (context->next_timeout == 0 ||
982 struct itimerspec new_value;
986 memset(&new_value, 0,
sizeof(new_value));
989 new_value.it_value.tv_sec = rem_timeout / 1000;
990 new_value.it_value.tv_nsec = (rem_timeout % 1000) * 1000000;
991 ret = timerfd_settime(context->eptimerfd, 0, &new_value, NULL);
994 "%s: timerfd_settime failed: %s (%d)\n",
1008 ssize_t bytes_written;
1020 addr_str[
sizeof(addr_str)-1] =
'\000';
1022 sizeof(addr_str) - 1)) {
1026 if (addr_str[0] ==
'[') {
1027 cp = strchr(addr_str,
']');
1028 if (cp) *cp =
'\000';
1029 if (memcmp(&addr_str[1],
"::ffff:", 7) == 0) {
1038 cp = strchr(addr_str,
':');
1039 if (cp) *cp =
'\000';
1051 if (hop_limit == 1) {
1057 else if (hop_limit < 1 || hop_limit > 255) {
1071 if (pdu->
data && opt == NULL) {
1075 pdu->
data[data_len] =
'\000';
1076 a_match = strstr((
char*)pdu->
data, cp);
1077 if (a_match && (a_match == (
char*)pdu->
data || a_match[-1] ==
' ') &&
1078 ((
size_t)(a_match - (
char*)pdu->
data + len) == data_len ||
1079 a_match[len] ==
' ')) {
1090 if (pdu->
data == NULL) {
1103 memmove(pdu->
data + len + 1, pdu->
data,
1105 memcpy(pdu->
data, cp, len);
1106 pdu->
data[len] =
' ';
1118 #if !COAP_DISABLE_TCP
1132 "Remote end did not indicate CSM support for BLOCK1 enabled\n");
1136 "Remote end did not indicate CSM support for BLOCK2 enabled\n");
1148 if (bytes_written < 0) {
1153 #if !COAP_DISABLE_TCP
1155 (
size_t)bytes_written < pdu->used_size + pdu->
hdr_size) {
1179 node->
id = pdu->
tid;
1192 if (!context || !node)
1197 ssize_t bytes_written;
1212 coap_retransmittimer_restart(context);
1228 if (bytes_written < 0)
1229 return (
int)bytes_written;
1236 #ifndef WITH_CONTIKI
1241 #ifndef WITHOUT_OBSERVE
1294 else if (session->
tls)
1307 #if COAP_DISABLE_TCP
1345 ssize_t bytes_written;
1350 switch (session->
proto) {
1352 #if !COAP_DISABLE_TCP
1361 #if !COAP_DISABLE_TCP
1373 if (bytes_written > 0)
1376 if (bytes_written > 0)
1388 #if COAP_CONSTRAINED_STACK
1389 static coap_mutex_t s_static_mutex = COAP_MUTEX_INITIALIZER;
1396 #if COAP_CONSTRAINED_STACK
1397 coap_mutex_lock(&s_static_mutex);
1407 if (bytes_read < 0) {
1408 if (bytes_read == -2)
1414 }
else if (bytes_read > 0) {
1422 #if !COAP_DISABLE_TCP
1424 ssize_t bytes_read = 0;
1429 size_t buf_len =
sizeof(packet->
payload);
1436 if (bytes_read > 0) {
1442 retry = bytes_read == (ssize_t)buf_len;
1443 while (bytes_read > 0) {
1448 size_t n =
min(len, (
size_t)bytes_read);
1468 size_t n =
min(len, (
size_t)bytes_read);
1477 "** %s: incoming PDU length too large (%zu > %lu)\n",
1518 }
while (bytes_read == 0 && retry);
1523 #if COAP_CONSTRAINED_STACK
1524 coap_mutex_unlock(&s_static_mutex);
1530 ssize_t bytes_read = -1;
1532 #if COAP_CONSTRAINED_STACK
1533 static coap_mutex_t e_static_mutex = COAP_MUTEX_INITIALIZER;
1543 #if COAP_CONSTRAINED_STACK
1544 coap_mutex_lock(&e_static_mutex);
1553 if (bytes_read < 0) {
1555 }
else if (bytes_read > 0) {
1565 #if COAP_CONSTRAINED_STACK
1566 coap_mutex_unlock(&e_static_mutex);
1585 return session != NULL;
1590 #ifdef COAP_EPOLL_SUPPORT
1594 "coap_io_do_io() requires libcoap not compiled for using epoll\n");
1651 #ifndef COAP_EPOLL_SUPPORT
1656 "coap_io_do_epoll() requires libcoap compiled for using epoll\n");
1662 for(j = 0; j < nevents; j++) {
1670 (events[j].events & EPOLLIN)) {
1676 (events[j].events & EPOLLOUT)) {
1687 (events[j].events & EPOLLIN)) {
1700 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
1709 (events[j].events & (EPOLLIN|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
1715 (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
1728 else if (ctx->eptimerfd != -1) {
1737 if (read(ctx->eptimerfd, &count,
sizeof(count)) == -1) {
1750 uint8_t *msg,
size_t msg_len) {
1788 if (!queue || !*queue)
1793 if (session == (*queue)->session &&
id == (*queue)->id) {
1795 *queue = (*queue)->
next;
1797 (*queue)->
t += (*node)->t;
1799 (*node)->next = NULL;
1810 }
while (q && (session != q->
session ||
id != q->
id));
1830 const uint8_t *b,
size_t blen) {
1831 return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0);
1873 const uint8_t *token,
size_t token_length) {
1914 while (queue && queue->
session != session && queue->
id !=
id)
1915 queue = queue->
next;
1928 uint16_t opt_type = 0;
1930 #if COAP_ERROR_PHRASE_LENGTH > 0
1937 size += strlen(phrase) + 1;
1971 uint16_t delta = opt_iter.
type - opt_type;
1975 }
else if (delta < 269) {
1985 switch (*option & 0x0f) {
1996 opt_type = opt_iter.
type;
2018 #if COAP_ERROR_PHRASE_LENGTH > 0
2034 unsigned char buf[1];
2048 #define SZX_TO_BYTES(SZX) ((size_t)(1 << ((SZX) + 4)))
2055 size_t len, wkc_len;
2058 int need_block2 = 0;
2094 offset = block.
num << (block.
szx + 4);
2095 if (block.
szx > 6) {
2100 block.
num = (
unsigned int)(offset >> (block.
szx + 4));
2124 if (block.
szx == 0) {
2126 "coap_wellknown_response: message to small even for szx == 0\n");
2158 "coap_wellknown_response: cannot add Block2 option\n");
2205 #ifndef WITHOUT_OBSERVE
2207 int num_cancelled = 0;
2220 return num_cancelled;
2266 unsigned int val = 0;
2313 int is_proxy_uri = 0;
2314 int is_proxy_scheme = 0;
2315 int skip_hop_limit_check = 0;
2321 is_proxy_scheme = 1;
2327 if (is_proxy_scheme || is_proxy_uri) {
2333 is_proxy_scheme ?
"Scheme" :
"Uri");
2337 if (((
size_t)pdu->
code - 1 <
2342 is_proxy_scheme ?
"Scheme" :
"Uri",
2359 memset(&uri, 0,
sizeof(uri));
2377 is_proxy_scheme = 0;
2378 skip_hop_limit_check = 1;
2384 if (!skip_hop_limit_check) {
2392 if (hop_limit == 1) {
2397 else if (hop_limit < 1 || hop_limit > 255) {
2414 if (!is_proxy_uri && !is_proxy_scheme) {
2420 if ((resource == NULL) || (resource->
is_unknown == 1) ||
2452 }
else if (is_proxy_uri || is_proxy_scheme) {
2455 ((
size_t)pdu->
code - 1 <
2517 if ((
size_t)pdu->
code - 1 <
2574 h(context, resource, session, pdu, &token, query, response);
2576 if (query && owns_query)
2590 && (response->
code == 0)) {
2599 (response->
code >= 64
2637 assert(response == NULL);
2670 #if !COAP_DISABLE_TCP
2734 switch (pdu->
type) {
2829 "coap_dispatch: cannot create error response\n");
2842 #if !COAP_DISABLE_TCP
2923 #if defined(HAVE_WINSOCK2_H)
2924 WORD wVersionRequested = MAKEWORD(2, 2);
2926 WSAStartup(wVersionRequested, &wsaData);
2938 #if defined(HAVE_WINSOCK2_H)
2944 #if ! defined WITH_CONTIKI && ! defined WITH_LWIP && ! defined RIOT_VERSION
2947 struct ipv6_mreq mreq;
2948 struct addrinfo *reslocal = NULL, *resmulti = NULL, hints, *ainfo;
2951 int mgroup_setup = 0;
2954 memset(&hints, 0,
sizeof(hints));
2955 hints.ai_family = AF_INET6;
2956 hints.ai_socktype = SOCK_DGRAM;
2958 result = getaddrinfo(
"::", NULL, &hints, &reslocal);
2961 "coap_join_mcast_group: cannot resolve link-local interface: %s\n",
2962 gai_strerror(result));
2967 for (ainfo = reslocal; ainfo != NULL; ainfo = ainfo->ai_next) {
2968 if (ainfo->ai_family == AF_INET6) {
2969 mreq.ipv6mr_interface =
2970 ((
struct sockaddr_in6 *)ainfo->ai_addr)->sin6_scope_id;
2975 memset(&hints, 0,
sizeof(hints));
2976 hints.ai_family = AF_INET6;
2977 hints.ai_socktype = SOCK_DGRAM;
2980 result = getaddrinfo(group_name, NULL, &hints, &resmulti);
2984 "coap_join_mcast_group: cannot resolve multicast address: %s\n",
2985 gai_strerror(result));
2989 for (ainfo = resmulti; ainfo != NULL; ainfo = ainfo->ai_next) {
2990 if (ainfo->ai_family == AF_INET6) {
2991 mreq.ipv6mr_multiaddr =
2992 ((
struct sockaddr_in6 *)ainfo->ai_addr)->sin6_addr;
3000 result = setsockopt(endpoint->
sock.
fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
3001 (
char *)&mreq,
sizeof(mreq));
3004 "coap_join_mcast_group: setsockopt: %s: '%s'\n",
3012 if (!mgroup_setup) {
3017 freeaddrinfo(resmulti);
3018 freeaddrinfo(reslocal);
3036 PROCESS_THREAD(coap_retransmit_process, ev, data) {
3046 if (ev == PROCESS_EVENT_TIMER) {
3047 if (etimer_expired(&the_coap_context.retransmit_timer)) {
3052 while (nextpdu && nextpdu->
t <= now) {
3058 etimer_set(&the_coap_context.retransmit_timer,
3059 nextpdu ? nextpdu->
t - now : 0xFFFF);
3061 #ifndef WITHOUT_OBSERVE
3062 if (etimer_expired(&the_coap_context.notify_timer)) {
3064 etimer_reset(&the_coap_context.notify_timer);
3090 static void coap_retransmittimer_execute(
void *arg) {
3096 ctx->timer_configured = 0;
3103 while (nextinqueue != NULL) {
3104 if (nextinqueue->
t > elapsed) {
3105 nextinqueue->
t -= elapsed;
3108 elapsed -= nextinqueue->
t;
3116 coap_retransmittimer_restart(ctx);
3122 if (ctx->timer_configured) {
3123 printf(
"clearing\n");
3124 sys_untimeout(coap_retransmittimer_execute, (
void*)ctx);
3125 ctx->timer_configured = 0;
3147 printf(
"scheduling for %d ticks\n", delay);
3148 sys_timeout(delay, coap_retransmittimer_execute, (
void*)ctx);
3149 ctx->timer_configured = 1;
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.
COAP_STATIC_INLINE void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
void coap_delete_all_async(coap_context_t *context)
Removes and frees off all of the async entries for the given context.
void coap_dtls_free_context(struct coap_dtls_context_t *dtls_context)
Releases the storage allocated for dtls_context.
int coap_dtls_send(struct coap_context_t *coap_context, struct coap_dtls_session_t *session, const coap_pdu_t *pdu)
Pulls together all the internal only header files.
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
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.
ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
ssize_t coap_network_send(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
const char * coap_socket_strerror(void)
#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_mcast_interface(Local)
#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_ERROR
@ COAP_NACK_NOT_DELIVERABLE
@ COAP_NACK_TOO_MANY_RETRIES
#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)
#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
#define COAP_SOCKET_EMPTY
coap_socket_flags_t values
void coap_free_endpoint(coap_endpoint_t *ep)
int coap_dtls_context_set_pki_root_cas(struct coap_context_t *ctx UNUSED, const char *ca_file UNUSED, const char *ca_path UNUSED)
int coap_dtls_context_set_pki(coap_context_t *ctx UNUSED, const coap_dtls_pki_t *setup_data UNUSED, const coap_dtls_role_t role UNUSED)
void * coap_dtls_new_client_session(coap_session_t *session UNUSED)
void * coap_tls_new_client_session(coap_session_t *session UNUSED, int *connected UNUSED)
int coap_dtls_receive(coap_session_t *session UNUSED, const uint8_t *data UNUSED, size_t data_len UNUSED)
int coap_dtls_hello(coap_session_t *session UNUSED, const uint8_t *data UNUSED, size_t data_len UNUSED)
ssize_t coap_tls_read(coap_session_t *session UNUSED, uint8_t *data UNUSED, size_t data_len UNUSED)
int coap_dtls_context_set_spsk(coap_context_t *ctx UNUSED, coap_dtls_spsk_t *setup_data UNUSED)
ssize_t coap_tls_write(coap_session_t *session UNUSED, const uint8_t *data UNUSED, size_t data_len UNUSED)
coap_session_t * coap_endpoint_get_session(coap_endpoint_t *endpoint, const coap_packet_t *packet, coap_tick_t now)
ssize_t coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node)
void coap_session_set_mtu(coap_session_t *session, unsigned mtu)
Set the session MTU.
void coap_session_send_csm(coap_session_t *session)
Notify session transport has just connected and CSM exchange can now start.
size_t coap_session_max_pdu_size(const coap_session_t *session)
Get maximum acceptable PDU size.
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
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.
coap_session_t * coap_new_server_session(struct coap_context_t *ctx, coap_endpoint_t *ep)
Creates a new server session for the specified endpoint.
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for stream data transmission.
#define SESSIONS_ITER_SAFE(e, el, rtmp)
#define COAP_SESSION_STATE_HANDSHAKE
#define COAP_SESSION_STATE_CSM
#define COAP_SESSION_TYPE_HELLO
server-side ephemeral session for responding to a client hello
#define COAP_PROTO_NOT_RELIABLE(p)
#define COAP_SESSION_STATE_CONNECTING
#define COAP_PROTO_RELIABLE(p)
#define COAP_SESSION_STATE_NONE
coap_session_state_t values
#define COAP_SESSION_STATE_ESTABLISHED
#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_write_block_opt(coap_block_t *block, uint16_t type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu.
#define COAP_MAX_BLOCK_SZX
The largest value for the SZX component in a Block option.
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block)
Initializes block from pdu.
void coap_delete_cache_entry(coap_context_t *ctx, 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...
#define COAP_DEFAULT_NSTART
The number of simultaneous outstanding interactions that a client maintains to a given server.
int64_t coap_tick_diff_t
This data type is used to represent the difference between two clock_tick_t values.
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
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.
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 long seed)
Seeds the default random number generation function with the given seed.
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, coap_session_t *, coap_pdu_t *, coap_binary_t *, coap_string_t *, coap_pdu_t *)
Definition of message handler function.
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
#define COAP_PRINT_STATUS_ERROR
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.
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
struct coap_dtls_context_t * coap_dtls_new_context(struct coap_context_t *coap_context)
Creates a new DTLS context for the given coap_context.
@ COAP_DTLS_ROLE_SERVER
Internal function invoked for server.
#define COAP_DTLS_PKI_SETUP_VERSION
Latest PKI setup version.
int coap_dtls_is_supported(void)
Returns 1 if support for DTLS is enabled, or 0 otherwise.
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, unsigned int 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.
#define COAP_EVENT_DTLS_ERROR
unsigned int coap_event_t
Scalar type to represent different events, e.g.
#define COAP_EVENT_TCP_FAILED
#define COAP_EVENT_DTLS_CONNECTED
#define COAP_EVENT_TCP_CONNECTED
TCP events for COAP_PROTO_TCP and COAP_PROTO_TLS.
coap_log_t coap_get_log_level(void)
Get the current logging level.
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
const char * coap_session_str(const coap_session_t *session)
Get session description.
const char * coap_endpoint_str(const coap_endpoint_t *endpoint)
Get endpoint description.
#define coap_log(level,...)
Logging function.
int coap_delete_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
Removes any subscription for observer from resource and releases the allocated storage.
coap_subscription_t * coap_add_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token, coap_string_t *query, int has_block2, coap_block_t block2, uint8_t code)
Adds the specified peer as observer for resource.
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe relationship for (sender ad...
#define COAP_OBSERVE_ESTABLISH
The value COAP_OBSERVE_ESTABLISH in a GET request indicates a new observe relationship for (sender ad...
void coap_touch_observer(coap_context_t *context, coap_session_t *session, const coap_binary_t *token)
Flags that data is ready to be sent to observers.
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
int coap_option_filter_set(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding entry for type in filter.
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
int coap_option_filter_get(coap_opt_filter_t filter, uint16_t type)
Checks if type is contained in filter.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
int coap_option_filter_unset(coap_opt_filter_t filter, uint16_t type)
Clears the corresponding entry for type in filter.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
COAP_STATIC_INLINE void coap_option_filter_clear(coap_opt_filter_t f)
Clears filter f.
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.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
coap_opt_t * coap_check_option(coap_pdu_t *pdu, uint16_t type, coap_opt_iterator_t *oi)
Retrieves the first option of type type from pdu.
#define COAP_SET_STR(st, l, v)
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
int coap_socket_connect_tcp1(coap_socket_t *sock, const coap_address_t *local_if, const coap_address_t *server, int default_port, coap_address_t *local_addr, coap_address_t *remote_addr)
Create a new TCP socket and initiate the connection.
int coap_socket_connect_tcp2(coap_socket_t *sock, coap_address_t *local_addr, coap_address_t *remote_addr)
Complete the TCP Connection.
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
#define COAP_STATIC_INLINE
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.
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
void coap_memory_init(void)
Initializes libcoap's memory management.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
#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)
unsigned int coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now)
Set sendqueue_basetime in the given context object ctx to now.
COAP_STATIC_INLINE int token_match(const uint8_t *a, size_t alen, const uint8_t *b, size_t blen)
respond_t
Internal flags to control the treatment of responses (specifically in presence of the No-Response opt...
static void handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
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_delete_all(coap_queue_t *queue)
Removes all items from given queue and frees the allocated storage.
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_context_get_coap_fd(coap_context_t *context)
Get the libcoap internal file descriptor for using in an application's select() or returned as an eve...
static coap_str_const_t coap_default_uri_wellknown
int coap_delete_node(coap_queue_t *node)
Destroys specified node.
static int coap_read_endpoint(coap_context_t *ctx, coap_endpoint_t *endpoint, coap_tick_t now)
coap_queue_t * coap_new_node(void)
Creates a new node suitable for adding to the CoAP sendqueue.
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, coap_tid_t id, coap_queue_t **node)
This function removes the element with given id from the list given list.
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
void coap_free_context(coap_context_t *context)
CoAP stack context must be released with coap_free_context().
COAP_STATIC_INLINE size_t get_wkc_len(coap_context_t *context, coap_opt_t *query_filter)
Quick hack to determine the size of the resource description for .well-known/core.
#define MAX_BITS
The maximum number of bits for fixed point integers that are used for retransmission time calculation...
static size_t coap_get_session_client_psk(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len)
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.
#define ACK_TIMEOUT
creates a Qx.FRAC_BITS from session's 'ack_timeout'
int coap_context_set_pki(coap_context_t *ctx, const coap_dtls_pki_t *setup_data)
Set the context's default PKI information for a server.
#define SZX_TO_BYTES(SZX)
static size_t coap_get_context_server_psk(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len)
coap_pdu_t * coap_wellknown_response(coap_context_t *context, coap_session_t *session, coap_pdu_t *request)
Creates a new response for given request with the contents of .well-known/core.
coap_tid_t coap_send_message_type(coap_session_t *session, coap_pdu_t *request, unsigned char type)
Helper funktion to create and send a message with type (usually ACK or RST).
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_accept_endpoint(coap_context_t *ctx, coap_endpoint_t *endpoint, coap_tick_t now)
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_tid_t coap_wait_ack(coap_context_t *context, coap_session_t *session, coap_queue_t *node)
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node)
Adds node to given queue, ordered by variable t in node.
static size_t coap_get_context_server_hint(const coap_session_t *session, uint8_t *hint, size_t max_hint_len)
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',...
static int coap_write_endpoint(coap_context_t *ctx, coap_endpoint_t *endpoint, coap_tick_t now)
static int coap_handle_dgram_for_proto(coap_context_t *ctx, coap_session_t *session, coap_packet_t *packet)
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.
static void coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
coap_queue_t * coap_find_transaction(coap_queue_t *queue, coap_session_t *session, coap_tid_t id)
Retrieves transaction from the queue.
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
int coap_option_check_critical(coap_context_t *ctx, coap_pdu_t *pdu, coap_opt_filter_t unknown)
Verifies that pdu contains no unknown critical options.
static void coap_connect_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
COAP_STATIC_INLINE void coap_free_node(coap_queue_t *node)
static enum respond_t no_response(coap_pdu_t *request, coap_pdu_t *response)
Checks for No-Response option in given request and returns 1 if response should be suppressed accordi...
int coap_context_set_psk(coap_context_t *ctx, const char *hint, const uint8_t *key, size_t key_len)
Set the context's default PSK hint and/or key for a server.
void coap_set_app_data(coap_context_t *ctx, void *app_data)
Stores data with the given CoAP context.
ssize_t coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu)
Send a pdu according to the session's protocol.
coap_tid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, const uint8_t *token, size_t token_length)
Cancels all outstanding messages for session session that have the specified token.
coap_tid_t coap_send_error(coap_session_t *session, coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
Sends an error response with code code for request request to dst.
#define SHR_FP(val, frac)
coap_pdu_t * coap_new_error_response(coap_pdu_t *request, unsigned char code, coap_opt_filter_t opts)
Creates a new ACK PDU with specified error code.
coap_tid_t coap_send_ack(coap_session_t *session, coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
int coap_context_set_psk2(coap_context_t *ctx, 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)
Returns any application-specific data that has been stored with context using the function coap_set_a...
static void handle_signaling(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu)
void coap_context_set_keepalive(coap_context_t *context, unsigned int seconds)
Set the context keepalive timer for sessions.
static void coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
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_join_mcast_group(coap_context_t *ctx, const char *group_name)
Function interface for joining a multicast group for listening.
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.
#define ACK_RANDOM_FACTOR
creates a Qx.FRAC_BITS from session's 'ack_random_factor'
COAP_STATIC_INLINE coap_queue_t * coap_malloc_node(void)
static void handle_response(coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd)
COAP_STATIC_INLINE coap_tid_t coap_send_rst(coap_session_t *session, coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
int coap_update_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Updates existing first option of given type in the pdu with the new data.
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
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.
coap_pdu_t * coap_pdu_init(uint8_t type, uint8_t code, uint16_t tid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
size_t coap_add_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Adds option of given type to pdu that is passed as first parameter.
int coap_pdu_parse_opt(coap_pdu_t *pdu)
Verify consistency in the given CoAP PDU structure and locate the data.
uint8_t * coap_add_data_after(coap_pdu_t *pdu, size_t len)
Adds given data to the pdu that is passed as first parameter but does not copy it.
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the 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.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
size_t coap_insert_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Inserts option of given type in the pdu with the appropriate data.
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.
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.
#define COAP_PDU_IS_RESPONSE(pdu)
#define COAP_OPTION_HOP_LIMIT
#define COAP_OPTION_NORESPONSE
#define COAP_OPTION_URI_HOST
#define COAP_OPTION_IF_MATCH
#define COAP_OPTION_BLOCK2
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_SIZE2
#define COAP_OPTION_BLOCK1
#define COAP_OPTION_PROXY_SCHEME
#define COAP_DEFAULT_PORT
#define COAP_SIGNALING_PONG
#define COAP_OPTION_URI_QUERY
#define COAP_DROPPED_RESPONSE
Indicates that a response is suppressed.
#define COAP_OPTION_IF_NONE_MATCH
#define COAP_OPTION_URI_PATH
#define COAP_SIGNALING_CSM
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
#define COAP_PDU_IS_EMPTY(pdu)
#define COAP_DEFAULT_MAX_PDU_RX_SIZE
#define COAP_PDU_IS_SIGNALING(pdu)
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER
#define COAP_OPTION_CONTENT_TYPE
#define COAP_SIGNALING_OPTION_CUSTODY
#define COAPS_DEFAULT_PORT
#define COAP_OPTION_URI_PORT
int coap_tid_t
coap_tid_t is used to store CoAP transaction id, i.e.
#define COAP_OPTION_ACCEPT
#define COAP_SIGNALING_RELEASE
#define COAP_OPTION_PROXY_URI
#define COAP_SIGNALING_PING
#define COAP_OPTION_OBSERVE
#define COAP_PDU_IS_REQUEST(pdu)
#define COAP_DEFAULT_URI_WELLKNOWN
well-known resources URI
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE
#define COAP_SIGNALING_ABORT
#define COAP_INVALID_TID
Indicates an invalid transaction id.
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.
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
void coap_handle_failed_notify(coap_context_t *context, coap_session_t *session, const coap_binary_t *token)
coap_print_status_t coap_print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen, size_t offset, coap_opt_t *query_filter)
Prints the names of all known resources to buf.
#define COAP_RESOURCE_CHECK_TIME
The interval in seconds to check if resources have changed.
#define RESOURCES_ITER(r, tmp)
coap_address_t remote
remote address and port
coap_address_t local
local address and port
multi-purpose address abstraction
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.
unsigned int num
block number
unsigned int szx
block size
unsigned int m
1 if more blocks follow, 0 otherwise
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
ssize_t(* network_read)(coap_socket_t *sock, struct coap_packet_t *packet)
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
void * app
application-specific data
struct coap_resource_t * unknown_resource
can be used for handling unknown resources
coap_session_t * sessions
client sessions
coap_nack_handler_t nack_handler
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
size_t(* get_server_psk)(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len)
ssize_t(* network_send)(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
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
size_t cache_ignore_count
The number of CoAP options to ignore when creating a cache-key.
coap_response_handler_t response_handler
struct coap_resource_t * resources
hash table or list of known resources
coap_cache_entry_t * cache
CoAP cache-entry cache.
coap_endpoint_t * endpoint
the endpoints used for listening
size_t(* get_server_hint)(const coap_session_t *session, uint8_t *hint, size_t max_hint_len)
coap_event_handler_t handle_event
Callback function that is used to signal events to the application.
size_t(* get_client_psk)(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len)
coap_dtls_spsk_t spsk_setup_data
Contains the initial PSK server setup data.
struct coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
The structure that holds the Client PSK information.
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 that holds the Server Pre-Shared Key and Identity Hint information.
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.
struct coap_context_t * context
endpoint's context
struct 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
Iterator to run through PDU options.
uint16_t type
decoded option type
coap_addr_tuple_t addr_info
local and remote addresses
unsigned char payload[COAP_RXBUFFER_SIZE]
payload
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
uint8_t * token
first byte of token, if any, or options
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
uint16_t tid
transaction id, if any, in regular host byte order
uint8_t code
request method (value 1–31) or response code (value 64-255)
uint8_t token_length
length of Token
uint8_t hdr_size
actual size used for protocol-specific header
uint8_t * data
first byte of payload, if any
size_t used_size
used bytes of storage for token, options and payload
size_t alloc_size
allocated storage for token, options and payload
coap_session_t * session
the CoAP session
coap_pdu_t * pdu
the CoAP PDU to send
unsigned int timeout
the randomized timeout value
struct coap_queue_t * next
coap_tick_t t
when to send PDU for the next time
coap_tid_t id
CoAP transaction id.
unsigned char retransmit_cnt
retransmission counter, will be removed when zero
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.
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)
coap_bin_const_t * psk_key
If client, this field contains the current pre-shared key for server; When this field is NULL,...
coap_endpoint_t * endpoint
session's endpoint
coap_socket_t sock
socket object for the session, if any
unsigned int max_retransmit
maximum re-transmit count (default 4)
coap_pdu_t * partial_pdu
incomplete incoming pdu
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 relationaship with peer
uint8_t read_header[8]
storage space for header of incoming message header
coap_addr_tuple_t addr_info
key: remote/local address info
coap_proto_t proto
protocol used
coap_bin_const_t * psk_hint
If client, this field contains the server provided identity hint.
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
struct coap_queue_t * delayqueue
list of delayed messages waiting to be sent
struct coap_context_t * context
session's context
size_t partial_read
if > 0 indicates number of bytes already read for an incoming message
void * tls
security parameters
uint8_t csm_block_supported
CSM TCP blocks supported.
uint8_t con_active
Active CON request sent.
coap_address_t local_if
optional local interface address
coap_session_type_t type
client or server side socket
coap_tid_t last_ping_mid
the last keepalive message id that was used in this session
size_t partial_write
if > 0 indicates number of bytes already written from the pdu at the head of sendqueue
coap_endpoint_t * endpoint
struct coap_session_t * session
coap_socket_flags_t flags
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
unsigned char token[8]
token used for subscription
size_t token_length
actual length of token
struct coap_session_t * session
subscriber session
uint16_t tid
request type code (GET/FETCH)
Representation of parsed URI.
coap_str_const_t host
host part of the URI
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
coap_string_t * coap_get_query(const coap_pdu_t *request)
#define HASH_ITER(hh, head, el, tmp)
#define LL_DELETE(head, del)
#define LL_FOREACH(head, el)
#define LL_FOREACH_SAFE(head, el, tmp)