Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arp.h
00001 /** 00002 * @file arp.h 00003 * @brief ARP (Address Resolution Protocol) 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _ARP_H 00030 #define _ARP_H 00031 00032 //Dependencies 00033 #include "core/net.h" 00034 00035 //ARP tick interval 00036 #ifndef ARP_TICK_INTERVAL 00037 #define ARP_TICK_INTERVAL 200 00038 #elif (ARP_TICK_INTERVAL < 10) 00039 #error ARP_TICK_INTERVAL parameter is not valid 00040 #endif 00041 00042 //Size of ARP cache 00043 #ifndef ARP_CACHE_SIZE 00044 #define ARP_CACHE_SIZE 8 00045 #elif (ARP_CACHE_SIZE < 4) 00046 #error ARP_CACHE_SIZE parameter is not valid 00047 #endif 00048 00049 //Maximum number of packets waiting for address resolution to complete 00050 #ifndef ARP_MAX_PENDING_PACKETS 00051 #define ARP_MAX_PENDING_PACKETS 2 00052 #elif (ARP_MAX_PENDING_PACKETS < 1) 00053 #error ARP_MAX_PENDING_PACKETS parameter is not valid 00054 #endif 00055 00056 //Maximum number of times that an ARP request will be retransmitted 00057 #ifndef ARP_MAX_REQUESTS 00058 #define ARP_MAX_REQUESTS 3 00059 #elif (ARP_MAX_REQUESTS < 1) 00060 #error ARP_MAX_REQUESTS parameter is not valid 00061 #endif 00062 00063 //Time interval between subsequent retransmissions of ARP requests 00064 #ifndef ARP_REQUEST_TIMEOUT 00065 #define ARP_REQUEST_TIMEOUT 1000 00066 #elif (ARP_REQUEST_TIMEOUT < 100) 00067 #error ARP_REQUEST_TIMEOUT parameter is not valid 00068 #endif 00069 00070 //Maximum number of times that a probe will be retransmitted 00071 #ifndef ARP_MAX_PROBES 00072 #define ARP_MAX_PROBES 2 00073 #elif (ARP_MAX_PROBES < 1) 00074 #error ARP_MAX_PROBES parameter is not valid 00075 #endif 00076 00077 //time interval between subsequent retransmissions of probes 00078 #ifndef ARP_PROBE_TIMEOUT 00079 #define ARP_PROBE_TIMEOUT 60000 00080 #elif (ARP_PROBE_TIMEOUT < 1000) 00081 #error ARP_PROBE_TIMEOUT parameter is not valid 00082 #endif 00083 00084 //The time a host is considered reachable after receiving a reachability confirmation 00085 #ifndef ARP_REACHABLE_TIME 00086 #define ARP_REACHABLE_TIME 60000 00087 #elif (ARP_REACHABLE_TIME < 1000) 00088 #error ARP_REACHABLE_TIME parameter is not valid 00089 #endif 00090 00091 //Delay before sending the first probe 00092 #ifndef ARP_DELAY_FIRST_PROBE_TIME 00093 #define ARP_DELAY_FIRST_PROBE_TIME 5000 00094 #elif (ARP_DELAY_FIRST_PROBE_TIME < 1000) 00095 #error ARP_DELAY_FIRST_PROBE_TIME parameter is not valid 00096 #endif 00097 00098 //Hardware type 00099 #define ARP_HARDWARE_TYPE_ETH 0x0001 00100 //Protocol type 00101 #define ARP_PROTOCOL_TYPE_IPV4 0x0800 00102 00103 00104 /** 00105 * @brief ARP opcodes 00106 **/ 00107 00108 typedef enum 00109 { 00110 ARP_OPCODE_ARP_REQUEST = 1, 00111 ARP_OPCODE_ARP_REPLY = 2 00112 } ArpOpcode; 00113 00114 00115 /** 00116 * @brief ARP cache entry states 00117 **/ 00118 00119 typedef enum 00120 { 00121 ARP_STATE_NONE = 0, 00122 ARP_STATE_INCOMPLETE = 1, 00123 ARP_STATE_REACHABLE = 2, 00124 ARP_STATE_STALE = 3, 00125 ARP_STATE_DELAY = 4, 00126 ARP_STATE_PROBE = 5, 00127 ARP_STATE_PERMANENT = 6 00128 } ArpState; 00129 00130 00131 //CodeWarrior or Win32 compiler? 00132 #if defined(__CWCC__) || defined(_WIN32) 00133 #pragma pack(push, 1) 00134 #endif 00135 00136 00137 /** 00138 * @brief ARP packet 00139 **/ 00140 00141 typedef __start_packed struct 00142 { 00143 uint16_t hrd; //0-1 00144 uint16_t pro; //2-3 00145 uint8_t hln; //4 00146 uint8_t pln; //5 00147 uint16_t op; //6-7 00148 MacAddr sha; //8-13 00149 Ipv4Addr spa; //14-17 00150 MacAddr tha; //18-23 00151 Ipv4Addr tpa; //24-27 00152 } __end_packed ArpPacket; 00153 00154 00155 //CodeWarrior or Win32 compiler? 00156 #if defined(__CWCC__) || defined(_WIN32) 00157 #pragma pack(pop) 00158 #endif 00159 00160 00161 /** 00162 * @brief ARP queue item 00163 **/ 00164 00165 typedef struct 00166 { 00167 NetBuffer *buffer; //Packet waiting for address resolution 00168 size_t offset; //Offset to the first byte of the packet 00169 } ArpQueueItem; 00170 00171 00172 /** 00173 * @brief ARP cache entry 00174 **/ 00175 00176 typedef struct 00177 { 00178 ArpState state; //Reachability state 00179 Ipv4Addr ipAddr; //Unicast IPv4 address 00180 MacAddr macAddr; //Link layer address associated with the IPv4 address 00181 systime_t timestamp; //Time stamp to manage entry lifetime 00182 systime_t timeout; //Timeout value 00183 uint_t retransmitCount; //Retransmission counter 00184 ArpQueueItem queue[ARP_MAX_PENDING_PACKETS]; //Packets waiting for address resolution to complete 00185 uint_t queueSize; //Number of queued packets 00186 } ArpCacheEntry; 00187 00188 00189 //Tick counter to handle periodic operations 00190 extern systime_t arpTickCounter; 00191 00192 //ARP related functions 00193 error_t arpInit(NetInterface *interface); 00194 void arpFlushCache(NetInterface *interface); 00195 00196 ArpCacheEntry *arpCreateEntry(NetInterface *interface); 00197 ArpCacheEntry *arpFindEntry(NetInterface *interface, Ipv4Addr ipAddr); 00198 00199 void arpSendQueuedPackets(NetInterface *interface, ArpCacheEntry *entry); 00200 void arpFlushQueuedPackets(NetInterface *interface, ArpCacheEntry *entry); 00201 00202 error_t arpResolve(NetInterface *interface, Ipv4Addr ipAddr, MacAddr *macAddr); 00203 00204 error_t arpEnqueuePacket(NetInterface *interface, 00205 Ipv4Addr ipAddr, NetBuffer *buffer, size_t offset); 00206 00207 void arpTick(NetInterface *interface); 00208 00209 void arpProcessPacket(NetInterface *interface, ArpPacket *arpPacket, size_t length); 00210 void arpProcessRequest(NetInterface *interface, ArpPacket *arpRequest); 00211 void arpProcessReply(NetInterface *interface, ArpPacket *arpResponse); 00212 00213 error_t arpSendProbe(NetInterface *interface, Ipv4Addr targetIpAddr); 00214 00215 error_t arpSendRequest(NetInterface *interface, 00216 Ipv4Addr targetIpAddr, const MacAddr *destMacAddr); 00217 00218 error_t arpSendReply(NetInterface *interface, Ipv4Addr targetIpAddr, 00219 const MacAddr *targetMacAddr, const MacAddr *destMacAddr); 00220 00221 void arpDumpPacket(const ArpPacket *arpPacket); 00222 00223 #endif 00224
Generated on Tue Jul 12 2022 17:10:12 by
