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 | |
| 12 | void sandbox_eth_disable_response(int index, bool disable); |
| 13 | |
Joe Hershberger | be71142 | 2015-04-21 13:57:19 -0500 | [diff] [blame] | 14 | void sandbox_eth_skip_timeout(void); |
| 15 | |
Joe Hershberger | 878123d | 2018-09-26 16:48:54 -0500 | [diff] [blame] | 16 | /* |
| 17 | * sandbox_eth_arp_req_to_reply() |
| 18 | * |
| 19 | * Check for an arp request to be sent. If so, inject a reply |
| 20 | * |
| 21 | * @dev: device that received the packet |
| 22 | * @packet: pointer to the received pacaket buffer |
| 23 | * @len: length of received packet |
| 24 | * @return 0 if injected, -EAGAIN if not |
| 25 | */ |
| 26 | int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet, |
| 27 | unsigned int len); |
| 28 | |
| 29 | /* |
| 30 | * sandbox_eth_ping_req_to_reply() |
| 31 | * |
| 32 | * Check for a ping request to be sent. If so, inject a reply |
| 33 | * |
| 34 | * @dev: device that received the packet |
| 35 | * @packet: pointer to the received pacaket buffer |
| 36 | * @len: length of received packet |
| 37 | * @return 0 if injected, -EAGAIN if not |
| 38 | */ |
| 39 | int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet, |
| 40 | unsigned int len); |
| 41 | |
Joe Hershberger | 54418d0 | 2018-09-26 16:49:00 -0500 | [diff] [blame] | 42 | /* |
| 43 | * sandbox_eth_recv_arp_req() |
| 44 | * |
| 45 | * Inject an ARP request for this target |
| 46 | * |
| 47 | * @dev: device that received the packet |
| 48 | * @return 0 if injected, -EOVERFLOW if not |
| 49 | */ |
| 50 | int sandbox_eth_recv_arp_req(struct udevice *dev); |
| 51 | |
Joe Hershberger | 9716dc1 | 2018-09-26 16:49:01 -0500 | [diff] [blame] | 52 | /* |
| 53 | * sandbox_eth_recv_ping_req() |
| 54 | * |
| 55 | * Inject a ping request for this target |
| 56 | * |
| 57 | * @dev: device that received the packet |
| 58 | * @return 0 if injected, -EOVERFLOW if not |
| 59 | */ |
| 60 | int sandbox_eth_recv_ping_req(struct udevice *dev); |
| 61 | |
Joe Hershberger | 2260f13 | 2018-09-26 16:48:55 -0500 | [diff] [blame] | 62 | /** |
| 63 | * A packet handler |
| 64 | * |
| 65 | * dev - device pointer |
| 66 | * pkt - pointer to the "sent" packet |
| 67 | * len - packet length |
| 68 | */ |
| 69 | typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt, |
| 70 | unsigned int len); |
| 71 | |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 72 | /** |
| 73 | * struct eth_sandbox_priv - memory for sandbox mock driver |
| 74 | * |
| 75 | * fake_host_hwaddr - MAC address of mocked machine |
| 76 | * fake_host_ipaddr - IP address of mocked machine |
| 77 | * disabled - Will not respond |
Joe Hershberger | 46d2b6e | 2018-09-26 16:48:57 -0500 | [diff] [blame] | 78 | * recv_packet_buffer - buffers of the packet returned as received |
| 79 | * recv_packet_length - lengths of the packet returned as received |
| 80 | * recv_packets - number of packets returned |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 81 | * tx_handler - function to generate responses to sent packets |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 82 | * 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] | 83 | */ |
| 84 | struct eth_sandbox_priv { |
| 85 | uchar fake_host_hwaddr[ARP_HLEN]; |
| 86 | struct in_addr fake_host_ipaddr; |
| 87 | bool disabled; |
Joe Hershberger | 46d2b6e | 2018-09-26 16:48:57 -0500 | [diff] [blame] | 88 | uchar * recv_packet_buffer[PKTBUFSRX]; |
| 89 | int recv_packet_length[PKTBUFSRX]; |
| 90 | int recv_packets; |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 91 | sandbox_eth_tx_hand_f *tx_handler; |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 92 | void *priv; |
Joe Hershberger | c136307 | 2018-09-26 16:48:56 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
Joe Hershberger | 2260f13 | 2018-09-26 16:48:55 -0500 | [diff] [blame] | 95 | /* |
| 96 | * Set packet handler |
| 97 | * |
| 98 | * handler - The func ptr to call on send. If NULL, set to default handler |
| 99 | */ |
| 100 | void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler); |
| 101 | |
Joe Hershberger | 11b8503 | 2018-09-26 16:48:59 -0500 | [diff] [blame] | 102 | /* |
| 103 | * Set priv ptr |
| 104 | * |
| 105 | * priv - priv void ptr to store in the device |
| 106 | */ |
| 107 | void sandbox_eth_set_priv(int index, void *priv); |
| 108 | |
Joe Hershberger | a630b6c | 2015-03-22 17:09:19 -0500 | [diff] [blame] | 109 | #endif /* __ETH_H */ |