coap_io.h
Go to the documentation of this file.
/*
* coap_io.h -- Default network I/O functions for libcoap
*
* Copyright (C) 2012-2013 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef _COAP_IO_H_
#define _COAP_IO_H_
#include <assert.h>
#include <sys/types.h>
#include "address.h"
typedef int coap_if_handle_t;
#define COAP_IF_INVALID -1
struct coap_packet_t;
typedef struct coap_packet_t coap_packet_t;
struct coap_context_t;
typedef struct coap_endpoint_t {
#if defined(WITH_POSIX) || defined(WITH_CONTIKI)
union {
int fd;
void *conn;
} handle;
#endif /* WITH_POSIX or WITH_CONTIKI */
#ifdef WITH_LWIP
struct udp_pcb *pcb;
struct coap_context_t *context;
#endif /* WITH_LWIP */
coap_address_t addr;
int ifindex;
int flags;
} coap_endpoint_t;
#define COAP_ENDPOINT_NOSEC 0x00
#define COAP_ENDPOINT_DTLS 0x01
coap_endpoint_t *coap_new_endpoint(const coap_address_t *addr, int flags);
void coap_free_endpoint(coap_endpoint_t *ep);
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);
ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet);
#ifndef coap_mcast_interface
# define coap_mcast_interface(Local) 0
#endif
void coap_free_packet(coap_packet_t *packet);
void coap_packet_populate_endpoint(coap_packet_t *packet,
coap_endpoint_t *target);
void coap_packet_copy_source(coap_packet_t *packet, coap_address_t *target);
void coap_packet_get_memmapped(coap_packet_t *packet,
unsigned char **address,
size_t *length);
#ifdef WITH_LWIP
struct pbuf *coap_packet_extract_pbuf(coap_packet_t *packet);
#endif
#ifdef WITH_CONTIKI
/*
* This is only included in coap_io.h instead of .c in order to be available for
* sizeof in mem.c.
*/
struct coap_packet_t {
coap_if_handle_t hnd;
coap_address_t src;
coap_address_t dst;
const coap_endpoint_t *interface;
int ifindex;
void *session;
size_t length;
unsigned char payload[];
};
#endif
#ifdef WITH_LWIP
/*
* This is only included in coap_io.h instead of .c in order to be available for
* sizeof in lwippools.h.
* Simple carry-over of the incoming pbuf that is later turned into a node.
*
* Source address data is currently side-banded via ip_current_dest_addr & co
* as the packets have limited lifetime anyway.
*/
struct coap_packet_t {
struct pbuf *pbuf;
const coap_endpoint_t *local_interface;
uint16_t srcport;
};
#endif
#endif /* _COAP_IO_H_ */
coap_endpoint_t::conn
void * conn
opaque connection (e.g.
Definition: coap_io.h:39
coap_free_endpoint
void coap_free_endpoint(coap_endpoint_t *ep)
Definition: coap_io.c:208
coap_free_packet
void coap_free_packet(coap_packet_t *packet)
Releases the storage allocated for packet.
Definition: coap_io.c:372
coap_endpoint_t::addr
coap_address_t addr
local interface address
Definition: coap_io.h:50
coap_address_t
multi-purpose address abstraction
Definition: address.h:59
coap_packet_populate_endpoint
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
coap_packet_t
Definition: coap_io.c:59
coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
Definition: coap_io.h:35
coap_network_send
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.
coap_endpoint_t
struct coap_endpoint_t coap_endpoint_t
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_endpoint_t::fd
int fd
on POSIX systems
Definition: coap_io.h:38
coap_new_endpoint
coap_endpoint_t * coap_new_endpoint(const coap_address_t *addr, int flags)
Definition: coap_io.c:138
coap_network_read
ssize_t coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet)
Function interface for reading data.
Definition: coap_io.c:425
coap_packet_copy_source
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
address.h
Representation of network addresses.
coap_endpoint_t::ifindex
int ifindex
Definition: coap_io.h:51
coap_endpoint_t::handle
union coap_endpoint_t::@1 handle
opaque handle to identify this endpoint
coap_packet_get_memmapped
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
coap_if_handle_t
int coap_if_handle_t
Abstract handle that is used to identify a local network interface.
Definition: coap_io.h:21
coap_context_t
The CoAP stack&#39;s global state is stored in a coap_context_t object.
Definition: net.h:76
coap_endpoint_t::flags
int flags
Definition: coap_io.h:52