2 EFI Address Resolution Protocol (ARP) Protocol interface header file.
4 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at<BR>
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/Arp.h>
22 #include <Protocol/ManagedNetwork.h>
23 #include <Protocol/ServiceBinding.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/NetLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
35 // Ethernet protocol type definitions.
37 #define ARP_ETHER_PROTO_TYPE 0x0806
38 #define IPV4_ETHER_PROTO_TYPE 0x0800
39 #define IPV6_ETHER_PROTO_TYPE 0x86DD
42 // ARP opcode definitions.
44 #define ARP_OPCODE_REQUEST 0x0001
45 #define ARP_OPCODE_REPLY 0x0002
48 // ARP timeout, retry count and interval definitions.
50 #define ARP_DEFAULT_TIMEOUT_VALUE (400 * TICKS_PER_SECOND)
51 #define ARP_DEFAULT_RETRY_COUNT 2
52 #define ARP_DEFAULT_RETRY_INTERVAL (5 * TICKS_PER_MS)
53 #define ARP_PERIODIC_TIMER_INTERVAL (500 * TICKS_PER_MS)
56 // ARP packet head definition.
69 // ARP Address definition for internal use.
73 UINT8
*SenderProtoAddr
;
75 UINT8
*TargetProtoAddr
;
78 #define MATCH_SW_ADDRESS 0x1
79 #define MATCH_HW_ADDRESS 0x2
82 // Enumeration for the search type. A search type is specified as the keyword to find
83 // a cache entry in the cache table.
87 ByProtoAddress
= MATCH_SW_ADDRESS
,
88 ByHwAddress
= MATCH_HW_ADDRESS
,
89 ByBoth
= MATCH_SW_ADDRESS
| MATCH_HW_ADDRESS
92 #define ARP_INSTANCE_DATA_SIGNATURE SIGNATURE_32('A', 'R', 'P', 'I')
95 Returns a pointer to the ARP_INSTANCE_DATA structure from the input a.
97 If the signatures matches, then a pointer to the data structure that contains
98 a specified field of that data structure is returned.
100 @param a Pointer to the field specified by ArpProto within a data
101 structure of type ARP_INSTANCE_DATA.
104 #define ARP_INSTANCE_DATA_FROM_THIS(a) \
109 ARP_INSTANCE_DATA_SIGNATURE \
112 typedef struct _ARP_SERVICE_DATA ARP_SERVICE_DATA
;
115 // ARP instance context data structure.
119 ARP_SERVICE_DATA
*ArpService
;
121 EFI_ARP_PROTOCOL ArpProto
;
123 EFI_ARP_CONFIG_DATA ConfigData
;
128 #define ARP_SERVICE_DATA_SIGNATURE SIGNATURE_32('A', 'R', 'P', 'S')
131 Returns a pointer to the ARP_SERVICE_DATA structure from the input a.
133 If the signatures matches, then a pointer to the data structure that contains
134 a specified field of that data structure is returned.
136 @param a Pointer to the field specified by ServiceBinding within
137 a data structure of type ARP_SERVICE_DATA.
140 #define ARP_SERVICE_DATA_FROM_THIS(a) \
145 ARP_SERVICE_DATA_SIGNATURE \
149 // ARP service data structure.
151 struct _ARP_SERVICE_DATA
{
153 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
155 EFI_HANDLE MnpChildHandle
;
156 EFI_HANDLE ImageHandle
;
157 EFI_HANDLE ControllerHandle
;
159 EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
;
160 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData
;
161 EFI_MANAGED_NETWORK_COMPLETION_TOKEN RxToken
;
163 EFI_SIMPLE_NETWORK_MODE SnpMode
;
165 UINTN ChildrenNumber
;
166 LIST_ENTRY ChildrenList
;
168 LIST_ENTRY PendingRequestTable
;
169 LIST_ENTRY DeniedCacheTable
;
170 LIST_ENTRY ResolvedCacheTable
;
172 EFI_EVENT PeriodicTimer
;
176 // User request context structure.
180 ARP_INSTANCE_DATA
*Instance
;
181 EFI_EVENT UserRequestEvent
;
182 VOID
*UserHwAddrBuffer
;
183 } USER_REQUEST_CONTEXT
;
185 #define ARP_MAX_PROTOCOL_ADDRESS_LEN sizeof(EFI_IP_ADDRESS)
186 #define ARP_MAX_HARDWARE_ADDRESS_LEN sizeof(EFI_MAC_ADDRESS)
189 // ARP address structure in an ARP packet.
196 UINT8 ProtoAddress
[ARP_MAX_PROTOCOL_ADDRESS_LEN
];
197 UINT8 HwAddress
[ARP_MAX_HARDWARE_ADDRESS_LEN
];
202 // Enumeration for ARP address type.
210 // ARP cache entry definition.
216 UINT32 DefaultDecayTime
;
218 UINT32 NextRetryTime
;
220 NET_ARP_ADDRESS Addresses
[2];
222 LIST_ENTRY UserRequestList
;
226 This function is used to assign a station address to the ARP cache for this instance
229 Each ARP instance has one station address. The EFI_ARP_PROTOCOL driver will
230 respond to ARP requests that match this registered station address. A call to
231 this function with the ConfigData field set to NULL will reset this ARP instance.
233 Once a protocol type and station address have been assigned to this ARP instance,
234 all the following ARP functions will use this information. Attempting to change
235 the protocol type or station address to a configured ARP instance will result in errors.
237 @param This Pointer to the EFI_ARP_PROTOCOL instance.
238 @param ConfigData Pointer to the EFI_ARP_CONFIG_DATA structure.
240 @retval EFI_SUCCESS The new station address was successfully
242 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
243 This is NULL. SwAddressLength is zero when
244 ConfigData is not NULL. StationAddress is NULL
245 when ConfigData is not NULL.
246 @retval EFI_ACCESS_DENIED The SwAddressType, SwAddressLength, or
247 StationAddress is different from the one that is
249 @retval EFI_OUT_OF_RESOURCES Storage for the new StationAddress could not be
256 IN EFI_ARP_PROTOCOL
*This
,
257 IN EFI_ARP_CONFIG_DATA
*ConfigData OPTIONAL
261 This function is used to insert entries into the ARP cache.
263 ARP cache entries are typically inserted and updated by network protocol drivers
264 as network traffic is processed. Most ARP cache entries will time out and be
265 deleted if the network traffic stops. ARP cache entries that were inserted
266 by the Add() function may be static (will not time out) or dynamic (will time out).
267 Default ARP cache timeout values are not covered in most network protocol
268 specifications (although RFC 1122 comes pretty close) and will only be
269 discussed in general in this specification. The timeout values that are
270 used in the EFI Sample Implementation should be used only as a guideline.
271 Final product implementations of the EFI network stack should be tuned for
272 their expected network environments.
274 @param This Pointer to the EFI_ARP_PROTOCOL instance.
275 @param DenyFlag Set to TRUE if this entry is a deny entry. Set to
276 FALSE if this entry is a normal entry.
277 @param TargetSwAddress Pointer to a protocol address to add (or deny).
278 May be set to NULL if DenyFlag is TRUE.
279 @param TargetHwAddress Pointer to a hardware address to add (or deny).
280 May be set to NULL if DenyFlag is TRUE.
281 @param TimeoutValue Time in 100-ns units that this entry will remain
282 in the ARP cache. A value of zero means that the
283 entry is permanent. A nonzero value will override
284 the one given by Configure() if the entry to be
285 added is a dynamic entry.
286 @param Overwrite If TRUE, the matching cache entry will be
287 overwritten with the supplied parameters. If
288 FALSE, EFI_ACCESS_DENIED is returned if the
289 corresponding cache entry already exists.
291 @retval EFI_SUCCESS The entry has been added or updated.
292 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
293 This is NULL. DenyFlag is FALSE and
294 TargetHwAddress is NULL. DenyFlag is FALSE and
295 TargetSwAddress is NULL. TargetHwAddress is NULL
296 and TargetSwAddress is NULL. Both TargetSwAddress
297 and TargetHwAddress are not NULL when DenyFlag is
299 @retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.
300 @retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite
302 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
308 IN EFI_ARP_PROTOCOL
*This
,
310 IN VOID
*TargetSwAddress OPTIONAL
,
311 IN VOID
*TargetHwAddress OPTIONAL
,
312 IN UINT32 TimeoutValue
,
317 This function searches the ARP cache for matching entries and allocates a buffer into
318 which those entries are copied.
320 The first part of the allocated buffer is EFI_ARP_FIND_DATA, following which
321 are protocol address pairs and hardware address pairs.
322 When finding a specific protocol address (BySwAddress is TRUE and AddressBuffer
323 is not NULL), the ARP cache timeout for the found entry is reset if Refresh is
324 set to TRUE. If the found ARP cache entry is a permanent entry, it is not
327 @param This Pointer to the EFI_ARP_PROTOCOL instance.
328 @param BySwAddress Set to TRUE to look for matching software protocol
329 addresses. Set to FALSE to look for matching
330 hardware protocol addresses.
331 @param AddressBuffer Pointer to address buffer. Set to NULL to match
333 @param EntryLength The size of an entry in the entries buffer.
334 @param EntryCount The number of ARP cache entries that are found by
335 the specified criteria.
336 @param Entries Pointer to the buffer that will receive the ARP
338 @param Refresh Set to TRUE to refresh the timeout value of the
339 matching ARP cache entry.
341 @retval EFI_SUCCESS The requested ARP cache entries were copied into
343 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
344 This is NULL. Both EntryCount and EntryLength are
345 NULL, when Refresh is FALSE.
346 @retval EFI_NOT_FOUND No matching entries were found.
347 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
353 IN EFI_ARP_PROTOCOL
*This
,
354 IN BOOLEAN BySwAddress
,
355 IN VOID
*AddressBuffer OPTIONAL
,
356 OUT UINT32
*EntryLength OPTIONAL
,
357 OUT UINT32
*EntryCount OPTIONAL
,
358 OUT EFI_ARP_FIND_DATA
**Entries OPTIONAL
,
363 This function removes specified ARP cache entries.
365 @param This Pointer to the EFI_ARP_PROTOCOL instance.
366 @param BySwAddress Set to TRUE to delete matching protocol addresses.
367 Set to FALSE to delete matching hardware
369 @param AddressBuffer Pointer to the address buffer that is used as a
370 key to look for the cache entry. Set to NULL to
373 @retval EFI_SUCCESS The entry was removed from the ARP cache.
374 @retval EFI_INVALID_PARAMETER This is NULL.
375 @retval EFI_NOT_FOUND The specified deletion key was not found.
376 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
382 IN EFI_ARP_PROTOCOL
*This
,
383 IN BOOLEAN BySwAddress
,
384 IN VOID
*AddressBuffer OPTIONAL
388 This function delete all dynamic entries from the ARP cache that match the specified
389 software protocol type.
391 @param This Pointer to the EFI_ARP_PROTOCOL instance.
393 @retval EFI_SUCCESS The cache has been flushed.
394 @retval EFI_INVALID_PARAMETER This is NULL.
395 @retval EFI_NOT_FOUND There are no matching dynamic cache entries.
396 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
402 IN EFI_ARP_PROTOCOL
*This
406 This function tries to resolve the TargetSwAddress and optionally returns a
407 TargetHwAddress if it already exists in the ARP cache.
409 @param This Pointer to the EFI_ARP_PROTOCOL instance.
410 @param TargetSwAddress Pointer to the protocol address to resolve.
411 @param ResolvedEvent Pointer to the event that will be signaled when
412 the address is resolved or some error occurs.
413 @param TargetHwAddress Pointer to the buffer for the resolved hardware
414 address in network byte order.
416 @retval EFI_SUCCESS The data is copied from the ARP cache into the
417 TargetHwAddress buffer.
418 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
419 This is NULL. TargetHwAddress is NULL.
420 @retval EFI_ACCESS_DENIED The requested address is not present in the normal
421 ARP cache but is present in the deny address list.
422 Outgoing traffic to that address is forbidden.
423 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
424 @retval EFI_NOT_READY The request has been started and is not finished.
430 IN EFI_ARP_PROTOCOL
*This
,
431 IN VOID
*TargetSwAddress OPTIONAL
,
432 IN EFI_EVENT ResolvedEvent OPTIONAL
,
433 OUT VOID
*TargetHwAddress
437 This function aborts the previous ARP request (identified by This, TargetSwAddress
438 and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
440 If the request is in the internal ARP request queue, the request is aborted
441 immediately and its ResolvedEvent is signaled. Only an asynchronous address
442 request needs to be canceled. If TargeSwAddress and ResolveEvent are both
443 NULL, all the pending asynchronous requests that have been issued by This
444 instance will be cancelled and their corresponding events will be signaled.
446 @param This Pointer to the EFI_ARP_PROTOCOL instance.
447 @param TargetSwAddress Pointer to the protocol address in previous
449 @param ResolvedEvent Pointer to the event that is used as the
450 notification event in previous request session.
452 @retval EFI_SUCCESS The pending request session(s) is/are aborted and
453 corresponding event(s) is/are signaled.
454 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
455 This is NULL. TargetSwAddress is not NULL and
456 ResolvedEvent is NULL. TargetSwAddress is NULL and
457 ResolvedEvent is not NULL.
458 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
459 @retval EFI_NOT_FOUND The request is not issued by
460 EFI_ARP_PROTOCOL.Request().
466 IN EFI_ARP_PROTOCOL
*This
,
467 IN VOID
*TargetSwAddress OPTIONAL
,
468 IN EFI_EVENT ResolvedEvent OPTIONAL
472 Configure the instance using the ConfigData. ConfigData is already validated.
474 @param[in] Instance Pointer to the instance context data to be
476 @param[in] ConfigData Pointer to the configuration data used to
477 configure the instance.
479 @retval EFI_SUCCESS The instance is configured with the ConfigData.
480 @retval EFI_ACCESS_DENIED The instance is already configured and the
481 ConfigData tries to reset some unchangeable
483 @retval EFI_INVALID_PARAMETER The ConfigData provides a non-unicast IPv4 address
484 when the SwAddressType is IPv4.
485 @retval EFI_OUT_OF_RESOURCES The instance fails to configure due to memory
490 ArpConfigureInstance (
491 IN ARP_INSTANCE_DATA
*Instance
,
492 IN EFI_ARP_CONFIG_DATA
*ConfigData OPTIONAL
496 Find the CacheEntry, using ProtocolAddress or HardwareAddress or both, as the keyword,
497 in the DeniedCacheTable.
499 @param[in] ArpService Pointer to the arp service context data.
500 @param[in] ProtocolAddress Pointer to the protocol address.
501 @param[in] HardwareAddress Pointer to the hardware address.
503 @return Pointer to the matched cache entry, if NULL no match is found.
507 ArpFindDeniedCacheEntry (
508 IN ARP_SERVICE_DATA
*ArpService
,
509 IN NET_ARP_ADDRESS
*ProtocolAddress OPTIONAL
,
510 IN NET_ARP_ADDRESS
*HardwareAddress OPTIONAL
514 Find the CacheEntry which matches the requirements in the specified CacheTable.
516 @param[in] CacheTable Pointer to the arp cache table.
517 @param[in] StartEntry Pointer to the start entry this search begins with
519 @param[in] FindOpType The search type.
520 @param[in] ProtocolAddress Pointer to the protocol address to match.
521 @param[in] HardwareAddress Pointer to the hardware address to match.
523 @return Pointer to the matched arp cache entry, if NULL, no match is found.
527 ArpFindNextCacheEntryInTable (
528 IN LIST_ENTRY
*CacheTable
,
529 IN LIST_ENTRY
*StartEntry
,
530 IN FIND_OPTYPE FindOpType
,
531 IN NET_ARP_ADDRESS
*ProtocolAddress OPTIONAL
,
532 IN NET_ARP_ADDRESS
*HardwareAddress OPTIONAL
536 Allocate a cache entry and initialize it.
538 @param[in] Instance Pointer to the instance context data.
540 @return Pointer to the new created cache entry.
545 IN ARP_INSTANCE_DATA
*Instance
549 Fill the addresses in the CacheEntry using the information passed in by
552 @param[in] CacheEntry Pointer to the cache entry.
553 @param[in] HwAddr Pointer to the software address.
554 @param[in] SwAddr Pointer to the hardware address.
560 ArpFillAddressInCacheEntry (
561 IN ARP_CACHE_ENTRY
*CacheEntry
,
562 IN NET_ARP_ADDRESS
*HwAddr OPTIONAL
,
563 IN NET_ARP_ADDRESS
*SwAddr OPTIONAL
567 Turn the CacheEntry into the resolved status.
569 @param[in] CacheEntry Pointer to the resolved cache entry.
570 @param[in] Instance Pointer to the instance context data.
571 @param[in] UserEvent Pointer to the UserEvent to notify.
573 @return The count of notifications sent to the instance.
578 IN ARP_CACHE_ENTRY
*CacheEntry
,
579 IN ARP_INSTANCE_DATA
*Instance OPTIONAL
,
580 IN EFI_EVENT UserEvent OPTIONAL
584 Delete cache entries in all the cache tables.
586 @param[in] Instance Pointer to the instance context data.
587 @param[in] BySwAddress Delete the cache entry by software address or by
589 @param[in] AddressBuffer Pointer to the buffer containing the address to
590 match for the deletion.
591 @param[in] Force This deletion is forced or not.
593 @return The count of the deleted cache entries.
597 ArpDeleteCacheEntry (
598 IN ARP_INSTANCE_DATA
*Instance
,
599 IN BOOLEAN BySwAddress
,
600 IN UINT8
*AddressBuffer OPTIONAL
,
605 Send out an arp frame using the CachEntry and the ArpOpCode.
607 @param[in] Instance Pointer to the instance context data.
608 @param[in] CacheEntry Pointer to the configuration data used to
609 configure the instance.
610 @param[in] ArpOpCode The opcode used to send out this Arp frame, either
618 IN ARP_INSTANCE_DATA
*Instance
,
619 IN ARP_CACHE_ENTRY
*CacheEntry
,
624 Initialize the instance context data.
626 @param[in] ArpService Pointer to the arp service context data this
628 @param[out] Instance Pointer to the instance context data.
635 IN ARP_SERVICE_DATA
*ArpService
,
636 OUT ARP_INSTANCE_DATA
*Instance
640 Process the Arp packets received from Mnp, the procedure conforms to RFC826.
642 @param[in] Context Pointer to the context data registerd to the
655 Queue ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK.
657 @param[in] Event The Event this notify function registered to.
658 @param[in] Context Pointer to the context data registerd to the
672 Process the already sent arp packets.
674 @param[in] Context Pointer to the context data registerd to the
687 Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK.
689 @param[in] Event The Event this notify function registered to.
690 @param[in] Context Pointer to the context data registerd to the
704 Process the arp cache olding and drive the retrying arp requests.
706 @param[in] Event The Event this notify function registered to.
707 @param[in] Context Pointer to the context data registerd to the
721 Cancel the arp request.
723 @param[in] Instance Pointer to the instance context data.
724 @param[in] TargetSwAddress Pointer to the buffer containing the target
725 software address to match the arp request.
726 @param[in] UserEvent The user event used to notify this request
729 @return The count of the cancelled requests.
734 IN ARP_INSTANCE_DATA
*Instance
,
735 IN VOID
*TargetSwAddress OPTIONAL
,
736 IN EFI_EVENT UserEvent OPTIONAL
740 Find the cache entry in the cache table.
742 @param[in] Instance Pointer to the instance context data.
743 @param[in] BySwAddress Set to TRUE to look for matching software protocol
744 addresses. Set to FALSE to look for matching
745 hardware protocol addresses.
746 @param[in] AddressBuffer Pointer to address buffer. Set to NULL to match
748 @param[out] EntryLength The size of an entry in the entries buffer.
749 @param[out] EntryCount The number of ARP cache entries that are found by
750 the specified criteria.
751 @param[out] Entries Pointer to the buffer that will receive the ARP
753 @param[in] Refresh Set to TRUE to refresh the timeout value of the
754 matching ARP cache entry.
756 @retval EFI_SUCCESS The requested ARP cache entries are copied into
758 @retval EFI_NOT_FOUND No matching entries found.
759 @retval EFI_OUT_OF_RESOURCE There is a memory allocation failure.
764 IN ARP_INSTANCE_DATA
*Instance
,
765 IN BOOLEAN BySwAddress
,
766 IN VOID
*AddressBuffer OPTIONAL
,
767 OUT UINT32
*EntryLength OPTIONAL
,
768 OUT UINT32
*EntryCount OPTIONAL
,
769 OUT EFI_ARP_FIND_DATA
**Entries OPTIONAL
,