net: dummy: Add support for receiving data
Add a recv callback to dummy API. After this it is possible to receive data by a dummy network interface. This is only useful if one attaches a virtual interface on top of the dummy one. One such example is the cooked mode capture interface. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
33c075d705
commit
9a9f6f3d96
|
@ -32,6 +32,12 @@ struct dummy_api {
|
|||
/** Send a network packet */
|
||||
int (*send)(const struct device *dev, struct net_pkt *pkt);
|
||||
|
||||
/**
|
||||
* Receive a network packet (only limited use for this, for example
|
||||
* receiving capturing packets and post processing them).
|
||||
*/
|
||||
enum net_verdict (*recv)(struct net_if *iface, struct net_pkt *pkt);
|
||||
|
||||
/** Start the device. Called when the bound network interface is brought up. */
|
||||
int (*start)(const struct device *dev);
|
||||
|
||||
|
|
|
@ -17,14 +17,17 @@ LOG_MODULE_REGISTER(net_l2_dummy, LOG_LEVEL_NONE);
|
|||
static inline enum net_verdict dummy_recv(struct net_if *iface,
|
||||
struct net_pkt *pkt)
|
||||
{
|
||||
net_pkt_lladdr_src(pkt)->addr = NULL;
|
||||
net_pkt_lladdr_src(pkt)->len = 0U;
|
||||
net_pkt_lladdr_src(pkt)->type = NET_LINK_DUMMY;
|
||||
net_pkt_lladdr_dst(pkt)->addr = NULL;
|
||||
net_pkt_lladdr_dst(pkt)->len = 0U;
|
||||
net_pkt_lladdr_dst(pkt)->type = NET_LINK_DUMMY;
|
||||
const struct dummy_api *api = net_if_get_device(iface)->api;
|
||||
|
||||
return NET_CONTINUE;
|
||||
if (api == NULL) {
|
||||
return NET_DROP;
|
||||
}
|
||||
|
||||
if (api->recv == NULL) {
|
||||
return NET_CONTINUE;
|
||||
}
|
||||
|
||||
return api->recv(iface, pkt);
|
||||
}
|
||||
|
||||
static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
|
||||
|
|
Loading…
Reference in a new issue