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);
215 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
217 "coap_socket_bind_udp: setsockopt SO_REUSEADDR: %s\n",
220 switch (listen_addr->
addr.
sa.sa_family) {
222 if (setsockopt(sock->
fd, IPPROTO_IP, GEN_IP_PKTINFO, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
224 "coap_socket_bind_udp: setsockopt IP_PKTINFO: %s\n",
229 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
231 "coap_socket_bind_udp: setsockopt IPV6_V6ONLY: %s\n",
233 if (setsockopt(sock->
fd, IPPROTO_IPV6, GEN_IPV6_PKTINFO, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
235 "coap_socket_bind_udp: setsockopt IPV6_PKTINFO: %s\n",
237 setsockopt(sock->
fd, IPPROTO_IP, GEN_IP_PKTINFO, OPTVAL_T(&on),
sizeof(on));
250 bound_addr->
size = (socklen_t)
sizeof(*bound_addr);
251 if (getsockname(sock->
fd, &bound_addr->
addr.
sa, &bound_addr->
size) < 0) {
253 "coap_socket_bind_udp: getsockname: %s\n",
280 sock->
fd = socket(server->
addr.
sa.sa_family, SOCK_STREAM, 0);
284 "coap_socket_connect_tcp1: socket: %s\n",
295 "coap_socket_connect_tcp1: ioctl FIONBIO: %s\n",
299 switch (server->
addr.
sa.sa_family) {
301 if (connect_addr.
addr.
sin.sin_port == 0)
302 connect_addr.
addr.
sin.sin_port = htons(default_port);
305 if (connect_addr.
addr.
sin6.sin6_port == 0)
306 connect_addr.
addr.
sin6.sin6_port = htons(default_port);
308 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
310 "coap_socket_connect_tcp1: setsockopt IPV6_V6ONLY: %s\n",
318 if (local_if && local_if->
addr.
sa.sa_family) {
320 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
322 "coap_socket_connect_tcp1: setsockopt SO_REUSEADDR: %s\n",
330 local_addr->
addr.
sa.sa_family = server->
addr.
sa.sa_family;
335 if (WSAGetLastError() == WSAEWOULDBLOCK) {
337 if (errno == EINPROGRESS) {
376 int optlen = (int)
sizeof( error );
378 socklen_t optlen = (socklen_t)
sizeof( error );
383 if (getsockopt(sock->
fd, SOL_SOCKET, SO_ERROR, OPTVAL_GT(&error),
391 "coap_socket_finish_connect_tcp: connect failed: %s\n",
419 sock->
fd = socket(listen_addr->
addr.
sa.sa_family, SOCK_STREAM, 0);
435 if (setsockopt (sock->
fd, SOL_SOCKET, SO_KEEPALIVE, OPTVAL_T(&on),
438 "coap_socket_bind_tcp: setsockopt SO_KEEPALIVE: %s\n",
441 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
444 "coap_socket_bind_tcp: setsockopt SO_REUSEADDR: %s\n",
447 switch (listen_addr->
addr.
sa.sa_family) {
452 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
454 "coap_socket_bind_tcp: setsockopt IPV6_V6ONLY: %s\n",
467 bound_addr->
size = (socklen_t)
sizeof(*bound_addr);
468 if (getsockname(sock->
fd, &bound_addr->
addr.
sa, &bound_addr->
size) < 0) {
500 new_client->
fd = accept(server->
fd, &remote_addr->
addr.
sa,
508 if (getsockname( new_client->
fd, &local_addr->
addr.
sa, &local_addr->
size) < 0)
540 sock->
fd = socket(connect_addr.
addr.
sa.sa_family, SOCK_DGRAM, 0);
557 switch (connect_addr.
addr.
sa.sa_family) {
559 if (connect_addr.
addr.
sin.sin_port == 0)
560 connect_addr.
addr.
sin.sin_port = htons(default_port);
563 if (connect_addr.
addr.
sin6.sin6_port == 0)
564 connect_addr.
addr.
sin6.sin6_port = htons(default_port);
566 if (setsockopt(sock->
fd, IPPROTO_IPV6, IPV6_V6ONLY, OPTVAL_T(&off),
sizeof(off)) ==
COAP_SOCKET_ERROR)
568 "coap_socket_connect_udp: setsockopt IPV6_V6ONLY: %s\n",
576 if (local_if && local_if->
addr.
sa.sa_family) {
577 if (setsockopt(sock->
fd, SOL_SOCKET, SO_REUSEADDR, OPTVAL_T(&on),
sizeof(on)) ==
COAP_SOCKET_ERROR)
579 "coap_socket_connect_udp: setsockopt SO_REUSEADDR: %s\n",
592 "coap_socket_connect_udp: getsockname for multicast socket: %s\n",
638 r = send(sock->
fd, (
const char *)data, (
int)data_len, 0);
640 r = send(sock->
fd, data, data_len, 0);
644 if (WSAGetLastError() == WSAEWOULDBLOCK) {
645 #elif EAGAIN != EWOULDBLOCK 646 if (errno==EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
648 if (errno==EAGAIN || errno == EINTR) {
657 if (r < (ssize_t)data_len)
670 r = recv(sock->
fd, (
char *)data, (
int)data_len, 0);
672 r = recv(sock->
fd, data, data_len, 0);
681 error = WSAGetLastError();
682 if (error == WSAEWOULDBLOCK) {
683 #elif EAGAIN != EWOULDBLOCK 684 if (errno==EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
686 if (errno==EAGAIN || errno == EINTR) {
691 if (error != WSAECONNRESET)
693 if (errno != ECONNRESET)
699 if (r < (ssize_t)data_len)
706 #if (!defined(WITH_CONTIKI)) != ( defined(HAVE_NETINET_IN_H) || defined(HAVE_WS2TCPIP_H) ) 717 struct in_addr ipi_spec_dst;
718 struct in_addr ipi_addr;
722 #if !defined(WITH_CONTIKI) && !defined(SOL_IP) 724 #define SOL_IP IPPROTO_IP 728 #define UNUSED_PARAM __attribute__ ((unused)) 735 static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
737 #define msghdr _WSAMSG 738 #define msg_name name 739 #define msg_namelen namelen 740 #define msg_iov lpBuffers 741 #define msg_iovlen dwBufferCount 742 #define msg_control Control.buf 743 #define msg_controllen Control.len 744 #define iovec _WSABUF 747 #define iov_len_t u_long 749 #define CMSG_DATA WSA_CMSG_DATA 750 #define ipi_spec_dst ipi_addr 752 #define iov_len_t size_t 757 ssize_t bytes_written = 0;
760 bytes_written = (ssize_t)datalen;
764 bytes_written = send(sock->
fd, (
const char *)data, (
int)datalen, 0);
766 bytes_written = send(sock->
fd, data, datalen, 0);
774 DWORD dwNumberOfBytesSent = 0;
783 memcpy (&iov[0].iov_base, &data,
sizeof (iov[0].iov_base));
786 memset( buf, 0,
sizeof(buf));
788 memset(&mhdr, 0,
sizeof(
struct msghdr));
789 memcpy (&mhdr.msg_name, &addr, sizeof (mhdr.msg_name));
798 struct cmsghdr *cmsg;
802 mhdr.msg_control = buf;
803 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
805 cmsg = CMSG_FIRSTHDR(&mhdr);
806 cmsg->cmsg_level =
SOL_IP;
807 cmsg->cmsg_type = IP_PKTINFO;
808 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
810 pktinfo = (
struct in_pktinfo *)CMSG_DATA(cmsg);
816 mhdr.msg_control = buf;
817 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in6_pktinfo));
819 cmsg = CMSG_FIRSTHDR(&mhdr);
820 cmsg->cmsg_level = IPPROTO_IPV6;
821 cmsg->cmsg_type = IPV6_PKTINFO;
822 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in6_pktinfo));
833 #if defined(IP_PKTINFO) 834 struct cmsghdr *cmsg;
837 mhdr.msg_control = buf;
838 mhdr.msg_controllen = CMSG_SPACE(
sizeof(
struct in_pktinfo));
840 cmsg = CMSG_FIRSTHDR(&mhdr);
841 cmsg->cmsg_level =
SOL_IP;
842 cmsg->cmsg_type = IP_PKTINFO;
843 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct in_pktinfo));
845 pktinfo = (
struct in_pktinfo *)CMSG_DATA(cmsg);
859 r = WSASendMsg(sock->
fd, &mhdr, 0 , &dwNumberOfBytesSent, NULL , NULL );
861 bytes_written = (ssize_t)dwNumberOfBytesSent;
865 bytes_written = sendmsg(sock->
fd, &mhdr, 0);
872 uip_udp_packet_sendto((
struct uip_udp_conn *)sock->conn, data, datalen,
874 bytes_written = datalen;
878 if (bytes_written < 0)
881 return bytes_written;
884 #define SIN6(A) ((struct sockaddr_in6 *)(A)) 920 if (WSAGetLastError() == WSAECONNRESET) {
922 if (errno == ECONNREFUSED) {
930 }
else if (len > 0) {
931 packet->
length = (size_t)len;
936 DWORD dwNumberOfBytesRecvd = 0;
939 #if !defined(WITH_CONTIKI) 945 iov[0].iov_base = packet->
payload;
948 memset(&mhdr, 0,
sizeof(
struct msghdr));
950 mhdr.msg_name = (
struct sockaddr*)&packet->
src.
addr;
951 mhdr.msg_namelen =
sizeof(packet->
src.
addr);
956 mhdr.msg_control = buf;
957 mhdr.msg_controllen =
sizeof(buf);
961 GUID wsaid = WSAID_WSARECVMSG;
962 DWORD cbBytesReturned = 0;
963 if (WSAIoctl(sock->
fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &wsaid,
sizeof(wsaid), &lpWSARecvMsg,
sizeof(lpWSARecvMsg), &cbBytesReturned, NULL, NULL) != 0) {
968 r = lpWSARecvMsg(sock->
fd, &mhdr, &dwNumberOfBytesRecvd, NULL , NULL );
970 len = (ssize_t)dwNumberOfBytesRecvd;
972 len = recvmsg(sock->
fd, &mhdr, 0);
977 if (WSAGetLastError() == WSAECONNRESET) {
979 if (errno == ECONNREFUSED) {
987 struct cmsghdr *cmsg;
989 packet->
src.
size = mhdr.msg_namelen;
990 packet->
length = (size_t)len;
994 for (cmsg = CMSG_FIRSTHDR(&mhdr); cmsg; cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
997 if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
1002 u.c = CMSG_DATA(cmsg);
1003 packet->
ifindex = (int)(u.p->ipi6_ifindex);
1004 memcpy(&packet->
dst.
addr.
sin6.sin6_addr, &u.p->ipi6_addr,
sizeof(
struct in6_addr));
1009 #if defined(IP_PKTINFO) 1010 if (cmsg->cmsg_level ==
SOL_IP && cmsg->cmsg_type == IP_PKTINFO) {
1015 u.c = CMSG_DATA(cmsg);
1016 packet->
ifindex = u.p->ipi_ifindex;
1017 if (packet->
dst.
addr.
sa.sa_family == AF_INET6) {
1018 memset(packet->
dst.
addr.
sin6.sin6_addr.s6_addr, 0, 10);
1019 packet->
dst.
addr.
sin6.sin6_addr.s6_addr[10] = 0xff;
1020 packet->
dst.
addr.
sin6.sin6_addr.s6_addr[11] = 0xff;
1021 memcpy(packet->
dst.
addr.
sin6.sin6_addr.s6_addr + 12, &u.p->ipi_addr,
sizeof(
struct in_addr));
1023 memcpy(&packet->
dst.
addr.
sin.sin_addr, &u.p->ipi_addr,
sizeof(
struct in_addr));
1027 #elif defined(IP_RECVDSTADDR) 1028 if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_RECVDSTADDR) {
1030 memcpy(&packet->
dst.
addr.
sin.sin_addr, CMSG_DATA(cmsg),
sizeof(
struct in_addr));
1039 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 1040 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLIPH_LEN]) 1042 if (uip_newdata()) {
1043 uip_ipaddr_copy(&packet->
src.
addr, &UIP_IP_BUF->srcipaddr);
1044 packet->
src.port = UIP_UDP_BUF->srcport;
1045 uip_ipaddr_copy(&(packet)->dst.addr, &UIP_IP_BUF->destipaddr);
1046 packet->
dst.port = UIP_UDP_BUF->destport;
1048 len = uip_datalen();
1056 ((
char *)uip_appdata)[len] = 0;
1059 #ifndef INET6_ADDRSTRLEN 1060 #define INET6_ADDRSTRLEN 40 1071 memcpy(&packet->
payload, uip_appdata, len);
1077 #ifndef WITH_CONTIKI 1083 #if !defined(WITH_CONTIKI) 1089 #if !defined(WITH_CONTIKI) 1094 unsigned int max_sockets,
1095 unsigned int *num_sockets,
1117 if (*num_sockets < max_sockets)
1118 sockets[(*num_sockets)++] = &ep->
sock;
1129 if (timeout == 0 || s_timeout < timeout)
1130 timeout = s_timeout;
1133 if (*num_sockets < max_sockets)
1134 sockets[(*num_sockets)++] = &s->
sock;
1161 if (timeout == 0 || s_timeout < timeout)
1162 timeout = s_timeout;
1182 if (timeout == 0 || s_timeout < timeout)
1183 timeout = s_timeout;
1187 if (*num_sockets < max_sockets)
1188 sockets[(*num_sockets)++] = &s->
sock;
1199 if (nextpdu && (timeout == 0 || nextpdu->
t - ( now - ctx->
sendqueue_basetime ) < timeout))
1205 if (tls_timeout > 0) {
1206 if (tls_timeout < now + COAP_TICKS_PER_SECOND / 10)
1207 tls_timeout = now + COAP_TICKS_PER_SECOND / 10;
1209 (
int)((tls_timeout - now) * 1000 / COAP_TICKS_PER_SECOND));
1210 if (timeout == 0 || tls_timeout - now < timeout)
1211 timeout = tls_timeout - now;
1219 while (tls_timeout > 0 && tls_timeout <= now) {
1230 if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
1231 timeout = tls_timeout - now;
1239 while (tls_timeout > 0 && tls_timeout <= now) {
1249 if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
1250 timeout = tls_timeout - now;
1256 return (
unsigned int)((timeout * 1000 + COAP_TICKS_PER_SECOND - 1) / COAP_TICKS_PER_SECOND);
1261 fd_set readfds, writefds, exceptfds;
1267 unsigned int num_sockets = 0, i, timeout;
1271 timeout =
coap_write(ctx, sockets, (
unsigned int)(
sizeof(sockets) /
sizeof(sockets[0])), &num_sockets, before);
1272 if (timeout == 0 || timeout_ms < timeout)
1273 timeout = timeout_ms;
1277 FD_ZERO(&exceptfds);
1278 for (i = 0; i < num_sockets; i++) {
1279 if (sockets[i]->fd + 1 > nfds)
1280 nfds = sockets[i]->
fd + 1;
1282 FD_SET(sockets[i]->fd, &readfds);
1284 FD_SET(sockets[i]->fd, &writefds);
1286 FD_SET(sockets[i]->fd, &readfds);
1288 FD_SET(sockets[i]->fd, &writefds);
1289 FD_SET(sockets[i]->fd, &exceptfds);
1293 if ( timeout > 0 ) {
1294 tv.tv_usec = (timeout % 1000) * 1000;
1295 tv.tv_sec = (long)(timeout / 1000);
1298 result = select(nfds, &readfds, &writefds, &exceptfds, timeout > 0 ? &tv : NULL);
1302 if (WSAGetLastError() != WSAEINVAL) {
1304 if (errno != EINTR) {
1312 for (i = 0; i < num_sockets; i++) {
1319 if ((sockets[i]->flags &
COAP_SOCKET_WANT_CONNECT) && (FD_ISSET(sockets[i]->fd, &writefds) || FD_ISSET(sockets[i]->fd, &exceptfds)))
1338 unsigned int max_sockets,
1339 unsigned int *num_sockets,
1349 static char szError[256];
1350 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)
1351 strcpy(szError,
"Unknown error");
1359 #ifndef WITH_CONTIKI 1361 return strerror(error);
1366 return strerror(errno);
1372 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
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)
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.