2016-06-01 21:06:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-06-01 21:06:27 +08:00
|
|
|
*/
|
2016-06-01 21:06:27 +08:00
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Public API for network L2 interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NET_L2_H__
|
|
|
|
#define __NET_L2_H__
|
|
|
|
|
|
|
|
#include <net/buf.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-07-20 21:29:45 +08:00
|
|
|
/**
|
|
|
|
* @brief Network Layer 2 abstraction layer
|
|
|
|
* @defgroup net_l2 Network L2 Abstraction Layer
|
2017-11-18 00:43:53 +08:00
|
|
|
* @ingroup networking
|
2017-07-20 21:29:45 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
struct net_if;
|
|
|
|
|
|
|
|
struct net_l2 {
|
|
|
|
/**
|
|
|
|
* This function is used by net core to get iface's L2 layer parsing
|
|
|
|
* what's relevant to itself.
|
|
|
|
*/
|
2017-04-05 14:37:44 +08:00
|
|
|
enum net_verdict (*recv)(struct net_if *iface, struct net_pkt *pkt);
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
/**
|
2017-04-05 14:37:44 +08:00
|
|
|
* This function is used by net core to push a packet to lower layer
|
|
|
|
* (interface's L2), which in turn might work on the packet relevantly.
|
2016-11-12 06:13:24 +08:00
|
|
|
* (adding proper header etc...)
|
|
|
|
*/
|
2017-04-05 14:37:44 +08:00
|
|
|
enum net_verdict (*send)(struct net_if *iface, struct net_pkt *pkt);
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used to get the amount of bytes the net core should
|
2017-04-05 14:37:44 +08:00
|
|
|
* reserve as headroom in a net packet. Such space is relevant to L2
|
2016-11-12 06:13:24 +08:00
|
|
|
* layer only.
|
|
|
|
*/
|
2017-04-21 22:27:50 +08:00
|
|
|
u16_t (*reserve)(struct net_if *iface, void *data);
|
2016-11-12 06:13:24 +08:00
|
|
|
|
2016-12-21 19:33:09 +08:00
|
|
|
/**
|
|
|
|
* This function is used to enable/disable traffic over a network
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
int (*enable)(struct net_if *iface, bool state);
|
2016-11-12 06:13:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NET_L2_GET_NAME(_name) (__net_l2_##_name)
|
|
|
|
#define NET_L2_DECLARE_PUBLIC(_name) \
|
2017-02-15 17:16:12 +08:00
|
|
|
extern const struct net_l2 NET_L2_GET_NAME(_name)
|
2016-11-12 06:13:24 +08:00
|
|
|
#define NET_L2_GET_CTX_TYPE(_name) _name##_CTX_TYPE
|
|
|
|
|
|
|
|
extern struct net_l2 __net_l2_start[];
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_L2_DUMMY
|
|
|
|
#define DUMMY_L2 DUMMY
|
|
|
|
#define DUMMY_L2_CTX_TYPE void*
|
|
|
|
NET_L2_DECLARE_PUBLIC(DUMMY_L2);
|
|
|
|
#endif /* CONFIG_NET_L2_DUMMY */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_L2_ETHERNET
|
|
|
|
#define ETHERNET_L2 ETHERNET
|
|
|
|
#define ETHERNET_L2_CTX_TYPE void*
|
|
|
|
NET_L2_DECLARE_PUBLIC(ETHERNET_L2);
|
|
|
|
#endif /* CONFIG_NET_L2_ETHERNET */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_L2_IEEE802154
|
|
|
|
#define IEEE802154_L2 IEEE802154
|
|
|
|
NET_L2_DECLARE_PUBLIC(IEEE802154_L2);
|
|
|
|
#endif /* CONFIG_NET_L2_IEEE802154 */
|
|
|
|
|
2017-08-09 14:21:11 +08:00
|
|
|
#ifdef CONFIG_NET_L2_BT
|
2016-11-12 06:13:24 +08:00
|
|
|
#define BLUETOOTH_L2 BLUETOOTH
|
|
|
|
#define BLUETOOTH_L2_CTX_TYPE void*
|
2017-08-11 19:49:24 +08:00
|
|
|
NET_L2_DECLARE_PUBLIC(BLUETOOTH_L2);
|
2017-08-09 14:21:11 +08:00
|
|
|
#endif /* CONFIG_NET_L2_BT */
|
2016-11-12 06:13:24 +08:00
|
|
|
|
2017-03-09 15:57:54 +08:00
|
|
|
#ifdef CONFIG_NET_OFFLOAD
|
2016-11-12 06:13:24 +08:00
|
|
|
#define OFFLOAD_IP_L2 OFFLOAD_IP
|
|
|
|
#define OFFLOAD_IP_L2_CTX_TYPE void*
|
2017-08-11 19:49:24 +08:00
|
|
|
NET_L2_DECLARE_PUBLIC(OFFLOAD_IP);
|
2017-03-09 15:57:54 +08:00
|
|
|
#endif /* CONFIG_NET_OFFLOAD */
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
extern struct net_l2 __net_l2_end[];
|
|
|
|
|
2016-12-21 19:33:09 +08:00
|
|
|
#define NET_L2_INIT(_name, _recv_fn, _send_fn, _reserve_fn, _enable_fn) \
|
2017-02-15 17:16:12 +08:00
|
|
|
const struct net_l2 (NET_L2_GET_NAME(_name)) __used \
|
2016-11-12 06:13:24 +08:00
|
|
|
__attribute__((__section__(".net_l2.init"))) = { \
|
|
|
|
.recv = (_recv_fn), \
|
|
|
|
.send = (_send_fn), \
|
|
|
|
.reserve = (_reserve_fn), \
|
2016-12-21 19:33:09 +08:00
|
|
|
.enable = (_enable_fn), \
|
2016-11-12 06:13:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NET_L2_GET_DATA(name, sfx) (__net_l2_data_##name##sfx)
|
|
|
|
|
|
|
|
#define NET_L2_DATA_INIT(name, sfx, ctx_type) \
|
|
|
|
static ctx_type NET_L2_GET_DATA(name, sfx) __used \
|
|
|
|
__attribute__((__section__(".net_l2.data")));
|
|
|
|
|
2017-07-20 21:29:45 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2016-06-01 21:06:27 +08:00
|
|
|
#endif
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
#endif /* __NET_L2_H__ */
|