9 #include "coap_config.h" 15 #ifdef HAVE_SYS_SELECT_H 16 # include <sys/select.h> 18 #ifdef HAVE_SYS_SOCKET_H 19 # include <sys/socket.h> 20 # define OPTVAL_T(t) (t) 21 # define OPTVAL_GT(t) (t) 23 #ifdef HAVE_SYS_IOCTL_H 24 #include <sys/ioctl.h> 26 #ifdef HAVE_NETINET_IN_H 27 # include <netinet/in.h> 29 #ifdef HAVE_WS2TCPIP_H 31 # define OPTVAL_T(t) (const char*)(t) 32 # define OPTVAL_GT(t) (char*)(t) 34 # define CMSG_DATA WSA_CMSG_DATA 57 #if !defined(WITH_CONTIKI) 59 #if defined(IP_PKTINFO) 60 # define GEN_IP_PKTINFO IP_PKTINFO 61 #elif defined(IP_RECVDSTADDR) 62 # define GEN_IP_PKTINFO IP_RECVDSTADDR 64 # error "Need IP_PKTINFO or IP_RECVDSTADDR to request ancillary data from OS." 68 #ifdef IPV6_RECVPKTINFO 69 # define GEN_IPV6_PKTINFO IPV6_RECVPKTINFO 70 #elif defined(IPV6_PKTINFO) 71 # define GEN_IPV6_PKTINFO IPV6_PKTINFO 73 # error "Need IPV6_PKTINFO or IPV6_RECVPKTINFO to request ancillary data from OS." 80 static int ep_initialized = 0;
103 sock->conn = udp_new(NULL, 0, NULL);
111 uip_ipaddr_copy(&bound_addr->
addr, &listen_addr->
addr);
112 bound_addr->port = listen_addr->port;
113 udp_bind((
struct uip_udp_conn *)sock->conn, bound_addr->port);
171 uip_udp_remove((
struct uip_udp_conn *)sock->conn);
198 sock->
fd = socket(listen_addr->
addr.
sa.sa_family, SOCK_DGRAM, 0);
213 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
216 switch (listen_addr->
addr.
sa.sa_family) {
218 if (setsockopt(sock->
fd, IPPROTO_IP, GEN_IP_PKTINFO, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
223 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
225 if (setsockopt(sock->
fd, IPPROTO_IPV6, GEN_IPV6_PKTINFO, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
227 setsockopt(sock->
fd, IPPROTO_IP, GEN_IP_PKTINFO, OPTVAL_T(&on),
sizeof(on));
239 bound_addr->
size = (socklen_t)
sizeof(*bound_addr);
240 if (getsockname(sock->
fd, &bound_addr->
addr.
sa, &bound_addr->
size) < 0) {
267 sock->
fd = socket(server->
addr.
sa.sa_family, SOCK_STREAM, 0);
282 switch (server->
addr.
sa.sa_family) {
284 if (connect_addr.
addr.
sin.sin_port == 0)
285 connect_addr.
addr.
sin.sin_port = htons(default_port);
288 if (connect_addr.
addr.
sin6.sin6_port == 0)
289 connect_addr.
addr.
sin6.sin6_port = htons(default_port);
291 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
299 if (local_if && local_if->
addr.
sa.sa_family) {
301 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
308 local_addr->
addr.
sa.sa_family = server->
addr.
sa.sa_family;
313 if (WSAGetLastError() == WSAEWOULDBLOCK) {
315 if (errno == EINPROGRESS) {
351 int optlen = (int)
sizeof( error );
353 socklen_t optlen = (socklen_t)
sizeof( error );
358 if (getsockopt(sock->
fd, SOL_SOCKET, SO_ERROR, OPTVAL_GT(&error),
391 sock->
fd = socket(listen_addr->
addr.
sa.sa_family, SOCK_STREAM, 0);
406 if (setsockopt (sock->
fd, SOL_SOCKET, SO_KEEPALIVE, OPTVAL_T(&on),
409 "coap_socket_bind_tcp: setsockopt SO_KEEPALIVE: %s\n",
412 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
415 "coap_socket_bind_tcp: setsockopt SO_REUSEADDR: %s\n",
418 switch (listen_addr->
addr.
sa.sa_family) {
423 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
435 bound_addr->
size = (socklen_t)
sizeof(*bound_addr);
436 if (getsockname(sock->
fd, &bound_addr->
addr.
sa, &bound_addr->
size) < 0) {
466 new_client->
fd = accept(server->
fd, &remote_addr->
addr.
sa,
474 if (getsockname( new_client->
fd, &local_addr->
addr.
sa, &local_addr->
size) < 0)
505 sock->
fd = socket(connect_addr.
addr.
sa.sa_family, SOCK_DGRAM, 0);
520 switch (connect_addr.
addr.
sa.sa_family) {
522 if (connect_addr.
addr.
sin.sin_port == 0)
523 connect_addr.
addr.
sin.sin_port = htons(default_port);
526 if (connect_addr.
addr.
sin6.sin6_port == 0)
527 connect_addr.
addr.
sin6.sin6_port = htons(default_port);
529 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
537 if (local_if && local_if->
addr.
sa.sa_family) {
538 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
591 r = send(sock->
fd, (
const char *)data, (
int)data_len, 0);
593 r = send(sock->
fd, data, data_len, 0);
597 if (WSAGetLastError() == WSAEWOULDBLOCK) {
598 #elif EAGAIN != EWOULDBLOCK 599 if (errno==EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
601 if (errno==EAGAIN || errno == EINTR) {
609 if (r < (ssize_t)data_len)
622 r = recv(sock->
fd, (
char *)data, (
int)data_len, 0);
624 r = recv(sock->
fd, data, data_len, 0);
633 error = WSAGetLastError();
634 if (error == WSAEWOULDBLOCK) {
635 #elif EAGAIN != EWOULDBLOCK 636 if (errno==EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
638 if (errno==EAGAIN || errno == EINTR) {
643 if (error != WSAECONNRESET)
645 if (errno != ECONNRESET)
650 if (r < (ssize_t)data_len)
657 #if (!defined(WITH_CONTIKI)) != ( defined(HAVE_NETINET_IN_H) || defined(HAVE_WS2TCPIP_H) ) 668 struct in_addr ipi_spec_dst;
669 struct in_addr ipi_addr;
673 #if !defined(WITH_CONTIKI) && !defined(SOL_IP) 675 #define SOL_IP IPPROTO_IP 679 #define UNUSED_PARAM __attribute__ ((unused)) 686 static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
688 #define msghdr _WSAMSG 689 #define msg_name name 690 #define msg_namelen namelen 691 #define msg_iov lpBuffers 692 #define msg_iovlen dwBufferCount 693 #define msg_control Control.buf 694 #define msg_controllen Control.len 695 #define iovec _WSABUF 698 #define iov_len_t u_long 700 #define CMSG_DATA WSA_CMSG_DATA 701 #define ipi_spec_dst ipi_addr 703 #define iov_len_t size_t 708 ssize_t bytes_written = 0;
711 bytes_written = (ssize_t)datalen;
715 bytes_written = send(sock->
fd, (
const char *)data, (
int)datalen, 0);
717 bytes_written = send(sock->
fd, data, datalen, 0);
725 DWORD dwNumberOfBytesSent = 0;
734 memcpy (&iov[0].iov_base, &data,
sizeof (iov[0].iov_base));
737 memset( buf, 0,
sizeof(buf));
739 memset(&mhdr, 0,
sizeof(
struct msghdr));
740 memcpy (&mhdr.msg_name, &addr, sizeof (mhdr.msg_name));
749 struct cmsghdr *cmsg;
753 mhdr.msg_control = buf;
754 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
756 cmsg = CMSG_FIRSTHDR(&mhdr);
757 cmsg->cmsg_level =
SOL_IP;
758 cmsg->cmsg_type = IP_PKTINFO;
759 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
761 pktinfo = (
struct in_pktinfo *)CMSG_DATA(cmsg);
767 mhdr.msg_control = buf;
768 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in6_pktinfo));
770 cmsg = CMSG_FIRSTHDR(&mhdr);
771 cmsg->cmsg_level = IPPROTO_IPV6;
772 cmsg->cmsg_type = IPV6_PKTINFO;
773 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in6_pktinfo));
784 #if defined(IP_PKTINFO) 785 struct cmsghdr *cmsg;
788 mhdr.msg_control = buf;
789 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
791 cmsg = CMSG_FIRSTHDR(&mhdr);
792 cmsg->cmsg_level =
SOL_IP;
793 cmsg->cmsg_type = IP_PKTINFO;
794 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
796 pktinfo = (
struct in_pktinfo *)CMSG_DATA(cmsg);
810 r = WSASendMsg(sock->
fd, &mhdr, 0 , &dwNumberOfBytesSent, NULL , NULL );
812 bytes_written = (ssize_t)dwNumberOfBytesSent;
816 bytes_written = sendmsg(sock->
fd, &mhdr, 0);
823 uip_udp_packet_sendto((
struct uip_udp_conn *)sock->conn, data, datalen,
825 bytes_written = datalen;
829 if (bytes_written < 0)
832 return bytes_written;
835 #define SIN6(A) ((struct sockaddr_in6 *)(A)) 871 if (WSAGetLastError() == WSAECONNRESET) {
873 if (errno == ECONNREFUSED) {
881 }
else if (len > 0) {
882 packet->
length = (size_t)len;
887 DWORD dwNumberOfBytesRecvd = 0;
890 #if !defined(WITH_CONTIKI) 896 iov[0].iov_base = packet->
payload;
899 memset(&mhdr, 0,
sizeof(
struct msghdr));
901 mhdr.msg_name = (
struct sockaddr*)&packet->
src.
addr;
902 mhdr.msg_namelen =
sizeof(packet->
src.
addr);
907 mhdr.msg_control = buf;
908 mhdr.msg_controllen =
sizeof(buf);
912 GUID wsaid = WSAID_WSARECVMSG;
913 DWORD cbBytesReturned = 0;
914 if (WSAIoctl(sock->
fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &wsaid,
sizeof(wsaid), &lpWSARecvMsg,
sizeof(lpWSARecvMsg), &cbBytesReturned, NULL, NULL) != 0) {
919 r = lpWSARecvMsg(sock->
fd, &mhdr, &dwNumberOfBytesRecvd, NULL , NULL );
921 len = (ssize_t)dwNumberOfBytesRecvd;
923 len = recvmsg(sock->
fd, &mhdr, 0);
928 if (WSAGetLastError() == WSAECONNRESET) {
930 if (errno == ECONNREFUSED) {
938 struct cmsghdr *cmsg;
940 packet->
src.
size = mhdr.msg_namelen;
941 packet->
length = (size_t)len;
945 for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
948 if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
953 u.c = CMSG_DATA(cmsg);
954 packet->
ifindex = (int)(u.p->ipi6_ifindex);
955 memcpy(&packet->
dst.
addr.
sin6.sin6_addr, &u.p->ipi6_addr,
sizeof(
struct in6_addr));
960 #if defined(IP_PKTINFO) 961 if (cmsg->cmsg_level ==
SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
966 u.c = CMSG_DATA(cmsg);
967 packet->
ifindex = u.p->ipi_ifindex;
968 if (packet->
dst.
addr.
sa.sa_family == AF_INET6) {
969 memset(packet->
dst.
addr.
sin6.sin6_addr.s6_addr, 0, 10);
970 packet->
dst.
addr.
sin6.sin6_addr.s6_addr[10] = 0xff;
971 packet->
dst.
addr.
sin6.sin6_addr.s6_addr[11] = 0xff;
972 memcpy(packet->
dst.
addr.
sin6.sin6_addr.s6_addr + 12, &u.p->ipi_addr,
sizeof(
struct in_addr));
974 memcpy(&packet->
dst.
addr.
sin.sin_addr, &u.p->ipi_addr,
sizeof(
struct in_addr));
978 #elif defined(IP_RECVDSTADDR) 979 if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_RECVDSTADDR) {
981 memcpy(&packet->
dst.
addr.
sin.sin_addr, CMSG_DATA(cmsg),
sizeof(
struct in_addr));
990 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 991 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN]) 994 uip_ipaddr_copy(&packet->
src.
addr, &UIP_IP_BUF->srcipaddr);
995 packet->
src.port = UIP_UDP_BUF->srcport;
996 uip_ipaddr_copy(&(packet)->dst.addr, &UIP_IP_BUF->destipaddr);
997 packet->
dst.port = UIP_UDP_BUF->destport;
1003 warn(
"discarded oversized packet\n");
1007 ((
char *)uip_appdata)[len] = 0;
1010 #ifndef INET6_ADDRSTRLEN 1011 #define INET6_ADDRSTRLEN 40 1016 debug(
"received %zd bytes from %s\n", len, addr_str);
1022 memcpy(&packet->
payload, uip_appdata, len);
1028 #ifndef WITH_CONTIKI 1034 #if !defined(WITH_CONTIKI) 1040 #if !defined(WITH_CONTIKI) 1045 unsigned int max_sockets,
1046 unsigned int *num_sockets,
1068 if (*num_sockets < max_sockets)
1069 sockets[(*num_sockets)++] = &ep->
sock;
1080 if (timeout == 0 || s_timeout < timeout)
1081 timeout = s_timeout;
1084 if (*num_sockets < max_sockets)
1085 sockets[(*num_sockets)++] = &s->
sock;
1112 if (timeout == 0 || s_timeout < timeout)
1113 timeout = s_timeout;
1133 if (timeout == 0 || s_timeout < timeout)
1134 timeout = s_timeout;
1138 if (*num_sockets < max_sockets)
1139 sockets[(*num_sockets)++] = &s->
sock;
1150 if (nextpdu && (timeout == 0 || nextpdu->
t - ( now - ctx->
sendqueue_basetime ) < timeout))
1156 if (tls_timeout > 0) {
1157 if (tls_timeout < now + COAP_TICKS_PER_SECOND / 10)
1158 tls_timeout = now + COAP_TICKS_PER_SECOND / 10;
1159 debug(
"** DTLS global timeout set to %dms\n", (
int)((tls_timeout - now) * 1000 / COAP_TICKS_PER_SECOND));
1160 if (timeout == 0 || tls_timeout - now < timeout)
1161 timeout = tls_timeout - now;
1169 while (tls_timeout > 0 && tls_timeout <= now) {
1179 if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
1180 timeout = tls_timeout - now;
1188 while (tls_timeout > 0 && tls_timeout <= now) {
1198 if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
1199 timeout = tls_timeout - now;
1205 return (
unsigned int)((timeout * 1000 + COAP_TICKS_PER_SECOND - 1) / COAP_TICKS_PER_SECOND);
1210 fd_set readfds, writefds, exceptfds;
1216 unsigned int num_sockets = 0, i, timeout;
1220 timeout =
coap_write(ctx, sockets, (
unsigned int)(
sizeof(sockets) /
sizeof(sockets[0])), &num_sockets, before);
1221 if (timeout == 0 || timeout_ms < timeout)
1222 timeout = timeout_ms;
1226 FD_ZERO(&exceptfds);
1227 for (i = 0; i < num_sockets; i++) {
1228 if (sockets[i]->fd + 1 > nfds)
1229 nfds = sockets[i]->
fd + 1;
1231 FD_SET(sockets[i]->fd, &readfds);
1233 FD_SET(sockets[i]->fd, &writefds);
1235 FD_SET(sockets[i]->fd, &readfds);
1237 FD_SET(sockets[i]->fd, &writefds);
1238 FD_SET(sockets[i]->fd, &exceptfds);
1242 if ( timeout > 0 ) {
1243 tv.tv_usec = (timeout % 1000) * 1000;
1244 tv.tv_sec = (long)(timeout / 1000);
1247 result = select(nfds, &readfds, &writefds, &exceptfds, timeout > 0 ? &tv : NULL);
1251 if (WSAGetLastError() != WSAEINVAL) {
1253 if (errno != EINTR) {
1261 for (i = 0; i < num_sockets; i++) {
1268 if ((sockets[i]->flags &
COAP_SOCKET_WANT_CONNECT) && (FD_ISSET(sockets[i]->fd, &writefds) || FD_ISSET(sockets[i]->fd, &exceptfds)))
1287 unsigned int max_sockets,
1288 unsigned int *num_sockets,
1298 static char szError[256];
1299 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)szError, (DWORD)
sizeof(szError), NULL) == 0)
1300 strcpy(szError,
"Unknown error");
1308 #ifndef WITH_CONTIKI 1310 return strerror(error);
1315 return strerror(errno);
1321 const uint8_t *data,
size_t data_len) {
#define LL_FOREACH(head, el)
#define COAP_SOCKET_EMPTY
coap_socket_flags_t values
#define COAP_RXBUFFER_SIZE
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
#define COAP_SESSION_TYPE_CLIENT
coap_session_type_t values
void coap_socket_close(coap_socket_t *sock)
struct coap_context_t * context
session's context
void * tls
security parameters
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...
coap_session_t * sessions
list of active sessions
coap_endpoint_t * endpoint
the endpoints used for listening
#define COAP_SOCKET_CONNECTED
the socket is connected
multi-purpose address abstraction
ssize_t coap_socket_send(coap_socket_t *sock, coap_session_t *session, const uint8_t *data, size_t data_len)
#define COAP_SOCKET_MULTICAST
socket is used for multicast communication
unsigned ref
reference count from queues
void coap_free_endpoint(coap_endpoint_t *ep)
coap_tid_t coap_session_send_ping(coap_session_t *session)
Send a ping message for the session.
int ifindex
the interface index
int coap_socket_accept_tcp(coap_socket_t *server, coap_socket_t *new_client, coap_address_t *local_addr, coap_address_t *remote_addr)
size_t coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
COAP_STATIC_INLINE void coap_address_init(coap_address_t *addr)
Resets the given coap_address_t object addr to its default values.
#define COAP_SOCKET_ERROR
struct in_addr ipi_spec_dst
static const char * coap_socket_format_errno(int error)
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)
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
#define COAP_SOCKET_CAN_READ
non blocking socket can now read without blocking
#define COAP_INVALID_SOCKET
#define COAP_SOCKET_WANT_ACCEPT
non blocking server socket is waiting for accept
unsigned char payload[COAP_RXBUFFER_SIZE]
payload
ssize_t coap_network_send(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
#define COAP_SOCKET_CAN_ACCEPT
non blocking server socket can now accept without blocking
coap_session_t * coap_session_reference(coap_session_t *session)
Increment reference counter on a session.
coap_queue_t * coap_peek_next(coap_context_t *context)
Returns the next pdu to send without removing from sendqeue.
Abstraction of virtual endpoint that can be attached to coap_context_t.
const char * coap_session_str(const coap_session_t *session)
Get session description.
coap_address_t local_addr
local address and port
const char * coap_socket_strerror(void)
#define COAP_SESSION_STATE_ESTABLISHED
coap_tick_t sendqueue_basetime
The time stamp in the first element of the sendqeue is relative to sendqueue_basetime.
int coap_run_once(coap_context_t *ctx, unsigned timeout_ms)
struct coap_endpoint_t * coap_malloc_endpoint(void)
coap_tick_t t
when to send PDU for the next time
struct in6_addr ipi6_addr
unsigned int ping_timeout
Minimum inactivity time before sending a ping message.
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
#define COAP_INVALID_TID
Indicates an invalid transaction id.
coap_address_t remote_addr
remote address and port
coap_address_t src
the packet's source address
ssize_t(* network_send)(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
struct coap_queue_t * delayqueue
list of delayed messages waiting to be sent
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
coap_proto_t proto
protocol used
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
void coap_packet_set_addr(coap_packet_t *packet, const coap_address_t *src, const coap_address_t *dst)
int coap_socket_connect_tcp2(coap_socket_t *sock, coap_address_t *local_addr, coap_address_t *remote_addr)
void coap_session_free(coap_session_t *session)
coap_socket_t sock
socket object for the session, if any
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
coap_proto_t proto
protocol used on this interface
Generic resource handling.
coap_session_type_t type
client or server side socket
coap_session_state_t state
current state of relationaship with peer
#define COAP_SESSION_TYPE_SERVER
server-side
void coap_session_release(coap_session_t *session)
Decrement reference counter on a session.
#define COAP_DEFAULT_SESSION_TIMEOUT
int ifindex
interface index
COAP_STATIC_INLINE int coap_address_isany(const coap_address_t *a)
Checks if given address object a denotes the wildcard address.
Pre-defined constants that reflect defaults for CoAP.
coap_address_t dst
the packet's destination address
#define warn(...)
Obsoleted.
COAP_STATIC_INLINE void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
size_t length
length of payload
#define COAP_SOCKET_WANT_READ
non blocking socket is waiting for reading
#define LL_FOREACH_SAFE(head, el, tmp)
#define COAP_PROTO_RELIABLE(p)
#define debug(...)
Obsoleted.
unsigned int csm_timeout
Timeout for waiting for a CSM from the remote side.
void coap_read(coap_context_t *ctx, coap_tick_t now)
For applications with their own message loop, reads all data from the network.
#define COAP_SOCKET_WANT_CONNECT
non blocking client socket is waiting for connect
coap_tick_t coap_dtls_get_timeout(coap_session_t *session UNUSED)
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_dtls_handle_timeout(coap_session_t *session UNUSED)
coap_log_t coap_get_log_level(void)
Get the current logging level.
coap_socket_flags_t flags
#define COAP_SOCKET_CAN_WRITE
non blocking socket can now write without blocking
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
coap_session_t * sessions
client sessions
#define coap_log(level,...)
Logging function.
union coap_address_t::@0 addr
coap_socket_t sock
socket object for the interface, if any
unsigned int coap_write(coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
For applications with their own message loop, send all pending retransmits and return the list of soc...
unsigned int ipi6_ifindex
int coap_socket_connect_udp(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)
socklen_t size
size of addr
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast address.
#define COAP_SOCKET_CAN_CONNECT
non blocking client socket can now connect without blocking
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context UNUSED)
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
#define COAP_SESSION_STATE_NONE
coap_session_state_t values
coap_tid_t coap_retransmit(coap_context_t *context, coap_queue_t *node)
Handles retransmissions of confirmable messages.
coap_queue_t * coap_pop_next(coap_context_t *context)
Returns the next pdu to send and removes it from the sendqeue.
int coap_socket_bind_tcp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
void coap_mfree_endpoint(struct coap_endpoint_t *ep)
The CoAP stack's global state is stored in a coap_context_t object.
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
#define COAP_SESSION_STATE_CSM
#define COAP_SOCKET_WANT_WRITE
non blocking socket is waiting for writing
unsigned int session_timeout
Number of seconds of inactivity after which an unused session will be closed.