2016-06-14 14:56:50 +08:00
|
|
|
/** @file
|
|
|
|
@brief Generic connection handling.
|
|
|
|
|
|
|
|
This is not to be included by the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-06-14 14:56:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CONNECTION_H
|
|
|
|
#define __CONNECTION_H
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-06-14 14:56:50 +08:00
|
|
|
|
|
|
|
#include <misc/util.h>
|
|
|
|
|
|
|
|
#include <net/net_core.h>
|
|
|
|
#include <net/net_ip.h>
|
2017-04-03 23:14:35 +08:00
|
|
|
#include <net/net_pkt.h>
|
2016-06-14 14:56:50 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-06-22 21:33:56 +08:00
|
|
|
struct net_conn;
|
|
|
|
|
2016-11-04 05:18:35 +08:00
|
|
|
struct net_conn_handle;
|
|
|
|
|
2016-06-14 14:56:50 +08:00
|
|
|
/**
|
|
|
|
* @brief Function that is called by connection subsystem when UDP/TCP
|
|
|
|
* packet is received and which matches local and remote IP address
|
|
|
|
* and port.
|
|
|
|
*/
|
2016-06-22 21:35:55 +08:00
|
|
|
typedef enum net_verdict (*net_conn_cb_t)(struct net_conn *conn,
|
2017-04-05 14:37:44 +08:00
|
|
|
struct net_pkt *pkt,
|
2016-06-14 14:56:50 +08:00
|
|
|
void *user_data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Information about a connection in the system.
|
|
|
|
*
|
|
|
|
* Stores the connection information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct net_conn {
|
|
|
|
/** Remote IP address */
|
2016-06-22 21:33:56 +08:00
|
|
|
struct sockaddr remote_addr;
|
2016-06-14 14:56:50 +08:00
|
|
|
|
|
|
|
/** Local IP address */
|
2016-06-22 21:33:56 +08:00
|
|
|
struct sockaddr local_addr;
|
2016-06-14 14:56:50 +08:00
|
|
|
|
|
|
|
/** Callback to be called when matching UDP packet is received */
|
|
|
|
net_conn_cb_t cb;
|
|
|
|
|
|
|
|
/** Possible user to pass to the callback */
|
|
|
|
void *user_data;
|
|
|
|
|
|
|
|
/** Connection protocol */
|
|
|
|
uint8_t proto;
|
|
|
|
|
|
|
|
/** Flags for the connection */
|
|
|
|
uint8_t flags;
|
|
|
|
|
|
|
|
/** Rank of this connection. Higher rank means more specific
|
|
|
|
* connection.
|
|
|
|
* Value is constructed like this:
|
|
|
|
* bit 0 local port, bit set if specific value
|
|
|
|
* bit 1 remote port, bit set if specific value
|
|
|
|
* bit 2 local address, bit set if unspecified address
|
|
|
|
* bit 3 remote address, bit set if unspecified address
|
|
|
|
* bit 4 local address, bit set if specific address
|
|
|
|
* bit 5 remote address, bit set if specific address
|
|
|
|
*/
|
|
|
|
uint8_t rank;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Register a callback to be called when UDP/TCP packet
|
|
|
|
* is received corresponding to received packet.
|
|
|
|
*
|
|
|
|
* @param proto Protocol for the connection (UDP or TCP)
|
|
|
|
* @param remote_addr Remote address of the connection end point.
|
|
|
|
* @param local_addr Local address of the connection end point.
|
|
|
|
* @param remote_port Remote port of the connection end point.
|
|
|
|
* @param local_port Local port of the connection end point.
|
|
|
|
* @param cb Callback to be called
|
|
|
|
* @param user_data User data supplied by caller.
|
2016-11-04 05:18:35 +08:00
|
|
|
* @param handle Connection handle that can be used when unregistering
|
2016-06-14 14:56:50 +08:00
|
|
|
*
|
|
|
|
* @return Return 0 if the registration succeed, <0 otherwise.
|
|
|
|
*/
|
2016-06-28 20:44:31 +08:00
|
|
|
int net_conn_register(enum net_ip_protocol proto,
|
2016-06-22 21:33:56 +08:00
|
|
|
const struct sockaddr *remote_addr,
|
|
|
|
const struct sockaddr *local_addr,
|
2016-06-14 14:56:50 +08:00
|
|
|
uint16_t remote_port,
|
|
|
|
uint16_t local_port,
|
|
|
|
net_conn_cb_t cb,
|
|
|
|
void *user_data,
|
2016-11-04 05:18:35 +08:00
|
|
|
struct net_conn_handle **handle);
|
2016-06-14 14:56:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unregister connection handler.
|
|
|
|
*
|
|
|
|
* @param handle Handle from registering.
|
|
|
|
*
|
|
|
|
* @return Return 0 if the unregistration succeed, <0 otherwise.
|
|
|
|
*/
|
2016-11-04 05:18:35 +08:00
|
|
|
int net_conn_unregister(struct net_conn_handle *handle);
|
2016-06-14 14:56:50 +08:00
|
|
|
|
2016-11-05 05:28:21 +08:00
|
|
|
/**
|
|
|
|
* @brief Change the callback and user_data for a registered connection
|
|
|
|
* handle.
|
|
|
|
*
|
|
|
|
* @param handle A handle registered with net_conn_register()
|
|
|
|
* @param cb Callback to be called
|
|
|
|
* @param user_data User data supplied by caller.
|
|
|
|
*
|
|
|
|
* @return Return 0 if the the change succeed, <0 otherwise.
|
|
|
|
*/
|
|
|
|
int net_conn_change_callback(struct net_conn_handle *handle,
|
|
|
|
net_conn_cb_t cb, void *user_data);
|
|
|
|
|
2016-06-14 14:56:50 +08:00
|
|
|
/**
|
|
|
|
* @brief Called by net_core.c when a network packet is received.
|
|
|
|
*
|
2017-04-05 14:37:44 +08:00
|
|
|
* @param pkt Network packet holding received data
|
2016-06-14 14:56:50 +08:00
|
|
|
*
|
|
|
|
* @return NET_OK if the packet was consumed, NET_DROP if
|
|
|
|
* the packet parsing failed and the caller should handle
|
|
|
|
* the received packet. If corresponding IP protocol support is
|
|
|
|
* disabled, the function will always return NET_DROP.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
|
2016-06-28 20:44:31 +08:00
|
|
|
enum net_verdict net_conn_input(enum net_ip_protocol proto,
|
2017-04-05 14:37:44 +08:00
|
|
|
struct net_pkt *pkt);
|
2016-06-14 14:56:50 +08:00
|
|
|
#else
|
2016-06-28 20:44:31 +08:00
|
|
|
static inline enum net_verdict net_conn_input(enum net_ip_protocol proto,
|
2017-04-05 14:37:44 +08:00
|
|
|
struct net_pkt *pkt)
|
2016-06-14 14:56:50 +08:00
|
|
|
{
|
|
|
|
return NET_DROP;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */
|
|
|
|
|
|
|
|
void net_conn_init(void);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __CONNECTION_H */
|