libcoap  4.1.2
coap_io.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_H_
11 #define _COAP_IO_H_
12 
13 #include <assert.h>
14 #include <sys/types.h>
15 
16 #include "address.h"
17 
18 #ifdef WITH_LWIP
19 # include <lwip/udp.h>
20 #endif
21 
25 typedef int coap_if_handle_t;
26 
28 #define COAP_IF_INVALID -1
29 
30 struct coap_packet_t;
32 
33 struct coap_context_t;
34 
39 typedef struct coap_endpoint_t {
40 #if defined(WITH_POSIX) || defined(WITH_CONTIKI)
41  union {
42  int fd;
43  void *conn;
44  } handle;
45 #endif /* WITH_POSIX or WITH_CONTIKI */
46 
47 #ifdef WITH_LWIP
48  struct udp_pcb *pcb;
51  struct coap_context_t *context;
52 #endif /* WITH_LWIP */
53 
55  int ifindex;
56  int flags;
58 
59 #define COAP_ENDPOINT_NOSEC 0x00
60 #define COAP_ENDPOINT_DTLS 0x01
61 
63 
65 
79 ssize_t coap_network_send(struct coap_context_t *context,
80  const coap_endpoint_t *local_interface,
81  const coap_address_t *dst,
82  unsigned char *data, size_t datalen);
83 
97 ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet);
98 
99 #ifndef coap_mcast_interface
100 # define coap_mcast_interface(Local) 0
101 #endif
102 
106 void coap_free_packet(coap_packet_t *packet);
107 
115  coap_endpoint_t *target);
116 
121 
127  unsigned char **address,
128  size_t *length);
129 
130 #ifdef WITH_LWIP
131 
135 struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
136 #endif
137 
138 #ifdef WITH_CONTIKI
139 /*
140  * This is only included in coap_io.h instead of .c in order to be available for
141  * sizeof in mem.c.
142  */
143 struct coap_packet_t {
144  coap_if_handle_t hnd;
145  coap_address_t src;
146  coap_address_t dst;
147  const coap_endpoint_t *interface;
148  int ifindex;
149  void *session;
150  size_t length;
151  unsigned char payload[];
152 };
153 #endif
154 
155 #ifdef WITH_LWIP
156 /*
157  * This is only included in coap_io.h instead of .c in order to be available for
158  * sizeof in lwippools.h.
159  * Simple carry-over of the incoming pbuf that is later turned into a node.
160  *
161  * Source address data is currently side-banded via ip_current_dest_addr & co
162  * as the packets have limited lifetime anyway.
163  */
164 struct coap_packet_t {
165  struct pbuf *pbuf;
166  const coap_endpoint_t *local_interface;
167  uint16_t srcport;
168 };
169 #endif
170 
171 #endif /* _COAP_IO_H_ */
void * conn
opaque connection (e.g.
Definition: coap_io.h:43
void coap_free_endpoint(coap_endpoint_t *ep)
Definition: coap_io.c:195
void coap_free_packet(coap_packet_t *packet)
Releases the storage allocated for packet.
Definition: coap_io.c:357
coap_address_t addr
local interface address
Definition: coap_io.h:54
multi-purpose address abstraction
Definition: address.h:57
void coap_packet_populate_endpoint(coap_packet_t *packet, coap_endpoint_t *target)
Populate the coap_endpoint_t *target from the incoming packet&#39;s destination data. ...
Definition: coap_io.c:379
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition: coap_io.h:39
ssize_t coap_network_send(struct coap_context_t *context, const coap_endpoint_t *local_interface, const coap_address_t *dst, unsigned char *data, size_t datalen)
Function interface for data transmission.
struct coap_endpoint_t coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
int fd
on POSIX systems
Definition: coap_io.h:42
coap_endpoint_t * coap_new_endpoint(const coap_address_t *addr, int flags)
Definition: coap_io.c:120
ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet)
Function interface for reading data.
Definition: coap_io.c:410
void coap_packet_copy_source(coap_packet_t *packet, coap_address_t *target)
Given an incoming packet, copy its source address into an address struct.
Definition: coap_io.c:387
Representation of network addresses.
union coap_endpoint_t::@1 handle
opaque handle to identify this endpoint
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&#39;s data in memory...
Definition: coap_io.c:392
int coap_if_handle_t
Abstract handle that is used to identify a local network interface.
Definition: coap_io.h:25
The CoAP stack&#39;s global state is stored in a coap_context_t object.
Definition: net.h:77