3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 This function is used to assign a station address to the ARP cache for this instance
26 of the ARP driver. A call to this function with the ConfigData field set to NULL
27 will reset this ARP instance.
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 @param This Pointer to the EFI_ARP_PROTOCOL instance.
86 @param DenyFlag Set to TRUE if this entry is a deny entry. Set to
87 FALSE if this entry is a normal entry.
88 @param TargetSwAddress Pointer to a protocol address to add (or deny).
89 May be set to NULL if DenyFlag is TRUE.
90 @param TargetHwAddress Pointer to a hardware address to add (or deny).
91 May be set to NULL if DenyFlag is TRUE.
92 @param TimeoutValue Time in 100-ns units that this entry will remain
93 in the ARP cache. A value of zero means that the
94 entry is permanent. A nonzero value will override
95 the one given by Configure() if the entry to be
96 added is a dynamic entry.
97 @param Overwrite If TRUE, the matching cache entry will be
98 overwritten with the supplied parameters. If
99 FALSE, EFI_ACCESS_DENIED is returned if the
100 corresponding cache entry already exists.
102 @retval EFI_SUCCESS The entry has been added or updated.
103 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
104 This is NULL. DenyFlag is FALSE and
105 TargetHwAddress is NULL. DenyFlag is FALSE and
106 TargetSwAddress is NULL. TargetHwAddress is NULL
107 and TargetSwAddress is NULL. Both TargetSwAddress
108 and TargetHwAddress are not NULL when DenyFlag is
110 @retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.
111 @retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite
113 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
119 IN EFI_ARP_PROTOCOL
*This
,
121 IN VOID
*TargetSwAddress OPTIONAL
,
122 IN VOID
*TargetHwAddress OPTIONAL
,
123 IN UINT32 TimeoutValue
,
128 ARP_INSTANCE_DATA
*Instance
;
129 ARP_SERVICE_DATA
*ArpService
;
130 ARP_CACHE_ENTRY
*CacheEntry
;
131 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
132 NET_ARP_ADDRESS MatchAddress
[2];
136 return EFI_INVALID_PARAMETER
;
139 if (((!DenyFlag
) && ((TargetHwAddress
== NULL
) || (TargetSwAddress
== NULL
))) ||
140 (DenyFlag
&& (TargetHwAddress
!= NULL
) && (TargetSwAddress
!= NULL
)) ||
141 ((TargetHwAddress
== NULL
) && (TargetSwAddress
== NULL
))) {
142 return EFI_INVALID_PARAMETER
;
145 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
147 if (!Instance
->Configured
) {
148 return EFI_NOT_STARTED
;
151 Status
= EFI_SUCCESS
;
152 ArpService
= Instance
->ArpService
;
153 SnpMode
= &Instance
->ArpService
->SnpMode
;
156 // Fill the hardware address part in the MatchAddress.
158 MatchAddress
[Hardware
].Type
= SnpMode
->IfType
;
159 MatchAddress
[Hardware
].Length
= (UINT8
) SnpMode
->HwAddressSize
;
160 MatchAddress
[Hardware
].AddressPtr
= TargetHwAddress
;
163 // Fill the software address part in the MatchAddress.
165 MatchAddress
[Protocol
].Type
= Instance
->ConfigData
.SwAddressType
;
166 MatchAddress
[Protocol
].Length
= Instance
->ConfigData
.SwAddressLength
;
167 MatchAddress
[Protocol
].AddressPtr
= TargetSwAddress
;
169 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
172 // See whether the entry to add exists. Check the DeinedCacheTable first.
174 CacheEntry
= ArpFindDeniedCacheEntry (
176 &MatchAddress
[Protocol
],
177 &MatchAddress
[Hardware
]
180 if (CacheEntry
== NULL
) {
182 // Check the ResolvedCacheTable
184 CacheEntry
= ArpFindNextCacheEntryInTable (
185 &ArpService
->ResolvedCacheTable
,
188 &MatchAddress
[Protocol
],
189 &MatchAddress
[Hardware
]
193 if ((CacheEntry
!= NULL
) && !Overwrite
) {
195 // The entry to add exists, if not Overwirte, deny this add request.
197 Status
= EFI_ACCESS_DENIED
;
201 if ((CacheEntry
== NULL
) && (TargetSwAddress
!= NULL
)) {
203 // Check whether there are pending requests matching the entry to be added.
205 CacheEntry
= ArpFindNextCacheEntryInTable (
206 &ArpService
->PendingRequestTable
,
209 &MatchAddress
[Protocol
],
214 if (CacheEntry
!= NULL
) {
216 // Remove it from the Table.
218 RemoveEntryList (&CacheEntry
->List
);
221 // It's a new entry, allocate memory for the entry.
223 CacheEntry
= ArpAllocCacheEntry (Instance
);
225 if (CacheEntry
== NULL
) {
226 DEBUG ((EFI_D_ERROR
, "ArpAdd: Failed to allocate pool for CacheEntry.\n"));
227 Status
= EFI_OUT_OF_RESOURCES
;
233 // Overwrite these parameters.
235 CacheEntry
->DefaultDecayTime
= TimeoutValue
;
236 CacheEntry
->DecayTime
= TimeoutValue
;
239 // Fill in the addresses.
241 ArpFillAddressInCacheEntry (
243 &MatchAddress
[Hardware
],
244 &MatchAddress
[Protocol
]
248 // Inform the user if there is any.
250 ArpAddressResolved (CacheEntry
, NULL
, NULL
);
253 // Add this CacheEntry to the corresponding CacheTable.
256 InsertHeadList (&ArpService
->DeniedCacheTable
, &CacheEntry
->List
);
258 InsertHeadList (&ArpService
->ResolvedCacheTable
, &CacheEntry
->List
);
263 gBS
->RestoreTPL (OldTpl
);
270 This function searches the ARP cache for matching entries and allocates a buffer into
271 which those entries are copied.
273 @param This Pointer to the EFI_ARP_PROTOCOL instance.
274 @param BySwAddress Set to TRUE to look for matching software protocol
275 addresses. Set to FALSE to look for matching
276 hardware protocol addresses.
277 @param AddressBuffer Pointer to address buffer. Set to NULL to match
279 @param EntryLength The size of an entry in the entries buffer.
280 @param EntryCount The number of ARP cache entries that are found by
281 the specified criteria.
282 @param Entries Pointer to the buffer that will receive the ARP
284 @param Refresh Set to TRUE to refresh the timeout value of the
285 matching ARP cache entry.
287 @retval EFI_SUCCESS The requested ARP cache entries were copied into
289 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
290 This is NULL. Both EntryCount and EntryLength are
291 NULL, when Refresh is FALSE.
292 @retval EFI_NOT_FOUND No matching entries were found.
293 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
299 IN EFI_ARP_PROTOCOL
*This
,
300 IN BOOLEAN BySwAddress
,
301 IN VOID
*AddressBuffer OPTIONAL
,
302 OUT UINT32
*EntryLength OPTIONAL
,
303 OUT UINT32
*EntryCount OPTIONAL
,
304 OUT EFI_ARP_FIND_DATA
**Entries OPTIONAL
,
309 ARP_INSTANCE_DATA
*Instance
;
312 if ((This
== NULL
) ||
313 (!Refresh
&& (EntryCount
== NULL
) && (EntryLength
== NULL
)) ||
314 ((Entries
!= NULL
) && ((EntryLength
== NULL
) || (EntryCount
== NULL
)))) {
315 return EFI_INVALID_PARAMETER
;
318 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
320 if (!Instance
->Configured
) {
321 return EFI_NOT_STARTED
;
324 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
327 // All the check passed, find the cache entries now.
329 Status
= ArpFindCacheEntry (
339 gBS
->RestoreTPL (OldTpl
);
346 This function removes specified ARP cache entries.
348 @param This Pointer to the EFI_ARP_PROTOCOL instance.
349 @param BySwAddress Set to TRUE to delete matching protocol addresses.
350 Set to FALSE to delete matching hardware
352 @param AddressBuffer Pointer to the address buffer that is used as a
353 key to look for the cache entry. Set to NULL to
356 @retval EFI_SUCCESS The entry was removed from the ARP cache.
357 @retval EFI_INVALID_PARAMETER This is NULL.
358 @retval EFI_NOT_FOUND The specified deletion key was not found.
359 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
365 IN EFI_ARP_PROTOCOL
*This
,
366 IN BOOLEAN BySwAddress
,
367 IN VOID
*AddressBuffer OPTIONAL
370 ARP_INSTANCE_DATA
*Instance
;
375 return EFI_INVALID_PARAMETER
;
378 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
380 if (!Instance
->Configured
) {
381 return EFI_NOT_STARTED
;
384 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
387 // Delete the specified cache entries.
389 Count
= ArpDeleteCacheEntry (Instance
, BySwAddress
, AddressBuffer
, TRUE
);
391 gBS
->RestoreTPL (OldTpl
);
393 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;
398 This function delete all dynamic entries from the ARP cache that match the specified
399 software protocol type.
401 @param This Pointer to the EFI_ARP_PROTOCOL instance.
403 @retval EFI_SUCCESS The cache has been flushed.
404 @retval EFI_INVALID_PARAMETER This is NULL.
405 @retval EFI_NOT_FOUND There are no matching dynamic cache entries.
406 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
412 IN EFI_ARP_PROTOCOL
*This
415 ARP_INSTANCE_DATA
*Instance
;
420 return EFI_INVALID_PARAMETER
;
423 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
425 if (!Instance
->Configured
) {
426 return EFI_NOT_STARTED
;
429 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
432 // Delete the dynamic entries from the cache table.
434 Count
= ArpDeleteCacheEntry (Instance
, FALSE
, NULL
, FALSE
);
436 gBS
->RestoreTPL (OldTpl
);
438 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;
443 This function tries to resolve the TargetSwAddress and optionally returns a
444 TargetHwAddress if it already exists in the ARP cache.
446 @param This Pointer to the EFI_ARP_PROTOCOL instance.
447 @param TargetSwAddress Pointer to the protocol address to resolve.
448 @param ResolvedEvent Pointer to the event that will be signaled when
449 the address is resolved or some error occurs.
450 @param TargetHwAddress Pointer to the buffer for the resolved hardware
451 address in network byte order.
453 @retval EFI_SUCCESS The data is copied from the ARP cache into the
454 TargetHwAddress buffer.
455 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
456 This is NULL. TargetHwAddress is NULL.
457 @retval EFI_ACCESS_DENIED The requested address is not present in the normal
458 ARP cache but is present in the deny address list.
459 Outgoing traffic to that address is forbidden.
460 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
461 @retval EFI_NOT_READY The request has been started and is not finished.
467 IN EFI_ARP_PROTOCOL
*This
,
468 IN VOID
*TargetSwAddress OPTIONAL
,
469 IN EFI_EVENT ResolvedEvent OPTIONAL
,
470 OUT VOID
*TargetHwAddress
474 ARP_INSTANCE_DATA
*Instance
;
475 ARP_SERVICE_DATA
*ArpService
;
476 EFI_SIMPLE_NETWORK_MODE
*SnpMode
;
477 ARP_CACHE_ENTRY
*CacheEntry
;
478 NET_ARP_ADDRESS HardwareAddress
;
479 NET_ARP_ADDRESS ProtocolAddress
;
480 USER_REQUEST_CONTEXT
*RequestContext
;
483 if ((This
== NULL
) || (TargetHwAddress
== NULL
)) {
484 return EFI_INVALID_PARAMETER
;
487 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
489 if (!Instance
->Configured
) {
490 return EFI_NOT_STARTED
;
493 Status
= EFI_SUCCESS
;
494 ArpService
= Instance
->ArpService
;
495 SnpMode
= &ArpService
->SnpMode
;
497 if ((TargetSwAddress
== NULL
) ||
498 ((Instance
->ConfigData
.SwAddressType
== IPV4_ETHER_PROTO_TYPE
) &&
499 IP4_IS_LOCAL_BROADCAST (*((UINT32
*)TargetSwAddress
)))) {
501 // Return the hardware broadcast address.
503 CopyMem (TargetHwAddress
, &SnpMode
->BroadcastAddress
, SnpMode
->HwAddressSize
);
508 if ((Instance
->ConfigData
.SwAddressType
== IPV4_ETHER_PROTO_TYPE
) &&
509 IP4_IS_MULTICAST (NTOHL (*((UINT32
*)TargetSwAddress
)))) {
511 // If the software address is an IPv4 multicast address, invoke Mnp to
512 // resolve the address.
514 Status
= ArpService
->Mnp
->McastIpToMac (
523 HardwareAddress
.Type
= SnpMode
->IfType
;
524 HardwareAddress
.Length
= (UINT8
)SnpMode
->HwAddressSize
;
525 HardwareAddress
.AddressPtr
= NULL
;
527 ProtocolAddress
.Type
= Instance
->ConfigData
.SwAddressType
;
528 ProtocolAddress
.Length
= Instance
->ConfigData
.SwAddressLength
;
529 ProtocolAddress
.AddressPtr
= TargetSwAddress
;
532 // Initialize the TargetHwAddrss to a zero address.
534 ZeroMem (TargetHwAddress
, SnpMode
->HwAddressSize
);
536 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
539 // Check whether the software address is in the denied table.
541 CacheEntry
= ArpFindDeniedCacheEntry (ArpService
, &ProtocolAddress
, NULL
);
542 if (CacheEntry
!= NULL
) {
543 Status
= EFI_ACCESS_DENIED
;
548 // Check whether the software address is already resolved.
550 CacheEntry
= ArpFindNextCacheEntryInTable (
551 &ArpService
->ResolvedCacheTable
,
557 if (CacheEntry
!= NULL
) {
559 // Resolved, copy the address into the user buffer.
563 CacheEntry
->Addresses
[Hardware
].AddressPtr
,
564 CacheEntry
->Addresses
[Hardware
].Length
570 if (ResolvedEvent
== NULL
) {
571 Status
= EFI_NOT_READY
;
576 // Create a request context for this arp request.
578 RequestContext
= AllocatePool (sizeof(USER_REQUEST_CONTEXT
));
579 if (RequestContext
== NULL
) {
580 DEBUG ((EFI_D_ERROR
, "ArpRequest: Allocate memory for RequestContext failed.\n"));
582 Status
= EFI_OUT_OF_RESOURCES
;
586 RequestContext
->Instance
= Instance
;
587 RequestContext
->UserRequestEvent
= ResolvedEvent
;
588 RequestContext
->UserHwAddrBuffer
= TargetHwAddress
;
589 InitializeListHead (&RequestContext
->List
);
592 // Check whether there is a same request.
594 CacheEntry
= ArpFindNextCacheEntryInTable (
595 &ArpService
->PendingRequestTable
,
601 if (CacheEntry
!= NULL
) {
603 CacheEntry
->NextRetryTime
= Instance
->ConfigData
.RetryTimeOut
;
604 CacheEntry
->RetryCount
= Instance
->ConfigData
.RetryCount
;
607 // Allocate a cache entry for this request.
609 CacheEntry
= ArpAllocCacheEntry (Instance
);
610 if (CacheEntry
== NULL
) {
611 DEBUG ((EFI_D_ERROR
, "ArpRequest: Allocate memory for CacheEntry failed.\n"));
612 gBS
->FreePool (RequestContext
);
614 Status
= EFI_OUT_OF_RESOURCES
;
619 // Fill the software address.
621 ArpFillAddressInCacheEntry (CacheEntry
, &HardwareAddress
, &ProtocolAddress
);
624 // Add this entry into the PendingRequestTable.
626 InsertTailList (&ArpService
->PendingRequestTable
, &CacheEntry
->List
);
630 // Link this request context into the cache entry.
632 InsertHeadList (&CacheEntry
->UserRequestList
, &RequestContext
->List
);
635 // Send out the ARP Request frame.
637 ArpSendFrame (Instance
, CacheEntry
, ARP_OPCODE_REQUEST
);
638 Status
= EFI_NOT_READY
;
642 gBS
->RestoreTPL (OldTpl
);
646 if ((ResolvedEvent
!= NULL
) && (Status
== EFI_SUCCESS
)) {
647 gBS
->SignalEvent (ResolvedEvent
);
650 // Dispatch the DPC queued by the NotifyFunction of ResolvedEvent.
652 NetLibDispatchDpc ();
660 This function aborts the previous ARP request (identified by This, TargetSwAddress
661 and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
663 @param This Pointer to the EFI_ARP_PROTOCOL instance.
664 @param TargetSwAddress Pointer to the protocol address in previous
666 @param ResolvedEvent Pointer to the event that is used as the
667 notification event in previous request session.
669 @retval EFI_SUCCESS The pending request session(s) is/are aborted and
670 corresponding event(s) is/are signaled.
671 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
672 This is NULL. TargetSwAddress is not NULL and
673 ResolvedEvent is NULL. TargetSwAddress is NULL and
674 ResolvedEvent is not NULL.
675 @retval EFI_NOT_STARTED The ARP driver instance has not been configured.
676 @retval EFI_NOT_FOUND The request is not issued by
677 EFI_ARP_PROTOCOL.Request().
683 IN EFI_ARP_PROTOCOL
*This
,
684 IN VOID
*TargetSwAddress OPTIONAL
,
685 IN EFI_EVENT ResolvedEvent OPTIONAL
688 ARP_INSTANCE_DATA
*Instance
;
692 if ((This
== NULL
) ||
693 ((TargetSwAddress
!= NULL
) && (ResolvedEvent
== NULL
)) ||
694 ((TargetSwAddress
== NULL
) && (ResolvedEvent
!= NULL
))) {
695 return EFI_INVALID_PARAMETER
;
698 Instance
= ARP_INSTANCE_DATA_FROM_THIS (This
);
700 if (!Instance
->Configured
) {
701 return EFI_NOT_STARTED
;
704 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
707 // Cancel the specified request.
709 Count
= ArpCancelRequest (Instance
, TargetSwAddress
, ResolvedEvent
);
712 // Dispatch the DPCs queued by the NotifyFunction of the events signaled
713 // by ArpCancleRequest.
715 NetLibDispatchDpc ();
717 gBS
->RestoreTPL (OldTpl
);
719 return (Count
== 0) ? EFI_NOT_FOUND
: EFI_SUCCESS
;