FreeRTOS_ARP.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * FreeRTOS+TCP V2.3.2 LTS Patch 1
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  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:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  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.
  21. *
  22. * http://aws.amazon.com/freertos
  23. * http://www.FreeRTOS.org
  24. */
  25. #ifndef FREERTOS_ARP_H
  26. #define FREERTOS_ARP_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Application level configuration options. */
  31. #include "FreeRTOSIPConfig.h"
  32. #include "FreeRTOSIPConfigDefaults.h"
  33. #include "IPTraceMacroDefaults.h"
  34. /*-----------------------------------------------------------*/
  35. /* Miscellaneous structure and definitions. */
  36. /*-----------------------------------------------------------*/
  37. /**
  38. * Structure for one row in the ARP cache table.
  39. */
  40. typedef struct xARP_CACHE_TABLE_ROW
  41. {
  42. uint32_t ulIPAddress; /**< The IP address of an ARP cache entry. */
  43. MACAddress_t xMACAddress; /**< The MAC address of an ARP cache entry. */
  44. 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. */
  45. uint8_t ucValid; /**< pdTRUE: xMACAddress is valid, pdFALSE: waiting for ARP reply */
  46. } ARPCacheRow_t;
  47. typedef enum
  48. {
  49. eARPCacheMiss = 0, /* 0 An ARP table lookup did not find a valid entry. */
  50. eARPCacheHit, /* 1 An ARP table lookup found a valid entry. */
  51. eCantSendPacket /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */
  52. } eARPLookupResult_t;
  53. /*
  54. * If ulIPAddress is already in the ARP cache table then reset the age of the
  55. * entry back to its maximum value. If ulIPAddress is not already in the ARP
  56. * cache table then add it - replacing the oldest current entry if there is not
  57. * a free space available.
  58. */
  59. void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress,
  60. const uint32_t ulIPAddress );
  61. #if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
  62. /* Becomes non-zero if another device responded to a gratuitous ARP message. */
  63. extern BaseType_t xARPHadIPClash;
  64. /* MAC-address of the other device containing the same IP-address. */
  65. extern MACAddress_t xARPClashMacAddress;
  66. #endif /* ipconfigARP_USE_CLASH_DETECTION */
  67. #if ( ipconfigUSE_ARP_REMOVE_ENTRY != 0 )
  68. /*
  69. * In some rare cases, it might be useful to remove a ARP cache entry of a
  70. * known MAC address to make sure it gets refreshed.
  71. */
  72. uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress );
  73. #endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */
  74. /*
  75. * Look for ulIPAddress in the ARP cache. If the IP address exists, copy the
  76. * associated MAC address into pxMACAddress, refresh the ARP cache entry's
  77. * age, and return eARPCacheHit. If the IP address does not exist in the ARP
  78. * cache return eARPCacheMiss. If the packet cannot be sent for any reason
  79. * (maybe DHCP is still in process, or the addressing needs a gateway but there
  80. * isn't a gateway defined) then return eCantSendPacket.
  81. */
  82. eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
  83. MACAddress_t * const pxMACAddress );
  84. #if ( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 )
  85. /* Lookup an IP-address if only the MAC-address is known */
  86. eARPLookupResult_t eARPGetCacheEntryByMac( MACAddress_t * const pxMACAddress,
  87. uint32_t * pulIPAddress );
  88. #endif
  89. /*
  90. * Reduce the age count in each entry within the ARP cache. An entry is no
  91. * longer considered valid and is deleted if its age reaches zero.
  92. */
  93. void vARPAgeCache( void );
  94. /*
  95. * Send out an ARP request for the IP address contained in pxNetworkBuffer, and
  96. * add an entry into the ARP table that indicates that an ARP reply is
  97. * outstanding so re-transmissions can be generated.
  98. */
  99. void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
  100. /*
  101. * After DHCP is ready and when changing IP address, force a quick send of our new IP
  102. * address
  103. */
  104. void vARPSendGratuitous( void );
  105. /* This function will check if the target IP-address belongs to this device.
  106. * If so, the packet will be passed to the IP-stack, who will answer it.
  107. * The function is to be called within the function xNetworkInterfaceOutput()
  108. * in NetworkInterface.c as follows:
  109. *
  110. * if( xCheckLoopback( pxDescriptor, bReleaseAfterSend ) != 0 )
  111. * {
  112. * / * The packet has been sent back to the IP-task.
  113. * * The IP-task will further handle it.
  114. * * Do not release the descriptor.
  115. * * /
  116. * return pdTRUE;
  117. * }
  118. * / * Send the packet as usual. * /
  119. */
  120. BaseType_t xCheckLoopback( NetworkBufferDescriptor_t * const pxDescriptor,
  121. BaseType_t bReleaseAfterSend );
  122. #ifdef __cplusplus
  123. } /* extern "C" */
  124. #endif
  125. #endif /* FREERTOS_ARP_H */