Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uip_arp.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * \addtogroup uip
  3. * @{
  4. */
  5. /**
  6. * \addtogroup uiparp
  7. * @{
  8. */
  9. /**
  10. * \file
  11. * Macros and definitions for the ARP module.
  12. * \author Adam Dunkels <[email protected]>
  13. */
  14. /*
  15. * Copyright (c) 2001-2003, Adam Dunkels.
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted provided that the following conditions
  20. * are met:
  21. * 1. Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright
  24. * notice, this list of conditions and the following disclaimer in the
  25. * documentation and/or other materials provided with the distribution.
  26. * 3. The name of the author may not be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  32. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  34. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  38. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  39. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41. *
  42. * This file is part of the uIP TCP/IP stack.
  43. *
  44. * $Id: uip_arp.h,v 1.2 2006/08/26 23:58:45 oliverschmidt Exp $
  45. *
  46. */
  47. #ifndef __UIP_ARP_H__
  48. #define __UIP_ARP_H__
  49. #include "uip.h"
  50. extern struct uip_eth_addr uip_ethaddr;
  51. /**
  52. * The Ethernet header.
  53. */
  54. struct uip_eth_hdr {
  55. struct uip_eth_addr dest;
  56. struct uip_eth_addr src;
  57. u16_t type;
  58. };
  59. #define UIP_ETHTYPE_ARP 0x0806
  60. #define UIP_ETHTYPE_IP 0x0800
  61. #define UIP_ETHTYPE_IPV6 0x86dd
  62. /* The uip_arp_init() function must be called before any of the other
  63. ARP functions. */
  64. void uip_arp_init(void);
  65. /* The uip_arp_ipin() function should be called whenever an IP packet
  66. arrives from the Ethernet. This function refreshes the ARP table or
  67. inserts a new mapping if none exists. The function assumes that an
  68. IP packet with an Ethernet header is present in the uip_buf buffer
  69. and that the length of the packet is in the uip_len variable. */
  70. /*void uip_arp_ipin(void);*/
  71. #define uip_arp_ipin()
  72. /* The uip_arp_arpin() should be called when an ARP packet is received
  73. by the Ethernet driver. This function also assumes that the
  74. Ethernet frame is present in the uip_buf buffer. When the
  75. uip_arp_arpin() function returns, the contents of the uip_buf
  76. buffer should be sent out on the Ethernet if the uip_len variable
  77. is > 0. */
  78. void uip_arp_arpin(void);
  79. /* The uip_arp_out() function should be called when an IP packet
  80. should be sent out on the Ethernet. This function creates an
  81. Ethernet header before the IP header in the uip_buf buffer. The
  82. Ethernet header will have the correct Ethernet MAC destination
  83. address filled in if an ARP table entry for the destination IP
  84. address (or the IP address of the default router) is present. If no
  85. such table entry is found, the IP packet is overwritten with an ARP
  86. request and we rely on TCP to retransmit the packet that was
  87. overwritten. In any case, the uip_len variable holds the length of
  88. the Ethernet frame that should be transmitted. */
  89. void uip_arp_out(void);
  90. /* The uip_arp_timer() function should be called every ten seconds. It
  91. is responsible for flushing old entries in the ARP table. */
  92. void uip_arp_timer(void);
  93. /** @} */
  94. /**
  95. * \addtogroup uipconffunc
  96. * @{
  97. */
  98. /**
  99. * Specifiy the Ethernet MAC address.
  100. *
  101. * The ARP code needs to know the MAC address of the Ethernet card in
  102. * order to be able to respond to ARP queries and to generate working
  103. * Ethernet headers.
  104. *
  105. * \note This macro only specifies the Ethernet MAC address to the ARP
  106. * code. It cannot be used to change the MAC address of the Ethernet
  107. * card.
  108. *
  109. * \param eaddr A pointer to a struct uip_eth_addr containing the
  110. * Ethernet MAC address of the Ethernet card.
  111. *
  112. * \hideinitializer
  113. */
  114. #define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \
  115. uip_ethaddr.addr[1] = eaddr.addr[1];\
  116. uip_ethaddr.addr[2] = eaddr.addr[2];\
  117. uip_ethaddr.addr[3] = eaddr.addr[3];\
  118. uip_ethaddr.addr[4] = eaddr.addr[4];\
  119. uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)
  120. /** @} */
  121. #endif /* __UIP_ARP_H__ */
  122. /** @} */