4 Copyright (c) 2006, 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.
19 This function is used to assign a station address to the ARP cache for this instance
20 of the ARP driver. Each ARP instance has one station address. The EFI_ARP_PROTOCOL
21 driver will respond to ARP requests that match this registered station address.
22 A call to this function with the ConfigData field set to NULL will reset this
25 Once a protocol type and station address have been assigned to this ARP instance,
26 all the following ARP functions will use this information. Attempting to change
27 the protocol type or station address to a configured ARP instance will result in errors.
29 @param This Pointer to the EFI_ARP_PROTOCOL instance.
30 @param ConfigData Pointer to the EFI_ARP_CONFIG_DATA structure.
32 @retval EFI_SUCCESS The new station address was successfully
34 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
35 This is NULL. SwAddressLength is zero when
36 ConfigData is not NULL. StationAddress is NULL
37 when ConfigData is not NULL.
38 @retval EFI_ACCESS_DENIED The SwAddressType, SwAddressLength, or
39 StationAddress is different from the one that is
41 @retval EFI_OUT_OF_RESOURCES Storage for the new StationAddress could not be
48 IN EFI_ARP_PROTOCOL
*This
,
49 IN EFI_ARP_CONFIG_DATA
*ConfigData OPTIONAL
53 ARP_INSTANCE_DATA
*Instance
;
57 return EFI_INVALID_PARAMETER
;
60 if ((ConfigData
!= NULL
) &&
61 ((ConfigData
->SwAddressLength
== 0) ||
62 (ConfigData
->StationAddress
== NULL
) ||
63 (ConfigData
->SwAddressType
<= 1500))) {
64 return EFI_INVALID_PARAMETER
;
67 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
69 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
72 // Configure this instance, the ConfigData has already passed the basic checks.
74 Status
= ArpConfigureInstance (Instance
, ConfigData
);
76 gBS
->RestoreTPL (OldTpl
);
83 This function is used to insert entries into the ARP cache.
85 ARP cache entries are typically inserted and updated by network protocol drivers
86 as network traffic is processed. Most ARP cache entries will time out and be
87 deleted if the network traffic stops. ARP cache entries that were inserted
88 by the Add() function may be static (will not time out) or dynamic (will time out).
89 Default ARP cache timeout values are not covered in most network protocol
90 specifications (although RFC 1122 comes pretty close) and will only be
91 discussed in general in this specification. The timeout values that are
92 used in the EFI Sample Implementation should be used only as a guideline.
93 Final product implementations of the EFI network stack should be tuned for
94 their expected network environments.
96 @param This Pointer to the EFI_ARP_PROTOCOL instance.
97 @param DenyFlag Set to TRUE if this entry is a deny entry. Set to
98 FALSE if this entry is a normal entry.
99 @param TargetSwAddress Pointer to a protocol address to add (or deny).
100 May be set to NULL if DenyFlag is TRUE.
101 @param TargetHwAddress Pointer to a hardware address to add (or deny).
102 May be set to NULL if DenyFlag is TRUE.
103 @param TimeoutValue Time in 100-ns units that this entry will remain
104 in the ARP cache. A value of zero means that the
105 entry is permanent. A nonzero value will override
106 the one given by Configure() if the entry to be
107 added is a dynamic entry.
108 @param Overwrite If TRUE, the matching cache entry will be
109 overwritten with the supplied parameters. If
110 FALSE, EFI_ACCESS_DENIED is returned if the
111 corresponding cache entry already exists.
113 @retval EFI_SUCCESS The entry has been added or updated.
114 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
115 This is NULL. DenyFlag is FALSE and
116 TargetHwAddress is NULL. DenyFlag is FALSE and
117 TargetSwAddress is NULL. TargetHwAddress is NULL
118 and TargetSwAddress is NULL. Both TargetSwAddress
119 and TargetHwAddress are not NULL when DenyFlag is
121 @retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.
122 @retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite
124 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
130 IN EFI_ARP_PROTOCOL
*This
,
132 IN VOID
*TargetSwAddress OPTIONAL
,
133 IN VOID
*TargetHwAddress OPTIONAL
,
134 IN UINT32 TimeoutValue
,
139 ARP_INSTANCE_DATA
*Instance
;
140 ARP_SERVICE_DATA
*ArpService
;
141 ARP_CACHE_ENTRY
*CacheEntry
;
142 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
143 NET_ARP_ADDRESS MatchAddress
[2];
147 return EFI_INVALID_PARAMETER
;
150 if (((!DenyFlag
) && ((TargetHwAddress
== NULL
) || (TargetSwAddress
== NULL
))) ||
151 (DenyFlag
&& (TargetHwAddress
!= NULL
) && (TargetSwAddress
!= NULL
)) ||
152 ((TargetHwAddress
== NULL
) && (TargetSwAddress
== NULL
))) {
153 return EFI_INVALID_PARAMETER
;
156 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
158 if (!Instance
->Configured
) {
159 return EFI_NOT_STARTED
;
162 Status
= EFI_SUCCESS
;
163 ArpService
= Instance
->ArpService
;
164 SnpMode
= &Instance
->ArpService
->SnpMode
;
167 // Fill the hardware address part in the MatchAddress.
169 MatchAddress
[Hardware
].Type
= SnpMode
->IfType
;
170 MatchAddress
[Hardware
].Length
= (UINT8
) SnpMode
->HwAddressSize
;
171 MatchAddress
[Hardware
].AddressPtr
= TargetHwAddress
;
174 // Fill the software address part in the MatchAddress.
176 MatchAddress
[Protocol
].Type
= Instance
->ConfigData
.SwAddressType
;
177 MatchAddress
[Protocol
].Length
= Instance
->ConfigData
.SwAddressLength
;
178 MatchAddress
[Protocol
].AddressPtr
= TargetSwAddress
;
180 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
183 // See whether the entry to add exists. Check the DeinedCacheTable first.
185 CacheEntry
= ArpFindDeniedCacheEntry (
187 &MatchAddress
[Protocol
],
188 &MatchAddress
[Hardware
]
191 if (CacheEntry
== NULL
) {
193 // Check the ResolvedCacheTable
195 CacheEntry
= ArpFindNextCacheEntryInTable (
196 &ArpService
->ResolvedCacheTable
,
199 &MatchAddress
[Protocol
],
200 &MatchAddress
[Hardware
]
204 if ((CacheEntry
!= NULL
) && !Overwrite
) {
206 // The entry to add exists, if not Overwirte, deny this add request.
208 Status
= EFI_ACCESS_DENIED
;
212 if ((CacheEntry
== NULL
) && (TargetSwAddress
!= NULL
)) {
214 // Check whether there are pending requests matching the entry to be added.
216 CacheEntry
= ArpFindNextCacheEntryInTable (
217 &ArpService
->PendingRequestTable
,
220 &MatchAddress
[Protocol
],
225 if (CacheEntry
!= NULL
) {
227 // Remove it from the Table.
229 RemoveEntryList (&CacheEntry
->List
);
232 // It's a new entry, allocate memory for the entry.
234 CacheEntry
= ArpAllocCacheEntry (Instance
);
236 if (CacheEntry
== NULL
) {
237 DEBUG ((EFI_D_ERROR
, "ArpAdd: Failed to allocate pool for CacheEntry.\n"));
238 Status
= EFI_OUT_OF_RESOURCES
;
244 // Overwrite these parameters.
246 CacheEntry
->DefaultDecayTime
= TimeoutValue
;
247 CacheEntry
->DecayTime
= TimeoutValue
;
250 // Fill in the addresses.
252 ArpFillAddressInCacheEntry (
254 &MatchAddress
[Hardware
],
255 &MatchAddress
[Protocol
]
259 // Inform the user if there is any.
261 ArpAddressResolved (CacheEntry
, NULL
, NULL
);
264 // Add this CacheEntry to the corresponding CacheTable.
267 InsertHeadList (&ArpService
->DeniedCacheTable
, &CacheEntry
->List
);
269 InsertHeadList (&ArpService
->ResolvedCacheTable
, &CacheEntry
->List
);
274 gBS
->RestoreTPL (OldTpl
);
281 This function searches the ARP cache for matching entries and allocates a buffer into
282 which those entries are copied.
284 The first part of the allocated buffer is EFI_ARP_FIND_DATA, following which
285 are protocol address pairs and hardware address pairs.
286 When finding a specific protocol address (BySwAddress is TRUE and AddressBuffer
287 is not NULL), the ARP cache timeout for the found entry is reset if Refresh is
288 set to TRUE. If the found ARP cache entry is a permanent entry, it is not
291 @param This Pointer to the EFI_ARP_PROTOCOL instance.
292 @param BySwAddress Set to TRUE to look for matching software protocol
293 addresses. Set to FALSE to look for matching
294 hardware protocol addresses.
295 @param AddressBuffer Pointer to address buffer. Set to NULL to match
297 @param EntryLength The size of an entry in the entries buffer.
298 @param EntryCount The number of ARP cache entries that are found by
299 the specified criteria.
300 @param Entries Pointer to the buffer that will receive the ARP
302 @param Refresh Set to TRUE to refresh the timeout value of the
303 matching ARP cache entry.
305 @retval EFI_SUCCESS The requested ARP cache entries were copied into
307 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
308 This is NULL. Both EntryCount and EntryLength are
309 NULL, when Refresh is FALSE.
310 @retval EFI_NOT_FOUND No matching entries were found.
311 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
317 IN EFI_ARP_PROTOCOL
*This
,
318 IN BOOLEAN BySwAddress
,
319 IN VOID
*AddressBuffer OPTIONAL
,
320 OUT UINT32
*EntryLength OPTIONAL
,
321 OUT UINT32
*EntryCount OPTIONAL
,
322 OUT EFI_ARP_FIND_DATA
**Entries OPTIONAL
,
327 ARP_INSTANCE_DATA
*Instance
;
330 if ((This
== NULL
) ||
331 (!Refresh
&& (EntryCount
== NULL
) && (EntryLength
== NULL
)) ||
332 ((Entries
!= NULL
) && ((EntryLength
== NULL
) || (EntryCount
== NULL
)))) {
333 return EFI_INVALID_PARAMETER
;
336 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
338 if (!Instance
->Configured
) {
339 return EFI_NOT_STARTED
;
342 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
345 // All the check passed, find the cache entries now.
347 Status
= ArpFindCacheEntry (
357 gBS
->RestoreTPL (OldTpl
);
364 This function removes specified ARP cache entries.
366 @param This Pointer to the EFI_ARP_PROTOCOL instance.
367 @param BySwAddress Set to TRUE to delete matching protocol addresses.
368 Set to FALSE to delete matching hardware
370 @param AddressBuffer Pointer to the address buffer that is used as a
371 key to look for the cache entry. Set to NULL to
374 @retval EFI_SUCCESS The entry was removed from the ARP cache.
375 @retval EFI_INVALID_PARAMETER This is NULL.
376 @retval EFI_NOT_FOUND The specified deletion key was not found.
377 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
383 IN EFI_ARP_PROTOCOL
*This
,
384 IN BOOLEAN BySwAddress
,
385 IN VOID
*AddressBuffer OPTIONAL
388 ARP_INSTANCE_DATA
*Instance
;
393 return EFI_INVALID_PARAMETER
;
396 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
398 if (!Instance
->Configured
) {
399 return EFI_NOT_STARTED
;
402 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
405 // Delete the specified cache entries.
407 Count
= ArpDeleteCacheEntry (Instance
, BySwAddress
, AddressBuffer
, TRUE
);
409 gBS
->RestoreTPL (OldTpl
);
411 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;
416 This function delete all dynamic entries from the ARP cache that match the specified
417 software protocol type.
419 @param This Pointer to the EFI_ARP_PROTOCOL instance.
421 @retval EFI_SUCCESS The cache has been flushed.
422 @retval EFI_INVALID_PARAMETER This is NULL.
423 @retval EFI_NOT_FOUND There are no matching dynamic cache entries.
424 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
430 IN EFI_ARP_PROTOCOL
*This
433 ARP_INSTANCE_DATA
*Instance
;
438 return EFI_INVALID_PARAMETER
;
441 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
443 if (!Instance
->Configured
) {
444 return EFI_NOT_STARTED
;
447 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
450 // Delete the dynamic entries from the cache table.
452 Count
= ArpDeleteCacheEntry (Instance
, FALSE
, NULL
, FALSE
);
454 gBS
->RestoreTPL (OldTpl
);
456 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;
461 This function tries to resolve the TargetSwAddress and optionally returns a
462 TargetHwAddress if it already exists in the ARP cache.
464 @param This Pointer to the EFI_ARP_PROTOCOL instance.
465 @param TargetSwAddress Pointer to the protocol address to resolve.
466 @param ResolvedEvent Pointer to the event that will be signaled when
467 the address is resolved or some error occurs.
468 @param TargetHwAddress Pointer to the buffer for the resolved hardware
469 address in network byte order.
471 @retval EFI_SUCCESS The data is copied from the ARP cache into the
472 TargetHwAddress buffer.
473 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
474 This is NULL. TargetHwAddress is NULL.
475 @retval EFI_ACCESS_DENIED The requested address is not present in the normal
476 ARP cache but is present in the deny address list.
477 Outgoing traffic to that address is forbidden.
478 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
479 @retval EFI_NOT_READY The request has been started and is not finished.
485 IN EFI_ARP_PROTOCOL
*This
,
486 IN VOID
*TargetSwAddress OPTIONAL
,
487 IN EFI_EVENT ResolvedEvent OPTIONAL
,
488 OUT VOID
*TargetHwAddress
492 ARP_INSTANCE_DATA
*Instance
;
493 ARP_SERVICE_DATA
*ArpService
;
494 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
495 ARP_CACHE_ENTRY
*CacheEntry
;
496 NET_ARP_ADDRESS HardwareAddress
;
497 NET_ARP_ADDRESS ProtocolAddress
;
498 USER_REQUEST_CONTEXT
*RequestContext
;
501 if ((This
== NULL
) || (TargetHwAddress
== NULL
)) {
502 return EFI_INVALID_PARAMETER
;
505 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
507 if (!Instance
->Configured
) {
508 return EFI_NOT_STARTED
;
511 Status
= EFI_SUCCESS
;
512 ArpService
= Instance
->ArpService
;
513 SnpMode
= &ArpService
->SnpMode
;
515 if ((TargetSwAddress
== NULL
) ||
516 ((Instance
->ConfigData
.SwAddressType
== IPV4_ETHER_PROTO_TYPE
) &&
517 IP4_IS_LOCAL_BROADCAST (*((UINT32
*)TargetSwAddress
)))) {
519 // Return the hardware broadcast address.
521 CopyMem (TargetHwAddress
, &SnpMode
->BroadcastAddress
, SnpMode
->HwAddressSize
);
526 if ((Instance
->ConfigData
.SwAddressType
== IPV4_ETHER_PROTO_TYPE
) &&
527 IP4_IS_MULTICAST (NTOHL (*((UINT32
*)TargetSwAddress
)))) {
529 // If the software address is an IPv4 multicast address, invoke Mnp to
530 // resolve the address.
532 Status
= ArpService
->Mnp
->McastIpToMac (
541 HardwareAddress
.Type
= SnpMode
->IfType
;
542 HardwareAddress
.Length
= (UINT8
)SnpMode
->HwAddressSize
;
543 HardwareAddress
.AddressPtr
= NULL
;
545 ProtocolAddress
.Type
= Instance
->ConfigData
.SwAddressType
;
546 ProtocolAddress
.Length
= Instance
->ConfigData
.SwAddressLength
;
547 ProtocolAddress
.AddressPtr
= TargetSwAddress
;
550 // Initialize the TargetHwAddrss to a zero address.
552 ZeroMem (TargetHwAddress
, SnpMode
->HwAddressSize
);
554 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
557 // Check whether the software address is in the denied table.
559 CacheEntry
= ArpFindDeniedCacheEntry (ArpService
, &ProtocolAddress
, NULL
);
560 if (CacheEntry
!= NULL
) {
561 Status
= EFI_ACCESS_DENIED
;
566 // Check whether the software address is already resolved.
568 CacheEntry
= ArpFindNextCacheEntryInTable (
569 &ArpService
->ResolvedCacheTable
,
575 if (CacheEntry
!= NULL
) {
577 // Resolved, copy the address into the user buffer.
581 CacheEntry
->Addresses
[Hardware
].AddressPtr
,
582 CacheEntry
->Addresses
[Hardware
].Length
588 if (ResolvedEvent
== NULL
) {
589 Status
= EFI_NOT_READY
;
594 // Create a request context for this arp request.
596 RequestContext
= AllocatePool (sizeof(USER_REQUEST_CONTEXT
));
597 if (RequestContext
== NULL
) {
598 DEBUG ((EFI_D_ERROR
, "ArpRequest: Allocate memory for RequestContext failed.\n"));
600 Status
= EFI_OUT_OF_RESOURCES
;
604 RequestContext
->Instance
= Instance
;
605 RequestContext
->UserRequestEvent
= ResolvedEvent
;
606 RequestContext
->UserHwAddrBuffer
= TargetHwAddress
;
607 InitializeListHead (&RequestContext
->List
);
610 // Check whether there is a same request.
612 CacheEntry
= ArpFindNextCacheEntryInTable (
613 &ArpService
->PendingRequestTable
,
619 if (CacheEntry
!= NULL
) {
621 CacheEntry
->NextRetryTime
= Instance
->ConfigData
.RetryTimeOut
;
622 CacheEntry
->RetryCount
= Instance
->ConfigData
.RetryCount
;
625 // Allocate a cache entry for this request.
627 CacheEntry
= ArpAllocCacheEntry (Instance
);
628 if (CacheEntry
== NULL
) {
629 DEBUG ((EFI_D_ERROR
, "ArpRequest: Allocate memory for CacheEntry failed.\n"));
630 gBS
->FreePool (RequestContext
);
632 Status
= EFI_OUT_OF_RESOURCES
;
637 // Fill the software address.
639 ArpFillAddressInCacheEntry (CacheEntry
, &HardwareAddress
, &ProtocolAddress
);
642 // Add this entry into the PendingRequestTable.
644 InsertTailList (&ArpService
->PendingRequestTable
, &CacheEntry
->List
);
648 // Link this request context into the cache entry.
650 InsertHeadList (&CacheEntry
->UserRequestList
, &RequestContext
->List
);
653 // Send out the ARP Request frame.
655 ArpSendFrame (Instance
, CacheEntry
, ARP_OPCODE_REQUEST
);
656 Status
= EFI_NOT_READY
;
660 gBS
->RestoreTPL (OldTpl
);
664 if ((ResolvedEvent
!= NULL
) && (Status
== EFI_SUCCESS
)) {
665 gBS
->SignalEvent (ResolvedEvent
);
668 // Dispatch the DPC queued by the NotifyFunction of ResolvedEvent.
670 NetLibDispatchDpc ();
678 This function aborts the previous ARP request (identified by This, TargetSwAddress
679 and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
681 If the request is in the internal ARP request queue, the request is aborted
682 immediately and its ResolvedEvent is signaled. Only an asynchronous address
683 request needs to be canceled. If TargeSwAddress and ResolveEvent are both
684 NULL, all the pending asynchronous requests that have been issued by This
685 instance will be cancelled and their corresponding events will be signaled.
687 @param This Pointer to the EFI_ARP_PROTOCOL instance.
688 @param TargetSwAddress Pointer to the protocol address in previous
690 @param ResolvedEvent Pointer to the event that is used as the
691 notification event in previous request session.
693 @retval EFI_SUCCESS The pending request session(s) is/are aborted and
694 corresponding event(s) is/are signaled.
695 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
696 This is NULL. TargetSwAddress is not NULL and
697 ResolvedEvent is NULL. TargetSwAddress is NULL and
698 ResolvedEvent is not NULL.
699 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
700 @retval EFI_NOT_FOUND The request is not issued by
701 EFI_ARP_PROTOCOL.Request().
707 IN EFI_ARP_PROTOCOL
*This
,
708 IN VOID
*TargetSwAddress OPTIONAL
,
709 IN EFI_EVENT ResolvedEvent OPTIONAL
712 ARP_INSTANCE_DATA
*Instance
;
716 if ((This
== NULL
) ||
717 ((TargetSwAddress
!= NULL
) && (ResolvedEvent
== NULL
)) ||
718 ((TargetSwAddress
== NULL
) && (ResolvedEvent
!= NULL
))) {
719 return EFI_INVALID_PARAMETER
;
722 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
724 if (!Instance
->Configured
) {
725 return EFI_NOT_STARTED
;
728 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
731 // Cancel the specified request.
733 Count
= ArpCancelRequest (Instance
, TargetSwAddress
, ResolvedEvent
);
736 // Dispatch the DPCs queued by the NotifyFunction of the events signaled
737 // by ArpCancleRequest.
739 NetLibDispatchDpc ();
741 gBS
->RestoreTPL (OldTpl
);
743 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;