1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015 National Instruments
*
* (C) Copyright 2015
* Joe Hershberger <joe.hershberger@ni.com>
*/
#ifndef __ETH_H
#define __ETH_H
#include <net.h>
void sandbox_eth_disable_response(int index, bool disable);
void sandbox_eth_skip_timeout(void);
/*
* sandbox_eth_arp_req_to_reply()
*
* Check for an arp request to be sent. If so, inject a reply
*
* @dev: device that received the packet
* @packet: pointer to the received pacaket buffer
* @len: length of received packet
* @return 0 if injected, -EAGAIN if not
*/
int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet,
unsigned int len);
/*
* sandbox_eth_ping_req_to_reply()
*
* Check for a ping request to be sent. If so, inject a reply
*
* @dev: device that received the packet
* @packet: pointer to the received pacaket buffer
* @len: length of received packet
* @return 0 if injected, -EAGAIN if not
*/
int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet,
unsigned int len);
/*
* sandbox_eth_recv_arp_req()
*
* Inject an ARP request for this target
*
* @dev: device that received the packet
* @return 0 if injected, -EOVERFLOW if not
*/
int sandbox_eth_recv_arp_req(struct udevice *dev);
/*
* sandbox_eth_recv_ping_req()
*
* Inject a ping request for this target
*
* @dev: device that received the packet
* @return 0 if injected, -EOVERFLOW if not
*/
int sandbox_eth_recv_ping_req(struct udevice *dev);
/**
* A packet handler
*
* dev - device pointer
* pkt - pointer to the "sent" packet
* len - packet length
*/
typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt,
unsigned int len);
/**
* struct eth_sandbox_priv - memory for sandbox mock driver
*
* fake_host_hwaddr - MAC address of mocked machine
* fake_host_ipaddr - IP address of mocked machine
* disabled - Will not respond
* recv_packet_buffer - buffers of the packet returned as received
* recv_packet_length - lengths of the packet returned as received
* recv_packets - number of packets returned
* tx_handler - function to generate responses to sent packets
* priv - a pointer to some structure a test may want to keep track of
*/
struct eth_sandbox_priv {
uchar fake_host_hwaddr[ARP_HLEN];
struct in_addr fake_host_ipaddr;
bool disabled;
uchar * recv_packet_buffer[PKTBUFSRX];
int recv_packet_length[PKTBUFSRX];
int recv_packets;
sandbox_eth_tx_hand_f *tx_handler;
void *priv;
};
/*
* Set packet handler
*
* handler - The func ptr to call on send. If NULL, set to default handler
*/
void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler);
/*
* Set priv ptr
*
* priv - priv void ptr to store in the device
*/
void sandbox_eth_set_priv(int index, void *priv);
#endif /* __ETH_H */
|