123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- #ifndef ZEPHYR_INCLUDE_NET_CAPTURE_H_
- #define ZEPHYR_INCLUDE_NET_CAPTURE_H_
- #include <zephyr.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct net_if;
- struct net_capture_interface_api {
-
- int (*cleanup)(const struct device *dev);
-
- int (*enable)(const struct device *dev, struct net_if *iface);
-
- int (*disable)(const struct device *dev);
-
- bool (*is_enabled)(const struct device *dev);
-
- int (*send)(const struct device *dev, struct net_if *iface,
- struct net_pkt *pkt);
- };
- int net_capture_setup(const char *remote_addr, const char *my_local_addr,
- const char *peer_addr, const struct device **dev);
- static inline int net_capture_cleanup(const struct device *dev)
- {
- #if defined(CONFIG_NET_CAPTURE)
- const struct net_capture_interface_api *api =
- (const struct net_capture_interface_api *)dev->api;
- return api->cleanup(dev);
- #else
- ARG_UNUSED(dev);
- return -ENOTSUP;
- #endif
- }
- static inline int net_capture_enable(const struct device *dev,
- struct net_if *iface)
- {
- #if defined(CONFIG_NET_CAPTURE)
- const struct net_capture_interface_api *api =
- (const struct net_capture_interface_api *)dev->api;
- return api->enable(dev, iface);
- #else
- ARG_UNUSED(dev);
- ARG_UNUSED(iface);
- return -ENOTSUP;
- #endif
- }
- static inline bool net_capture_is_enabled(const struct device *dev)
- {
- #if defined(CONFIG_NET_CAPTURE)
- const struct net_capture_interface_api *api =
- (const struct net_capture_interface_api *)dev->api;
- return api->is_enabled(dev);
- #else
- ARG_UNUSED(dev);
- return false;
- #endif
- }
- static inline int net_capture_disable(const struct device *dev)
- {
- #if defined(CONFIG_NET_CAPTURE)
- const struct net_capture_interface_api *api =
- (const struct net_capture_interface_api *)dev->api;
- return api->disable(dev);
- #else
- ARG_UNUSED(dev);
- return -ENOTSUP;
- #endif
- }
- static inline int net_capture_send(const struct device *dev,
- struct net_if *iface,
- struct net_pkt *pkt)
- {
- #if defined(CONFIG_NET_CAPTURE)
- const struct net_capture_interface_api *api =
- (const struct net_capture_interface_api *)dev->api;
- return api->send(dev, iface, pkt);
- #else
- ARG_UNUSED(dev);
- ARG_UNUSED(iface);
- ARG_UNUSED(pkt);
- return -ENOTSUP;
- #endif
- }
- #if defined(CONFIG_NET_CAPTURE)
- void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt);
- #else
- static inline void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt)
- {
- ARG_UNUSED(iface);
- ARG_UNUSED(pkt);
- }
- #endif
- struct net_capture_info {
- const struct device *capture_dev;
- struct net_if *capture_iface;
- struct net_if *tunnel_iface;
- struct sockaddr *peer;
- struct sockaddr *local;
- bool is_enabled;
- };
- typedef void (*net_capture_cb_t)(struct net_capture_info *info,
- void *user_data);
- #if defined(CONFIG_NET_CAPTURE)
- void net_capture_foreach(net_capture_cb_t cb, void *user_data);
- #else
- static inline void net_capture_foreach(net_capture_cb_t cb, void *user_data)
- {
- ARG_UNUSED(cb);
- ARG_UNUSED(user_data);
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|