Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Joe Hershberger | a630b6c | 2015-03-22 17:09:19 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 National Instruments |
| 4 | * |
| 5 | * (C) Copyright 2015 |
| 6 | * Joe Hershberger <joe.hershberger@ni.com> |
Joe Hershberger | a630b6c | 2015-03-22 17:09:19 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef __ETH_H |
| 10 | #define __ETH_H |
| 11 | |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <net.h> |
| 13 | |
Joe Hershberger | a630b6c | 2015-03-22 17:09:19 -0500 | [diff] [blame] | 14 | void sandbox_eth_disable_response(int index, bool disable); |
| 15 | |
Joe Hershberger | be71142 | 2015-04-21 13:57:19 -0500 | [diff] [blame] | 16 | void sandbox_eth_skip_timeout(void); |
| 17 | |
Joe Hershberger | 878123d | 2018-09-26 16:48:54 -0500 | [diff] [blame] | 18 | /* |
| 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 |
| 26 | * @return 0 if injected, -EAGAIN if not |
| 27 | */ |
| 28 | int 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 |
| 39 | * @return 0 if injected, -EAGAIN if not |
| 40 | */ |
| 41 | int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet, |
| 42 | unsigned int len); |
| 43 | |
Joe Hershberger | 54418d0 | 2018-09-26 16:49:00 -0500 | [diff] [blame] | 44 | /* |
| 45 | * sandbox_eth_recv_arp_req() |
| 46 | * |
| 47 | * Inject an ARP request for this target |
| 48 | * |
| 49 | * @dev: device that received the packet |
| 50 | * @return 0 if injected, -EOVERFLOW if not |
| 51 | */ |
| 52 | int sandbox_eth_recv_arp_req(struct udevice *dev); |
| 53 | |
Joe Hershberger | 9716dc1 | 2018-09-26 16:49:01 -0500 | [diff] [blame] | 54 | /* |
| 55 | * sandbox_eth_recv_ping_req() |
| 56 | * |
| 57 | * Inject a ping request for this target |
| 58 | * |
| 59 | * @dev: device that received the packet |
| 60 | * @return 0 if injected, -EOVERFLOW if not |
| 61 | */ |
| 62 | int sandbox_eth_recv_ping_req(struct udevice *dev); |
| 63 | |
Joe Hershberger | 2260f13 | 2018-09-26 16:48:55 -0500 | [diff] [blame] | 64 | /** |
| 65 | * A packet handler |
| 66 | * |
| 67 | * dev - device pointer |
| 68 | * pkt - pointer to the "sent" packet |
| 69 | * len - packet length |
| 70 | */ |
| 71 | typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt, |
| 72 | unsigned int len); |
| 73 | |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 74 | /** |
| 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 Hershberger | 46d2b6e | 2018-09-26 16:48:57 -0500 | [diff] [blame] | 80 | * 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 Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 83 | * tx_handler - function to generate responses to sent packets |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 84 | * priv - a pointer to some structure a test may want to keep track of |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 85 | */ |
| 86 | struct eth_sandbox_priv { |
| 87 | uchar fake_host_hwaddr[ARP_HLEN]; |
| 88 | struct in_addr fake_host_ipaddr; |
| 89 | bool disabled; |
Joe Hershberger | 46d2b6e | 2018-09-26 16:48:57 -0500 | [diff] [blame] | 90 | uchar * recv_packet_buffer[PKTBUFSRX]; |
| 91 | int recv_packet_length[PKTBUFSRX]; |
| 92 | int recv_packets; |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 93 | sandbox_eth_tx_hand_f *tx_handler; |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 94 | void *priv; |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 95 | }; |
| 96 | |
Joe Hershberger | 2260f13 | 2018-09-26 16:48:55 -0500 | [diff] [blame] | 97 | /* |
| 98 | * Set packet handler |
| 99 | * |
| 100 | * handler - The func ptr to call on send. If NULL, set to default handler |
| 101 | */ |
| 102 | void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler); |
| 103 | |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 104 | /* |
| 105 | * Set priv ptr |
| 106 | * |
| 107 | * priv - priv void ptr to store in the device |
| 108 | */ |
| 109 | void sandbox_eth_set_priv(int index, void *priv); |
| 110 | |
Joe Hershberger | a630b6c | 2015-03-22 17:09:19 -0500 | [diff] [blame] | 111 | #endif /* __ETH_H */ |