libcoap  4.3.0rc2
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  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
10 #ifndef COAP_IO_INTERNAL_H_
11 #define COAP_IO_INTERNAL_H_
12 
13 #include <sys/types.h>
14 
15 #include "address.h"
16 
17 #ifdef RIOT_VERSION
18 #include "net/gnrc.h"
19 #endif /* RIOT_VERSION */
20 
21 struct coap_socket_t {
22 #if defined(WITH_LWIP)
23  struct udp_pcb *pcb;
24 #elif defined(WITH_CONTIKI)
25  void *conn;
26 #else
28 #endif /* WITH_LWIP */
29 #if defined(RIOT_VERSION)
30  gnrc_pktsnip_t *pkt; /* pointer to received packet for processing */
31 #endif /* RIOT_VERSION */
33  coap_session_t *session; /* Used by the epoll logic for an active session. */
34  coap_endpoint_t *endpoint; /* Used by the epoll logic for a listening
35  endpoint. */
36 };
37 
41 #define COAP_SOCKET_EMPTY 0x0000
42 #define COAP_SOCKET_NOT_EMPTY 0x0001
43 #define COAP_SOCKET_BOUND 0x0002
44 #define COAP_SOCKET_CONNECTED 0x0004
45 #define COAP_SOCKET_WANT_READ 0x0010
46 #define COAP_SOCKET_WANT_WRITE 0x0020
47 #define COAP_SOCKET_WANT_ACCEPT 0x0040
48 #define COAP_SOCKET_WANT_CONNECT 0x0080
49 #define COAP_SOCKET_CAN_READ 0x0100
50 #define COAP_SOCKET_CAN_WRITE 0x0200
51 #define COAP_SOCKET_CAN_ACCEPT 0x0400
52 #define COAP_SOCKET_CAN_CONNECT 0x0800
53 #define COAP_SOCKET_MULTICAST 0x1000
57 
58 const char *coap_socket_format_errno(int error);
59 
60 int
62  const coap_address_t *local_if,
63  const coap_address_t *server,
64  int default_port,
65  coap_address_t *local_addr,
66  coap_address_t *remote_addr);
67 
68 int
70  const coap_address_t *listen_addr,
71  coap_address_t *bound_addr );
72 
74 
75 ssize_t
77  const uint8_t *data, size_t data_len );
78 
79 ssize_t
80 coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
81 
82 ssize_t
83 coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len);
84 
85 void
86 coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func);
87 
88 #ifdef WITH_LWIP
89 ssize_t
90 coap_socket_send_pdu( coap_socket_t *sock, coap_session_t *session,
91  coap_pdu_t *pdu );
92 #endif
93 
106 ssize_t coap_network_send( coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen );
107 
119 ssize_t coap_network_read( coap_socket_t *sock, coap_packet_t *packet );
120 
121 #ifndef coap_mcast_interface
122 # define coap_mcast_interface(Local) 0
123 #endif
124 
130  unsigned char **address,
131  size_t *length);
132 
133 #ifdef WITH_LWIP
138 struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
139 #endif
140 
141 #if defined(WITH_LWIP)
142 /*
143  * This is only included in coap_io.h instead of .c in order to be available for
144  * sizeof in lwippools.h.
145  * Simple carry-over of the incoming pbuf that is later turned into a node.
146  *
147  * Source address data is currently side-banded via ip_current_dest_addr & co
148  * as the packets have limited lifetime anyway.
149  */
150 struct coap_packet_t {
151  struct pbuf *pbuf;
152  const coap_endpoint_t *local_interface;
154  int ifindex;
155 // uint16_t srcport;
156 };
157 #else
160  int ifindex;
161  size_t length;
162  unsigned char payload[COAP_RXBUFFER_SIZE];
163 };
164 #endif
165 
166 #endif /* COAP_IO_INTERNAL_H_ */
Representation of network addresses.
uint16_t coap_socket_flags_t
Definition: coap_io.h:46
#define COAP_RXBUFFER_SIZE
Definition: coap_io.h:22
int coap_fd_t
Definition: coap_io.h:40
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:240
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
Definition: coap_io.c:476
void coap_socket_close(coap_socket_t *sock)
Definition: coap_io.c:366
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:1510
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:743
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
Definition: coap_io.c:425
ssize_t coap_network_read(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
Definition: coap_io.c:750
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
Definition: coap_io.c:152
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:569
const char * coap_socket_format_errno(int error)
Definition: coap_io.c:1501
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:147
coap_endpoint_t * coap_malloc_endpoint(void)
Definition: coap_io.c:142
multi-purpose address abstraction
Definition: address.h:94
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