3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://aws.amazon.com/freertos
23 * http://www.FreeRTOS.org
26 #ifndef FREERTOS_ARP_H
27 #define FREERTOS_ARP_H
33 /* Application level configuration options. */
34 #include "FreeRTOSIPConfig.h"
35 #include "FreeRTOSIPConfigDefaults.h"
36 #include "IPTraceMacroDefaults.h"
38 /*-----------------------------------------------------------*/
39 /* Miscellaneous structure and definitions. */
40 /*-----------------------------------------------------------*/
42 typedef struct xARP_CACHE_TABLE_ROW
44 uint32_t ulIPAddress; /* The IP address of an ARP cache entry. */
45 MACAddress_t xMACAddress; /* The MAC address of an ARP cache entry. */
46 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. */
47 uint8_t ucValid; /* pdTRUE: xMACAddress is valid, pdFALSE: waiting for ARP reply */
52 eARPCacheMiss = 0, /* 0 An ARP table lookup did not find a valid entry. */
53 eARPCacheHit, /* 1 An ARP table lookup found a valid entry. */
54 eCantSendPacket /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */
59 eNotFragment = 0, /* The IP packet being sent is not part of a fragment. */
60 eFirstFragment, /* The IP packet being sent is the first in a set of fragmented packets. */
61 eFollowingFragment /* The IP packet being sent is part of a set of fragmented packets. */
62 } eIPFragmentStatus_t;
65 * If ulIPAddress is already in the ARP cache table then reset the age of the
66 * entry back to its maximum value. If ulIPAddress is not already in the ARP
67 * cache table then add it - replacing the oldest current entry if there is not
68 * a free space available.
70 void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress );
72 #if( ipconfigARP_USE_CLASH_DETECTION != 0 )
73 /* Becomes non-zero if another device responded to a gratuitos ARP message. */
74 extern BaseType_t xARPHadIPClash;
75 /* MAC-address of the other device containing the same IP-address. */
76 extern MACAddress_t xARPClashMacAddress;
77 #endif /* ipconfigARP_USE_CLASH_DETECTION */
79 #if( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )
82 * In some rare cases, it might be useful to remove a ARP cache entry of a
83 * known MAC address to make sure it gets refreshed.
85 uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress );
87 #endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */
90 * Look for ulIPAddress in the ARP cache. If the IP address exists, copy the
91 * associated MAC address into pxMACAddress, refresh the ARP cache entry's
92 * age, and return eARPCacheHit. If the IP address does not exist in the ARP
93 * cache return eARPCacheMiss. If the packet cannot be sent for any reason
94 * (maybe DHCP is still in process, or the addressing needs a gateway but there
95 * isn't a gateway defined) then return eCantSendPacket.
97 eARPLookupResult_t eARPGetCacheEntry( uint32_t *pulIPAddress, MACAddress_t * const pxMACAddress );
99 #if( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )
101 /* Lookup an IP-address if only the MAC-address is known */
102 eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress, uint32_t *pulIPAddress );
106 * Reduce the age count in each entry within the ARP cache. An entry is no
107 * longer considered valid and is deleted if its age reaches zero.
109 void vARPAgeCache( void );
112 * Send out an ARP request for the IP address contained in pxNetworkBuffer, and
113 * add an entry into the ARP table that indicates that an ARP reply is
114 * outstanding so re-transmissions can be generated.
116 void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
119 * After DHCP is ready and when changing IP address, force a quick send of our new IP
122 void vARPSendGratuitous( void );
128 #endif /* FREERTOS_ARP_H */