Loading...
Searching...
No Matches
coap_io_internal.h
Go to the documentation of this file.
/*
* coap_io.h -- Default network I/O functions for libcoap
*
* Copyright (C) 2012-2023 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_IO_INTERNAL_H_
#define COAP_IO_INTERNAL_H_
#include "coap_internal.h"
#include "coap_layers_internal.h"
#include <sys/types.h>
#include "coap_address.h"
#ifdef WITH_CONTIKI
struct uip_udp_conn;
#endif /* WITH_CONTIKI */
#ifdef RIOT_VERSION
#include "net/gnrc.h"
#endif /* RIOT_VERSION */
struct coap_socket_t {
#if defined(WITH_LWIP)
struct udp_pcb *pcb;
#elif defined(WITH_CONTIKI)
struct uip_udp_conn *udp_conn;
coap_context_t *context;
#else
coap_fd_t fd;
#endif /* WITH_LWIP */
#if defined(RIOT_VERSION)
gnrc_pktsnip_t *pkt;
#endif /* RIOT_VERSION */
coap_socket_flags_t flags;
coap_session_t *session;
#if COAP_SERVER_SUPPORT
coap_endpoint_t *endpoint;
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
coap_address_t mcast_addr;
#endif /* COAP_CLIENT_SUPPORT */
coap_layer_func_t lfunc[COAP_LAYER_LAST];
};
#define COAP_SOCKET_EMPTY 0x0000
#define COAP_SOCKET_NOT_EMPTY 0x0001
#define COAP_SOCKET_BOUND 0x0002
#define COAP_SOCKET_CONNECTED 0x0004
#define COAP_SOCKET_WANT_READ 0x0010
#define COAP_SOCKET_WANT_WRITE 0x0020
#define COAP_SOCKET_WANT_ACCEPT 0x0040
#define COAP_SOCKET_WANT_CONNECT 0x0080
#define COAP_SOCKET_CAN_READ 0x0100
#define COAP_SOCKET_CAN_WRITE 0x0200
#define COAP_SOCKET_CAN_ACCEPT 0x0400
#define COAP_SOCKET_CAN_CONNECT 0x0800
#define COAP_SOCKET_MULTICAST 0x1000
#if COAP_SERVER_SUPPORT
coap_endpoint_t *coap_malloc_endpoint(void);
void coap_mfree_endpoint(coap_endpoint_t *ep);
#endif /* COAP_SERVER_SUPPORT */
const char *coap_socket_format_errno(int error);
#if COAP_CLIENT_SUPPORT
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);
#endif /* COAP_CLIENT_SUPPORT */
int coap_socket_bind_udp(coap_socket_t *sock,
const coap_address_t *listen_addr,
coap_address_t *bound_addr);
void coap_socket_close(coap_socket_t *sock);
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len);
void coap_epoll_ctl_add(coap_socket_t *sock, uint32_t events, const char *func);
void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func);
void coap_update_epoll_timer(coap_context_t *context, coap_tick_t delay);
#ifdef WITH_LWIP
ssize_t coap_socket_send_pdu(coap_socket_t *sock, coap_session_t *session,
coap_pdu_t *pdu);
#endif
ssize_t coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
const uint8_t *data, size_t datalen);
ssize_t coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet);
#ifndef coap_mcast_interface
# define coap_mcast_interface(Local) 0
#endif
void coap_packet_get_memmapped(coap_packet_t *packet,
unsigned char **address,
size_t *length);
#ifdef WITH_LWIP
void coap_io_process_timeout(void *arg);
#endif
struct coap_packet_t {
coap_addr_tuple_t addr_info;
int ifindex;
size_t length;
unsigned char *payload;
};
#ifdef WITH_CONTIKI
void coap_start_io_process(void);
void coap_stop_io_process(void);
#endif /* WITH_CONTIKI */
#endif /* COAP_IO_INTERNAL_H_ */
coap_address.h
Representation of network addresses.
coap_internal.h
Pulls together all the internal only header files.
coap_socket_flags_t
uint16_t coap_socket_flags_t
Definition coap_io.h:53
coap_fd_t
int coap_fd_t
Definition coap_io.h:47
coap_epoll_ctl_add
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...
coap_socket_connect_udp
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)
coap_socket_format_errno
const char * coap_socket_format_errno(int error)
Definition coap_io.c:1764
coap_socket_read
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:692
coap_socket_close
void coap_socket_close(coap_socket_t *sock)
Function interface to close off a socket.
Definition coap_io.c:400
coap_socket_send
ssize_t coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for data transmission.
Definition coap_io.c:798
coap_socket_recv
ssize_t coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
Definition coap_io.c:991
coap_update_epoll_timer
void coap_update_epoll_timer(coap_context_t *context, coap_tick_t delay)
Update the epoll timer fd as to when it is to trigger.
coap_packet_get_memmapped
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:978
coap_socket_write
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:633
coap_socket_bind_udp
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
Definition coap_io.c:92
coap_malloc_endpoint
coap_endpoint_t * coap_malloc_endpoint(void)
coap_epoll_ctl_mod
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 ...
coap_mfree_endpoint
void coap_mfree_endpoint(coap_endpoint_t *ep)
coap_layers_internal.h
Internal layer I/O functions.
COAP_LAYER_LAST
@ COAP_LAYER_LAST
Definition coap_layers_internal.h:26
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:144
coap_addr_tuple_t
Definition coap_io.h:55
coap_address_t
Multi-purpose address abstraction.
Definition coap_address.h:109
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition coap_net_internal.h:49
coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition coap_session_internal.h:219
coap_layer_func_t
Definition coap_layers_internal.h:106
coap_packet_t
Definition coap_io_internal.h:207
coap_packet_t::length
size_t length
length of payload
Definition coap_io_internal.h:210
coap_packet_t::addr_info
coap_addr_tuple_t addr_info
local and remote addresses
Definition coap_io_internal.h:208
coap_packet_t::payload
unsigned char * payload
payload
Definition coap_io_internal.h:211
coap_packet_t::ifindex
int ifindex
the interface index
Definition coap_io_internal.h:209
coap_pdu_t
structure for CoAP PDUs
Definition coap_pdu_internal.h:119
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition coap_session_internal.h:68
coap_socket_t
Definition coap_io_internal.h:34
coap_socket_t::lfunc
coap_layer_func_t lfunc[COAP_LAYER_LAST]
Layer functions to use.
Definition coap_io_internal.h:55
coap_socket_t::session
coap_session_t * session
Used to determine session owner.
Definition coap_io_internal.h:47
coap_socket_t::endpoint
coap_endpoint_t * endpoint
Used by the epoll logic for a listening endpoint.
Definition coap_io_internal.h:49
coap_socket_t::fd
coap_fd_t fd
Definition coap_io_internal.h:41
coap_socket_t::mcast_addr
coap_address_t mcast_addr
remote address and port (multicast track)
Definition coap_io_internal.h:53
coap_socket_t::flags
coap_socket_flags_t flags
1 or more of COAP_SOCKET* flag values
Definition coap_io_internal.h:46