Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_l2.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_NET_NET_L2_H_
13#define ZEPHYR_INCLUDE_NET_NET_L2_H_
14
15#include <zephyr/device.h>
16#include <zephyr/net/buf.h>
17#include <zephyr/net/capture.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
31struct net_if;
32
49
55struct net_l2 {
60 enum net_verdict (*recv)(struct net_if *iface, struct net_pkt *pkt);
61
68 int (*send)(struct net_if *iface, struct net_pkt *pkt);
69
74 int (*enable)(struct net_if *iface, bool state);
75
79 enum net_l2_flags (*get_flags)(struct net_if *iface);
80};
81
83#define NET_L2_GET_NAME(_name) _net_l2_##_name
84#define NET_L2_DECLARE_PUBLIC(_name) \
85 extern const struct net_l2 NET_L2_GET_NAME(_name)
86#define NET_L2_GET_CTX_TYPE(_name) _name##_CTX_TYPE
87
88#ifdef CONFIG_NET_L2_VIRTUAL
89#define VIRTUAL_L2 VIRTUAL
90NET_L2_DECLARE_PUBLIC(VIRTUAL_L2);
91#endif /* CONFIG_NET_L2_DUMMY */
92
93#ifdef CONFIG_NET_L2_DUMMY
94#define DUMMY_L2 DUMMY
95#define DUMMY_L2_CTX_TYPE void*
96NET_L2_DECLARE_PUBLIC(DUMMY_L2);
97#endif /* CONFIG_NET_L2_DUMMY */
98
99#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_SOCKETS_OFFLOAD)
100#define OFFLOADED_NETDEV_L2 OFFLOADED_NETDEV
101NET_L2_DECLARE_PUBLIC(OFFLOADED_NETDEV_L2);
102#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_SOCKETS_OFFLOAD */
103
104#ifdef CONFIG_NET_L2_ETHERNET
105#define ETHERNET_L2 ETHERNET
106NET_L2_DECLARE_PUBLIC(ETHERNET_L2);
107#endif /* CONFIG_NET_L2_ETHERNET */
108
109#ifdef CONFIG_NET_L2_PPP
110#define PPP_L2 PPP
111NET_L2_DECLARE_PUBLIC(PPP_L2);
112#endif /* CONFIG_NET_L2_PPP */
113
114#ifdef CONFIG_NET_L2_IEEE802154
115#define IEEE802154_L2 IEEE802154
116NET_L2_DECLARE_PUBLIC(IEEE802154_L2);
117#endif /* CONFIG_NET_L2_IEEE802154 */
118
119#ifdef CONFIG_NET_L2_OPENTHREAD
120#define OPENTHREAD_L2 OPENTHREAD
121NET_L2_DECLARE_PUBLIC(OPENTHREAD_L2);
122#endif /* CONFIG_NET_L2_OPENTHREAD */
123
124#ifdef CONFIG_NET_L2_CANBUS_RAW
125#define CANBUS_RAW_L2 CANBUS_RAW
126#define CANBUS_RAW_L2_CTX_TYPE void*
127NET_L2_DECLARE_PUBLIC(CANBUS_RAW_L2);
128#endif /* CONFIG_NET_L2_CANBUS_RAW */
129
130#ifdef CONFIG_NET_L2_CUSTOM_IEEE802154
131#ifndef CUSTOM_IEEE802154_L2
132#define CUSTOM_IEEE802154_L2 CUSTOM_IEEE802154
133#endif
134#define CUSTOM_IEEE802154_L2_CTX_TYPE void*
135NET_L2_DECLARE_PUBLIC(CUSTOM_IEEE802154_L2);
136#endif /* CONFIG_NET_L2_CUSTOM_IEEE802154 */
137
138#define NET_L2_INIT(_name, _recv_fn, _send_fn, _enable_fn, _get_flags_fn) \
139 const STRUCT_SECTION_ITERABLE(net_l2, \
140 NET_L2_GET_NAME(_name)) = { \
141 .recv = (_recv_fn), \
142 .send = (_send_fn), \
143 .enable = (_enable_fn), \
144 .get_flags = (_get_flags_fn), \
145 }
146
147#define NET_L2_GET_DATA(name, sfx) _net_l2_data_##name##sfx
148
149#define NET_L2_DATA_INIT(name, sfx, ctx_type) \
150 static ctx_type NET_L2_GET_DATA(name, sfx) __used;
151
152typedef int (*net_l2_send_t)(const struct device *dev, struct net_pkt *pkt);
153
154static inline int net_l2_send(net_l2_send_t send_fn,
155 const struct device *dev,
156 struct net_if *iface,
157 struct net_pkt *pkt)
158{
159 net_capture_pkt(iface, pkt);
160
161 return send_fn(dev, pkt);
162}
163
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* ZEPHYR_INCLUDE_NET_NET_L2_H_ */
Network packet capture definitions.
net_verdict
Net Verdict.
Definition net_core.h:100
net_l2_flags
L2 flags.
Definition net_l2.h:34
@ NET_L2_POINT_TO_POINT
Is this L2 point-to-point with tunneling so no need to have IP address etc to network interface.
Definition net_l2.h:47
@ NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE
Do not join solicited node multicast group.
Definition net_l2.h:39
@ NET_L2_PROMISC_MODE
Is promiscuous mode supported.
Definition net_l2.h:42
@ NET_L2_MULTICAST
IP multicast supported.
Definition net_l2.h:36
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
Buffer management.
state
Definition parser_state.h:29
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
Network Interface structure.
Definition net_if.h:678
Network L2 structure.
Definition net_l2.h:55
int(* send)(struct net_if *iface, struct net_pkt *pkt)
This function is used by net core to push a packet to lower layer (interface's L2),...
Definition net_l2.h:68
enum net_verdict(* recv)(struct net_if *iface, struct net_pkt *pkt)
This function is used by net core to get iface's L2 layer parsing what's relevant to itself.
Definition net_l2.h:60
enum net_l2_flags(* get_flags)(struct net_if *iface)
Return L2 flags for the network interface.
Definition net_l2.h:79
int(* enable)(struct net_if *iface, bool state)
This function is used to enable/disable traffic over a network interface.
Definition net_l2.h:74
Network packet.
Definition net_pkt.h:67
struct net_if * iface
Network interface.
Definition net_pkt.h:90