libcoap 4.3.5-develop-19cef11
coap_io_internal.h
Go to the documentation of this file.
1/*
2 * coap_io.h -- Default network I/O functions for libcoap
3 *
4 * Copyright (C) 2012-2024 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_IO_INTERNAL_H_
18#define COAP_IO_INTERNAL_H_
19
20#include "coap_internal.h"
22#include <sys/types.h>
23
24#include "coap_address.h"
25
26#ifdef WITH_CONTIKI
27struct uip_udp_conn;
28#endif /* WITH_CONTIKI */
29
30#ifdef RIOT_VERSION
31#include "net/gnrc.h"
32#include "net/sock/udp.h"
33#if ! COAP_DISABLE_TCP
34#include "net/sock/tcp.h"
35#endif /* ! COAP_DISABLE_TCP */
36#endif /* RIOT_VERSION */
37
39#if defined(WITH_LWIP)
40 struct pbuf *p;
41 struct udp_pcb *udp_pcb;
42#if ! COAP_DISABLE_TCP
43 struct tcp_pcb *tcp_pcb;
44#endif /* ! COAP_DISABLE_TCP */
45
46#elif defined(WITH_CONTIKI)
47 struct uip_udp_conn *udp_conn;
48 coap_context_t *context;
49
50#elif defined(RIOT_VERSION)
51 sock_udp_t udp;
52#if ! COAP_DISABLE_TCP
53 sock_tcp_t tcp;
54#endif /* ! COAP_DISABLE_TCP */
56#else
58#endif /* ! WITH_LWIP && !WITH_CONTIKI && ! RIOT_VERSION */
61#if COAP_SERVER_SUPPORT
64#endif /* COAP_SERVER_SUPPORT */
65#if COAP_CLIENT_SUPPORT
67#endif /* COAP_CLIENT_SUPPORT */
69};
70
74#define COAP_SOCKET_EMPTY 0x0000
75#define COAP_SOCKET_NOT_EMPTY 0x0001
76#define COAP_SOCKET_BOUND 0x0002
77#define COAP_SOCKET_CONNECTED 0x0004
78#define COAP_SOCKET_WANT_READ 0x0010
79#define COAP_SOCKET_WANT_WRITE 0x0020
80#define COAP_SOCKET_WANT_ACCEPT 0x0040
81#define COAP_SOCKET_WANT_CONNECT 0x0080
82#define COAP_SOCKET_CAN_READ 0x0100
83#define COAP_SOCKET_CAN_WRITE 0x0200
84#define COAP_SOCKET_CAN_ACCEPT 0x0400
85#define COAP_SOCKET_CAN_CONNECT 0x0800
86#define COAP_SOCKET_MULTICAST 0x1000
88#if COAP_SERVER_SUPPORT
91#endif /* COAP_SERVER_SUPPORT */
92
93const char *coap_socket_format_errno(int error);
94
95#if COAP_CLIENT_SUPPORT
97 const coap_address_t *local_if,
98 const coap_address_t *server,
99 int default_port,
100 coap_address_t *local_addr,
101 coap_address_t *remote_addr);
102#endif /* COAP_CLIENT_SUPPORT */
103
104#if COAP_SERVER_SUPPORT
106 const coap_address_t *listen_addr,
107 coap_address_t *bound_addr);
108#endif /* COAP_SERVER_SUPPORT */
109
117
128ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
129
140ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len);
141
151void coap_epoll_ctl_add(coap_socket_t *sock, uint32_t events, const char *func);
152
162void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func);
163
172
173#ifdef WITH_LWIP
174ssize_t coap_socket_send_pdu(coap_socket_t *sock, coap_session_t *session,
175 coap_pdu_t *pdu);
176#endif
177
190ssize_t coap_socket_send(coap_socket_t *sock, coap_session_t *session,
191 const uint8_t *data, size_t datalen);
192
205ssize_t coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet);
206
207#ifndef coap_mcast_interface
208# define coap_mcast_interface(Local) 0
209#endif
210
216 unsigned char **address,
217 size_t *length);
218
219#ifdef WITH_LWIP
220void coap_io_process_timeout(void *arg);
221void coap_io_lwip_init(void);
222void coap_io_lwip_cleanup(void);
223#endif
224
228 size_t length;
229 unsigned char *payload;
230};
231
232#ifdef WITH_CONTIKI
233void coap_start_io_process(void);
234void coap_stop_io_process(void);
235#endif /* WITH_CONTIKI */
236
237#endif /* COAP_IO_INTERNAL_H_ */
Representation of network addresses.
Pulls together all the internal only header files.
uint16_t coap_socket_flags_t
Definition: coap_io.h:53
int coap_fd_t
Definition: coap_io.h:47
void coap_epoll_ctl_add(coap_socket_t *sock, uint32_t events, const char *func)
Epoll specific function to add the state of events that epoll is to track for the appropriate file de...
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)
const char * coap_socket_format_errno(int error)
Definition: coap_io.c:1896
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
Function interface for data stream receiving off a socket.
Definition: coap_io.c:677
void coap_socket_close(coap_socket_t *sock)
Function interface to close off a socket.
Definition: coap_io.c:375
ssize_t coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
Definition: coap_io.c:1021
ssize_t coap_socket_send(coap_socket_t *sock, coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for data transmission.
Definition: coap_io.c:824
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.
Definition: coap_io.c:1008
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
Function interface for data stream sending off a socket.
Definition: coap_io.c:618
void coap_update_io_timer(coap_context_t *context, coap_tick_t delay)
Update when to continue with I/O processing, unless packets come in in the meantime.
Definition: coap_io.c:504
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
coap_endpoint_t * coap_malloc_endpoint(void)
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 ...
void coap_mfree_endpoint(coap_endpoint_t *ep)
Internal layer I/O functions.
@ COAP_LAYER_LAST
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:143
Multi-purpose address abstraction.
Definition: coap_address.h:148
The CoAP stack's global state is stored in a coap_context_t object.
Abstraction of virtual endpoint that can be attached to coap_context_t.
size_t length
length of payload
coap_addr_tuple_t addr_info
local and remote addresses
unsigned char * payload
payload
int ifindex
the interface index
structure for CoAP PDUs
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
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