eth.h 2.7 KB

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