mikroSDK Reference Manual
arp.h
Go to the documentation of this file.
1
31#ifndef _ARP_H
32#define _ARP_H
33
34//Dependencies
35#include "core/net.h"
36
37//ARP tick interval
38#ifndef ARP_TICK_INTERVAL
39 #define ARP_TICK_INTERVAL 200
40#elif (ARP_TICK_INTERVAL < 10)
41 #error ARP_TICK_INTERVAL parameter is not valid
42#endif
43
44//Size of ARP cache
45#ifndef ARP_CACHE_SIZE
46 #define ARP_CACHE_SIZE 8
47#elif (ARP_CACHE_SIZE < 1)
48 #error ARP_CACHE_SIZE parameter is not valid
49#endif
50
51//Maximum number of packets waiting for address resolution to complete
52#ifndef ARP_MAX_PENDING_PACKETS
53 #define ARP_MAX_PENDING_PACKETS 2
54#elif (ARP_MAX_PENDING_PACKETS < 1)
55 #error ARP_MAX_PENDING_PACKETS parameter is not valid
56#endif
57
58//Maximum number of times that an ARP request will be retransmitted
59#ifndef ARP_MAX_REQUESTS
60 #define ARP_MAX_REQUESTS 3
61#elif (ARP_MAX_REQUESTS < 1)
62 #error ARP_MAX_REQUESTS parameter is not valid
63#endif
64
65//Time interval between subsequent retransmissions of ARP requests
66#ifndef ARP_REQUEST_TIMEOUT
67 #define ARP_REQUEST_TIMEOUT 1000
68#elif (ARP_REQUEST_TIMEOUT < 100)
69 #error ARP_REQUEST_TIMEOUT parameter is not valid
70#endif
71
72//Maximum number of times that a probe will be retransmitted
73#ifndef ARP_MAX_PROBES
74 #define ARP_MAX_PROBES 2
75#elif (ARP_MAX_PROBES < 1)
76 #error ARP_MAX_PROBES parameter is not valid
77#endif
78
79//time interval between subsequent retransmissions of probes
80#ifndef ARP_PROBE_TIMEOUT
81 #define ARP_PROBE_TIMEOUT 60000
82#elif (ARP_PROBE_TIMEOUT < 1000)
83 #error ARP_PROBE_TIMEOUT parameter is not valid
84#endif
85
86//The time a host is considered reachable after receiving a reachability confirmation
87#ifndef ARP_REACHABLE_TIME
88 #define ARP_REACHABLE_TIME 60000
89#elif (ARP_REACHABLE_TIME < 1000)
90 #error ARP_REACHABLE_TIME parameter is not valid
91#endif
92
93//Delay before sending the first probe
94#ifndef ARP_DELAY_FIRST_PROBE_TIME
95 #define ARP_DELAY_FIRST_PROBE_TIME 5000
96#elif (ARP_DELAY_FIRST_PROBE_TIME < 1000)
97 #error ARP_DELAY_FIRST_PROBE_TIME parameter is not valid
98#endif
99
100//Hardware type
101#define ARP_HARDWARE_TYPE_ETH 0x0001
102//Protocol type
103#define ARP_PROTOCOL_TYPE_IPV4 0x0800
104
105//C++ guard
106#ifdef __cplusplus
107extern "C" {
108#endif
109
110
115typedef enum
116{
117 ARP_OPCODE_ARP_REQUEST = 1,
118 ARP_OPCODE_ARP_REPLY = 2
119} ArpOpcode;
120
121
126typedef enum
127{
128 ARP_STATE_NONE = 0,
129 ARP_STATE_INCOMPLETE = 1,
130 ARP_STATE_REACHABLE = 2,
131 ARP_STATE_STALE = 3,
132 ARP_STATE_DELAY = 4,
133 ARP_STATE_PROBE = 5,
134 ARP_STATE_PERMANENT = 6
135} ArpState;
136
137
138//CodeWarrior or Win32 compiler?
139#if defined(__CWCC__) || defined(_WIN32)
140 #pragma pack(push, 1)
141#endif
142
143
149{
150 uint16_t hrd; //0-1
151 uint16_t pro; //2-3
152 uint8_t hln; //4
153 uint8_t pln; //5
154 uint16_t op; //6-7
155 MacAddr sha; //8-13
156 Ipv4Addr spa; //14-17
157 MacAddr tha; //18-23
158 Ipv4Addr tpa; //24-27
159} ArpPacket;
160
161
162//CodeWarrior or Win32 compiler?
163#if defined(__CWCC__) || defined(_WIN32)
164 #pragma pack(pop)
165#endif
166
167
172typedef struct
173{
175 size_t offset;
176 NetTxAncillary ancillary;
178
179
195
196
197//Tick counter to handle periodic operations
198extern systime_t arpTickCounter;
199
200//ARP related functions
201error_t arpInit(NetInterface *interface);
202error_t arpEnable(NetInterface *interface, bool_t enable);
203
204error_t arpAddStaticEntry(NetInterface *interface, Ipv4Addr ipAddr,
205 const MacAddr *macAddr);
206
207error_t arpRemoveStaticEntry(NetInterface *interface, Ipv4Addr ipAddr);
208
209error_t arpResolve(NetInterface *interface, Ipv4Addr ipAddr, MacAddr *macAddr);
210
211error_t arpEnqueuePacket(NetInterface *interface, Ipv4Addr ipAddr,
212 NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
213
214void arpTick(NetInterface *interface);
215
216void arpProcessPacket(NetInterface *interface, ArpPacket *arpPacket,
217 size_t length);
218
219void arpProcessRequest(NetInterface *interface, ArpPacket *arpRequest);
220void arpProcessReply(NetInterface *interface, ArpPacket *arpReply);
221
222error_t arpSendProbe(NetInterface *interface, Ipv4Addr targetIpAddr);
223
224error_t arpSendRequest(NetInterface *interface, Ipv4Addr targetIpAddr,
225 const MacAddr *destMacAddr);
226
227error_t arpSendReply(NetInterface *interface, Ipv4Addr senderIpAddr,
228 Ipv4Addr targetIpAddr, const MacAddr *targetMacAddr);
229
230void arpDumpPacket(const ArpPacket *arpPacket);
231
232//C++ guard
233#ifdef __cplusplus
234}
235#endif
236
237#endif
ArpState
ARP cache entry states.
Definition arp.h:127
typedef __packed_struct
ARP packet.
Definition arp.h:149
ArpOpcode
ARP opcodes.
Definition arp.h:116
error_t
Error codes.
Definition error.h:43
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
ARP cache entry.
Definition arp.h:185
systime_t timestamp
Time stamp to manage entry lifetime.
Definition arp.h:189
Ipv4Addr ipAddr
Unicast IPv4 address.
Definition arp.h:187
MacAddr macAddr
Link layer address associated with the IPv4 address.
Definition arp.h:188
uint_t retransmitCount
Retransmission counter.
Definition arp.h:191
ArpState state
Reachability state.
Definition arp.h:186
systime_t timeout
Timeout value.
Definition arp.h:190
uint_t queueSize
Number of queued packets.
Definition arp.h:193
ARP queue item.
Definition arp.h:173
NetBuffer * buffer
Packet waiting for address resolution.
Definition arp.h:174
NetTxAncillary ancillary
Additional options.
Definition arp.h:176
size_t offset
Offset to the first byte of the packet.
Definition arp.h:175
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89