libcoap  4.3.1
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-2022 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"
21 #include <sys/types.h>
22 
23 #include "coap_address.h"
24 
25 #ifdef RIOT_VERSION
26 #include "net/gnrc.h"
27 #endif /* RIOT_VERSION */
28 
29 struct coap_socket_t {
30 #if defined(WITH_LWIP)
31  struct udp_pcb *pcb;
32 #elif defined(WITH_CONTIKI)
33  void *conn;
34 #else
36 #endif /* WITH_LWIP */
37 #if defined(RIOT_VERSION)
38  gnrc_pktsnip_t *pkt; /* pointer to received packet for processing */
39 #endif /* RIOT_VERSION */
41  coap_session_t *session; /* Used by the epoll logic for an active session. */
42  coap_endpoint_t *endpoint; /* Used by the epoll logic for a listening
43  endpoint. */
44 };
45 
49 #define COAP_SOCKET_EMPTY 0x0000
50 #define COAP_SOCKET_NOT_EMPTY 0x0001
51 #define COAP_SOCKET_BOUND 0x0002
52 #define COAP_SOCKET_CONNECTED 0x0004
53 #define COAP_SOCKET_WANT_READ 0x0010
54 #define COAP_SOCKET_WANT_WRITE 0x0020
55 #define COAP_SOCKET_WANT_ACCEPT 0x0040
56 #define COAP_SOCKET_WANT_CONNECT 0x0080
57 #define COAP_SOCKET_CAN_READ 0x0100
58 #define COAP_SOCKET_CAN_WRITE 0x0200
59 #define COAP_SOCKET_CAN_ACCEPT 0x0400
60 #define COAP_SOCKET_CAN_CONNECT 0x0800
61 #define COAP_SOCKET_MULTICAST 0x1000
63 #if COAP_SERVER_SUPPORT
66 #endif /* COAP_SERVER_SUPPORT */
67 
68 const char *coap_socket_format_errno(int error);
69 
70 #if COAP_CLIENT_SUPPORT
71 int
73  const coap_address_t *local_if,
74  const coap_address_t *server,
75  int default_port,
76  coap_address_t *local_addr,
77  coap_address_t *remote_addr);
78 #endif /* COAP_CLIENT_SUPPORT */
79 
80 int
82  const coap_address_t *listen_addr,
83  coap_address_t *bound_addr );
84 
86 
87 ssize_t
89  const uint8_t *data, size_t data_len );
90 
91 ssize_t
92 coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
93 
94 ssize_t
95 coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len);
96 
97 void
98 coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func);
99 
107 
108 #ifdef WITH_LWIP
109 ssize_t
110 coap_socket_send_pdu( coap_socket_t *sock, coap_session_t *session,
111  coap_pdu_t *pdu );
112 #endif
113 
126 ssize_t coap_network_send( coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen );
127 
139 ssize_t coap_network_read( coap_socket_t *sock, coap_packet_t *packet );
140 
141 #ifndef coap_mcast_interface
142 # define coap_mcast_interface(Local) 0
143 #endif
144 
150  unsigned char **address,
151  size_t *length);
152 
153 #ifdef WITH_LWIP
158 struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
159 #endif
160 
161 #if defined(WITH_LWIP)
162 /*
163  * This is only included in coap_io.h instead of .c in order to be available for
164  * sizeof in lwippools.h.
165  * Simple carry-over of the incoming pbuf that is later turned into a node.
166  *
167  * Source address data is currently side-banded via ip_current_dest_addr & co
168  * as the packets have limited lifetime anyway.
169  */
170 struct coap_packet_t {
171  struct pbuf *pbuf;
172  const coap_endpoint_t *local_interface;
174  int ifindex;
175 // uint16_t srcport;
176 };
177 #else
180  int ifindex;
181  size_t length;
182  unsigned char payload[COAP_RXBUFFER_SIZE];
183 };
184 #endif
185 
186 #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
#define COAP_RXBUFFER_SIZE
Definition: coap_io.h:29
int coap_fd_t
Definition: coap_io.h:47
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)
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
Definition: coap_io.c:537
void coap_socket_close(coap_socket_t *sock)
Definition: coap_io.c:377
ssize_t coap_socket_send(coap_socket_t *sock, coap_session_t *session, const uint8_t *data, size_t data_len)
Definition: coap_io.c:1610
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.
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:804
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
Definition: coap_io.c:483
ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
Definition: coap_io.c:811
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
Definition: coap_io.c:161
ssize_t coap_network_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:630
const char * coap_socket_format_errno(int error)
Definition: coap_io.c:1601
void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func)
void coap_mfree_endpoint(coap_endpoint_t *ep)
coap_endpoint_t * coap_malloc_endpoint(void)
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:127
multi-purpose address abstraction
Definition: coap_address.h:96
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[COAP_RXBUFFER_SIZE]
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_session_t * session
coap_endpoint_t * endpoint
coap_socket_flags_t flags