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 
21 typedef int coap_if_handle_t;
22 
24 #define COAP_IF_INVALID -1
25 
26 struct coap_packet_t;
28 
29 struct coap_context_t;
30 
35 typedef struct coap_endpoint_t {
36 #if defined(WITH_POSIX) || defined(WITH_CONTIKI)
37  union {
38  int fd;
39  void *conn;
40  } handle;
41 #endif /* WITH_POSIX or WITH_CONTIKI */
42 
43 #ifdef WITH_LWIP
44  struct udp_pcb *pcb;
47  struct coap_context_t *context;
48 #endif /* WITH_LWIP */
49 
51  int ifindex;
52  int flags;
54 
55 #define COAP_ENDPOINT_NOSEC 0x00
56 #define COAP_ENDPOINT_DTLS 0x01
57 
59 
61 
75 ssize_t coap_network_send(struct coap_context_t *context,
76  const coap_endpoint_t *local_interface,
77  const coap_address_t *dst,
78  unsigned char *data, size_t datalen);
79 
93 ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet);
94 
95 #ifndef coap_mcast_interface
96 # define coap_mcast_interface(Local) 0
97 #endif
98 
102 void coap_free_packet(coap_packet_t *packet);
103 
111  coap_endpoint_t *target);
112 
117 
123  unsigned char **address,
124  size_t *length);
125 
126 #ifdef WITH_LWIP
127 
131 struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
132 #endif
133 
134 #ifdef WITH_CONTIKI
135 /*
136  * This is only included in coap_io.h instead of .c in order to be available for
137  * sizeof in mem.c.
138  */
139 struct coap_packet_t {
140  coap_if_handle_t hnd;
141  coap_address_t src;
142  coap_address_t dst;
143  const coap_endpoint_t *interface;
144  int ifindex;
145  void *session;
146  size_t length;
147  unsigned char payload[];
148 };
149 #endif
150 
151 #ifdef WITH_LWIP
152 /*
153  * This is only included in coap_io.h instead of .c in order to be available for
154  * sizeof in lwippools.h.
155  * Simple carry-over of the incoming pbuf that is later turned into a node.
156  *
157  * Source address data is currently side-banded via ip_current_dest_addr & co
158  * as the packets have limited lifetime anyway.
159  */
160 struct coap_packet_t {
161  struct pbuf *pbuf;
162  const coap_endpoint_t *local_interface;
163  uint16_t srcport;
164 };
165 #endif
166 
167 #endif /* _COAP_IO_H_ */
void * conn
opaque connection (e.g.
Definition: coap_io.h:39
void coap_free_endpoint(coap_endpoint_t *ep)
Definition: coap_io.c:208
void coap_free_packet(coap_packet_t *packet)
Releases the storage allocated for packet.
Definition: coap_io.c:372
coap_address_t addr
local interface address
Definition: coap_io.h:50
multi-purpose address abstraction
Definition: address.h:59
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:394
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition: coap_io.h:35
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:38
coap_endpoint_t * coap_new_endpoint(const coap_address_t *addr, int flags)
Definition: coap_io.c:138
ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet)
Function interface for reading data.
Definition: coap_io.c:425
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:402
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:407
int coap_if_handle_t
Abstract handle that is used to identify a local network interface.
Definition: coap_io.h:21
The CoAP stack&#39;s global state is stored in a coap_context_t object.
Definition: net.h:76