2007-07-30 04:37:10 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation
|
2007-07-30 04:37:10 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
**/
|
|
|
|
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,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_NOTIFY,
|
2007-07-30 04:37:10 +02:00
|
|
|
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,
|
2008-02-14 10:40:22 +01:00
|
|
|
TPL_CALLBACK,
|
2007-07-30 04:37:10 +02:00
|
|
|
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 lists.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
InitializeListHead (&ArpService->ChildrenList);
|
|
|
|
InitializeListHead (&ArpService->PendingRequestTable);
|
|
|
|
InitializeListHead (&ArpService->DeniedCacheTable);
|
|
|
|
InitializeListHead (&ArpService->ResolvedCacheTable);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
ERROR_EXIT:
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clean the arp service context data.
|
|
|
|
|
|
|
|
@param ArpService Pointer to the buffer containing the arp service
|
|
|
|
context data.
|
|
|
|
|
|
|
|
@return None.
|
|
|
|
|
|
|
|
**/
|
|
|
|
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.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
ArpService = AllocateZeroPool (sizeof(ARP_SERVICE_DATA));
|
2007-07-30 04:37:10 +02:00
|
|
|
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);
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (ArpService);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
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) {
|
2007-12-18 08:01:23 +01:00
|
|
|
return EFI_DEVICE_ERROR;
|
2007-07-30 04:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status));
|
2007-12-18 08:01:23 +01:00
|
|
|
return EFI_DEVICE_ERROR;
|
2007-07-30 04:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding);
|
|
|
|
|
2007-12-18 08:01:23 +01:00
|
|
|
if (NumberOfChildren == 0) {
|
2007-07-30 04:37:10 +02:00
|
|
|
//
|
2007-12-18 08:01:23 +01:00
|
|
|
// Uninstall the ARP ServiceBinding protocol.
|
2007-07-30 04:37:10 +02:00
|
|
|
//
|
2007-12-18 08:01:23 +01:00
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
NicHandle,
|
|
|
|
&gEfiArpServiceBindingProtocolGuid,
|
|
|
|
&ArpService->ServiceBinding,
|
|
|
|
NULL
|
|
|
|
);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
//
|
2007-12-18 08:01:23 +01:00
|
|
|
// Clean the arp servicebinding context data and free the memory allocated.
|
2007-07-30 04:37:10 +02:00
|
|
|
//
|
2007-12-18 08:01:23 +01:00
|
|
|
ArpCleanService (ArpService);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (ArpService);
|
2007-12-18 08:01:23 +01:00
|
|
|
} else {
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
while (!IsListEmpty (&ArpService->ChildrenList)) {
|
2007-12-18 08:01:23 +01:00
|
|
|
Instance = NET_LIST_HEAD (&ArpService->ChildrenList, ARP_INSTANCE_DATA, List);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2007-12-18 08:01:23 +01:00
|
|
|
ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
|
|
|
|
}
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
ASSERT (IsListEmpty (&ArpService->PendingRequestTable));
|
|
|
|
ASSERT (IsListEmpty (&ArpService->DeniedCacheTable));
|
|
|
|
ASSERT (IsListEmpty (&ArpService->ResolvedCacheTable));
|
2007-12-18 08:01:23 +01:00
|
|
|
}
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2007-12-18 08:01:23 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
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;
|
2007-11-20 06:42:23 +01:00
|
|
|
EFI_TPL OldTpl;
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
if ((This == NULL) || (ChildHandle == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate memory for the instance context data.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
Instance = AllocateZeroPool (sizeof(ARP_INSTANCE_DATA));
|
2007-07-30 04:37:10 +02:00
|
|
|
if (Instance == NULL) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: Failed to allocate memory for Instance.\n"));
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
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)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status));
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Instance);
|
2007-07-30 04:37:10 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Insert the instance into children list managed by the arp service context data.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
InsertTailList (&ArpService->ChildrenList, &Instance->List);
|
2007-07-30 04:37:10 +02:00
|
|
|
ArpService->ChildrenNumber++;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->RestoreTPL (OldTpl);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Instance);
|
2007-07-30 04:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-11-20 06:42:23 +01:00
|
|
|
EFI_TPL OldTpl;
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
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)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n",
|
2007-07-30 04:37:10 +02:00
|
|
|
Status));
|
|
|
|
|
|
|
|
Instance->Destroyed = FALSE;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
RemoveEntryList (&Instance->List);
|
2007-07-30 04:37:10 +02:00
|
|
|
ArpService->ChildrenNumber--;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->RestoreTPL (OldTpl);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
gBS->FreePool (Instance);
|
2007-07-30 04:37:10 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
The entry point for Arp driver which installs the driver binding and component name
|
|
|
|
protocol on its ImageHandle.
|
|
|
|
|
|
|
|
@param ImageHandle The image handle of the driver.
|
|
|
|
@param SystemTable The system table.
|
2007-07-30 04:37:10 +02:00
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
@retval EFI_SUCCES if the driver binding and component name protocols are successfully
|
|
|
|
@retval Others Failed to install the protocols.
|
|
|
|
|
|
|
|
**/
|
2007-07-30 04:37:10 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ArpDriverEntryPoint (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
2007-09-30 05:08:02 +02:00
|
|
|
return EfiLibInstallDriverBindingComponentName2 (
|
2007-07-30 04:37:10 +02:00
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gArpDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gArpComponentName,
|
2007-09-30 05:08:02 +02:00
|
|
|
&gArpComponentName2
|
2007-07-30 04:37:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|