Procházet zdrojové kódy

Added from uip-0.9/uip/uip_arp.[ch]

tags/v0.9.3
Michael Brown před 18 roky
rodič
revize
bb37bd47f8
2 změnil soubory, kde provedl 624 přidání a 0 odebrání
  1. 423
    0
      src/proto/uip/uip_arp.c
  2. 201
    0
      src/proto/uip/uip_arp.h

+ 423
- 0
src/proto/uip/uip_arp.c Zobrazit soubor

@@ -0,0 +1,423 @@
1
+/**
2
+ * \addtogroup uip
3
+ * @{
4
+ */
5
+
6
+/**
7
+ * \defgroup uiparp uIP Address Resolution Protocol
8
+ * @{
9
+ * 
10
+ * The Address Resolution Protocol ARP is used for mapping between IP
11
+ * addresses and link level addresses such as the Ethernet MAC
12
+ * addresses. ARP uses broadcast queries to ask for the link level
13
+ * address of a known IP address and the host which is configured with
14
+ * the IP address for which the query was meant, will respond with its
15
+ * link level address.
16
+ *
17
+ * \note This ARP implementation only supports Ethernet.
18
+ */
19
+ 
20
+/**
21
+ * \file
22
+ * Implementation of the ARP Address Resolution Protocol.
23
+ * \author Adam Dunkels <adam@dunkels.com>
24
+ *
25
+ */
26
+
27
+/*
28
+ * Copyright (c) 2001-2003, Adam Dunkels.
29
+ * All rights reserved. 
30
+ *
31
+ * Redistribution and use in source and binary forms, with or without 
32
+ * modification, are permitted provided that the following conditions 
33
+ * are met: 
34
+ * 1. Redistributions of source code must retain the above copyright 
35
+ *    notice, this list of conditions and the following disclaimer. 
36
+ * 2. Redistributions in binary form must reproduce the above copyright 
37
+ *    notice, this list of conditions and the following disclaimer in the 
38
+ *    documentation and/or other materials provided with the distribution. 
39
+ * 3. The name of the author may not be used to endorse or promote
40
+ *    products derived from this software without specific prior
41
+ *    written permission.  
42
+ *
43
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
44
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
47
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
54
+ *
55
+ * This file is part of the uIP TCP/IP stack.
56
+ *
57
+ * $Id$
58
+ *
59
+ */
60
+
61
+
62
+#include "uip_arp.h"
63
+
64
+#include <string.h>
65
+
66
+struct arp_hdr {
67
+  struct uip_eth_hdr ethhdr;
68
+  u16_t hwtype;
69
+  u16_t protocol;
70
+  u8_t hwlen;
71
+  u8_t protolen;
72
+  u16_t opcode;
73
+  struct uip_eth_addr shwaddr;
74
+  u16_t sipaddr[2];
75
+  struct uip_eth_addr dhwaddr;
76
+  u16_t dipaddr[2]; 
77
+};
78
+
79
+struct ethip_hdr {
80
+  struct uip_eth_hdr ethhdr;
81
+  /* IP header. */
82
+  u8_t vhl,
83
+    tos,          
84
+    len[2],       
85
+    ipid[2],        
86
+    ipoffset[2],  
87
+    ttl,          
88
+    proto;     
89
+  u16_t ipchksum;
90
+  u16_t srcipaddr[2], 
91
+    destipaddr[2];
92
+};
93
+
94
+#define ARP_REQUEST 1
95
+#define ARP_REPLY   2
96
+
97
+#define ARP_HWTYPE_ETH 1
98
+
99
+struct arp_entry {
100
+  u16_t ipaddr[2];
101
+  struct uip_eth_addr ethaddr;
102
+  u8_t time;
103
+};
104
+
105
+struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
106
+				    UIP_ETHADDR1,
107
+				    UIP_ETHADDR2,
108
+				    UIP_ETHADDR3,
109
+				    UIP_ETHADDR4,
110
+				    UIP_ETHADDR5}};
111
+
112
+static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
113
+static u16_t ipaddr[2];
114
+static u8_t i, c;
115
+
116
+static u8_t arptime;
117
+static u8_t tmpage;
118
+
119
+#define BUF   ((struct arp_hdr *)&uip_buf[0])
120
+#define IPBUF ((struct ethip_hdr *)&uip_buf[0])
121
+/*-----------------------------------------------------------------------------------*/
122
+/**
123
+ * Initialize the ARP module.
124
+ *
125
+ */
126
+/*-----------------------------------------------------------------------------------*/
127
+void
128
+uip_arp_init(void)
129
+{
130
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
131
+    memset(arp_table[i].ipaddr, 0, 4);
132
+  }
133
+}
134
+/*-----------------------------------------------------------------------------------*/
135
+/**
136
+ * Periodic ARP processing function.
137
+ *
138
+ * This function performs periodic timer processing in the ARP module
139
+ * and should be called at regular intervals. The recommended interval
140
+ * is 10 seconds between the calls.
141
+ *
142
+ */
143
+/*-----------------------------------------------------------------------------------*/
144
+void
145
+uip_arp_timer(void)
146
+{
147
+  struct arp_entry *tabptr;
148
+  
149
+  ++arptime;
150
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
151
+    tabptr = &arp_table[i];
152
+    if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
153
+       arptime - tabptr->time >= UIP_ARP_MAXAGE) {
154
+      memset(tabptr->ipaddr, 0, 4);
155
+    }
156
+  }
157
+
158
+}
159
+/*-----------------------------------------------------------------------------------*/
160
+static void
161
+uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
162
+{
163
+  register struct arp_entry *tabptr;
164
+  /* Walk through the ARP mapping table and try to find an entry to
165
+     update. If none is found, the IP -> MAC address mapping is
166
+     inserted in the ARP table. */
167
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
168
+
169
+    tabptr = &arp_table[i];
170
+    /* Only check those entries that are actually in use. */
171
+    if(tabptr->ipaddr[0] != 0 &&
172
+       tabptr->ipaddr[1] != 0) {
173
+
174
+      /* Check if the source IP address of the incoming packet matches
175
+         the IP address in this ARP table entry. */
176
+      if(ipaddr[0] == tabptr->ipaddr[0] &&
177
+	 ipaddr[1] == tabptr->ipaddr[1]) {
178
+	 
179
+	/* An old entry found, update this and return. */
180
+	memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
181
+	tabptr->time = arptime;
182
+
183
+	return;
184
+      }
185
+    }
186
+  }
187
+
188
+  /* If we get here, no existing ARP table entry was found, so we
189
+     create one. */
190
+
191
+  /* First, we try to find an unused entry in the ARP table. */
192
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
193
+    tabptr = &arp_table[i];
194
+    if(tabptr->ipaddr[0] == 0 &&
195
+       tabptr->ipaddr[1] == 0) {
196
+      break;
197
+    }
198
+  }
199
+
200
+  /* If no unused entry is found, we try to find the oldest entry and
201
+     throw it away. */
202
+  if(i == UIP_ARPTAB_SIZE) {
203
+    tmpage = 0;
204
+    c = 0;
205
+    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
206
+      tabptr = &arp_table[i];
207
+      if(arptime - tabptr->time > tmpage) {
208
+	tmpage = arptime - tabptr->time;
209
+	c = i;
210
+      }
211
+    }
212
+    i = c;
213
+  }
214
+
215
+  /* Now, i is the ARP table entry which we will fill with the new
216
+     information. */
217
+  memcpy(tabptr->ipaddr, ipaddr, 4);
218
+  memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
219
+  tabptr->time = arptime;
220
+}
221
+/*-----------------------------------------------------------------------------------*/
222
+/**
223
+ * ARP processing for incoming IP packets
224
+ *
225
+ * This function should be called by the device driver when an IP
226
+ * packet has been received. The function will check if the address is
227
+ * in the ARP cache, and if so the ARP cache entry will be
228
+ * refreshed. If no ARP cache entry was found, a new one is created.
229
+ *
230
+ * This function expects an IP packet with a prepended Ethernet header
231
+ * in the uip_buf[] buffer, and the length of the packet in the global
232
+ * variable uip_len.
233
+ */
234
+/*-----------------------------------------------------------------------------------*/
235
+void
236
+uip_arp_ipin(void)
237
+{
238
+  uip_len -= sizeof(struct uip_eth_hdr);
239
+	
240
+  /* Only insert/update an entry if the source IP address of the
241
+     incoming IP packet comes from a host on the local network. */
242
+  if((IPBUF->srcipaddr[0] & uip_arp_netmask[0]) !=
243
+     (uip_hostaddr[0] & uip_arp_netmask[0])) {
244
+    return;
245
+  }
246
+  if((IPBUF->srcipaddr[1] & uip_arp_netmask[1]) !=
247
+     (uip_hostaddr[1] & uip_arp_netmask[1])) {
248
+    return;
249
+  }
250
+  uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
251
+  
252
+  return;
253
+}
254
+/*-----------------------------------------------------------------------------------*/
255
+/**
256
+ * ARP processing for incoming ARP packets.
257
+ *
258
+ * This function should be called by the device driver when an ARP
259
+ * packet has been received. The function will act differently
260
+ * depending on the ARP packet type: if it is a reply for a request
261
+ * that we previously sent out, the ARP cache will be filled in with
262
+ * the values from the ARP reply. If the incoming ARP packet is an ARP
263
+ * request for our IP address, an ARP reply packet is created and put
264
+ * into the uip_buf[] buffer.
265
+ *
266
+ * When the function returns, the value of the global variable uip_len
267
+ * indicates whether the device driver should send out a packet or
268
+ * not. If uip_len is zero, no packet should be sent. If uip_len is
269
+ * non-zero, it contains the length of the outbound packet that is
270
+ * present in the uip_buf[] buffer.
271
+ *
272
+ * This function expects an ARP packet with a prepended Ethernet
273
+ * header in the uip_buf[] buffer, and the length of the packet in the
274
+ * global variable uip_len.
275
+ */
276
+/*-----------------------------------------------------------------------------------*/
277
+void
278
+uip_arp_arpin(void)
279
+{
280
+
281
+  if(uip_len < sizeof(struct arp_hdr)) {
282
+    uip_len = 0;
283
+    return;
284
+  }
285
+
286
+  uip_len = 0;
287
+
288
+  switch(BUF->opcode) {
289
+  case HTONS(ARP_REQUEST):
290
+    /* ARP request. If it asked for our address, we send out a
291
+       reply. */
292
+    if(BUF->dipaddr[0] == uip_hostaddr[0] &&
293
+       BUF->dipaddr[1] == uip_hostaddr[1]) {
294
+      /* The reply opcode is 2. */
295
+      BUF->opcode = HTONS(2);
296
+
297
+      memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
298
+      memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
299
+      memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
300
+      memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
301
+      
302
+      BUF->dipaddr[0] = BUF->sipaddr[0];
303
+      BUF->dipaddr[1] = BUF->sipaddr[1];
304
+      BUF->sipaddr[0] = uip_hostaddr[0];
305
+      BUF->sipaddr[1] = uip_hostaddr[1];
306
+
307
+      BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);      
308
+      uip_len = sizeof(struct arp_hdr);
309
+    }      
310
+    break;
311
+  case HTONS(ARP_REPLY):
312
+    /* ARP reply. We insert or update the ARP table if it was meant
313
+       for us. */
314
+    if(BUF->dipaddr[0] == uip_hostaddr[0] &&
315
+       BUF->dipaddr[1] == uip_hostaddr[1]) {
316
+
317
+      uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
318
+    }
319
+    break;
320
+  }
321
+
322
+  return;
323
+}
324
+/*-----------------------------------------------------------------------------------*/
325
+/**
326
+ * Prepend Ethernet header to an outbound IP packet and see if we need
327
+ * to send out an ARP request.
328
+ *
329
+ * This function should be called before sending out an IP packet. The
330
+ * function checks the destination IP address of the IP packet to see
331
+ * what Ethernet MAC address that should be used as a destination MAC
332
+ * address on the Ethernet.
333
+ *
334
+ * If the destination IP address is in the local network (determined
335
+ * by logical ANDing of netmask and our IP address), the function
336
+ * checks the ARP cache to see if an entry for the destination IP
337
+ * address is found. If so, an Ethernet header is prepended and the
338
+ * function returns. If no ARP cache entry is found for the
339
+ * destination IP address, the packet in the uip_buf[] is replaced by
340
+ * an ARP request packet for the IP address. The IP packet is dropped
341
+ * and it is assumed that they higher level protocols (e.g., TCP)
342
+ * eventually will retransmit the dropped packet.
343
+ *
344
+ * If the destination IP address is not on the local network, the IP
345
+ * address of the default router is used instead.
346
+ *
347
+ * When the function returns, a packet is present in the uip_buf[]
348
+ * buffer, and the length of the packet is in the global variable
349
+ * uip_len.
350
+ */
351
+/*-----------------------------------------------------------------------------------*/
352
+void
353
+uip_arp_out(void)
354
+{
355
+  struct arp_entry *tabptr;
356
+  /* Find the destination IP address in the ARP table and construct
357
+     the Ethernet header. If the destination IP addres isn't on the
358
+     local network, we use the default router's IP address instead.
359
+
360
+     If not ARP table entry is found, we overwrite the original IP
361
+     packet with an ARP request for the IP address. */
362
+
363
+  /* Check if the destination address is on the local network. */
364
+  if((IPBUF->destipaddr[0] & uip_arp_netmask[0]) !=
365
+     (uip_hostaddr[0] & uip_arp_netmask[0]) ||
366
+     (IPBUF->destipaddr[1] & uip_arp_netmask[1]) !=
367
+     (uip_hostaddr[1] & uip_arp_netmask[1])) {
368
+    /* Destination address was not on the local network, so we need to
369
+       use the default router's IP address instead of the destination
370
+       address when determining the MAC address. */
371
+    ipaddr[0] = uip_arp_draddr[0];
372
+    ipaddr[1] = uip_arp_draddr[1];
373
+  } else {
374
+    /* Else, we use the destination IP address. */
375
+    ipaddr[0] = IPBUF->destipaddr[0];
376
+    ipaddr[1] = IPBUF->destipaddr[1];
377
+  }
378
+      
379
+  for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
380
+    tabptr = &arp_table[i];
381
+    if(ipaddr[0] == tabptr->ipaddr[0] &&
382
+       ipaddr[1] == tabptr->ipaddr[1])
383
+      break;
384
+  }
385
+
386
+  if(i == UIP_ARPTAB_SIZE) {
387
+    /* The destination address was not in our ARP table, so we
388
+       overwrite the IP packet with an ARP request. */
389
+
390
+    memset(BUF->ethhdr.dest.addr, 0xff, 6);
391
+    memset(BUF->dhwaddr.addr, 0x00, 6);
392
+    memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
393
+    memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
394
+    
395
+    BUF->dipaddr[0] = ipaddr[0];
396
+    BUF->dipaddr[1] = ipaddr[1];
397
+    BUF->sipaddr[0] = uip_hostaddr[0];
398
+    BUF->sipaddr[1] = uip_hostaddr[1];
399
+    BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
400
+    BUF->hwtype = HTONS(ARP_HWTYPE_ETH);
401
+    BUF->protocol = HTONS(UIP_ETHTYPE_IP);
402
+    BUF->hwlen = 6;
403
+    BUF->protolen = 4;
404
+    BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
405
+
406
+    uip_appdata = &uip_buf[40 + UIP_LLH_LEN];
407
+    
408
+    uip_len = sizeof(struct arp_hdr);
409
+    return;
410
+  }
411
+
412
+  /* Build an ethernet header. */
413
+  memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
414
+  memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
415
+  
416
+  IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
417
+
418
+  uip_len += sizeof(struct uip_eth_hdr);
419
+}
420
+/*-----------------------------------------------------------------------------------*/
421
+
422
+/** @} */
423
+/** @} */

+ 201
- 0
src/proto/uip/uip_arp.h Zobrazit soubor

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

Načítá se…
Zrušit
Uložit