arpdriver.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 797 行 · 第 1/2 页
C
797 行
/*++
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,
0x10,
NULL,
NULL
};
STATIC
EFI_STATUS
ArpCreateService (
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle,
IN ARP_SERVICE_DATA *ArpService
)
/*++
Routine Description:
Create and initialize the arp service context data.
Arguments:
ImageHandle - The image handle representing the loaded driver image.
ControllerHandle - The controller handle the driver binds to.
ArpService - Pointer to the buffer containing the arp service context data.
Returns:
EFI_SUCCESS - The arp service context is initialized.
other - Failed to initialize the arp service context.
--*/
{
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 (
EFI_EVENT_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 (
EFI_EVENT_NOTIFY_SIGNAL | EFI_EVENT_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;
}
STATIC
VOID
ArpCleanService (
IN ARP_SERVICE_DATA *ArpService
)
/*++
Routine Description:
Clean the arp service context data.
Arguments:
ArpService - Pointer to the buffer containing the arp service context data.
Returns:
None.
--*/
{
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
);
}
}
EFI_STATUS
EFIAPI
ArpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
/*++
Routine Description:
Test to see if this driver supports ControllerHandle.
Arguments:
This - Protocol instance pointer.
ControllerHandle - Handle of device to test.
RemainingDevicePath - Optional parameter use to pick a specific child
device to start.
Returns:
EFI_SUCCES - This driver supports this device
EFI_ALREADY_STARTED - This driver is already running on this device.
other - This driver does not support this device.
--*/
{
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;
}
EFI_STATUS
EFIAPI
ArpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
/*++
Routine Description:
Start this driver on ControllerHandle.
Arguments:
This - Protocol instance pointer.
ControllerHandle - Handle of device to bind driver to
RemainingDevicePath - Optional parameter use to pick a specific child
device to start.
Returns:
EFI_SUCCES - This driver is added to ControllerHandle
EFI_ALREADY_STARTED - This driver is already running on ControllerHandle
other - This driver does not support this device
--*/
{
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.
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?