Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
capture.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2021 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_CAPTURE_H_
14#define ZEPHYR_INCLUDE_NET_CAPTURE_H_
15
16#include <zephyr.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
31struct net_if;
32
33struct net_capture_interface_api {
37 int (*cleanup)(const struct device *dev);
38
40 int (*enable)(const struct device *dev, struct net_if *iface);
41
43 int (*disable)(const struct device *dev);
44
47 bool (*is_enabled)(const struct device *dev);
48
50 int (*send)(const struct device *dev, struct net_if *iface,
51 struct net_pkt *pkt);
52};
53
71int net_capture_setup(const char *remote_addr, const char *my_local_addr,
72 const char *peer_addr, const struct device **dev);
73
85static inline int net_capture_cleanup(const struct device *dev)
86{
87#if defined(CONFIG_NET_CAPTURE)
88 const struct net_capture_interface_api *api =
89 (const struct net_capture_interface_api *)dev->api;
90
91 return api->cleanup(dev);
92#else
93 ARG_UNUSED(dev);
94
95 return -ENOTSUP;
96#endif
97}
98
111static inline int net_capture_enable(const struct device *dev,
112 struct net_if *iface)
113{
114#if defined(CONFIG_NET_CAPTURE)
115 const struct net_capture_interface_api *api =
116 (const struct net_capture_interface_api *)dev->api;
117
118 return api->enable(dev, iface);
119#else
120 ARG_UNUSED(dev);
121 ARG_UNUSED(iface);
122
123 return -ENOTSUP;
124#endif
125}
126
134static inline bool net_capture_is_enabled(const struct device *dev)
135{
136#if defined(CONFIG_NET_CAPTURE)
137 const struct net_capture_interface_api *api =
138 (const struct net_capture_interface_api *)dev->api;
139
140 return api->is_enabled(dev);
141#else
142 ARG_UNUSED(dev);
143
144 return false;
145#endif
146}
147
155static inline int net_capture_disable(const struct device *dev)
156{
157#if defined(CONFIG_NET_CAPTURE)
158 const struct net_capture_interface_api *api =
159 (const struct net_capture_interface_api *)dev->api;
160
161 return api->disable(dev);
162#else
163 ARG_UNUSED(dev);
164
165 return -ENOTSUP;
166#endif
167}
168
178static inline int net_capture_send(const struct device *dev,
179 struct net_if *iface,
180 struct net_pkt *pkt)
181{
182#if defined(CONFIG_NET_CAPTURE)
183 const struct net_capture_interface_api *api =
184 (const struct net_capture_interface_api *)dev->api;
185
186 return api->send(dev, iface, pkt);
187#else
188 ARG_UNUSED(dev);
189 ARG_UNUSED(iface);
190 ARG_UNUSED(pkt);
191
192 return -ENOTSUP;
193#endif
194}
195
205#if defined(CONFIG_NET_CAPTURE)
206void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt);
207#else
208static inline void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt)
209{
210 ARG_UNUSED(iface);
211 ARG_UNUSED(pkt);
212}
213#endif
214
215struct net_capture_info {
216 const struct device *capture_dev;
217 struct net_if *capture_iface;
218 struct net_if *tunnel_iface;
219 struct sockaddr *peer;
220 struct sockaddr *local;
221 bool is_enabled;
222};
223
231typedef void (*net_capture_cb_t)(struct net_capture_info *info,
232 void *user_data);
233
243#if defined(CONFIG_NET_CAPTURE)
244void net_capture_foreach(net_capture_cb_t cb, void *user_data);
245#else
246static inline void net_capture_foreach(net_capture_cb_t cb, void *user_data)
247{
248 ARG_UNUSED(cb);
249 ARG_UNUSED(user_data);
250}
251#endif
252
259#ifdef __cplusplus
260}
261#endif
262
263#endif /* ZEPHYR_INCLUDE_NET_CAPTURE_H_ */
void
Definition: eswifi_shell.c:15
static int net_capture_disable(const struct device *dev)
Disable network packet capturing support.
Definition: capture.h:155
static int net_capture_send(const struct device *dev, struct net_if *iface, struct net_pkt *pkt)
Send captured packet.
Definition: capture.h:178
static bool net_capture_is_enabled(const struct device *dev)
Is network packet capture enabled or disabled.
Definition: capture.h:134
static int net_capture_cleanup(const struct device *dev)
Cleanup network packet capturing support.
Definition: capture.h:85
int net_capture_setup(const char *remote_addr, const char *my_local_addr, const char *peer_addr, const struct device **dev)
Setup network packet capturing support.
static int net_capture_enable(const struct device *dev, struct net_if *iface)
Enable network packet capturing support.
Definition: capture.h:111
#define ENOTSUP
Definition: errno.h:115
#define bool
Definition: stdbool.h:13
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
Definition: net_ip.h:335
static const intptr_t user_data[5]
Definition: main.c:590
NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)