libcoap  4.3.0
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-2013 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 
12 #ifndef COAP_IO_INTERNAL_H_
13 #define COAP_IO_INTERNAL_H_
14 
15 #include <sys/types.h>
16 
17 #include "address.h"
18 
19 #ifdef RIOT_VERSION
20 #include "net/gnrc.h"
21 #endif /* RIOT_VERSION */
22 
23 struct coap_socket_t {
24 #if defined(WITH_LWIP)
25  struct udp_pcb *pcb;
26 #elif defined(WITH_CONTIKI)
27  void *conn;
28 #else
30 #endif /* WITH_LWIP */
31 #if defined(RIOT_VERSION)
32  gnrc_pktsnip_t *pkt; /* pointer to received packet for processing */
33 #endif /* RIOT_VERSION */
35  coap_session_t *session; /* Used by the epoll logic for an active session. */
36  coap_endpoint_t *endpoint; /* Used by the epoll logic for a listening
37  endpoint. */
38 };
39 
43 #define COAP_SOCKET_EMPTY 0x0000
44 #define COAP_SOCKET_NOT_EMPTY 0x0001
45 #define COAP_SOCKET_BOUND 0x0002
46 #define COAP_SOCKET_CONNECTED 0x0004
47 #define COAP_SOCKET_WANT_READ 0x0010
48 #define COAP_SOCKET_WANT_WRITE 0x0020
49 #define COAP_SOCKET_WANT_ACCEPT 0x0040
50 #define COAP_SOCKET_WANT_CONNECT 0x0080
51 #define COAP_SOCKET_CAN_READ 0x0100
52 #define COAP_SOCKET_CAN_WRITE 0x0200
53 #define COAP_SOCKET_CAN_ACCEPT 0x0400
54 #define COAP_SOCKET_CAN_CONNECT 0x0800
55 #define COAP_SOCKET_MULTICAST 0x1000
59 
60 const char *coap_socket_format_errno(int error);
61 
62 int
64  const coap_address_t *local_if,
65  const coap_address_t *server,
66  int default_port,
67  coap_address_t *local_addr,
68  coap_address_t *remote_addr);
69 
70 int
72  const coap_address_t *listen_addr,
73  coap_address_t *bound_addr );
74 
76 
77 ssize_t
79  const uint8_t *data, size_t data_len );
80 
81 ssize_t
82 coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
83 
84 ssize_t
85 coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len);
86 
87 void
88 coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func);
89 
90 #ifdef WITH_LWIP
91 ssize_t
92 coap_socket_send_pdu( coap_socket_t *sock, coap_session_t *session,
93  coap_pdu_t *pdu );
94 #endif
95 
108 ssize_t coap_network_send( coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen );
109 
121 ssize_t coap_network_read( coap_socket_t *sock, coap_packet_t *packet );
122 
123 #ifndef coap_mcast_interface
124 # define coap_mcast_interface(Local) 0
125 #endif
126 
132  unsigned char **address,
133  size_t *length);
134 
135 #ifdef WITH_LWIP
140 struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
141 #endif
142 
143 #if defined(WITH_LWIP)
144 /*
145  * This is only included in coap_io.h instead of .c in order to be available for
146  * sizeof in lwippools.h.
147  * Simple carry-over of the incoming pbuf that is later turned into a node.
148  *
149  * Source address data is currently side-banded via ip_current_dest_addr & co
150  * as the packets have limited lifetime anyway.
151  */
152 struct coap_packet_t {
153  struct pbuf *pbuf;
154  const coap_endpoint_t *local_interface;
156  int ifindex;
157 // uint16_t srcport;
158 };
159 #else
162  int ifindex;
163  size_t length;
164  unsigned char payload[COAP_RXBUFFER_SIZE];
165 };
166 #endif
167 
168 #endif /* COAP_IO_INTERNAL_H_ */
Representation of network addresses.
uint16_t coap_socket_flags_t
Definition: coap_io.h:48
#define COAP_RXBUFFER_SIZE
Definition: coap_io.h:24
int coap_fd_t
Definition: coap_io.h:42
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)
Definition: coap_io.c:242
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
Definition: coap_io.c:478
void coap_socket_close(coap_socket_t *sock)
Definition: coap_io.c:368
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:1508
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:745
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
Definition: coap_io.c:427
ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
Definition: coap_io.c:752
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
Definition: coap_io.c:154
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:571
const char * coap_socket_format_errno(int error)
Definition: coap_io.c:1499
void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func)
void coap_mfree_endpoint(coap_endpoint_t *ep)
Definition: coap_io.c:149
coap_endpoint_t * coap_malloc_endpoint(void)
Definition: coap_io.c:144
multi-purpose address abstraction
Definition: address.h:96
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 token, if any, follows the fixed size header, then options until payload mark...
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