blob: f042a5f3b92e46c8b47c077b0d294918b341b602 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Joe Hershbergera630b6c2015-03-22 17:09:19 -05002/*
3 * Copyright (c) 2015 National Instruments
4 *
5 * (C) Copyright 2015
6 * Joe Hershberger <joe.hershberger@ni.com>
Joe Hershbergera630b6c2015-03-22 17:09:19 -05007 */
8
9#ifndef __ETH_H
10#define __ETH_H
11
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
13
Joe Hershbergera630b6c2015-03-22 17:09:19 -050014void sandbox_eth_disable_response(int index, bool disable);
15
Joe Hershbergerbe711422015-04-21 13:57:19 -050016void sandbox_eth_skip_timeout(void);
17
Joe Hershberger878123d2018-09-26 16:48:54 -050018/*
19 * sandbox_eth_arp_req_to_reply()
20 *
21 * Check for an arp request to be sent. If so, inject a reply
22 *
23 * @dev: device that received the packet
24 * @packet: pointer to the received pacaket buffer
25 * @len: length of received packet
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010026 * Return: 0 if injected, -EAGAIN if not
Joe Hershberger878123d2018-09-26 16:48:54 -050027 */
28int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet,
29 unsigned int len);
30
31/*
32 * sandbox_eth_ping_req_to_reply()
33 *
34 * Check for a ping request to be sent. If so, inject a reply
35 *
36 * @dev: device that received the packet
37 * @packet: pointer to the received pacaket buffer
38 * @len: length of received packet
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010039 * Return: 0 if injected, -EAGAIN if not
Joe Hershberger878123d2018-09-26 16:48:54 -050040 */
41int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet,
42 unsigned int len);
43
Joe Hershberger54418d02018-09-26 16:49:00 -050044/*
45 * sandbox_eth_recv_arp_req()
46 *
47 * Inject an ARP request for this target
48 *
49 * @dev: device that received the packet
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010050 * Return: 0 if injected, -EOVERFLOW if not
Joe Hershberger54418d02018-09-26 16:49:00 -050051 */
52int sandbox_eth_recv_arp_req(struct udevice *dev);
53
Joe Hershberger9716dc12018-09-26 16:49:01 -050054/*
55 * sandbox_eth_recv_ping_req()
56 *
57 * Inject a ping request for this target
58 *
59 * @dev: device that received the packet
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010060 * Return: 0 if injected, -EOVERFLOW if not
Joe Hershberger9716dc12018-09-26 16:49:01 -050061 */
62int sandbox_eth_recv_ping_req(struct udevice *dev);
63
Joe Hershberger2260f132018-09-26 16:48:55 -050064/**
65 * A packet handler
66 *
67 * dev - device pointer
68 * pkt - pointer to the "sent" packet
69 * len - packet length
70 */
71typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt,
72 unsigned int len);
73
Joe Hershbergerc1363072018-09-26 16:48:56 -050074/**
75 * struct eth_sandbox_priv - memory for sandbox mock driver
76 *
77 * fake_host_hwaddr - MAC address of mocked machine
78 * fake_host_ipaddr - IP address of mocked machine
79 * disabled - Will not respond
Joe Hershberger46d2b6e2018-09-26 16:48:57 -050080 * recv_packet_buffer - buffers of the packet returned as received
81 * recv_packet_length - lengths of the packet returned as received
82 * recv_packets - number of packets returned
Joe Hershbergerc1363072018-09-26 16:48:56 -050083 * tx_handler - function to generate responses to sent packets
Joe Hershberger11b85032018-09-26 16:48:59 -050084 * priv - a pointer to some structure a test may want to keep track of
Joe Hershbergerc1363072018-09-26 16:48:56 -050085 */
86struct eth_sandbox_priv {
87 uchar fake_host_hwaddr[ARP_HLEN];
88 struct in_addr fake_host_ipaddr;
89 bool disabled;
Joe Hershberger46d2b6e2018-09-26 16:48:57 -050090 uchar * recv_packet_buffer[PKTBUFSRX];
91 int recv_packet_length[PKTBUFSRX];
92 int recv_packets;
Joe Hershbergerc1363072018-09-26 16:48:56 -050093 sandbox_eth_tx_hand_f *tx_handler;
Joe Hershberger11b85032018-09-26 16:48:59 -050094 void *priv;
Joe Hershbergerc1363072018-09-26 16:48:56 -050095};
96
Joe Hershberger2260f132018-09-26 16:48:55 -050097/*
98 * Set packet handler
99 *
100 * handler - The func ptr to call on send. If NULL, set to default handler
101 */
102void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler);
103
Joe Hershberger11b85032018-09-26 16:48:59 -0500104/*
105 * Set priv ptr
106 *
107 * priv - priv void ptr to store in the device
108 */
109void sandbox_eth_set_priv(int index, void *priv);
110
Joe Hershbergera630b6c2015-03-22 17:09:19 -0500111#endif /* __ETH_H */