123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #ifndef ZEPHYR_INCLUDE_NET_NET_L2_H_
- #define ZEPHYR_INCLUDE_NET_NET_L2_H_
- #include <device.h>
- #include <net/buf.h>
- #include <net/capture.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct net_if;
- enum net_l2_flags {
-
- NET_L2_MULTICAST = BIT(0),
-
- NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE = BIT(1),
-
- NET_L2_PROMISC_MODE = BIT(2),
-
- NET_L2_POINT_TO_POINT = BIT(3),
- } __packed;
- struct net_l2 {
-
- enum net_verdict (*recv)(struct net_if *iface, struct net_pkt *pkt);
-
- int (*send)(struct net_if *iface, struct net_pkt *pkt);
-
- int (*enable)(struct net_if *iface, bool state);
-
- enum net_l2_flags (*get_flags)(struct net_if *iface);
- };
- #define NET_L2_GET_NAME(_name) _net_l2_##_name
- #define NET_L2_DECLARE_PUBLIC(_name) \
- extern const struct net_l2 NET_L2_GET_NAME(_name)
- #define NET_L2_GET_CTX_TYPE(_name) _name##_CTX_TYPE
- #ifdef CONFIG_NET_L2_VIRTUAL
- #define VIRTUAL_L2 VIRTUAL
- NET_L2_DECLARE_PUBLIC(VIRTUAL_L2);
- #endif
- #ifdef CONFIG_NET_L2_DUMMY
- #define DUMMY_L2 DUMMY
- #define DUMMY_L2_CTX_TYPE void*
- NET_L2_DECLARE_PUBLIC(DUMMY_L2);
- #endif
- #ifdef CONFIG_NET_L2_ETHERNET
- #define ETHERNET_L2 ETHERNET
- NET_L2_DECLARE_PUBLIC(ETHERNET_L2);
- #endif
- #ifdef CONFIG_NET_L2_PPP
- #define PPP_L2 PPP
- NET_L2_DECLARE_PUBLIC(PPP_L2);
- #endif
- #ifdef CONFIG_NET_L2_IEEE802154
- #define IEEE802154_L2 IEEE802154
- NET_L2_DECLARE_PUBLIC(IEEE802154_L2);
- #endif
- #ifdef CONFIG_NET_L2_BT
- #define BLUETOOTH_L2 BLUETOOTH
- #define BLUETOOTH_L2_CTX_TYPE void*
- NET_L2_DECLARE_PUBLIC(BLUETOOTH_L2);
- #endif
- #ifdef CONFIG_NET_L2_OPENTHREAD
- #define OPENTHREAD_L2 OPENTHREAD
- NET_L2_DECLARE_PUBLIC(OPENTHREAD_L2);
- #endif
- #ifdef CONFIG_NET_L2_CANBUS_RAW
- #define CANBUS_RAW_L2 CANBUS_RAW
- #define CANBUS_RAW_L2_CTX_TYPE void*
- NET_L2_DECLARE_PUBLIC(CANBUS_RAW_L2);
- #endif
- #ifdef CONFIG_NET_L2_CANBUS
- #define CANBUS_L2 CANBUS
- NET_L2_DECLARE_PUBLIC(CANBUS_L2);
- #endif
- #define NET_L2_INIT(_name, _recv_fn, _send_fn, _enable_fn, _get_flags_fn) \
- const STRUCT_SECTION_ITERABLE(net_l2, \
- NET_L2_GET_NAME(_name)) = { \
- .recv = (_recv_fn), \
- .send = (_send_fn), \
- .enable = (_enable_fn), \
- .get_flags = (_get_flags_fn), \
- }
- #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;
- typedef int (*net_l2_send_t)(const struct device *dev, struct net_pkt *pkt);
- static inline int net_l2_send(net_l2_send_t send_fn,
- const struct device *dev,
- struct net_if *iface,
- struct net_pkt *pkt)
- {
- net_capture_pkt(iface, pkt);
- return send_fn(dev, pkt);
- }
- #ifdef __cplusplus
- }
- #endif
- #endif
|