Import ArpDxe, Dhcp4Dxe, Ip4Dxe, Mtftp4Dxe, PxeBcDxe and PxeDhcp4Dxe.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3492 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
30
MdeModulePkg/Universal/Network/ArpDxe/ArpDebug.h
Normal file
30
MdeModulePkg/Universal/Network/ArpDxe/ArpDebug.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ArpDebug.h
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _ARP_DEBUG_H_
|
||||
#define _ARP_DEBUG_H_
|
||||
|
||||
|
||||
#define ARP_DEBUG_TRACE(PrintArg) NET_DEBUG_TRACE ("Arp", PrintArg)
|
||||
#define ARP_DEBUG_WARN(PrintArg) NET_DEBUG_WARNING ("Arp", PrintArg)
|
||||
#define ARP_DEBUG_ERROR(PrintArg) NET_DEBUG_ERROR ("Arp", PrintArg)
|
||||
|
||||
#endif
|
||||
|
763
MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c
Normal file
763
MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c
Normal file
@@ -0,0 +1,763 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ArpDriver.c
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include "ArpDriver.h"
|
||||
#include "ArpImpl.h"
|
||||
|
||||
EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding = {
|
||||
ArpDriverBindingSupported,
|
||||
ArpDriverBindingStart,
|
||||
ArpDriverBindingStop,
|
||||
0xa,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Create and initialize the arp service context data.
|
||||
|
||||
@param ImageHandle The image handle representing the loaded driver
|
||||
image.
|
||||
@param ControllerHandle The controller handle the driver binds to.
|
||||
@param ArpService Pointer to the buffer containing the arp service
|
||||
context data.
|
||||
|
||||
@retval EFI_SUCCESS The arp service context is initialized.
|
||||
@retval other Failed to initialize the arp service context.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ArpCreateService (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN ARP_SERVICE_DATA *ArpService
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
ASSERT (ArpService != NULL);
|
||||
|
||||
ArpService->Signature = ARP_SERVICE_DATA_SIGNATURE;
|
||||
|
||||
//
|
||||
// Init the servicebinding protocol members.
|
||||
//
|
||||
ArpService->ServiceBinding.CreateChild = ArpServiceBindingCreateChild;
|
||||
ArpService->ServiceBinding.DestroyChild = ArpServiceBindingDestroyChild;
|
||||
|
||||
//
|
||||
// Save the handles.
|
||||
//
|
||||
ArpService->ImageHandle = ImageHandle;
|
||||
ArpService->ControllerHandle = ControllerHandle;
|
||||
|
||||
//
|
||||
// Create a MNP child instance.
|
||||
//
|
||||
Status = NetLibCreateServiceChild (
|
||||
ControllerHandle,
|
||||
ImageHandle,
|
||||
&gEfiManagedNetworkServiceBindingProtocolGuid,
|
||||
&ArpService->MnpChildHandle
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Open the MNP protocol.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ArpService->MnpChildHandle,
|
||||
&gEfiManagedNetworkProtocolGuid,
|
||||
(VOID **)&ArpService->Mnp,
|
||||
ImageHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Get the underlayer Snp mode data.
|
||||
//
|
||||
Status = ArpService->Mnp->GetModeData (ArpService->Mnp, NULL, &ArpService->SnpMode);
|
||||
if ((Status != EFI_NOT_STARTED) && EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
if (ArpService->SnpMode.IfType != NET_IFTYPE_ETHERNET) {
|
||||
//
|
||||
// Only support the ethernet.
|
||||
//
|
||||
Status = EFI_UNSUPPORTED;
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Set the Mnp config parameters.
|
||||
//
|
||||
ArpService->MnpConfigData.ReceivedQueueTimeoutValue = 0;
|
||||
ArpService->MnpConfigData.TransmitQueueTimeoutValue = 0;
|
||||
ArpService->MnpConfigData.ProtocolTypeFilter = ARP_ETHER_PROTO_TYPE;
|
||||
ArpService->MnpConfigData.EnableUnicastReceive = TRUE;
|
||||
ArpService->MnpConfigData.EnableMulticastReceive = FALSE;
|
||||
ArpService->MnpConfigData.EnableBroadcastReceive = TRUE;
|
||||
ArpService->MnpConfigData.EnablePromiscuousReceive = FALSE;
|
||||
ArpService->MnpConfigData.FlushQueuesOnReset = TRUE;
|
||||
ArpService->MnpConfigData.EnableReceiveTimestamps = FALSE;
|
||||
ArpService->MnpConfigData.DisableBackgroundPolling = FALSE;
|
||||
|
||||
//
|
||||
// Configure the Mnp child.
|
||||
//
|
||||
Status = ArpService->Mnp->Configure (ArpService->Mnp, &ArpService->MnpConfigData);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Create the event used in the RxToken.
|
||||
//
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
NET_TPL_EVENT,
|
||||
ArpOnFrameRcvd,
|
||||
ArpService,
|
||||
&ArpService->RxToken.Event
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Create the Arp heartbeat timer.
|
||||
//
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_NOTIFY_SIGNAL | EVT_TIMER,
|
||||
NET_TPL_TIMER,
|
||||
ArpTimerHandler,
|
||||
ArpService,
|
||||
&ArpService->PeriodicTimer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Start the heartbeat timer.
|
||||
//
|
||||
Status = gBS->SetTimer (
|
||||
ArpService->PeriodicTimer,
|
||||
TimerPeriodic,
|
||||
ARP_PERIODIC_TIMER_INTERVAL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init the lock.
|
||||
//
|
||||
NET_LOCK_INIT (&ArpService->Lock);
|
||||
|
||||
//
|
||||
// Init the lists.
|
||||
//
|
||||
NetListInit (&ArpService->ChildrenList);
|
||||
NetListInit (&ArpService->PendingRequestTable);
|
||||
NetListInit (&ArpService->DeniedCacheTable);
|
||||
NetListInit (&ArpService->ResolvedCacheTable);
|
||||
|
||||
ERROR_EXIT:
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Clean the arp service context data.
|
||||
|
||||
@param ArpService Pointer to the buffer containing the arp service
|
||||
context data.
|
||||
|
||||
@return None.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
VOID
|
||||
ArpCleanService (
|
||||
IN ARP_SERVICE_DATA *ArpService
|
||||
)
|
||||
{
|
||||
NET_CHECK_SIGNATURE (ArpService, ARP_SERVICE_DATA_SIGNATURE);
|
||||
|
||||
if (ArpService->PeriodicTimer != NULL) {
|
||||
//
|
||||
// Cancle and close the PeriodicTimer.
|
||||
//
|
||||
gBS->SetTimer (ArpService->PeriodicTimer, TimerCancel, 0);
|
||||
gBS->CloseEvent (ArpService->PeriodicTimer);
|
||||
}
|
||||
|
||||
if (ArpService->RxToken.Event != NULL) {
|
||||
//
|
||||
// Cancle the RxToken and close the event in the RxToken.
|
||||
//
|
||||
ArpService->Mnp->Cancel (ArpService->Mnp, NULL);
|
||||
gBS->CloseEvent (ArpService->RxToken.Event);
|
||||
}
|
||||
|
||||
if (ArpService->Mnp != NULL) {
|
||||
//
|
||||
// Reset the Mnp child and close the Mnp protocol.
|
||||
//
|
||||
ArpService->Mnp->Configure (ArpService->Mnp, NULL);
|
||||
gBS->CloseProtocol (
|
||||
ArpService->MnpChildHandle,
|
||||
&gEfiManagedNetworkProtocolGuid,
|
||||
ArpService->ImageHandle,
|
||||
ArpService->ControllerHandle
|
||||
);
|
||||
}
|
||||
|
||||
if (ArpService->MnpChildHandle != NULL) {
|
||||
//
|
||||
// Destroy the mnp child.
|
||||
//
|
||||
NetLibDestroyServiceChild(
|
||||
ArpService->ControllerHandle,
|
||||
ArpService->ImageHandle,
|
||||
&gEfiManagedNetworkServiceBindingProtocolGuid,
|
||||
ArpService->MnpChildHandle
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Test to see if this driver supports ControllerHandle.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param ControllerHandle Handle of device to test.
|
||||
@param RemainingDevicePath Optional parameter use to pick a specific child
|
||||
device to start.
|
||||
|
||||
@retval EFI_SUCCES This driver supports this device
|
||||
@retval EFI_ALREADY_STARTED This driver is already running on this device.
|
||||
@retval other This driver does not support this device.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Test to see if Arp SB is already installed.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiArpServiceBindingProtocolGuid,
|
||||
NULL,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
||||
);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
//
|
||||
// Test to see if MNP SB is installed.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiManagedNetworkServiceBindingProtocolGuid,
|
||||
NULL,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Start this driver on ControllerHandle.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param ControllerHandle Handle of device to bind driver to
|
||||
@param RemainingDevicePath Optional parameter use to pick a specific child
|
||||
device to start.
|
||||
|
||||
@retval EFI_SUCCES This driver is added to ControllerHandle
|
||||
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
|
||||
@retval other This driver does not support this device
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
|
||||
//
|
||||
// Allocate a zero pool for ArpService.
|
||||
//
|
||||
ArpService = NetAllocateZeroPool (sizeof(ARP_SERVICE_DATA));
|
||||
if (ArpService == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the arp service context data.
|
||||
//
|
||||
Status = ArpCreateService (This->DriverBindingHandle, ControllerHandle, ArpService);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// Install the ARP service binding protocol.
|
||||
//
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&ControllerHandle,
|
||||
&gEfiArpServiceBindingProtocolGuid,
|
||||
&ArpService->ServiceBinding,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// OK, start to receive arp packets from Mnp.
|
||||
//
|
||||
Status = ArpService->Mnp->Receive (ArpService->Mnp, &ArpService->RxToken);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
||||
ERROR:
|
||||
|
||||
//
|
||||
// On error, clean the arp service context data, and free the memory allocated.
|
||||
//
|
||||
ArpCleanService (ArpService);
|
||||
NetFreePool (ArpService);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Stop this driver on ControllerHandle.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param ControllerHandle Handle of device to stop driver on
|
||||
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number
|
||||
of children is zero stop the entire bus driver.
|
||||
@param ChildHandleBuffer List of Child Handles to Stop.
|
||||
|
||||
@retval EFI_SUCCES This driver is removed ControllerHandle
|
||||
@retval other This driver was not removed from this device
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE NicHandle;
|
||||
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
|
||||
//
|
||||
// Get the NicHandle which the arp servicebinding is installed on.
|
||||
//
|
||||
NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid);
|
||||
if (NicHandle == NULL) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to get the arp servicebinding protocol on the NicHandle.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
NicHandle,
|
||||
&gEfiArpServiceBindingProtocolGuid,
|
||||
(VOID **)&ServiceBinding,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ARP_DEBUG_ERROR (("ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status));
|
||||
return Status;
|
||||
}
|
||||
|
||||
ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding);
|
||||
|
||||
while (!NetListIsEmpty (&ArpService->ChildrenList)) {
|
||||
//
|
||||
// Iterate all the instances.
|
||||
//
|
||||
Instance = NET_LIST_HEAD (&ArpService->ChildrenList, ARP_INSTANCE_DATA, List);
|
||||
|
||||
//
|
||||
// Destroy this arp child.
|
||||
//
|
||||
ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
|
||||
}
|
||||
|
||||
ASSERT (NetListIsEmpty (&ArpService->PendingRequestTable));
|
||||
ASSERT (NetListIsEmpty (&ArpService->DeniedCacheTable));
|
||||
ASSERT (NetListIsEmpty (&ArpService->ResolvedCacheTable));
|
||||
|
||||
//
|
||||
// Uninstall the ARP ServiceBinding protocol.
|
||||
//
|
||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||
NicHandle,
|
||||
&gEfiArpServiceBindingProtocolGuid,
|
||||
&ArpService->ServiceBinding,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ARP_DEBUG_ERROR (("ArpDriverBindingStop: Failed to uninstall ArpSb, %r.\n", Status));
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Clean the arp servicebinding context data and free the memory allocated.
|
||||
//
|
||||
ArpCleanService (ArpService);
|
||||
NetFreePool (ArpService);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Creates a child handle with a set of I/O services.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param ChildHandle Pointer to the handle of the child to create. If
|
||||
it is NULL, then a new handle is created. If it is
|
||||
not NULL, then the I/O services are added to the
|
||||
existing child handle.
|
||||
|
||||
@retval EFI_SUCCES The child handle was created with the I/O
|
||||
services.
|
||||
@retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
|
||||
the child.
|
||||
@retval other The child handle was not created.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpServiceBindingCreateChild (
|
||||
IN EFI_SERVICE_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE *ChildHandle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
VOID *Mnp;
|
||||
|
||||
if ((This == NULL) || (ChildHandle == NULL)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
|
||||
|
||||
//
|
||||
// Allocate memory for the instance context data.
|
||||
//
|
||||
Instance = NetAllocateZeroPool (sizeof(ARP_INSTANCE_DATA));
|
||||
if (Instance == NULL) {
|
||||
ARP_DEBUG_ERROR (("ArpSBCreateChild: Failed to allocate memory for Instance.\n"));
|
||||
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// Init the instance context data.
|
||||
//
|
||||
ArpInitInstance (ArpService, Instance);
|
||||
|
||||
//
|
||||
// Install the ARP protocol onto the ChildHandle.
|
||||
//
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
ChildHandle,
|
||||
&gEfiArpProtocolGuid,
|
||||
(VOID *)&Instance->ArpProto,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ARP_DEBUG_ERROR (("ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status));
|
||||
|
||||
NetFreePool (Instance);
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Save the ChildHandle.
|
||||
//
|
||||
Instance->Handle = *ChildHandle;
|
||||
|
||||
//
|
||||
// Open the Managed Network protocol BY_CHILD.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ArpService->MnpChildHandle,
|
||||
&gEfiManagedNetworkProtocolGuid,
|
||||
(VOID **) &Mnp,
|
||||
gArpDriverBinding.DriverBindingHandle,
|
||||
Instance->Handle,
|
||||
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
// Insert the instance into children list managed by the arp service context data.
|
||||
//
|
||||
NetListInsertTail (&ArpService->ChildrenList, &Instance->List);
|
||||
ArpService->ChildrenNumber++;
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
ERROR:
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
|
||||
gBS->CloseProtocol (
|
||||
ArpService->MnpChildHandle,
|
||||
&gEfiManagedNetworkProtocolGuid,
|
||||
gArpDriverBinding.DriverBindingHandle,
|
||||
Instance->Handle
|
||||
);
|
||||
|
||||
gBS->UninstallMultipleProtocolInterfaces (
|
||||
Instance->Handle,
|
||||
&gEfiArpProtocolGuid,
|
||||
&Instance->ArpProto,
|
||||
NULL
|
||||
);
|
||||
|
||||
//
|
||||
// Free the allocated memory.
|
||||
//
|
||||
NetFreePool (Instance);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Destroys a child handle with a set of I/O services.
|
||||
|
||||
@param This Protocol instance pointer.
|
||||
@param ChildHandle Handle of the child to destroy.
|
||||
|
||||
@retval EFI_SUCCES The I/O services were removed from the child
|
||||
handle.
|
||||
@retval EFI_UNSUPPORTED The child handle does not support the I/O services
|
||||
that are being removed.
|
||||
@retval EFI_INVALID_PARAMETER Child handle is not a valid EFI Handle.
|
||||
@retval EFI_ACCESS_DENIED The child handle could not be destroyed because
|
||||
its I/O services are being used.
|
||||
@retval other The child handle was not destroyed.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpServiceBindingDestroyChild (
|
||||
IN EFI_SERVICE_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ChildHandle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
EFI_ARP_PROTOCOL *Arp;
|
||||
|
||||
if ((This == NULL) || (ChildHandle == NULL)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
|
||||
|
||||
//
|
||||
// Get the arp protocol.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ChildHandle,
|
||||
&gEfiArpProtocolGuid,
|
||||
(VOID **)&Arp,
|
||||
ArpService->ImageHandle,
|
||||
ChildHandle,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (Arp);
|
||||
|
||||
if (Instance->Destroyed) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Use the Destroyed as a flag to avoid re-entrance.
|
||||
//
|
||||
Instance->Destroyed = TRUE;
|
||||
|
||||
//
|
||||
// Close the Managed Network protocol.
|
||||
//
|
||||
gBS->CloseProtocol (
|
||||
ArpService->MnpChildHandle,
|
||||
&gEfiManagedNetworkProtocolGuid,
|
||||
gArpDriverBinding.DriverBindingHandle,
|
||||
ChildHandle
|
||||
);
|
||||
|
||||
//
|
||||
// Uninstall the ARP protocol.
|
||||
//
|
||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||
ChildHandle,
|
||||
&gEfiArpProtocolGuid,
|
||||
&Instance->ArpProto,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
ARP_DEBUG_ERROR (("ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n",
|
||||
Status));
|
||||
|
||||
Instance->Destroyed = FALSE;
|
||||
return Status;
|
||||
}
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
Instance->Destroyed = FALSE;
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
if (Instance->Configured) {
|
||||
//
|
||||
// Delete the related cache entry.
|
||||
//
|
||||
ArpDeleteCacheEntry (Instance, FALSE, NULL, TRUE);
|
||||
|
||||
//
|
||||
// Reset the instance configuration.
|
||||
//
|
||||
ArpConfigureInstance (Instance, NULL);
|
||||
}
|
||||
|
||||
//
|
||||
// Remove this instance from the ChildrenList.
|
||||
//
|
||||
NetListRemoveEntry (&Instance->List);
|
||||
ArpService->ChildrenNumber--;
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
NetFreePool (Instance);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
//@MT: EFI_DRIVER_ENTRY_POINT (ArpDriverEntryPoint)
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverEntryPoint (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
The entry point for Arp driver which installs the driver binding and component name
|
||||
protocol on its ImageHandle.
|
||||
|
||||
Arguments:
|
||||
|
||||
ImageHandle - The image handle of the driver.
|
||||
SystemTable - The system table.
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - if the driver binding and component name protocols are successfully
|
||||
installed, otherwise if failed.
|
||||
|
||||
--*/
|
||||
{
|
||||
return NetLibInstallAllDriverProtocols (
|
||||
ImageHandle,
|
||||
SystemTable,
|
||||
&gArpDriverBinding,
|
||||
ImageHandle,
|
||||
&gArpComponentName,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
84
MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.h
Normal file
84
MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006 - 2007, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ArpDriver.c
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _ARP_DRIVER_H_
|
||||
#define _ARP_DRIVER_H_
|
||||
|
||||
|
||||
#include <PiDxe.h>
|
||||
|
||||
#include <Protocol/Arp.h>
|
||||
#include <Protocol/ManagedNetwork.h>
|
||||
#include <Protocol/ServiceBinding.h>
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
#include "ArpDebug.h"
|
||||
|
||||
//
|
||||
// Global variables
|
||||
//
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding;
|
||||
extern EFI_COMPONENT_NAME_PROTOCOL gArpComponentName;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpServiceBindingCreateChild (
|
||||
IN EFI_SERVICE_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE *ChildHandle
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpServiceBindingDestroyChild (
|
||||
IN EFI_SERVICE_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ChildHandle
|
||||
);
|
||||
|
||||
#endif
|
||||
|
59
MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
Normal file
59
MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
Normal file
@@ -0,0 +1,59 @@
|
||||
#/** @file
|
||||
# Component description file for ARP module
|
||||
#
|
||||
# Copyright (c) 2006, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = ArpDxe
|
||||
FILE_GUID = 529D3F93-E8E9-4e73-B1E1-BDF6A9D50113
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
EDK_RELEASE_VERSION = 0x00020000
|
||||
EFI_SPECIFICATION_VERSION = 0x00020000
|
||||
|
||||
ENTRY_POINT = ArpDriverEntryPoint
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources.common]
|
||||
ArpMain.c
|
||||
ArpDriver.h
|
||||
ComponentName.c
|
||||
ArpImpl.h
|
||||
ArpImpl.c
|
||||
ArpDebug.h
|
||||
ArpDriver.c
|
||||
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
|
||||
[LibraryClasses]
|
||||
UefiLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
DebugLib
|
||||
NetLib
|
||||
|
||||
|
||||
[Protocols]
|
||||
gEfiManagedNetworkServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||
gEfiArpServiceBindingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||
gEfiManagedNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||
gEfiArpProtocolGuid # PROTOCOL ALWAYS_CONSUMED
|
||||
|
72
MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.msa
Normal file
72
MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.msa
Normal file
@@ -0,0 +1,72 @@
|
||||
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<MsaHeader>
|
||||
<ModuleName>Arp</ModuleName>
|
||||
<ModuleType>DXE_DRIVER</ModuleType>
|
||||
<GuidValue>529D3F93-E8E9-4e73-B1E1-BDF6A9D50113</GuidValue>
|
||||
<Version>1.0</Version>
|
||||
<Abstract>Component name for module Arp</Abstract>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2007, Intel Corporation. All rights reserved.</Copyright>
|
||||
<License>All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
|
||||
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
|
||||
</MsaHeader>
|
||||
<ModuleDefinitions>
|
||||
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
|
||||
<BinaryModule>false</BinaryModule>
|
||||
<OutputFileBasename>Arp</OutputFileBasename>
|
||||
</ModuleDefinitions>
|
||||
<LibraryClassDefinitions>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>DebugLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiDriverEntryPoint</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiBootServicesTableLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiLib</Keyword>
|
||||
</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>ArpDriver.c</Filename>
|
||||
<Filename>ArpDebug.h</Filename>
|
||||
<Filename>ArpImpl.c</Filename>
|
||||
<Filename>ArpImpl.h</Filename>
|
||||
<Filename>ComponentName.c</Filename>
|
||||
<Filename>ArpDriver.h</Filename>
|
||||
<Filename>ArpMain.c</Filename>
|
||||
</SourceFiles>
|
||||
<PackageDependencies>
|
||||
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
|
||||
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
|
||||
</PackageDependencies>
|
||||
<Protocols>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">
|
||||
<ProtocolCName>gEfiArpProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">
|
||||
<ProtocolCName>gEfiManagedNetworkProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">
|
||||
<ProtocolCName>gEfiArpServiceBindingProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">
|
||||
<ProtocolCName>gEfiManagedNetworkServiceBindingProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
</Protocols>
|
||||
<Externs>
|
||||
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
|
||||
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
|
||||
<Extern>
|
||||
<ModuleEntryPoint>ArpDriverEntryPoint</ModuleEntryPoint>
|
||||
</Extern>
|
||||
</Externs>
|
||||
</ModuleSurfaceArea>
|
1628
MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
Normal file
1628
MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.c
Normal file
File diff suppressed because it is too large
Load Diff
341
MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.h
Normal file
341
MdeModulePkg/Universal/Network/ArpDxe/ArpImpl.h
Normal file
@@ -0,0 +1,341 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006 - 2007, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ArpImpl.h
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _ARP_IMPL_H_
|
||||
#define _ARP_IMPL_H_
|
||||
|
||||
|
||||
#include <PiDxe.h>
|
||||
|
||||
#include <Protocol/Arp.h>
|
||||
#include <Protocol/ManagedNetwork.h>
|
||||
#include <Protocol/ServiceBinding.h>
|
||||
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/NetLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
|
||||
#include "ArpDebug.h"
|
||||
|
||||
#define ARP_ETHER_PROTO_TYPE 0x0806
|
||||
#define IPv4_ETHER_PROTO_TYPE 0x0800
|
||||
#define IPv6_ETHER_PROTO_TYPE 0x86DD
|
||||
|
||||
#define ARP_OPCODE_REQUEST 0x0001
|
||||
#define ARP_OPCODE_REPLY 0x0002
|
||||
|
||||
#define ARP_DEFAULT_TIMEOUT_VALUE (400 * TICKS_PER_SECOND)
|
||||
#define ARP_DEFAULT_RETRY_COUNT 2
|
||||
#define ARP_DEFAULT_RETRY_INTERVAL (5 * TICKS_PER_MS)
|
||||
#define ARP_PERIODIC_TIMER_INTERVAL (500 * TICKS_PER_MS)
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct _ARP_HEAD {
|
||||
UINT16 HwType;
|
||||
UINT16 ProtoType;
|
||||
UINT8 HwAddrLen;
|
||||
UINT8 ProtoAddrLen;
|
||||
UINT16 OpCode;
|
||||
} ARP_HEAD;
|
||||
#pragma pack()
|
||||
|
||||
typedef struct _ARP_ADDRESS {
|
||||
UINT8 *SenderHwAddr;
|
||||
UINT8 *SenderProtoAddr;
|
||||
UINT8 *TargetHwAddr;
|
||||
UINT8 *TargetProtoAddr;
|
||||
} ARP_ADDRESS;
|
||||
|
||||
#define MATCH_SW_ADDRESS 0x1
|
||||
#define MATCH_HW_ADDRESS 0x2
|
||||
|
||||
typedef enum {
|
||||
ByNone = 0,
|
||||
ByProtoAddress = MATCH_SW_ADDRESS,
|
||||
ByHwAddress = MATCH_HW_ADDRESS,
|
||||
ByBoth = MATCH_SW_ADDRESS | MATCH_HW_ADDRESS
|
||||
} FIND_OPTYPE;
|
||||
|
||||
#define ARP_INSTANCE_DATA_SIGNATURE EFI_SIGNATURE_32('A', 'R', 'P', 'I')
|
||||
|
||||
#define ARP_INSTANCE_DATA_FROM_THIS(a) \
|
||||
CR ( \
|
||||
(a), \
|
||||
ARP_INSTANCE_DATA, \
|
||||
ArpProto, \
|
||||
ARP_INSTANCE_DATA_SIGNATURE \
|
||||
)
|
||||
|
||||
typedef struct _ARP_SERVICE_DATA ARP_SERVICE_DATA;
|
||||
|
||||
typedef struct _ARP_INSTANCE_DATA {
|
||||
UINT32 Signature;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_ARP_PROTOCOL ArpProto;
|
||||
NET_LIST_ENTRY List;
|
||||
EFI_ARP_CONFIG_DATA ConfigData;
|
||||
BOOLEAN Configured;
|
||||
BOOLEAN Destroyed;
|
||||
} ARP_INSTANCE_DATA;
|
||||
|
||||
#define ARP_SERVICE_DATA_SIGNATURE EFI_SIGNATURE_32('A', 'R', 'P', 'S')
|
||||
|
||||
#define ARP_SERVICE_DATA_FROM_THIS(a) \
|
||||
CR ( \
|
||||
(a), \
|
||||
ARP_SERVICE_DATA, \
|
||||
ServiceBinding, \
|
||||
ARP_SERVICE_DATA_SIGNATURE \
|
||||
)
|
||||
|
||||
struct _ARP_SERVICE_DATA {
|
||||
UINT32 Signature;
|
||||
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
|
||||
|
||||
EFI_HANDLE MnpChildHandle;
|
||||
EFI_HANDLE ImageHandle;
|
||||
EFI_HANDLE ControllerHandle;
|
||||
|
||||
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
|
||||
EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
|
||||
EFI_MANAGED_NETWORK_COMPLETION_TOKEN RxToken;
|
||||
|
||||
EFI_SIMPLE_NETWORK_MODE SnpMode;
|
||||
|
||||
NET_LOCK Lock;
|
||||
|
||||
UINTN ChildrenNumber;
|
||||
NET_LIST_ENTRY ChildrenList;
|
||||
|
||||
NET_LIST_ENTRY PendingRequestTable;
|
||||
NET_LIST_ENTRY DeniedCacheTable;
|
||||
NET_LIST_ENTRY ResolvedCacheTable;
|
||||
|
||||
EFI_EVENT PeriodicTimer;
|
||||
};
|
||||
|
||||
typedef struct _USER_REQUEST_CONTEXT {
|
||||
NET_LIST_ENTRY List;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
EFI_EVENT UserRequestEvent;
|
||||
VOID *UserHwAddrBuffer;
|
||||
} USER_REQUEST_CONTEXT;
|
||||
|
||||
#define ARP_MAX_PROTOCOL_ADDRESS_LEN sizeof(EFI_IP_ADDRESS)
|
||||
#define ARP_MAX_HARDWARE_ADDRESS_LEN sizeof(EFI_MAC_ADDRESS)
|
||||
|
||||
typedef struct _NET_ARP_ADDRESS {
|
||||
UINT16 Type;
|
||||
UINT8 Length;
|
||||
UINT8 *AddressPtr;
|
||||
union {
|
||||
UINT8 ProtoAddress[ARP_MAX_PROTOCOL_ADDRESS_LEN];
|
||||
UINT8 HwAddress[ARP_MAX_HARDWARE_ADDRESS_LEN];
|
||||
} Buffer;
|
||||
} NET_ARP_ADDRESS;
|
||||
|
||||
typedef enum {
|
||||
Hardware,
|
||||
Protocol
|
||||
} ARP_ADDRESS_TYPE;
|
||||
|
||||
typedef struct _ARP_CACHE_ENTRY {
|
||||
NET_LIST_ENTRY List;
|
||||
|
||||
UINT32 RetryCount;
|
||||
UINT32 DefaultDecayTime;
|
||||
UINT32 DecayTime;
|
||||
UINT32 NextRetryTime;
|
||||
|
||||
NET_ARP_ADDRESS Addresses[2];
|
||||
|
||||
NET_LIST_ENTRY UserRequestList;
|
||||
} ARP_CACHE_ENTRY;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpConfigure (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpAdd (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN DenyFlag,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN VOID *TargetHwAddress OPTIONAL,
|
||||
IN UINT32 TimeoutValue,
|
||||
IN BOOLEAN Overwrite
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpFind (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN VOID *AddressBuffer OPTIONAL,
|
||||
OUT UINT32 *EntryLength OPTIONAL,
|
||||
OUT UINT32 *EntryCount OPTIONAL,
|
||||
OUT EFI_ARP_FIND_DATA **Entries OPTIONAL,
|
||||
IN BOOLEAN Refresh
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDelete (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN VOID *AddressBuffer OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpFlush (
|
||||
IN EFI_ARP_PROTOCOL *This
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpRequest (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN EFI_EVENT ResolvedEvent OPTIONAL,
|
||||
OUT VOID *TargetHwAddress
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpCancel (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN EFI_EVENT ResolvedEvent OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ArpConfigureInstance (
|
||||
IN ARP_INSTANCE_DATA *Instance,
|
||||
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
|
||||
);
|
||||
|
||||
ARP_CACHE_ENTRY *
|
||||
ArpFindDeniedCacheEntry (
|
||||
IN ARP_SERVICE_DATA *ArpService,
|
||||
IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,
|
||||
IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL
|
||||
);
|
||||
|
||||
ARP_CACHE_ENTRY *
|
||||
ArpFindNextCacheEntryInTable (
|
||||
IN NET_LIST_ENTRY *CacheTable,
|
||||
IN NET_LIST_ENTRY *StartEntry,
|
||||
IN FIND_OPTYPE FindOpType,
|
||||
IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,
|
||||
IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL
|
||||
);
|
||||
|
||||
ARP_CACHE_ENTRY *
|
||||
ArpAllocCacheEntry (
|
||||
IN ARP_INSTANCE_DATA *Instance
|
||||
);
|
||||
|
||||
VOID
|
||||
ArpFillAddressInCacheEntry (
|
||||
IN ARP_CACHE_ENTRY *CacheEntry,
|
||||
IN NET_ARP_ADDRESS *HwAddr OPTIONAL,
|
||||
IN NET_ARP_ADDRESS *SwAddr OPTIONAL
|
||||
);
|
||||
|
||||
UINTN
|
||||
ArpAddressResolved (
|
||||
IN ARP_CACHE_ENTRY *CacheEntry,
|
||||
IN ARP_INSTANCE_DATA *Instance OPTIONAL,
|
||||
IN EFI_EVENT UserEvent OPTIONAL
|
||||
);
|
||||
|
||||
UINTN
|
||||
ArpDeleteCacheEntry (
|
||||
IN ARP_INSTANCE_DATA *Instance,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN UINT8 *AddressBuffer OPTIONAL,
|
||||
IN BOOLEAN Force
|
||||
);
|
||||
|
||||
VOID
|
||||
ArpSendFrame (
|
||||
IN ARP_INSTANCE_DATA *Instance,
|
||||
IN ARP_CACHE_ENTRY *CacheEntry,
|
||||
IN UINT16 ArpOpCode
|
||||
);
|
||||
|
||||
VOID
|
||||
ArpInitInstance (
|
||||
IN ARP_SERVICE_DATA *ArpService,
|
||||
IN ARP_INSTANCE_DATA *Instance
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArpOnFrameRcvd (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArpOnFrameSent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ArpTimerHandler (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
UINTN
|
||||
ArpCancelRequest (
|
||||
IN ARP_INSTANCE_DATA *Instance,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN EFI_EVENT UserEvent OPTIONAL
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ArpFindCacheEntry (
|
||||
IN ARP_INSTANCE_DATA *Instance,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN VOID *AddressBuffer OPTIONAL,
|
||||
OUT UINT32 *EntryLength OPTIONAL,
|
||||
OUT UINT32 *EntryCount OPTIONAL,
|
||||
OUT EFI_ARP_FIND_DATA **Entries OPTIONAL,
|
||||
IN BOOLEAN Refresh
|
||||
);
|
||||
|
||||
#endif
|
||||
|
727
MdeModulePkg/Universal/Network/ArpDxe/ArpMain.c
Normal file
727
MdeModulePkg/Universal/Network/ArpDxe/ArpMain.c
Normal file
@@ -0,0 +1,727 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ArpMain.c
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#include "ArpImpl.h"
|
||||
|
||||
|
||||
/**
|
||||
This function is used to assign a station address to the ARP cache for this instance
|
||||
of the ARP driver. A call to this function with the ConfigData field set to NULL
|
||||
will reset this ARP instance.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param ConfigData Pointer to the EFI_ARP_CONFIG_DATA structure.
|
||||
|
||||
@retval EFI_SUCCESS The new station address was successfully
|
||||
registered.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
||||
This is NULL. SwAddressLength is zero when
|
||||
ConfigData is not NULL. StationAddress is NULL
|
||||
when ConfigData is not NULL.
|
||||
@retval EFI_ACCESS_DENIED The SwAddressType, SwAddressLength, or
|
||||
StationAddress is different from the one that is
|
||||
already registered.
|
||||
@retval EFI_OUT_OF_RESOURCES Storage for the new StationAddress could not be
|
||||
allocated.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpConfigure (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
|
||||
if (This == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((ConfigData != NULL) &&
|
||||
((ConfigData->SwAddressLength == 0) ||
|
||||
(ConfigData->StationAddress == NULL) ||
|
||||
(ConfigData->SwAddressType <= 1500))) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&Instance->ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure this instance, the ConfigData has already passed the basic checks.
|
||||
//
|
||||
Status = ArpConfigureInstance (Instance, ConfigData);
|
||||
|
||||
NET_UNLOCK (&Instance->ArpService->Lock);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function is used to insert entries into the ARP cache.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param DenyFlag Set to TRUE if this entry is a deny entry. Set to
|
||||
FALSE if this entry is a normal entry.
|
||||
@param TargetSwAddress Pointer to a protocol address to add (or deny).
|
||||
May be set to NULL if DenyFlag is TRUE.
|
||||
@param TargetHwAddress Pointer to a hardware address to add (or deny).
|
||||
May be set to NULL if DenyFlag is TRUE.
|
||||
@param TimeoutValue Time in 100-ns units that this entry will remain
|
||||
in the ARP cache. A value of zero means that the
|
||||
entry is permanent. A nonzero value will override
|
||||
the one given by Configure() if the entry to be
|
||||
added is a dynamic entry.
|
||||
@param Overwrite If TRUE, the matching cache entry will be
|
||||
overwritten with the supplied parameters. If
|
||||
FALSE, EFI_ACCESS_DENIED is returned if the
|
||||
corresponding cache entry already exists.
|
||||
|
||||
@retval EFI_SUCCESS The entry has been added or updated.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
||||
This is NULL. DenyFlag is FALSE and
|
||||
TargetHwAddress is NULL. DenyFlag is FALSE and
|
||||
TargetSwAddress is NULL. TargetHwAddress is NULL
|
||||
and TargetSwAddress is NULL. Both TargetSwAddress
|
||||
and TargetHwAddress are not NULL when DenyFlag is
|
||||
TRUE.
|
||||
@retval EFI_OUT_OF_RESOURCES The new ARP cache entry could not be allocated.
|
||||
@retval EFI_ACCESS_DENIED The ARP cache entry already exists and Overwrite
|
||||
is not true.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpAdd (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN DenyFlag,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN VOID *TargetHwAddress OPTIONAL,
|
||||
IN UINT32 TimeoutValue,
|
||||
IN BOOLEAN Overwrite
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
ARP_CACHE_ENTRY *CacheEntry;
|
||||
EFI_SIMPLE_NETWORK_MODE *SnpMode;
|
||||
NET_ARP_ADDRESS MatchAddress[2];
|
||||
|
||||
if (This == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (((!DenyFlag) && ((TargetHwAddress == NULL) || (TargetSwAddress == NULL))) ||
|
||||
(DenyFlag && (TargetHwAddress != NULL) && (TargetSwAddress != NULL)) ||
|
||||
((TargetHwAddress == NULL) && (TargetSwAddress == NULL))) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
ArpService = Instance->ArpService;
|
||||
SnpMode = &Instance->ArpService->SnpMode;
|
||||
|
||||
//
|
||||
// Fill the hardware address part in the MatchAddress.
|
||||
//
|
||||
MatchAddress[Hardware].Type = SnpMode->IfType;
|
||||
MatchAddress[Hardware].Length = (UINT8) SnpMode->HwAddressSize;
|
||||
MatchAddress[Hardware].AddressPtr = TargetHwAddress;
|
||||
|
||||
//
|
||||
// Fill the software address part in the MatchAddress.
|
||||
//
|
||||
MatchAddress[Protocol].Type = Instance->ConfigData.SwAddressType;
|
||||
MatchAddress[Protocol].Length = Instance->ConfigData.SwAddressLength;
|
||||
MatchAddress[Protocol].AddressPtr = TargetSwAddress;
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// See whether the entry to add exists. Check the DeinedCacheTable first.
|
||||
//
|
||||
CacheEntry = ArpFindDeniedCacheEntry (
|
||||
ArpService,
|
||||
&MatchAddress[Protocol],
|
||||
&MatchAddress[Hardware]
|
||||
);
|
||||
|
||||
if (CacheEntry == NULL) {
|
||||
//
|
||||
// Check the ResolvedCacheTable
|
||||
//
|
||||
CacheEntry = ArpFindNextCacheEntryInTable (
|
||||
&ArpService->ResolvedCacheTable,
|
||||
NULL,
|
||||
ByBoth,
|
||||
&MatchAddress[Protocol],
|
||||
&MatchAddress[Hardware]
|
||||
);
|
||||
}
|
||||
|
||||
if ((CacheEntry != NULL) && !Overwrite) {
|
||||
//
|
||||
// The entry to add exists, if not Overwirte, deny this add request.
|
||||
//
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
if ((CacheEntry == NULL) && (TargetSwAddress != NULL)) {
|
||||
//
|
||||
// Check whether there are pending requests matching the entry to be added.
|
||||
//
|
||||
CacheEntry = ArpFindNextCacheEntryInTable (
|
||||
&ArpService->PendingRequestTable,
|
||||
NULL,
|
||||
ByProtoAddress,
|
||||
&MatchAddress[Protocol],
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
if (CacheEntry != NULL) {
|
||||
//
|
||||
// Remove it from the Table.
|
||||
//
|
||||
NetListRemoveEntry (&CacheEntry->List);
|
||||
} else {
|
||||
//
|
||||
// It's a new entry, allocate memory for the entry.
|
||||
//
|
||||
CacheEntry = ArpAllocCacheEntry (Instance);
|
||||
|
||||
if (CacheEntry == NULL) {
|
||||
ARP_DEBUG_ERROR (("ArpAdd: Failed to allocate pool for CacheEntry.\n"));
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Overwrite these parameters.
|
||||
//
|
||||
CacheEntry->DefaultDecayTime = TimeoutValue;
|
||||
CacheEntry->DecayTime = TimeoutValue;
|
||||
|
||||
//
|
||||
// Fill in the addresses.
|
||||
//
|
||||
ArpFillAddressInCacheEntry (
|
||||
CacheEntry,
|
||||
&MatchAddress[Hardware],
|
||||
&MatchAddress[Protocol]
|
||||
);
|
||||
|
||||
//
|
||||
// Inform the user if there is any.
|
||||
//
|
||||
ArpAddressResolved (CacheEntry, NULL, NULL);
|
||||
|
||||
//
|
||||
// Add this CacheEntry to the corresponding CacheTable.
|
||||
//
|
||||
if (DenyFlag) {
|
||||
NetListInsertHead (&ArpService->DeniedCacheTable, &CacheEntry->List);
|
||||
} else {
|
||||
NetListInsertHead (&ArpService->ResolvedCacheTable, &CacheEntry->List);
|
||||
}
|
||||
|
||||
UNLOCK_EXIT:
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function searches the ARP cache for matching entries and allocates a buffer into
|
||||
which those entries are copied.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param BySwAddress Set to TRUE to look for matching software protocol
|
||||
addresses. Set to FALSE to look for matching
|
||||
hardware protocol addresses.
|
||||
@param AddressBuffer Pointer to address buffer. Set to NULL to match
|
||||
all addresses.
|
||||
@param EntryLength The size of an entry in the entries buffer.
|
||||
@param EntryCount The number of ARP cache entries that are found by
|
||||
the specified criteria.
|
||||
@param Entries Pointer to the buffer that will receive the ARP
|
||||
cache entries.
|
||||
@param Refresh Set to TRUE to refresh the timeout value of the
|
||||
matching ARP cache entry.
|
||||
|
||||
@retval EFI_SUCCESS The requested ARP cache entries were copied into
|
||||
the buffer.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
||||
This is NULL. Both EntryCount and EntryLength are
|
||||
NULL, when Refresh is FALSE.
|
||||
@retval EFI_NOT_FOUND No matching entries were found.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpFind (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN VOID *AddressBuffer OPTIONAL,
|
||||
OUT UINT32 *EntryLength OPTIONAL,
|
||||
OUT UINT32 *EntryCount OPTIONAL,
|
||||
OUT EFI_ARP_FIND_DATA **Entries OPTIONAL,
|
||||
IN BOOLEAN Refresh
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
|
||||
if ((This == NULL) ||
|
||||
(!Refresh && (EntryCount == NULL) && (EntryLength == NULL)) ||
|
||||
((Entries != NULL) && ((EntryLength == NULL) || (EntryCount == NULL)))) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
ArpService = Instance->ArpService;
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// All the check passed, find the cache entries now.
|
||||
//
|
||||
Status = ArpFindCacheEntry (
|
||||
Instance,
|
||||
BySwAddress,
|
||||
AddressBuffer,
|
||||
EntryLength,
|
||||
EntryCount,
|
||||
Entries,
|
||||
Refresh
|
||||
);
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function removes specified ARP cache entries.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param BySwAddress Set to TRUE to delete matching protocol addresses.
|
||||
Set to FALSE to delete matching hardware
|
||||
addresses.
|
||||
@param AddressBuffer Pointer to the address buffer that is used as a
|
||||
key to look for the cache entry. Set to NULL to
|
||||
delete all entries.
|
||||
|
||||
@retval EFI_SUCCESS The entry was removed from the ARP cache.
|
||||
@retval EFI_INVALID_PARAMETER This is NULL.
|
||||
@retval EFI_NOT_FOUND The specified deletion key was not found.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpDelete (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN BOOLEAN BySwAddress,
|
||||
IN VOID *AddressBuffer OPTIONAL
|
||||
)
|
||||
{
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
UINTN Count;
|
||||
|
||||
if (This == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
ArpService = Instance->ArpService;
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the specified cache entries.
|
||||
//
|
||||
Count = ArpDeleteCacheEntry (Instance, BySwAddress, AddressBuffer, TRUE);
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function delete all dynamic entries from the ARP cache that match the specified
|
||||
software protocol type.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
|
||||
@retval EFI_SUCCESS The cache has been flushed.
|
||||
@retval EFI_INVALID_PARAMETER This is NULL.
|
||||
@retval EFI_NOT_FOUND There are no matching dynamic cache entries.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpFlush (
|
||||
IN EFI_ARP_PROTOCOL *This
|
||||
)
|
||||
{
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
UINTN Count;
|
||||
|
||||
if (This == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
ArpService = Instance->ArpService;
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the dynamic entries from the cache table.
|
||||
//
|
||||
Count = ArpDeleteCacheEntry (Instance, FALSE, NULL, FALSE);
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function tries to resolve the TargetSwAddress and optionally returns a
|
||||
TargetHwAddress if it already exists in the ARP cache.
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param TargetSwAddress Pointer to the protocol address to resolve.
|
||||
@param ResolvedEvent Pointer to the event that will be signaled when
|
||||
the address is resolved or some error occurs.
|
||||
@param TargetHwAddress Pointer to the buffer for the resolved hardware
|
||||
address in network byte order.
|
||||
|
||||
@retval EFI_SUCCESS The data is copied from the ARP cache into the
|
||||
TargetHwAddress buffer.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
||||
This is NULL. TargetHwAddress is NULL.
|
||||
@retval EFI_ACCESS_DENIED The requested address is not present in the normal
|
||||
ARP cache but is present in the deny address list.
|
||||
Outgoing traffic to that address is forbidden.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
@retval EFI_NOT_READY The request has been started and is not finished.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpRequest (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN EFI_EVENT ResolvedEvent OPTIONAL,
|
||||
OUT VOID *TargetHwAddress
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
EFI_SIMPLE_NETWORK_MODE *SnpMode;
|
||||
ARP_CACHE_ENTRY *CacheEntry;
|
||||
NET_ARP_ADDRESS HardwareAddress;
|
||||
NET_ARP_ADDRESS ProtocolAddress;
|
||||
USER_REQUEST_CONTEXT *RequestContext;
|
||||
|
||||
if ((This == NULL) || (TargetHwAddress == NULL)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
ArpService = Instance->ArpService;
|
||||
SnpMode = &ArpService->SnpMode;
|
||||
|
||||
if ((TargetSwAddress == NULL) ||
|
||||
((Instance->ConfigData.SwAddressType == IPv4_ETHER_PROTO_TYPE) &&
|
||||
IP4_IS_LOCAL_BROADCAST (*((UINT32 *)TargetSwAddress)))) {
|
||||
//
|
||||
// Return the hardware broadcast address.
|
||||
//
|
||||
NetCopyMem (TargetHwAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize);
|
||||
|
||||
goto SIGNAL_USER;
|
||||
}
|
||||
|
||||
if ((Instance->ConfigData.SwAddressType == IPv4_ETHER_PROTO_TYPE) &&
|
||||
IP4_IS_MULTICAST (NTOHL (*((UINT32 *)TargetSwAddress)))) {
|
||||
//
|
||||
// If the software address is an IPv4 multicast address, invoke Mnp to
|
||||
// resolve the address.
|
||||
//
|
||||
Status = ArpService->Mnp->McastIpToMac (
|
||||
ArpService->Mnp,
|
||||
FALSE,
|
||||
TargetSwAddress,
|
||||
TargetHwAddress
|
||||
);
|
||||
goto SIGNAL_USER;
|
||||
}
|
||||
|
||||
HardwareAddress.Type = SnpMode->IfType;
|
||||
HardwareAddress.Length = (UINT8)SnpMode->HwAddressSize;
|
||||
HardwareAddress.AddressPtr = NULL;
|
||||
|
||||
ProtocolAddress.Type = Instance->ConfigData.SwAddressType;
|
||||
ProtocolAddress.Length = Instance->ConfigData.SwAddressLength;
|
||||
ProtocolAddress.AddressPtr = TargetSwAddress;
|
||||
|
||||
//
|
||||
// Initialize the TargetHwAddrss to a zero address.
|
||||
//
|
||||
NetZeroMem (TargetHwAddress, SnpMode->HwAddressSize);
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// Check whether the software address is in the denied table.
|
||||
//
|
||||
CacheEntry = ArpFindDeniedCacheEntry (ArpService, &ProtocolAddress, NULL);
|
||||
if (CacheEntry != NULL) {
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Check whether the software address is already resolved.
|
||||
//
|
||||
CacheEntry = ArpFindNextCacheEntryInTable (
|
||||
&ArpService->ResolvedCacheTable,
|
||||
NULL,
|
||||
ByProtoAddress,
|
||||
&ProtocolAddress,
|
||||
NULL
|
||||
);
|
||||
if (CacheEntry != NULL) {
|
||||
//
|
||||
// Resolved, copy the address into the user buffer.
|
||||
//
|
||||
NetCopyMem (
|
||||
TargetHwAddress,
|
||||
CacheEntry->Addresses[Hardware].AddressPtr,
|
||||
CacheEntry->Addresses[Hardware].Length
|
||||
);
|
||||
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
if (ResolvedEvent == NULL) {
|
||||
Status = EFI_NOT_READY;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a request context for this arp request.
|
||||
//
|
||||
RequestContext = NetAllocatePool (sizeof(USER_REQUEST_CONTEXT));
|
||||
if (RequestContext == NULL) {
|
||||
ARP_DEBUG_ERROR (("ArpRequest: Allocate memory for RequestContext failed.\n"));
|
||||
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
RequestContext->Instance = Instance;
|
||||
RequestContext->UserRequestEvent = ResolvedEvent;
|
||||
RequestContext->UserHwAddrBuffer = TargetHwAddress;
|
||||
NetListInit (&RequestContext->List);
|
||||
|
||||
//
|
||||
// Check whether there is a same request.
|
||||
//
|
||||
CacheEntry = ArpFindNextCacheEntryInTable (
|
||||
&ArpService->PendingRequestTable,
|
||||
NULL,
|
||||
ByProtoAddress,
|
||||
&ProtocolAddress,
|
||||
NULL
|
||||
);
|
||||
if (CacheEntry != NULL) {
|
||||
|
||||
CacheEntry->NextRetryTime = Instance->ConfigData.RetryTimeOut;
|
||||
CacheEntry->RetryCount = Instance->ConfigData.RetryCount;
|
||||
} else {
|
||||
//
|
||||
// Allocate a cache entry for this request.
|
||||
//
|
||||
CacheEntry = ArpAllocCacheEntry (Instance);
|
||||
if (CacheEntry == NULL) {
|
||||
ARP_DEBUG_ERROR (("ArpRequest: Allocate memory for CacheEntry failed.\n"));
|
||||
NetFreePool (RequestContext);
|
||||
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto UNLOCK_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Fill the software address.
|
||||
//
|
||||
ArpFillAddressInCacheEntry (CacheEntry, &HardwareAddress, &ProtocolAddress);
|
||||
|
||||
//
|
||||
// Add this entry into the PendingRequestTable.
|
||||
//
|
||||
NetListInsertTail (&ArpService->PendingRequestTable, &CacheEntry->List);
|
||||
}
|
||||
|
||||
//
|
||||
// Link this request context into the cache entry.
|
||||
//
|
||||
NetListInsertHead (&CacheEntry->UserRequestList, &RequestContext->List);
|
||||
|
||||
//
|
||||
// Send out the ARP Request frame.
|
||||
//
|
||||
ArpSendFrame (Instance, CacheEntry, ARP_OPCODE_REQUEST);
|
||||
Status = EFI_NOT_READY;
|
||||
|
||||
UNLOCK_EXIT:
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
SIGNAL_USER:
|
||||
|
||||
if ((ResolvedEvent != NULL) && (Status == EFI_SUCCESS)) {
|
||||
gBS->SignalEvent (ResolvedEvent);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This function aborts the previous ARP request (identified by This, TargetSwAddress
|
||||
and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
|
||||
|
||||
@param This Pointer to the EFI_ARP_PROTOCOL instance.
|
||||
@param TargetSwAddress Pointer to the protocol address in previous
|
||||
request session.
|
||||
@param ResolvedEvent Pointer to the event that is used as the
|
||||
notification event in previous request session.
|
||||
|
||||
@retval EFI_SUCCESS The pending request session(s) is/are aborted and
|
||||
corresponding event(s) is/are signaled.
|
||||
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
||||
This is NULL. TargetSwAddress is not NULL and
|
||||
ResolvedEvent is NULL. TargetSwAddress is NULL and
|
||||
ResolvedEvent is not NULL.
|
||||
@retval EFI_NOT_STARTED The ARP driver instance has not been configured.
|
||||
@retval EFI_NOT_FOUND The request is not issued by
|
||||
EFI_ARP_PROTOCOL.Request().
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpCancel (
|
||||
IN EFI_ARP_PROTOCOL *This,
|
||||
IN VOID *TargetSwAddress OPTIONAL,
|
||||
IN EFI_EVENT ResolvedEvent OPTIONAL
|
||||
)
|
||||
{
|
||||
ARP_INSTANCE_DATA *Instance;
|
||||
ARP_SERVICE_DATA *ArpService;
|
||||
UINTN Count;
|
||||
|
||||
if ((This == NULL) ||
|
||||
((TargetSwAddress != NULL) && (ResolvedEvent == NULL)) ||
|
||||
((TargetSwAddress == NULL) && (ResolvedEvent != NULL))) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
|
||||
|
||||
if (!Instance->Configured) {
|
||||
return EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
ArpService = Instance->ArpService;
|
||||
|
||||
if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) {
|
||||
return EFI_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
//
|
||||
// Cancel the specified request.
|
||||
//
|
||||
Count = ArpCancelRequest (Instance, TargetSwAddress, ResolvedEvent);
|
||||
|
||||
NET_UNLOCK (&ArpService->Lock);
|
||||
|
||||
return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;
|
||||
}
|
156
MdeModulePkg/Universal/Network/ArpDxe/ComponentName.c
Normal file
156
MdeModulePkg/Universal/Network/ArpDxe/ComponentName.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2006 - 2007, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
Module Name:
|
||||
|
||||
ComponentName.c
|
||||
|
||||
Abstract:
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#include "ArpDriver.h"
|
||||
|
||||
//
|
||||
// EFI Component Name Functions
|
||||
//
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpComponentNameGetDriverName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **DriverName
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpComponentNameGetControllerName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
);
|
||||
|
||||
//
|
||||
// EFI Component Name Protocol
|
||||
//
|
||||
EFI_COMPONENT_NAME_PROTOCOL gArpComponentName = {
|
||||
ArpComponentNameGetDriverName,
|
||||
ArpComponentNameGetControllerName,
|
||||
"eng"
|
||||
};
|
||||
|
||||
STATIC EFI_UNICODE_STRING_TABLE mArpDriverNameTable[] = {
|
||||
{ "eng", L"ARP Network Service Driver" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpComponentNameGetDriverName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **DriverName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Retrieves a Unicode string that is the user readable name of the EFI Driver.
|
||||
|
||||
Arguments:
|
||||
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||
Language - A pointer to a three character ISO 639-2 language identifier.
|
||||
This is the language of the driver name that that the caller
|
||||
is requesting, and it must match one of the languages specified
|
||||
in SupportedLanguages. The number of languages supported by a
|
||||
driver is up to the driver writer.
|
||||
DriverName - A pointer to the Unicode string to return. This Unicode string
|
||||
is the name of the driver specified by This in the language
|
||||
specified by Language.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCES - The Unicode string for the Driver specified by This
|
||||
and the language specified by Language was returned
|
||||
in DriverName.
|
||||
EFI_INVALID_PARAMETER - Language is NULL.
|
||||
EFI_INVALID_PARAMETER - DriverName is NULL.
|
||||
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||
language specified by Language.
|
||||
|
||||
--*/
|
||||
{
|
||||
return LookupUnicodeString (
|
||||
Language,
|
||||
gArpComponentName.SupportedLanguages,
|
||||
mArpDriverNameTable,
|
||||
DriverName
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
ArpComponentNameGetControllerName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Retrieves a Unicode string that is the user readable name of the controller
|
||||
that is being managed by an EFI Driver.
|
||||
|
||||
Arguments:
|
||||
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||
ControllerHandle - The handle of a controller that the driver specified by
|
||||
This is managing. This handle specifies the controller
|
||||
whose name is to be returned.
|
||||
ChildHandle - The handle of the child controller to retrieve the name
|
||||
of. This is an optional parameter that may be NULL. It
|
||||
will be NULL for device drivers. It will also be NULL
|
||||
for a bus drivers that wish to retrieve the name of the
|
||||
bus controller. It will not be NULL for a bus driver
|
||||
that wishes to retrieve the name of a child controller.
|
||||
Language - A pointer to a three character ISO 639-2 language
|
||||
identifier. This is the language of the controller name
|
||||
that that the caller is requesting, and it must match one
|
||||
of the languages specified in SupportedLanguages. The
|
||||
number of languages supported by a driver is up to the
|
||||
driver writer.
|
||||
ControllerName - A pointer to the Unicode string to return. This Unicode
|
||||
string is the name of the controller specified by
|
||||
ControllerHandle and ChildHandle in the language specified
|
||||
by Language from the point of view of the driver specified
|
||||
by This.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - The Unicode string for the user readable name in the
|
||||
language specified by Language for the driver
|
||||
specified by This was returned in DriverName.
|
||||
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
|
||||
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
|
||||
EFI_INVALID_PARAMETER - Language is NULL.
|
||||
EFI_INVALID_PARAMETER - ControllerName is NULL.
|
||||
EFI_UNSUPPORTED - The driver specified by This is not currently managing
|
||||
the controller specified by ControllerHandle and
|
||||
ChildHandle.
|
||||
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||
language specified by Language.
|
||||
|
||||
--*/
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user