1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/****************************************************************************
* include/nuttx/net/arp.h
* Macros and definitions for the ARP module.
*
* Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Derived from uIP with has a similar BSD-styple license:
*
* Author: Adam Dunkels <adam@dunkels.com>
* Copyright (c) 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_NET_ARP_H
#define __INCLUDE_NUTTX_NET_ARP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <net/ethernet.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/uip.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Recognized values of the type bytes in the Ethernet header */
#define UIP_ETHTYPE_ARP 0x0806 /* Address resolution protocol */
#define UIP_ETHTYPE_IP 0x0800 /* IP protocol */
#define UIP_ETHTYPE_IP6 0x86dd /* IP protocol version 6 */
/* Size of the Ethernet header */
#define UIP_ETHH_LEN 14 /* Minimum size: 2*6 + 2 */
/****************************************************************************
* Public Types
****************************************************************************/
/* The Ethernet header -- 14 bytes. The first two fields are type 'struct
* ether_addr but are represented as a simple byte array here because
* some compilers refuse to pack 6 byte structures.
*/
struct uip_eth_hdr
{
uint8_t dest[6]; /* Ethernet destination address (6 bytes) */
uint8_t src[6]; /* Ethernet source address (6 bytes) */
uint16_t type; /* Type code (2 bytes) */
};
/* One entry in the ARP table (volatile!) */
struct arp_entry
{
in_addr_t at_ipaddr; /* IP address */
struct ether_addr at_ethaddr; /* Hardware address */
uint8_t at_time;
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef CONFIG_NET_ARP
/****************************************************************************
* Name: arp_init
*
* Description:
* Initialize the ARP module. This function must be called before any of
* the other ARP functions.
*
****************************************************************************/
void arp_init(void);
/****************************************************************************
* Name: arp_ipin
*
* Description:
* The arp_ipin() function should be called whenever an IP packet
* arrives from the Ethernet. This function refreshes the ARP table or
* inserts a new mapping if none exists. The function assumes that an
* IP packet with an Ethernet header is present in the d_buf buffer
* and that the length of the packet is in the d_len field.
*
****************************************************************************/
#ifdef CONFIG_NET_ARP_IPIN
void arp_ipin(struct uip_driver_s *dev);
#else
# define arp_ipin(dev)
#endif
/****************************************************************************
* Name: arp_arpin
*
* Description:
* The arp_arpin() should be called when an ARP packet is received
* by the Ethernet driver. This function also assumes that the
* Ethernet frame is present in the d_buf buffer. When the
* arp_arpin() function returns, the contents of the d_buf
* buffer should be sent out on the Ethernet if the d_len field
* is > 0.
*
****************************************************************************/
void arp_arpin(struct uip_driver_s *dev);
/****************************************************************************
* Name: arp_arpin
*
* Description:
* The arp_out() function should be called when an IP packet
* should be sent out on the Ethernet. This function creates an
* Ethernet header before the IP header in the d_buf buffer. The
* Ethernet header will have the correct Ethernet MAC destination
* address filled in if an ARP table entry for the destination IP
* address (or the IP address of the default router) is present. If no
* such table entry is found, the IP packet is overwritten with an ARP
* request and we rely on TCP to retransmit the packet that was
* overwritten. In any case, the d_len field holds the length of
* the Ethernet frame that should be transmitted.
*
****************************************************************************/
void arp_out(struct uip_driver_s *dev);
/****************************************************************************
* Function: arp_timer_init
*
* Description:
* Initialized the 10 second timer that is need by uIP to age ARP
* associations
*
* Parameters:
* None
*
* Returned Value:
* None
*
* Assumptions:
* Called once at system initialization time
*
****************************************************************************/
void arp_timer_init(void);
/****************************************************************************
* Name: arp_timer
*
* Description:
* This function performs periodic timer processing in the ARP module
* and should be called at regular intervals. The recommended interval
* is 10 seconds between the calls. It is responsible for flushing old
* entries in the ARP table.
*
****************************************************************************/
void arp_timer(void);
/****************************************************************************
* Name: arp_update
*
* Description:
* Add the IP/HW address mapping to the ARP table -OR- change the IP
* address of an existing association.
*
* Input parameters:
* pipaddr - Refers to an IP address uint16_t[2] in network order
* ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN]
*
* Assumptions
* Interrupts are disabled
*
****************************************************************************/
void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
/****************************************************************************
* Name: arp_find
*
* Description:
* Find the ARP entry corresponding to this IP address.
*
* Input parameters:
* ipaddr - Refers to an IP address in network order
*
* Assumptions
* Interrupts are disabled; Returned value will become unstable when
* interrupts are re-enabled or if any other uIP APIs are called.
*
****************************************************************************/
struct arp_entry *arp_find(in_addr_t ipaddr);
/****************************************************************************
* Name: arp_delete
*
* Description:
* Remove an IP association from the ARP table
*
* Input parameters:
* ipaddr - Refers to an IP address in network order
*
* Assumptions
* Interrupts are disabled
*
****************************************************************************/
#define arp_delete(ipaddr) \
{ \
struct arp_entry *tabptr = arp_find(ipaddr); \
if (tabptr) \
{ \
tabptr->at_ipaddr = 0; \
} \
}
#else /* CONFIG_NET_ARP */
/* If ARP is disabled, stub out all ARP interfaces */
# define arp_init()
# define arp_ipin(dev)
# define arp_arpin(dev)
# define arp_out(dev)
# define arp_timer()
# define arp_update(pipaddr,ethaddr)
# define arp_find(ipaddr) NULL
# define arp_delete(ipaddr)
# define arp_timer_init(void);
#endif /* CONFIG_NET_ARP */
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_NET_ARP_H */
|