]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_ARP.h
Added +TCP code to main repo.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / include / FreeRTOS_ARP.h
1 /*\r
2  * FreeRTOS+TCP Labs Build 160919 (C) 2016 Real Time Engineers ltd.\r
3  * Authors include Hein Tibosch and Richard Barry\r
4  *\r
5  *******************************************************************************\r
6  ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
7  ***                                                                         ***\r
8  ***                                                                         ***\r
9  ***   FREERTOS+TCP IS STILL IN THE LAB (mainly because the FTP and HTTP     ***\r
10  ***   demos have a dependency on FreeRTOS+FAT, which is only in the Labs    ***\r
11  ***   download):                                                            ***\r
12  ***                                                                         ***\r
13  ***   FreeRTOS+TCP is functional and has been used in commercial products   ***\r
14  ***   for some time.  Be aware however that we are still refining its       ***\r
15  ***   design, the source code does not yet quite conform to the strict      ***\r
16  ***   coding and style standards mandated by Real Time Engineers ltd., and  ***\r
17  ***   the documentation and testing is not necessarily complete.            ***\r
18  ***                                                                         ***\r
19  ***   PLEASE REPORT EXPERIENCES USING THE SUPPORT RESOURCES FOUND ON THE    ***\r
20  ***   URL: http://www.FreeRTOS.org/contact  Active early adopters may, at   ***\r
21  ***   the sole discretion of Real Time Engineers Ltd., be offered versions  ***\r
22  ***   under a license other than that described below.                      ***\r
23  ***                                                                         ***\r
24  ***                                                                         ***\r
25  ***** NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ******* NOTE ***\r
26  *******************************************************************************\r
27  *\r
28  * FreeRTOS+TCP can be used under two different free open source licenses.  The\r
29  * license that applies is dependent on the processor on which FreeRTOS+TCP is\r
30  * executed, as follows:\r
31  *\r
32  * If FreeRTOS+TCP is executed on one of the processors listed under the Special\r
33  * License Arrangements heading of the FreeRTOS+TCP license information web\r
34  * page, then it can be used under the terms of the FreeRTOS Open Source\r
35  * License.  If FreeRTOS+TCP is used on any other processor, then it can be used\r
36  * under the terms of the GNU General Public License V2.  Links to the relevant\r
37  * licenses follow:\r
38  *\r
39  * The FreeRTOS+TCP License Information Page: http://www.FreeRTOS.org/tcp_license\r
40  * The FreeRTOS Open Source License: http://www.FreeRTOS.org/license\r
41  * The GNU General Public License Version 2: http://www.FreeRTOS.org/gpl-2.0.txt\r
42  *\r
43  * FreeRTOS+TCP is distributed in the hope that it will be useful.  You cannot\r
44  * use FreeRTOS+TCP unless you agree that you use the software 'as is'.\r
45  * FreeRTOS+TCP is provided WITHOUT ANY WARRANTY; without even the implied\r
46  * warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
47  * PURPOSE. Real Time Engineers Ltd. disclaims all conditions and terms, be they\r
48  * implied, expressed, or statutory.\r
49  *\r
50  * 1 tab == 4 spaces!\r
51  *\r
52  * http://www.FreeRTOS.org\r
53  * http://www.FreeRTOS.org/plus\r
54  * http://www.FreeRTOS.org/labs\r
55  *\r
56  */\r
57 \r
58 #ifndef FREERTOS_ARP_H\r
59 #define FREERTOS_ARP_H\r
60 \r
61 #ifdef __cplusplus\r
62 extern "C" {\r
63 #endif\r
64 \r
65 /* Application level configuration options. */\r
66 #include "FreeRTOSIPConfig.h"\r
67 #include "FreeRTOSIPConfigDefaults.h"\r
68 #include "IPTraceMacroDefaults.h"\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 /* Miscellaneous structure and definitions. */\r
72 /*-----------------------------------------------------------*/\r
73 \r
74 typedef struct xARP_CACHE_TABLE_ROW\r
75 {\r
76         uint32_t ulIPAddress;           /* The IP address of an ARP cache entry. */\r
77         MACAddress_t xMACAddress;  /* The MAC address of an ARP cache entry. */\r
78         uint8_t ucAge;                          /* A value that is periodically decremented but can also be refreshed by active communication.  The ARP cache entry is removed if the value reaches zero. */\r
79     uint8_t ucValid;                    /* pdTRUE: xMACAddress is valid, pdFALSE: waiting for ARP reply */\r
80 } ARPCacheRow_t;\r
81 \r
82 typedef enum\r
83 {\r
84         eARPCacheMiss = 0,                      /* 0 An ARP table lookup did not find a valid entry. */\r
85         eARPCacheHit,                           /* 1 An ARP table lookup found a valid entry. */\r
86         eCantSendPacket                         /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */\r
87 } eARPLookupResult_t;\r
88 \r
89 typedef enum\r
90 {\r
91         eNotFragment = 0,                       /* The IP packet being sent is not part of a fragment. */\r
92         eFirstFragment,                         /* The IP packet being sent is the first in a set of fragmented packets. */\r
93         eFollowingFragment                      /* The IP packet being sent is part of a set of fragmented packets. */\r
94 } eIPFragmentStatus_t;\r
95 \r
96 /*\r
97  * If ulIPAddress is already in the ARP cache table then reset the age of the\r
98  * entry back to its maximum value.  If ulIPAddress is not already in the ARP\r
99  * cache table then add it - replacing the oldest current entry if there is not\r
100  * a free space available.\r
101  */\r
102 void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress );\r
103 \r
104 #if( ipconfigARP_USE_CLASH_DETECTION != 0 )\r
105         /* Becomes non-zero if another device responded to a gratuitos ARP message. */\r
106         extern BaseType_t xARPHadIPClash;\r
107         /* MAC-address of the other device containing the same IP-address. */\r
108         extern MACAddress_t xARPClashMacAddress;\r
109 #endif /* ipconfigARP_USE_CLASH_DETECTION */\r
110 \r
111 #if( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )\r
112 \r
113         /*\r
114          * In some rare cases, it might be useful to remove a ARP cache entry of a\r
115          * known MAC address to make sure it gets refreshed.\r
116          */\r
117         uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress );\r
118 \r
119 #endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */\r
120 \r
121 /*\r
122  * Look for ulIPAddress in the ARP cache.  If the IP address exists, copy the\r
123  * associated MAC address into pxMACAddress, refresh the ARP cache entry's\r
124  * age, and return eARPCacheHit.  If the IP address does not exist in the ARP\r
125  * cache return eARPCacheMiss.  If the packet cannot be sent for any reason\r
126  * (maybe DHCP is still in process, or the addressing needs a gateway but there\r
127  * isn't a gateway defined) then return eCantSendPacket.\r
128  */\r
129 eARPLookupResult_t eARPGetCacheEntry( uint32_t *pulIPAddress, MACAddress_t * const pxMACAddress );\r
130 \r
131 #if( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )\r
132 \r
133         /* Lookup an IP-address if only the MAC-address is known */\r
134         eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress, uint32_t *pulIPAddress );\r
135 \r
136 #endif\r
137 /*\r
138  * Reduce the age count in each entry within the ARP cache.  An entry is no\r
139  * longer considered valid and is deleted if its age reaches zero.\r
140  */\r
141 void vARPAgeCache( void );\r
142 \r
143 /*\r
144  * Send out an ARP request for the IP address contained in pxNetworkBuffer, and\r
145  * add an entry into the ARP table that indicates that an ARP reply is\r
146  * outstanding so re-transmissions can be generated.\r
147  */\r
148 void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );\r
149 \r
150 /*\r
151  * After DHCP is ready and when changing IP address, force a quick send of our new IP\r
152  * address\r
153  */\r
154 void vARPSendGratuitous( void );\r
155 \r
156 #ifdef __cplusplus\r
157 } // extern "C"\r
158 #endif\r
159 \r
160 #endif /* FREERTOS_ARP_H */\r
161 \r
162 \r
163 \r
164 \r
165 \r
166 \r
167 \r
168 \r
169 \r
170 \r
171 \r
172 \r
173 \r