]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/uIP_Demo_Rowley_ARM7/uip/uip_arp.h
bf9049888c48c463f7e3b10fd44d47432213f4ea
[freertos] / FreeRTOS / Demo / uIP_Demo_Rowley_ARM7 / uip / uip_arp.h
1 /**\r
2  * \addtogroup uip\r
3  * @{\r
4  */\r
5 \r
6 /**\r
7  * \addtogroup uiparp \r
8  * @{\r
9  */\r
10  \r
11 /**\r
12  * \file\r
13  * Macros and definitions for the ARP module.\r
14  * \author Adam Dunkels <adam@dunkels.com>\r
15  */\r
16   \r
17 \r
18 /*\r
19  * Copyright (c) 2001-2003, Adam Dunkels.\r
20  * All rights reserved. \r
21  *\r
22  * Redistribution and use in source and binary forms, with or without \r
23  * modification, are permitted provided that the following conditions \r
24  * are met: \r
25  * 1. Redistributions of source code must retain the above copyright \r
26  *    notice, this list of conditions and the following disclaimer. \r
27  * 2. Redistributions in binary form must reproduce the above copyright \r
28  *    notice, this list of conditions and the following disclaimer in the \r
29  *    documentation and/or other materials provided with the distribution. \r
30  * 3. The name of the author may not be used to endorse or promote\r
31  *    products derived from this software without specific prior\r
32  *    written permission.  \r
33  *\r
34  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
35  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
36  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
37  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
38  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
40  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
41  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  \r
45  *\r
46  * This file is part of the uIP TCP/IP stack.\r
47  *\r
48  * $Id: uip_arp.h,v 1.3.2.2 2003/10/06 15:10:22 adam Exp $\r
49  *\r
50  */\r
51 \r
52 #ifndef __UIP_ARP_H__\r
53 #define __UIP_ARP_H__\r
54 \r
55 #include "uip.h"\r
56 \r
57 \r
58 /**\r
59  * Representation of a 48-bit Ethernet address.\r
60  */\r
61 struct uip_eth_addr {\r
62   u8_t addr[6];\r
63 } __attribute__ ((packed, aligned (1)));\r
64 \r
65 extern struct uip_eth_addr uip_ethaddr;\r
66 \r
67 /**\r
68  * The Ethernet header. \r
69  */\r
70 struct uip_eth_hdr {\r
71   struct uip_eth_addr dest;\r
72   struct uip_eth_addr src;\r
73   u16_t type;\r
74 } __attribute__ ((packed));\r
75 \r
76 #define UIP_ETHTYPE_ARP 0x0806\r
77 #define UIP_ETHTYPE_IP  0x0800\r
78 #define UIP_ETHTYPE_IP6 0x86dd \r
79 \r
80 \r
81 /* The uip_arp_init() function must be called before any of the other\r
82    ARP functions. */\r
83 void uip_arp_init(void);\r
84 \r
85 /* The uip_arp_ipin() function should be called whenever an IP packet\r
86    arrives from the Ethernet. This function refreshes the ARP table or\r
87    inserts a new mapping if none exists. The function assumes that an\r
88    IP packet with an Ethernet header is present in the uip_buf buffer\r
89    and that the length of the packet is in the uip_len variable. */\r
90 void uip_arp_ipin(void);\r
91 \r
92 /* The uip_arp_arpin() should be called when an ARP packet is received\r
93    by the Ethernet driver. This function also assumes that the\r
94    Ethernet frame is present in the uip_buf buffer. When the\r
95    uip_arp_arpin() function returns, the contents of the uip_buf\r
96    buffer should be sent out on the Ethernet if the uip_len variable\r
97    is > 0. */\r
98 void uip_arp_arpin(void);\r
99 \r
100 /* The uip_arp_out() function should be called when an IP packet\r
101    should be sent out on the Ethernet. This function creates an\r
102    Ethernet header before the IP header in the uip_buf buffer. The\r
103    Ethernet header will have the correct Ethernet MAC destination\r
104    address filled in if an ARP table entry for the destination IP\r
105    address (or the IP address of the default router) is present. If no\r
106    such table entry is found, the IP packet is overwritten with an ARP\r
107    request and we rely on TCP to retransmit the packet that was\r
108    overwritten. In any case, the uip_len variable holds the length of\r
109    the Ethernet frame that should be transmitted. */\r
110 void uip_arp_out(void);\r
111 \r
112 /* The uip_arp_timer() function should be called every ten seconds. It\r
113    is responsible for flushing old entries in the ARP table. */\r
114 void uip_arp_timer(void);\r
115 \r
116 /** @} */\r
117 \r
118 /**\r
119  * \addtogroup uipconffunc\r
120  * @{\r
121  */\r
122 \r
123 /**\r
124  * Set the default router's IP address.\r
125  *\r
126  * \param addr A pointer to a 4-byte array containing the IP address\r
127  * of the default router.\r
128  *\r
129  * \hideinitializer\r
130  */\r
131 #define uip_setdraddr(addr) do { uip_arp_draddr[0] = addr[0]; \\r
132                                  uip_arp_draddr[1] = addr[1]; } while(0)\r
133 \r
134 /**\r
135  * Set the netmask.\r
136  *\r
137  * \param addr A pointer to a 4-byte array containing the IP address\r
138  * of the netmask.\r
139  *\r
140  * \hideinitializer\r
141  */\r
142 #define uip_setnetmask(addr) do { uip_arp_netmask[0] = addr[0]; \\r
143                                   uip_arp_netmask[1] = addr[1]; } while(0)\r
144 \r
145 \r
146 /**\r
147  * Get the default router's IP address.\r
148  *\r
149  * \param addr A pointer to a 4-byte array that will be filled in with\r
150  * the IP address of the default router.\r
151  *\r
152  * \hideinitializer\r
153  */\r
154 #define uip_getdraddr(addr) do { addr[0] = uip_arp_draddr[0]; \\r
155                                  addr[1] = uip_arp_draddr[1]; } while(0)\r
156 \r
157 /**\r
158  * Get the netmask.\r
159  *\r
160  * \param addr A pointer to a 4-byte array that will be filled in with\r
161  * the value of the netmask.\r
162  *\r
163  * \hideinitializer\r
164  */\r
165 #define uip_getnetmask(addr) do { addr[0] = uip_arp_netmask[0]; \\r
166                                   addr[1] = uip_arp_netmask[1]; } while(0)\r
167 \r
168 \r
169 /**\r
170  * Specifiy the Ethernet MAC address.\r
171  *\r
172  * The ARP code needs to know the MAC address of the Ethernet card in\r
173  * order to be able to respond to ARP queries and to generate working\r
174  * Ethernet headers.\r
175  *\r
176  * \note This macro only specifies the Ethernet MAC address to the ARP\r
177  * code. It cannot be used to change the MAC address of the Ethernet\r
178  * card.\r
179  *\r
180  * \param eaddr A pointer to a struct uip_eth_addr containing the\r
181  * Ethernet MAC address of the Ethernet card.\r
182  *\r
183  * \hideinitializer\r
184  */\r
185 #define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \\r
186                               uip_ethaddr.addr[1] = eaddr.addr[1];\\r
187                               uip_ethaddr.addr[2] = eaddr.addr[2];\\r
188                               uip_ethaddr.addr[3] = eaddr.addr[3];\\r
189                               uip_ethaddr.addr[4] = eaddr.addr[4];\\r
190                               uip_ethaddr.addr[5] = eaddr.addr[5];} while(0)\r
191 \r
192 /** @} */\r
193 \r
194 /**\r
195  * \internal Internal variables that are set using the macros\r
196  * uip_setdraddr and uip_setnetmask.\r
197  */\r
198 extern u16_t uip_arp_draddr[2], uip_arp_netmask[2];\r
199 #endif /* __UIP_ARP_H__ */\r
200 \r
201 \r