net: remove conn API
conn was deprecated in 38217347
. 3 Releases later and now that no module
is using it RIOT-internally anymore, I think it is time to say goodbye.
This commit is contained in:
parent
3897b75096
commit
13770361bb
36
Makefile.dep
36
Makefile.dep
|
@ -55,14 +55,6 @@ ifneq (,$(filter gnrc_%,$(filter-out gnrc_netapi gnrc_netreg gnrc_netif% gnrc_pk
|
|||
USEMODULE += gnrc
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_conn_%,$(USEMODULE)))
|
||||
USEMODULE += gnrc_conn
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_conn_udp,$(USEMODULE)))
|
||||
USEMODULE += gnrc_udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_sock_%,$(USEMODULE)))
|
||||
USEMODULE += gnrc_sock
|
||||
endif
|
||||
|
@ -412,18 +404,6 @@ ifneq (,$(filter lwip_udplite,$(USEMODULE)))
|
|||
USEMODULE += lwip_udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter lwip_conn_%,$(USEMODULE)))
|
||||
USEMODULE += lwip_conn
|
||||
endif
|
||||
|
||||
ifneq (,$(filter lwip_conn_ip,$(USEMODULE)))
|
||||
USEMODULE += lwip_raw
|
||||
endif
|
||||
|
||||
ifneq (,$(filter lwip_conn_udp,$(USEMODULE)))
|
||||
USEMODULE += lwip_udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter lwip_sock_%,$(USEMODULE)))
|
||||
USEMODULE += lwip_sock
|
||||
endif
|
||||
|
@ -495,22 +475,6 @@ ifneq (,$(filter oonf_common,$(USEMODULE)))
|
|||
USEMODULE += posix_sockets
|
||||
endif
|
||||
|
||||
ifneq (,$(filter %_conn_ip,$(USEMODULE)))
|
||||
USEMODULE += conn_ip
|
||||
endif
|
||||
|
||||
ifneq (,$(filter %_conn_tcp,$(USEMODULE)))
|
||||
USEMODULE += conn_tcp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter %_conn_udp,$(USEMODULE)))
|
||||
USEMODULE += conn_udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter conn_%,$(USEMODULE)))
|
||||
USEMODULE += conn
|
||||
endif
|
||||
|
||||
# if any log_* is used, also use LOG pseudomodule
|
||||
ifneq (,$(filter log_%,$(USEMODULE)))
|
||||
USEMODULE += log
|
||||
|
|
|
@ -46,7 +46,7 @@ void microcoap_server_loop(void)
|
|||
rc = sock_udp_recv(&sock, (char *)_udp_buf, sizeof(_udp_buf),
|
||||
SOCK_NO_TIMEOUT, &remote);
|
||||
if (rc < 0) {
|
||||
DEBUG("Error in conn_udp_recvfrom(). rc=%u\n", rc);
|
||||
DEBUG("Error in sock_udp_recv(). rc=%u\n", rc);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
PSEUDOMODULES += auto_init_gnrc_rpl
|
||||
PSEUDOMODULES += conn
|
||||
PSEUDOMODULES += conn_ip
|
||||
PSEUDOMODULES += conn_tcp
|
||||
PSEUDOMODULES += conn_udp
|
||||
PSEUDOMODULES += core_%
|
||||
PSEUDOMODULES += emb6_router
|
||||
PSEUDOMODULES += gnrc_ipv6_default
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
ifneq (,$(filter emb6_conn_udp,$(USEMODULE)))
|
||||
USEMODULE += emb6_sock
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_sock_%,$(USEMODULE)))
|
||||
USEMODULE += core_mbox
|
||||
USEMODULE += emb6_sock
|
||||
|
|
|
@ -22,10 +22,6 @@ ifneq (,$(filter emb6_contrib,$(USEMODULE)))
|
|||
DIRS += $(EMB6_CONTRIB)
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_conn_udp,$(USEMODULE)))
|
||||
DIRS += $(EMB6_CONTRIB)/conn/udp
|
||||
endif
|
||||
|
||||
ifneq (,$(filter emb6_ipv6,$(USEMODULE)))
|
||||
DIRS += $(EMB6_DIR)/emb6/src/net/ipv6
|
||||
INCLUDES += -I$(EMB6_DIR)/emb6/inc/net/ipv6
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
MODULE = emb6_conn_udp
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
|
@ -1,245 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "evproc.h"
|
||||
#include "msg.h"
|
||||
#include "mutex.h"
|
||||
#include "net/af.h"
|
||||
#include "net/conn/udp.h"
|
||||
#include "net/ipv6/hdr.h"
|
||||
#include "sched.h"
|
||||
#include "uip.h"
|
||||
|
||||
#define _MSG_TYPE_CLOSE (0x4123)
|
||||
#define _MSG_TYPE_RCV (0x4124)
|
||||
|
||||
/* struct to describe a sendto command for emb6 thread */
|
||||
typedef struct {
|
||||
struct udp_socket sock;
|
||||
mutex_t mutex;
|
||||
const void *data;
|
||||
int res;
|
||||
uint16_t data_len;
|
||||
} _send_cmd_t;
|
||||
|
||||
extern uint16_t uip_slen;
|
||||
|
||||
static bool send_registered = false;
|
||||
|
||||
static void _input_callback(struct udp_socket *c, void *ptr,
|
||||
const uip_ipaddr_t *src_addr, uint16_t src_port,
|
||||
const uip_ipaddr_t *dst_addr, uint16_t dst_port,
|
||||
const uint8_t *data, uint16_t datalen);
|
||||
static void _output_callback(c_event_t c_event, p_data_t p_data);
|
||||
|
||||
static int _reg_and_bind(struct udp_socket *c, void *ptr,
|
||||
udp_socket_input_callback_t cb, uint16_t port)
|
||||
{
|
||||
if (udp_socket_register(c, ptr, cb) < 0) {
|
||||
return -EMFILE;
|
||||
}
|
||||
if (udp_socket_bind(c, port) < 0) {
|
||||
udp_socket_close(c);
|
||||
return -EALREADY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len,
|
||||
int family, uint16_t port)
|
||||
{
|
||||
int res;
|
||||
|
||||
(void)addr;
|
||||
(void)addr_len;
|
||||
if (family != AF_INET6) {
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
mutex_init(&conn->mutex);
|
||||
mutex_lock(&conn->mutex);
|
||||
if ((res = _reg_and_bind(&conn->sock, conn, _input_callback, port)) < 0) {
|
||||
conn->sock.input_callback = NULL;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return res;
|
||||
}
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void conn_udp_close(conn_udp_t *conn)
|
||||
{
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
msg_t msg;
|
||||
msg.type = _MSG_TYPE_CLOSE;
|
||||
msg.content.ptr = conn;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_send(&msg, conn->waiting_thread);
|
||||
mutex_lock(&conn->mutex);
|
||||
}
|
||||
udp_socket_close(&conn->sock);
|
||||
conn->sock.input_callback = NULL;
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port)
|
||||
{
|
||||
if (conn->sock.input_callback != NULL) {
|
||||
mutex_lock(&conn->mutex);
|
||||
memset(addr, 0, sizeof(ipv6_addr_t));
|
||||
*port = ntohs(conn->sock.udp_conn->lport);
|
||||
mutex_unlock(&conn->mutex);
|
||||
return sizeof(ipv6_addr_t);
|
||||
}
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
int conn_udp_recvfrom(conn_udp_t *conn, void *data, size_t max_len, void *addr,
|
||||
size_t *addr_len, uint16_t *port)
|
||||
{
|
||||
int res = -EIO;
|
||||
msg_t msg;
|
||||
|
||||
if (conn->sock.input_callback == NULL) {
|
||||
return -ENOTSOCK;
|
||||
}
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
mutex_unlock(&conn->mutex);
|
||||
return -EALREADY;
|
||||
}
|
||||
conn->waiting_thread = sched_active_pid;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_receive(&msg);
|
||||
if (msg.type == _MSG_TYPE_CLOSE) {
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
return -EINTR;
|
||||
}
|
||||
else if (msg.type == _MSG_TYPE_RCV) {
|
||||
mutex_lock(&conn->mutex);
|
||||
if (msg.content.ptr == conn) {
|
||||
if (max_len < conn->recv_info.datalen) {
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memcpy(data, conn->recv_info.data, conn->recv_info.datalen);
|
||||
memcpy(addr, conn->recv_info.src, sizeof(ipv6_addr_t));
|
||||
*addr_len = sizeof(ipv6_addr_t);
|
||||
*port = conn->recv_info.src_port;
|
||||
res = (int)conn->recv_info.datalen;
|
||||
}
|
||||
conn->waiting_thread = KERNEL_PID_UNDEF;
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_len,
|
||||
const void *dst, size_t dst_len, int family, uint16_t sport,
|
||||
uint16_t dport)
|
||||
{
|
||||
int res;
|
||||
_send_cmd_t send_cmd;
|
||||
|
||||
if (!send_registered) {
|
||||
if (evproc_regCallback(EVENT_TYPE_CONN_SEND, _output_callback) != E_SUCCESS) {
|
||||
return -EIO;
|
||||
}
|
||||
else {
|
||||
send_registered = true;
|
||||
}
|
||||
}
|
||||
mutex_init(&send_cmd.mutex);
|
||||
if ((len > (UIP_BUFSIZE - (UIP_LLH_LEN + UIP_IPUDPH_LEN))) ||
|
||||
(len > UINT16_MAX)) {
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
if ((dst_len > sizeof(ipv6_addr_t)) || (family != AF_INET6)) {
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
mutex_lock(&send_cmd.mutex);
|
||||
send_cmd.data = data;
|
||||
send_cmd.data_len = (uint16_t)len;
|
||||
if ((res = _reg_and_bind(&send_cmd.sock, NULL, NULL, sport)) < 0) {
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
return res;
|
||||
}
|
||||
udp_socket_connect(&send_cmd.sock, (uip_ipaddr_t *)dst, dport); /* can't fail at this point */
|
||||
/* change to emb6 thread context */
|
||||
if (evproc_putEvent(E_EVPROC_TAIL, EVENT_TYPE_CONN_SEND, &send_cmd) != E_SUCCESS) {
|
||||
udp_socket_close(&send_cmd.sock);
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
return -EIO;
|
||||
}
|
||||
/* block thread until data was send */
|
||||
mutex_lock(&send_cmd.mutex);
|
||||
udp_socket_close(&send_cmd.sock);
|
||||
mutex_unlock(&send_cmd.mutex);
|
||||
|
||||
return send_cmd.res;
|
||||
}
|
||||
|
||||
static void _input_callback(struct udp_socket *c, void *ptr,
|
||||
const uip_ipaddr_t *src_addr, uint16_t src_port,
|
||||
const uip_ipaddr_t *dst_addr, uint16_t dst_port,
|
||||
const uint8_t *data, uint16_t datalen)
|
||||
{
|
||||
conn_udp_t *conn = ptr;
|
||||
|
||||
(void)dst_addr;
|
||||
(void)dst_port;
|
||||
mutex_lock(&conn->mutex);
|
||||
if (conn->waiting_thread != KERNEL_PID_UNDEF) {
|
||||
msg_t msg;
|
||||
conn->recv_info.src_port = src_port;
|
||||
conn->recv_info.src = (const ipv6_addr_t *)src_addr;
|
||||
conn->recv_info.data = data;
|
||||
conn->recv_info.datalen = datalen - sizeof(ipv6_hdr_t);
|
||||
msg.type = _MSG_TYPE_RCV;
|
||||
msg.content.ptr = conn;
|
||||
mutex_unlock(&conn->mutex);
|
||||
msg_send(&msg, conn->waiting_thread);
|
||||
}
|
||||
else {
|
||||
mutex_unlock(&conn->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static void _output_callback(c_event_t c_event, p_data_t p_data)
|
||||
{
|
||||
if ((c_event != EVENT_TYPE_CONN_SEND) || (p_data == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_send_cmd_t *send_cmd = (_send_cmd_t *)p_data;
|
||||
|
||||
if ((send_cmd->res = udp_socket_send(&send_cmd->sock, send_cmd->data, send_cmd->data_len)) < 0) {
|
||||
send_cmd->res = -EHOSTUNREACH;
|
||||
}
|
||||
mutex_unlock(&send_cmd->mutex);
|
||||
}
|
||||
|
||||
/** @} */
|
|
@ -213,7 +213,7 @@ int sock_udp_send(sock_udp_t *sock, const void *data, size_t len,
|
|||
/* we want the send in the uip thread (which udp_socket_send does not offer)
|
||||
* so we need to do it manually */
|
||||
if (!send_registered) {
|
||||
if (evproc_regCallback(EVENT_TYPE_CONN_SEND, _output_callback) != E_SUCCESS) {
|
||||
if (evproc_regCallback(EVENT_TYPE_SOCK_SEND, _output_callback) != E_SUCCESS) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
else {
|
||||
|
@ -253,7 +253,7 @@ int sock_udp_send(sock_udp_t *sock, const void *data, size_t len,
|
|||
}
|
||||
mutex_lock(&send_cmd.block);
|
||||
/* change to emb6 thread context */
|
||||
if (evproc_putEvent(E_EVPROC_TAIL, EVENT_TYPE_CONN_SEND, &send_cmd) == E_SUCCESS) {
|
||||
if (evproc_putEvent(E_EVPROC_TAIL, EVENT_TYPE_SOCK_SEND, &send_cmd) == E_SUCCESS) {
|
||||
/* block thread until data was sent */
|
||||
mutex_lock(&send_cmd.block);
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ static void _input_callback(struct udp_socket *c, void *ptr,
|
|||
static void _output_callback(c_event_t c_event, p_data_t p_data)
|
||||
{
|
||||
|
||||
if ((c_event != EVENT_TYPE_CONN_SEND) || (p_data == NULL)) {
|
||||
if ((c_event != EVENT_TYPE_SOCK_SEND) || (p_data == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup emb6_conn_udp udp_conn wrapper for emb6
|
||||
* @ingroup emb6
|
||||
* @brief UDP conn for emb6
|
||||
*
|
||||
* For this implementation to receive with an open connection only with one
|
||||
* thread at once. If you use @ref conn_udp_recvfrom() with more than one thread
|
||||
* simultaneously, it will return `-EALREADY`.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief UDP conn definitions
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef EMB6_CONN_UDP_H
|
||||
#define EMB6_CONN_UDP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "mutex.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
|
||||
#include "uip.h"
|
||||
#include "udp-socket.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief @ref net_conn_udp definition for emb6
|
||||
*/
|
||||
struct conn_udp {
|
||||
struct udp_socket sock; /**< emb6 internal socket */
|
||||
mutex_t mutex; /**< mutex for the connection */
|
||||
kernel_pid_t waiting_thread; /**< thread waiting for an incoming packet
|
||||
* on this connection */
|
||||
struct {
|
||||
uint16_t src_port; /**< source port */
|
||||
const ipv6_addr_t *src; /**< source address */
|
||||
const void *data; /**< data of received packet */
|
||||
size_t datalen; /**< length of received packet data */
|
||||
} recv_info; /**< info on received packet */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EMB6_CONN_UDP_H */
|
||||
/** @} */
|
|
@ -1,7 +1,7 @@
|
|||
From 6b0721c0d546652238c139f0d41790cb77996442 Mon Sep 17 00:00:00 2001
|
||||
From: Martine Lenders <mail@martine-lenders.eu>
|
||||
Date: Fri, 26 Feb 2016 12:35:52 +0100
|
||||
Subject: [PATCH 4/4] Provide event type for RIOT's conn_.*_send
|
||||
Subject: [PATCH 4/4] Provide event type for RIOT's sock_.*_send
|
||||
|
||||
---
|
||||
utils/inc/evproc.h | 4 +++-
|
||||
|
@ -15,7 +15,7 @@ index 5316a67..78153be 100644
|
|||
EVENT_TYPE_ICMP6, \
|
||||
EVENT_TYPE_TCPIP, \
|
||||
EVENT_TYPE_SLIP_POLL, \
|
||||
+ EVENT_TYPE_CONN_SEND, \
|
||||
+ EVENT_TYPE_SOCK_SEND, \
|
||||
EVENT_TYPE_PCK_LL }
|
||||
|
||||
#define EVENT_TYPE_NONE 0x00 ///< No event
|
||||
|
@ -23,7 +23,7 @@ index 5316a67..78153be 100644
|
|||
#define EVENT_TYPE_ICMP6 0x05 ///< New icmp6 packet event
|
||||
#define EVENT_TYPE_TCPIP 0x06 ///< New tcpip event
|
||||
#define EVENT_TYPE_SLIP_POLL 0x07 ///< Process slip handler
|
||||
+#define EVENT_TYPE_CONN_SEND 0x08 ///< Send command from conn layer
|
||||
+#define EVENT_TYPE_SOCK_SEND 0x08 ///< Send command from sock layer
|
||||
#define OBLIG_EVENT_PRIOR 0x0a
|
||||
#define EVENT_TYPE_PCK_LL 0x0a ///< New low level packet received
|
||||
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
INCLUDES += -I$(RIOTBASE)/pkg/lwip/include \
|
||||
-I$(PKGDIRBASE)/lwip/src/include
|
||||
|
||||
ifneq (,$(filter lwip_conn,$(USEMODULE)))
|
||||
DIRS += $(RIOTBASE)/pkg/lwip/contrib/conn
|
||||
endif
|
||||
ifneq (,$(filter lwip_conn_ip,$(USEMODULE)))
|
||||
DIRS += $(RIOTBASE)/pkg/lwip/contrib/conn/ip
|
||||
endif
|
||||
ifneq (,$(filter lwip_conn_udp,$(USEMODULE)))
|
||||
DIRS += $(RIOTBASE)/pkg/lwip/contrib/conn/udp
|
||||
endif
|
||||
ifneq (,$(filter lwip_contrib,$(USEMODULE)))
|
||||
DIRS += $(RIOTBASE)/pkg/lwip/contrib
|
||||
endif
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
MODULE := lwip_conn
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
|
@ -1,3 +0,0 @@
|
|||
MODULE := lwip_conn_ip
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "net/ipv4/addr.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "net/conn/ip.h"
|
||||
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/conn.h"
|
||||
|
||||
int conn_ip_create(conn_ip_t *conn, const void *addr, size_t addr_len, int family, int proto)
|
||||
{
|
||||
struct netconn *tmp;
|
||||
int res;
|
||||
|
||||
res = lwip_conn_create(&tmp, addr, addr_len, family, NETCONN_RAW, proto, 0);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
conn->lwip_conn = tmp;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void conn_ip_close(conn_ip_t *conn)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
netconn_delete(conn->lwip_conn);
|
||||
}
|
||||
|
||||
int conn_ip_getlocaladdr(conn_ip_t *conn, void *addr)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
return lwip_conn_getlocaladdr(conn->lwip_conn, addr, NULL);
|
||||
}
|
||||
|
||||
int conn_ip_recvfrom(conn_ip_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
return lwip_conn_recvfrom(conn->lwip_conn, data, max_len, addr, addr_len, NULL);
|
||||
}
|
||||
|
||||
int conn_ip_sendto(const void *data, size_t len, const void *src, size_t src_len,
|
||||
void *dst, size_t dst_len, int family, int proto)
|
||||
{
|
||||
struct netconn *tmp;
|
||||
int res;
|
||||
|
||||
res = lwip_conn_create(&tmp, src, src_len, family, NETCONN_RAW, proto, 0);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
res = lwip_conn_sendto(tmp, data, len, dst, dst_len, 0);
|
||||
netconn_delete(tmp);
|
||||
return res;
|
||||
}
|
||||
|
||||
/** @} */
|
|
@ -1,206 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "byteorder.h"
|
||||
#include "net/af.h"
|
||||
#include "net/ipv4/addr.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "net/conn.h"
|
||||
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/opt.h"
|
||||
|
||||
int lwip_conn_create(struct netconn **netconn, const void *addr, size_t addr_len, int family,
|
||||
int type, int proto, uint16_t port)
|
||||
{
|
||||
struct netconn *tmp;
|
||||
int res = 0;
|
||||
|
||||
switch (family) {
|
||||
#if LWIP_IPV4
|
||||
case AF_INET:
|
||||
if (addr_len != sizeof(ipv4_addr_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
case AF_INET6:
|
||||
if (addr_len != sizeof(ipv6_addr_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
type |= NETCONN_TYPE_IPV6;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
if ((tmp = netconn_new_with_proto_and_callback(type, proto, NULL)) == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
switch (netconn_bind(tmp, (ip_addr_t *)addr, port)) {
|
||||
case ERR_USE:
|
||||
netconn_delete(tmp);
|
||||
res = -EADDRINUSE;
|
||||
break;
|
||||
case ERR_VAL:
|
||||
netconn_delete(tmp);
|
||||
res = -EINVAL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*netconn = tmp;
|
||||
return res;
|
||||
}
|
||||
|
||||
int lwip_conn_getlocaladdr(struct netconn *netconn, void *addr, uint16_t *port)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
if (netconn_getaddr(netconn, addr, &tmp, 1) != ERR_OK) {
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
if (port != NULL) {
|
||||
*port = tmp;
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
if (netconn->type & NETCONN_TYPE_IPV6) {
|
||||
return sizeof(ipv6_addr_t);
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
return sizeof(ipv4_addr_t);
|
||||
#else
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
}
|
||||
|
||||
int lwip_conn_recvfrom(struct netconn *netconn, void *data, size_t max_len, void *addr,
|
||||
size_t *addr_len, uint16_t *port)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
size_t len = 0;
|
||||
err_t res = 0;
|
||||
uint8_t *data_ptr = data;
|
||||
|
||||
if (netconn == NULL) {
|
||||
return -ENOTSOCK;
|
||||
}
|
||||
if ((res = netconn_recv(netconn, &buf))) {
|
||||
switch (res) {
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case ERR_TIMEOUT:
|
||||
return -ETIMEDOUT;
|
||||
#endif
|
||||
case ERR_MEM:
|
||||
return -ENOMEM;
|
||||
default:
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
len = buf->p->tot_len;
|
||||
if (len > max_len) {
|
||||
netbuf_delete(buf);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
if (netconn->type & NETCONN_TYPE_IPV6) {
|
||||
*addr_len = sizeof(ipv6_addr_t);
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
*addr_len = sizeof(ipv4_addr_t);
|
||||
#else
|
||||
netbuf_delete(buf);
|
||||
return -EOPNOTSUPP;
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
}
|
||||
#endif
|
||||
/* copy address */
|
||||
memcpy(addr, &buf->addr, *addr_len);
|
||||
/* copy port */
|
||||
if (port != NULL) {
|
||||
*port = buf->port;
|
||||
}
|
||||
/* copy data */
|
||||
for (struct pbuf *q = buf->p; q != NULL; q = q->next) {
|
||||
memcpy(data_ptr, q->payload, q->len);
|
||||
data_ptr += q->len;
|
||||
}
|
||||
|
||||
netbuf_delete(buf);
|
||||
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
int lwip_conn_sendto(struct netconn *netconn, const void *data, size_t len,
|
||||
const void *addr, size_t addr_len, uint16_t port)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
int res;
|
||||
|
||||
#if LWIP_IPV6
|
||||
if (netconn->type & NETCONN_TYPE_IPV6) {
|
||||
if (addr_len != sizeof(ipv6_addr_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
#if LWIP_IPV4
|
||||
if (addr_len != sizeof(ipv4_addr_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
#if LWIP_IPV6
|
||||
}
|
||||
#endif
|
||||
buf = netbuf_new();
|
||||
if ((buf == NULL) || (netbuf_alloc(buf, len) == NULL)) {
|
||||
netbuf_delete(buf);
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (netbuf_take(buf, data, len) != ERR_OK) {
|
||||
netbuf_delete(buf);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
switch ((res = netconn_sendto(netconn, buf, addr, port))) {
|
||||
case ERR_OK:
|
||||
res = len;
|
||||
break;
|
||||
case ERR_RTE:
|
||||
res = -EHOSTUNREACH;
|
||||
break;
|
||||
case ERR_VAL:
|
||||
res = -EINVAL;
|
||||
break;
|
||||
case ERR_IF:
|
||||
res = -EAFNOSUPPORT;
|
||||
break;
|
||||
default:
|
||||
res = -EIO;
|
||||
break;
|
||||
}
|
||||
netbuf_delete(buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
/** @} */
|
|
@ -1,3 +0,0 @@
|
|||
MODULE := lwip_conn_udp
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "net/ipv4/addr.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "net/conn/udp.h"
|
||||
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/conn.h"
|
||||
|
||||
int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len, int family, uint16_t port)
|
||||
{
|
||||
struct netconn *tmp;
|
||||
int res;
|
||||
|
||||
res = lwip_conn_create(&tmp, addr, addr_len, family, NETCONN_UDP, 0, port);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
conn->lwip_conn = tmp;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void conn_udp_close(conn_udp_t *conn)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
netconn_delete(conn->lwip_conn);
|
||||
}
|
||||
|
||||
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
return lwip_conn_getlocaladdr(conn->lwip_conn, addr, port);
|
||||
}
|
||||
|
||||
int conn_udp_recvfrom(conn_udp_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len,
|
||||
uint16_t *port)
|
||||
{
|
||||
assert(conn != NULL);
|
||||
return lwip_conn_recvfrom(conn->lwip_conn, data, max_len, addr, addr_len, port);
|
||||
}
|
||||
|
||||
int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_len,
|
||||
const void *dst, size_t dst_len, int family, uint16_t sport,
|
||||
uint16_t dport)
|
||||
{
|
||||
struct netconn *tmp;
|
||||
int res;
|
||||
|
||||
res = lwip_conn_create(&tmp, src, src_len, family, NETCONN_UDP, 0, sport);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
res = lwip_conn_sendto(tmp, data, len, dst, dst_len, dport);
|
||||
netconn_delete(tmp);
|
||||
return res;
|
||||
}
|
||||
|
||||
/** @} */
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pkg_lwip_conn Connection type definitions for lwIP
|
||||
* @ingroup pkg_lwip
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef LWIP_CONN_H
|
||||
#define LWIP_CONN_H
|
||||
|
||||
#include "lwip/api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Generic @ref net_conn object for lwIP (used internally)
|
||||
*/
|
||||
struct conn {
|
||||
struct netconn *lwip_conn; /**< stack-internal connection object */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief @ref net_conn_ip definition for lwIP
|
||||
*/
|
||||
struct conn_ip {
|
||||
struct netconn *lwip_conn; /**< stack-internal connection object */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief @ref net_conn_udp definition for lwIP
|
||||
*/
|
||||
struct conn_udp {
|
||||
struct netconn *lwip_conn; /**< stack-internal connection object */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Internal consolidation functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief consolidation function for @ref conn_ip_create() and @ref
|
||||
* conn_udp_create()
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
int lwip_conn_create(struct netconn **netconn, const void *addr, size_t addr_len,
|
||||
int family, int type, int proto, uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief consolidation function for @ref conn_ip_getlocaladdr() and @ref
|
||||
* conn_udp_getlocaladdr()
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
int lwip_conn_getlocaladdr(struct netconn *netconn, void *addr, uint16_t *port);
|
||||
|
||||
/**
|
||||
* @brief consolidation function for @ref conn_ip_recvfrom() and @ref
|
||||
* conn_udp_recvfrom()
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
int lwip_conn_recvfrom(struct netconn *netconn, void *data, size_t max_len,
|
||||
void *addr, size_t *addr_len, uint16_t *port);
|
||||
|
||||
/**
|
||||
* @brief consolidation function for @ref conn_ip_sendto() and @ref
|
||||
* conn_udp_sendto()
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
int lwip_conn_sendto(struct netconn *netconn, const void *data, size_t len,
|
||||
const void *addr, size_t addr_len, uint16_t port);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_CONN_H */
|
||||
/** @} */
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_conn Application connection API
|
||||
* @ingroup net
|
||||
* @deprecated Please use @ref net_sock instead
|
||||
* @brief Provides a minimal common API for applications to connect to the
|
||||
* different network stacks.
|
||||
*
|
||||
* About
|
||||
* =====
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~
|
||||
* +---------------+
|
||||
* | Application |
|
||||
* +---------------+
|
||||
* ^
|
||||
* |
|
||||
* v
|
||||
* conn
|
||||
* ^
|
||||
* |
|
||||
* v
|
||||
* +---------------+
|
||||
* | Network Stack |
|
||||
* +---------------+
|
||||
* ~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* This module provides a minimal set of functions to establish a connection using
|
||||
* different types of connections. Together, they serve as a common API
|
||||
* that connects application- and network stack code.
|
||||
*
|
||||
* Currently the following connection types are defined:
|
||||
*
|
||||
* * @ref conn_ip_t (net/conn/ip.h): raw IP connections
|
||||
* * @ref conn_tcp_t (net/conn/tcp.h): TCP connections
|
||||
* * @ref conn_udp_t (net/conn/udp.h): UDP connections
|
||||
*
|
||||
* Each network stack must implement at least one connection type.
|
||||
*
|
||||
* Note that there might be no relation between the different connection types.
|
||||
* For simplicity and modularity this API doesn't put any restriction of the actual
|
||||
* implementation of the type. For example, one implementation might choose
|
||||
* to have all connection types have a common base class or use the raw IPv6
|
||||
* connection type to send e.g. UDP packets, while others will keep them
|
||||
* completely separate from each other.
|
||||
*
|
||||
* How To Use
|
||||
* ==========
|
||||
*
|
||||
* A RIOT application uses the functions provided by one or more of the connection types
|
||||
* headers (for example @ref conn_udp_t), regardless of the network stack it uses.
|
||||
* The network stack used under the bonnet is specified by including the appropriate
|
||||
* module (for example USEMODULE += gnrc_conn_udp)
|
||||
*
|
||||
* This allows for network stack agnostic code on the application layer.
|
||||
* The application code to establish a connection is always the same, allowing
|
||||
* the network stack underneath to be switched simply by changing the USEMODULE
|
||||
* definition in the application's Makefile.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Application connection API definitions
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef NET_CONN_H
|
||||
#define NET_CONN_H
|
||||
|
||||
#include "net/conn/ip.h"
|
||||
#include "net/conn/tcp.h"
|
||||
#include "net/conn/udp.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Find the best matching source address for a given prefix
|
||||
*
|
||||
* @param[in] dst Pointer to the IPv6 address to find a match for
|
||||
* Must not be NULL
|
||||
*
|
||||
* @return NULL if no matching address on any interface could be found
|
||||
* @return pointer to an IPv6 address configured on an interface with the best
|
||||
* match to @p dst
|
||||
*/
|
||||
ipv6_addr_t *conn_find_best_source(const ipv6_addr_t *dst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_CONN_H */
|
||||
/** @} */
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_conn_ip Raw IPv4/IPv6 connections
|
||||
* @ingroup net_conn
|
||||
* @deprecated Please use @ref net_sock_ip instead
|
||||
* @brief Connection submodule for raw IPv4/IPv6 connections
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Raw IPv4/IPv6 connection definitions
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef NET_CONN_IP_H
|
||||
#define NET_CONN_IP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MODULE_GNRC_CONN_IP
|
||||
#include "net/gnrc/conn.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_LWIP_CONN_IP
|
||||
#include "lwip/conn.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of @ref conn_ip_t to allow for external definition.
|
||||
*/
|
||||
struct conn_ip;
|
||||
|
||||
/**
|
||||
* @brief Implementation-specific type of a raw IPv4/IPv6 connection object
|
||||
*/
|
||||
typedef struct conn_ip conn_ip_t;
|
||||
|
||||
/**
|
||||
* @brief Creates a new raw IPv4/IPv6 connection object
|
||||
*
|
||||
* @param[out] conn Preallocated connection object. Must fill the size of the stack-specific
|
||||
* connection desriptor.
|
||||
* @param[in] addr The local IP address for @p conn.
|
||||
* @param[in] addr_len Length of @p addr. Must be fitting for the @p family.
|
||||
* @param[in] family The family of @p addr (see @ref net_af).
|
||||
* @param[in] proto @ref net_protnum for the IPv6 packets to receive.
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' bind() function specification.
|
||||
*/
|
||||
int conn_ip_create(conn_ip_t *conn, const void *addr, size_t addr_len, int family, int proto);
|
||||
|
||||
/**
|
||||
* @brief Closes a raw IPv4/IPv6 connection
|
||||
*
|
||||
* @param[in,out] conn A raw IPv4/IPv6 connection object.
|
||||
*/
|
||||
void conn_ip_close(conn_ip_t *conn);
|
||||
|
||||
/**
|
||||
* @brief Gets the local address of a raw IPv4/IPv6 connection
|
||||
*
|
||||
* @param[in] conn A raw IPv4/IPv6 connection object.
|
||||
* @param[out] addr The local IP address. Must have space for any address of the connection's
|
||||
* family.
|
||||
*
|
||||
* @return length of @p addr on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' getsockname() function
|
||||
* specification.
|
||||
*/
|
||||
int conn_ip_getlocaladdr(conn_ip_t *conn, void *addr);
|
||||
|
||||
/**
|
||||
* @brief Receives a message over IPv4/IPv6
|
||||
*
|
||||
* @param[in] conn A raw IPv4/IPv6 connection object.
|
||||
* @param[out] data Pointer where the received data should be stored.
|
||||
* @param[in] max_len Maximum space available at @p data.
|
||||
* @param[out] addr NULL pointer or the sender's IP address. Must have space for any address
|
||||
* of the connection's family.
|
||||
* @param[out] addr_len Length of @p addr. Can be NULL if @p addr is NULL.
|
||||
*
|
||||
* @note Function may block.
|
||||
*
|
||||
* @return The number of bytes received on success.
|
||||
* @return 0, if no received data is available, but everything is in order.
|
||||
* @return any other negative number in case of an error. For portability, implementations should
|
||||
* draw inspiration of the errno values from the POSIX' recv(), recvfrom(), or recvmsg()
|
||||
* function specification.
|
||||
*/
|
||||
int conn_ip_recvfrom(conn_ip_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len);
|
||||
|
||||
/**
|
||||
* @brief Sends a message over IPv4/IPv6
|
||||
*
|
||||
* @param[in] data Pointer where the received data should be stored.
|
||||
* @param[in] len Maximum space available at @p data.
|
||||
* @param[in] src The source address. May be NULL for all any interface address.
|
||||
* @param[in] src_len Length of @p src.
|
||||
* @param[in] dst The receiver's network address.
|
||||
* @param[in] dst_len Length of @p dst.
|
||||
* @param[in] family The family of @p src and @p dst (see @ref net_af).
|
||||
* @param[in] proto @ref net_protnum for the IPv6 packets to set.
|
||||
*
|
||||
* @note Function may block.
|
||||
*
|
||||
* @return The number of bytes send on success.
|
||||
* @return any other negative number in case of an error. For portability, implementations should
|
||||
* draw inspiration of the errno values from the POSIX' send(), sendfrom(), or sendmsg()
|
||||
* function specification.
|
||||
*/
|
||||
int conn_ip_sendto(const void *data, size_t len, const void *src, size_t src_len,
|
||||
void *dst, size_t dst_len, int family, int proto);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_CONN_IP_H */
|
||||
/** @} */
|
|
@ -1,178 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_conn_tcp TCP connections
|
||||
* @ingroup net_conn
|
||||
* @deprecated Please use @ref net_sock_tcp instead
|
||||
* @brief Connection submodule for TCP connections
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief TCP connection definitions
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef NET_CONN_TCP_H
|
||||
#define NET_CONN_TCP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MODULE_GNRC_CONN_TCP
|
||||
#include "net/gnrc/conn.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of @ref conn_tcp_t to allow for external definition.
|
||||
*/
|
||||
struct conn_tcp;
|
||||
|
||||
/**
|
||||
* @brief Implementation-specific type of a TCP connection object
|
||||
*/
|
||||
typedef struct conn_tcp conn_tcp_t;
|
||||
|
||||
/**
|
||||
* @brief Creates a new TCP connection object
|
||||
*
|
||||
* @param[out] conn Preallocated connection object. Must fill the size of the stack-specific
|
||||
* connection desriptor.
|
||||
* @param[in] addr The local network layer address for @p conn.
|
||||
* @param[in] addr_len The length of @p addr. Must be fitting for the @p family.
|
||||
* @param[in] family The family of @p addr (see @ref net_af).
|
||||
* @param[in] port The local TCP port for @p conn.
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' bind() function specification.
|
||||
*/
|
||||
int conn_tcp_create(conn_tcp_t *conn, const void *addr, size_t addr_len, int family,
|
||||
uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief Closes a TCP connection
|
||||
*
|
||||
* @param[in,out] conn A TCP connection object.
|
||||
*/
|
||||
void conn_tcp_close(conn_tcp_t *conn);
|
||||
|
||||
/**
|
||||
* @brief Gets the local address of a TCP connection
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[out] addr The local network layer address. Must have space for any address of
|
||||
* the connection's family.
|
||||
* @param[out] port The local TCP port.
|
||||
*
|
||||
* @return length of @p addr on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' getsockname() function
|
||||
* specification.
|
||||
*/
|
||||
int conn_tcp_getlocaladdr(conn_tcp_t *conn, void *addr, uint16_t *port);
|
||||
|
||||
/**
|
||||
* @brief Gets the address of the connected peer of a TCP connection
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[out] addr The network layer address of the connected peer. Must have space for any
|
||||
* address of the connection's family.
|
||||
* @param[out] port The TCP port of the connected peer.
|
||||
*
|
||||
* @return length of @p addr on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' getpeername() function
|
||||
* specification.
|
||||
*/
|
||||
int conn_tcp_getpeeraddr(conn_tcp_t *conn, void *addr, uint16_t *port);
|
||||
|
||||
/**
|
||||
* @brief Connects to a remote TCP peer
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[in] addr The remote network layer address for @p conn.
|
||||
* @param[in] addr_len Length of @p addr.
|
||||
* @param[in] port The remote TCP port for @p conn.
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' connect() function specification.
|
||||
*/
|
||||
int conn_tcp_connect(conn_tcp_t *conn, const void *addr, size_t addr_len, uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief Marks connection to listen for a connection request by a remote TCP peer
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[in] queue_len Maximum length of the queue for connection requests.
|
||||
* An implementation may choose to silently adapt this value to its needs
|
||||
* (setting it to a minimum or maximum value). Any negative number must be
|
||||
* set at least to 0.
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' listen() function specification.
|
||||
*/
|
||||
int conn_tcp_listen(conn_tcp_t *conn, int queue_len);
|
||||
|
||||
/**
|
||||
* @brief Receives and handles TCP connection requests from other peers
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[out] out_conn A new TCP connection object for the established connection.
|
||||
*
|
||||
* @return 0 on success.
|
||||
* @return any other negative number in case of an error. For portability implementations should
|
||||
* draw inspiration of the errno values from the POSIX' accept() function specification.
|
||||
*/
|
||||
int conn_tcp_accept(conn_tcp_t *conn, conn_tcp_t *out_conn);
|
||||
|
||||
/**
|
||||
* @brief Receives a TCP message
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[out] data Pointer where the received data should be stored.
|
||||
* @param[in] max_len Maximum space available at @p data.
|
||||
*
|
||||
* @note Function may block.
|
||||
*
|
||||
* @return The number of bytes received on success.
|
||||
* @return 0, if no received data is available, but everything is in order.
|
||||
* @return any other negative number in case of an error. For portability, implementations should
|
||||
* draw inspiration of the errno values from the POSIX' recv(), recvfrom(), or recvmsg()
|
||||
* function specification.
|
||||
*/
|
||||
int conn_tcp_recv(conn_tcp_t *conn, void *data, size_t max_len);
|
||||
|
||||
/**
|
||||
* @brief Sends a TCP message
|
||||
*
|
||||
* @param[in] conn A TCP connection object.
|
||||
* @param[in] data Pointer where the received data should be stored.
|
||||
* @param[in] len Maximum space available at @p data.
|
||||
*
|
||||
* @note Function may block.
|
||||
*
|
||||
* @return The number of bytes send on success.
|
||||
* @return any other negative number in case of an error. For portability, implementations should
|
||||
* draw inspiration of the errno values from the POSIX' send(), sendfrom(), or sendmsg()
|
||||
* function specification.
|
||||
*/
|
||||
int conn_tcp_send(conn_tcp_t *conn, const void *data, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_CONN_TCP_H */
|
||||
/** @} */
|
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||