Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file arp.h \brief ARP Protocol Library. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'arp.h' |
||
5 | // Title : ARP Protocol Library |
||
6 | // Author : Pascal Stang |
||
7 | // Created : 9/7/2004 |
||
8 | // Revised : 7/3/2005 |
||
9 | // Version : 0.1 |
||
10 | // Target MCU : Atmel AVR series |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | /// \ingroup network |
||
14 | /// \defgroup arp ARP Protocol Library (arp.c) |
||
15 | /// \code #include "net/arp.h" \endcode |
||
16 | /// \par Description |
||
17 | /// To send anything over ethernet (or most any other physical network) |
||
18 | /// a packet must be addressed to a physical network node address, often |
||
19 | /// called a MAC/hardware/ethernet address. This MAC address identifies |
||
20 | /// a specific interface (like the ethernet card in your computer) on the |
||
21 | /// network. |
||
22 | /// ARP (Address Resolution Protocol) assists in mapping IP addresses to |
||
23 | /// the MAC addresses required to actually get data to its destination. |
||
24 | /// In other words, an IP address is not enough to send information over |
||
25 | /// ethernet. You need the MAC address of the network interface/card that |
||
26 | /// "owns" that IP address. ARP maintains a table mapping IP addresses to |
||
27 | /// MAC addresses. This table can be filled by both listening to |
||
28 | /// traffic on the network, as well as making specific ARP requests if |
||
29 | /// an IP<->MAC mapping is not in the table. |
||
30 | /// |
||
31 | /// \note This code is currently below version 1.0, and therefore is considered |
||
32 | /// to be lacking in some functionality or documentation, or may not be fully |
||
33 | /// tested. Nonetheless, you can expect most functions to work. |
||
34 | /// |
||
35 | // This code is distributed under the GNU Public License |
||
36 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
37 | //***************************************************************************** |
||
38 | //@{ |
||
39 | |||
40 | #ifndef ARP_H |
||
41 | #define ARP_H |
||
42 | |||
43 | #include "global.h" |
||
44 | #include "net.h" |
||
45 | |||
46 | #ifndef ARP_TABLE_SIZE |
||
47 | #define ARP_TABLE_SIZE 8 |
||
48 | #endif |
||
49 | |||
50 | #ifndef ARP_CACHE_TIME_TO_LIVE |
||
51 | #define ARP_CACHE_TIME_TO_LIVE 100 |
||
52 | #endif |
||
53 | |||
54 | //#define ARP_DEBUG_PRINT |
||
55 | |||
56 | |||
57 | /*! Initialize ARP system. |
||
58 | Clears ARP table and prepares it for use. This is typically done |
||
59 | once at program initialization. */ |
||
60 | void arpInit(void); |
||
61 | |||
62 | /*! Set IP and Ethernet hardware/MAC address. |
||
63 | This must be done before valid replies can be generated for ARP |
||
64 | requests. Typically done once at program initialization. */ |
||
65 | void arpSetAddress(struct netEthAddr* myeth, uint32_t myip); |
||
66 | |||
67 | /*! Processes incoming ARP packets. |
||
68 | This function is to be called when an ARP type packet has arrived |
||
69 | over the network. If the packet type is an ARP request for us, |
||
70 | an ARP reply will be generated and sent. */ |
||
71 | void arpArpIn(unsigned int len, struct netEthArpHeader* packet); |
||
72 | |||
73 | /*! Process incoming IP packets to harvest IP<->MAC relationships. |
||
74 | This function should be called when IP packets are received over the |
||
75 | network. It does nothing more than harvest the IP<->MAC address |
||
76 | relationships from the ethernet and IP header of the packet. The |
||
77 | packet is not changed nor processed. Nothing is sent on the network. |
||
78 | Use of this command is not required, but it is a good way to |
||
79 | automatically fill the ARP table with information about nodes that are |
||
80 | active on the network. |
||
81 | |||
82 | \warning On very busy or heavily populated netorks, this can quickly |
||
83 | fill the ARP table with unnecessary entries, and/or cause some CPU load. |
||
84 | */ |
||
85 | void arpIpIn(struct netEthIpHeader* packet); |
||
86 | |||
87 | /*! Process outgoing IP packet to fill in ethernet header information. |
||
88 | To be sent on a network, an IP packet must have the correct ethernet |
||
89 | header information appended to the front. This function will fill |
||
90 | in this information. |
||
91 | |||
92 | A physical destination IP address argument is needed to support |
||
93 | sending to a gateway (i.e. when a packet is destined for a node that |
||
94 | is not on this network, IP addressing is as usual, but we phyiscally |
||
95 | send the packet to the gateway's ethernet address/interface). |
||
96 | |||
97 | \warning Technically, if an IP<->MAC address mapping is not in the |
||
98 | ARP table, then the IP packet should be held while an ARP request is |
||
99 | made, and the reply received. However, in single-threaded ram-limited |
||
100 | embedded systems, such a holdup is unacceptable. This function instead |
||
101 | sends the packet as an ethernet broadcast if a mapping cannot be found. |
||
102 | |||
103 | \todo Send the packet broadcast AND send an ARP request, if a mapping |
||
104 | is not found. |
||
105 | */ |
||
106 | void arpIpOut(struct netEthIpHeader* packet, uint32_t phyDstIp); |
||
107 | |||
108 | /*! Periodic ARP cache maintenance. |
||
109 | This function is to be called once per second and will slowly |
||
110 | expire old ARP cache entries. */ |
||
111 | void arpTimer(void); |
||
112 | |||
113 | |||
114 | /*! Check if this IP address is present in the ARP cache. Internal function. |
||
115 | If IP address is found, function returns index of entry. If not found, |
||
116 | returns -1. */ |
||
117 | int arpMatchIp(uint32_t ipaddr); |
||
118 | |||
119 | //! Print diagnotic information about ARP packet. |
||
120 | void arpPrintHeader(struct netArpHeader* packet); |
||
121 | //! Print diagnotic information about ARP cache. |
||
122 | void arpPrintTable(void); |
||
123 | |||
124 | #endif |
||
125 | //@} |
Powered by WebSVN v2.8.3