NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg

Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
This commit is contained in:
Liming Gao
2019-05-15 20:02:18 +08:00
parent c0fd7f734e
commit 4542f8b813
147 changed files with 24 additions and 24 deletions

View File

@@ -1,94 +0,0 @@
/** @file
Help functions to access UDP service.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/Dpc.h>
//
// Pointer to the DPC Protocol
//
EFI_DPC_PROTOCOL *mDpc;
/**
This constructor function caches the EFI_DPC_PROTOCOL pointer.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor always return EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
DpcLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Locate the EFI_DPC_PROTOCOL in the handle database
//
Status = gBS->LocateProtocol (&gEfiDpcProtocolGuid, NULL, (VOID **)&mDpc);
ASSERT_EFI_ERROR (Status);
return Status;
}
/**
Add a Deferred Procedure Call to the end of the DPC queue.
@param[in] DpcTpl The EFI_TPL that the DPC should be invoked.
@param[in] DpcProcedure Pointer to the DPC's function.
@param[in] DpcContext Pointer to the DPC's context. Passed to DpcProcedure
when DpcProcedure is invoked.
@retval EFI_SUCCESS The DPC was queued.
@retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL.
@retval EFI_INVALID_PARAMETER DpcProcedure is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
add the DPC to the queue.
**/
EFI_STATUS
EFIAPI
QueueDpc (
IN EFI_TPL DpcTpl,
IN EFI_DPC_PROCEDURE DpcProcedure,
IN VOID *DpcContext OPTIONAL
)
{
//
// Call the EFI_DPC_PROTOCOL to queue the DPC
//
return mDpc->QueueDpc (mDpc, DpcTpl, DpcProcedure, DpcContext);
}
/**
Dispatch the queue of DPCs. ALL DPCs that have been queued with a DpcTpl
value greater than or equal to the current TPL are invoked in the order that
they were queued. DPCs with higher DpcTpl values are invoked before DPCs with
lower DpcTpl values.
@retval EFI_SUCCESS One or more DPCs were invoked.
@retval EFI_NOT_FOUND No DPCs were invoked.
**/
EFI_STATUS
EFIAPI
DispatchDpc (
VOID
)
{
//
// Call the EFI_DPC_PROTOCOL to dispatch previously queued DPCs
//
return mDpc->DispatchDpc (mDpc);
}

View File

@@ -1,40 +0,0 @@
## @file
# This library instance provides DPC service by consuming EFI DPC Protocol.
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeDpcLib
MODULE_UNI_FILE = DxeDpcLib.uni
FILE_GUID = 38897D86-FF36-4472-AE64-1DB9AE715C81
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = DpcLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = DpcLibConstructor
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DpcLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
DebugLib
UefiBootServicesTableLib
[Protocols]
gEfiDpcProtocolGuid ## CONSUMES
[Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SAL_DRIVER, Depex.common.DXE_SMM_DRIVER]
gEfiDpcProtocolGuid

View File

@@ -1,16 +0,0 @@
// /** @file
// This library instance provides DPC service by consuming EFI DPC Protocol.
//
// This library instance provides the DPC service by consuming EFI DPC Protocol.
//
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Provides the DPC service by consuming EFI DPC Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides the DPC service by consuming EFI DPC Protocol."

File diff suppressed because it is too large Load Diff

View File

@@ -1,85 +0,0 @@
/** @file
Header file for HttpLib.
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _DXE_HTTP_LIB_H_
#define _DXE_HTTP_LIB_H_
#include <Uefi.h>
#include <Library/NetLib.h>
#include <Library/HttpLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <IndustryStandard/Http11.h>
#include <Protocol/HttpUtilities.h>
#define BIT(x) (1 << x)
#define HTTP_VERSION_CRLF_STR " HTTP/1.1\r\n"
#define EMPTY_SPACE " "
#define NET_IS_HEX_CHAR(Ch) \
((('0' <= (Ch)) && ((Ch) <= '9')) || \
(('A' <= (Ch)) && ((Ch) <= 'F')) || \
(('a' <= (Ch)) && ((Ch) <= 'f')))
//
// Field index of the HTTP URL parse result.
//
#define HTTP_URI_FIELD_SCHEME 0
#define HTTP_URI_FIELD_AUTHORITY 1
#define HTTP_URI_FIELD_PATH 2
#define HTTP_URI_FIELD_QUERY 3
#define HTTP_URI_FIELD_FRAGMENT 4
#define HTTP_URI_FIELD_USERINFO 5
#define HTTP_URI_FIELD_HOST 6
#define HTTP_URI_FIELD_PORT 7
#define HTTP_URI_FIELD_MAX 8
#define HTTP_URI_PORT_MAX_NUM 65535
//
// Structure to store the parse result of a HTTP URL.
//
typedef struct {
UINT32 Offset;
UINT32 Length;
} HTTP_URL_FILED_DATA;
typedef struct {
UINT16 FieldBitMap;
HTTP_URL_FILED_DATA FieldData[HTTP_URI_FIELD_MAX];
} HTTP_URL_PARSER;
typedef enum {
UrlParserUrlStart,
UrlParserScheme,
UrlParserSchemeColon, // ":"
UrlParserSchemeColonSlash, // ":/"
UrlParserSchemeColonSlashSlash, // "://"
UrlParserAuthority,
UrlParserAtInAuthority,
UrlParserPath,
UrlParserQueryStart, // "?"
UrlParserQuery,
UrlParserFragmentStart, // "#"
UrlParserFragment,
UrlParserUserInfo,
UrlParserHostStart, // "@"
UrlParserHost,
UrlParserHostIpv6, // "["(Ipv6 address) "]"
UrlParserPortStart, // ":"
UrlParserPort,
UrlParserStateMax
} HTTP_URL_PARSE_STATE;
#endif

View File

@@ -1,42 +0,0 @@
## @file
# It provides the helper routines to parse the HTTP message byte stream.
#
# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeHttpLib
MODULE_UNI_FILE = DxeHttpLib.uni
FILE_GUID = ABBAB4CD-EA88-45b9-8234-C8A7450531FC
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = HttpLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DxeHttpLib.c
DxeHttpLib.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
UefiBootServicesTableLib
MemoryAllocationLib
NetLib
[Protocols]
gEfiHttpUtilitiesProtocolGuid ## SOMETIMES_CONSUMES

View File

@@ -1,16 +0,0 @@
// /** @file
// Provides the helper routines for HTTP.
//
// This library instance provides the helper routines to parse the HTTP message byte stream.
//
// Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Provides the helper routines for HTTP"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides the helper routines to parse the HTTP message byte stream."

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +0,0 @@
## @file
# This library instance provides IP services upon EFI IPv4/IPv6 Protocols.
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeIpIoLib
MODULE_UNI_FILE = DxeIpIoLib.uni
FILE_GUID = A302F877-8625-425c-B1EC-7487B62C4FDA
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = IpIoLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DxeIpIoLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
DpcLib
[Protocols]
gEfiIp4ProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES

View File

@@ -1,16 +0,0 @@
// /** @file
// This library instance provides IP services upon EFI IPv4/IPv6 Protocols.
//
// This library instance provides IP services upon EFI IPv4/IPv6 Protocols.
//
// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "EFI IPv4/IPv6 IP Services Library"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides IP services upon EFI IPv4/IPv6 Protocols."

File diff suppressed because it is too large Load Diff

View File

@@ -1,61 +0,0 @@
## @file
# This library instance provides the basic network services.
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeNetLib
MODULE_UNI_FILE = DxeNetLib.uni
FILE_GUID = db6dcef3-9f4e-4340-9351-fc35aa8a5888
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NetLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DxeNetLib.c
NetBuffer.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
BaseMemoryLib
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
UefiLib
MemoryAllocationLib
DevicePathLib
PrintLib
[Guids]
gEfiSmbiosTableGuid ## SOMETIMES_CONSUMES ## SystemTable
gEfiSmbios3TableGuid ## SOMETIMES_CONSUMES ## SystemTable
gEfiAdapterInfoMediaStateGuid ## SOMETIMES_CONSUMES
[Protocols]
gEfiSimpleNetworkProtocolGuid ## SOMETIMES_CONSUMES
gEfiManagedNetworkProtocolGuid ## SOMETIMES_CONSUMES
gEfiManagedNetworkServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiIp4Config2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiComponentNameProtocolGuid ## SOMETIMES_CONSUMES
gEfiComponentName2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES

View File

@@ -1,16 +0,0 @@
// /** @file
// This library instance provides the basic network services.
//
// This library instance provides the basic network services.
//
// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Provides the basic network services"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides the basic network services."

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,44 +0,0 @@
## @file
# This library instance provides TCP services by EFI TCPv4/TCPv6 Protocols.
#
# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeTcpIoLib
MODULE_UNI_FILE = DxeTcpIoLib.uni
FILE_GUID = D4608509-1AB0-4cc7-827A-AB8E1E7BD3E6
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TcpIoLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DxeTcpIoLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
[Protocols]
gEfiTcp4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiTcp4ProtocolGuid ## SOMETIMES_CONSUMES
gEfiTcp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiTcp6ProtocolGuid ## SOMETIMES_CONSUMES

View File

@@ -1,16 +0,0 @@
// /** @file
// This library instance provides TCP services by EFI TCPv4/TCPv6 Protocols.
//
// This library instance provides TCP services by EFI TCPv4/TCPv6 Protocols.
//
// Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Provides TCP services by EFI TCPv4/TCPv6 Protocols"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides TCP services by EFI TCPv4/TCPv6 Protocols."

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +0,0 @@
## @file
# This library instance provides UDP services by consuming EFI UDPv4/UDPv6 Protocols.
#
# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeUpdIoLib
MODULE_UNI_FILE = DxeUpdIoLib.uni
FILE_GUID = 7E615AA1-41EE-49d4-B7E9-1D7A60AA5C8D
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = UdpIoLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
DxeUdpIoLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
DebugLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
DpcLib
[Protocols]
gEfiUdp4ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiUdp4ProtocolGuid ## SOMETIMES_CONSUMES
gEfiUdp6ServiceBindingProtocolGuid ## SOMETIMES_CONSUMES
gEfiUdp6ProtocolGuid ## SOMETIMES_CONSUMES

View File

@@ -1,16 +0,0 @@
// /** @file
// This library instance provides UDP services by consuming EFI UDPv4/UDPv6 Protocols.
//
// This library instance provides UDP services by consuming EFI UDPv4/UDPv6 Protocols.
//
// Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Provides UDP services by consuming EFI UDPv4/UDPv6 Protocols"
#string STR_MODULE_DESCRIPTION #language en-US "This library instance provides UDP services by consuming EFI UDPv4/UDPv6 Protocols."

View File

@@ -1,811 +0,0 @@
/** @file
ARP driver functions.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#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[in] ImageHandle The image handle representing the loaded driver
image.
@param[in] ControllerHandle The controller handle the driver binds to.
@param[in, out] ArpService Pointer to the buffer containing the arp service
context data.
@retval EFI_SUCCESS The arp service context is initialized.
@retval EFI_UNSUPPORTED The underlayer Snp mode type is not ethernet.
Failed to initialize the service context.
@retval other Failed to initialize the arp service context.
**/
EFI_STATUS
ArpCreateService (
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle,
IN OUT ARP_SERVICE_DATA *ArpService
)
{
EFI_STATUS Status;
ASSERT (ArpService != NULL);
ArpService->Signature = ARP_SERVICE_DATA_SIGNATURE;
//
// Init the lists.
//
InitializeListHead (&ArpService->ChildrenList);
InitializeListHead (&ArpService->PendingRequestTable);
InitializeListHead (&ArpService->DeniedCacheTable);
InitializeListHead (&ArpService->ResolvedCacheTable);
//
// 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,
TPL_NOTIFY,
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,
TPL_CALLBACK,
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
);
ERROR_EXIT:
return Status;
}
/**
Clean the arp service context data.
@param[in, out] ArpService Pointer to the buffer containing the arp service
context data.
@return None.
**/
VOID
ArpCleanService (
IN OUT 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
);
}
}
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@param[in] Entry The entry to be removed.
@param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
@retval EFI_SUCCESS The entry has been removed successfully.
@retval Others Fail to remove the entry.
**/
EFI_STATUS
EFIAPI
ArpDestroyChildEntryInHandleBuffer (
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
ARP_INSTANCE_DATA *Instance;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
if (Entry == NULL || Context == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = NET_LIST_USER_STRUCT_S (Entry, ARP_INSTANCE_DATA, List, ARP_INSTANCE_DATA_SIGNATURE);
ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
}
/**
Tests to see if this driver supports a given controller.
If a child device is provided, it further tests to see if this driver supports
creating a handle for the specified child device.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
This parameter is ignored by device drivers,
and is optional for bus drivers.
@retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver
specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed
by the driver specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by
a different driver or an application that
requires exclusive acces. Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the
driver specified by This.
**/
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.
The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been
moved into this common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed or the system behavior
will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally
aligned EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified
by This must have been called with the same calling parameters, and Supported()
must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
This parameter is ignored by device drivers,
and is optional for bus drivers.
@retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.
Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
resources.
@retval Others The driver failded to start the 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 = AllocateZeroPool (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);
FreePool (ArpService);
return Status;
}
/**
Stop this driver on ControllerHandle.
Release the control of this controller and remove the IScsi functions. The Stop()
function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed or the system behavior
will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
Not used.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.Not used.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
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;
LIST_ENTRY *List;
//
// 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)) {
DEBUG ((EFI_D_ERROR, "ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status));
return EFI_DEVICE_ERROR;
}
ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding);
if (NumberOfChildren != 0) {
//
// NumberOfChildren is not zero, destroy all the ARP children instances.
//
List = &ArpService->ChildrenList;
Status = NetDestroyLinkList (
List,
ArpDestroyChildEntryInHandleBuffer,
ServiceBinding,
NULL
);
ASSERT (IsListEmpty (&ArpService->PendingRequestTable));
ASSERT (IsListEmpty (&ArpService->DeniedCacheTable));
ASSERT (IsListEmpty (&ArpService->ResolvedCacheTable));
} else if (IsListEmpty (&ArpService->ChildrenList)) {
//
// Uninstall the ARP ServiceBinding protocol.
//
gBS->UninstallMultipleProtocolInterfaces (
NicHandle,
&gEfiArpServiceBindingProtocolGuid,
&ArpService->ServiceBinding,
NULL
);
//
// Clean the arp servicebinding context data and free the memory allocated.
//
ArpCleanService (ArpService);
FreePool (ArpService);
}
return EFI_SUCCESS;
}
/**
Creates a child handle and installs a protocol.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned
in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol
installs on the existing ChildHandle.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Pointer to the handle of the child to create. If it is NULL,
then a new handle is created. If it is a pointer to an existing
UEFI handle, then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available 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;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
//
// Allocate memory for the instance context data.
//
Instance = AllocateZeroPool (sizeof(ARP_INSTANCE_DATA));
if (Instance == NULL) {
DEBUG ((EFI_D_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)) {
DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status));
FreePool (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;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Insert the instance into children list managed by the arp service context data.
//
InsertTailList (&ArpService->ChildrenList, &Instance->List);
ArpService->ChildrenNumber++;
gBS->RestoreTPL (OldTpl);
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.
//
FreePool (Instance);
}
return Status;
}
/**
Destroys a child handle with a protocol installed on it.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is
being removed.
@retval EFI_INVALID_PARAMETER Child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its 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;
EFI_TPL OldTpl;
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->InDestroy) {
return EFI_SUCCESS;
}
//
// Use the InDestroy as a flag to avoid re-entrance.
//
Instance->InDestroy = 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)) {
DEBUG ((EFI_D_ERROR, "ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n",
Status));
Instance->InDestroy = FALSE;
return Status;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
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.
//
RemoveEntryList (&Instance->List);
ArpService->ChildrenNumber--;
gBS->RestoreTPL (OldTpl);
FreePool (Instance);
return Status;
}
/**
The entry point for Arp driver which installs the driver binding and component name
protocol on its ImageHandle.
@param[in] ImageHandle The image handle of the driver.
@param[in] SystemTable The system table.
@retval EFI_SUCCESS if the driver binding and component name protocols
are successfully
@retval Others Failed to install the protocols.
**/
EFI_STATUS
EFIAPI
ArpDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gArpDriverBinding,
ImageHandle,
&gArpComponentName,
&gArpComponentName2
);
}

View File

@@ -1,334 +0,0 @@
/** @file
ARP driver header file.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _ARP_DRIVER_H_
#define _ARP_DRIVER_H_
#include <Uefi.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>
//
// Global variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gArpComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gArpComponentName2;
//
// Function prototypes for the Drivr Binding Protocol
//
/**
Tests to see if this driver supports a given controller.
If a child device is provided, it further tests to see if this driver supports
creating a handle for the specified child device.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to test. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
This parameter is ignored by device drivers,
and is optional for bus drivers.
@retval EFI_SUCCESS The device specified by ControllerHandle and
RemainingDevicePath is supported by the driver
specified by This.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed
by the driver specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by
a different driver or an application that
requires exclusive acces. Currently not implemented.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the
driver specified by This.
**/
EFI_STATUS
EFIAPI
ArpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle.
The Start() function is designed to be invoked from the EFI boot service ConnectController().
As a result, much of the error checking on the parameters to Start() has been
moved into this common boot service. It is legal to call Start() from other locations,
but the following calling restrictions must be followed or the system behavior
will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE.
2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally
aligned EFI_DEVICE_PATH_PROTOCOL.
3. Prior to calling Start(), the Supported() function for the driver specified
by This must have been called with the same calling parameters, and Supported()
must have returned EFI_SUCCESS.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle The handle of the controller to start. This handle
must support a protocol interface that supplies
an I/O abstraction to the driver.
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
This parameter is ignored by device drivers,
and is optional for bus drivers.
@retval EFI_SUCCESS The device was started.
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.
Currently not implemented.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
resources.
@retval Others The driver failded to start the device.
**/
EFI_STATUS
EFIAPI
ArpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle.
Release the control of this controller and remove the IScsi functions. The Stop()
function is designed to be invoked from the EFI boot service DisconnectController().
As a result, much of the error checking on the parameters to Stop() has been moved
into this common boot service. It is legal to call Stop() from other locations,
but the following calling restrictions must be followed or the system behavior
will not be deterministic.
1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
same driver's Start() function.
2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
EFI_HANDLE. In addition, all of these handles must have been created in this driver's
Start() function, and the Start() function must have called OpenProtocol() on
ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
@param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param[in] ControllerHandle A handle to the device being stopped. The handle must
support a bus specific I/O protocol for the driver
to use to stop the device.
@param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
Not used.
@param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
if NumberOfChildren is 0.Not used.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
ArpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
Creates a child handle and installs a protocol.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned
in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol
installs on the existing ChildHandle.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Pointer to the handle of the child to create. If it is NULL,
then a new handle is created. If it is a pointer to an existing
UEFI handle, then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available 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
);
/**
Destroys a child handle with a protocol installed on it.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is
being removed.
@retval EFI_INVALID_PARAMETER Child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its 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 Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
ArpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
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
);
#endif

View File

@@ -1,62 +0,0 @@
## @file
# This module produces EFI ARP Protocol and EFI ARP Service Binding Protocol.
#
# This module produces EFI ARP Protocol upon EFI MNP Protocol, to provide a generic
# implementation of the Address Resolution Protocol that is described in RFCs 826
# and 1122.
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = ArpDxe
MODULE_UNI_FILE = ArpDxe.uni
FILE_GUID = 529D3F93-E8E9-4e73-B1E1-BDF6A9D50113
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = ArpDriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
# DRIVER_BINDING = gArpDriverBinding
# COMPONENT_NAME = gArpComponentName
# COMPONENT_NAME2 = gArpComponentName2
#
[Sources]
ArpMain.c
ArpDriver.h
ComponentName.c
ArpImpl.h
ArpImpl.c
ArpDriver.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
DebugLib
NetLib
DpcLib
[Protocols]
gEfiArpServiceBindingProtocolGuid ## BY_START
gEfiManagedNetworkServiceBindingProtocolGuid ## TO_START
gEfiArpProtocolGuid ## BY_START
gEfiManagedNetworkProtocolGuid ## TO_START
[UserExtensions.TianoCore."ExtraFiles"]
ArpDxeExtra.uni

View File

@@ -1,18 +0,0 @@
// /** @file
// This module produces EFI ARP Protocol and EFI ARP Service Binding Protocol.
//
// This module produces EFI ARP Protocol upon EFI MNP Protocol, to provide a generic
// implementation of the Address Resolution Protocol that is described in RFCs 826
// and 1122.
//
// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "EFI Address Resolution Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI ARP Protocol using the EFI MNP Protocol to provide a generic implementation of the Address Resolution Protocol that is described in RFCs 826 and 1122."

View File

@@ -1,14 +0,0 @@
// /** @file
// ArpDxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"ARP DXE Driver"

File diff suppressed because it is too large Load Diff

View File

@@ -1,770 +0,0 @@
/** @file
EFI Address Resolution Protocol (ARP) Protocol interface header file.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _ARP_IMPL_H_
#define _ARP_IMPL_H_
#include <Uefi.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 <Library/DpcLib.h>
//
// Ethernet protocol type definitions.
//
#define ARP_ETHER_PROTO_TYPE 0x0806
#define IPV4_ETHER_PROTO_TYPE 0x0800
#define IPV6_ETHER_PROTO_TYPE 0x86DD
//
// ARP opcode definitions.
//
#define ARP_OPCODE_REQUEST 0x0001
#define ARP_OPCODE_REPLY 0x0002
//
// ARP timeout, retry count and interval definitions.
//
#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)
//
// ARP packet head definition.
//
#pragma pack(1)
typedef struct {
UINT16 HwType;
UINT16 ProtoType;
UINT8 HwAddrLen;
UINT8 ProtoAddrLen;
UINT16 OpCode;
} ARP_HEAD;
#pragma pack()
//
// ARP Address definition for internal use.
//
typedef struct {
UINT8 *SenderHwAddr;
UINT8 *SenderProtoAddr;
UINT8 *TargetHwAddr;
UINT8 *TargetProtoAddr;
} ARP_ADDRESS;
#define MATCH_SW_ADDRESS 0x1
#define MATCH_HW_ADDRESS 0x2
//
// Enumeration for the search type. A search type is specified as the keyword to find
// a cache entry in the cache table.
//
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 SIGNATURE_32('A', 'R', 'P', 'I')
/**
Returns a pointer to the ARP_INSTANCE_DATA structure from the input a.
If the signatures matches, then a pointer to the data structure that contains
a specified field of that data structure is returned.
@param a Pointer to the field specified by ArpProto within a data
structure of type ARP_INSTANCE_DATA.
**/
#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;
//
// ARP instance context data structure.
//
typedef struct {
UINT32 Signature;
ARP_SERVICE_DATA *ArpService;
EFI_HANDLE Handle;
EFI_ARP_PROTOCOL ArpProto;
LIST_ENTRY List;
EFI_ARP_CONFIG_DATA ConfigData;
BOOLEAN Configured;
BOOLEAN InDestroy;
} ARP_INSTANCE_DATA;
#define ARP_SERVICE_DATA_SIGNATURE SIGNATURE_32('A', 'R', 'P', 'S')
/**
Returns a pointer to the ARP_SERVICE_DATA structure from the input a.
If the signatures matches, then a pointer to the data structure that contains
a specified field of that data structure is returned.
@param a Pointer to the field specified by ServiceBinding within
a data structure of type ARP_SERVICE_DATA.
**/
#define ARP_SERVICE_DATA_FROM_THIS(a) \
CR ( \
(a), \
ARP_SERVICE_DATA, \
ServiceBinding, \
ARP_SERVICE_DATA_SIGNATURE \
)
//
// ARP service data structure.
//
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;
UINTN ChildrenNumber;
LIST_ENTRY ChildrenList;
LIST_ENTRY PendingRequestTable;
LIST_ENTRY DeniedCacheTable;
LIST_ENTRY ResolvedCacheTable;
EFI_EVENT PeriodicTimer;
};
//
// User request context structure.
//
typedef struct {
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 union {
UINT8 ProtoAddress[ARP_MAX_PROTOCOL_ADDRESS_LEN];
UINT8 HwAddress[ARP_MAX_HARDWARE_ADDRESS_LEN];
} NET_ARP_ADDRESS_UNION;
//
// ARP address structure in an ARP packet.
//
typedef struct {
UINT16 Type;
UINT8 Length;
UINT8 *AddressPtr;
NET_ARP_ADDRESS_UNION Buffer;
} NET_ARP_ADDRESS;
//
// Enumeration for ARP address type.
//
typedef enum {
Hardware,
Protocol
} ARP_ADDRESS_TYPE;
//
// ARP cache entry definition.
//
typedef struct {
LIST_ENTRY List;
UINT32 RetryCount;
UINT32 DefaultDecayTime;
UINT32 DecayTime;
UINT32 NextRetryTime;
NET_ARP_ADDRESS Addresses[2];
LIST_ENTRY UserRequestList;
} ARP_CACHE_ENTRY;
/**
This function is used to assign a station address to the ARP cache for this instance
of the ARP driver.
Each ARP instance has one station address. The EFI_ARP_PROTOCOL driver will
respond to ARP requests that match this registered station address. A call to
this function with the ConfigData field set to NULL will reset this ARP instance.
Once a protocol type and station address have been assigned to this ARP instance,
all the following ARP functions will use this information. Attempting to change
the protocol type or station address to a configured ARP instance will result in errors.
@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
);
/**
This function is used to insert entries into the ARP cache.
ARP cache entries are typically inserted and updated by network protocol drivers
as network traffic is processed. Most ARP cache entries will time out and be
deleted if the network traffic stops. ARP cache entries that were inserted
by the Add() function may be static (will not time out) or dynamic (will time out).
Default ARP cache timeout values are not covered in most network protocol
specifications (although RFC 1122 comes pretty close) and will only be
discussed in general in this specification. The timeout values that are
used in the EFI Sample Implementation should be used only as a guideline.
Final product implementations of the EFI network stack should be tuned for
their expected network environments.
@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
);
/**
This function searches the ARP cache for matching entries and allocates a buffer into
which those entries are copied.
The first part of the allocated buffer is EFI_ARP_FIND_DATA, following which
are protocol address pairs and hardware address pairs.
When finding a specific protocol address (BySwAddress is TRUE and AddressBuffer
is not NULL), the ARP cache timeout for the found entry is reset if Refresh is
set to TRUE. If the found ARP cache entry is a permanent entry, it is not
affected by Refresh.
@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
);
/**
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
);
/**
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
);
/**
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
);
/**
This function aborts the previous ARP request (identified by This, TargetSwAddress
and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
If the request is in the internal ARP request queue, the request is aborted
immediately and its ResolvedEvent is signaled. Only an asynchronous address
request needs to be canceled. If TargeSwAddress and ResolveEvent are both
NULL, all the pending asynchronous requests that have been issued by This
instance will be cancelled and their corresponding events will be signaled.
@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
);
/**
Configure the instance using the ConfigData. ConfigData is already validated.
@param[in] Instance Pointer to the instance context data to be
configured.
@param[in] ConfigData Pointer to the configuration data used to
configure the instance.
@retval EFI_SUCCESS The instance is configured with the ConfigData.
@retval EFI_ACCESS_DENIED The instance is already configured and the
ConfigData tries to reset some unchangeable
fields.
@retval EFI_INVALID_PARAMETER The ConfigData provides a non-unicast IPv4 address
when the SwAddressType is IPv4.
@retval EFI_OUT_OF_RESOURCES The instance fails to configure due to memory
limitation.
**/
EFI_STATUS
ArpConfigureInstance (
IN ARP_INSTANCE_DATA *Instance,
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
);
/**
Find the CacheEntry, using ProtocolAddress or HardwareAddress or both, as the keyword,
in the DeniedCacheTable.
@param[in] ArpService Pointer to the arp service context data.
@param[in] ProtocolAddress Pointer to the protocol address.
@param[in] HardwareAddress Pointer to the hardware address.
@return Pointer to the matched cache entry, if NULL no match is found.
**/
ARP_CACHE_ENTRY *
ArpFindDeniedCacheEntry (
IN ARP_SERVICE_DATA *ArpService,
IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,
IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL
);
/**
Find the CacheEntry which matches the requirements in the specified CacheTable.
@param[in] CacheTable Pointer to the arp cache table.
@param[in] StartEntry Pointer to the start entry this search begins with
in the cache table.
@param[in] FindOpType The search type.
@param[in] ProtocolAddress Pointer to the protocol address to match.
@param[in] HardwareAddress Pointer to the hardware address to match.
@return Pointer to the matched arp cache entry, if NULL, no match is found.
**/
ARP_CACHE_ENTRY *
ArpFindNextCacheEntryInTable (
IN LIST_ENTRY *CacheTable,
IN LIST_ENTRY *StartEntry,
IN FIND_OPTYPE FindOpType,
IN NET_ARP_ADDRESS *ProtocolAddress OPTIONAL,
IN NET_ARP_ADDRESS *HardwareAddress OPTIONAL
);
/**
Allocate a cache entry and initialize it.
@param[in] Instance Pointer to the instance context data.
@return Pointer to the new created cache entry.
**/
ARP_CACHE_ENTRY *
ArpAllocCacheEntry (
IN ARP_INSTANCE_DATA *Instance
);
/**
Fill the addresses in the CacheEntry using the information passed in by
HwAddr and SwAddr.
@param[in] CacheEntry Pointer to the cache entry.
@param[in] HwAddr Pointer to the software address.
@param[in] SwAddr Pointer to the hardware address.
@return None.
**/
VOID
ArpFillAddressInCacheEntry (
IN ARP_CACHE_ENTRY *CacheEntry,
IN NET_ARP_ADDRESS *HwAddr OPTIONAL,
IN NET_ARP_ADDRESS *SwAddr OPTIONAL
);
/**
Turn the CacheEntry into the resolved status.
@param[in] CacheEntry Pointer to the resolved cache entry.
@param[in] Instance Pointer to the instance context data.
@param[in] UserEvent Pointer to the UserEvent to notify.
@return The count of notifications sent to the instance.
**/
UINTN
ArpAddressResolved (
IN ARP_CACHE_ENTRY *CacheEntry,
IN ARP_INSTANCE_DATA *Instance OPTIONAL,
IN EFI_EVENT UserEvent OPTIONAL
);
/**
Delete cache entries in all the cache tables.
@param[in] Instance Pointer to the instance context data.
@param[in] BySwAddress Delete the cache entry by software address or by
hardware address.
@param[in] AddressBuffer Pointer to the buffer containing the address to
match for the deletion.
@param[in] Force This deletion is forced or not.
@return The count of the deleted cache entries.
**/
UINTN
ArpDeleteCacheEntry (
IN ARP_INSTANCE_DATA *Instance,
IN BOOLEAN BySwAddress,
IN UINT8 *AddressBuffer OPTIONAL,
IN BOOLEAN Force
);
/**
Send out an arp frame using the CachEntry and the ArpOpCode.
@param[in] Instance Pointer to the instance context data.
@param[in] CacheEntry Pointer to the configuration data used to
configure the instance.
@param[in] ArpOpCode The opcode used to send out this Arp frame, either
request or reply.
@return None.
**/
VOID
ArpSendFrame (
IN ARP_INSTANCE_DATA *Instance,
IN ARP_CACHE_ENTRY *CacheEntry,
IN UINT16 ArpOpCode
);
/**
Initialize the instance context data.
@param[in] ArpService Pointer to the arp service context data this
instance belongs to.
@param[out] Instance Pointer to the instance context data.
@return None.
**/
VOID
ArpInitInstance (
IN ARP_SERVICE_DATA *ArpService,
OUT ARP_INSTANCE_DATA *Instance
);
/**
Process the Arp packets received from Mnp, the procedure conforms to RFC826.
@param[in] Context Pointer to the context data registerd to the
Event.
@return None.
**/
VOID
EFIAPI
ArpOnFrameRcvdDpc (
IN VOID *Context
);
/**
Queue ArpOnFrameRcvdDpc as a DPC at TPL_CALLBACK.
@param[in] Event The Event this notify function registered to.
@param[in] Context Pointer to the context data registerd to the
Event.
@return None.
**/
VOID
EFIAPI
ArpOnFrameRcvd (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Process the already sent arp packets.
@param[in] Context Pointer to the context data registerd to the
Event.
@return None.
**/
VOID
EFIAPI
ArpOnFrameSentDpc (
IN VOID *Context
);
/**
Request ArpOnFrameSentDpc as a DPC at TPL_CALLBACK.
@param[in] Event The Event this notify function registered to.
@param[in] Context Pointer to the context data registerd to the
Event.
@return None.
**/
VOID
EFIAPI
ArpOnFrameSent (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Process the arp cache olding and drive the retrying arp requests.
@param[in] Event The Event this notify function registered to.
@param[in] Context Pointer to the context data registerd to the
Event.
@return None.
**/
VOID
EFIAPI
ArpTimerHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Cancel the arp request.
@param[in] Instance Pointer to the instance context data.
@param[in] TargetSwAddress Pointer to the buffer containing the target
software address to match the arp request.
@param[in] UserEvent The user event used to notify this request
cancellation.
@return The count of the cancelled requests.
**/
UINTN
ArpCancelRequest (
IN ARP_INSTANCE_DATA *Instance,
IN VOID *TargetSwAddress OPTIONAL,
IN EFI_EVENT UserEvent OPTIONAL
);
/**
Find the cache entry in the cache table.
@param[in] Instance Pointer to the instance context data.
@param[in] BySwAddress Set to TRUE to look for matching software protocol
addresses. Set to FALSE to look for matching
hardware protocol addresses.
@param[in] AddressBuffer Pointer to address buffer. Set to NULL to match
all addresses.
@param[out] EntryLength The size of an entry in the entries buffer.
@param[out] EntryCount The number of ARP cache entries that are found by
the specified criteria.
@param[out] Entries Pointer to the buffer that will receive the ARP
cache entries.
@param[in] Refresh Set to TRUE to refresh the timeout value of the
matching ARP cache entry.
@retval EFI_SUCCESS The requested ARP cache entries are copied into
the buffer.
@retval EFI_NOT_FOUND No matching entries found.
@retval EFI_OUT_OF_RESOURCE There is a memory allocation failure.
**/
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

View File

@@ -1,739 +0,0 @@
/** @file
Implementation of EFI Address Resolution Protocol (ARP) Protocol interface functions.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "ArpImpl.h"
/**
This function is used to assign a station address to the ARP cache for this instance
of the ARP driver.
Each ARP instance has one station address. The EFI_ARP_PROTOCOL driver will
respond to ARP requests that match this registered station address. A call to
this function with the ConfigData field set to NULL will reset this ARP instance.
Once a protocol type and station address have been assigned to this ARP instance,
all the following ARP functions will use this information. Attempting to change
the protocol type or station address to a configured ARP instance will result in errors.
@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;
EFI_TPL OldTpl;
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);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Configure this instance, the ConfigData has already passed the basic checks.
//
Status = ArpConfigureInstance (Instance, ConfigData);
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
This function is used to insert entries into the ARP cache.
ARP cache entries are typically inserted and updated by network protocol drivers
as network traffic is processed. Most ARP cache entries will time out and be
deleted if the network traffic stops. ARP cache entries that were inserted
by the Add() function may be static (will not time out) or dynamic (will time out).
Default ARP cache timeout values are not covered in most network protocol
specifications (although RFC 1122 comes pretty close) and will only be
discussed in general in this specification. The timeout values that are
used in the EFI Sample Implementation should be used only as a guideline.
Final product implementations of the EFI network stack should be tuned for
their expected network environments.
@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];
EFI_TPL OldTpl;
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;
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// 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.
//
RemoveEntryList (&CacheEntry->List);
} else {
//
// It's a new entry, allocate memory for the entry.
//
CacheEntry = ArpAllocCacheEntry (Instance);
if (CacheEntry == NULL) {
DEBUG ((EFI_D_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) {
InsertHeadList (&ArpService->DeniedCacheTable, &CacheEntry->List);
} else {
InsertHeadList (&ArpService->ResolvedCacheTable, &CacheEntry->List);
}
UNLOCK_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
This function searches the ARP cache for matching entries and allocates a buffer into
which those entries are copied.
The first part of the allocated buffer is EFI_ARP_FIND_DATA, following which
are protocol address pairs and hardware address pairs.
When finding a specific protocol address (BySwAddress is TRUE and AddressBuffer
is not NULL), the ARP cache timeout for the found entry is reset if Refresh is
set to TRUE. If the found ARP cache entry is a permanent entry, it is not
affected by Refresh.
@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;
EFI_TPL OldTpl;
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);
if (!Instance->Configured) {
return EFI_NOT_STARTED;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// All the check passed, find the cache entries now.
//
Status = ArpFindCacheEntry (
Instance,
BySwAddress,
AddressBuffer,
EntryLength,
EntryCount,
Entries,
Refresh
);
gBS->RestoreTPL (OldTpl);
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;
UINTN Count;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
if (!Instance->Configured) {
return EFI_NOT_STARTED;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Delete the specified cache entries.
//
Count = ArpDeleteCacheEntry (Instance, BySwAddress, AddressBuffer, TRUE);
gBS->RestoreTPL (OldTpl);
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;
UINTN Count;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = ARP_INSTANCE_DATA_FROM_THIS (This);
if (!Instance->Configured) {
return EFI_NOT_STARTED;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Delete the dynamic entries from the cache table.
//
Count = ArpDeleteCacheEntry (Instance, FALSE, NULL, FALSE);
gBS->RestoreTPL (OldTpl);
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;
EFI_TPL OldTpl;
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.
//
CopyMem (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.
//
ZeroMem (TargetHwAddress, SnpMode->HwAddressSize);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// 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.
//
CopyMem (
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 = AllocatePool (sizeof(USER_REQUEST_CONTEXT));
if (RequestContext == NULL) {
DEBUG ((EFI_D_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;
InitializeListHead (&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) {
DEBUG ((EFI_D_ERROR, "ArpRequest: Allocate memory for CacheEntry failed.\n"));
FreePool (RequestContext);
Status = EFI_OUT_OF_RESOURCES;
goto UNLOCK_EXIT;
}
//
// Fill the software address.
//
ArpFillAddressInCacheEntry (CacheEntry, &HardwareAddress, &ProtocolAddress);
//
// Add this entry into the PendingRequestTable.
//
InsertTailList (&ArpService->PendingRequestTable, &CacheEntry->List);
}
//
// Link this request context into the cache entry.
//
InsertHeadList (&CacheEntry->UserRequestList, &RequestContext->List);
//
// Send out the ARP Request frame.
//
ArpSendFrame (Instance, CacheEntry, ARP_OPCODE_REQUEST);
Status = EFI_NOT_READY;
UNLOCK_EXIT:
gBS->RestoreTPL (OldTpl);
SIGNAL_USER:
if ((ResolvedEvent != NULL) && (Status == EFI_SUCCESS)) {
gBS->SignalEvent (ResolvedEvent);
//
// Dispatch the DPC queued by the NotifyFunction of ResolvedEvent.
//
DispatchDpc ();
}
return Status;
}
/**
This function aborts the previous ARP request (identified by This, TargetSwAddress
and ResolvedEvent) that is issued by EFI_ARP_PROTOCOL.Request().
If the request is in the internal ARP request queue, the request is aborted
immediately and its ResolvedEvent is signaled. Only an asynchronous address
request needs to be canceled. If TargeSwAddress and ResolveEvent are both
NULL, all the pending asynchronous requests that have been issued by This
instance will be cancelled and their corresponding events will be signaled.
@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;
UINTN Count;
EFI_TPL OldTpl;
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;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Cancel the specified request.
//
Count = ArpCancelRequest (Instance, TargetSwAddress, ResolvedEvent);
//
// Dispatch the DPCs queued by the NotifyFunction of the events signaled
// by ArpCancleRequest.
//
DispatchDpc ();
gBS->RestoreTPL (OldTpl);
return (Count == 0) ? EFI_NOT_FOUND : EFI_SUCCESS;
}

View File

@@ -1,219 +0,0 @@
/** @file
UEFI Component Name(2) protocol implementation for ArpDxe driver.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "ArpDriver.h"
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gArpComponentName = {
ArpComponentNameGetDriverName,
ArpComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gArpComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) ArpComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) ArpComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mArpDriverNameTable[] = {
{ "eng;en", L"ARP Network Service Driver" },
{ NULL, NULL }
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mArpControllerNameTable[] = {
{ "eng;en", L"ARP Controller" },
{ NULL, NULL }
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
ArpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mArpDriverNameTable,
DriverName,
(BOOLEAN)(This == &gArpComponentName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
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_STATUS Status;
EFI_ARP_PROTOCOL *Arp;
//
// Only provide names for child handles.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver produced ChildHandle
//
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEfiManagedNetworkProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Retrieve an instance of a produced protocol from ChildHandle
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiArpProtocolGuid,
(VOID **)&Arp,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mArpControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gArpComponentName)
);
}

View File

@@ -1,431 +0,0 @@
/** @file
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Dhcp4Impl.h"
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
DhcpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
DhcpComponentNameGetControllerName (
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
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gDhcp4ComponentName = {
DhcpComponentNameGetDriverName,
DhcpComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gDhcp4ComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) DhcpComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) DhcpComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcpDriverNameTable[] = {
{
"eng;en",
L"DHCP Protocol Driver"
},
{
NULL,
NULL
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDhcpControllerNameTable = NULL;
CHAR16 *mDhcp4ControllerName[] = {
L"DHCPv4 (State=0, Stopped)",
L"DHCPv4 (State=1, Init)",
L"DHCPv4 (State=2, Selecting)",
L"DHCPv4 (State=3, Requesting)",
L"DHCPv4 (State=4, Bound)",
L"DHCPv4 (State=5, Renewing)",
L"DHCPv4 (State=6, Rebinding)",
L"DHCPv4 (State=7, InitReboot)",
L"DHCPv4 (State=8, Rebooting)"
};
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
DhcpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mDhcpDriverNameTable,
DriverName,
(BOOLEAN)(This == &gDhcp4ComponentName)
);
}
/**
Update the component name for the Dhcp4 child handle.
@param Dhcp4[in] A pointer to the EFI_DHCP4_PROTOCOL.
@retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
@retval EFI_INVALID_PARAMETER The input parameter is invalid.
@retval EFI_DEVICE_ERROR DHCP is in unknown state.
**/
EFI_STATUS
UpdateName (
IN EFI_DHCP4_PROTOCOL *Dhcp4
)
{
EFI_STATUS Status;
EFI_DHCP4_MODE_DATA Dhcp4ModeData;
if (Dhcp4 == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Format the child name into the string buffer.
//
Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData);
if (EFI_ERROR (Status)) {
return Status;
}
if (gDhcpControllerNameTable != NULL) {
FreeUnicodeStringTable (gDhcpControllerNameTable);
gDhcpControllerNameTable = NULL;
}
if (Dhcp4ModeData.State > Dhcp4Rebooting) {
return EFI_DEVICE_ERROR;
}
Status = AddUnicodeString2 (
"eng",
gDhcp4ComponentName.SupportedLanguages,
&gDhcpControllerNameTable,
mDhcp4ControllerName[Dhcp4ModeData.State],
TRUE
);
if (EFI_ERROR (Status)) {
return Status;
}
return AddUnicodeString2 (
"en",
gDhcp4ComponentName2.SupportedLanguages,
&gDhcpControllerNameTable,
mDhcp4ControllerName[Dhcp4ModeData.State],
FALSE
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
DhcpComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_DHCP4_PROTOCOL *Dhcp4;
//
// Only provide names for child handles.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver produced ChildHandle
//
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEfiUdp4ProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Retrieve an instance of a produced protocol from ChildHandle
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiDhcp4ProtocolGuid,
(VOID **)&Dhcp4,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Update the component name for this child handle.
//
Status = UpdateName (Dhcp4);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
gDhcpControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gDhcp4ComponentName)
);
}

View File

@@ -1,732 +0,0 @@
/** @file
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Dhcp4Impl.h"
#include "Dhcp4Driver.h"
EFI_DRIVER_BINDING_PROTOCOL gDhcp4DriverBinding = {
Dhcp4DriverBindingSupported,
Dhcp4DriverBindingStart,
Dhcp4DriverBindingStop,
0xa,
NULL,
NULL
};
EFI_SERVICE_BINDING_PROTOCOL mDhcp4ServiceBindingTemplate = {
Dhcp4ServiceBindingCreateChild,
Dhcp4ServiceBindingDestroyChild
};
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
both device drivers and bus drivers.
Entry point of the DHCP driver to install various protocols.
@param[in] ImageHandle The firmware allocated handle for the UEFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
**/
EFI_STATUS
EFIAPI
Dhcp4DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gDhcp4DriverBinding,
ImageHandle,
&gDhcp4ComponentName,
&gDhcp4ComponentName2
);
}
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Dhcp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiUdp4ServiceBindingProtocolGuid,
NULL,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
return Status;
}
/**
Configure the default UDP child to receive all the DHCP traffics
on this network interface.
@param[in] UdpIo The UDP IO to configure
@param[in] Context The context to the function
@retval EFI_SUCCESS The UDP IO is successfully configured.
@retval Others Failed to configure the UDP child.
**/
EFI_STATUS
EFIAPI
DhcpConfigUdpIo (
IN UDP_IO *UdpIo,
IN VOID *Context
)
{
EFI_UDP4_CONFIG_DATA UdpConfigData;
UdpConfigData.AcceptBroadcast = TRUE;
UdpConfigData.AcceptPromiscuous = FALSE;
UdpConfigData.AcceptAnyPort = FALSE;
UdpConfigData.AllowDuplicatePort = TRUE;
UdpConfigData.TypeOfService = 0;
UdpConfigData.TimeToLive = 64;
UdpConfigData.DoNotFragment = FALSE;
UdpConfigData.ReceiveTimeout = 0;
UdpConfigData.TransmitTimeout = 0;
UdpConfigData.UseDefaultAddress = FALSE;
UdpConfigData.StationPort = DHCP_CLIENT_PORT;
UdpConfigData.RemotePort = DHCP_SERVER_PORT;
ZeroMem (&UdpConfigData.StationAddress, sizeof (EFI_IPv4_ADDRESS));
ZeroMem (&UdpConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));
return UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);;
}
/**
Destroy the DHCP service. The Dhcp4 service may be partly initialized,
or partly destroyed. If a resource is destroyed, it is marked as so in
case the destroy failed and being called again later.
@param[in] DhcpSb The DHCP service instance to destroy.
@retval EFI_SUCCESS Always return success.
**/
EFI_STATUS
Dhcp4CloseService (
IN DHCP_SERVICE *DhcpSb
)
{
DhcpCleanLease (DhcpSb);
if (DhcpSb->UdpIo != NULL) {
UdpIoFreeIo (DhcpSb->UdpIo);
DhcpSb->UdpIo = NULL;
}
if (DhcpSb->Timer != NULL) {
gBS->SetTimer (DhcpSb->Timer, TimerCancel, 0);
gBS->CloseEvent (DhcpSb->Timer);
DhcpSb->Timer = NULL;
}
return EFI_SUCCESS;
}
/**
Create a new DHCP service binding instance for the controller.
@param[in] Controller The controller to install DHCP service binding
protocol onto
@param[in] ImageHandle The driver's image handle
@param[out] Service The variable to receive the created DHCP service
instance.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource .
@retval EFI_SUCCESS The DHCP service instance is created.
@retval other Other error occurs.
**/
EFI_STATUS
Dhcp4CreateService (
IN EFI_HANDLE Controller,
IN EFI_HANDLE ImageHandle,
OUT DHCP_SERVICE **Service
)
{
DHCP_SERVICE *DhcpSb;
EFI_STATUS Status;
*Service = NULL;
DhcpSb = AllocateZeroPool (sizeof (DHCP_SERVICE));
if (DhcpSb == NULL) {
return EFI_OUT_OF_RESOURCES;
}
DhcpSb->Signature = DHCP_SERVICE_SIGNATURE;
DhcpSb->ServiceState = DHCP_UNCONFIGED;
DhcpSb->Controller = Controller;
DhcpSb->Image = ImageHandle;
InitializeListHead (&DhcpSb->Children);
DhcpSb->DhcpState = Dhcp4Stopped;
DhcpSb->Xid = NET_RANDOM (NetRandomInitSeed ());
CopyMem (
&DhcpSb->ServiceBinding,
&mDhcp4ServiceBindingTemplate,
sizeof (EFI_SERVICE_BINDING_PROTOCOL)
);
//
// Create various resources, UdpIo, Timer, and get Mac address
//
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_CALLBACK,
DhcpOnTimerTick,
DhcpSb,
&DhcpSb->Timer
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
DhcpSb->UdpIo = UdpIoCreateIo (
Controller,
ImageHandle,
DhcpConfigUdpIo,
UDP_IO_UDP4_VERSION,
NULL
);
if (DhcpSb->UdpIo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
DhcpSb->HwLen = (UINT8) DhcpSb->UdpIo->SnpMode.HwAddressSize;
DhcpSb->HwType = DhcpSb->UdpIo->SnpMode.IfType;
CopyMem (&DhcpSb->Mac, &DhcpSb->UdpIo->SnpMode.CurrentAddress, sizeof (DhcpSb->Mac));
*Service = DhcpSb;
return EFI_SUCCESS;
ON_ERROR:
Dhcp4CloseService (DhcpSb);
FreePool (DhcpSb);
return Status;
}
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Dhcp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
DHCP_SERVICE *DhcpSb;
EFI_STATUS Status;
//
// First: test for the DHCP4 Protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDhcp4ServiceBindingProtocolGuid,
NULL,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (Status == EFI_SUCCESS) {
return EFI_ALREADY_STARTED;
}
Status = Dhcp4CreateService (ControllerHandle, This->DriverBindingHandle, &DhcpSb);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (DhcpSb != NULL);
//
// Start the receiving
//
Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
Status = gBS->SetTimer (DhcpSb->Timer, TimerPeriodic, TICKS_PER_SECOND);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
//
// Install the Dhcp4ServiceBinding Protocol onto ControlerHandle
//
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiDhcp4ServiceBindingProtocolGuid,
&DhcpSb->ServiceBinding,
NULL
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
return Status;
ON_ERROR:
Dhcp4CloseService (DhcpSb);
FreePool (DhcpSb);
return Status;
}
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@param[in] Entry The entry to be removed.
@param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
@retval EFI_SUCCESS The entry has been removed successfully.
@retval Others Fail to remove the entry.
**/
EFI_STATUS
EFIAPI
Dhcp4DestroyChildEntry (
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
DHCP_PROTOCOL *Instance;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
if (Entry == NULL || Context == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP_PROTOCOL, Link, DHCP_PROTOCOL_SIGNATURE);
ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
}
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
Dhcp4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
DHCP_SERVICE *DhcpSb;
EFI_HANDLE NicHandle;
EFI_STATUS Status;
LIST_ENTRY *List;
UINTN ListLength;
//
// DHCP driver opens UDP child, So, the ControllerHandle is the
// UDP child handle. locate the Nic handle first.
//
NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiUdp4ProtocolGuid);
if (NicHandle == NULL) {
return EFI_SUCCESS;
}
Status = gBS->OpenProtocol (
NicHandle,
&gEfiDhcp4ServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
This->DriverBindingHandle,
NicHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
DhcpSb = DHCP_SERVICE_FROM_THIS (ServiceBinding);
if (!IsListEmpty (&DhcpSb->Children)) {
//
// Destroy all the children instances before destory the service.
//
List = &DhcpSb->Children;
Status = NetDestroyLinkList (
List,
Dhcp4DestroyChildEntry,
ServiceBinding,
&ListLength
);
if (EFI_ERROR (Status) || ListLength != 0) {
Status = EFI_DEVICE_ERROR;
}
}
if (NumberOfChildren == 0 && !IsListEmpty (&DhcpSb->Children)) {
Status = EFI_DEVICE_ERROR;
}
if (NumberOfChildren == 0 && IsListEmpty (&DhcpSb->Children)) {
//
// Destroy the service itself if no child instance left.
//
DhcpSb->ServiceState = DHCP_DESTROY;
gBS->UninstallProtocolInterface (
NicHandle,
&gEfiDhcp4ServiceBindingProtocolGuid,
ServiceBinding
);
Dhcp4CloseService (DhcpSb);
if (gDhcpControllerNameTable != NULL) {
FreeUnicodeStringTable (gDhcpControllerNameTable);
gDhcpControllerNameTable = NULL;
}
FreePool (DhcpSb);
Status = EFI_SUCCESS;
}
return Status;
}
/**
Initialize a new DHCP instance.
@param DhcpSb The dhcp service instance
@param Instance The dhcp instance to initialize
**/
VOID
DhcpInitProtocol (
IN DHCP_SERVICE *DhcpSb,
IN OUT DHCP_PROTOCOL *Instance
)
{
Instance->Signature = DHCP_PROTOCOL_SIGNATURE;
CopyMem (&Instance->Dhcp4Protocol, &mDhcp4ProtocolTemplate, sizeof (Instance->Dhcp4Protocol));
InitializeListHead (&Instance->Link);
Instance->Handle = NULL;
Instance->Service = DhcpSb;
Instance->InDestroy = FALSE;
Instance->CompletionEvent = NULL;
Instance->RenewRebindEvent = NULL;
Instance->Token = NULL;
Instance->UdpIo = NULL;
Instance->ElaspedTime = 0;
NetbufQueInit (&Instance->ResponseQueue);
}
/**
Creates a child handle and installs a protocol.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Pointer to the handle of the child to create. If it is NULL,
then a new handle is created. If it is a pointer to an existing UEFI handle,
then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
the child
@retval other The child handle was not created
**/
EFI_STATUS
EFIAPI
Dhcp4ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE *ChildHandle
)
{
DHCP_SERVICE *DhcpSb;
DHCP_PROTOCOL *Instance;
EFI_STATUS Status;
EFI_TPL OldTpl;
VOID *Udp4;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = AllocatePool (sizeof (*Instance));
if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
DhcpSb = DHCP_SERVICE_FROM_THIS (This);
DhcpInitProtocol (DhcpSb, Instance);
//
// Install DHCP4 onto ChildHandle
//
Status = gBS->InstallMultipleProtocolInterfaces (
ChildHandle,
&gEfiDhcp4ProtocolGuid,
&Instance->Dhcp4Protocol,
NULL
);
if (EFI_ERROR (Status)) {
FreePool (Instance);
return Status;
}
Instance->Handle = *ChildHandle;
//
// Open the Udp4 protocol BY_CHILD.
//
Status = gBS->OpenProtocol (
DhcpSb->UdpIo->UdpHandle,
&gEfiUdp4ProtocolGuid,
(VOID **) &Udp4,
gDhcp4DriverBinding.DriverBindingHandle,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
gBS->UninstallMultipleProtocolInterfaces (
Instance->Handle,
&gEfiDhcp4ProtocolGuid,
&Instance->Dhcp4Protocol,
NULL
);
FreePool (Instance);
return Status;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
InsertTailList (&DhcpSb->Children, &Instance->Link);
DhcpSb->NumChildren++;
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
/**
Destroys a child handle with a protocol installed on it.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
@retval EFI_INVALID_PARAMETER Child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its services are being used.
@retval other The child handle was not destroyed
**/
EFI_STATUS
EFIAPI
Dhcp4ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
)
{
DHCP_SERVICE *DhcpSb;
DHCP_PROTOCOL *Instance;
EFI_DHCP4_PROTOCOL *Dhcp;
EFI_TPL OldTpl;
EFI_STATUS Status;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
//
// Retrieve the private context data structures
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiDhcp4ProtocolGuid,
(VOID **) &Dhcp,
gDhcp4DriverBinding.DriverBindingHandle,
ChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Instance = DHCP_INSTANCE_FROM_THIS (Dhcp);
DhcpSb = DHCP_SERVICE_FROM_THIS (This);
if (Instance->Service != DhcpSb) {
return EFI_INVALID_PARAMETER;
}
//
// A child can be destroyed more than once. For example,
// Dhcp4DriverBindingStop will destroy all of its children.
// when caller driver is being stopped, it will destroy the
// dhcp child it opens.
//
if (Instance->InDestroy) {
return EFI_SUCCESS;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Instance->InDestroy = TRUE;
//
// Close the Udp4 protocol.
//
gBS->CloseProtocol (
DhcpSb->UdpIo->UdpHandle,
&gEfiUdp4ProtocolGuid,
gDhcp4DriverBinding.DriverBindingHandle,
ChildHandle
);
//
// Uninstall the DHCP4 protocol first to enable a top down destruction.
//
gBS->RestoreTPL (OldTpl);
Status = gBS->UninstallProtocolInterface (
ChildHandle,
&gEfiDhcp4ProtocolGuid,
Dhcp
);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (EFI_ERROR (Status)) {
Instance->InDestroy = FALSE;
gBS->RestoreTPL (OldTpl);
return Status;
}
if (DhcpSb->ActiveChild == Instance) {
DhcpYieldControl (DhcpSb);
}
RemoveEntryList (&Instance->Link);
DhcpSb->NumChildren--;
if (Instance->UdpIo != NULL) {
UdpIoCleanIo (Instance->UdpIo);
gBS->CloseProtocol (
Instance->UdpIo->UdpHandle,
&gEfiUdp4ProtocolGuid,
Instance->Service->Image,
Instance->Handle
);
UdpIoFreeIo (Instance->UdpIo);
Instance->UdpIo = NULL;
Instance->Token = NULL;
}
gBS->RestoreTPL (OldTpl);
FreePool (Instance);
return EFI_SUCCESS;
}

View File

@@ -1,146 +0,0 @@
/** @file
Header for the DHCP4 driver.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_DHCP4_DRIVER_H__
#define __EFI_DHCP4_DRIVER_H__
extern EFI_COMPONENT_NAME_PROTOCOL gDhcp4ComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gDhcp4ComponentName2;
extern EFI_UNICODE_STRING_TABLE *gDhcpControllerNameTable;
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Dhcp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Dhcp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
Dhcp4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
Creates a child handle and installs a protocol.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Pointer to the handle of the child to create. If it is NULL,
then a new handle is created. If it is a pointer to an existing UEFI handle,
then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
the child
@retval other The child handle was not created
**/
EFI_STATUS
EFIAPI
Dhcp4ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE *ChildHandle
);
/**
Destroys a child handle with a protocol installed on it.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
@retval EFI_INVALID_PARAMETER Child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its services are being used.
@retval other The child handle was not destroyed
**/
EFI_STATUS
EFIAPI
Dhcp4ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@@ -1,66 +0,0 @@
## @file
# This module produces EFI DHCPv4 Protocol and EFI DHCPv4 Service Binding Protocol.
#
# This module produces EFI DHCPv4 Protocol upon EFI UDPv4 Protocol, to provide the
# capability to collect configuration information for the EFI IPv4 Protocol drivers
# and to provide DHCPv4 server and PXE boot server discovery services.
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Dhcp4Dxe
MODULE_UNI_FILE = Dhcp4Dxe.uni
FILE_GUID = 94734718-0BBC-47fb-96A5-EE7A5AE6A2AD
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = Dhcp4DriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
# DRIVER_BINDING = gDhcp4DriverBinding
# COMPONENT_NAME = gDhcp4ComponentName
# COMPONENT_NAME2 = gDhcp4ComponentName2
#
[Sources]
Dhcp4Impl.c
Dhcp4Io.c
Dhcp4Io.h
ComponentName.c
Dhcp4Driver.h
Dhcp4Driver.c
Dhcp4Option.c
Dhcp4Option.h
Dhcp4Impl.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
DebugLib
NetLib
UdpIoLib
[Protocols]
gEfiDhcp4ServiceBindingProtocolGuid ## BY_START
gEfiUdp4ServiceBindingProtocolGuid ## TO_START
gEfiDhcp4ProtocolGuid ## BY_START
gEfiUdp4ProtocolGuid ## TO_START
[UserExtensions.TianoCore."ExtraFiles"]
Dhcp4DxeExtra.uni

View File

@@ -1,18 +0,0 @@
// /** @file
// This module produces EFI DHCPv4 Protocol and EFI DHCPv4 Service Binding Protocol.
//
// This module produces EFI DHCPv4 Protocol upon EFI UDPv4 Protocol, to provide the
// capability to collect configuration information for the EFI IPv4 Protocol drivers
// and to provide DHCPv4 server and PXE boot server discovery services.
//
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "EFI DHCPv4 Driver"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI DHCPv4 Protocol using the EFI UDPv4 Protocol, providing the capability to collect configuration information for the EFI IPv4 Protocol drivers and providing DHCPv4 server and PXE boot server discovery services."

View File

@@ -1,14 +0,0 @@
// /** @file
// Dhcp4Dxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"DHCP v4 DXE Driver"

File diff suppressed because it is too large Load Diff

View File

@@ -1,206 +0,0 @@
/** @file
EFI DHCP protocol implementation.
RFCs supported are:
RFC 2131: Dynamic Host Configuration Protocol
RFC 2132: DHCP Options and BOOTP Vendor Extensions
RFC 1534: Interoperation Between DHCP and BOOTP
RFC 3396: Encoding Long Options in DHCP.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_DHCP4_IMPL_H__
#define __EFI_DHCP4_IMPL_H__
#include <Uefi.h>
#include <Protocol/Dhcp4.h>
#include <Protocol/Udp4.h>
#include <IndustryStandard/Dhcp.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/NetLib.h>
typedef struct _DHCP_SERVICE DHCP_SERVICE;
typedef struct _DHCP_PROTOCOL DHCP_PROTOCOL;
#include "Dhcp4Option.h"
#include "Dhcp4Io.h"
#define DHCP_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', 'C', 'P')
#define DHCP_PROTOCOL_SIGNATURE SIGNATURE_32 ('d', 'h', 'c', 'p')
#define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
//
// The state of the DHCP service. It starts as UNCONFIGED. If
// and active child configures the service successfully, it
// goes to CONFIGED. If the active child configures NULL, it
// goes back to UNCONFIGED. It becomes DESTROY if it is (partly)
// destroyed.
//
#define DHCP_UNCONFIGED 0
#define DHCP_CONFIGED 1
#define DHCP_DESTROY 2
struct _DHCP_PROTOCOL {
UINT32 Signature;
EFI_DHCP4_PROTOCOL Dhcp4Protocol;
LIST_ENTRY Link;
EFI_HANDLE Handle;
DHCP_SERVICE *Service;
BOOLEAN InDestroy;
EFI_EVENT CompletionEvent;
EFI_EVENT RenewRebindEvent;
EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;
UDP_IO *UdpIo; // The UDP IO used for TransmitReceive.
UINT32 Timeout;
UINT16 ElaspedTime;
NET_BUF_QUEUE ResponseQueue;
};
//
// DHCP driver is specical in that it is a singleton. Although it
// has a service binding, there can be only one active child.
//
struct _DHCP_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
INTN ServiceState; // CONFIGED, UNCONFIGED, and DESTROY
EFI_HANDLE Controller;
EFI_HANDLE Image;
LIST_ENTRY Children;
UINTN NumChildren;
INTN DhcpState;
EFI_STATUS IoStatus; // the result of last user operation
UINT32 Xid;
IP4_ADDR ClientAddr; // lease IP or configured client address
IP4_ADDR Netmask;
IP4_ADDR ServerAddr;
EFI_DHCP4_PACKET *LastOffer; // The last received offer
EFI_DHCP4_PACKET *Selected;
DHCP_PARAMETER *Para;
UINT32 Lease;
UINT32 T1;
UINT32 T2;
INTN ExtraRefresh; // This refresh is reqested by user
UDP_IO *UdpIo; // Udp child receiving all DHCP message
UDP_IO *LeaseIoPort; // Udp child with lease IP
EFI_DHCP4_PACKET *LastPacket; // The last sent packet for retransmission
EFI_MAC_ADDRESS Mac;
UINT8 HwType;
UINT8 HwLen;
UINT8 ClientAddressSendOut[16];
DHCP_PROTOCOL *ActiveChild;
EFI_DHCP4_CONFIG_DATA ActiveConfig;
UINT32 UserOptionLen;
//
// Timer event and various timer
//
EFI_EVENT Timer;
UINT32 PacketToLive; // Retransmission timer for our packets
UINT32 LastTimeout; // Record the init value of PacketToLive every time
INTN CurRetry;
INTN MaxRetries;
UINT32 LeaseLife;
};
typedef struct {
EFI_DHCP4_PACKET_OPTION **Option;
UINT32 OptionCount;
UINT32 Index;
} DHCP_PARSE_CONTEXT;
#define DHCP_INSTANCE_FROM_THIS(Proto) \
CR ((Proto), DHCP_PROTOCOL, Dhcp4Protocol, DHCP_PROTOCOL_SIGNATURE)
#define DHCP_SERVICE_FROM_THIS(Sb) \
CR ((Sb), DHCP_SERVICE, ServiceBinding, DHCP_SERVICE_SIGNATURE)
extern EFI_DHCP4_PROTOCOL mDhcp4ProtocolTemplate;
/**
Give up the control of the DHCP service to let other child
resume. Don't change the service's DHCP state and the Client
address and option list configure as required by RFC2131.
@param DhcpSb The DHCP service instance.
**/
VOID
DhcpYieldControl (
IN DHCP_SERVICE *DhcpSb
);
/**
Complete a Dhcp4 transaction and signal the upper layer.
@param Instance Dhcp4 instance.
**/
VOID
PxeDhcpDone (
IN DHCP_PROTOCOL *Instance
);
/**
Free the resource related to the configure parameters.
DHCP driver will make a copy of the user's configure
such as the time out value.
@param Config The DHCP configure data
**/
VOID
DhcpCleanConfigure (
IN OUT EFI_DHCP4_CONFIG_DATA *Config
);
/**
Callback of Dhcp packet. Does nothing.
@param Arg The context.
**/
VOID
EFIAPI
DhcpDummyExtFree (
IN VOID *Arg
);
/**
Set the elapsed time based on the given instance and the pointer to the
elapsed time option.
@param[in] Elapsed The pointer to the position to append.
@param[in] Instance The pointer to the Dhcp4 instance.
**/
VOID
SetElapsedTime (
IN UINT16 *Elapsed,
IN DHCP_PROTOCOL *Instance
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,189 +0,0 @@
/** @file
The DHCP4 protocol implementation.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_DHCP4_IO_H__
#define __EFI_DHCP4_IO_H__
#include <Uefi.h>
#include <Protocol/ServiceBinding.h>
#include <Library/NetLib.h>
#include <Library/UdpIoLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#define DHCP_WAIT_OFFER 3 // Time to wait the offers
#define DHCP_DEFAULT_LEASE 7 * 24 * 60 * 60 // Seven days as default.
#define DHCP_SERVER_PORT 67
#define DHCP_CLIENT_PORT 68
//
// BOOTP header "op" field
//
#define BOOTP_REQUEST 1
#define BOOTP_REPLY 2
//
// DHCP message types
//
#define DHCP_MSG_DISCOVER 1
#define DHCP_MSG_OFFER 2
#define DHCP_MSG_REQUEST 3
#define DHCP_MSG_DECLINE 4
#define DHCP_MSG_ACK 5
#define DHCP_MSG_NAK 6
#define DHCP_MSG_RELEASE 7
#define DHCP_MSG_INFORM 8
//
// DHCP notify user type
//
#define DHCP_NOTIFY_COMPLETION 1
#define DHCP_NOTIFY_RENEWREBIND 2
#define DHCP_NOTIFY_ALL 3
#define DHCP_IS_BOOTP(Parameter) (((Parameter) == NULL) || ((Parameter)->DhcpType == 0))
#define DHCP_CONNECTED(State) \
(((State) == Dhcp4Bound) || ((State) == (Dhcp4Renewing)) || ((State) == Dhcp4Rebinding))
/**
Set the DHCP state. If CallUser is true, it will try to notify
the user before change the state by DhcpNotifyUser. It returns
EFI_ABORTED if the user return EFI_ABORTED, otherwise, it returns
EFI_SUCCESS. If CallUser is FALSE, it isn't necessary to test
the return value of this function.
@param DhcpSb The DHCP service instance
@param State The new DHCP state to change to
@param CallUser Whether we need to call user
@retval EFI_SUCCESS The state is changed
@retval EFI_ABORTED The user asks to abort the DHCP process.
**/
EFI_STATUS
DhcpSetState (
IN OUT DHCP_SERVICE *DhcpSb,
IN INTN State,
IN BOOLEAN CallUser
);
/**
Build and transmit a DHCP message according to the current states.
This function implement the Table 5. of RFC 2131. Always transits
the state (as defined in Figure 5. of the same RFC) before sending
a DHCP message. The table is adjusted accordingly.
@param[in] DhcpSb The DHCP service instance
@param[in] Seed The seed packet which the new packet is based on
@param[in] Para The DHCP parameter of the Seed packet
@param[in] Type The message type to send
@param[in] Msg The human readable message to include in the packet
sent.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet
@retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP
@retval EFI_SUCCESS The message is sent
@retval other Other error occurs
**/
EFI_STATUS
DhcpSendMessage (
IN DHCP_SERVICE *DhcpSb,
IN EFI_DHCP4_PACKET *Seed,
IN DHCP_PARAMETER *Para,
IN UINT8 Type,
IN UINT8 *Msg
);
/**
Each DHCP service has three timer. Two of them are count down timer.
One for the packet retransmission. The other is to collect the offers.
The third timer increaments the lease life which is compared to T1, T2,
and lease to determine the time to renew and rebind the lease.
DhcpOnTimerTick will be called once every second.
@param[in] Event The timer event
@param[in] Context The context, which is the DHCP service instance.
**/
VOID
EFIAPI
DhcpOnTimerTick (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Handle the received DHCP packets. This function drives the DHCP
state machine.
@param UdpPacket The UDP packets received.
@param EndPoint The local/remote UDP access point
@param IoStatus The status of the UDP receive
@param Context The opaque parameter to the function.
**/
VOID
EFIAPI
DhcpInput (
NET_BUF *UdpPacket,
UDP_END_POINT *EndPoint,
EFI_STATUS IoStatus,
VOID *Context
);
/**
Send an initial DISCOVER or REQUEST message according to the
DHCP service's current state.
@param[in] DhcpSb The DHCP service instance
@retval EFI_SUCCESS The request has been sent
@retval other Some error occurs when sending the request.
**/
EFI_STATUS
DhcpInitRequest (
IN DHCP_SERVICE *DhcpSb
);
/**
Clean up the DHCP related states, IoStatus isn't reset.
@param DhcpSb The DHCP instance service.
**/
VOID
DhcpCleanLease (
IN DHCP_SERVICE *DhcpSb
);
/**
Release the net buffer when packet is sent.
@param UdpPacket The UDP packets received.
@param EndPoint The local/remote UDP access point
@param IoStatus The status of the UDP receive
@param Context The opaque parameter to the function.
**/
VOID
EFIAPI
DhcpOnPacketSent (
NET_BUF *Packet,
UDP_END_POINT *EndPoint,
EFI_STATUS IoStatus,
VOID *Context
);
#endif

View File

@@ -1,890 +0,0 @@
/** @file
Function to validate, parse, process the DHCP options.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Dhcp4Impl.h"
///
/// A list of the format of DHCP Options sorted by option tag
/// to validate a dhcp message. Refere the comments of the
/// DHCP_OPTION_FORMAT structure.
///
DHCP_OPTION_FORMAT DhcpOptionFormats[] = {
{DHCP4_TAG_NETMASK, DHCP_OPTION_IP, 1, 1 , TRUE},
{DHCP4_TAG_TIME_OFFSET, DHCP_OPTION_INT32, 1, 1 , FALSE},
{DHCP4_TAG_ROUTER, DHCP_OPTION_IP, 1, -1 , TRUE},
{DHCP4_TAG_TIME_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_NAME_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_DNS_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_LOG_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_COOKIE_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_LPR_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_IMPRESS_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_RL_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_HOSTNAME, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_BOOTFILE_LEN, DHCP_OPTION_INT16, 1, 1 , FALSE},
{DHCP4_TAG_DUMP, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_DOMAINNAME, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_SWAP_SERVER, DHCP_OPTION_IP, 1, 1 , FALSE},
{DHCP4_TAG_ROOTPATH, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_EXTEND_PATH, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_IPFORWARD, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_NONLOCAL_SRR, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_POLICY_SRR, DHCP_OPTION_IPPAIR, 1, -1 , FALSE},
{DHCP4_TAG_EMTU, DHCP_OPTION_INT16, 1, 1 , FALSE},
{DHCP4_TAG_TTL, DHCP_OPTION_INT8, 1, 1 , FALSE},
{DHCP4_TAG_PATHMTU_AGE, DHCP_OPTION_INT32, 1, 1 , FALSE},
{DHCP4_TAG_PATHMTU_PLATEAU,DHCP_OPTION_INT16, 1, -1 , FALSE},
{DHCP4_TAG_IFMTU, DHCP_OPTION_INT16, 1, 1 , FALSE},
{DHCP4_TAG_SUBNET_LOCAL, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_BROADCAST, DHCP_OPTION_IP, 1, 1 , FALSE},
{DHCP4_TAG_DISCOVER_MASK, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_SUPPLY_MASK, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_DISCOVER_ROUTE, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_ROUTER_SOLICIT, DHCP_OPTION_IP, 1, 1 , FALSE},
{DHCP4_TAG_STATIC_ROUTE, DHCP_OPTION_IPPAIR, 1, -1 , FALSE},
{DHCP4_TAG_TRAILER, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_ARPAGE, DHCP_OPTION_INT32, 1, 1 , FALSE},
{DHCP4_TAG_ETHER_ENCAP, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_TCP_TTL, DHCP_OPTION_INT8, 1, 1 , FALSE},
{DHCP4_TAG_KEEP_INTERVAL, DHCP_OPTION_INT32, 1, 1 , FALSE},
{DHCP4_TAG_KEEP_GARBAGE, DHCP_OPTION_SWITCH, 1, 1 , FALSE},
{DHCP4_TAG_NIS_DOMAIN, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_NIS_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_NTP_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_VENDOR, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_NBNS, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_NBDD, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_NBTYPE, DHCP_OPTION_INT8, 1, 1 , FALSE},
{DHCP4_TAG_NBSCOPE, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_XFONT, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_XDM, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_REQUEST_IP, DHCP_OPTION_IP, 1, 1 , FALSE},
{DHCP4_TAG_LEASE, DHCP_OPTION_INT32, 1, 1 , TRUE},
{DHCP4_TAG_OVERLOAD, DHCP_OPTION_INT8, 1, 1 , TRUE},
{DHCP4_TAG_MSG_TYPE, DHCP_OPTION_INT8, 1, 1 , TRUE},
{DHCP4_TAG_SERVER_ID, DHCP_OPTION_IP, 1, 1 , TRUE},
{DHCP4_TAG_PARA_LIST, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_MESSAGE, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_MAXMSG, DHCP_OPTION_INT16, 1, 1 , FALSE},
{DHCP4_TAG_T1, DHCP_OPTION_INT32, 1, 1 , TRUE},
{DHCP4_TAG_T2, DHCP_OPTION_INT32, 1, 1 , TRUE},
{DHCP4_TAG_VENDOR_CLASS_ID,DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_CLIENT_ID, DHCP_OPTION_INT8, 2, -1 , FALSE},
{DHCP4_TAG_NISPLUS, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_NISPLUS_SERVER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_TFTP, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_BOOTFILE, DHCP_OPTION_INT8, 1, -1 , FALSE},
{DHCP4_TAG_MOBILEIP, DHCP_OPTION_IP, 0, -1 , FALSE},
{DHCP4_TAG_SMTP, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_POP3, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_NNTP, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_WWW, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_FINGER, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_IRC, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_STTALK, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_STDA, DHCP_OPTION_IP, 1, -1 , FALSE},
{DHCP4_TAG_CLASSLESS_ROUTE,DHCP_OPTION_INT8, 5, -1 , FALSE},
};
/**
Binary search the DhcpOptionFormats array to find the format
information about a specific option.
@param[in] Tag The option's tag.
@return The point to the option's format, NULL if not found.
**/
DHCP_OPTION_FORMAT *
DhcpFindOptionFormat (
IN UINT8 Tag
)
{
INTN Left;
INTN Right;
INTN Middle;
Left = 0;
Right = sizeof (DhcpOptionFormats) / sizeof (DHCP_OPTION_FORMAT) - 1;
while (Right >= Left) {
Middle = (Left + Right) / 2;
if (Tag == DhcpOptionFormats[Middle].Tag) {
return &DhcpOptionFormats[Middle];
}
if (Tag < DhcpOptionFormats[Middle].Tag) {
Right = Middle - 1;
} else {
Left = Middle + 1;
}
}
return NULL;
}
/**
Validate whether a single DHCP option is valid according to its format.
@param[in] Format The option's format
@param[in] OptValue The value of the option
@param[in] Len The length of the option value
@retval TRUE The option is valid.
@retval FALSE Otherwise.
**/
BOOLEAN
DhcpOptionIsValid (
IN DHCP_OPTION_FORMAT *Format,
IN UINT8 *OptValue,
IN INTN Len
)
{
INTN Unit;
INTN Occur;
INTN Index;
Unit = 0;
switch (Format->Type) {
case DHCP_OPTION_SWITCH:
case DHCP_OPTION_INT8:
Unit = 1;
break;
case DHCP_OPTION_INT16:
Unit = 2;
break;
case DHCP_OPTION_INT32:
case DHCP_OPTION_IP:
Unit = 4;
break;
case DHCP_OPTION_IPPAIR:
Unit = 8;
break;
}
ASSERT (Unit != 0);
//
// Validate that the option appears in the full units.
//
if ((Len % Unit) != 0) {
return FALSE;
}
//
// Validate the occurance of the option unit is with in [MinOccur, MaxOccur]
//
Occur = Len / Unit;
if (((Format->MinOccur != -1) && (Occur < Format->MinOccur)) ||
((Format->MaxOccur != -1) && (Occur > Format->MaxOccur))
) {
return FALSE;
}
//
// If the option is of type switch, only 0/1 are valid values.
//
if (Format->Type == DHCP_OPTION_SWITCH) {
for (Index = 0; Index < Occur; Index++) {
if ((OptValue[Index] != 0) && (OptValue[Index] != 1)) {
return FALSE;
}
}
}
return TRUE;
}
/**
Extract the client interested options, all the parameters are
converted to host byte order.
@param[in] Tag The DHCP option tag
@param[in] Len The length of the option
@param[in] Data The value of the DHCP option
@param[out] Para The variable to save the interested parameter
@retval EFI_SUCCESS The DHCP option is successfully extracted.
@retval EFI_INVALID_PARAMETER The DHCP option is mal-formated
**/
EFI_STATUS
DhcpGetParameter (
IN UINT8 Tag,
IN INTN Len,
IN UINT8 *Data,
OUT DHCP_PARAMETER *Para
)
{
switch (Tag) {
case DHCP4_TAG_NETMASK:
Para->NetMask = NetGetUint32 (Data);
break;
case DHCP4_TAG_ROUTER:
//
// Return the first router to consumer which is the preferred one
//
Para->Router = NetGetUint32 (Data);
break;
case DHCP4_TAG_LEASE:
Para->Lease = NetGetUint32 (Data);
break;
case DHCP4_TAG_OVERLOAD:
Para->Overload = *Data;
if ((Para->Overload < 1) || (Para->Overload > 3)) {
return EFI_INVALID_PARAMETER;
}
break;
case DHCP4_TAG_MSG_TYPE:
Para->DhcpType = *Data;
if ((Para->DhcpType < 1) || (Para->DhcpType > 9)) {
return EFI_INVALID_PARAMETER;
}
break;
case DHCP4_TAG_SERVER_ID:
Para->ServerId = NetGetUint32 (Data);
break;
case DHCP4_TAG_T1:
Para->T1 = NetGetUint32 (Data);
break;
case DHCP4_TAG_T2:
Para->T2 = NetGetUint32 (Data);
break;
}
return EFI_SUCCESS;
}
/**
Inspect all the options in a single buffer. DHCP options may be contained
in several buffers, such as the BOOTP options filed, boot file or server
name. Each option buffer is required to end with DHCP4_TAG_EOP.
@param[in] Buffer The buffer which contains DHCP options
@param[in] BufLen The length of the buffer
@param[in] Check The callback function for each option found
@param[in] Context The opaque parameter for the Check
@param[out] Overload Variable to save the value of DHCP4_TAG_OVERLOAD
option.
@retval EFI_SUCCESS All the options are valid
@retval EFI_INVALID_PARAMETER The options are mal-formated.
**/
EFI_STATUS
DhcpIterateBufferOptions (
IN UINT8 *Buffer,
IN INTN BufLen,
IN DHCP_CHECK_OPTION Check OPTIONAL,
IN VOID *Context,
OUT UINT8 *Overload OPTIONAL
)
{
INTN Cur;
UINT8 Tag;
UINT8 Len;
Cur = 0;
while (Cur < BufLen) {
Tag = Buffer[Cur];
if (Tag == DHCP4_TAG_PAD) {
Cur++;
continue;
} else if (Tag == DHCP4_TAG_EOP) {
return EFI_SUCCESS;
}
Cur++;
if (Cur == BufLen) {
return EFI_INVALID_PARAMETER;
}
Len = Buffer[Cur++];
if (Cur + Len > BufLen) {
return EFI_INVALID_PARAMETER;
}
if ((Tag == DHCP4_TAG_OVERLOAD) && (Overload != NULL)) {
if (Len != 1) {
return EFI_INVALID_PARAMETER;
}
*Overload = Buffer[Cur];
}
if ((Check != NULL) && EFI_ERROR (Check (Tag, Len, Buffer + Cur, Context))) {
return EFI_INVALID_PARAMETER;
}
Cur += Len;
}
//
// Each option buffer is expected to end with an EOP
//
return EFI_INVALID_PARAMETER;
}
/**
Iterate through a DHCP message to visit each option. First inspect
all the options in the OPTION field. Then if overloaded, inspect
the options in FILENAME and SERVERNAME fields. One option may be
encoded in several places. See RFC 3396 Encoding Long Options in DHCP
@param[in] Packet The DHCP packet to check the options for
@param[in] Check The callback function to be called for each option
found
@param[in] Context The opaque parameter for Check
@retval EFI_SUCCESS The DHCP packet's options are well formated
@retval EFI_INVALID_PARAMETER The DHCP packet's options are not well formated
**/
EFI_STATUS
DhcpIterateOptions (
IN EFI_DHCP4_PACKET *Packet,
IN DHCP_CHECK_OPTION Check OPTIONAL,
IN VOID *Context
)
{
EFI_STATUS Status;
UINT8 Overload;
Overload = 0;
Status = DhcpIterateBufferOptions (
Packet->Dhcp4.Option,
Packet->Length - sizeof (EFI_DHCP4_HEADER) - sizeof (UINT32),
Check,
Context,
&Overload
);
if (EFI_ERROR (Status)) {
return Status;
}
if ((Overload == DHCP_OVERLOAD_FILENAME) || (Overload == DHCP_OVERLOAD_BOTH)) {
Status = DhcpIterateBufferOptions (
(UINT8 *) Packet->Dhcp4.Header.BootFileName,
128,
Check,
Context,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
}
if ((Overload == DHCP_OVERLOAD_SVRNAME) || (Overload == DHCP_OVERLOAD_BOTH)) {
Status = DhcpIterateBufferOptions (
(UINT8 *) Packet->Dhcp4.Header.ServerName,
64,
Check,
Context,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
}
return EFI_SUCCESS;
}
/**
Call back function to DhcpIterateOptions to compute each option's
length. It just adds the data length of all the occurances of this
Tag. Context is an array of 256 DHCP_OPTION_COUNT.
@param[in] Tag The current option to check
@param[in] Len The length of the option data
@param[in] Data The option data
@param[in] Context The context, which is a array of 256
DHCP_OPTION_COUNT.
@retval EFI_SUCCESS It always returns EFI_SUCCESS.
**/
EFI_STATUS
DhcpGetOptionLen (
IN UINT8 Tag,
IN UINT8 Len,
IN UINT8 *Data,
IN VOID *Context
)
{
DHCP_OPTION_COUNT *OpCount;
OpCount = (DHCP_OPTION_COUNT *) Context;
OpCount[Tag].Offset = (UINT16) (OpCount[Tag].Offset + Len);
return EFI_SUCCESS;
}
/**
Call back function to DhcpIterateOptions to consolidate each option's
data. There are maybe several occurrence of the same option.
@param[in] Tag The option to consolidate its data
@param[in] Len The length of option data
@param[in] Data The data of the option's current occurance
@param[in] Context The context, which is DHCP_OPTION_CONTEXT. This
array is just a wrap to pass THREE parameters.
@retval EFI_SUCCESS It always returns EFI_SUCCESS
**/
EFI_STATUS
DhcpFillOption (
IN UINT8 Tag,
IN UINT8 Len,
IN UINT8 *Data,
IN VOID *Context
)
{
DHCP_OPTION_CONTEXT *OptContext;
DHCP_OPTION_COUNT *OptCount;
DHCP_OPTION *Options;
UINT8 *Buf;
UINT8 Index;
OptContext = (DHCP_OPTION_CONTEXT *) Context;
OptCount = OptContext->OpCount;
Index = OptCount[Tag].Index;
Options = OptContext->Options;
Buf = OptContext->Buf;
if (Options[Index].Data == NULL) {
Options[Index].Tag = Tag;
Options[Index].Data = Buf + OptCount[Tag].Offset;
}
CopyMem (Buf + OptCount[Tag].Offset, Data, Len);
OptCount[Tag].Offset = (UINT16) (OptCount[Tag].Offset + Len);
Options[Index].Len = (UINT16) (Options[Index].Len + Len);
return EFI_SUCCESS;
}
/**
Parse the options of a DHCP packet. It supports RFC 3396: Encoding
Long Options in DHCP. That is, it will combine all the option value
of all the occurances of each option.
A little bit of implemenation:
It adopts the "Key indexed counting" algorithm. First, it allocates
an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded
as a UINT8. It then iterates the DHCP packet to get data length of
each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it
knows the number of present options and their length. It allocates a
array of DHCP_OPTION and a continuous buffer after the array to put
all the options' data. Each option's data is pointed to by the Data
field in DHCP_OPTION structure. At last, it call DhcpIterateOptions
with DhcpFillOption to fill each option's data to its position in the
buffer.
@param[in] Packet The DHCP packet to parse the options
@param[out] Count The number of valid dhcp options present in the
packet
@param[out] OptionPoint The array that contains the DHCP options. Caller
should free it.
@retval EFI_NOT_FOUND Cannot find any option.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to parse the packet.
@retval EFI_INVALID_PARAMETER The options are mal-formated
@retval EFI_SUCCESS The options are parsed into OptionPoint
**/
EFI_STATUS
DhcpParseOption (
IN EFI_DHCP4_PACKET *Packet,
OUT INTN *Count,
OUT DHCP_OPTION **OptionPoint
)
{
DHCP_OPTION_CONTEXT Context;
DHCP_OPTION *Options;
DHCP_OPTION_COUNT *OptCount;
EFI_STATUS Status;
UINT16 TotalLen;
INTN OptNum;
INTN Index;
ASSERT ((Count != NULL) && (OptionPoint != NULL));
//
// First compute how many options and how long each option is
// with the "Key indexed counting" algorithms.
//
OptCount = AllocateZeroPool (DHCP_MAX_OPTIONS * sizeof (DHCP_OPTION_COUNT));
if (OptCount == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = DhcpIterateOptions (Packet, DhcpGetOptionLen, OptCount);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
//
// Before the loop, Offset is the length of the option. After loop,
// OptCount[Index].Offset specifies the offset into the continuous
// option value buffer to put the data.
//
TotalLen = 0;
OptNum = 0;
for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
if (OptCount[Index].Offset != 0) {
OptCount[Index].Index = (UINT8) OptNum;
TotalLen = (UINT16) (TotalLen + OptCount[Index].Offset);
OptCount[Index].Offset = (UINT16) (TotalLen - OptCount[Index].Offset);
OptNum++;
}
}
*Count = OptNum;
*OptionPoint = NULL;
if (OptNum == 0) {
goto ON_EXIT;
}
//
// Allocate a buffer to hold the DHCP options, and after that, a
// continuous buffer to put all the options' data.
//
Options = AllocateZeroPool ((UINTN) (OptNum * sizeof (DHCP_OPTION)) + TotalLen);
if (Options == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
Context.OpCount = OptCount;
Context.Options = Options;
Context.Buf = (UINT8 *) (Options + OptNum);
Status = DhcpIterateOptions (Packet, DhcpFillOption, &Context);
if (EFI_ERROR (Status)) {
FreePool (Options);
goto ON_EXIT;
}
*OptionPoint = Options;
ON_EXIT:
FreePool (OptCount);
return Status;
}
/**
Validate the packet's options. If necessary, allocate
and fill in the interested parameters.
@param[in] Packet The packet to validate the options
@param[out] Para The variable to save the DHCP parameters.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to validate the packet.
@retval EFI_INVALID_PARAMETER The options are mal-formated
@retval EFI_SUCCESS The options are parsed into OptionPoint
**/
EFI_STATUS
DhcpValidateOptions (
IN EFI_DHCP4_PACKET *Packet,
OUT DHCP_PARAMETER **Para OPTIONAL
)
{
DHCP_PARAMETER Parameter;
DHCP_OPTION_FORMAT *Format;
DHCP_OPTION *AllOption;
DHCP_OPTION *Option;
EFI_STATUS Status;
BOOLEAN Updated;
INTN Count;
INTN Index;
if (Para != NULL) {
*Para = NULL;
}
AllOption = NULL;
Status = DhcpParseOption (Packet, &Count, &AllOption);
if (EFI_ERROR (Status) || (Count == 0)) {
return Status;
}
ASSERT (AllOption != NULL);
Updated = FALSE;
ZeroMem (&Parameter, sizeof (Parameter));
for (Index = 0; Index < Count; Index++) {
Option = &AllOption[Index];
//
// Find the format of the option then validate it.
//
Format = DhcpFindOptionFormat (Option->Tag);
if (Format == NULL) {
continue;
}
if (!DhcpOptionIsValid (Format, Option->Data, Option->Len)) {
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
//
// Get the client interested parameters
//
if (Format->Alert && (Para != NULL)) {
Updated = TRUE;
Status = DhcpGetParameter (Option->Tag, Option->Len, Option->Data, &Parameter);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
}
}
if (Updated && (Para != NULL)) {
*Para = AllocateCopyPool (sizeof (DHCP_PARAMETER), &Parameter);
if (*Para == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
}
ON_EXIT:
FreePool (AllOption);
return Status;
}
/**
Append an option to the memory, if the option is longer than
255 bytes, splits it into several options.
@param[out] Buf The buffer to append the option to
@param[in] Tag The option's tag
@param[in] DataLen The length of the option's data
@param[in] Data The option's data
@return The position to append the next option
**/
UINT8 *
DhcpAppendOption (
OUT UINT8 *Buf,
IN UINT8 Tag,
IN UINT16 DataLen,
IN UINT8 *Data
)
{
INTN Index;
INTN Len;
ASSERT (DataLen != 0);
for (Index = 0; Index < (DataLen + 254) / 255; Index++) {
Len = MIN (255, DataLen - Index * 255);
*(Buf++) = Tag;
*(Buf++) = (UINT8) Len;
CopyMem (Buf, Data + Index * 255, (UINTN) Len);
Buf += Len;
}
return Buf;
}
/**
Build a new DHCP packet from a seed packet. Options may be deleted or
appended. The caller should free the NewPacket when finished using it.
@param[in] SeedPacket The seed packet to start with
@param[in] DeleteCount The number of options to delete
@param[in] DeleteList The options to delete from the packet
@param[in] AppendCount The number of options to append
@param[in] AppendList The options to append to the packet
@param[out] NewPacket The new packet, allocated and built by this
function.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory
@retval EFI_INVALID_PARAMETER The options in SeekPacket are mal-formated
@retval EFI_SUCCESS The packet is build.
**/
EFI_STATUS
DhcpBuild (
IN EFI_DHCP4_PACKET *SeedPacket,
IN UINT32 DeleteCount,
IN UINT8 *DeleteList OPTIONAL,
IN UINT32 AppendCount,
IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL,
OUT EFI_DHCP4_PACKET **NewPacket
)
{
DHCP_OPTION *Mark;
DHCP_OPTION *SeedOptions;
EFI_DHCP4_PACKET *Packet;
EFI_STATUS Status;
INTN Count;
UINT32 Index;
UINT32 Len;
UINT8 *Buf;
//
// Use an array of DHCP_OPTION to mark the existance
// and position of each valid options.
//
Mark = AllocatePool (sizeof (DHCP_OPTION) * DHCP_MAX_OPTIONS);
if (Mark == NULL) {
return EFI_OUT_OF_RESOURCES;
}
for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
Mark[Index].Tag = (UINT8) Index;
Mark[Index].Len = 0;
}
//
// Get list of the options from the seed packet, then put
// them to the mark array according to their tags.
//
SeedOptions = NULL;
Status = DhcpParseOption (SeedPacket, &Count, &SeedOptions);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
if (SeedOptions != NULL) {
for (Index = 0; Index < (UINT32) Count; Index++) {
Mark[SeedOptions[Index].Tag] = SeedOptions[Index];
}
}
//
// Mark the option's length is zero if it is in the DeleteList.
//
for (Index = 0; Index < DeleteCount; Index++) {
Mark[DeleteList[Index]].Len = 0;
}
//
// Add or replace the option if it is in the append list.
//
for (Index = 0; Index < AppendCount; Index++) {
Mark[AppendList[Index]->OpCode].Len = AppendList[Index]->Length;
Mark[AppendList[Index]->OpCode].Data = AppendList[Index]->Data;
}
//
// compute the new packet length. No need to add 1 byte for
// EOP option since EFI_DHCP4_PACKET includes one extra byte
// for option. It is necessary to split the option if it is
// longer than 255 bytes.
//
Len = sizeof (EFI_DHCP4_PACKET);
for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
if (Mark[Index].Len != 0) {
Len += ((Mark[Index].Len + 254) / 255) * 2 + Mark[Index].Len;
}
}
Status = EFI_OUT_OF_RESOURCES;
Packet = (EFI_DHCP4_PACKET *) AllocatePool (Len);
if (Packet == NULL) {
goto ON_ERROR;
}
Packet->Size = Len;
Packet->Length = 0;
CopyMem (&Packet->Dhcp4.Header, &SeedPacket->Dhcp4.Header, sizeof (Packet->Dhcp4.Header));
Packet->Dhcp4.Magik = DHCP_OPTION_MAGIC;
Buf = Packet->Dhcp4.Option;
for (Index = 0; Index < DHCP_MAX_OPTIONS; Index++) {
if (Mark[Index].Len != 0) {
Buf = DhcpAppendOption (Buf, Mark[Index].Tag, Mark[Index].Len, Mark[Index].Data);
}
}
*(Buf++) = DHCP4_TAG_EOP;
Packet->Length = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32)
+ (UINT32) (Buf - Packet->Dhcp4.Option);
*NewPacket = Packet;
Status = EFI_SUCCESS;
ON_ERROR:
if (SeedOptions != NULL) {
FreePool (SeedOptions);
}
FreePool (Mark);
return Status;
}

View File

@@ -1,228 +0,0 @@
/** @file
To validate, parse and process the DHCP options.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_DHCP4_OPTION_H__
#define __EFI_DHCP4_OPTION_H__
///
/// DHCP option tags (types)
///
#define DHCP_OPTION_MAGIC 0x63538263 // Network byte order
#define DHCP_MAX_OPTIONS 256
//
// DHCP option types, this is used to validate the DHCP options.
//
#define DHCP_OPTION_SWITCH 1
#define DHCP_OPTION_INT8 2
#define DHCP_OPTION_INT16 3
#define DHCP_OPTION_INT32 4
#define DHCP_OPTION_IP 5
#define DHCP_OPTION_IPPAIR 6
//
// Value of DHCP overload option
//
#define DHCP_OVERLOAD_FILENAME 1
#define DHCP_OVERLOAD_SVRNAME 2
#define DHCP_OVERLOAD_BOTH 3
///
/// The DHCP option structure. This structure extends the EFI_DHCP_OPTION
/// structure to support options longer than 255 bytes, such as classless route.
///
typedef struct {
UINT8 Tag;
UINT16 Len;
UINT8 *Data;
} DHCP_OPTION;
///
/// Structures used to parse the DHCP options with RFC3396 support.
///
typedef struct {
UINT8 Index;
UINT16 Offset;
} DHCP_OPTION_COUNT;
typedef struct {
DHCP_OPTION_COUNT *OpCount;
DHCP_OPTION *Options;
UINT8 *Buf;
} DHCP_OPTION_CONTEXT;
///
/// The options that matters to DHCP driver itself. The user of
/// DHCP clients may be interested in other options, such as
/// classless route, who can parse the DHCP offer to get them.
///
typedef struct {
IP4_ADDR NetMask; // DHCP4_TAG_NETMASK
IP4_ADDR Router; // DHCP4_TAG_ROUTER, only the first router is used
//
// DHCP specific options
//
UINT8 DhcpType; // DHCP4_TAG_MSG_TYPE
UINT8 Overload; // DHCP4_TAG_OVERLOAD
IP4_ADDR ServerId; // DHCP4_TAG_SERVER_ID
UINT32 Lease; // DHCP4_TAG_LEASE
UINT32 T1; // DHCP4_TAG_T1
UINT32 T2; // DHCP4_TAG_T2
} DHCP_PARAMETER;
///
/// Structure used to describe and validate the format of DHCP options.
/// Type is the options' data type, such as DHCP_OPTION_INT8. MinOccur
/// is the minium occurance of this data type. MaxOccur is defined
/// similarly. If MaxOccur is -1, it means that there is no limit on the
/// maximum occurance. Alert tells whether DHCP client should further
/// inspect the option to parse DHCP_PARAMETER.
///
typedef struct {
UINT8 Tag;
INTN Type;
INTN MinOccur;
INTN MaxOccur;
BOOLEAN Alert;
} DHCP_OPTION_FORMAT;
typedef
EFI_STATUS
(*DHCP_CHECK_OPTION) (
IN UINT8 Tag,
IN UINT8 Len,
IN UINT8 *Data,
IN VOID *Context
);
/**
Iterate through a DHCP message to visit each option. First inspect
all the options in the OPTION field. Then if overloaded, inspect
the options in FILENAME and SERVERNAME fields. One option may be
encoded in several places. See RFC 3396 Encoding Long Options in DHCP
@param[in] Packet The DHCP packet to check the options for
@param[in] Check The callback function to be called for each option
found
@param[in] Context The opaque parameter for Check
@retval EFI_SUCCESS The DHCP packet's options are well formated
@retval EFI_INVALID_PARAMETER The DHCP packet's options are not well formated
**/
EFI_STATUS
DhcpIterateOptions (
IN EFI_DHCP4_PACKET *Packet,
IN DHCP_CHECK_OPTION Check OPTIONAL,
IN VOID *Context
);
/**
Validate the packet's options. If necessary, allocate
and fill in the interested parameters.
@param[in] Packet The packet to validate the options
@param[out] Para The variable to save the DHCP parameters.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to validate the packet.
@retval EFI_INVALID_PARAMETER The options are mal-formated
@retval EFI_SUCCESS The options are parsed into OptionPoint
**/
EFI_STATUS
DhcpValidateOptions (
IN EFI_DHCP4_PACKET *Packet,
OUT DHCP_PARAMETER **Para OPTIONAL
);
/**
Parse the options of a DHCP packet. It supports RFC 3396: Encoding
Long Options in DHCP. That is, it will combine all the option value
of all the occurances of each option.
A little bit of implemenation:
It adopts the "Key indexed counting" algorithm. First, it allocates
an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded
as a UINT8. It then iterates the DHCP packet to get data length of
each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it
knows the number of present options and their length. It allocates a
array of DHCP_OPTION and a continuous buffer after the array to put
all the options' data. Each option's data is pointed to by the Data
field in DHCP_OPTION structure. At last, it call DhcpIterateOptions
with DhcpFillOption to fill each option's data to its position in the
buffer.
@param[in] Packet The DHCP packet to parse the options
@param[out] Count The number of valid dhcp options present in the
packet
@param[out] OptionPoint The array that contains the DHCP options. Caller
should free it.
@retval EFI_NOT_FOUND Cannot find any option.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to parse the packet.
@retval EFI_INVALID_PARAMETER The options are mal-formated
@retval EFI_SUCCESS The options are parsed into OptionPoint
**/
EFI_STATUS
DhcpParseOption (
IN EFI_DHCP4_PACKET *Packet,
OUT INTN *Count,
OUT DHCP_OPTION **OptionPoint
);
/**
Append an option to the memory, if the option is longer than
255 bytes, splits it into several options.
@param[out] Buf The buffer to append the option to
@param[in] Tag The option's tag
@param[in] DataLen The length of the option's data
@param[in] Data The option's data
@return The position to append the next option
**/
UINT8 *
DhcpAppendOption (
OUT UINT8 *Buf,
IN UINT8 Tag,
IN UINT16 DataLen,
IN UINT8 *Data
);
/**
Build a new DHCP packet from a seed packet. Options may be deleted or
appended. The caller should free the NewPacket when finished using it.
@param[in] SeedPacket The seed packet to start with
@param[in] DeleteCount The number of options to delete
@param[in] DeleteList The options to delete from the packet
@param[in] AppendCount The number of options to append
@param[in] AppendList The options to append to the packet
@param[out] NewPacket The new packet, allocated and built by this
function.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory
@retval EFI_INVALID_PARAMETER The options in SeekPacket are mal-formated
@retval EFI_SUCCESS The packet is build.
**/
EFI_STATUS
DhcpBuild (
IN EFI_DHCP4_PACKET *SeedPacket,
IN UINT32 DeleteCount,
IN UINT8 *DeleteList OPTIONAL,
IN UINT32 AppendCount,
IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL,
OUT EFI_DHCP4_PACKET **NewPacket
);
#endif

View File

@@ -1,341 +0,0 @@
/** @file
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
Dpc.c
Abstract:
**/
#include "Dpc.h"
//
// Handle for the EFI_DPC_PROTOCOL instance
//
EFI_HANDLE mDpcHandle = NULL;
//
// The EFI_DPC_PROTOCOL instances that is installed onto mDpcHandle
//
EFI_DPC_PROTOCOL mDpc = {
DpcQueueDpc,
DpcDispatchDpc
};
//
// Global variables used to meaasure the DPC Queue Depths
//
UINTN mDpcQueueDepth = 0;
UINTN mMaxDpcQueueDepth = 0;
//
// Free list of DPC entries. As DPCs are queued, entries are removed from this
// free list. As DPC entries are dispatched, DPC entries are added to the free list.
// If the free list is empty and a DPC is queued, the free list is grown by allocating
// an additional set of DPC entries.
//
LIST_ENTRY mDpcEntryFreeList = INITIALIZE_LIST_HEAD_VARIABLE(mDpcEntryFreeList);
//
// An array of DPC queues. A DPC queue is allocated for every leval EFI_TPL value.
// As DPCs are queued, they are added to the end of the linked list.
// As DPCs are dispatched, they are removed from the beginning of the linked list.
//
LIST_ENTRY mDpcQueue[TPL_HIGH_LEVEL + 1];
/**
Add a Deferred Procedure Call to the end of the DPC queue.
@param This Protocol instance pointer.
@param DpcTpl The EFI_TPL that the DPC should be invoked.
@param DpcProcedure Pointer to the DPC's function.
@param DpcContext Pointer to the DPC's context. Passed to DpcProcedure
when DpcProcedure is invoked.
@retval EFI_SUCCESS The DPC was queued.
@retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL.
@retval EFI_INVALID_PARAMETER DpcProcedure is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
add the DPC to the queue.
**/
EFI_STATUS
EFIAPI
DpcQueueDpc (
IN EFI_DPC_PROTOCOL *This,
IN EFI_TPL DpcTpl,
IN EFI_DPC_PROCEDURE DpcProcedure,
IN VOID *DpcContext OPTIONAL
)
{
EFI_STATUS ReturnStatus;
EFI_TPL OriginalTpl;
DPC_ENTRY *DpcEntry;
UINTN Index;
//
// Make sure DpcTpl is valid
//
if (DpcTpl < TPL_APPLICATION || DpcTpl > TPL_HIGH_LEVEL) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure DpcProcedure is valid
//
if (DpcProcedure == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Assume this function will succeed
//
ReturnStatus = EFI_SUCCESS;
//
// Raise the TPL level to TPL_HIGH_LEVEL for DPC list operation and save the
// current TPL value so it can be restored when this function returns.
//
OriginalTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
//
// Check to see if there are any entries in the DPC free list
//
if (IsListEmpty (&mDpcEntryFreeList)) {
//
// If the current TPL is greater than TPL_NOTIFY, then memory allocations
// can not be performed, so the free list can not be expanded. In this case
// return EFI_OUT_OF_RESOURCES.
//
if (OriginalTpl > TPL_NOTIFY) {
ReturnStatus = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Add 64 DPC entries to the free list
//
for (Index = 0; Index < 64; Index++) {
//
// Lower the TPL level to perform a memory allocation
//
gBS->RestoreTPL (OriginalTpl);
//
// Allocate a new DPC entry
//
DpcEntry = AllocatePool (sizeof (DPC_ENTRY));
//
// Raise the TPL level back to TPL_HIGH_LEVEL for DPC list operations
//
gBS->RaiseTPL (TPL_HIGH_LEVEL);
//
// If the allocation of a DPC entry fails, and the free list is empty,
// then return EFI_OUT_OF_RESOURCES.
//
if (DpcEntry == NULL) {
if (IsListEmpty (&mDpcEntryFreeList)) {
ReturnStatus = EFI_OUT_OF_RESOURCES;
goto Done;
}
}
//
// Add the newly allocated DPC entry to the DPC free list
//
InsertTailList (&mDpcEntryFreeList, &DpcEntry->ListEntry);
}
}
//
// Retrieve the first node from the free list of DPCs
//
DpcEntry = (DPC_ENTRY *)(GetFirstNode (&mDpcEntryFreeList));
//
// Remove the first node from the free list of DPCs
//
RemoveEntryList (&DpcEntry->ListEntry);
//
// Fill in the DPC entry with the DpcProcedure and DpcContext
//
DpcEntry->DpcProcedure = DpcProcedure;
DpcEntry->DpcContext = DpcContext;
//
// Add the DPC entry to the end of the list for the specified DplTpl.
//
InsertTailList (&mDpcQueue[DpcTpl], &DpcEntry->ListEntry);
//
// Increment the measured DPC queue depth across all TPLs
//
mDpcQueueDepth++;
//
// Measure the maximum DPC queue depth across all TPLs
//
if (mDpcQueueDepth > mMaxDpcQueueDepth) {
mMaxDpcQueueDepth = mDpcQueueDepth;
}
Done:
//
// Restore the original TPL level when this function was called
//
gBS->RestoreTPL (OriginalTpl);
return ReturnStatus;
}
/**
Dispatch the queue of DPCs. ALL DPCs that have been queued with a DpcTpl
value greater than or equal to the current TPL are invoked in the order that
they were queued. DPCs with higher DpcTpl values are invoked before DPCs with
lower DpcTpl values.
@param This Protocol instance pointer.
@retval EFI_SUCCESS One or more DPCs were invoked.
@retval EFI_NOT_FOUND No DPCs were invoked.
**/
EFI_STATUS
EFIAPI
DpcDispatchDpc (
IN EFI_DPC_PROTOCOL *This
)
{
EFI_STATUS ReturnStatus;
EFI_TPL OriginalTpl;
EFI_TPL Tpl;
DPC_ENTRY *DpcEntry;
//
// Assume that no DPCs will be invoked
//
ReturnStatus = EFI_NOT_FOUND;
//
// Raise the TPL level to TPL_HIGH_LEVEL for DPC list operation and save the
// current TPL value so it can be restored when this function returns.
//
OriginalTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
//
// Check to see if there are 1 or more DPCs currently queued
//
if (mDpcQueueDepth > 0) {
//
// Loop from TPL_HIGH_LEVEL down to the current TPL value
//
for (Tpl = TPL_HIGH_LEVEL; Tpl >= OriginalTpl; Tpl--) {
//
// Check to see if the DPC queue is empty
//
while (!IsListEmpty (&mDpcQueue[Tpl])) {
//
// Retrieve the first DPC entry from the DPC queue specified by Tpl
//
DpcEntry = (DPC_ENTRY *)(GetFirstNode (&mDpcQueue[Tpl]));
//
// Remove the first DPC entry from the DPC queue specified by Tpl
//
RemoveEntryList (&DpcEntry->ListEntry);
//
// Decrement the measured DPC Queue Depth across all TPLs
//
mDpcQueueDepth--;
//
// Lower the TPL to TPL value of the current DPC queue
//
gBS->RestoreTPL (Tpl);
//
// Invoke the DPC passing in its context
//
(DpcEntry->DpcProcedure) (DpcEntry->DpcContext);
//
// At least one DPC has been invoked, so set the return status to EFI_SUCCESS
//
ReturnStatus = EFI_SUCCESS;
//
// Raise the TPL level back to TPL_HIGH_LEVEL for DPC list operations
//
gBS->RaiseTPL (TPL_HIGH_LEVEL);
//
// Add the invoked DPC entry to the DPC free list
//
InsertTailList (&mDpcEntryFreeList, &DpcEntry->ListEntry);
}
}
}
//
// Restore the original TPL level when this function was called
//
gBS->RestoreTPL (OriginalTpl);
return ReturnStatus;
}
/**
The entry point for DPC driver which installs the EFI_DPC_PROTOCOL onto a new handle.
@param ImageHandle The image handle of the driver.
@param SystemTable The system table.
@retval EFI_SUCCES The DPC queues were initialized and the EFI_DPC_PROTOCOL was
installed onto a new handle.
@retval Others Failed to install EFI_DPC_PROTOCOL.
**/
EFI_STATUS
EFIAPI
DpcDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINTN Index;
//
// ASSERT() if the EFI_DPC_PROTOCOL is already present in the handle database
//
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiDpcProtocolGuid);
//
// Initialize the DPC queue for all possible TPL values
//
for (Index = 0; Index <= TPL_HIGH_LEVEL; Index++) {
InitializeListHead (&mDpcQueue[Index]);
}
//
// Install the EFI_DPC_PROTOCOL instance onto a new handle
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mDpcHandle,
&gEfiDpcProtocolGuid,
&mDpc,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@@ -1,80 +0,0 @@
/** @file
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
Dpc.h
Abstract:
**/
#ifndef _DPC_H_
#define _DPC_H_
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Protocol/Dpc.h>
//
// Internal data struture for managing DPCs. A DPC entry is either on the free
// list or on a DPC queue at a specific EFI_TPL.
//
typedef struct {
LIST_ENTRY ListEntry;
EFI_DPC_PROCEDURE DpcProcedure;
VOID *DpcContext;
} DPC_ENTRY;
/**
Add a Deferred Procedure Call to the end of the DPC queue.
@param This Protocol instance pointer.
@param DpcTpl The EFI_TPL that the DPC should be invoked.
@param DpcProcedure Pointer to the DPC's function.
@param DpcContext Pointer to the DPC's context. Passed to DpcProcedure
when DpcProcedure is invoked.
@retval EFI_SUCCESS The DPC was queued.
@retval EFI_INVALID_PARAMETER DpcTpl is not a valid EFI_TPL.
@retval EFI_INVALID_PARAMETER DpcProcedure is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
add the DPC to the queue.
**/
EFI_STATUS
EFIAPI
DpcQueueDpc (
IN EFI_DPC_PROTOCOL *This,
IN EFI_TPL DpcTpl,
IN EFI_DPC_PROCEDURE DpcProcedure,
IN VOID *DpcContext OPTIONAL
);
/**
Dispatch the queue of DPCs. ALL DPCs that have been queued with a DpcTpl
value greater than or equal to the current TPL are invoked in the order that
they were queued. DPCs with higher DpcTpl values are invoked before DPCs with
lower DpcTpl values.
@param This Protocol instance pointer.
@retval EFI_SUCCESS One or more DPCs were invoked.
@retval EFI_NOT_FOUND No DPCs were invoked.
**/
EFI_STATUS
EFIAPI
DpcDispatchDpc (
IN EFI_DPC_PROTOCOL *This
);
#endif

View File

@@ -1,46 +0,0 @@
## @file
# This module produces Deferred Procedure Call Protocol.
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DpcDxe
MODULE_UNI_FILE = DpcDxe.uni
FILE_GUID = A210F973-229D-4f4d-AA37-9895E6C9EABA
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = DpcDriverEntryPoint
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
[Sources]
Dpc.c
Dpc.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
UefiDriverEntryPoint
BaseLib
DebugLib
UefiBootServicesTableLib
MemoryAllocationLib
[Protocols]
gEfiDpcProtocolGuid ## PRODUCES
[Depex]
TRUE
[UserExtensions.TianoCore."ExtraFiles"]
DpcDxeExtra.uni

View File

@@ -1,16 +0,0 @@
// /** @file
// This module produces Deferred Procedure Call Protocol.
//
// This module produces Deferred Procedure Call Protocol.
//
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Produces Deferred Procedure Call Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces Deferred Procedure Call Protocol."

View File

@@ -1,14 +0,0 @@
// /** @file
// DpcDxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"Deferred Procedure Call DXE Driver"

View File

@@ -1,428 +0,0 @@
/** @file
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Ip4ComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Ip4ComponentNameGetControllerName (
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
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIp4ComponentName = {
Ip4ComponentNameGetDriverName,
Ip4ComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIp4ComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ip4ComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ip4ComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIp4DriverNameTable[] = {
{
"eng;en",
L"IP4 Network Service Driver"
},
{
NULL,
NULL
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIp4ControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Ip4ComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mIp4DriverNameTable,
DriverName,
(BOOLEAN)(This == &gIp4ComponentName)
);
}
/**
Update the component name for the IP4 child handle.
@param Ip4[in] A pointer to the EFI_IP4_PROTOCOL.
@retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
@retval EFI_INVALID_PARAMETER The input parameter is invalid.
**/
EFI_STATUS
UpdateName (
IN EFI_IP4_PROTOCOL *Ip4
)
{
EFI_STATUS Status;
CHAR16 HandleName[80];
EFI_IP4_MODE_DATA Ip4ModeData;
if (Ip4 == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Format the child name into the string buffer as:
// IPv4 (SrcIP=127.0.0.1, DestIP=127.0.0.1)
//
Status = Ip4->GetModeData (Ip4, &Ip4ModeData, NULL, NULL);
if (EFI_ERROR (Status)) {
return Status;
}
if (!Ip4ModeData.IsStarted || !Ip4ModeData.IsConfigured) {
UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (Not started)");
} else {
UnicodeSPrint (HandleName, sizeof (HandleName),
L"IPv4 (SrcIP=%d.%d.%d.%d)",
Ip4ModeData.ConfigData.StationAddress.Addr[0],
Ip4ModeData.ConfigData.StationAddress.Addr[1],
Ip4ModeData.ConfigData.StationAddress.Addr[2],
Ip4ModeData.ConfigData.StationAddress.Addr[3]
);
}
if (gIp4ControllerNameTable != NULL) {
FreeUnicodeStringTable (gIp4ControllerNameTable);
gIp4ControllerNameTable = NULL;
}
Status = AddUnicodeString2 (
"eng",
gIp4ComponentName.SupportedLanguages,
&gIp4ControllerNameTable,
HandleName,
TRUE
);
if (EFI_ERROR (Status)) {
return Status;
}
return AddUnicodeString2 (
"en",
gIp4ComponentName2.SupportedLanguages,
&gIp4ControllerNameTable,
HandleName,
FALSE
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Ip4ComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_IP4_PROTOCOL *Ip4;
//
// Only provide names for child handles.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver produced ChildHandle
//
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEfiManagedNetworkProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Retrieve an instance of a produced protocol from ChildHandle
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiIp4ProtocolGuid,
(VOID **)&Ip4,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Update the component name for this child handle.
//
Status = UpdateName (Ip4);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
gIp4ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gIp4ComponentName)
);
}

View File

@@ -1,306 +0,0 @@
/** @file
Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
/**
Return the cast type (Unicast/Boradcast) specific to an
interface. All the addresses are host byte ordered.
@param[in] IpAddr The IP address to classify in host byte order
@param[in] IpIf The interface that IpAddr received from
@return The cast type of this IP address specific to the interface.
@retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
@retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the
interface
@retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
@retval 0 Otherwise.
**/
INTN
Ip4GetNetCast (
IN IP4_ADDR IpAddr,
IN IP4_INTERFACE *IpIf
)
{
if (IpAddr == IpIf->Ip) {
return IP4_LOCAL_HOST;
} else if (IpAddr == IpIf->SubnetBrdcast) {
return IP4_SUBNET_BROADCAST;
} else if (IpAddr == IpIf->NetBrdcast) {
return IP4_NET_BROADCAST;
}
return 0;
}
/**
Find the cast type of the packet related to the local host.
This isn't the same as link layer cast type. For example, DHCP
server may send local broadcast to the local unicast MAC.
@param[in] IpSb The IP4 service binding instance that received the
packet
@param[in] Dst The destination address in the packet (host byte
order)
@param[in] Src The source address in the packet (host byte order)
@return The cast type for the Dst, it will return on the first non-promiscuous
cast type to a configured interface. If the packet doesn't match any of
the interface, multicast address and local broadcast address are checked.
**/
INTN
Ip4GetHostCast (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Dst,
IN IP4_ADDR Src
)
{
LIST_ENTRY *Entry;
IP4_INTERFACE *IpIf;
INTN Type;
INTN Class;
Type = 0;
if (IpSb->MnpConfigData.EnablePromiscuousReceive) {
Type = IP4_PROMISCUOUS;
}
//
// Go through the interface list of the IP service, most likely.
//
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
//
// Skip the unconfigured interface and invalid source address:
// source address can't be broadcast.
//
if (!IpIf->Configured || IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {
continue;
}
if ((Class = Ip4GetNetCast (Dst, IpIf)) > Type) {
return Class;
}
}
//
// If it is local broadcast address. The source address must
// be a unicast address on one of the direct connected network.
// If it is a multicast address, accept it only if we are in
// the group.
//
if (Dst == IP4_ALLONE_ADDRESS) {
IpIf = Ip4FindNet (IpSb, Src);
if (IpIf != NULL && !IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {
return IP4_LOCAL_BROADCAST;
}
} else if (IP4_IS_MULTICAST (Dst) && Ip4FindGroup (&IpSb->IgmpCtrl, Dst) != NULL) {
return IP4_MULTICAST;
}
return Type;
}
/**
Find an interface whose configured IP address is Ip.
@param[in] IpSb The IP4 service binding instance
@param[in] Ip The Ip address (host byte order) to find
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindInterface (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip
)
{
LIST_ENTRY *Entry;
IP4_INTERFACE *IpIf;
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
if (IpIf->Configured && (IpIf->Ip == Ip)) {
return IpIf;
}
}
return NULL;
}
/**
Find an interface that Ip is on that connected network.
@param[in] IpSb The IP4 service binding instance
@param[in] Ip The Ip address (host byte order) to find
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindNet (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip
)
{
LIST_ENTRY *Entry;
IP4_INTERFACE *IpIf;
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
if (IpIf->Configured && IP4_NET_EQUAL (Ip, IpIf->Ip, IpIf->SubnetMask)) {
return IpIf;
}
}
return NULL;
}
/**
Find an interface of the service with the same Ip/Netmask pair.
@param[in] IpSb Ip4 service binding instance
@param[in] Ip The Ip adress to find (host byte order)
@param[in] Netmask The network to find (host byte order)
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindStationAddress (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip,
IN IP4_ADDR Netmask
)
{
LIST_ENTRY *Entry;
IP4_INTERFACE *IpIf;
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
if (IpIf->Configured && (IpIf->Ip == Ip) && (IpIf->SubnetMask == Netmask)) {
return IpIf;
}
}
return NULL;
}
/**
Get the MAC address for a multicast IP address. Call
Mnp's McastIpToMac to find the MAC address in stead of
hard code the NIC to be Ethernet.
@param[in] Mnp The Mnp instance to get the MAC address.
@param[in] Multicast The multicast IP address to translate.
@param[out] Mac The buffer to hold the translated address.
@retval EFI_SUCCESS if the multicast IP is successfully translated to a
multicast MAC address.
@retval other Otherwise some error.
**/
EFI_STATUS
Ip4GetMulticastMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
IN IP4_ADDR Multicast,
OUT EFI_MAC_ADDRESS *Mac
)
{
EFI_IP_ADDRESS EfiIp;
EFI_IP4 (EfiIp.v4) = HTONL (Multicast);
return Mnp->McastIpToMac (Mnp, FALSE, &EfiIp, Mac);
}
/**
Convert the multibyte field in IP header's byter order.
In spite of its name, it can also be used to convert from
host to network byte order.
@param[in] Head The IP head to convert
@return Point to the converted IP head
**/
IP4_HEAD *
Ip4NtohHead (
IN IP4_HEAD *Head
)
{
Head->TotalLen = NTOHS (Head->TotalLen);
Head->Id = NTOHS (Head->Id);
Head->Fragment = NTOHS (Head->Fragment);
Head->Src = NTOHL (Head->Src);
Head->Dst = NTOHL (Head->Dst);
return Head;
}
/**
Validate that Ip/Netmask pair is OK to be used as station
address. Only continuous netmasks are supported. and check
that StationAddress is a unicast address on the newtwork.
@param[in] Ip The IP address to validate.
@param[in] Netmask The netmaks of the IP.
@retval TRUE The Ip/Netmask pair is valid.
@retval FALSE The Ip/Netmask pair is invalid.
**/
BOOLEAN
Ip4StationAddressValid (
IN IP4_ADDR Ip,
IN IP4_ADDR Netmask
)
{
//
// Only support the station address with 0.0.0.0/0 to enable DHCP client.
//
if (Netmask == IP4_ALLZERO_ADDRESS) {
return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);
}
//
// Only support the continuous net masks
//
if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {
return FALSE;
}
//
// Station address can't be class D or class E address
//
if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {
return FALSE;
}
return NetIp4IsUnicast (Ip, Netmask);
}

View File

@@ -1,217 +0,0 @@
/** @file
Common definition for IP4.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_COMMON_H__
#define __EFI_IP4_COMMON_H__
typedef struct _IP4_INTERFACE IP4_INTERFACE;
typedef struct _IP4_PROTOCOL IP4_PROTOCOL;
typedef struct _IP4_SERVICE IP4_SERVICE;
#define IP4_ETHER_PROTO 0x0800
//
// The packet is received as link level broadcast/multicast/promiscuous.
//
#define IP4_LINK_BROADCAST 0x00000001
#define IP4_LINK_MULTICAST 0x00000002
#define IP4_LINK_PROMISC 0x00000004
//
// IP4 address cast type classfication. Keep it true that any
// type bigger than or equal to LOCAL_BROADCAST is broadcast.
//
#define IP4_PROMISCUOUS 1
#define IP4_LOCAL_HOST 2
#define IP4_MULTICAST 3
#define IP4_LOCAL_BROADCAST 4 // Destination is 255.255.255.255
#define IP4_SUBNET_BROADCAST 5
#define IP4_NET_BROADCAST 6
//
// IP4 header flags
//
#define IP4_HEAD_DF_MASK 0x4000
#define IP4_HEAD_MF_MASK 0x2000
#define IP4_HEAD_OFFSET_MASK 0x1fff
#define IP4_ALLZERO_ADDRESS 0x00000000u
#define IP4_ALLONE_ADDRESS 0xFFFFFFFFu
#define IP4_ALLSYSTEM_ADDRESS 0xE0000001u
#define IP4_ALLROUTER_ADDRESS 0xE0000002u
///
/// Compose the fragment field to be used in the IP4 header.
///
#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \
((UINT16)(((Df) ? IP4_HEAD_DF_MASK : 0) | ((Mf) ? IP4_HEAD_MF_MASK : 0) | (((Offset) >> 3) & IP4_HEAD_OFFSET_MASK)))
#define IP4_LAST_FRAGMENT(FragmentField) \
(((FragmentField) & IP4_HEAD_MF_MASK) == 0)
#define IP4_FIRST_FRAGMENT(FragmentField) \
((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
#define IP4_DO_NOT_FRAGMENT(FragmentField) \
((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))
#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)
///
/// Conver the Microsecond to second. IP transmit/receive time is
/// in the unit of microsecond. IP ticks once per second.
///
#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
/**
Return the cast type (Unicast/Boradcast) specific to an
interface. All the addresses are host byte ordered.
@param[in] IpAddr The IP address to classify in host byte order
@param[in] IpIf The interface that IpAddr received from
@return The cast type of this IP address specific to the interface.
@retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
@retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the
interface
@retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
@retval 0 Otherwise.
**/
INTN
Ip4GetNetCast (
IN IP4_ADDR IpAddr,
IN IP4_INTERFACE *IpIf
);
/**
Find the cast type of the packet related to the local host.
This isn't the same as link layer cast type. For example, DHCP
server may send local broadcast to the local unicast MAC.
@param[in] IpSb The IP4 service binding instance that received the
packet
@param[in] Dst The destination address in the packet (host byte
order)
@param[in] Src The source address in the packet (host byte order)
@return The cast type for the Dst, it will return on the first non-promiscuous
cast type to a configured interface. If the packet doesn't match any of
the interface, multicast address and local broadcast address are checked.
**/
INTN
Ip4GetHostCast (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Dst,
IN IP4_ADDR Src
);
/**
Find an interface whose configured IP address is Ip.
@param[in] IpSb The IP4 service binding instance
@param[in] Ip The Ip address (host byte order) to find
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindInterface (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip
);
/**
Find an interface that Ip is on that connected network.
@param[in] IpSb The IP4 service binding instance
@param[in] Ip The Ip address (host byte order) to find
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindNet (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip
);
/**
Find an interface of the service with the same Ip/Netmask pair.
@param[in] IpSb Ip4 service binding instance
@param[in] Ip The Ip adress to find (host byte order)
@param[in] Netmask The network to find (host byte order)
@return The IP4_INTERFACE point if found, otherwise NULL
**/
IP4_INTERFACE *
Ip4FindStationAddress (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Ip,
IN IP4_ADDR Netmask
);
/**
Get the MAC address for a multicast IP address. Call
Mnp's McastIpToMac to find the MAC address in stead of
hard code the NIC to be Ethernet.
@param[in] Mnp The Mnp instance to get the MAC address.
@param[in] Multicast The multicast IP address to translate.
@param[out] Mac The buffer to hold the translated address.
@retval EFI_SUCCESS if the multicast IP is successfully translated to a
multicast MAC address.
@retval other Otherwise some error.
**/
EFI_STATUS
Ip4GetMulticastMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
IN IP4_ADDR Multicast,
OUT EFI_MAC_ADDRESS *Mac
);
/**
Convert the multibyte field in IP header's byter order.
In spite of its name, it can also be used to convert from
host to network byte order.
@param[in] Head The IP head to convert
@return Point to the converted IP head
**/
IP4_HEAD *
Ip4NtohHead (
IN IP4_HEAD *Head
);
/**
Validate that Ip/Netmask pair is OK to be used as station
address. Only continuous netmasks are supported. and check
that StationAddress is a unicast address on the newtwork.
@param[in] Ip The IP address to validate.
@param[in] Netmask The netmaks of the IP.
@retval TRUE The Ip/Netmask pair is valid.
@retval FALSE The Ip/Netmask pair is invalid.
**/
BOOLEAN
Ip4StationAddressValid (
IN IP4_ADDR Ip,
IN IP4_ADDR Netmask
);
#endif

View File

@@ -1,94 +0,0 @@
/** @file
Vfr file for IP4Dxe.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4NvData.h"
#define EFI_NETWORK_DEVICE_CLASS 0x04
formset
guid = IP4_CONFIG2_NVDATA_GUID,
title = STRING_TOKEN(STR_IP4_CONFIG2_FORM_TITLE),
help = STRING_TOKEN(STR_IP4_CONFIG2_FORM_HELP),
class = EFI_NETWORK_DEVICE_CLASS,
subclass = 0x03,
varstore IP4_CONFIG2_IFR_NVDATA,
name = IP4_CONFIG2_IFR_NVDATA,
guid = IP4_CONFIG2_NVDATA_GUID;
form formid = FORMID_MAIN_FORM,
title = STRING_TOKEN(STR_IP4_DEVICE_FORM_TITLE);
checkbox varid = IP4_CONFIG2_IFR_NVDATA.Configure,
prompt = STRING_TOKEN(STR_IP4_CONFIGURE),
help = STRING_TOKEN(STR_IP4_CONFIGURE_HELP),
flags = INTERACTIVE,
key = KEY_ENABLE,
endcheckbox;
suppressif ideqval IP4_CONFIG2_IFR_NVDATA.Configure == 0x00;
checkbox varid = IP4_CONFIG2_IFR_NVDATA.DhcpEnable,
prompt = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
help = STRING_TOKEN(STR_IP4_ENABLE_DHCP),
flags = INTERACTIVE,
key = KEY_DHCP_ENABLE,
endcheckbox;
endif;
suppressif ideqval IP4_CONFIG2_IFR_NVDATA.DhcpEnable == 0x01 OR ideqval IP4_CONFIG2_IFR_NVDATA.Configure == 0x00;
string varid = IP4_CONFIG2_IFR_NVDATA.StationAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_IP_ADDRESS),
help = STRING_TOKEN(STR_IP4_IP_ADDRESS_HELP),
flags = INTERACTIVE,
key = KEY_LOCAL_IP,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = IP4_CONFIG2_IFR_NVDATA.SubnetMask,
prompt = STRING_TOKEN(STR_IP4_LOCAL_MASK),
help = STRING_TOKEN(STR_IP4_MASK_HELP),
flags = INTERACTIVE,
key = KEY_SUBNET_MASK,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = IP4_CONFIG2_IFR_NVDATA.GatewayAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_GATEWAY),
help = STRING_TOKEN(STR_IP4_GATEWAY_HELP),
flags = INTERACTIVE,
key = KEY_GATE_WAY,
minsize = IP_MIN_SIZE,
maxsize = IP_MAX_SIZE,
endstring;
string varid = IP4_CONFIG2_IFR_NVDATA.DnsAddress,
prompt = STRING_TOKEN(STR_IP4_LOCAL_DNS),
help = STRING_TOKEN(STR_IP4_DNS_HELP),
flags = INTERACTIVE,
key = KEY_DNS,
minsize = IP_MIN_SIZE,
maxsize = ADDRESS_STR_MAX_SIZE,
endstring;
endif;
subtitle text = STRING_TOKEN(STR_NULL);
text
help = STRING_TOKEN(STR_SAVE_CHANGES),
text = STRING_TOKEN(STR_SAVE_CHANGES),
flags = INTERACTIVE,
key = KEY_SAVE_CHANGES;
endform;
endformset;

File diff suppressed because it is too large Load Diff

View File

@@ -1,294 +0,0 @@
/** @file
Definitions for EFI IPv4 Configuration II Protocol implementation.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __IP4_CONFIG2_IMPL_H__
#define __IP4_CONFIG2_IMPL_H__
#define IP4_CONFIG2_INSTANCE_SIGNATURE SIGNATURE_32 ('I', 'P', 'C', '2')
#define IP4_FORM_CALLBACK_INFO_SIGNATURE SIGNATURE_32 ('I', 'F', 'C', 'I')
#define IP4_CONFIG2_VARIABLE_ATTRIBUTE (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS)
#define DATA_ATTRIB_SIZE_FIXED 0x1
#define DATA_ATTRIB_VOLATILE 0x2
#define DATA_ATTRIB_SET(Attrib, Bits) (BOOLEAN)((Attrib) & (Bits))
#define SET_DATA_ATTRIB(Attrib, Bits) ((Attrib) |= (Bits))
#define REMOVE_DATA_ATTRIB(Attrib, Bits) ((Attrib) &= (~Bits))
typedef struct _IP4_CONFIG2_INSTANCE IP4_CONFIG2_INSTANCE;
#define IP4_CONFIG2_INSTANCE_FROM_PROTOCOL(Proto) \
CR ((Proto), \
IP4_CONFIG2_INSTANCE, \
Ip4Config2, \
IP4_CONFIG2_INSTANCE_SIGNATURE \
)
#define IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE(Instance) \
CR ((Instance), \
IP4_SERVICE, \
Ip4Config2Instance, \
IP4_SERVICE_SIGNATURE \
)
#define IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Callback) \
CR ((Callback), \
IP4_CONFIG2_INSTANCE, \
CallbackInfo, \
IP4_CONFIG2_INSTANCE_SIGNATURE \
)
#define IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(ConfigAccess) \
CR ((ConfigAccess), \
IP4_FORM_CALLBACK_INFO, \
HiiConfigAccessProtocol, \
IP4_FORM_CALLBACK_INFO_SIGNATURE \
)
/**
The prototype of work function for EfiIp4Config2SetData().
@param[in] Instance The pointer to the IP4 config2 instance data.
@param[in] DataSize In bytes, the size of the buffer pointed to by Data.
@param[in] Data The data buffer to set.
@retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
8 bytes.
@retval EFI_SUCCESS The specified configuration data for the EFI IPv4
network stack was set successfully.
**/
typedef
EFI_STATUS
(*IP4_CONFIG2_SET_DATA) (
IN IP4_CONFIG2_INSTANCE *Instance,
IN UINTN DataSize,
IN VOID *Data
);
/**
The prototype of work function for EfiIp4Config2GetData().
@param[in] Instance The pointer to the IP4 config2 instance data.
@param[in, out] DataSize On input, in bytes, the size of Data. On output, in
bytes, the size of buffer required to store the specified
configuration data.
@param[in] Data The data buffer in which the configuration data is returned.
Ignored if DataSize is ZERO.
@retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
configuration data, and the required size is
returned in DataSize.
@retval EFI_SUCCESS The specified configuration data was obtained successfully.
**/
typedef
EFI_STATUS
(*IP4_CONFIG2_GET_DATA) (
IN IP4_CONFIG2_INSTANCE *Instance,
IN OUT UINTN *DataSize,
IN VOID *Data OPTIONAL
);
typedef union {
VOID *Ptr;
EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;
EFI_IP4_CONFIG2_POLICY *Policy;
EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress;
EFI_IPv4_ADDRESS *Gateway;
EFI_IPv4_ADDRESS *DnsServers;
} IP4_CONFIG2_DATA;
typedef struct {
IP4_CONFIG2_SET_DATA SetData;
IP4_CONFIG2_GET_DATA GetData;
EFI_STATUS Status;
UINT8 Attribute;
NET_MAP EventMap;
IP4_CONFIG2_DATA Data;
UINTN DataSize;
} IP4_CONFIG2_DATA_ITEM;
typedef struct {
UINT16 Offset;
UINT32 DataSize;
EFI_IP4_CONFIG2_DATA_TYPE DataType;
} IP4_CONFIG2_DATA_RECORD;
#pragma pack(1)
//
// heap data that contains the data for each data record.
//
// EFI_IP4_CONFIG2_POLICY Policy;
// UINT32 ManualaddressCount;
// UINT32 GatewayCount;
// UINT32 DnsServersCount;
// EFI_IP4_CONFIG2_MANUAL_ADDRESS ManualAddress[];
// EFI_IPv4_ADDRESS Gateway[];
// EFI_IPv4_ADDRESS DnsServers[];
//
typedef struct {
UINT16 Checksum;
UINT16 DataRecordCount;
IP4_CONFIG2_DATA_RECORD DataRecord[1];
} IP4_CONFIG2_VARIABLE;
#pragma pack()
typedef struct {
EFI_IP4_CONFIG2_POLICY Policy; ///< manual or automatic
EFI_IP4_CONFIG2_MANUAL_ADDRESS *ManualAddress; ///< IP addresses
UINT32 ManualAddressCount; ///< IP addresses count
EFI_IPv4_ADDRESS *GatewayAddress; ///< Gateway address
UINT32 GatewayAddressCount; ///< Gateway address count
EFI_IPv4_ADDRESS *DnsAddress; ///< DNS server address
UINT32 DnsAddressCount; ///< DNS server address count
} IP4_CONFIG2_NVDATA;
typedef struct _IP4_FORM_CALLBACK_INFO {
UINT32 Signature;
EFI_HANDLE ChildHandle;
EFI_HII_CONFIG_ACCESS_PROTOCOL HiiConfigAccessProtocol;
EFI_DEVICE_PATH_PROTOCOL *HiiVendorDevicePath;
EFI_HII_HANDLE RegisteredHandle;
} IP4_FORM_CALLBACK_INFO;
struct _IP4_CONFIG2_INSTANCE {
UINT32 Signature;
BOOLEAN Configured;
LIST_ENTRY Link;
UINT16 IfIndex;
EFI_IP4_CONFIG2_PROTOCOL Ip4Config2;
EFI_IP4_CONFIG2_INTERFACE_INFO InterfaceInfo;
EFI_IP4_CONFIG2_POLICY Policy;
IP4_CONFIG2_DATA_ITEM DataItem[Ip4Config2DataTypeMaximum];
EFI_EVENT Dhcp4SbNotifyEvent;
VOID *Registration;
EFI_HANDLE Dhcp4Handle;
EFI_DHCP4_PROTOCOL *Dhcp4;
BOOLEAN DhcpSuccess;
BOOLEAN OtherInfoOnly;
EFI_EVENT Dhcp4Event;
UINT32 FailedIaAddressCount;
EFI_IPv4_ADDRESS *DeclineAddress;
UINT32 DeclineAddressCount;
IP4_FORM_CALLBACK_INFO CallbackInfo;
IP4_CONFIG2_NVDATA Ip4NvData;
};
//
// Configure the DHCP to request the routers and netmask
// from server. The DHCP4_TAG_NETMASK is included in Head.
//
#pragma pack(1)
typedef struct {
EFI_DHCP4_PACKET_OPTION Head;
UINT8 Route;
UINT8 Dns;
} IP4_CONFIG2_DHCP4_OPTION;
#pragma pack()
/**
Read the configuration data from variable storage according to the VarName and
gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the
data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
configuration data to IP4_CONFIG2_INSTANCE.
@param[in] VarName The pointer to the variable name
@param[in, out] Instance The pointer to the IP4 config2 instance data.
@retval EFI_NOT_FOUND The variable can not be found or already corrupted.
@retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
@retval EFI_SUCCESS The configuration data was retrieved successfully.
**/
EFI_STATUS
Ip4Config2ReadConfigData (
IN CHAR16 *VarName,
IN OUT IP4_CONFIG2_INSTANCE *Instance
);
/**
Start the DHCP configuration for this IP service instance.
It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the
DHCP configuration.
@param[in] Instance The IP4 config2 instance to configure.
@retval EFI_SUCCESS The auto configuration is successfully started.
@retval Others Failed to start auto configuration.
**/
EFI_STATUS
Ip4StartAutoConfig (
IN IP4_CONFIG2_INSTANCE *Instance
);
/**
Initialize an IP4_CONFIG2_INSTANCE.
@param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
@retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.
**/
EFI_STATUS
Ip4Config2InitInstance (
OUT IP4_CONFIG2_INSTANCE *Instance
);
/**
Release an IP4_CONFIG2_INSTANCE.
@param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.
**/
VOID
Ip4Config2CleanInstance (
IN OUT IP4_CONFIG2_INSTANCE *Instance
);
/**
Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.
@param Event The event that is signalled.
@param Context The IP4 service binding instance.
**/
VOID
EFIAPI
Ip4AutoReconfigCallBack (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.
@param[in, out] Instance The buffer of IP4 config2 instance to be freed.
@retval EFI_SUCCESS The child was successfully destroyed.
@retval Others Failed to destroy the child.
**/
EFI_STATUS
Ip4Config2DestroyDhcp4 (
IN OUT IP4_CONFIG2_INSTANCE *Instance
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,45 +0,0 @@
/** @file
The header file of IP4Config2Nv.c
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _IP4_CONFIG2NV_H_
#define _IP4_CONFIG2NV_H_
#include "Ip4Impl.h"
extern UINT8 Ip4Config2Bin[];
extern UINT8 Ip4DxeStrings[];
#define NIC_ITEM_CONFIG_SIZE (sizeof (IP4_CONFIG2_INSTANCE) + (sizeof (EFI_IPv4_ADDRESS) * MAX_IP4_CONFIG_DNS))
/**
Install HII Config Access protocol for network device and allocate resource.
@param[in, out] Instance The IP4 config2 Instance.
@retval EFI_SUCCESS The HII Config Access protocol is installed.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
@retval Others Other errors as indicated.
**/
EFI_STATUS
Ip4Config2FormInit (
IN OUT IP4_CONFIG2_INSTANCE *Instance
);
/**
Uninstall the HII Config Access protocol for network devices and free up the resources.
@param[in, out] Instance The IP4 config2 instance to unload a form.
**/
VOID
Ip4Config2FormUnload (
IN OUT IP4_CONFIG2_INSTANCE *Instance
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,184 +0,0 @@
/** @file
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_DRIVER_H__
#define __EFI_IP4_DRIVER_H__
#include <Protocol/ServiceBinding.h>
extern EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gIp4ComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gIp4ComponentName2;
extern EFI_UNICODE_STRING_TABLE *gIp4ControllerNameTable;
typedef struct {
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
} IP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
//
// Function prototype for the driver's entry point
//
/**
This is the declaration of an EFI image entry point. This entry point is
the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
both device drivers and bus drivers.
The entry point for IP4 driver which install the driver
binding and component name protocol on its image.
@param[in] ImageHandle The firmware allocated handle for the UEFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
**/
EFI_STATUS
EFIAPI
Ip4DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
//
// Function prototypes for the Drivr Binding Protocol
//
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Ip4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL * This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make
drivers as small as possible, there are a few calling restrictions for
this service. ConnectController() must follow these
calling restrictions. If any other agent wishes to call Start() it
must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to
@param[in] RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS 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
Ip4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL * This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to
make drivers as small as possible, there are a few calling
restrictions for this service. DisconnectController()
must follow these calling restrictions. If any other agent wishes
to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
of children is zero stop the entire bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
Ip4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// Function prototypes for the ServiceBinding Protocol
//
/**
Creates a child handle and installs a protocol.
The CreateChild() function installs a protocol on ChildHandle.
If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Pointer to the handle of the child to create. If it is NULL,
then a new handle is created. If it is a pointer to an existing UEFI handle,
then the protocol is added to the existing UEFI handle.
@retval EFI_SUCCES The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
the child
@retval other The child handle was not created
**/
EFI_STATUS
EFIAPI
Ip4ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
);
/**
Destroys a child handle with a protocol installed on it.
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
last protocol on ChildHandle, then ChildHandle is destroyed.
@param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
@param ChildHandle Handle of the child to destroy
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
@retval EFI_INVALID_PARAMETER Child handle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
because its services are being used.
@retval other The child handle was not destroyed
**/
EFI_STATUS
EFIAPI
Ip4ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@@ -1,109 +0,0 @@
## @file
# This module produces EFI IPv4 Protocol and EFI IPv4 Service Binding Protocol.
#
# This module produces EFI IPv4 Protocol upon EFI MNP Protocol and EFI ARP Protocol,
# to provide basic network IPv4 packet I/O services, which includes support for a
# subset of the Internet Control Message Protocol (ICMP) and may include support for
# the Internet Group Management Protocol (IGMP).
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Ip4Dxe
MODULE_UNI_FILE = Ip4Dxe.uni
FILE_GUID = 9FB1A1F3-3B71-4324-B39A-745CBB015FFF
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = Ip4DriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
# DRIVER_BINDING = gIp4DriverBinding
# COMPONENT_NAME = gIp4ComponentName
# COMPONENT_NAME2 = gIp4ComponentName2
#
[Sources]
Ip4Driver.c
Ip4Option.h
Ip4Route.h
Ip4If.c
Ip4Igmp.h
Ip4Output.c
Ip4Icmp.c
Ip4Igmp.c
Ip4Impl.c
Ip4Common.h
Ip4Impl.h
Ip4Driver.h
Ip4Common.c
Ip4If.h
Ip4Option.c
Ip4Output.h
ComponentName.c
Ip4Input.h
Ip4Route.c
Ip4Icmp.h
Ip4Input.c
Ip4Config2Impl.c
Ip4Config2Impl.h
Ip4Config2.vfr
Ip4DxeStrings.uni
Ip4NvData.h
Ip4Config2Nv.h
Ip4Config2Nv.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
UefiLib
BaseLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib
DebugLib
NetLib
DpcLib
HiiLib
PrintLib
DevicePathLib
UefiHiiServicesLib
[Protocols]
## BY_START
## UNDEFINED # variable
gEfiIp4ServiceBindingProtocolGuid
gEfiIp4ProtocolGuid ## BY_START
gEfiManagedNetworkServiceBindingProtocolGuid ## TO_START
gEfiManagedNetworkProtocolGuid ## TO_START
gEfiArpServiceBindingProtocolGuid ## TO_START
gEfiIp4Config2ProtocolGuid ## BY_START
gEfiArpProtocolGuid ## TO_START
gEfiDhcp4ServiceBindingProtocolGuid ## TO_START
gEfiDhcp4ProtocolGuid ## TO_START
gEfiIpSec2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiHiiConfigAccessProtocolGuid ## BY_START
gEfiDevicePathProtocolGuid ## TO_START
[Guids]
## SOMETIMES_CONSUMES ## GUID # HiiIsConfigHdrMatch EFI_NIC_IP4_CONFIG_VARIABLE
## SOMETIMES_PRODUCES ## GUID # HiiConstructConfigHdr EFI_NIC_IP4_CONFIG_VARIABLE
## SOMETIMES_PRODUCES ## GUID # HiiGetBrowserData EFI_NIC_IP4_CONFIG_VARIABLE
## SOMETIMES_CONSUMES ## HII
gIp4Config2NvDataGuid
[UserExtensions.TianoCore."ExtraFiles"]
Ip4DxeExtra.uni

View File

@@ -1,19 +0,0 @@
// /** @file
// This module produces EFI IPv4 Protocol and EFI IPv4 Service Binding Protocol.
//
// This module produces EFI IPv4 Protocol upon EFI MNP Protocol and EFI ARP Protocol,
// to provide basic network IPv4 packet I/O services, which includes support for a
// subset of the Internet Control Message Protocol (ICMP) and may include support for
// the Internet Group Management Protocol (IGMP).
//
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Produces EFI IPv4 Protocol and EFI IPv4 Service Binding Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI IPv4 Protocol upon EFI MNP Protocol and EFI ARP Protocol to provide basic network IPv4 packet I/O services, which includes support for a subset of the Internet Control Message Protocol (ICMP), and may include support for the Internet Group Management Protocol (IGMP)."

View File

@@ -1,14 +0,0 @@
// /** @file
// Ip4Dxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"IP v4 DXE Driver"

View File

@@ -1,30 +0,0 @@
// /** @file
// String definitions for Ip4Config2 formset
// Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
//**/
/=#
#langdef en-US "English"
#string STR_IP4_CONFIG2_FORM_TITLE #language en-US "IPv4 Network Configuration"
#string STR_IP4_CONFIG2_FORM_HELP #language en-US "Configure network parameters."
#string STR_IP4_DEVICE_FORM_TITLE #language en-US ""
#string STR_IP4_DEVICE_FORM_HELP #language en-US ""
#string STR_IP4_CONFIGURE #language en-US "Configured"
#string STR_IP4_CONFIGURE_HELP #language en-US "Indicate whether network address configured successfully or not."
#string STR_IP4_ENABLE_DHCP #language en-US "Enable DHCP"
#string STR_IP4_LOCAL_IP_ADDRESS #language en-US "Local IP Address"
#string STR_IP4_IP_ADDRESS_HELP #language en-US "Enter IP address in dotted-decimal notation. Example: 192.168.10.12\r\n"
#string STR_IP4_LOCAL_MASK #language en-US "Local NetMask"
#string STR_IP4_MASK_HELP #language en-US "Enter NetMask in dotted-decimal notation. Example: 255.255.255.0\r\n"
#string STR_IP4_LOCAL_GATEWAY #language en-US "Local Gateway"
#string STR_IP4_GATEWAY_HELP #language en-US "Enter Gateway in dotted-decimal notation. Example: 192.168.10.1\r\n"
#string STR_IP4_LOCAL_DNS #language en-US "Local DNS Servers"
#string STR_IP4_DNS_HELP #language en-US "Enter DNS Servers in dotted-decimal notation. Example: 192.168.10.8 192.168.10.9\r\n"
#string STR_SAVE_CHANGES #language en-US "Save Changes and Exit"
#string STR_NULL #language en-US ""

View File

@@ -1,363 +0,0 @@
/** @file
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
IP4_ICMP_CLASS
mIcmpClass[] = {
{ICMP_ECHO_REPLY, ICMP_QUERY_MESSAGE },
{1, ICMP_INVALID_MESSAGE},
{2, ICMP_INVALID_MESSAGE},
{ICMP_DEST_UNREACHABLE, ICMP_ERROR_MESSAGE },
{ICMP_SOURCE_QUENCH, ICMP_ERROR_MESSAGE },
{ICMP_REDIRECT, ICMP_ERROR_MESSAGE },
{6, ICMP_INVALID_MESSAGE},
{7, ICMP_INVALID_MESSAGE},
{ICMP_ECHO_REQUEST, ICMP_QUERY_MESSAGE },
{9, ICMP_INVALID_MESSAGE},
{10, ICMP_INVALID_MESSAGE},
{ICMP_TIME_EXCEEDED, ICMP_ERROR_MESSAGE },
{ICMP_PARAMETER_PROBLEM, ICMP_ERROR_MESSAGE },
{ICMP_TIMESTAMP , ICMP_QUERY_MESSAGE },
{14, ICMP_INVALID_MESSAGE},
{ICMP_INFO_REQUEST , ICMP_QUERY_MESSAGE },
{ICMP_INFO_REPLY , ICMP_QUERY_MESSAGE },
};
EFI_IP4_ICMP_TYPE
mIp4SupportedIcmp[23] = {
{ICMP_ECHO_REPLY, ICMP_DEFAULT_CODE },
{ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACHABLE },
{ICMP_DEST_UNREACHABLE, ICMP_HOST_UNREACHABLE },
{ICMP_DEST_UNREACHABLE, ICMP_PROTO_UNREACHABLE },
{ICMP_DEST_UNREACHABLE, ICMP_PORT_UNREACHABLE },
{ICMP_DEST_UNREACHABLE, ICMP_FRAGMENT_FAILED },
{ICMP_DEST_UNREACHABLE, ICMP_SOURCEROUTE_FAILED },
{ICMP_DEST_UNREACHABLE, ICMP_NET_UNKNOWN },
{ICMP_DEST_UNREACHABLE, ICMP_HOST_UNKNOWN },
{ICMP_DEST_UNREACHABLE, ICMP_SOURCE_ISOLATED },
{ICMP_DEST_UNREACHABLE, ICMP_NET_PROHIBITED },
{ICMP_DEST_UNREACHABLE, ICMP_HOST_PROHIBITED },
{ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACHABLE_TOS },
{ICMP_DEST_UNREACHABLE, ICMP_HOST_UNREACHABLE_TOS},
{ICMP_SOURCE_QUENCH, ICMP_DEFAULT_CODE },
{ICMP_REDIRECT, ICMP_NET_REDIRECT },
{ICMP_REDIRECT, ICMP_HOST_REDIRECT },
{ICMP_REDIRECT, ICMP_NET_TOS_REDIRECT },
{ICMP_REDIRECT, ICMP_HOST_TOS_REDIRECT },
{ICMP_ECHO_REQUEST, ICMP_DEFAULT_CODE },
{ICMP_TIME_EXCEEDED, ICMP_TIMEOUT_IN_TRANSIT },
{ICMP_TIME_EXCEEDED, ICMP_TIMEOUT_REASSEMBLE },
{ICMP_PARAMETER_PROBLEM, ICMP_DEFAULT_CODE },
};
/**
Process the ICMP redirect. Find the instance then update
its route cache.
All kinds of redirect is treated as host redirect as
specified by RFC1122 3.3.1.2:
"Since the subnet mask appropriate to the destination
address is generally not known, a Network Redirect
message SHOULD be treated identically to a Host Redirect
message;"
@param[in] IpSb The IP4 service binding instance that received
the packet.
@param[in] Head The IP head of the received ICMPpacket.
@param[in] Packet The content of the ICMP redirect packet with IP
head removed.
@param[in] Icmp The buffer to store the ICMP error message if
something is wrong.
@retval EFI_INVALID_PARAMETER The parameter is invalid
@retval EFI_SUCCESS Successfully updated the route caches
**/
EFI_STATUS
Ip4ProcessIcmpRedirect (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet,
IN IP4_ICMP_ERROR_HEAD *Icmp
)
{
LIST_ENTRY *Entry;
IP4_PROTOCOL *Ip4Instance;
IP4_ROUTE_CACHE_ENTRY *CacheEntry;
IP4_INTERFACE *IpIf;
IP4_ADDR Gateway;
IP4_ADDR Src;
IP4_ADDR Dst;
//
// Find the interface whose IP address is the source of the
// orgianl IP packet.
//
IpIf = Ip4FindInterface (IpSb, NTOHL (Icmp->IpHead.Src));
Gateway = NTOHL (Icmp->Fourth);
//
// discard the packet if the new gateway address it specifies
// is not on the same connected net through which the Redirect
// arrived. (RFC1122 3.2.2.2).
//
if ((IpIf == NULL) || !IP4_NET_EQUAL (Gateway, IpIf->Ip, IpIf->SubnetMask)) {
NetbufFree (Packet);
return EFI_INVALID_PARAMETER;
}
//
// Update each IP child's route cache on the interface.
//
NET_LIST_FOR_EACH (Entry, &IpIf->IpInstances) {
Ip4Instance = NET_LIST_USER_STRUCT (Entry, IP4_PROTOCOL, AddrLink);
if (Ip4Instance->RouteTable == NULL) {
continue;
}
Dst = NTOHL (Icmp->IpHead.Dst);
Src = NTOHL (Icmp->IpHead.Src);
CacheEntry = Ip4FindRouteCache (Ip4Instance->RouteTable, Dst, Src);
//
// Only update the route cache's gateway if the source of the
// Redirect is the current first-hop gateway
//
if ((CacheEntry != NULL) && (NTOHL (Head->Src) == CacheEntry->NextHop)) {
CacheEntry->NextHop = Gateway;
}
}
NetbufFree (Packet);
return EFI_SUCCESS;
}
/**
Process the ICMP error packet. If it is an ICMP redirect packet,
update call Ip4ProcessIcmpRedirect to update the IP instance's
route cache, otherwise, deliver the packet to upper layer.
@param[in] IpSb The IP4 service that received the packet.
@param[in] Head The IP4 head of the ICMP error packet
@param[in] Packet The content of the ICMP error with IP4 head
removed.
@retval EFI_SUCCESS The ICMP error is processed successfully.
@retval EFI_INVALID_PARAMETER The packet is invalid
@retval Others Failed to process the packet.
**/
EFI_STATUS
Ip4ProcessIcmpError (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
)
{
IP4_ICMP_ERROR_HEAD Icmp;
if (Packet->TotalSize < sizeof (Icmp)) {
NetbufFree (Packet);
return EFI_INVALID_PARAMETER;
}
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
//
// If it is an ICMP redirect error, update the route cache
// as RFC1122. Otherwise, demultiplex it to IP instances.
//
if (Icmp.Head.Type == ICMP_REDIRECT) {
return Ip4ProcessIcmpRedirect (IpSb, Head, Packet, &Icmp);
}
IP4_GET_CLIP_INFO (Packet)->Status = EFI_ICMP_ERROR;
return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0);
}
/**
Replay an ICMP echo request.
@param[in] IpSb The IP4 service that receivd the packet
@param[in] Head The IP4 head of the ICMP error packet
@param[in] Packet The content of the ICMP error with IP4 head
removed.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
@retval EFI_SUCCESS The ICMP Echo request is successfully answered.
@retval Others Failed to answer the ICMP echo request.
**/
EFI_STATUS
Ip4IcmpReplyEcho (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
)
{
IP4_ICMP_QUERY_HEAD *Icmp;
NET_BUF *Data;
EFI_STATUS Status;
IP4_HEAD ReplyHead;
//
// make a copy the packet, it is really a bad idea to
// send the MNP's buffer back to MNP.
//
Data = NetbufDuplicate (Packet, NULL, IP4_MAX_HEADLEN);
if (Data == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}
//
// Change the ICMP type to echo reply, exchange the source
// and destination, then send it. The source is updated to
// use specific destination. See RFC1122. SRR/RR option
// update is omitted.
//
Icmp = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL);
ASSERT (Icmp != NULL);
Icmp->Head.Type = ICMP_ECHO_REPLY;
Icmp->Head.Checksum = 0;
Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize));
ReplyHead.Tos = 0;
ReplyHead.Fragment = 0;
ReplyHead.Ttl = 64;
ReplyHead.Protocol = EFI_IP_PROTO_ICMP;
ReplyHead.Src = 0;
//
// Ip4Output will select a source for us
//
ReplyHead.Dst = Head->Src;
Status = Ip4Output (
IpSb,
NULL,
Data,
&ReplyHead,
NULL,
0,
IP4_ALLZERO_ADDRESS,
Ip4SysPacketSent,
NULL
);
if (EFI_ERROR (Status)) {
NetbufFree (Data);
}
ON_EXIT:
NetbufFree (Packet);
return Status;
}
/**
Process the ICMP query message. If it is an ICMP echo
request, answer it. Otherwise deliver it to upper layer.
@param[in] IpSb The IP4 service that receivd the packet
@param[in] Head The IP4 head of the ICMP query packet
@param[in] Packet The content of the ICMP query with IP4 head
removed.
@retval EFI_INVALID_PARAMETER The packet is invalid
@retval EFI_SUCCESS The ICMP query message is processed
@retval Others Failed to process ICMP query.
**/
EFI_STATUS
Ip4ProcessIcmpQuery (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
)
{
IP4_ICMP_QUERY_HEAD Icmp;
if (Packet->TotalSize < sizeof (Icmp)) {
NetbufFree (Packet);
return EFI_INVALID_PARAMETER;
}
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
if (Icmp.Head.Type == ICMP_ECHO_REQUEST) {
return Ip4IcmpReplyEcho (IpSb, Head, Packet);
}
return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0);
}
/**
Handle the ICMP packet. First validate the message format,
then according to the message types, process it as query or
error packet.
@param[in] IpSb The IP4 service that receivd the packet.
@param[in] Head The IP4 head of the ICMP query packet.
@param[in] Packet The content of the ICMP query with IP4 head
removed.
@retval EFI_INVALID_PARAMETER The packet is malformated.
@retval EFI_SUCCESS The ICMP message is successfully processed.
@retval Others Failed to handle ICMP packet.
**/
EFI_STATUS
Ip4IcmpHandle (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
)
{
IP4_ICMP_HEAD Icmp;
UINT16 Checksum;
if (Packet->TotalSize < sizeof (Icmp)) {
goto DROP;
}
NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);
if (Icmp.Type > ICMP_TYPE_MAX) {
goto DROP;
}
Checksum = (UINT16) (~NetbufChecksum (Packet));
if ((Icmp.Checksum != 0) && (Checksum != 0)) {
goto DROP;
}
if (mIcmpClass[Icmp.Type].IcmpClass == ICMP_ERROR_MESSAGE) {
return Ip4ProcessIcmpError (IpSb, Head, Packet);
} else if (mIcmpClass[Icmp.Type].IcmpClass == ICMP_QUERY_MESSAGE) {
return Ip4ProcessIcmpQuery (IpSb, Head, Packet);
}
DROP:
NetbufFree (Packet);
return EFI_INVALID_PARAMETER;
}

View File

@@ -1,97 +0,0 @@
/** @file
Header file for ICMP protocol.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_ICMP_H__
#define __EFI_IP4_ICMP_H__
//
// ICMP type definations
//
#define ICMP_ECHO_REPLY 0
#define ICMP_DEST_UNREACHABLE 3
#define ICMP_SOURCE_QUENCH 4
#define ICMP_REDIRECT 5
#define ICMP_ECHO_REQUEST 8
#define ICMP_TIME_EXCEEDED 11
#define ICMP_PARAMETER_PROBLEM 12
#define ICMP_TIMESTAMP 13
#define ICMP_INFO_REQUEST 15
#define ICMP_INFO_REPLY 16
#define ICMP_TYPE_MAX ICMP_INFO_REPLY
#define ICMP_DEFAULT_CODE 0
//
// ICMP code definations for ICMP_DEST_UNREACHABLE
//
#define ICMP_NET_UNREACHABLE 0
#define ICMP_HOST_UNREACHABLE 1
#define ICMP_PROTO_UNREACHABLE 2 // Host may generate
#define ICMP_PORT_UNREACHABLE 3 // Host may generate
#define ICMP_FRAGMENT_FAILED 4
#define ICMP_SOURCEROUTE_FAILED 5 // Host may generate
#define ICMP_NET_UNKNOWN 6
#define ICMP_HOST_UNKNOWN 7
#define ICMP_SOURCE_ISOLATED 8
#define ICMP_NET_PROHIBITED 9
#define ICMP_HOST_PROHIBITED 10
#define ICMP_NET_UNREACHABLE_TOS 11
#define ICMP_HOST_UNREACHABLE_TOS 12
//
// ICMP code definations for ICMP_TIME_EXCEEDED
//
#define ICMP_TIMEOUT_IN_TRANSIT 0
#define ICMP_TIMEOUT_REASSEMBLE 1 // Host may generate
//
// ICMP code definations for ICMP_TIME_EXCEEDED
//
#define ICMP_NET_REDIRECT 0
#define ICMP_HOST_REDIRECT 1
#define ICMP_NET_TOS_REDIRECT 2
#define ICMP_HOST_TOS_REDIRECT 3
//
// ICMP message classes, each class of ICMP message shares
// a common message format. INVALID_MESSAGE is only a flag.
//
#define ICMP_INVALID_MESSAGE 0
#define ICMP_ERROR_MESSAGE 1
#define ICMP_QUERY_MESSAGE 2
typedef struct {
UINT8 IcmpType;
UINT8 IcmpClass;
} IP4_ICMP_CLASS;
extern IP4_ICMP_CLASS mIcmpClass[];
extern EFI_IP4_ICMP_TYPE mIp4SupportedIcmp[];
/**
Handle the ICMP packet. First validate the message format,
then according to the message types, process it as query or
error packet.
@param[in] IpSb The IP4 service that receivd the packet.
@param[in] Head The IP4 head of the ICMP query packet.
@param[in] Packet The content of the ICMP query with IP4 head
removed.
@retval EFI_INVALID_PARAMETER The packet is malformated.
@retval EFI_SUCCESS The ICMP message is successfully processed.
@retval Others Failed to handle ICMP packet.
**/
EFI_STATUS
Ip4IcmpHandle (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,340 +0,0 @@
/** @file
Definition for IP4 pesudo interface structure.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_IF_H__
#define __EFI_IP4_IF_H__
#define IP4_FRAME_RX_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'R')
#define IP4_FRAME_TX_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'T')
#define IP4_FRAME_ARP_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'A')
#define IP4_INTERFACE_SIGNATURE SIGNATURE_32 ('I', 'P', 'I', 'F')
/**
This prototype is used by both receive and transmission.
When receiving Netbuf is allocated by IP4_INTERFACE, and
released by IP4. Flag shows whether the frame is received
as link broadcast/multicast...
When transmitting, the Netbuf is from IP4, and provided
to the callback as a reference. Flag isn't used.
@param[in] IpInstance The instance that sent or received the packet.
IpInstance can be NULL which means that it is the IP4 driver
itself sending the packets. IP4 driver may send packets that
don't belong to any instance, such as ICMP errors, ICMP echo
responses, or IGMP packets. IpInstance is used as a tag in
this module.
@param[in] Packet The sent or received packet.
@param[in] IoStatus Status of sending or receiving.
@param[in] LinkFlag Indicate if the frame is received as link broadcast/multicast.
When transmitting, it is not used.
@param[in] Context Additional data for callback.
@retval None.
**/
typedef
VOID
(*IP4_FRAME_CALLBACK)(
IN IP4_PROTOCOL *IpInstance OPTIONAL,
IN NET_BUF *Packet,
IN EFI_STATUS IoStatus,
IN UINT32 LinkFlag,
IN VOID *Context
);
///
/// Each receive request is wrapped in an IP4_LINK_RX_TOKEN.
/// Upon completion, the Callback will be called. Only one
/// receive request is send to MNP. IpInstance is always NULL.
/// Reference MNP's spec for information.
///
typedef struct {
UINT32 Signature;
IP4_INTERFACE *Interface;
IP4_PROTOCOL *IpInstance;
IP4_FRAME_CALLBACK CallBack;
VOID *Context;
EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
} IP4_LINK_RX_TOKEN;
///
/// Each transmit request is wrapped in an IP4_LINK_TX_TOKEN.
/// Upon completion, the Callback will be called.
///
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
IP4_INTERFACE *Interface;
IP4_SERVICE *IpSb;
IP4_PROTOCOL *IpInstance;
IP4_FRAME_CALLBACK CallBack;
NET_BUF *Packet;
VOID *Context;
EFI_MAC_ADDRESS DstMac;
EFI_MAC_ADDRESS SrcMac;
EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
EFI_MANAGED_NETWORK_TRANSMIT_DATA MnpTxData;
} IP4_LINK_TX_TOKEN;
///
/// Only one ARP request is requested for all the frames in
/// a time. It is started for the first frames to the Ip. Any
/// subsequent transmission frame will be linked to Frames, and
/// be sent all at once the ARP requests succeed.
///
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
LIST_ENTRY Frames;
IP4_INTERFACE *Interface;
//
// ARP requesting staffs
//
EFI_EVENT OnResolved;
IP4_ADDR Ip;
EFI_MAC_ADDRESS Mac;
} IP4_ARP_QUE;
/**
Callback to select which frame to cancel. Caller can cancel a
single frame, or all the frame from an IP instance.
@param Frame The sending frame to check for cancellation.
@param Context Additional data for callback.
@retval TRUE The sending of the frame should be cancelled.
@retval FALSE Do not cancel the frame sending.
**/
typedef
BOOLEAN
(*IP4_FRAME_TO_CANCEL)(
IP4_LINK_TX_TOKEN *Frame,
VOID *Context
);
//
// Each IP4 instance has its own station address. All the instances
// with the same station address share a single interface structure.
// Each interface has its own ARP child, and shares one MNP child.
// Notice the special cases that DHCP can configure the interface
// with 0.0.0.0/0.0.0.0.
//
struct _IP4_INTERFACE {
UINT32 Signature;
LIST_ENTRY Link;
INTN RefCnt;
//
// IP address and subnet mask of the interface. It also contains
// the subnet/net broadcast address for quick access. The fields
// are invalid if (Configured == FALSE)
//
IP4_ADDR Ip;
IP4_ADDR SubnetMask;
IP4_ADDR SubnetBrdcast;
IP4_ADDR NetBrdcast;
BOOLEAN Configured;
//
// Handle used to create/destroy ARP child. All the IP children
// share one MNP which is owned by IP service binding.
//
EFI_HANDLE Controller;
EFI_HANDLE Image;
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
EFI_ARP_PROTOCOL *Arp;
EFI_HANDLE ArpHandle;
//
// Queues to keep the frames sent and waiting ARP request.
//
LIST_ENTRY ArpQues;
LIST_ENTRY SentFrames;
IP4_LINK_RX_TOKEN *RecvRequest;
//
// The interface's MAC and broadcast MAC address.
//
EFI_MAC_ADDRESS Mac;
EFI_MAC_ADDRESS BroadcastMac;
UINT32 HwaddrLen;
//
// All the IP instances that have the same IP/SubnetMask are linked
// together through IpInstances. If any of the instance enables
// promiscuous receive, PromiscRecv is true.
//
LIST_ENTRY IpInstances;
BOOLEAN PromiscRecv;
};
/**
Create an IP4_INTERFACE. Delay the creation of ARP instance until
the interface is configured.
@param[in] Mnp The shared MNP child of this IP4 service binding
instance.
@param[in] Controller The controller this IP4 service binding instance
is installed. Most like the UNDI handle.
@param[in] ImageHandle This driver's image handle.
@return Point to the created IP4_INTERFACE, otherwise NULL.
**/
IP4_INTERFACE *
Ip4CreateInterface (
IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
IN EFI_HANDLE Controller,
IN EFI_HANDLE ImageHandle
);
/**
Set the interface's address, create and configure
the ARP child if necessary.
@param Interface The interface to set the address.
@param IpAddr The interface's IP address.
@param SubnetMask The interface's netmask.
@retval EFI_SUCCESS The interface is configured with Ip/netmask pair,
and a ARP is created for it.
@retval Others Failed to set the interface's address.
**/
EFI_STATUS
Ip4SetAddress (
IN OUT IP4_INTERFACE *Interface,
IN IP4_ADDR IpAddr,
IN IP4_ADDR SubnetMask
);
/**
Free the interface used by IpInstance. All the IP instance with
the same Ip/Netmask pair share the same interface. It is reference
counted. All the frames haven't been sent will be cancelled.
Because the IpInstance is optional, the caller must remove
IpInstance from the interface's instance list itself.
@param[in] Interface The interface used by the IpInstance.
@param[in] IpInstance The Ip instance that free the interface. NULL if
the Ip driver is releasing the default interface.
@retval EFI_SUCCESS The interface use IpInstance is freed.
**/
EFI_STATUS
Ip4FreeInterface (
IN IP4_INTERFACE *Interface,
IN IP4_PROTOCOL *IpInstance OPTIONAL
);
/**
Send a frame from the interface. If the next hop is broadcast or
multicast address, it is transmitted immediately. If the next hop
is a unicast, it will consult ARP to resolve the NextHop's MAC.
If some error happened, the CallBack won't be called. So, the caller
must test the return value, and take action when there is an error.
@param[in] Interface The interface to send the frame from
@param[in] IpInstance The IP child that request the transmission. NULL
if it is the IP4 driver itself.
@param[in] Packet The packet to transmit.
@param[in] NextHop The immediate destination to transmit the packet
to.
@param[in] CallBack Function to call back when transmit finished.
@param[in] Context Opaque parameter to the call back.
@param[in] IpSb The pointer to the IP4 service binding instance.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource to send the frame
@retval EFI_NO_MAPPING Can't resolve the MAC for the nexthop
@retval EFI_SUCCESS The packet is successfully transmitted.
@retval other Other error occurs.
**/
EFI_STATUS
Ip4SendFrame (
IN IP4_INTERFACE *Interface,
IN IP4_PROTOCOL *IpInstance OPTIONAL,
IN NET_BUF *Packet,
IN IP4_ADDR NextHop,
IN IP4_FRAME_CALLBACK CallBack,
IN VOID *Context,
IN IP4_SERVICE *IpSb
);
/**
Remove all the frames on the interface that pass the FrameToCancel,
either queued on ARP queues or that have already been delivered to
MNP and not yet recycled.
@param[in] Interface Interface to remove the frames from.
@param[in] IoStatus The transmit status returned to the frames'
callback.
@param[in] FrameToCancel Function to select the frame to cancel, NULL to
select all.
@param[in] Context Opaque parameters passed to FrameToCancel.
**/
VOID
Ip4CancelFrames (
IN IP4_INTERFACE *Interface,
IN EFI_STATUS IoStatus,
IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL,
IN VOID *Context
);
/**
If there is a pending receive request, cancel it. Don't call
the receive request's callback because this function can be only
called if the instance or driver is tearing itself down. It
doesn't make sense to call it back. But it is necessary to call
the transmit token's callback to give it a chance to free the
packet and update the upper layer's transmit request status, say
that from the UDP.
@param[in] Interface The interface used by the IpInstance
**/
VOID
Ip4CancelReceive (
IN IP4_INTERFACE *Interface
);
/**
Request to receive the packet from the interface.
@param[in] Interface The interface to receive the frames from.
@param[in] IpInstance The instance that requests the receive. NULL for
the driver itself.
@param[in] CallBack Function to call when receive finished.
@param[in] Context Opaque parameter to the callback.
@retval EFI_ALREADY_STARTED There is already a pending receive request.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive.
@retval EFI_SUCCESS The recieve request has been started.
@retval other Other error occurs.
**/
EFI_STATUS
Ip4ReceiveFrame (
IN IP4_INTERFACE *Interface,
IN IP4_PROTOCOL *IpInstance OPTIONAL,
IN IP4_FRAME_CALLBACK CallBack,
IN VOID *Context
);
#endif

View File

@@ -1,615 +0,0 @@
/** @file
This file implements the RFC2236: IGMP v2.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
//
// Route Alert option in IGMP report to direct routers to
// examine the packet more closely.
//
UINT32 mRouteAlertOption = 0x00000494;
/**
Init the IGMP control data of the IP4 service instance, configure
MNP to receive ALL SYSTEM multicast.
@param[in, out] IpSb The IP4 service whose IGMP is to be initialized.
@retval EFI_SUCCESS IGMP of the IpSb is successfully initialized.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource to initialize IGMP.
@retval Others Failed to initialize the IGMP of IpSb.
**/
EFI_STATUS
Ip4InitIgmp (
IN OUT IP4_SERVICE *IpSb
)
{
IGMP_SERVICE_DATA *IgmpCtrl;
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
IGMP_GROUP *Group;
EFI_STATUS Status;
IgmpCtrl = &IpSb->IgmpCtrl;
//
// Configure MNP to receive ALL_SYSTEM multicast
//
Group = AllocatePool (sizeof (IGMP_GROUP));
if (Group == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Mnp = IpSb->Mnp;
Group->Address = IP4_ALLSYSTEM_ADDRESS;
Group->RefCnt = 1;
Group->DelayTime = 0;
Group->ReportByUs = FALSE;
Status = Ip4GetMulticastMac (Mnp, IP4_ALLSYSTEM_ADDRESS, &Group->Mac);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
Status = Mnp->Groups (Mnp, TRUE, &Group->Mac);
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
goto ON_ERROR;
}
InsertHeadList (&IgmpCtrl->Groups, &Group->Link);
return EFI_SUCCESS;
ON_ERROR:
FreePool (Group);
return Status;
}
/**
Find the IGMP_GROUP structure which contains the status of multicast
group Address in this IGMP control block
@param[in] IgmpCtrl The IGMP control block to search from.
@param[in] Address The multicast address to search.
@return NULL if the multicast address isn't in the IGMP control block. Otherwise
the point to the IGMP_GROUP which contains the status of multicast group
for Address.
**/
IGMP_GROUP *
Ip4FindGroup (
IN IGMP_SERVICE_DATA *IgmpCtrl,
IN IP4_ADDR Address
)
{
LIST_ENTRY *Entry;
IGMP_GROUP *Group;
NET_LIST_FOR_EACH (Entry, &IgmpCtrl->Groups) {
Group = NET_LIST_USER_STRUCT (Entry, IGMP_GROUP, Link);
if (Group->Address == Address) {
return Group;
}
}
return NULL;
}
/**
Count the number of IP4 multicast groups that are mapped to the
same MAC address. Several IP4 multicast address may be mapped to
the same MAC address.
@param[in] IgmpCtrl The IGMP control block to search in.
@param[in] Mac The MAC address to search.
@return The number of the IP4 multicast group that mapped to the same
multicast group Mac.
**/
INTN
Ip4FindMac (
IN IGMP_SERVICE_DATA *IgmpCtrl,
IN EFI_MAC_ADDRESS *Mac
)
{
LIST_ENTRY *Entry;
IGMP_GROUP *Group;
INTN Count;
Count = 0;
NET_LIST_FOR_EACH (Entry, &IgmpCtrl->Groups) {
Group = NET_LIST_USER_STRUCT (Entry, IGMP_GROUP, Link);
if (NET_MAC_EQUAL (&Group->Mac, Mac, sizeof (EFI_MAC_ADDRESS))) {
Count++;
}
}
return Count;
}
/**
Send an IGMP protocol message to the Dst, such as IGMP v1 membership report.
@param[in] IpSb The IP4 service instance that requests the
transmission.
@param[in] Dst The destinaton to send to.
@param[in] Type The IGMP message type, such as IGMP v1 membership
report.
@param[in] Group The group address in the IGMP message head.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to build the message.
@retval EFI_SUCCESS The IGMP message is successfully send.
@retval Others Failed to send the IGMP message.
**/
EFI_STATUS
Ip4SendIgmpMessage (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Dst,
IN UINT8 Type,
IN IP4_ADDR Group
)
{
IP4_HEAD Head;
NET_BUF *Packet;
IGMP_HEAD *Igmp;
//
// Allocate a net buffer to hold the message
//
Packet = NetbufAlloc (IP4_MAX_HEADLEN + sizeof (IGMP_HEAD));
if (Packet == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Fill in the IGMP and IP header, then transmit the message
//
NetbufReserve (Packet, IP4_MAX_HEADLEN);
Igmp = (IGMP_HEAD *) NetbufAllocSpace (Packet, sizeof (IGMP_HEAD), FALSE);
if (Igmp == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Igmp->Type = Type;
Igmp->MaxRespTime = 0;
Igmp->Checksum = 0;
Igmp->Group = HTONL (Group);
Igmp->Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Igmp, sizeof (IGMP_HEAD)));
Head.Tos = 0;
Head.Protocol = IP4_PROTO_IGMP;
Head.Ttl = 1;
Head.Fragment = 0;
Head.Dst = Dst;
Head.Src = IP4_ALLZERO_ADDRESS;
return Ip4Output (
IpSb,
NULL,
Packet,
&Head,
(UINT8 *) &mRouteAlertOption,
sizeof (UINT32),
IP4_ALLZERO_ADDRESS,
Ip4SysPacketSent,
NULL
);
}
/**
Send an IGMP membership report. Depends on whether the server is
v1 or v2, it will send either a V1 or V2 membership report.
@param[in] IpSb The IP4 service instance that requests the
transmission.
@param[in] Group The group address to report.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory to build the message.
@retval EFI_SUCCESS The IGMP report message is successfully send.
@retval Others Failed to send the report.
**/
EFI_STATUS
Ip4SendIgmpReport (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Group
)
{
if (IpSb->IgmpCtrl.Igmpv1QuerySeen != 0) {
return Ip4SendIgmpMessage (IpSb, Group, IGMP_V1_MEMBERSHIP_REPORT, Group);
} else {
return Ip4SendIgmpMessage (IpSb, Group, IGMP_V2_MEMBERSHIP_REPORT, Group);
}
}
/**
Join the multicast group on behalf of this IP4 child
@param[in] IpInstance The IP4 child that wants to join the group.
@param[in] Address The group to join.
@retval EFI_SUCCESS Successfully join the multicast group.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@retval Others Failed to join the multicast group.
**/
EFI_STATUS
Ip4JoinGroup (
IN IP4_PROTOCOL *IpInstance,
IN IP4_ADDR Address
)
{
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
IP4_SERVICE *IpSb;
IGMP_SERVICE_DATA *IgmpCtrl;
IGMP_GROUP *Group;
EFI_STATUS Status;
IpSb = IpInstance->Service;
IgmpCtrl = &IpSb->IgmpCtrl;
Mnp = IpSb->Mnp;
//
// If the IP service already is a member in the group, just
// increase the refernce count and return.
//
Group = Ip4FindGroup (IgmpCtrl, Address);
if (Group != NULL) {
Group->RefCnt++;
return EFI_SUCCESS;
}
//
// Otherwise, create a new IGMP_GROUP, Get the multicast's MAC address,
// send a report, then direct MNP to receive the multicast.
//
Group = AllocatePool (sizeof (IGMP_GROUP));
if (Group == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Group->Address = Address;
Group->RefCnt = 1;
Group->DelayTime = IGMP_UNSOLICIATED_REPORT;
Group->ReportByUs = TRUE;
Status = Ip4GetMulticastMac (Mnp, Address, &Group->Mac);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
Status = Ip4SendIgmpReport (IpSb, Address);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
Status = Mnp->Groups (Mnp, TRUE, &Group->Mac);
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
goto ON_ERROR;
}
InsertHeadList (&IgmpCtrl->Groups, &Group->Link);
return EFI_SUCCESS;
ON_ERROR:
FreePool (Group);
return Status;
}
/**
Leave the IP4 multicast group on behalf of IpInstance.
@param[in] IpInstance The IP4 child that wants to leave the group
address.
@param[in] Address The group address to leave.
@retval EFI_NOT_FOUND The IP4 service instance isn't in the group.
@retval EFI_SUCCESS Successfully leave the multicast group.
@retval Others Failed to leave the multicast group.
**/
EFI_STATUS
Ip4LeaveGroup (
IN IP4_PROTOCOL *IpInstance,
IN IP4_ADDR Address
)
{
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
IP4_SERVICE *IpSb;
IGMP_SERVICE_DATA *IgmpCtrl;
IGMP_GROUP *Group;
EFI_STATUS Status;
IpSb = IpInstance->Service;
IgmpCtrl = &IpSb->IgmpCtrl;
Mnp = IpSb->Mnp;
Group = Ip4FindGroup (IgmpCtrl, Address);
if (Group == NULL) {
return EFI_NOT_FOUND;
}
//
// If more than one instance is in the group, decrease
// the RefCnt then return.
//
if (--Group->RefCnt > 0) {
return EFI_SUCCESS;
}
//
// If multiple IP4 group addresses are mapped to the same
// multicast MAC address, don't configure the MNP to leave
// the MAC.
//
if (Ip4FindMac (IgmpCtrl, &Group->Mac) == 1) {
Status = Mnp->Groups (Mnp, FALSE, &Group->Mac);
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
return Status;
}
}
//
// Send a leave report if the membership is reported by us
// and we are talking IGMPv2.
//
if (Group->ReportByUs && IgmpCtrl->Igmpv1QuerySeen == 0) {
Ip4SendIgmpMessage (IpSb, IP4_ALLROUTER_ADDRESS, IGMP_LEAVE_GROUP, Group->Address);
}
RemoveEntryList (&Group->Link);
FreePool (Group);
return EFI_SUCCESS;
}
/**
Handle the received IGMP message for the IP4 service instance.
@param[in] IpSb The IP4 service instance that received the message.
@param[in] Head The IP4 header of the received message.
@param[in] Packet The IGMP message, without IP4 header.
@retval EFI_INVALID_PARAMETER The IGMP message is malformated.
@retval EFI_SUCCESS The IGMP message is successfully processed.
**/
EFI_STATUS
Ip4IgmpHandle (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
)
{
IGMP_SERVICE_DATA *IgmpCtrl;
IGMP_HEAD Igmp;
IGMP_GROUP *Group;
IP4_ADDR Address;
LIST_ENTRY *Entry;
IgmpCtrl = &IpSb->IgmpCtrl;
//
// Must checksum over the whole packet, later IGMP version
// may employ message longer than 8 bytes. IP's header has
// already been trimmed off.
//
if ((Packet->TotalSize < sizeof (Igmp)) || (NetbufChecksum (Packet) != 0)) {
NetbufFree (Packet);
return EFI_INVALID_PARAMETER;
}
//
// Copy the packet in case it is fragmented
//
NetbufCopy (Packet, 0, sizeof (IGMP_HEAD), (UINT8 *)&Igmp);
switch (Igmp.Type) {
case IGMP_MEMBERSHIP_QUERY:
//
// If MaxRespTime is zero, it is most likely that we are
// talking to a V1 router
//
if (Igmp.MaxRespTime == 0) {
IgmpCtrl->Igmpv1QuerySeen = IGMP_V1ROUTER_PRESENT;
Igmp.MaxRespTime = 100;
}
//
// Igmp is ticking once per second but MaxRespTime is in
// the unit of 100ms.
//
Igmp.MaxRespTime /= 10;
Address = NTOHL (Igmp.Group);
if (Address == IP4_ALLSYSTEM_ADDRESS) {
break;
}
NET_LIST_FOR_EACH (Entry, &IgmpCtrl->Groups) {
Group = NET_LIST_USER_STRUCT (Entry, IGMP_GROUP, Link);
//
// If address is all zero, all the memberships will be reported.
// otherwise only one is reported.
//
if ((Address == IP4_ALLZERO_ADDRESS) || (Address == Group->Address)) {
//
// If the timer is pending, only update it if the time left
// is longer than the MaxRespTime. TODO: randomize the DelayTime.
//
if ((Group->DelayTime == 0) || (Group->DelayTime > Igmp.MaxRespTime)) {
Group->DelayTime = MAX (1, Igmp.MaxRespTime);
}
}
}
break;
case IGMP_V1_MEMBERSHIP_REPORT:
case IGMP_V2_MEMBERSHIP_REPORT:
Address = NTOHL (Igmp.Group);
Group = Ip4FindGroup (IgmpCtrl, Address);
if ((Group != NULL) && (Group->DelayTime > 0)) {
Group->DelayTime = 0;
Group->ReportByUs = FALSE;
}
break;
}
NetbufFree (Packet);
return EFI_SUCCESS;
}
/**
The periodical timer function for IGMP. It does the following
things:
1. Decrease the Igmpv1QuerySeen to make it possible to refresh
the IGMP server type.
2. Decrease the report timer for each IGMP group in "delaying
member" state.
@param[in] IpSb The IP4 service instance that is ticking.
**/
VOID
Ip4IgmpTicking (
IN IP4_SERVICE *IpSb
)
{
IGMP_SERVICE_DATA *IgmpCtrl;
LIST_ENTRY *Entry;
IGMP_GROUP *Group;
IgmpCtrl = &IpSb->IgmpCtrl;
if (IgmpCtrl->Igmpv1QuerySeen > 0) {
IgmpCtrl->Igmpv1QuerySeen--;
}
//
// Decrease the report timer for each IGMP group in "delaying member"
//
NET_LIST_FOR_EACH (Entry, &IgmpCtrl->Groups) {
Group = NET_LIST_USER_STRUCT (Entry, IGMP_GROUP, Link);
ASSERT (Group->DelayTime >= 0);
if (Group->DelayTime > 0) {
Group->DelayTime--;
if (Group->DelayTime == 0) {
Ip4SendIgmpReport (IpSb, Group->Address);
Group->ReportByUs = TRUE;
}
}
}
}
/**
Add a group address to the array of group addresses.
The caller should make sure that no duplicated address
existed in the array. Although the function doesn't
assume the byte order of the both Source and Addr, the
network byte order is used by the caller.
@param[in] Source The array of group addresses to add to.
@param[in] Count The number of group addresses in the Source.
@param[in] Addr The IP4 multicast address to add.
@return NULL if failed to allocate memory for the new groups,
otherwise the new combined group addresses.
**/
IP4_ADDR *
Ip4CombineGroups (
IN IP4_ADDR *Source,
IN UINT32 Count,
IN IP4_ADDR Addr
)
{
IP4_ADDR *Groups;
Groups = AllocatePool (sizeof (IP4_ADDR) * (Count + 1));
if (Groups == NULL) {
return NULL;
}
CopyMem (Groups, Source, Count * sizeof (IP4_ADDR));
Groups[Count] = Addr;
return Groups;
}
/**
Remove a group address from the array of group addresses.
Although the function doesn't assume the byte order of the
both Groups and Addr, the network byte order is used by
the caller.
@param Groups The array of group addresses to remove from.
@param Count The number of group addresses in the Groups.
@param Addr The IP4 multicast address to remove.
@return The nubmer of group addresses in the Groups after remove.
It is Count if the Addr isn't in the Groups.
**/
INTN
Ip4RemoveGroupAddr (
IN OUT IP4_ADDR *Groups,
IN UINT32 Count,
IN IP4_ADDR Addr
)
{
UINT32 Index;
for (Index = 0; Index < Count; Index++) {
if (Groups[Index] == Addr) {
break;
}
}
while (Index < Count - 1) {
Groups[Index] = Groups[Index + 1];
Index++;
}
return Index;
}

View File

@@ -1,201 +0,0 @@
/** @file
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_IGMP_H__
#define __EFI_IP4_IGMP_H__
//
// IGMP message type
//
#define IGMP_MEMBERSHIP_QUERY 0x11
#define IGMP_V1_MEMBERSHIP_REPORT 0x12
#define IGMP_V2_MEMBERSHIP_REPORT 0x16
#define IGMP_LEAVE_GROUP 0x17
#define IGMP_V1ROUTER_PRESENT 400
#define IGMP_UNSOLICIATED_REPORT 10
#pragma pack(1)
typedef struct {
UINT8 Type;
UINT8 MaxRespTime;
UINT16 Checksum;
IP4_ADDR Group;
} IGMP_HEAD;
#pragma pack()
///
/// The status of multicast group. It isn't necessary to maintain
/// explicit state of host state diagram. A group with non-zero
/// DelayTime is in "delaying member" state. otherwise, it is in
/// "idle member" state.
///
typedef struct {
LIST_ENTRY Link;
INTN RefCnt;
IP4_ADDR Address;
INTN DelayTime;
BOOLEAN ReportByUs;
EFI_MAC_ADDRESS Mac;
} IGMP_GROUP;
///
/// The IGMP status. Each IP4 service instance has a IGMP_SERVICE_DATA
/// attached. The Igmpv1QuerySeen remember whether the server on this
/// connected network is v1 or v2.
///
typedef struct {
INTN Igmpv1QuerySeen;
LIST_ENTRY Groups;
} IGMP_SERVICE_DATA;
/**
Init the IGMP control data of the IP4 service instance, configure
MNP to receive ALL SYSTEM multicast.
@param[in, out] IpSb The IP4 service whose IGMP is to be initialized.
@retval EFI_SUCCESS IGMP of the IpSb is successfully initialized.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource to initialize IGMP.
@retval Others Failed to initialize the IGMP of IpSb.
**/
EFI_STATUS
Ip4InitIgmp (
IN OUT IP4_SERVICE *IpSb
);
/**
Join the multicast group on behalf of this IP4 child
@param[in] IpInstance The IP4 child that wants to join the group.
@param[in] Address The group to join.
@retval EFI_SUCCESS Successfully join the multicast group.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
@retval Others Failed to join the multicast group.
**/
EFI_STATUS
Ip4JoinGroup (
IN IP4_PROTOCOL *IpInstance,
IN IP4_ADDR Address
);
/**
Leave the IP4 multicast group on behalf of IpInstance.
@param[in] IpInstance The IP4 child that wants to leave the group
address.
@param[in] Address The group address to leave.
@retval EFI_NOT_FOUND The IP4 service instance isn't in the group.
@retval EFI_SUCCESS Successfully leave the multicast group.
@retval Others Failed to leave the multicast group.
**/
EFI_STATUS
Ip4LeaveGroup (
IN IP4_PROTOCOL *IpInstance,
IN IP4_ADDR Address
);
/**
Handle the received IGMP message for the IP4 service instance.
@param[in] IpSb The IP4 service instance that received the message.
@param[in] Head The IP4 header of the received message.
@param[in] Packet The IGMP message, without IP4 header.
@retval EFI_INVALID_PARAMETER The IGMP message is malformated.
@retval EFI_SUCCESS The IGMP message is successfully processed.
**/
EFI_STATUS
Ip4IgmpHandle (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet
);
/**
The periodical timer function for IGMP. It does the following
things:
1. Decrease the Igmpv1QuerySeen to make it possible to refresh
the IGMP server type.
2. Decrease the report timer for each IGMP group in "delaying
member" state.
@param[in] IpSb The IP4 service instance that is ticking.
**/
VOID
Ip4IgmpTicking (
IN IP4_SERVICE *IpSb
);
/**
Add a group address to the array of group addresses.
The caller should make sure that no duplicated address
existed in the array. Although the function doesn't
assume the byte order of the both Source and Addr, the
network byte order is used by the caller.
@param[in] Source The array of group addresses to add to.
@param[in] Count The number of group addresses in the Source.
@param[in] Addr The IP4 multicast address to add.
@return NULL if failed to allocate memory for the new groups,
otherwise the new combined group addresses.
**/
IP4_ADDR *
Ip4CombineGroups (
IN IP4_ADDR *Source,
IN UINT32 Count,
IN IP4_ADDR Addr
);
/**
Remove a group address from the array of group addresses.
Although the function doesn't assume the byte order of the
both Groups and Addr, the network byte order is used by
the caller.
@param Groups The array of group addresses to remove from.
@param Count The number of group addresses in the Groups.
@param Addr The IP4 multicast address to remove.
@return The nubmer of group addresses in the Groups after remove.
It is Count if the Addr isn't in the Groups.
**/
INTN
Ip4RemoveGroupAddr (
IN OUT IP4_ADDR *Groups,
IN UINT32 Count,
IN IP4_ADDR Addr
);
/**
Find the IGMP_GROUP structure which contains the status of multicast
group Address in this IGMP control block
@param[in] IgmpCtrl The IGMP control block to search from.
@param[in] Address The multicast address to search.
@return NULL if the multicast address isn't in the IGMP control block. Otherwise
the point to the IGMP_GROUP which contains the status of multicast group
for Address.
**/
IGMP_GROUP *
Ip4FindGroup (
IN IGMP_SERVICE_DATA *IgmpCtrl,
IN IP4_ADDR Address
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,417 +0,0 @@
/** @file
Ip4 internal functions and type defintions.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_IMPL_H__
#define __EFI_IP4_IMPL_H__
#include <Uefi.h>
#include <Protocol/IpSec.h>
#include <Protocol/Ip4.h>
#include <Protocol/Ip4Config2.h>
#include <Protocol/Arp.h>
#include <Protocol/ManagedNetwork.h>
#include <Protocol/Dhcp4.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/HiiConfigAccess.h>
#include <IndustryStandard/Dhcp.h>
#include <Library/DebugLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiLib.h>
#include <Library/NetLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DpcLib.h>
#include <Library/PrintLib.h>
#include <Library/DevicePathLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiHiiServicesLib.h>
#include "Ip4Common.h"
#include "Ip4Driver.h"
#include "Ip4If.h"
#include "Ip4Icmp.h"
#include "Ip4Option.h"
#include "Ip4Igmp.h"
#include "Ip4Route.h"
#include "Ip4Input.h"
#include "Ip4Output.h"
#include "Ip4Config2Impl.h"
#include "Ip4Config2Nv.h"
#include "Ip4NvData.h"
#define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')
#define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')
//
// The state of IP4 protocol. It starts from UNCONFIGED. if it is
// successfully configured, it goes to CONFIGED. if configure NULL
// is called, it becomes UNCONFIGED again.
//
#define IP4_STATE_UNCONFIGED 0
#define IP4_STATE_CONFIGED 1
//
// The state of IP4 service. It starts from UNSTARTED. It transits
// to STARTED if autoconfigure is started. If default address is
// configured, it becomes CONFIGED. and if partly destroyed, it goes
// to DESTROY.
//
#define IP4_SERVICE_UNSTARTED 0
#define IP4_SERVICE_STARTED 1
#define IP4_SERVICE_CONFIGED 2
#define IP4_SERVICE_DESTROY 3
///
/// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.
/// The user's data is kept in the Packet. When fragment is
/// needed, each fragment of the Packet has a reference to the
/// Packet, no data is actually copied. The Packet will be
/// released when all the fragments of it have been recycled by
/// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and
/// user's event signalled.
///
typedef struct {
IP4_PROTOCOL *IpInstance;
EFI_IP4_COMPLETION_TOKEN *Token;
EFI_EVENT IpSecRecycleSignal;
NET_BUF *Packet;
BOOLEAN Sent;
INTN Life;
} IP4_TXTOKEN_WRAP;
///
/// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet
/// will be released after it has been processed by the receiver. Upon then,
/// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled
/// to notice IPsec to free the resources.
///
typedef struct {
EFI_EVENT IpSecRecycleSignal;
NET_BUF *Packet;
} IP4_IPSEC_WRAP;
///
/// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the
/// upper layers. The received packet is kept in the Packet.
/// The Packet itself may be constructured from some fragments.
/// All the fragments of the Packet is organized by a
/// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by
/// the upper layer, the assemble entry and its associated
/// fragments will be freed at last.
///
typedef struct {
LIST_ENTRY Link;
IP4_PROTOCOL *IpInstance;
NET_BUF *Packet;
EFI_IP4_RECEIVE_DATA RxData;
} IP4_RXDATA_WRAP;
struct _IP4_PROTOCOL {
UINT32 Signature;
EFI_IP4_PROTOCOL Ip4Proto;
EFI_HANDLE Handle;
INTN State;
BOOLEAN InDestroy;
IP4_SERVICE *Service;
LIST_ENTRY Link; // Link to all the IP protocol from the service
//
// User's transmit/receive tokens, and received/deliverd packets
//
NET_MAP RxTokens;
NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)
LIST_ENTRY Received; // Received but not delivered packet
LIST_ENTRY Delivered; // Delivered and to be recycled packets
EFI_LOCK RecycleLock;
//
// Instance's address and route tables. There are two route tables.
// RouteTable is used by the IP4 driver to route packet. EfiRouteTable
// is used to communicate the current route info to the upper layer.
//
IP4_INTERFACE *Interface;
LIST_ENTRY AddrLink; // Ip instances with the same IP address.
IP4_ROUTE_TABLE *RouteTable;
EFI_IP4_ROUTE_TABLE *EfiRouteTable;
UINT32 EfiRouteCount;
//
// IGMP data for this instance
//
IP4_ADDR *Groups; // stored in network byte order
UINT32 GroupCount;
EFI_IP4_CONFIG_DATA ConfigData;
};
struct _IP4_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
INTN State;
//
// List of all the IP instances and interfaces, and default
// interface and route table and caches.
//
UINTN NumChildren;
LIST_ENTRY Children;
LIST_ENTRY Interfaces;
IP4_INTERFACE *DefaultInterface;
IP4_ROUTE_TABLE *DefaultRouteTable;
//
// Ip reassemble utilities, and IGMP data
//
IP4_ASSEMBLE_TABLE Assemble;
IGMP_SERVICE_DATA IgmpCtrl;
//
// Low level protocol used by this service instance
//
EFI_HANDLE Image;
EFI_HANDLE Controller;
EFI_HANDLE MnpChildHandle;
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
EFI_SIMPLE_NETWORK_MODE SnpMode;
EFI_EVENT Timer;
EFI_EVENT ReconfigCheckTimer;
EFI_EVENT ReconfigEvent;
BOOLEAN Reconfig;
//
// Underlying media present status.
//
BOOLEAN MediaPresent;
//
// IPv4 Configuration II Protocol instance
//
IP4_CONFIG2_INSTANCE Ip4Config2Instance;
CHAR16 *MacString;
UINT32 MaxPacketSize;
UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.
};
#define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \
CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)
#define IP4_SERVICE_FROM_PROTOCOL(Sb) \
CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)
#define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \
CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)
#define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)
extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;
/**
Config the MNP parameter used by IP. The IP driver use one MNP
child to transmit/receive frames. By default, it configures MNP
to receive unicast/multicast/broadcast. And it will enable/disable
the promiscous receive according to whether there is IP child
enable that or not. If Force is FALSE, it will iterate through
all the IP children to check whether the promiscuous receive
setting has been changed. If it hasn't been changed, it won't
reconfigure the MNP. If Force is TRUE, the MNP is configured no
matter whether that is changed or not.
@param[in] IpSb The IP4 service instance that is to be changed.
@param[in] Force Force the configuration or not.
@retval EFI_SUCCESS The MNP is successfully configured/reconfigured.
@retval Others Configuration failed.
**/
EFI_STATUS
Ip4ServiceConfigMnp (
IN IP4_SERVICE *IpSb,
IN BOOLEAN Force
);
/**
Intiialize the IP4_PROTOCOL structure to the unconfigured states.
@param IpSb The IP4 service instance.
@param IpInstance The IP4 child instance.
**/
VOID
Ip4InitProtocol (
IN IP4_SERVICE *IpSb,
IN OUT IP4_PROTOCOL *IpInstance
);
/**
Clean up the IP4 child, release all the resources used by it.
@param[in] IpInstance The IP4 child to clean up.
@retval EFI_SUCCESS The IP4 child is cleaned up.
@retval EFI_DEVICE_ERROR Some resources failed to be released.
**/
EFI_STATUS
Ip4CleanProtocol (
IN IP4_PROTOCOL *IpInstance
);
/**
Cancel the user's receive/transmit request.
@param[in] IpInstance The IP4 child.
@param[in] Token The token to cancel. If NULL, all token will be
cancelled.
@retval EFI_SUCCESS The token is cancelled.
@retval EFI_NOT_FOUND The token isn't found on either the
transmit/receive queue.
@retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.
**/
EFI_STATUS
Ip4Cancel (
IN IP4_PROTOCOL *IpInstance,
IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL
);
/**
Change the IP4 child's multicast setting. The caller
should make sure that the parameters is valid.
@param[in] IpInstance The IP4 child to change the setting.
@param[in] JoinFlag TRUE to join the group, otherwise leave it
@param[in] GroupAddress The target group address
@retval EFI_ALREADY_STARTED Want to join the group, but already a member of it
@retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
@retval EFI_DEVICE_ERROR Failed to set the group configuraton
@retval EFI_SUCCESS Successfully updated the group setting.
@retval EFI_NOT_FOUND Try to leave the group which it isn't a member.
**/
EFI_STATUS
Ip4Groups (
IN IP4_PROTOCOL *IpInstance,
IN BOOLEAN JoinFlag,
IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL
);
/**
This heart beat timer of IP4 service instance times out all of its IP4 children's
received-but-not-delivered and transmitted-but-not-recycle packets, and provides
time input for its IGMP protocol.
@param[in] Event The IP4 service instance's heart beat timer.
@param[in] Context The IP4 service instance.
**/
VOID
EFIAPI
Ip4TimerTicking (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
This dedicated timer is used to poll underlying network media status. In case
of cable swap or wireless network switch, a new round auto configuration will
be initiated. The timer will signal the IP4 to run DHCP configuration again.
IP4 driver will free old IP address related resource, such as route table and
Interface, then initiate a DHCP process to acquire new IP, eventually create
route table for new IP address.
@param[in] Event The IP4 service instance's heart beat timer.
@param[in] Context The IP4 service instance.
**/
VOID
EFIAPI
Ip4TimerReconfigChecking (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Decrease the life of the transmitted packets. If it is
decreased to zero, cancel the packet. This function is
called by Ip4PacketTimerTicking which time out both the
received-but-not-delivered and transmitted-but-not-recycle
packets.
@param[in] Map The IP4 child's transmit map.
@param[in] Item Current transmitted packet.
@param[in] Context Not used.
@retval EFI_SUCCESS Always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
Ip4SentPacketTicking (
IN NET_MAP *Map,
IN NET_MAP_ITEM *Item,
IN VOID *Context
);
/**
The callback function for the net buffer which wraps the user's
transmit token. Although it seems this function is pretty simple,
there are some subtle things.
When user requests the IP to transmit a packet by passing it a
token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data
is wrapped in an net buffer. the net buffer's Free function is
set to Ip4FreeTxToken. The Token and token wrap are added to the
IP child's TxToken map. Then the buffer is passed to Ip4Output for
transmission. If something error happened before that, the buffer
is freed, which in turn will free the token wrap. The wrap may
have been added to the TxToken map or not, and the user's event
shouldn't be fired because we are still in the EfiIp4Transmit. If
the buffer has been sent by Ip4Output, it should be removed from
the TxToken map and user's event signaled. The token wrap and buffer
are bound together. Check the comments in Ip4Output for information
about IP fragmentation.
@param[in] Context The token's wrap.
**/
VOID
EFIAPI
Ip4FreeTxToken (
IN VOID *Context
);
extern EFI_IPSEC2_PROTOCOL *mIpSec;
extern BOOLEAN mIpSec2Installed;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,246 +0,0 @@
/** @file
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_INPUT_H__
#define __EFI_IP4_INPUT_H__
#define IP4_MIN_HEADLEN 20
#define IP4_MAX_HEADLEN 60
///
/// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54
///
#define IP4_MAX_IPSEC_HEADLEN 54
#define IP4_ASSEMLE_HASH_SIZE 31
#define IP4_FRAGMENT_LIFE 120
#define IP4_MAX_PACKET_SIZE 65535
///
/// Per packet information for input process. LinkFlag specifies whether
/// the packet is received as Link layer unicast, multicast or broadcast.
/// The CastType is the IP layer cast type, such as IP multicast or unicast.
/// Start, End and Length are staffs used to assemble the packets. Start
/// is the sequence number of the first byte of data in the packet. Length
/// is the number of bytes of data. End = Start + Length, that is, the
/// sequence number of last byte + 1. Each assembled packet has a count down
/// life. If it isn't consumed before Life reaches zero, the packet is released.
///
typedef struct {
UINTN LinkFlag;
INTN CastType;
INTN Start;
INTN End;
INTN Length;
UINT32 Life;
EFI_STATUS Status;
} IP4_CLIP_INFO;
///
/// Structure used to assemble IP packets.
///
typedef struct {
LIST_ENTRY Link;
//
// Identity of one IP4 packet. Each fragment of a packet has
// the same (Dst, Src, Id, Protocol).
//
IP4_ADDR Dst;
IP4_ADDR Src;
UINT16 Id;
UINT8 Protocol;
INTN TotalLen;
INTN CurLen;
LIST_ENTRY Fragments; // List of all the fragments of this packet
IP4_HEAD *Head; // IP head of the first fragment
IP4_CLIP_INFO *Info; // Per packet info of the first fragment
INTN Life; // Count down life for the packet.
} IP4_ASSEMBLE_ENTRY;
///
/// Each Ip service instance has an assemble table to reassemble
/// the packets before delivery to its children. It is organized
/// as hash table.
///
typedef struct {
LIST_ENTRY Bucket[IP4_ASSEMLE_HASH_SIZE];
} IP4_ASSEMBLE_TABLE;
#define IP4_GET_CLIP_INFO(Packet) ((IP4_CLIP_INFO *) ((Packet)->ProtoData))
#define IP4_ASSEMBLE_HASH(Dst, Src, Id, Proto) \
(((Dst) + (Src) + ((Id) << 16) + (Proto)) % IP4_ASSEMLE_HASH_SIZE)
#define IP4_RXDATA_WRAP_SIZE(NumFrag) \
(sizeof (IP4_RXDATA_WRAP) + sizeof (EFI_IP4_FRAGMENT_DATA) * ((NumFrag) - 1))
/**
Initialize an already allocated assemble table. This is generally
the assemble table embedded in the IP4 service instance.
@param[in, out] Table The assemble table to initialize.
**/
VOID
Ip4InitAssembleTable (
IN OUT IP4_ASSEMBLE_TABLE *Table
);
/**
Clean up the assemble table: remove all the fragments
and assemble entries.
@param[in] Table The assemble table to clean up
**/
VOID
Ip4CleanAssembleTable (
IN IP4_ASSEMBLE_TABLE *Table
);
/**
The IP4 input routine. It is called by the IP4_INTERFACE when a
IP4 fragment is received from MNP.
@param[in] Ip4Instance The IP4 child that request the receive, most like
it is NULL.
@param[in] Packet The IP4 packet received.
@param[in] IoStatus The return status of receive request.
@param[in] Flag The link layer flag for the packet received, such
as multicast.
@param[in] Context The IP4 service instance that own the MNP.
**/
VOID
Ip4AccpetFrame (
IN IP4_PROTOCOL *Ip4Instance,
IN NET_BUF *Packet,
IN EFI_STATUS IoStatus,
IN UINT32 Flag,
IN VOID *Context
);
/**
Demultiple the packet. the packet delivery is processed in two
passes. The first pass will enque a shared copy of the packet
to each IP4 child that accepts the packet. The second pass will
deliver a non-shared copy of the packet to each IP4 child that
has pending receive requests. Data is copied if more than one
child wants to consume the packet because each IP child needs
its own copy of the packet to make changes.
@param[in] IpSb The IP4 service instance that received the packet.
@param[in] Head The header of the received packet.
@param[in] Packet The data of the received packet.
@param[in] Option Point to the IP4 packet header options.
@param[in] OptionLen Length of the IP4 packet header options.
@retval EFI_NOT_FOUND No IP child accepts the packet.
@retval EFI_SUCCESS The packet is enqueued or delivered to some IP
children.
**/
EFI_STATUS
Ip4Demultiplex (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet,
IN UINT8 *Option,
IN UINT32 OptionLen
);
/**
Enqueue a received packet to all the IP children that share
the same interface.
@param[in] IpSb The IP4 service instance that receive the packet.
@param[in] Head The header of the received packet.
@param[in] Packet The data of the received packet.
@param[in] Option Point to the IP4 packet header options.
@param[in] OptionLen Length of the IP4 packet header options.
@param[in] IpIf The interface to enqueue the packet to.
@return The number of the IP4 children that accepts the packet
**/
INTN
Ip4InterfaceEnquePacket (
IN IP4_SERVICE *IpSb,
IN IP4_HEAD *Head,
IN NET_BUF *Packet,
IN UINT8 *Option,
IN UINT32 OptionLen,
IN IP4_INTERFACE *IpIf
);
/**
Deliver the received packets to upper layer if there are both received
requests and enqueued packets. If the enqueued packet is shared, it will
duplicate it to a non-shared packet, release the shared packet, then
deliver the non-shared packet up.
@param[in] IpInstance The IP child to deliver the packet up.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
packets.
@retval EFI_SUCCESS All the enqueued packets that can be delivered
are delivered up.
**/
EFI_STATUS
Ip4InstanceDeliverPacket (
IN IP4_PROTOCOL *IpInstance
);
/**
Timeout the fragment and enqueued packets.
@param[in] IpSb The IP4 service instance to timeout
**/
VOID
Ip4PacketTimerTicking (
IN IP4_SERVICE *IpSb
);
/**
The work function to locate IPsec protocol to process the inbound or
outbound IP packets. The process routine handls the packet with following
actions: bypass the packet, discard the packet, or protect the packet.
@param[in] IpSb The IP4 service instance.
@param[in, out] Head The The caller supplied IP4 header.
@param[in, out] Netbuf The IP4 packet to be processed by IPsec.
@param[in, out] Options The caller supplied options.
@param[in, out] OptionsLen The length of the option.
@param[in] Direction The directionality in an SPD entry,
EfiIPsecInBound or EfiIPsecOutBound.
@param[in] Context The token's wrap.
@retval EFI_SUCCESS The IPsec protocol is not available or disabled.
@retval EFI_SUCCESS The packet was bypassed and all buffers remain the same.
@retval EFI_SUCCESS The packet was protected.
@retval EFI_ACCESS_DENIED The packet was discarded.
@retval EFI_OUT_OF_RESOURCES There is no suffcient resource to complete the operation.
@retval EFI_BUFFER_TOO_SMALL The number of non-empty block is bigger than the
number of input data blocks when build a fragment table.
**/
EFI_STATUS
Ip4IpSecProcessPacket (
IN IP4_SERVICE *IpSb,
IN OUT IP4_HEAD **Head,
IN OUT NET_BUF **Netbuf,
IN OUT UINT8 **Options,
IN OUT UINT32 *OptionsLen,
IN EFI_IPSEC_TRAFFIC_DIR Direction,
IN VOID *Context
);
#endif

View File

@@ -1,45 +0,0 @@
/** @file
Routines used to operate the Ip4Dxe.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _IP4_NV_DATA_H_
#define _IP4_NV_DATA_H_
#include <Guid/Ip4Config2Hii.h>
#define FORMID_MAIN_FORM 1
#define FORMID_DEVICE_FORM 2
#define KEY_ENABLE 0x100
#define KEY_DHCP_ENABLE 0x101
#define KEY_LOCAL_IP 0x102
#define KEY_SUBNET_MASK 0x103
#define KEY_GATE_WAY 0x104
#define KEY_DNS 0x105
#define KEY_SAVE_CHANGES 0x106
#define IP_MIN_SIZE 7
#define IP_MAX_SIZE 15
#define IP4_STR_MAX_SIZE 16
#define ADDRESS_STR_MAX_SIZE 255
#define MAX_IP4_CONFIG_DNS 16
///
/// IP4_CONFIG2_IFR_NVDATA contains the IP4 configure
/// parameters for that NIC.
///
typedef struct {
UINT8 Configure; ///< NIC configure status
UINT8 DhcpEnable; ///< Static or DHCP
CHAR16 StationAddress[IP4_STR_MAX_SIZE]; ///< IP addresses
CHAR16 SubnetMask[IP4_STR_MAX_SIZE]; ///< Subnet address
CHAR16 GatewayAddress[IP4_STR_MAX_SIZE]; ///< Gateway address
CHAR16 DnsAddress[ADDRESS_STR_MAX_SIZE]; ///< DNS server address
} IP4_CONFIG2_IFR_NVDATA;
#endif

View File

@@ -1,204 +0,0 @@
/** @file
IP4 option support functions.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
/**
Validate the IP4 option format for both the packets we received
and will transmit.
@param[in] Option The first byte of the option
@param[in] OptionLen The length of the whole option
@param[in] Rcvd The option is from the packet we received if TRUE,
otherwise the option we wants to transmit.
@retval TRUE The option is properly formatted
@retval FALSE The option is mal-formated
**/
BOOLEAN
Ip4OptionIsValid (
IN UINT8 *Option,
IN UINT32 OptionLen,
IN BOOLEAN Rcvd
)
{
UINT32 Cur;
UINT32 Len;
UINT32 Point;
Cur = 0;
while (Cur < OptionLen) {
switch (Option[Cur]) {
case IP4_OPTION_NOP:
Cur++;
break;
case IP4_OPTION_EOP:
Cur = OptionLen;
break;
case IP4_OPTION_LSRR:
case IP4_OPTION_SSRR:
case IP4_OPTION_RR:
Len = Option[Cur + 1];
Point = Option[Cur + 2];
//
// SRR/RR options are formatted as |Type|Len|Point|Ip1|Ip2|...
//
if ((OptionLen - Cur < Len) || (Len < 3) || ((Len - 3) % 4 != 0)) {
return FALSE;
}
if ((Point > Len + 1) || (Point % 4 != 0)) {
return FALSE;
}
//
// The Point must point pass the last entry if the packet is received
// by us. It must point to 4 if the packet is to be sent by us for
// source route option.
//
if ((Option[Cur] != IP4_OPTION_RR) &&
((Rcvd && (Point != Len + 1)) || (!Rcvd && (Point != 4)))) {
return FALSE;
}
Cur += Len;
break;
default:
Len = Option[Cur + 1];
if ((OptionLen - Cur < Len) || (Len < 2)) {
return FALSE;
}
Cur = Cur + Len;
break;
}
}
return TRUE;
}
/**
Copy the option from the original option to buffer. It
handles the details such as:
1. whether copy the single IP4 option to the first/non-first
fragments.
2. Pad the options copied over to aligned to 4 bytes.
@param[in] Option The original option to copy from
@param[in] OptionLen The length of the original option
@param[in] FirstFragment Whether it is the first fragment
@param[in, out] Buf The buffer to copy options to. NULL
@param[in, out] BufLen The length of the buffer
@retval EFI_SUCCESS The options are copied over
@retval EFI_BUFFER_TOO_SMALL Buf is NULL or BufLen provided is too small.
**/
EFI_STATUS
Ip4CopyOption (
IN UINT8 *Option,
IN UINT32 OptionLen,
IN BOOLEAN FirstFragment,
IN OUT UINT8 *Buf, OPTIONAL
IN OUT UINT32 *BufLen
)
{
UINT8 OptBuf[40];
UINT32 Cur;
UINT32 Next;
UINT8 Type;
UINT32 Len;
ASSERT ((BufLen != NULL) && (OptionLen <= 40));
Cur = 0;
Next = 0;
while (Cur < OptionLen) {
Type = Option[Cur];
Len = Option[Cur + 1];
if (Type == IP4_OPTION_NOP) {
//
// Keep the padding, in case that the sender wants to align
// the option, say, to 4 bytes
//
OptBuf[Next] = IP4_OPTION_NOP;
Next++;
Cur++;
} else if (Type == IP4_OPTION_EOP) {
//
// Don't append the EOP to avoid including only a EOP option
//
break;
} else {
//
// don't copy options that is only valid for the first fragment
//
if (FirstFragment || (Type & IP4_OPTION_COPY_MASK) != 0) {
CopyMem (OptBuf + Next, Option + Cur, Len);
Next += Len;
}
Cur += Len;
}
}
//
// Don't append an EOP only option.
//
if (Next == 0) {
*BufLen = 0;
return EFI_SUCCESS;
}
//
// Append an EOP if the end of option doesn't coincide with the
// end of the IP header, that is, isn't aligned to 4 bytes..
//
if ((Next % 4) != 0) {
OptBuf[Next] = IP4_OPTION_EOP;
Next++;
}
//
// Head length is in the unit of 4 bytes. Now, Len is the
// acutal option length to appear in the IP header.
//
Len = ((Next + 3) &~0x03);
//
// If the buffer is too small, set the BufLen then return
//
if ((Buf == NULL) || (*BufLen < Len)) {
*BufLen = Len;
return EFI_BUFFER_TOO_SMALL;
}
//
// Copy the option to the Buf, zero the buffer first to pad
// the options with NOP to align to 4 bytes.
//
ZeroMem (Buf, Len);
CopyMem (Buf, OptBuf, Next);
*BufLen = Len;
return EFI_SUCCESS;
}

View File

@@ -1,66 +0,0 @@
/** @file
IP4 option support routines.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_OPTION_H__
#define __EFI_IP4_OPTION_H__
#define IP4_OPTION_EOP 0
#define IP4_OPTION_NOP 1
#define IP4_OPTION_LSRR 131 // Loss source and record routing, 10000011
#define IP4_OPTION_SSRR 137 // Strict source and record routing, 10001001
#define IP4_OPTION_RR 7 // Record routing, 00000111
#define IP4_OPTION_COPY_MASK 0x80
/**
Validate the IP4 option format for both the packets we received
and will transmit. It will compute the ICMP error message fields
if the option is mal-formated. But this information isn't used.
@param[in] Option The first byte of the option
@param[in] OptionLen The length of the whole option
@param[in] Rcvd The option is from the packet we received if TRUE,
otherwise the option we wants to transmit.
@retval TRUE The option is properly formatted
@retval FALSE The option is mal-formated
**/
BOOLEAN
Ip4OptionIsValid (
IN UINT8 *Option,
IN UINT32 OptionLen,
IN BOOLEAN Rcvd
);
/**
Copy the option from the original option to buffer. It
handles the details such as:
1. whether copy the single IP4 option to the first/non-first
fragments.
2. Pad the options copied over to aligned to 4 bytes.
@param[in] Option The original option to copy from
@param[in] OptionLen The length of the original option
@param[in] FirstFragment Whether it is the first fragment
@param[in, out] Buf The buffer to copy options to. NULL
@param[in, out] BufLen The length of the buffer
@retval EFI_SUCCESS The options are copied over
@retval EFI_BUFFER_TOO_SMALL Buf is NULL or BufLen provided is too small.
**/
EFI_STATUS
Ip4CopyOption (
IN UINT8 *Option,
IN UINT32 OptionLen,
IN BOOLEAN FirstFragment,
IN OUT UINT8 *Buf, OPTIONAL
IN OUT UINT32 *BufLen
);
#endif

View File

@@ -1,482 +0,0 @@
/** @file
Transmit the IP4 packet.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
UINT16 mIp4Id;
/**
Prepend an IP4 head to the Packet. It will copy the options and
build the IP4 header fields. Used for IP4 fragmentation.
@param Packet The packet to prepend IP4 header to
@param Head The caller supplied header. The caller should set
the following header fields: Tos, TotalLen, Id,
Fragment, Ttl, Protocol, Src and Dst. All the fields
are in host byte order. This function will fill in
the Ver, HeadLen, and checksum.
@param Option The orginal IP4 option to copy from
@param OptLen The length of the IP4 option
@retval EFI_BAD_BUFFER_SIZE There is no enought room in the head space of
Packet.
@retval EFI_SUCCESS The IP4 header is successfully added to the packet.
**/
EFI_STATUS
Ip4PrependHead (
IN OUT NET_BUF *Packet,
IN IP4_HEAD *Head,
IN UINT8 *Option,
IN UINT32 OptLen
)
{
UINT32 HeadLen;
UINT32 Len;
IP4_HEAD *PacketHead;
BOOLEAN FirstFragment;
//
// Prepend the options: first get the option length, then copy it over.
//
HeadLen = 0;
FirstFragment = IP4_FIRST_FRAGMENT (Head->Fragment);
Ip4CopyOption (Option, OptLen, FirstFragment, NULL, &Len);
HeadLen = IP4_MIN_HEADLEN + Len;
ASSERT (((Len % 4) == 0) && (HeadLen <= IP4_MAX_HEADLEN));
PacketHead = (IP4_HEAD *) NetbufAllocSpace (Packet, HeadLen, NET_BUF_HEAD);
if (PacketHead == NULL) {
return EFI_BAD_BUFFER_SIZE;
}
Ip4CopyOption (Option, OptLen, FirstFragment, (UINT8 *) (PacketHead + 1), &Len);
//
// Set the head up, convert the host byte order to network byte order
//
PacketHead->Ver = 4;
PacketHead->HeadLen = (UINT8) (HeadLen >> 2);
PacketHead->Tos = Head->Tos;
PacketHead->TotalLen = HTONS ((UINT16) Packet->TotalSize);
PacketHead->Id = HTONS (Head->Id);
PacketHead->Fragment = HTONS (Head->Fragment);
PacketHead->Checksum = 0;
PacketHead->Ttl = Head->Ttl;
PacketHead->Protocol = Head->Protocol;
PacketHead->Src = HTONL (Head->Src);
PacketHead->Dst = HTONL (Head->Dst);
PacketHead->Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) PacketHead, HeadLen));
Packet->Ip.Ip4 = PacketHead;
return EFI_SUCCESS;
}
/**
Select an interface to send the packet generated in the IP4 driver
itself, that is, not by the requests of IP4 child's consumer. Such
packets include the ICMP echo replies, and other ICMP error packets.
@param[in] IpSb The IP4 service that wants to send the packets.
@param[in] Dst The destination of the packet
@param[in] Src The source of the packet
@return NULL if no proper interface is found, otherwise the interface that
can be used to send the system packet from.
**/
IP4_INTERFACE *
Ip4SelectInterface (
IN IP4_SERVICE *IpSb,
IN IP4_ADDR Dst,
IN IP4_ADDR Src
)
{
IP4_INTERFACE *IpIf;
IP4_INTERFACE *Selected;
LIST_ENTRY *Entry;
//
// Select the interface the Dst is on if one of the connected
// network. Some IP instance may be configured with 0.0.0.0/0,
// don't select that interface now.
//
IpIf = Ip4FindNet (IpSb, Dst);
if ((IpIf != NULL) && (IpIf->Ip != IP4_ALLZERO_ADDRESS)) {
return IpIf;
}
//
// If source is one of the interface address, select it.
//
IpIf = Ip4FindInterface (IpSb, Src);
if ((IpIf != NULL) && (IpIf->Ip != IP4_ALLZERO_ADDRESS)) {
return IpIf;
}
//
// Select a configured interface as the fall back. Always prefer
// an interface with non-zero address.
//
Selected = NULL;
NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
if (IpIf->Configured && ((Selected == NULL) || (Selected->Ip == 0))) {
Selected = IpIf;
}
}
return Selected;
}
/**
The default callback function for system generated packet.
It will free the packet.
@param Ip4Instance The IP4 child that issued the transmission. It most
like is NULL.
@param Packet The packet that transmitted.
@param IoStatus The result of the transmission, succeeded or failed.
@param LinkFlag Not used when transmission. check IP4_FRAME_CALLBACK
for reference.
@param Context The context provided by us
**/
VOID
Ip4SysPacketSent (
IP4_PROTOCOL *Ip4Instance,
NET_BUF *Packet,
EFI_STATUS IoStatus,
UINT32 LinkFlag,
VOID *Context
)
{
NetbufFree (Packet);
}
/**
Transmit an IP4 packet. The packet comes either from the IP4
child's consumer (IpInstance != NULL) or the IP4 driver itself
(IpInstance == NULL). It will route the packet, fragment it,
then transmit all the fragments through some interface.
@param[in] IpSb The IP4 service instance to transmit the packet
@param[in] IpInstance The IP4 child that issues the transmission. It is
NULL if the packet is from the system.
@param[in] Packet The user data to send, excluding the IP header.
@param[in] Head The caller supplied header. The caller should set
the following header fields: Tos, TotalLen, Id, tl,
Fragment, Protocol, Src and Dst. All the fields are
in host byte order. This function will fill in the
Ver, HeadLen, Fragment, and checksum. The Fragment
only need to include the DF flag. Ip4Output will
compute the MF and offset for you.
@param[in] Option The original option to append to the IP headers
@param[in] OptLen The length of the option
@param[in] GateWay The next hop address to transmit packet to.
255.255.255.255 means broadcast.
@param[in] Callback The callback function to issue when transmission
completed.
@param[in] Context The opaque context for the callback
@retval EFI_NO_MAPPING There is no interface to the destination.
@retval EFI_NOT_FOUND There is no route to the destination
@retval EFI_SUCCESS The packet is successfully transmitted.
@retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length +
total data length is greater than MTU (or greater
than the maximum packet size if Token.Packet.TxData.
OverrideData.DoNotFragment is TRUE.)
@retval Others Failed to transmit the packet.
**/
EFI_STATUS
Ip4Output (
IN IP4_SERVICE *IpSb,
IN IP4_PROTOCOL *IpInstance OPTIONAL,
IN NET_BUF *Packet,
IN IP4_HEAD *Head,
IN UINT8 *Option,
IN UINT32 OptLen,
IN IP4_ADDR GateWay,
IN IP4_FRAME_CALLBACK Callback,
IN VOID *Context
)
{
IP4_INTERFACE *IpIf;
IP4_ROUTE_CACHE_ENTRY *CacheEntry;
IP4_ADDR Dest;
EFI_STATUS Status;
NET_BUF *Fragment;
UINT32 Index;
UINT32 HeadLen;
UINT32 PacketLen;
UINT32 Offset;
UINT32 Mtu;
UINT32 Num;
BOOLEAN RawData;
//
// Select an interface/source for system packet, application
// should select them itself.
//
if (IpInstance == NULL) {
IpIf = Ip4SelectInterface (IpSb, Head->Dst, Head->Src);
} else {
IpIf = IpInstance->Interface;
}
if (IpIf == NULL) {
return EFI_NO_MAPPING;
}
if ((Head->Src == IP4_ALLZERO_ADDRESS) && (IpInstance == NULL)) {
Head->Src = IpIf->Ip;
}
//
// Before IPsec process, prepared the IP head.
// If Ip4Output is transmitting RawData, don't update IPv4 header.
//
HeadLen = sizeof (IP4_HEAD) + ((OptLen + 3) & (~0x03));
if ((IpInstance != NULL) && IpInstance->ConfigData.RawData) {
RawData = TRUE;
} else {
Head->HeadLen = (UINT8) (HeadLen >> 2);
Head->Id = mIp4Id++;
Head->Ver = 4;
RawData = FALSE;
}
//
// Call IPsec process.
//
Status = Ip4IpSecProcessPacket (
IpSb,
&Head,
&Packet,
&Option,
&OptLen,
EfiIPsecOutBound,
Context
);
if (EFI_ERROR(Status)) {
return Status;
}
Dest = Head->Dst;
if (IP4_IS_BROADCAST (Ip4GetNetCast (Dest, IpIf)) || (Dest == IP4_ALLONE_ADDRESS)) {
//
// Set the gateway to local broadcast if the Dest is
// the broadcast address for the connected network or
// it is local broadcast.
//
GateWay = IP4_ALLONE_ADDRESS;
} else if (IP4_IS_MULTICAST (Dest)) {
//
// Set the gateway to the destination if it is an multicast
// address. The IP4_INTERFACE won't consult ARP to send local
// broadcast and multicast.
//
GateWay = Head->Dst;
} else if (GateWay == IP4_ALLZERO_ADDRESS) {
//
// Route the packet unless overrided, that is, GateWay isn't zero.
//
if (IpInstance == NULL) {
CacheEntry = Ip4Route (IpSb->DefaultRouteTable, Head->Dst, Head->Src, IpIf->SubnetMask, TRUE);
} else {
CacheEntry = Ip4Route (IpInstance->RouteTable, Head->Dst, Head->Src, IpIf->SubnetMask, FALSE);
//
// If failed to route the packet by using the instance's route table,
// try to use the default route table.
//
if (CacheEntry == NULL) {
CacheEntry = Ip4Route (IpSb->DefaultRouteTable, Head->Dst, Head->Src, IpIf->SubnetMask, TRUE);
}
}
if (CacheEntry == NULL) {
return EFI_NOT_FOUND;
}
GateWay = CacheEntry->NextHop;
Ip4FreeRouteCacheEntry (CacheEntry);
}
//
// OK, selected the source and route, fragment the packet then send
// them. Tag each fragment other than the first one as spawn from it.
//
Mtu = IpSb->MaxPacketSize + sizeof (IP4_HEAD);
if (Packet->TotalSize + HeadLen > Mtu) {
//
// Fragmentation is diabled for RawData mode.
//
if (RawData) {
return EFI_BAD_BUFFER_SIZE;
}
//
// Packet is fragmented from the tail to the head, that is, the
// first frame sent is the last fragment of the packet. The first
// fragment is NOT sent in this loop. First compute how many
// fragments there are.
//
Mtu = (Mtu - HeadLen) & (~0x07);
Num = (Packet->TotalSize + Mtu - 1) / Mtu;
//
// Initialize the packet length and Offset. Other than the last
// fragment, the packet length equals to MTU. The offset is always
// aligned to MTU.
//
PacketLen = Packet->TotalSize - (Num - 1) * Mtu;
Offset = Mtu * (Num - 1);
for (Index = 0; Index < Num - 1; Index++, Offset -= Mtu) {
Fragment = NetbufGetFragment (Packet, Offset, PacketLen, IP4_MAX_HEADLEN);
if (Fragment == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
//
// Update the header's fragment. The caller fills the IP4 header
// fields that are required by Ip4PrependHead except the fragment.
//
Head->Fragment = IP4_HEAD_FRAGMENT_FIELD (FALSE, (Index != 0), Offset);
Ip4PrependHead (Fragment, Head, Option, OptLen);
//
// Transmit the fragments, pass the Packet address as the context.
// So, we can find all the fragments spawned from the Packet by
// compare the NetBuf and Context to the Packet.
//
Status = Ip4SendFrame (
IpIf,
IpInstance,
Fragment,
GateWay,
Ip4SysPacketSent,
Packet,
IpSb
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
PacketLen = Mtu;
}
//
// Trim the already sent data, then adjust the head's fragment field.
//
NetbufTrim (Packet, Packet->TotalSize - Mtu, FALSE);
Head->Fragment = IP4_HEAD_FRAGMENT_FIELD (FALSE, TRUE, 0);
}
//
// Send the first fragment, it is either the orginal packet, or the
// first fragment of a fragmented packet. It seems that there is a subtle
// bug here: what if the caller free the packet in Callback and IpIf (or
// MNP child used by that interface) still holds the fragments and try
// to access the data? The caller can free the packet if it recycles the
// consumer's (such as UDP) data in the Callback. But this can't happen.
// The detailed sequence is:
// 1. for the packets generated by IP4 driver itself:
// The Callback is Ip4SysPacketSent, which is the same as the
// fragments' callback. Ip4SysPacketSent simply calls NetbufFree
// to release its reference to the packet. So, no problem for
// system packets.
//
// 2. for the upper layer's packets (use UDP as an example):
// UDP requests the IP layer to transmit some data which is
// wrapped in an asynchronous token, the token is wrapped
// in IP4_TXTOKEN_WRAP by IP4. IP4 also wrap the user's data
// in a net buffer, which is Packet we get here. IP4_TXTOKEN_WRAP
// is bound with the Packet. It will only be freed when all
// the references to Packet have been released. Upon then, the
// Packet's OnFree callback will release the IP4_TXTOKEN_WRAP,
// and singal the user's recycle event. So, also no problem for
// upper layer's packets.
//
Ip4PrependHead (Packet, Head, Option, OptLen);
Status = Ip4SendFrame (IpIf, IpInstance, Packet, GateWay, Callback, Context, IpSb);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
return EFI_SUCCESS;
ON_ERROR:
Ip4CancelPacket (IpIf, Packet, Status);
return Status;
}
/**
The filter function to find a packet and all its fragments.
The packet's fragments have their Context set to the packet.
@param[in] Frame The frames hold by the low level interface
@param[in] Context Context to the function, which is the packet.
@retval TRUE This is the packet to cancel or its fragments.
@retval FALSE This is unrelated packet.
**/
BOOLEAN
Ip4CancelPacketFragments (
IN IP4_LINK_TX_TOKEN *Frame,
IN VOID *Context
)
{
if ((Frame->Packet == (NET_BUF *) Context) || (Frame->Context == Context)) {
return TRUE;
}
return FALSE;
}
/**
Cancel the Packet and all its fragments.
@param IpIf The interface from which the Packet is sent
@param Packet The Packet to cancel
@param IoStatus The status returns to the sender.
**/
VOID
Ip4CancelPacket (
IN IP4_INTERFACE *IpIf,
IN NET_BUF *Packet,
IN EFI_STATUS IoStatus
)
{
Ip4CancelFrames (IpIf, IoStatus, Ip4CancelPacketFragments, Packet);
}

View File

@@ -1,120 +0,0 @@
/** @file
Copyright (c) 2005 - 2006, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_OUTPUT_H__
#define __EFI_IP4_OUTPUT_H__
/**
The default callback function for system generated packet.
It will free the packet.
@param Ip4Instance The IP4 child that issued the transmission. It most
like is NULL.
@param Packet The packet that transmitted.
@param IoStatus The result of the transmission, succeeded or failed.
@param LinkFlag Not used when transmission. check IP4_FRAME_CALLBACK
for reference.
@param Context The context provided by us
**/
VOID
Ip4SysPacketSent (
IP4_PROTOCOL *Ip4Instance,
NET_BUF *Packet,
EFI_STATUS IoStatus,
UINT32 LinkFlag,
VOID *Context
);
/**
Transmit an IP4 packet. The packet comes either from the IP4
child's consumer (IpInstance != NULL) or the IP4 driver itself
(IpInstance == NULL). It will route the packet, fragment it,
then transmit all the fragments through some interface.
@param[in] IpSb The IP4 service instance to transmit the packet
@param[in] IpInstance The IP4 child that issues the transmission. It is
NULL if the packet is from the system.
@param[in] Packet The user data to send, excluding the IP header.
@param[in] Head The caller supplied header. The caller should set
the following header fields: Tos, TotalLen, Id, tl,
Fragment, Protocol, Src and Dst. All the fields are
in host byte order. This function will fill in the
Ver, HeadLen, Fragment, and checksum. The Fragment
only need to include the DF flag. Ip4Output will
compute the MF and offset for you.
@param[in] Option The original option to append to the IP headers
@param[in] OptLen The length of the option
@param[in] GateWay The next hop address to transmit packet to.
255.255.255.255 means broadcast.
@param[in] Callback The callback function to issue when transmission
completed.
@param[in] Context The opaque context for the callback
@retval EFI_NO_MAPPING There is no interface to the destination.
@retval EFI_NOT_FOUND There is no route to the destination
@retval EFI_SUCCESS The packet is successfully transmitted.
@retval Others Failed to transmit the packet.
**/
EFI_STATUS
Ip4Output (
IN IP4_SERVICE *IpSb,
IN IP4_PROTOCOL *IpInstance OPTIONAL,
IN NET_BUF *Packet,
IN IP4_HEAD *Head,
IN UINT8 *Option,
IN UINT32 OptLen,
IN IP4_ADDR GateWay,
IN IP4_FRAME_CALLBACK Callback,
IN VOID *Context
);
/**
Cancel the Packet and all its fragments.
@param IpIf The interface from which the Packet is sent
@param Packet The Packet to cancel
@param IoStatus The status returns to the sender.
**/
VOID
Ip4CancelPacket (
IN IP4_INTERFACE *IpIf,
IN NET_BUF *Packet,
IN EFI_STATUS IoStatus
);
/**
Prepend an IP4 head to the Packet. It will copy the options and
build the IP4 header fields. Used for IP4 fragmentation.
@param Packet The packet to prepend IP4 header to
@param Head The caller supplied header. The caller should set
the following header fields: Tos, TotalLen, Id,
Fragment, Ttl, Protocol, Src and Dst. All the fields
are in host byte order. This function will fill in
the Ver, HeadLen, and checksum.
@param Option The orginal IP4 option to copy from
@param OptLen The length of the IP4 option
@retval EFI_BAD_BUFFER_SIZE There is no enought room in the head space of
Packet.
@retval EFI_SUCCESS The IP4 header is successfully added to the packet.
**/
EFI_STATUS
Ip4PrependHead (
IN OUT NET_BUF *Packet,
IN IP4_HEAD *Head,
IN UINT8 *Option,
IN UINT32 OptLen
);
extern UINT16 mIp4Id;
#endif

View File

@@ -1,673 +0,0 @@
/** @file
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Ip4Impl.h"
/**
Allocate a route entry then initialize it with the Dest/Netmaks
and Gateway.
@param[in] Dest The destination network
@param[in] Netmask The destination network mask
@param[in] GateWay The nexthop address
@return NULL if failed to allocate memeory, otherwise the newly created
route entry.
**/
IP4_ROUTE_ENTRY *
Ip4CreateRouteEntry (
IN IP4_ADDR Dest,
IN IP4_ADDR Netmask,
IN IP4_ADDR GateWay
)
{
IP4_ROUTE_ENTRY *RtEntry;
RtEntry = AllocatePool (sizeof (IP4_ROUTE_ENTRY));
if (RtEntry == NULL) {
return NULL;
}
InitializeListHead (&RtEntry->Link);
RtEntry->RefCnt = 1;
RtEntry->Dest = Dest;
RtEntry->Netmask = Netmask;
RtEntry->NextHop = GateWay;
RtEntry->Flag = 0;
return RtEntry;
}
/**
Free the route table entry. It is reference counted.
@param RtEntry The route entry to free.
**/
VOID
Ip4FreeRouteEntry (
IN IP4_ROUTE_ENTRY *RtEntry
)
{
ASSERT (RtEntry->RefCnt > 0);
if (--RtEntry->RefCnt == 0) {
FreePool (RtEntry);
}
}
/**
Allocate and initialize an IP4 route cache entry.
@param[in] Dst The destination address
@param[in] Src The source address
@param[in] GateWay The next hop address
@param[in] Tag The tag from the caller. This marks all the cache
entries spawned from one route table entry.
@return NULL if failed to allocate memory for the cache, other point
to the created route cache entry.
**/
IP4_ROUTE_CACHE_ENTRY *
Ip4CreateRouteCacheEntry (
IN IP4_ADDR Dst,
IN IP4_ADDR Src,
IN IP4_ADDR GateWay,
IN UINTN Tag
)
{
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;
RtCacheEntry = AllocatePool (sizeof (IP4_ROUTE_CACHE_ENTRY));
if (RtCacheEntry == NULL) {
return NULL;
}
InitializeListHead (&RtCacheEntry->Link);
RtCacheEntry->RefCnt = 1;
RtCacheEntry->Dest = Dst;
RtCacheEntry->Src = Src;
RtCacheEntry->NextHop = GateWay;
RtCacheEntry->Tag = Tag;
return RtCacheEntry;
}
/**
Free the route cache entry. It is reference counted.
@param RtCacheEntry The route cache entry to free.
**/
VOID
Ip4FreeRouteCacheEntry (
IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry
)
{
ASSERT (RtCacheEntry->RefCnt > 0);
if (--RtCacheEntry->RefCnt == 0) {
FreePool (RtCacheEntry);
}
}
/**
Initialize an empty route cache table.
@param[in, out] RtCache The rotue cache table to initialize.
**/
VOID
Ip4InitRouteCache (
IN OUT IP4_ROUTE_CACHE *RtCache
)
{
UINT32 Index;
for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
InitializeListHead (&(RtCache->CacheBucket[Index]));
}
}
/**
Clean up a route cache, that is free all the route cache
entries enqueued in the cache.
@param[in] RtCache The route cache table to clean up
**/
VOID
Ip4CleanRouteCache (
IN IP4_ROUTE_CACHE *RtCache
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;
UINT32 Index;
for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtCache->CacheBucket[Index])) {
RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);
RemoveEntryList (Entry);
Ip4FreeRouteCacheEntry (RtCacheEntry);
}
}
}
/**
Create an empty route table, includes its internal route cache
@return NULL if failed to allocate memory for the route table, otherwise
the point to newly created route table.
**/
IP4_ROUTE_TABLE *
Ip4CreateRouteTable (
VOID
)
{
IP4_ROUTE_TABLE *RtTable;
UINT32 Index;
RtTable = AllocatePool (sizeof (IP4_ROUTE_TABLE));
if (RtTable == NULL) {
return NULL;
}
RtTable->RefCnt = 1;
RtTable->TotalNum = 0;
for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
InitializeListHead (&(RtTable->RouteArea[Index]));
}
RtTable->Next = NULL;
Ip4InitRouteCache (&RtTable->Cache);
return RtTable;
}
/**
Free the route table and its associated route cache. Route
table is reference counted.
@param[in] RtTable The route table to free.
**/
VOID
Ip4FreeRouteTable (
IN IP4_ROUTE_TABLE *RtTable
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP4_ROUTE_ENTRY *RtEntry;
UINT32 Index;
ASSERT (RtTable->RefCnt > 0);
if (--RtTable->RefCnt > 0) {
return ;
}
//
// Free all the route table entry and its route cache.
//
for (Index = 0; Index <= IP4_MASK_MAX; Index++) {
NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
RemoveEntryList (Entry);
Ip4FreeRouteEntry (RtEntry);
}
}
Ip4CleanRouteCache (&RtTable->Cache);
FreePool (RtTable);
}
/**
Remove all the cache entries bearing the Tag. When a route cache
entry is created, it is tagged with the address of route entry
from which it is spawned. When a route entry is deleted, the cache
entries spawned from it are also deleted.
@param RtCache Route cache to remove the entries from
@param Tag The Tag of the entries to remove
**/
VOID
Ip4PurgeRouteCache (
IN OUT IP4_ROUTE_CACHE *RtCache,
IN UINTN Tag
)
{
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;
UINT32 Index;
for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {
NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtCache->CacheBucket[Index]) {
RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);
if (RtCacheEntry->Tag == Tag) {
RemoveEntryList (Entry);
Ip4FreeRouteCacheEntry (RtCacheEntry);
}
}
}
}
/**
Add a route entry to the route table. All the IP4_ADDRs are in
host byte order.
@param[in, out] RtTable Route table to add route to
@param[in] Dest The destination of the network
@param[in] Netmask The netmask of the destination
@param[in] Gateway The next hop address
@retval EFI_ACCESS_DENIED The same route already exists
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry
@retval EFI_SUCCESS The route is added successfully.
**/
EFI_STATUS
Ip4AddRoute (
IN OUT IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Netmask,
IN IP4_ADDR Gateway
)
{
LIST_ENTRY *Head;
LIST_ENTRY *Entry;
IP4_ROUTE_ENTRY *RtEntry;
//
// All the route entries with the same netmask length are
// linke to the same route area
//
Head = &(RtTable->RouteArea[NetGetMaskLength (Netmask)]);
//
// First check whether the route exists
//
NET_LIST_FOR_EACH (Entry, Head) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
if (IP4_NET_EQUAL (RtEntry->Dest, Dest, Netmask) && (RtEntry->NextHop == Gateway)) {
return EFI_ACCESS_DENIED;
}
}
//
// Create a route entry and insert it to the route area.
//
RtEntry = Ip4CreateRouteEntry (Dest, Netmask, Gateway);
if (RtEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (Gateway == IP4_ALLZERO_ADDRESS) {
RtEntry->Flag = IP4_DIRECT_ROUTE;
}
InsertHeadList (Head, &RtEntry->Link);
RtTable->TotalNum++;
return EFI_SUCCESS;
}
/**
Remove a route entry and all the route caches spawn from it.
@param RtTable The route table to remove the route from
@param Dest The destination network
@param Netmask The netmask of the Dest
@param Gateway The next hop address
@retval EFI_SUCCESS The route entry is successfully removed
@retval EFI_NOT_FOUND There is no route entry in the table with that
properity.
**/
EFI_STATUS
Ip4DelRoute (
IN OUT IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Netmask,
IN IP4_ADDR Gateway
)
{
LIST_ENTRY *Head;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP4_ROUTE_ENTRY *RtEntry;
Head = &(RtTable->RouteArea[NetGetMaskLength (Netmask)]);
NET_LIST_FOR_EACH_SAFE (Entry, Next, Head) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
if (IP4_NET_EQUAL (RtEntry->Dest, Dest, Netmask) && (RtEntry->NextHop == Gateway)) {
Ip4PurgeRouteCache (&RtTable->Cache, (UINTN) RtEntry);
RemoveEntryList (Entry);
Ip4FreeRouteEntry (RtEntry);
RtTable->TotalNum--;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Find a route cache with the dst and src. This is used by ICMP
redirect messasge process. All kinds of redirect is treated as
host redirect according to RFC1122. So, only route cache entries
are modified according to the ICMP redirect message.
@param[in] RtTable The route table to search the cache for
@param[in] Dest The destination address
@param[in] Src The source address
@return NULL if no route entry to the (Dest, Src). Otherwise the point
to the correct route cache entry.
**/
IP4_ROUTE_CACHE_ENTRY *
Ip4FindRouteCache (
IN IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Src
)
{
LIST_ENTRY *Entry;
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;
UINT32 Index;
Index = IP4_ROUTE_CACHE_HASH (Dest, Src);
NET_LIST_FOR_EACH (Entry, &RtTable->Cache.CacheBucket[Index]) {
RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);
if ((RtCacheEntry->Dest == Dest) && (RtCacheEntry->Src == Src)) {
NET_GET_REF (RtCacheEntry);
return RtCacheEntry;
}
}
return NULL;
}
/**
Search the route table for a most specific match to the Dst. It searches
from the longest route area (mask length == 32) to the shortest route area
(default routes). In each route area, it will first search the instance's
route table, then the default route table. This is required by the following
requirements:
1. IP search the route table for a most specific match
2. The local route entries have precedence over the default route entry.
@param[in] RtTable The route table to search from
@param[in] Dst The destionation address to search
@return NULL if no route matches the Dst, otherwise the point to the
most specific route to the Dst.
**/
IP4_ROUTE_ENTRY *
Ip4FindRouteEntry (
IN IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dst
)
{
LIST_ENTRY *Entry;
IP4_ROUTE_ENTRY *RtEntry;
IP4_ROUTE_TABLE *Table;
INTN Index;
RtEntry = NULL;
for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
for (Table = RtTable; Table != NULL; Table = Table->Next) {
NET_LIST_FOR_EACH (Entry, &Table->RouteArea[Index]) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
if (IP4_NET_EQUAL (RtEntry->Dest, Dst, RtEntry->Netmask)) {
NET_GET_REF (RtEntry);
return RtEntry;
}
}
}
}
return NULL;
}
/**
Search the route table to route the packet. Return/create a route
cache if there is a route to the destination.
@param[in] RtTable The route table to search from
@param[in] Dest The destination address to search for
@param[in] Src The source address to search for
@param[in] SubnetMask The subnet mask of the Src address, this field is
used to check if the station is using /32 subnet.
@param[in] AlwaysTryDestAddr Always try to use the dest address as next hop even
though we can't find a matching route entry. This
field is only valid when using /32 subnet.
@return NULL if failed to route packet, otherwise a route cache
entry that can be used to route packet.
**/
IP4_ROUTE_CACHE_ENTRY *
Ip4Route (
IN IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Src,
IN IP4_ADDR SubnetMask,
IN BOOLEAN AlwaysTryDestAddr
)
{
LIST_ENTRY *Head;
LIST_ENTRY *Entry;
LIST_ENTRY *Next;
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;
IP4_ROUTE_CACHE_ENTRY *Cache;
IP4_ROUTE_ENTRY *RtEntry;
IP4_ADDR NextHop;
UINT32 Count;
ASSERT (RtTable != NULL);
Head = &RtTable->Cache.CacheBucket[IP4_ROUTE_CACHE_HASH (Dest, Src)];
RtCacheEntry = Ip4FindRouteCache (RtTable, Dest, Src);
//
// If found, promote the cache entry to the head of the hash bucket. LRU
//
if (RtCacheEntry != NULL) {
RemoveEntryList (&RtCacheEntry->Link);
InsertHeadList (Head, &RtCacheEntry->Link);
return RtCacheEntry;
}
//
// Search the route table for the most specific route
//
RtEntry = Ip4FindRouteEntry (RtTable, Dest);
if (RtEntry == NULL) {
if (SubnetMask != IP4_ALLONE_ADDRESS) {
return NULL;
} else if (!AlwaysTryDestAddr) {
return NULL;
}
}
//
// Found a route to the Dest, if it is a direct route, the packet
// will be sent directly to the destination, such as for connected
// network. Otherwise, it is an indirect route, the packet will be
// sent to the next hop router.
//
// When using /32 subnet mask, the packet will always be sent to the direct
// destination first, if we can't find a matching route cache.
//
if (SubnetMask == IP4_ALLONE_ADDRESS || ((RtEntry->Flag & IP4_DIRECT_ROUTE) != 0)) {
NextHop = Dest;
} else {
NextHop = RtEntry->NextHop;
}
if (RtEntry != NULL) {
Ip4FreeRouteEntry (RtEntry);
}
//
// Create a route cache entry, and tag it as spawned from this route entry
// For /32 subnet mask, the default route in RtEntry will be used if failed
// to send the packet to driect destination address.
//
RtCacheEntry = Ip4CreateRouteCacheEntry (Dest, Src, NextHop, (UINTN) RtEntry);
if (RtCacheEntry == NULL) {
return NULL;
}
InsertHeadList (Head, &RtCacheEntry->Link);
NET_GET_REF (RtCacheEntry);
//
// Each bucket of route cache can contain at most 64 entries.
// Remove the entries at the tail of the bucket. These entries
// are likely to be used least.
//
Count = 0;
NET_LIST_FOR_EACH_SAFE (Entry, Next, Head) {
if (++Count < IP4_ROUTE_CACHE_MAX) {
continue;
}
Cache = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);
RemoveEntryList (Entry);
Ip4FreeRouteCacheEntry (Cache);
}
return RtCacheEntry;
}
/**
Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of
GetModeData. The EFI_IP4_ROUTE_TABLE is clumsy to use in the
internal operation of the IP4 driver.
@param[in] IpInstance The IP4 child that requests the route table.
@retval EFI_SUCCESS The route table is successfully build
@retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the rotue table.
**/
EFI_STATUS
Ip4BuildEfiRouteTable (
IN IP4_PROTOCOL *IpInstance
)
{
LIST_ENTRY *Entry;
IP4_ROUTE_TABLE *RtTable;
IP4_ROUTE_ENTRY *RtEntry;
EFI_IP4_ROUTE_TABLE *Table;
UINT32 Count;
INT32 Index;
RtTable = IpInstance->RouteTable;
if (IpInstance->EfiRouteTable != NULL) {
FreePool (IpInstance->EfiRouteTable);
IpInstance->EfiRouteTable = NULL;
IpInstance->EfiRouteCount = 0;
}
Count = RtTable->TotalNum;
if (RtTable->Next != NULL) {
Count += RtTable->Next->TotalNum;
}
if (Count == 0) {
return EFI_SUCCESS;
}
Table = AllocatePool (sizeof (EFI_IP4_ROUTE_TABLE) * Count);
if (Table == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Copy the route entry to EFI route table. Keep the order of
// route entry copied from most specific to default route. That
// is, interlevel the route entry from the instance's route area
// and those from the default route table's route area.
//
Count = 0;
for (Index = IP4_MASK_MAX; Index >= 0; Index--) {
for (RtTable = IpInstance->RouteTable; RtTable != NULL; RtTable = RtTable->Next) {
NET_LIST_FOR_EACH (Entry, &(RtTable->RouteArea[Index])) {
RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);
EFI_IP4 (Table[Count].SubnetAddress) = HTONL (RtEntry->Dest & RtEntry->Netmask);
EFI_IP4 (Table[Count].SubnetMask) = HTONL (RtEntry->Netmask);
EFI_IP4 (Table[Count].GatewayAddress) = HTONL (RtEntry->NextHop);
Count++;
}
}
}
IpInstance->EfiRouteTable = Table;
IpInstance->EfiRouteCount = Count;
return EFI_SUCCESS;
}

View File

@@ -1,225 +0,0 @@
/** @file
EFI IP4 route table and route cache table defintions.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_IP4_ROUTE_H__
#define __EFI_IP4_ROUTE_H__
#include "Ip4Common.h"
#define IP4_DIRECT_ROUTE 0x00000001
#define IP4_ROUTE_CACHE_HASH_VALUE 31
#define IP4_ROUTE_CACHE_MAX 64 // Max NO. of cache entry per hash bucket
#define IP4_ROUTE_CACHE_HASH(Dst, Src) (((Dst) ^ (Src)) % IP4_ROUTE_CACHE_HASH_VALUE)
///
/// The route entry in the route table. Dest/Netmask is the destion
/// network. The nexthop is the gateway to send the packet to in
/// order to reach the Dest/Netmask. If the Flag has IP4_DIRECT_ROUTE
/// on, the gateway is the destination of the IP packet itself. Route
/// enties of the connected network have the flag on.
///
typedef struct {
LIST_ENTRY Link;
INTN RefCnt;
IP4_ADDR Dest;
IP4_ADDR Netmask;
IP4_ADDR NextHop;
UINT32 Flag;
} IP4_ROUTE_ENTRY;
///
/// The route cache entry. The route cache entry is optional.
/// But it is necessary to support the ICMP redirect message.
/// Check Ip4ProcessIcmpRedirect for information.
///
/// The cache entry field Tag is used to tag all the route
/// cache entry spawned from a route table entry. This makes
/// it simple to delete all the route cache entries from a
/// to-be-deleted route entry.
///
typedef struct {
LIST_ENTRY Link;
INTN RefCnt;
IP4_ADDR Dest;
IP4_ADDR Src;
IP4_ADDR NextHop;
UINTN Tag;
} IP4_ROUTE_CACHE_ENTRY;
///
/// The route cache table is organized as a hash table. Each
/// IP4 route table has a embedded route cache. For now the
/// route cache and route table are binded togehter. But keep
/// the route cache a seperated structure in case we want to
/// detach them later.
///
typedef struct {
LIST_ENTRY CacheBucket[IP4_ROUTE_CACHE_HASH_VALUE];
} IP4_ROUTE_CACHE;
///
/// Each IP4 instance has its own route table. Each ServiceBinding
/// instance has a default route table and default address.
///
/// All the route table entries with the same mask are linked
/// together in one route area. For example, RouteArea[0] contains
/// the default routes. A route table also contains a route cache.
///
typedef struct _IP4_ROUTE_TABLE IP4_ROUTE_TABLE;
struct _IP4_ROUTE_TABLE {
INTN RefCnt;
UINT32 TotalNum;
LIST_ENTRY RouteArea[IP4_MASK_NUM];
IP4_ROUTE_TABLE *Next;
IP4_ROUTE_CACHE Cache;
};
/**
Create an empty route table, includes its internal route cache
@return NULL if failed to allocate memory for the route table, otherwise
the point to newly created route table.
**/
IP4_ROUTE_TABLE *
Ip4CreateRouteTable (
VOID
);
/**
Free the route table and its associated route cache. Route
table is reference counted.
@param[in] RtTable The route table to free.
**/
VOID
Ip4FreeRouteTable (
IN IP4_ROUTE_TABLE *RtTable
);
/**
Add a route entry to the route table. All the IP4_ADDRs are in
host byte order.
@param[in, out] RtTable Route table to add route to
@param[in] Dest The destination of the network
@param[in] Netmask The netmask of the destination
@param[in] Gateway The next hop address
@retval EFI_ACCESS_DENIED The same route already exists
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry
@retval EFI_SUCCESS The route is added successfully.
**/
EFI_STATUS
Ip4AddRoute (
IN OUT IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Netmask,
IN IP4_ADDR Gateway
);
/**
Remove a route entry and all the route caches spawn from it.
@param RtTable The route table to remove the route from
@param Dest The destination network
@param Netmask The netmask of the Dest
@param Gateway The next hop address
@retval EFI_SUCCESS The route entry is successfully removed
@retval EFI_NOT_FOUND There is no route entry in the table with that
properity.
**/
EFI_STATUS
Ip4DelRoute (
IN OUT IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Netmask,
IN IP4_ADDR Gateway
);
/**
Find a route cache with the dst and src. This is used by ICMP
redirect messasge process. All kinds of redirect is treated as
host redirect according to RFC1122. So, only route cache entries
are modified according to the ICMP redirect message.
@param[in] RtTable The route table to search the cache for
@param[in] Dest The destination address
@param[in] Src The source address
@return NULL if no route entry to the (Dest, Src). Otherwise the point
to the correct route cache entry.
**/
IP4_ROUTE_CACHE_ENTRY *
Ip4FindRouteCache (
IN IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Src
);
/**
Free the route cache entry. It is reference counted.
@param RtCacheEntry The route cache entry to free.
**/
VOID
Ip4FreeRouteCacheEntry (
IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry
);
/**
Search the route table to route the packet. Return/create a route
cache if there is a route to the destination.
@param[in] RtTable The route table to search from
@param[in] Dest The destination address to search for
@param[in] Src The source address to search for
@param[in] SubnetMask The subnet mask of the Src address, this field is
used to check if the station is using /32 subnet.
@param[in] AlwaysTryDestAddr Always try to use the dest address as next hop even
though we can't find a matching route entry. This
field is only valid when using /32 subnet.
@return NULL if failed to route packet, otherwise a route cache
entry that can be used to route packet.
**/
IP4_ROUTE_CACHE_ENTRY *
Ip4Route (
IN IP4_ROUTE_TABLE *RtTable,
IN IP4_ADDR Dest,
IN IP4_ADDR Src,
IN IP4_ADDR SubnetMask,
IN BOOLEAN AlwaysTryDestAddr
);
/**
Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of
GetModeData. The EFI_IP4_ROUTE_TABLE is clumsy to use in the
internal operation of the IP4 driver.
@param[in] IpInstance The IP4 child that requests the route table.
@retval EFI_SUCCESS The route table is successfully build
@retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the rotue table.
**/
EFI_STATUS
Ip4BuildEfiRouteTable (
IN IP4_PROTOCOL *IpInstance
);
#endif

View File

@@ -1,341 +0,0 @@
/** @file
UEFI Component Name(2) protocol implementation for MnpDxe driver.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "MnpImpl.h"
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName = {
MnpComponentNameGetDriverName,
MnpComponentNameGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) MnpComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) MnpComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[] = {
{
"eng;en",
L"MNP Network Service Driver"
},
{
NULL,
NULL
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
MnpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mMnpDriverNameTable,
DriverName,
(BOOLEAN) (This == &gMnpComponentName)
);
}
/**
Update the component name for the MNP child handle.
@param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL.
@retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
@retval EFI_INVALID_PARAMETER The input parameter is invalid.
**/
EFI_STATUS
UpdateName (
IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
CHAR16 HandleName[80];
EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;
EFI_SIMPLE_NETWORK_MODE SnpModeData;
UINTN OffSet;
UINTN Index;
if (Mnp == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (Mnp);
//
// Format the child name into the string buffer as:
// MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0)
//
Status = Mnp->GetModeData (Mnp, &MnpConfigData, &SnpModeData);
if (!EFI_ERROR (Status)) {
OffSet = 0;
//
// Print the MAC address.
//
OffSet += UnicodeSPrint (
HandleName,
sizeof (HandleName),
L"MNP (MAC="
);
for (Index = 0; Index < SnpModeData.HwAddressSize; Index++) {
OffSet += UnicodeSPrint (
HandleName + OffSet,
sizeof (HandleName) - OffSet * sizeof (CHAR16),
L"%02X-",
SnpModeData.CurrentAddress.Addr[Index]
);
}
ASSERT (OffSet > 0);
//
// Remove the last '-'
//
OffSet--;
//
// Print the ProtocolType and VLAN ID for this instance.
//
OffSet += UnicodeSPrint (
HandleName + OffSet,
sizeof (HandleName) - OffSet * sizeof (CHAR16),
L", ProtocolType=0x%X, VlanId=%d)",
MnpConfigData.ProtocolTypeFilter,
Instance->MnpServiceData->VlanId
);
} else if (Status == EFI_NOT_STARTED) {
UnicodeSPrint (
HandleName,
sizeof (HandleName),
L"MNP (Not started)"
);
} else {
return Status;
}
if (gMnpControllerNameTable != NULL) {
FreeUnicodeStringTable (gMnpControllerNameTable);
gMnpControllerNameTable = NULL;
}
Status = AddUnicodeString2 (
"eng",
gMnpComponentName.SupportedLanguages,
&gMnpControllerNameTable,
HandleName,
TRUE
);
if (EFI_ERROR (Status)) {
return Status;
}
return AddUnicodeString2 (
"en",
gMnpComponentName2.SupportedLanguages,
&gMnpControllerNameTable,
HandleName,
FALSE
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
Currently not implemented.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the user readable name
specified by This, ControllerHandle, ChildHandle,
and Language was returned in ControllerName.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
MnpComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
//
// Only provide names for MNP child handles.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver is currently managing ControllerHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gMnpDriverBinding.DriverBindingHandle,
&gEfiSimpleNetworkProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Make sure this driver produced ChildHandle
//
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Retrieve an instance of a produced protocol from ChildHandle
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiManagedNetworkProtocolGuid,
(VOID **)&Mnp,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Update the component name for this child handle.
//
Status = UpdateName (Mnp);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
gMnpControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gMnpComponentName)
);
}

View File

@@ -1,144 +0,0 @@
/** @file
The header file of UEFI Component Name(2) protocol.
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _COMPONENT_NAME_H_
#define _COMPONENT_NAME_H_
#include <Protocol/ComponentName.h>
#include <Protocol/ComponentName2.h>
extern EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2;
extern EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName;
extern EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable;
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
MnpComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
Currently not implemented.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the user readable name
specified by This, ControllerHandle, ChildHandle,
and Language was returned in ControllerName.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
MnpComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,683 +0,0 @@
/** @file
Implementation of driver entry point and driver binding protocol.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "MnpDriver.h"
#include "MnpImpl.h"
#include "MnpVlan.h"
EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {
MnpDriverBindingSupported,
MnpDriverBindingStart,
MnpDriverBindingStop,
0xa,
NULL,
NULL
};
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@param[in] Entry The entry to be removed.
@param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
@retval EFI_SUCCESS The entry has been removed successfully.
@retval Others Fail to remove the entry.
**/
EFI_STATUS
EFIAPI
MnpDestroyServiceDataEntry (
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
MNP_SERVICE_DATA *MnpServiceData;
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
return MnpDestroyServiceData (MnpServiceData);
}
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@param[in] Entry The entry to be removed.
@param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
@retval EFI_SUCCESS The entry has been removed successfully.
@retval Others Fail to remove the entry.
**/
EFI_STATUS
EFIAPI
MnpDestroyServiceChildEntry (
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
MNP_SERVICE_DATA *MnpServiceData;
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
return MnpDestroyServiceChild (MnpServiceData);
}
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_ALREADY_STARTED This driver is already running on this device.
@retval Others This driver does not support this device.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
//
// Test to open the Simple Network protocol BY_DRIVER.
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleNetworkProtocolGuid,
(VOID **) &Snp,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close the openned SNP protocol.
//
gBS->CloseProtocol (
ControllerHandle,
&gEfiSimpleNetworkProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make drivers as small
as possible, there are a few calling restrictions for this service.
ConnectController() must follow these calling restrictions. If any other
agent wishes to call Start() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle.
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data.
@retval Others This driver does not support this device.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
EFI_STATUS Status;
MNP_SERVICE_DATA *MnpServiceData;
MNP_DEVICE_DATA *MnpDeviceData;
LIST_ENTRY *Entry;
VLAN_TCI *VlanVariable;
UINTN NumberOfVlan;
UINTN Index;
VlanVariable = NULL;
//
// Initialize the Mnp Device Data
//
MnpDeviceData = AllocateZeroPool (sizeof (MNP_DEVICE_DATA));
if (MnpDeviceData == NULL) {
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Device Data.\n"));
return EFI_OUT_OF_RESOURCES;
}
Status = MnpInitializeDeviceData (MnpDeviceData, This->DriverBindingHandle, ControllerHandle);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeDeviceData failed, %r.\n", Status));
FreePool (MnpDeviceData);
return Status;
}
//
// Check whether NIC driver has already produced VlanConfig protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiVlanConfigProtocolGuid,
NULL,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (!EFI_ERROR (Status)) {
//
// NIC hardware already implement VLAN,
// no need to provide software VLAN implementation in MNP driver
//
MnpDeviceData->NumberOfVlan = 0;
ZeroMem (&MnpDeviceData->VlanConfig, sizeof (EFI_VLAN_CONFIG_PROTOCOL));
MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);
Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Install VLAN Config Protocol
//
Status = gBS->InstallMultipleProtocolInterfaces (
&ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
if (EFI_ERROR (Status)) {
goto Exit;
}
//
// Get current VLAN configuration from EFI Variable
//
NumberOfVlan = 0;
Status = MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &VlanVariable);
if (EFI_ERROR (Status)) {
//
// No VLAN is set, create a default MNP service data for untagged frame
//
MnpDeviceData->NumberOfVlan = 0;
MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);
Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Create MNP service data for each VLAN
//
MnpDeviceData->NumberOfVlan = NumberOfVlan;
for (Index = 0; Index < NumberOfVlan; Index++) {
MnpServiceData = MnpCreateServiceData (
MnpDeviceData,
VlanVariable[Index].Bits.Vid,
(UINT8) VlanVariable[Index].Bits.Priority
);
if (MnpServiceData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
}
Exit:
if (VlanVariable != NULL) {
FreePool (VlanVariable);
}
if (EFI_ERROR (Status)) {
//
// Destroy all MNP service data
//
while (!IsListEmpty (&MnpDeviceData->ServiceList)) {
Entry = GetFirstNode (&MnpDeviceData->ServiceList);
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
MnpDestroyServiceData (MnpServiceData);
}
//
// Uninstall the VLAN Config Protocol if any
//
if (MnpDeviceData->VlanConfig.Set != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
MnpDeviceData->ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
}
//
// Destroy Mnp Device Data
//
MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);
FreePool (MnpDeviceData);
}
return Status;
}
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to make drivers as
small as possible, there are a few calling restrictions for this service.
DisconnectController() must follow these calling restrictions. If any other
agent wishes to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on.
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If
number of children is zero stop the entire
bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
EFI_STATUS Status;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData;
LIST_ENTRY *List;
UINTN ListLength;
//
// Try to retrieve MNP service binding protocol from the ControllerHandle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
//
// Retrieve VLAN Config Protocol from the ControllerHandle
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiVlanConfigProtocolGuid,
(VOID **) &VlanConfig,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MnpDriverBindingStop: try to stop unknown Controller.\n"));
return EFI_DEVICE_ERROR;
}
MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (VlanConfig);
} else {
MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);
MnpDeviceData = MnpServiceData->MnpDeviceData;
}
if (NumberOfChildren == 0) {
//
// Destroy all MNP service data
//
List = &MnpDeviceData->ServiceList;
Status = NetDestroyLinkList (
List,
MnpDestroyServiceDataEntry,
NULL,
&ListLength
);
if (EFI_ERROR (Status) || ListLength !=0) {
return EFI_DEVICE_ERROR;
}
//
// Uninstall the VLAN Config Protocol if any
//
if (MnpDeviceData->VlanConfig.Set != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
MnpDeviceData->ControllerHandle,
&gEfiVlanConfigProtocolGuid,
&MnpDeviceData->VlanConfig,
NULL
);
}
//
// Destroy Mnp Device Data
//
MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);
FreePool (MnpDeviceData);
if (gMnpControllerNameTable != NULL) {
FreeUnicodeStringTable (gMnpControllerNameTable);
gMnpControllerNameTable = NULL;
}
return EFI_SUCCESS;
}
//
// Stop all MNP child
//
List = &MnpDeviceData->ServiceList;
Status = NetDestroyLinkList (
List,
MnpDestroyServiceChildEntry,
NULL,
&ListLength
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Creates a child handle with a set of I/O services.
@param[in] This Protocol instance pointer.
@param[in, out] 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 protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
create the child.
@retval Others The child handle was not created.
**/
EFI_STATUS
EFIAPI
MnpServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
)
{
EFI_STATUS Status;
MNP_SERVICE_DATA *MnpServiceData;
MNP_INSTANCE_DATA *Instance;
VOID *MnpSb;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (This);
//
// Allocate buffer for the new instance.
//
Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA));
if (Instance == NULL) {
DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));
return EFI_OUT_OF_RESOURCES;
}
//
// Init the instance data.
//
MnpInitializeInstanceData (MnpServiceData, Instance);
Status = gBS->InstallMultipleProtocolInterfaces (
ChildHandle,
&gEfiManagedNetworkProtocolGuid,
&Instance->ManagedNetwork,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG (
(EFI_D_ERROR,
"MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",
Status)
);
goto ErrorExit;
}
//
// Save the instance's childhandle.
//
Instance->Handle = *ChildHandle;
Status = gBS->OpenProtocol (
MnpServiceData->ServiceHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid,
(VOID **) &MnpSb,
gMnpDriverBinding.DriverBindingHandle,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
//
// Add the child instance into ChildrenList.
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
InsertTailList (&MnpServiceData->ChildrenList, &Instance->InstEntry);
MnpServiceData->ChildrenNumber++;
gBS->RestoreTPL (OldTpl);
ErrorExit:
if (EFI_ERROR (Status)) {
if (Instance->Handle != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
Instance->Handle,
&gEfiManagedNetworkProtocolGuid,
&Instance->ManagedNetwork,
NULL
);
}
FreePool (Instance);
}
return Status;
}
/**
Destroys a child handle with a set of I/O services.
The DestroyChild() function does the opposite of CreateChild(). It removes a
protocol that was installed by CreateChild() from ChildHandle. If the removed
protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
@param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
instance.
@param[in] ChildHandle Handle of the child to destroy.
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
is being removed.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the
ChildHandle because its services are being
used.
@retval Others The child handle was not destroyed.
**/
EFI_STATUS
EFIAPI
MnpServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
)
{
EFI_STATUS Status;
MNP_SERVICE_DATA *MnpServiceData;
EFI_MANAGED_NETWORK_PROTOCOL *ManagedNetwork;
MNP_INSTANCE_DATA *Instance;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (This);
//
// Try to retrieve ManagedNetwork Protocol from ChildHandle.
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiManagedNetworkProtocolGuid,
(VOID **) &ManagedNetwork,
gMnpDriverBinding.DriverBindingHandle,
ChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (ManagedNetwork);
//
// MnpServiceBindingDestroyChild may be called twice: first called by
// MnpServiceBindingStop, second called by uninstalling the MNP protocol
// in this ChildHandle. Use destroyed to make sure the resource clean code
// will only excecute once.
//
if (Instance->Destroyed) {
return EFI_SUCCESS;
}
Instance->Destroyed = TRUE;
//
// Close the Simple Network protocol.
//
gBS->CloseProtocol (
MnpServiceData->ServiceHandle,
&gEfiManagedNetworkServiceBindingProtocolGuid,
MnpServiceData->MnpDeviceData->ImageHandle,
ChildHandle
);
//
// Uninstall the ManagedNetwork protocol.
//
Status = gBS->UninstallMultipleProtocolInterfaces (
ChildHandle,
&gEfiManagedNetworkProtocolGuid,
&Instance->ManagedNetwork,
NULL
);
if (EFI_ERROR (Status)) {
DEBUG (
(EFI_D_ERROR,
"MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",
Status)
);
Instance->Destroyed = FALSE;
return Status;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Reset the configuration.
//
ManagedNetwork->Configure (ManagedNetwork, NULL);
//
// Try to flush the RcvdPacketQueue.
//
MnpFlushRcvdDataQueue (Instance);
//
// Clean the RxTokenMap.
//
NetMapClean (&Instance->RxTokenMap);
//
// Remove this instance from the ChildrenList.
//
RemoveEntryList (&Instance->InstEntry);
MnpServiceData->ChildrenNumber--;
gBS->RestoreTPL (OldTpl);
FreePool (Instance);
return Status;
}
/**
The entry point for Mnp driver which installs the driver binding and component
name protocol on its ImageHandle.
@param[in] ImageHandle The image handle of the driver.
@param[in] SystemTable The system table.
@retval EFI_SUCCES The driver binding and component name protocols are
successfully installed.
@retval Others Other errors as indicated.
**/
EFI_STATUS
EFIAPI
MnpDriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gMnpDriverBinding,
ImageHandle,
&gMnpComponentName,
&gMnpComponentName2
);
}

View File

@@ -1,268 +0,0 @@
/** @file
Declaration of strctures and functions for MnpDxe driver.
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _MNP_DRIVER_H_
#define _MNP_DRIVER_H_
#include <Uefi.h>
#include <Protocol/ManagedNetwork.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/ServiceBinding.h>
#include <Protocol/VlanConfig.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/NetLib.h>
#include <Library/DpcLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
#include "ComponentName.h"
#define MNP_DEVICE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'D')
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding;
typedef struct {
UINT32 Signature;
EFI_HANDLE ControllerHandle;
EFI_HANDLE ImageHandle;
EFI_VLAN_CONFIG_PROTOCOL VlanConfig;
UINTN NumberOfVlan;
CHAR16 *MacString;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
//
// List of MNP_SERVICE_DATA
//
LIST_ENTRY ServiceList;
//
// Number of configured MNP Service Binding child
//
UINTN ConfiguredChildrenNumber;
LIST_ENTRY GroupAddressList;
UINT32 GroupAddressCount;
LIST_ENTRY FreeTxBufList;
LIST_ENTRY AllTxBufList;
UINT32 TxBufCount;
NET_BUF_QUEUE FreeNbufQue;
INTN NbufCnt;
EFI_EVENT PollTimer;
BOOLEAN EnableSystemPoll;
EFI_EVENT TimeoutCheckTimer;
EFI_EVENT MediaDetectTimer;
UINT32 UnicastCount;
UINT32 BroadcastCount;
UINT32 MulticastCount;
UINT32 PromiscuousCount;
//
// The size of the data buffer in the MNP_PACKET_BUFFER used to
// store a packet.
//
UINT32 BufferLength;
UINT32 PaddingSize;
NET_BUF *RxNbufCache;
} MNP_DEVICE_DATA;
#define MNP_DEVICE_DATA_FROM_THIS(a) \
CR ( \
(a), \
MNP_DEVICE_DATA, \
VlanConfig, \
MNP_DEVICE_DATA_SIGNATURE \
)
#define MNP_SERVICE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'S')
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
MNP_DEVICE_DATA *MnpDeviceData;
EFI_HANDLE ServiceHandle;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
LIST_ENTRY ChildrenList;
UINTN ChildrenNumber;
UINT32 Mtu;
UINT16 VlanId;
UINT8 Priority;
} MNP_SERVICE_DATA;
#define MNP_SERVICE_DATA_FROM_THIS(a) \
CR ( \
(a), \
MNP_SERVICE_DATA, \
ServiceBinding, \
MNP_SERVICE_DATA_SIGNATURE \
)
#define MNP_SERVICE_DATA_FROM_LINK(a) \
CR ( \
(a), \
MNP_SERVICE_DATA, \
Link, \
MNP_SERVICE_DATA_SIGNATURE \
)
/**
Test to see if this driver supports ControllerHandle. This service
is called by the EFI boot service ConnectController(). In
order to make drivers as small as possible, there are a few calling
restrictions for this service. ConnectController() must
follow these calling restrictions. If any other agent wishes to call
Supported() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to test.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_ALREADY_STARTED This driver is already running on this device.
@retval Others This driver does not support this device.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Start this driver on ControllerHandle. This service is called by the
EFI boot service ConnectController(). In order to make drivers as small
as possible, there are a few calling restrictions for this service.
ConnectController() must follow these calling restrictions. If any other
agent wishes to call Start() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] RemainingDevicePath Optional parameter use to pick a specific
child device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle.
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data.
@retval Others This driver does not support this device.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
/**
Stop this driver on ControllerHandle. This service is called by the
EFI boot service DisconnectController(). In order to make drivers as
small as possible, there are a few calling restrictions for this service.
DisconnectController() must follow these calling restrictions. If any other
agent wishes to call Stop() it must also follow these calling restrictions.
@param[in] This Protocol instance pointer.
@param[in] ControllerHandle Handle of device to stop driver on.
@param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If
number of children is zero stop the entire
bus driver.
@param[in] ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
**/
EFI_STATUS
EFIAPI
MnpDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
);
/**
Creates a child handle with a set of I/O services.
@param[in] This Protocol instance pointer.
@param[in, out] 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 protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_OUT_OF_RESOURCES There are not enough resources available to
create the child.
@retval Others The child handle was not created.
**/
EFI_STATUS
EFIAPI
MnpServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN OUT EFI_HANDLE *ChildHandle
);
/**
Destroys a child handle with a set of I/O services.
The DestroyChild() function does the opposite of CreateChild(). It removes a
protocol that was installed by CreateChild() from ChildHandle. If the removed
protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
@param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
instance.
@param[in] ChildHandle Handle of the child to destroy.
@retval EFI_SUCCES The protocol was removed from ChildHandle.
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
is being removed.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
@retval EFI_ACCESS_DENIED The protocol could not be removed from the
ChildHandle because its services are being
used.
@retval Others The child handle was not destroyed.
**/
EFI_STATUS
EFIAPI
MnpServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@@ -1,68 +0,0 @@
## @file
# This module produces EFI MNP Protocol, EFI MNP Servie Binding Protocol and EFI VLAN Protocol.
#
# This module produces EFI Managed Network Protocol upon EFI Simple Network Protocol,
# to provide raw asynchronous network I/O services. It also produces EFI VLAN Protocol
# to provide manageability interface for VLAN configuration.
#
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MnpDxe
MODULE_UNI_FILE = MnpDxe.uni
FILE_GUID = 025BBFC7-E6A9-4b8b-82AD-6815A1AEAF4A
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = MnpDriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
# DRIVER_BINDING = gMnpDriverBinding
# COMPONENT_NAME = gMnpComponentName
# COMPONENT_NAME2 = gMnpComponentName2
#
[Sources]
MnpMain.c
MnpIo.c
ComponentName.h
MnpDriver.h
ComponentName.c
MnpDriver.c
MnpConfig.c
MnpImpl.h
MnpVlan.h
MnpVlan.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
BaseLib
BaseMemoryLib
MemoryAllocationLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
DebugLib
NetLib
DpcLib
[Protocols]
gEfiManagedNetworkServiceBindingProtocolGuid ## BY_START
gEfiSimpleNetworkProtocolGuid ## TO_START
gEfiManagedNetworkProtocolGuid ## BY_START
## BY_START
## UNDEFINED # variable
gEfiVlanConfigProtocolGuid
[UserExtensions.TianoCore."ExtraFiles"]
MnpDxeExtra.uni

View File

@@ -1,18 +0,0 @@
// /** @file
// This module produces EFI MNP Protocol, EFI MNP Servie Binding Protocol and EFI VLAN Protocol.
//
// This module produces EFI Managed Network Protocol upon EFI Simple Network Protocol,
// to provide raw asynchronous network I/O services. It also produces EFI VLAN Protocol
// to provide manageability interface for VLAN configuration.
//
// Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Produces EFI MNP Protocol, EFI MNP Servie Binding Protocol and EFI VLAN Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI Managed Network Protocol upon EFI Simple Network Protocol to provide raw asynchronous network I/O services. It also produces EFI VLAN Protocol to provide manageability interface for VLAN configuration."

View File

@@ -1,14 +0,0 @@
// /** @file
// MnpDxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"MNP DXE Driver"

View File

@@ -1,898 +0,0 @@
/** @file
Declaration of structures and functions of MnpDxe driver.
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _MNP_IMPL_H_
#define _MNP_IMPL_H_
#include "MnpDriver.h"
#define NET_ETHER_FCS_SIZE 4
#define MNP_SYS_POLL_INTERVAL (10 * TICKS_PER_MS) // 10 milliseconds
#define MNP_TIMEOUT_CHECK_INTERVAL (50 * TICKS_PER_MS) // 50 milliseconds
#define MNP_MEDIA_DETECT_INTERVAL (500 * TICKS_PER_MS) // 500 milliseconds
#define MNP_TX_TIMEOUT_TIME (500 * TICKS_PER_MS) // 500 milliseconds
#define MNP_INIT_NET_BUFFER_NUM 512
#define MNP_NET_BUFFER_INCREASEMENT 64
#define MNP_MAX_NET_BUFFER_NUM 65536
#define MNP_TX_BUFFER_INCREASEMENT 32 // Same as the recycling Q length for xmit_done in UNDI command.
#define MNP_MAX_TX_BUFFER_NUM 65536
#define MNP_MAX_RCVD_PACKET_QUE_SIZE 256
#define MNP_RECEIVE_UNICAST 0x01
#define MNP_RECEIVE_BROADCAST 0x02
#define UNICAST_PACKET MNP_RECEIVE_UNICAST
#define BROADCAST_PACKET MNP_RECEIVE_BROADCAST
#define MNP_INSTANCE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'I')
#define MNP_INSTANCE_DATA_FROM_THIS(a) \
CR ( \
(a), \
MNP_INSTANCE_DATA, \
ManagedNetwork, \
MNP_INSTANCE_DATA_SIGNATURE \
)
typedef struct {
UINT32 Signature;
MNP_SERVICE_DATA *MnpServiceData;
EFI_HANDLE Handle;
LIST_ENTRY InstEntry;
EFI_MANAGED_NETWORK_PROTOCOL ManagedNetwork;
BOOLEAN Configured;
BOOLEAN Destroyed;
LIST_ENTRY GroupCtrlBlkList;
NET_MAP RxTokenMap;
LIST_ENTRY RxDeliveredPacketQueue;
LIST_ENTRY RcvdPacketQueue;
UINTN RcvdPacketQueueSize;
EFI_MANAGED_NETWORK_CONFIG_DATA ConfigData;
UINT8 ReceiveFilter;
} MNP_INSTANCE_DATA;
typedef struct {
LIST_ENTRY AddrEntry;
EFI_MAC_ADDRESS Address;
INTN RefCnt;
} MNP_GROUP_ADDRESS;
typedef struct {
LIST_ENTRY CtrlBlkEntry;
MNP_GROUP_ADDRESS *GroupAddress;
} MNP_GROUP_CONTROL_BLOCK;
typedef struct {
LIST_ENTRY WrapEntry;
MNP_INSTANCE_DATA *Instance;
EFI_MANAGED_NETWORK_RECEIVE_DATA RxData;
NET_BUF *Nbuf;
UINT64 TimeoutTick;
} MNP_RXDATA_WRAP;
#define MNP_TX_BUF_WRAP_SIGNATURE SIGNATURE_32 ('M', 'T', 'B', 'W')
typedef struct {
UINT32 Signature;
LIST_ENTRY WrapEntry; // Link to FreeTxBufList
LIST_ENTRY AllEntry; // Link to AllTxBufList
BOOLEAN InUse;
UINT8 TxBuf[1];
} MNP_TX_BUF_WRAP;
/**
Initialize the mnp device context data.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@param[in] ImageHandle The driver image handle.
@param[in] ControllerHandle Handle of device to bind driver to.
@retval EFI_SUCCESS The mnp service context is initialized.
@retval EFI_UNSUPPORTED ControllerHandle does not support Simple Network Protocol.
@retval Others Other errors as indicated.
**/
EFI_STATUS
MnpInitializeDeviceData (
IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle
);
/**
Destroy the MNP device context data.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@param[in] ImageHandle The driver image handle.
**/
VOID
MnpDestroyDeviceData (
IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN EFI_HANDLE ImageHandle
);
/**
Create mnp service context data.
@param[in] MnpDeviceData Pointer to the mnp device context data.
@param[in] VlanId The VLAN ID.
@param[in] Priority The VLAN priority. If VlanId is 0,
Priority is ignored.
@return A pointer to MNP_SERVICE_DATA or NULL if failed to create MNP service context.
**/
MNP_SERVICE_DATA *
MnpCreateServiceData (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN UINT16 VlanId,
IN UINT8 Priority OPTIONAL
);
/**
Initialize the mnp service context data.
@param[in, out] MnpServiceData Pointer to the mnp service context data.
@param[in] ImageHandle The driver image handle.
@param[in] ControllerHandle Handle of device to bind driver to.
@retval EFI_SUCCESS The mnp service context is initialized.
@retval EFI_UNSUPPORTED ControllerHandle does not support Simple Network Protocol.
@retval Others Other errors as indicated.
**/
EFI_STATUS
MnpInitializeServiceData (
IN OUT MNP_SERVICE_DATA *MnpServiceData,
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle
);
/**
Destroy the MNP service context data.
@param[in, out] MnpServiceData Pointer to the mnp service context data.
@retval EFI_SUCCESS The mnp service context is destroyed.
@retval Others Errors as indicated.
**/
EFI_STATUS
MnpDestroyServiceData (
IN OUT MNP_SERVICE_DATA *MnpServiceData
);
/**
Destroy all child of the MNP service data.
@param[in, out] MnpServiceData Pointer to the mnp service context data.
@retval EFI_SUCCESS All child are destroyed.
@retval Others Failed to destroy all child.
**/
EFI_STATUS
MnpDestroyServiceChild (
IN OUT MNP_SERVICE_DATA *MnpServiceData
);
/**
Find the MNP Service Data for given VLAN ID.
@param[in] MnpDeviceData Pointer to the mnp device context data.
@param[in] VlanId The VLAN ID.
@return A pointer to MNP_SERVICE_DATA or NULL if not found.
**/
MNP_SERVICE_DATA *
MnpFindServiceData (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN UINT16 VlanId
);
/**
Initialize the mnp instance context data.
@param[in] MnpServiceData Pointer to the mnp service context data.
@param[in, out] Instance Pointer to the mnp instance context data
to initialize.
**/
VOID
MnpInitializeInstanceData (
IN MNP_SERVICE_DATA *MnpServiceData,
IN OUT MNP_INSTANCE_DATA *Instance
);
/**
Check whether the token specified by Arg matches the token in Item.
@param[in] Map Pointer to the NET_MAP.
@param[in] Item Pointer to the NET_MAP_ITEM.
@param[in] Arg Pointer to the Arg, it's a pointer to the token to
check.
@retval EFI_SUCCESS The token specified by Arg is different from the
token in Item.
@retval EFI_ACCESS_DENIED The token specified by Arg is the same as that in
Item.
**/
EFI_STATUS
EFIAPI
MnpTokenExist (
IN NET_MAP *Map,
IN NET_MAP_ITEM *Item,
IN VOID *Arg
);
/**
Cancel the token specified by Arg if it matches the token in Item.
@param[in, out] Map Pointer to the NET_MAP.
@param[in, out] Item Pointer to the NET_MAP_ITEM.
@param[in] Arg Pointer to the Arg, it's a pointer to the
token to cancel.
@retval EFI_SUCCESS The Arg is NULL, and the token in Item is cancelled,
or the Arg isn't NULL, and the token in Item is
different from the Arg.
@retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the
Arg, and the token is cancelled.
**/
EFI_STATUS
EFIAPI
MnpCancelTokens (
IN OUT NET_MAP *Map,
IN OUT NET_MAP_ITEM *Item,
IN VOID *Arg
);
/**
Flush the instance's received data.
@param[in, out] Instance Pointer to the mnp instance context data.
**/
VOID
MnpFlushRcvdDataQueue (
IN OUT MNP_INSTANCE_DATA *Instance
);
/**
Configure the Instance using ConfigData.
@param[in, out] Instance Pointer to the mnp instance context data.
@param[in] ConfigData Pointer to the configuration data used to configure
the isntance.
@retval EFI_SUCCESS The Instance is configured.
@retval EFI_UNSUPPORTED EnableReceiveTimestamps is on and the
implementation doesn't support it.
@retval Others Other errors as indicated.
**/
EFI_STATUS
MnpConfigureInstance (
IN OUT MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData OPTIONAL
);
/**
Do the group operations for this instance.
@param[in, out] Instance Pointer to the instance context data.
@param[in] JoinFlag Set to TRUE to join a group. Set to TRUE to
leave a group/groups.
@param[in] MacAddress Pointer to the group address to join or leave.
@param[in] CtrlBlk Pointer to the group control block if JoinFlag
is FALSE.
@retval EFI_SUCCESS The group operation finished.
@retval EFI_OUT_OF_RESOURCES Failed due to lack of memory resources.
@retval Others Other errors as indicated.
**/
EFI_STATUS
MnpGroupOp (
IN OUT MNP_INSTANCE_DATA *Instance,
IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL,
IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk OPTIONAL
);
/**
Validates the Mnp transmit token.
@param[in] Instance Pointer to the Mnp instance context data.
@param[in] Token Pointer to the transmit token to check.
@return The Token is valid or not.
**/
BOOLEAN
MnpIsValidTxToken (
IN MNP_INSTANCE_DATA *Instance,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
);
/**
Build the packet to transmit from the TxData passed in.
@param[in] MnpServiceData Pointer to the mnp service context data.
@param[in] TxData Pointer to the transmit data containing the information
to build the packet.
@param[out] PktBuf Pointer to record the address of the packet.
@param[out] PktLen Pointer to a UINT32 variable used to record the packet's
length.
@retval EFI_SUCCESS TxPackage is built.
@retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.
**/
EFI_STATUS
MnpBuildTxPacket (
IN MNP_SERVICE_DATA *MnpServiceData,
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
OUT UINT8 **PktBuf,
OUT UINT32 *PktLen
);
/**
Synchronously send out the packet.
This functon places the packet buffer to SNP driver's tansmit queue. The packet
can be considered successfully sent out once SNP acccetp the packet, while the
packet buffer recycle is deferred for better performance.
@param[in] MnpServiceData Pointer to the mnp service context data.
@param[in] Packet Pointer to the pakcet buffer.
@param[in] Length The length of the packet.
@param[in, out] Token Pointer to the token the packet generated from.
@retval EFI_SUCCESS The packet is sent out.
@retval EFI_TIMEOUT Time out occurs, the packet isn't sent.
@retval EFI_DEVICE_ERROR An unexpected network error occurs.
**/
EFI_STATUS
MnpSyncSendPacket (
IN MNP_SERVICE_DATA *MnpServiceData,
IN UINT8 *Packet,
IN UINT32 Length,
IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
);
/**
Try to deliver the received packet to the instance.
@param[in, out] Instance Pointer to the mnp instance context data.
@retval EFI_SUCCESS The received packet is delivered, or there is no
packet to deliver, or there is no available receive
token.
@retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.
**/
EFI_STATUS
MnpInstanceDeliverPacket (
IN OUT MNP_INSTANCE_DATA *Instance
);
/**
Recycle the RxData and other resources used to hold and deliver the received
packet.
@param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registerd to the Event.
**/
VOID
EFIAPI
MnpRecycleRxData (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Try to receive a packet and deliver it.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@retval EFI_SUCCESS add return value to function comment
@retval EFI_NOT_STARTED The simple network protocol is not started.
@retval EFI_NOT_READY No packet received.
@retval EFI_DEVICE_ERROR An unexpected error occurs.
**/
EFI_STATUS
MnpReceivePacket (
IN OUT MNP_DEVICE_DATA *MnpDeviceData
);
/**
Allocate a free NET_BUF from MnpDeviceData->FreeNbufQue. If there is none
in the queue, first try to allocate some and add them into the queue, then
fetch the NET_BUF from the updated FreeNbufQue.
@param[in, out] MnpDeviceData Pointer to the MNP_DEVICE_DATA.
@return Pointer to the allocated free NET_BUF structure, if NULL the
operation is failed.
**/
NET_BUF *
MnpAllocNbuf (
IN OUT MNP_DEVICE_DATA *MnpDeviceData
);
/**
Try to reclaim the Nbuf into the buffer pool.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@param[in, out] Nbuf Pointer to the NET_BUF to free.
**/
VOID
MnpFreeNbuf (
IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN OUT NET_BUF *Nbuf
);
/**
Allocate a free TX buffer from MnpDeviceData->FreeTxBufList. If there is none
in the queue, first try to recycle some from SNP, then try to allocate some and add
them into the queue, then fetch the NET_BUF from the updated FreeTxBufList.
@param[in, out] MnpDeviceData Pointer to the MNP_DEVICE_DATA.
@return Pointer to the allocated free NET_BUF structure, if NULL the
operation is failed.
**/
UINT8 *
MnpAllocTxBuf (
IN OUT MNP_DEVICE_DATA *MnpDeviceData
);
/**
Try to recycle all the transmitted buffer address from SNP.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@retval EFI_SUCCESS Successed to recyclethe transmitted buffer address.
@retval Others Failed to recyclethe transmitted buffer address.
**/
EFI_STATUS
MnpRecycleTxBuf (
IN OUT MNP_DEVICE_DATA *MnpDeviceData
);
/**
Remove the received packets if timeout occurs.
@param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the event.
**/
VOID
EFIAPI
MnpCheckPacketTimeout (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Poll to update MediaPresent field in SNP ModeData by Snp.GetStatus().
@param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the event.
**/
VOID
EFIAPI
MnpCheckMediaStatus (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Poll to receive the packets from Snp. This function is either called by upperlayer
protocols/applications or the system poll timer notify mechanism.
@param[in] Event The event this notify function registered to.
@param[in] Context Pointer to the context data registered to the event.
**/
VOID
EFIAPI
MnpSystemPoll (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Returns the operational parameters for the current MNP child driver. May also
support returning the underlying SNP driver mode data.
The GetModeData() function is used to read the current mode data (operational
parameters) from the MNP or the underlying SNP.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type
EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related
Definitions" below.
@param[out] SnpModeData Pointer to storage for SNP operational parameters. This
feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this
MNP implementation.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured. The default values are returned in
MnpConfigData if it is not NULL.
@retval Others The mode data could not be read.
**/
EFI_STATUS
EFIAPI
MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
);
/**
Sets or clears the operational parameters for the MNP child driver.
The Configure() function is used to set, change, or reset the operational
parameters for the MNP child driver instance. Until the operational parameters
have been set, no network traffic can be sent or received by this MNP child
driver instance. Once the operational parameters have been reset, no more
traffic can be sent or received until the operational parameters have been set
again.
Each MNP child driver instance can be started and stopped independently of
each other by setting or resetting their receive filter settings with the
Configure() function.
After any successful call to Configure(), the MNP child driver instance is
started. The internal periodic timer (if supported) is enabled. Data can be
transmitted and may be received if the receive filters have also been enabled.
Note: If multiple MNP child driver instances will receive the same packet
because of overlapping receive filter settings, then the first MNP child
driver instance will receive the original packet and additional instances will
receive copies of the original packet.
Note: Warning: Receive filter settings that overlap will consume extra
processor and/or DMA resources and degrade system and network performance.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] MnpConfigData Pointer to configuration data that will be assigned
to the MNP child driver instance. If NULL, the MNP
child driver instance is reset to startup defaults
and all pending transmit and receive requests are
flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is
defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* MnpConfigData.ProtocolTypeFilter is not
valid.
The operational data for the MNP child driver
instance is unchanged.
@retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)
could not be allocated.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_UNSUPPORTED The requested feature is unsupported in
this [MNP] implementation. The operational data
for the MNP child driver instance is unchanged.
@retval EFI_DEVICE_ERROR An unexpected network or system error
occurred. The MNP child driver instance has
been reset to startup defaults.
@retval Others The MNP child driver instance has been reset to
startup defaults.
**/
EFI_STATUS
EFIAPI
MnpConfigure (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
);
/**
Translates an IP multicast address to a hardware (MAC) multicast address. This
function may be unsupported in some MNP implementations.
The McastIpToMac() function translates an IP multicast address to a hardware
(MAC) multicast address. This function may be implemented by calling the
underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be
unsupported in some MNP implementations.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.
Set to FALSE if IpAddress is an IPv4 multicast address.
@param[in] IpAddress Pointer to the multicast IP address (in network byte
order) to convert.
@param[out] MacAddress Pointer to the resulting multicast MAC address.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
* This is NULL.
* IpAddress is NULL.
* IpAddress is not a valid multicast IP
address.
* MacAddress is NULL.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this
MNP implementation.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
@retval Others The address could not be converted.
**/
EFI_STATUS
EFIAPI
MnpMcastIpToMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN Ipv6Flag,
IN EFI_IP_ADDRESS *IpAddress,
OUT EFI_MAC_ADDRESS *MacAddress
);
/**
Enables and disables receive filters for multicast address. This function may
be unsupported in some MNP implementations.
The Groups() function only adds and removes multicast MAC addresses from the
filter list. The MNP driver does not transmit or process Internet Group
Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
NULL, then all joined groups are left.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] JoinFlag Set to TRUE to join this multicast group.
Set to FALSE to leave this multicast group.
@param[in] MacAddress Pointer to the multicast MAC group (address) to join or
leave.
@retval EFI_SUCCESS The requested operation completed successfully.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
* This is NULL.
* JoinFlag is TRUE and MacAddress is NULL.
* MacAddress is not a valid multicast MAC
address.
* The MNP multicast group settings are
unchanged.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_ALREADY_STARTED The supplied multicast group is already joined.
@retval EFI_NOT_FOUND The supplied multicast group is not joined.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP
implementation.
@retval Others The requested operation could not be completed.
The MNP multicast group settings are unchanged.
**/
EFI_STATUS
EFIAPI
MnpGroups (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
);
/**
Places asynchronous outgoing data packets into the transmit queue.
The Transmit() function places a completion token into the transmit packet
queue. This function is always asynchronous.
The caller must fill in the Token.Event and Token.TxData fields in the
completion token, and these fields cannot be NULL. When the transmit operation
completes, the MNP updates the Token.Status field and the Token.Event is
signaled.
Note: There may be a performance penalty if the packet needs to be
defragmented before it can be transmitted by the network device. Systems in
which performance is critical should review the requirements and features of
the underlying communications device and drivers.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the transmit data
descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN
is defined in "Related Definitions" below.
@retval EFI_SUCCESS The transmit completion token was cached.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* Token is NULL.
* Token.Event is NULL.
* Token.TxData is NULL.
* Token.TxData.DestinationAddress is not
NULL and Token.TxData.HeaderLength is zero.
* Token.TxData.FragmentCount is zero.
* (Token.TxData.HeaderLength +
Token.TxData.DataLength) is not equal to the
sum of the
Token.TxData.FragmentTable[].FragmentLength
fields.
* One or more of the
Token.TxData.FragmentTable[].FragmentLength
fields is zero.
* One or more of the
Token.TxData.FragmentTable[].FragmentBufferfields
is NULL.
* Token.TxData.DataLength is greater than MTU.
@retval EFI_ACCESS_DENIED The transmit completion token is already in the
transmit queue.
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_NOT_READY The transmit request could not be queued because
the transmit queue is full.
**/
EFI_STATUS
EFIAPI
MnpTransmit (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
);
/**
Aborts an asynchronous transmit or receive request.
The Cancel() function is used to abort a pending transmit or receive request.
If the token is in the transmit or receive request queues, after calling this
function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
signaled. If the token is not in one of the queues, which usually means that
the asynchronous operation has completed, this function will not signal the
token and EFI_NOT_FOUND is returned.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token that has been issued by
EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all
pending tokens are aborted.
@retval EFI_SUCCESS The asynchronous I/O request was aborted and
Token.Event was signaled. When Token is NULL,
all pending requests were aborted and their
events were signaled.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
request was not found in the transmit or
receive queue. It has either completed or was
not issued by Transmit() and Receive().
**/
EFI_STATUS
EFIAPI
MnpCancel (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
);
/**
Places an asynchronous receiving request into the receiving queue.
The Receive() function places a completion token into the receive packet
queue. This function is always asynchronous.
The caller must fill in the Token.Event field in the completion token, and
this field cannot be NULL. When the receive operation completes, the MNP
updates the Token.Status and Token.RxData fields and the Token.Event is
signaled.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the receive
data descriptor. Type
EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in
EFI_MANAGED_NETWORK_PROTOCOL.Transmit().
@retval EFI_SUCCESS The receive completion token was cached.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* Token is NULL.
* Token.Event is NULL
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_ACCESS_DENIED The receive completion token was already in the
receive queue.
@retval EFI_NOT_READY The receive request could not be queued because
the receive queue is full.
**/
EFI_STATUS
EFIAPI
MnpReceive (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
);
/**
Polls for incoming data packets and processes outgoing data packets.
The Poll() function can be used by network drivers and applications to
increase the rate that data packets are moved between the communications
device and the transmit and receive queues.
Normally, a periodic timer event internally calls the Poll() function. But, in
some systems, the periodic timer event may not call Poll() fast enough to
transmit and/or receive all data packets without missing packets. Drivers and
applications that are experiencing packet loss should try calling the Poll()
function more often.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@retval EFI_SUCCESS Incoming or outgoing data was processed.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The
MNP child driver instance has been reset to startup
defaults.
@retval EFI_NOT_READY No incoming or outgoing data was processed. Consider
increasing the polling rate.
@retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
queue. Consider increasing the polling rate.
**/
EFI_STATUS
EFIAPI
MnpPoll (
IN EFI_MANAGED_NETWORK_PROTOCOL *This
);
/**
Configure the Snp receive filters according to the instances' receive filter
settings.
@param[in] MnpDeviceData Pointer to the mnp device context data.
@retval EFI_SUCCESS The receive filters is configured.
@retval EFI_OUT_OF_RESOURCES The receive filters can't be configured due
to lack of memory resource.
**/
EFI_STATUS
MnpConfigReceiveFilters (
IN MNP_DEVICE_DATA *MnpDeviceData
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,789 +0,0 @@
/** @file
Implementation of Managed Network Protocol public services.
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "MnpImpl.h"
/**
Returns the operational parameters for the current MNP child driver. May also
support returning the underlying SNP driver mode data.
The GetModeData() function is used to read the current mode data (operational
parameters) from the MNP or the underlying SNP.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type
EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related
Definitions" below.
@param[out] SnpModeData Pointer to storage for SNP operational parameters. This
feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this
MNP implementation.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured. The default values are returned in
MnpConfigData if it is not NULL.
@retval Others The mode data could not be read.
**/
EFI_STATUS
EFIAPI
MnpGetModeData (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
)
{
MNP_INSTANCE_DATA *Instance;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
EFI_TPL OldTpl;
EFI_STATUS Status;
UINT32 InterruptStatus;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (MnpConfigData != NULL) {
//
// Copy the instance configuration data.
//
CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));
}
if (SnpModeData != NULL) {
//
// Copy the underlayer Snp mode data.
//
Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
//
// Upon successful return of GetStatus(), the Snp->Mode->MediaPresent
// will be updated to reflect any change of media status
//
Snp->GetStatus (Snp, &InterruptStatus, NULL);
CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));
}
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
} else {
Status = EFI_SUCCESS;
}
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Sets or clears the operational parameters for the MNP child driver.
The Configure() function is used to set, change, or reset the operational
parameters for the MNP child driver instance. Until the operational parameters
have been set, no network traffic can be sent or received by this MNP child
driver instance. Once the operational parameters have been reset, no more
traffic can be sent or received until the operational parameters have been set
again.
Each MNP child driver instance can be started and stopped independently of
each other by setting or resetting their receive filter settings with the
Configure() function.
After any successful call to Configure(), the MNP child driver instance is
started. The internal periodic timer (if supported) is enabled. Data can be
transmitted and may be received if the receive filters have also been enabled.
Note: If multiple MNP child driver instances will receive the same packet
because of overlapping receive filter settings, then the first MNP child
driver instance will receive the original packet and additional instances will
receive copies of the original packet.
Note: Warning: Receive filter settings that overlap will consume extra
processor and/or DMA resources and degrade system and network performance.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] MnpConfigData Pointer to configuration data that will be assigned
to the MNP child driver instance. If NULL, the MNP
child driver instance is reset to startup defaults
and all pending transmit and receive requests are
flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is
defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* MnpConfigData.ProtocolTypeFilter is not
valid.
The operational data for the MNP child driver
instance is unchanged.
@retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)
could not be allocated.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_UNSUPPORTED The requested feature is unsupported in
this [MNP] implementation. The operational data
for the MNP child driver instance is unchanged.
@retval EFI_DEVICE_ERROR An unexpected network or system error
occurred. The MNP child driver instance has
been reset to startup defaults.
@retval Others The MNP child driver instance has been reset to
startup defaults.
**/
EFI_STATUS
EFIAPI
MnpConfigure (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
)
{
MNP_INSTANCE_DATA *Instance;
EFI_TPL OldTpl;
EFI_STATUS Status;
if ((This == NULL) ||
((MnpConfigData != NULL) &&
(MnpConfigData->ProtocolTypeFilter > 0) &&
(MnpConfigData->ProtocolTypeFilter <= 1500))
) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if ((MnpConfigData == NULL) && (!Instance->Configured)) {
//
// If the instance is not configured and a reset is requested, just return.
//
Status = EFI_SUCCESS;
goto ON_EXIT;
}
//
// Configure the instance.
//
Status = MnpConfigureInstance (Instance, MnpConfigData);
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Translates an IP multicast address to a hardware (MAC) multicast address. This
function may be unsupported in some MNP implementations.
The McastIpToMac() function translates an IP multicast address to a hardware
(MAC) multicast address. This function may be implemented by calling the
underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be
unsupported in some MNP implementations.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.
Set to FALSE if IpAddress is an IPv4 multicast address.
@param[in] IpAddress Pointer to the multicast IP address (in network byte
order) to convert.
@param[out] MacAddress Pointer to the resulting multicast MAC address.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
* This is NULL.
* IpAddress is NULL.
* IpAddress is not a valid multicast IP
address.
* MacAddress is NULL.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this
MNP implementation.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
@retval Others The address could not be converted.
**/
EFI_STATUS
EFIAPI
MnpMcastIpToMac (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN Ipv6Flag,
IN EFI_IP_ADDRESS *IpAddress,
OUT EFI_MAC_ADDRESS *MacAddress
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
EFI_TPL OldTpl;
EFI_IPv6_ADDRESS *Ip6Address;
if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {
return EFI_INVALID_PARAMETER;
}
Ip6Address = &IpAddress->v6;
if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||
(!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))
) {
//
// The IP address passed in is not a multicast address.
//
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
ASSERT (Snp != NULL);
ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));
if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {
if (!Ipv6Flag) {
//
// Translate the IPv4 address into a multicast MAC address if the NIC is an
// ethernet NIC according to RFC1112..
//
MacAddress->Addr[0] = 0x01;
MacAddress->Addr[1] = 0x00;
MacAddress->Addr[2] = 0x5E;
MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);
MacAddress->Addr[4] = IpAddress->v4.Addr[2];
MacAddress->Addr[5] = IpAddress->v4.Addr[3];
} else {
//
// Translate the IPv6 address into a multicast MAC address if the NIC is an
// ethernet NIC according to RFC2464.
//
MacAddress->Addr[0] = 0x33;
MacAddress->Addr[1] = 0x33;
MacAddress->Addr[2] = Ip6Address->Addr[12];
MacAddress->Addr[3] = Ip6Address->Addr[13];
MacAddress->Addr[4] = Ip6Address->Addr[14];
MacAddress->Addr[5] = Ip6Address->Addr[15];
}
Status = EFI_SUCCESS;
} else {
//
// Invoke Snp to translate the multicast IP address.
//
Status = Snp->MCastIpToMac (
Snp,
Ipv6Flag,
IpAddress,
MacAddress
);
}
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Enables and disables receive filters for multicast address. This function may
be unsupported in some MNP implementations.
The Groups() function only adds and removes multicast MAC addresses from the
filter list. The MNP driver does not transmit or process Internet Group
Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
NULL, then all joined groups are left.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] JoinFlag Set to TRUE to join this multicast group.
Set to FALSE to leave this multicast group.
@param[in] MacAddress Pointer to the multicast MAC group (address) to join or
leave.
@retval EFI_SUCCESS The requested operation completed successfully.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
* This is NULL.
* JoinFlag is TRUE and MacAddress is NULL.
* MacAddress is not a valid multicast MAC
address.
* The MNP multicast group settings are
unchanged.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_ALREADY_STARTED The supplied multicast group is already joined.
@retval EFI_NOT_FOUND The supplied multicast group is not joined.
@retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP
implementation.
@retval Others The requested operation could not be completed.
The MNP multicast group settings are unchanged.
**/
EFI_STATUS
EFIAPI
MnpGroups (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN BOOLEAN JoinFlag,
IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
)
{
MNP_INSTANCE_DATA *Instance;
EFI_SIMPLE_NETWORK_MODE *SnpMode;
MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;
MNP_GROUP_ADDRESS *GroupAddress;
LIST_ENTRY *ListEntry;
BOOLEAN AddressExist;
EFI_TPL OldTpl;
EFI_STATUS Status;
if (This == NULL || (JoinFlag && (MacAddress == NULL))) {
//
// This is NULL, or it's a join operation but MacAddress is NULL.
//
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
if ((!Instance->ConfigData.EnableMulticastReceive) ||
((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize))) {
//
// The instance isn't configured to do mulitcast receive. OR
// the passed in MacAddress is not a mutlticast mac address.
//
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
Status = EFI_SUCCESS;
AddressExist = FALSE;
GroupCtrlBlk = NULL;
if (MacAddress != NULL) {
//
// Search the instance's GroupCtrlBlkList to find the specific address.
//
NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {
GroupCtrlBlk = NET_LIST_USER_STRUCT (
ListEntry,
MNP_GROUP_CONTROL_BLOCK,
CtrlBlkEntry
);
GroupAddress = GroupCtrlBlk->GroupAddress;
if (0 == CompareMem (
MacAddress,
&GroupAddress->Address,
SnpMode->HwAddressSize
)) {
//
// There is already the same multicast mac address configured.
//
AddressExist = TRUE;
break;
}
}
if (JoinFlag && AddressExist) {
//
// The multicast mac address to join already exists.
//
Status = EFI_ALREADY_STARTED;
}
if (!JoinFlag && !AddressExist) {
//
// The multicast mac address to leave doesn't exist in this instance.
//
Status = EFI_NOT_FOUND;
}
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
} else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {
//
// The MacAddress is NULL and there is no configured multicast mac address,
// just return.
//
goto ON_EXIT;
}
//
// OK, it is time to take action.
//
Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Places asynchronous outgoing data packets into the transmit queue.
The Transmit() function places a completion token into the transmit packet
queue. This function is always asynchronous.
The caller must fill in the Token.Event and Token.TxData fields in the
completion token, and these fields cannot be NULL. When the transmit operation
completes, the MNP updates the Token.Status field and the Token.Event is
signaled.
Note: There may be a performance penalty if the packet needs to be
defragmented before it can be transmitted by the network device. Systems in
which performance is critical should review the requirements and features of
the underlying communications device and drivers.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the transmit data
descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN
is defined in "Related Definitions" below.
@retval EFI_SUCCESS The transmit completion token was cached.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* Token is NULL.
* Token.Event is NULL.
* Token.TxData is NULL.
* Token.TxData.DestinationAddress is not
NULL and Token.TxData.HeaderLength is zero.
* Token.TxData.FragmentCount is zero.
* (Token.TxData.HeaderLength +
Token.TxData.DataLength) is not equal to the
sum of the
Token.TxData.FragmentTable[].FragmentLength
fields.
* One or more of the
Token.TxData.FragmentTable[].FragmentLength
fields is zero.
* One or more of the
Token.TxData.FragmentTable[].FragmentBufferfields
is NULL.
* Token.TxData.DataLength is greater than MTU.
@retval EFI_ACCESS_DENIED The transmit completion token is already in the
transmit queue.
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_NOT_READY The transmit request could not be queued because
the transmit queue is full.
**/
EFI_STATUS
EFIAPI
MnpTransmit (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
MNP_SERVICE_DATA *MnpServiceData;
UINT8 *PktBuf;
UINT32 PktLen;
EFI_TPL OldTpl;
if ((This == NULL) || (Token == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
if (!MnpIsValidTxToken (Instance, Token)) {
//
// The Token is invalid.
//
Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
MnpServiceData = Instance->MnpServiceData;
NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
//
// Build the tx packet
//
Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
//
// OK, send the packet synchronously.
//
Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Places an asynchronous receiving request into the receiving queue.
The Receive() function places a completion token into the receive packet
queue. This function is always asynchronous.
The caller must fill in the Token.Event field in the completion token, and
this field cannot be NULL. When the receive operation completes, the MNP
updates the Token.Status and Token.RxData fields and the Token.Event is
signaled.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token associated with the receive
data descriptor. Type
EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in
EFI_MANAGED_NETWORK_PROTOCOL.Transmit().
@retval EFI_SUCCESS The receive completion token was cached.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER One or more of the following conditions is
TRUE:
* This is NULL.
* Token is NULL.
* Token.Event is NULL
@retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
lack of system resources (usually memory).
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
The MNP child driver instance has been reset to
startup defaults.
@retval EFI_ACCESS_DENIED The receive completion token was already in the
receive queue.
@retval EFI_NOT_READY The receive request could not be queued because
the receive queue is full.
**/
EFI_STATUS
EFIAPI
MnpReceive (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
EFI_TPL OldTpl;
if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
//
// Check whether this token(event) is already in the rx token queue.
//
Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
}
//
// Insert the Token into the RxTokenMap.
//
Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);
if (!EFI_ERROR (Status)) {
//
// Try to deliver any buffered packets.
//
Status = MnpInstanceDeliverPacket (Instance);
//
// Dispatch the DPC queued by the NotifyFunction of Token->Event.
//
DispatchDpc ();
}
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Aborts an asynchronous transmit or receive request.
The Cancel() function is used to abort a pending transmit or receive request.
If the token is in the transmit or receive request queues, after calling this
function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
signaled. If the token is not in one of the queues, which usually means that
the asynchronous operation has completed, this function will not signal the
token and EFI_NOT_FOUND is returned.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@param[in] Token Pointer to a token that has been issued by
EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all
pending tokens are aborted.
@retval EFI_SUCCESS The asynchronous I/O request was aborted and
Token.Event was signaled. When Token is NULL,
all pending requests were aborted and their
events were signaled.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_INVALID_PARAMETER This is NULL.
@retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
request was not found in the transmit or
receive queue. It has either completed or was
not issued by Transmit() and Receive().
**/
EFI_STATUS
EFIAPI
MnpCancel (
IN EFI_MANAGED_NETWORK_PROTOCOL *This,
IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
//
// Iterate the RxTokenMap to cancel the specified Token.
//
Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);
if (Token != NULL) {
Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
//
// Dispatch the DPC queued by the NotifyFunction of the cancled token's events.
//
DispatchDpc ();
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}
/**
Polls for incoming data packets and processes outgoing data packets.
The Poll() function can be used by network drivers and applications to
increase the rate that data packets are moved between the communications
device and the transmit and receive queues.
Normally, a periodic timer event internally calls the Poll() function. But, in
some systems, the periodic timer event may not call Poll() fast enough to
transmit and/or receive all data packets without missing packets. Drivers and
applications that are experiencing packet loss should try calling the Poll()
function more often.
@param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
@retval EFI_SUCCESS Incoming or outgoing data was processed.
@retval EFI_NOT_STARTED This MNP child driver instance has not been
configured.
@retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The
MNP child driver instance has been reset to startup
defaults.
@retval EFI_NOT_READY No incoming or outgoing data was processed. Consider
increasing the polling rate.
@retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
queue. Consider increasing the polling rate.
**/
EFI_STATUS
EFIAPI
MnpPoll (
IN EFI_MANAGED_NETWORK_PROTOCOL *This
)
{
EFI_STATUS Status;
MNP_INSTANCE_DATA *Instance;
EFI_TPL OldTpl;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
if (!Instance->Configured) {
Status = EFI_NOT_STARTED;
goto ON_EXIT;
}
//
// Try to receive packets.
//
Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);
//
// Dispatch the DPC queued by the NotifyFunction of rx token's events.
//
DispatchDpc ();
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
}

View File

@@ -1,732 +0,0 @@
/** @file
VLAN Config Protocol implementation and VLAN packet process routine.
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "MnpImpl.h"
#include "MnpVlan.h"
VLAN_DEVICE_PATH mVlanDevicePathTemplate = {
{
MESSAGING_DEVICE_PATH,
MSG_VLAN_DP,
{
(UINT8) (sizeof (VLAN_DEVICE_PATH)),
(UINT8) ((sizeof (VLAN_DEVICE_PATH)) >> 8)
}
},
0
};
EFI_VLAN_CONFIG_PROTOCOL mVlanConfigProtocolTemplate = {
VlanConfigSet,
VlanConfigFind,
VlanConfigRemove
};
/**
Create a child handle for the VLAN ID.
@param[in] ImageHandle The driver image handle.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] VlanId The VLAN ID.
@param[out] Devicepath Pointer to returned device path for child handle.
@return The handle of VLAN child or NULL if failed to create VLAN child.
**/
EFI_HANDLE
MnpCreateVlanChild (
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle,
IN UINT16 VlanId,
OUT EFI_DEVICE_PATH_PROTOCOL **Devicepath OPTIONAL
)
{
EFI_HANDLE ChildHandle;
VLAN_DEVICE_PATH VlanNode;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
EFI_DEVICE_PATH_PROTOCOL *VlanDevicePath;
EFI_STATUS Status;
//
// Try to get parent device path
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
(VOID **) &ParentDevicePath,
ImageHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return NULL;
}
//
// Construct device path for child handle: MAC + VLAN
//
CopyMem (&VlanNode, &mVlanDevicePathTemplate, sizeof (VLAN_DEVICE_PATH));
VlanNode.VlanId = VlanId;
VlanDevicePath = AppendDevicePathNode (
ParentDevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &VlanNode
);
if (VlanDevicePath == NULL) {
return NULL;
}
//
// Create child VLAN handle by installing DevicePath protocol
//
ChildHandle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&ChildHandle,
&gEfiDevicePathProtocolGuid,
VlanDevicePath,
NULL
);
if (EFI_ERROR (Status)) {
FreePool (VlanDevicePath);
return NULL;
}
if (Devicepath != NULL) {
*Devicepath = VlanDevicePath;
}
return ChildHandle;
}
/**
Remove VLAN tag from a packet.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@param[in, out] Nbuf Pointer to the NET_BUF to remove VLAN tag.
@param[out] VlanId Pointer to the returned VLAN ID.
@retval TRUE VLAN tag is removed from this packet.
@retval FALSE There is no VLAN tag in this packet.
**/
BOOLEAN
MnpRemoveVlanTag (
IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN OUT NET_BUF *Nbuf,
OUT UINT16 *VlanId
)
{
UINT8 *Packet;
UINTN ProtocolOffset;
UINT16 ProtocolType;
VLAN_TCI VlanTag;
ProtocolOffset = MnpDeviceData->Snp->Mode->HwAddressSize * 2;
//
// Get the packet buffer.
//
Packet = NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Packet != NULL);
//
// Check whether this is VLAN tagged frame by Ether Type
//
*VlanId = 0;
ProtocolType = NTOHS (*(UINT16 *) (Packet + ProtocolOffset));
if (ProtocolType != ETHER_TYPE_VLAN) {
//
// Not a VLAN tagged frame
//
return FALSE;
}
VlanTag.Uint16 = NTOHS (*(UINT16 *) (Packet + ProtocolOffset + sizeof (ProtocolType)));
*VlanId = VlanTag.Bits.Vid;
//
// Move hardware address (DA + SA) 4 bytes right to override VLAN tag
//
CopyMem (Packet + NET_VLAN_TAG_LEN, Packet, ProtocolOffset);
//
// Remove VLAN tag from the Nbuf
//
NetbufTrim (Nbuf, NET_VLAN_TAG_LEN, NET_BUF_HEAD);
return TRUE;
}
/**
Build the vlan packet to transmit from the TxData passed in.
@param MnpServiceData Pointer to the mnp service context data.
@param TxData Pointer to the transmit data containing the
information to build the packet.
@param ProtocolType Pointer to the Ethernet protocol type.
@param Packet Pointer to record the address of the packet.
@param Length Pointer to a UINT32 variable used to record the
packet's length.
**/
VOID
MnpInsertVlanTag (
IN MNP_SERVICE_DATA *MnpServiceData,
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
OUT UINT16 *ProtocolType,
IN OUT UINT8 **Packet,
IN OUT UINT32 *Length
)
{
VLAN_TCI *VlanTci;
UINT16 *Tpid;
UINT16 *EtherType;
MNP_DEVICE_DATA *MnpDeviceData;
EFI_SIMPLE_NETWORK_MODE *SnpMode;
MnpDeviceData = MnpServiceData->MnpDeviceData;
SnpMode = MnpDeviceData->Snp->Mode;
*ProtocolType = ETHER_TYPE_VLAN;
*Length = *Length + NET_VLAN_TAG_LEN;
*Packet = *Packet - NET_VLAN_TAG_LEN;
Tpid = (UINT16 *) (*Packet + SnpMode->MediaHeaderSize - sizeof (*ProtocolType));
VlanTci = (VLAN_TCI *) (UINTN) (Tpid + 1);
if (TxData->HeaderLength != 0) {
//
// Media header is in packet, move DA+SA 4 bytes left
//
CopyMem (
*Packet,
*Packet + NET_VLAN_TAG_LEN,
SnpMode->MediaHeaderSize - sizeof (*ProtocolType)
);
*Tpid = HTONS (ETHER_TYPE_VLAN);
} else {
//
// Media header not in packet, VLAN TCI and original protocol type becomes payload
//
EtherType = (UINT16 *) (UINTN) (VlanTci + 1);
*EtherType = HTONS (TxData->ProtocolType);
}
VlanTci->Bits.Vid = MnpServiceData->VlanId;
VlanTci->Bits.Cfi = VLAN_TCI_CFI_CANONICAL_MAC;
VlanTci->Bits.Priority = MnpServiceData->Priority;
VlanTci->Uint16 = HTONS (VlanTci->Uint16);
}
/**
Check VLAN configuration variable and delete the duplicative content if has identical Vlan ID.
@param[in] MnpDeviceData Pointer to the MNP device context data.
@param[in] Buffer Pointer to the buffer contains the array of VLAN_TCI.
@param[in] NumberOfVlan Pointer to number of VLAN.
@param[out] NewNumberOfVlan Pointer to number of unique VLAN.
@retval EFI_SUCCESS The VLAN variable is successfully checked.
@retval EFI_OUT_OF_RESOURCES There is not enough resource to set the configuration.
**/
EFI_STATUS
MnpCheckVlanVariable (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN VLAN_TCI *Buffer,
IN UINTN NumberOfVlan,
OUT UINTN *NewNumberOfVlan
)
{
UINTN Index;
UINTN Index2;
UINTN Count;
BOOLEAN FoundDuplicateItem;
EFI_STATUS Status;
Count = 0;
FoundDuplicateItem = FALSE;
Status = EFI_SUCCESS;
for (Index = 0; Index < NumberOfVlan; Index++) {
for (Index2 = Index + 1; Index2 < NumberOfVlan; Index2++) {
if (Buffer[Index].Bits.Vid == Buffer[Index2].Bits.Vid) {
FoundDuplicateItem = TRUE;
Count++;
break;
}
}
if (FoundDuplicateItem) {
for (Index2 = Index +1; Index2 < NumberOfVlan; Index++, Index2++) {
CopyMem (Buffer + Index, Buffer + Index2, sizeof (VLAN_TCI));
}
}
FoundDuplicateItem = FALSE;
}
*NewNumberOfVlan = NumberOfVlan - Count;
if (Count != 0) {
Status = MnpSetVlanVariable (MnpDeviceData, *NewNumberOfVlan, Buffer);
}
return Status;
}
/**
Get VLAN configuration variable.
@param[in] MnpDeviceData Pointer to the MNP device context data.
@param[out] NumberOfVlan Pointer to number of VLAN to be returned.
@param[out] VlanVariable Pointer to the buffer to return requested
array of VLAN_TCI.
@retval EFI_SUCCESS The array of VLAN_TCI was returned in VlanVariable
and number of VLAN was returned in NumberOfVlan.
@retval EFI_NOT_FOUND VLAN configuration variable not found.
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the configuration.
**/
EFI_STATUS
MnpGetVlanVariable (
IN MNP_DEVICE_DATA *MnpDeviceData,
OUT UINTN *NumberOfVlan,
OUT VLAN_TCI **VlanVariable
)
{
UINTN BufferSize;
EFI_STATUS Status;
VLAN_TCI *Buffer;
UINTN NewNumberOfVlan;
//
// Get VLAN configuration from EFI Variable
//
Buffer = NULL;
BufferSize = 0;
Status = gRT->GetVariable (
MnpDeviceData->MacString,
&gEfiVlanConfigProtocolGuid,
NULL,
&BufferSize,
NULL
);
if (Status != EFI_BUFFER_TOO_SMALL) {
return EFI_NOT_FOUND;
}
//
// Allocate buffer to read the variable
//
Buffer = AllocateZeroPool (BufferSize);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = gRT->GetVariable (
MnpDeviceData->MacString,
&gEfiVlanConfigProtocolGuid,
NULL,
&BufferSize,
Buffer
);
if (EFI_ERROR (Status)) {
FreePool (Buffer);
return Status;
}
Status = MnpCheckVlanVariable (MnpDeviceData, Buffer, BufferSize / sizeof (VLAN_TCI), &NewNumberOfVlan);
if (!EFI_ERROR (Status)) {
*NumberOfVlan = NewNumberOfVlan;
*VlanVariable = Buffer;
}
return Status;
}
/**
Set VLAN configuration variable.
@param[in] MnpDeviceData Pointer to the MNP device context data.
@param[in] NumberOfVlan Number of VLAN in array VlanVariable.
@param[in] VlanVariable Pointer to array of VLAN_TCI.
@retval EFI_SUCCESS The VLAN variable is successfully set.
@retval EFI_OUT_OF_RESOURCES There is not enough resource to set the configuration.
**/
EFI_STATUS
MnpSetVlanVariable (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN UINTN NumberOfVlan,
IN VLAN_TCI *VlanVariable
)
{
return gRT->SetVariable (
MnpDeviceData->MacString,
&gEfiVlanConfigProtocolGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
NumberOfVlan * sizeof (VLAN_TCI),
VlanVariable
);
}
/**
Create a VLAN device or modify the configuration parameter of an
already-configured VLAN.
The Set() function is used to create a new VLAN device or change the VLAN
configuration parameters. If the VlanId hasn't been configured in the
physical Ethernet device, a new VLAN device will be created. If a VLAN with
this VlanId is already configured, then related configuration will be updated
as the input parameters.
If VlanId is zero, the VLAN device will send and receive untagged frames.
Otherwise, the VLAN device will send and receive VLAN-tagged frames containing the VlanId.
If VlanId is out of scope of (0-4094), EFI_INVALID_PARAMETER is returned.
If Priority is out of the scope of (0-7), then EFI_INVALID_PARAMETER is returned.
If there is not enough system memory to perform the registration, then
EFI_OUT_OF_RESOURCES is returned.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId A unique identifier (1-4094) of the VLAN which is being created
or modified, or zero (0).
@param[in] Priority 3 bit priority in VLAN header. Priority 0 is default value. If
VlanId is zero (0), Priority is ignored.
@retval EFI_SUCCESS The VLAN is successfully configured.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- VlanId is an invalid VLAN Identifier.
- Priority is invalid.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to perform the registration.
**/
EFI_STATUS
EFIAPI
VlanConfigSet (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 VlanId,
IN UINT8 Priority
)
{
EFI_STATUS Status;
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData;
VLAN_TCI *OldVariable;
VLAN_TCI *NewVariable;
UINTN NumberOfVlan;
UINTN Index;
BOOLEAN IsAdd;
LIST_ENTRY *Entry;
if ((This == NULL) || (VlanId > 4094) || (Priority > 7)) {
return EFI_INVALID_PARAMETER;
}
IsAdd = FALSE;
MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);
if (MnpDeviceData->NumberOfVlan == 0) {
//
// No existing VLAN, this is the first VLAN to add
//
IsAdd = TRUE;
Entry = GetFirstNode (&MnpDeviceData->ServiceList);
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
if (VlanId != 0) {
//
// VlanId is not 0, need destroy the default MNP service data
//
Status = MnpDestroyServiceChild (MnpServiceData);
if (EFI_ERROR (Status)) {
return Status;
}
Status = MnpDestroyServiceData (MnpServiceData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Create a new MNP service data for this VLAN
//
MnpServiceData = MnpCreateServiceData (MnpDeviceData, VlanId, Priority);
if (MnpServiceData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
} else {
//
// Try to find VlanId in existing VLAN list
//
MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);
if (MnpServiceData == NULL) {
//
// VlanId not found, create a new MNP service data
//
IsAdd = TRUE;
MnpServiceData = MnpCreateServiceData (MnpDeviceData, VlanId, Priority);
if (MnpServiceData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
}
MnpServiceData->VlanId = VlanId;
MnpServiceData->Priority = Priority;
if (IsAdd) {
MnpDeviceData->NumberOfVlan++;
}
//
// Update VLAN configuration variable
//
OldVariable = NULL;
NewVariable = NULL;
NumberOfVlan = 0;
MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &OldVariable);
if (IsAdd) {
//
// VLAN not exist - add
//
NewVariable = AllocateZeroPool ((NumberOfVlan + 1) * sizeof (VLAN_TCI));
if (NewVariable == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
if (OldVariable != NULL) {
CopyMem (NewVariable, OldVariable, NumberOfVlan * sizeof (VLAN_TCI));
}
Index = NumberOfVlan++;
} else {
//
// VLAN already exist - update
//
for (Index = 0; Index < NumberOfVlan; Index++) {
if (OldVariable[Index].Bits.Vid == VlanId) {
break;
}
}
ASSERT (Index < NumberOfVlan);
NewVariable = OldVariable;
OldVariable = NULL;
}
NewVariable[Index].Bits.Vid = VlanId;
NewVariable[Index].Bits.Priority = Priority;
Status = MnpSetVlanVariable (MnpDeviceData, NumberOfVlan, NewVariable);
FreePool (NewVariable);
Exit:
if (OldVariable != NULL) {
FreePool (OldVariable);
}
return Status;
}
/**
Find configuration information for specified VLAN or all configured VLANs.
The Find() function is used to find the configuration information for matching
VLAN and allocate a buffer into which those entries are copied.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId Pointer to VLAN identifier. Set to NULL to find all
configured VLANs.
@param[out] NumberOfVlan The number of VLANs which is found by the specified criteria.
@param[out] Entries The buffer which receive the VLAN configuration.
@retval EFI_SUCCESS The VLAN is successfully found.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- Specified VlanId is invalid.
@retval EFI_NOT_FOUND No matching VLAN is found.
**/
EFI_STATUS
EFIAPI
VlanConfigFind (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 *VlanId OPTIONAL,
OUT UINT16 *NumberOfVlan,
OUT EFI_VLAN_FIND_DATA **Entries
)
{
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData;
LIST_ENTRY *Entry;
EFI_VLAN_FIND_DATA *VlanData;
if ((This == NULL) || (VlanId != NULL && *VlanId > 4094) || (NumberOfVlan == NULL) || (Entries == NULL)) {
return EFI_INVALID_PARAMETER;
}
*NumberOfVlan = 0;
*Entries = NULL;
MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);
if (MnpDeviceData->NumberOfVlan == 0) {
return EFI_NOT_FOUND;
}
if (VlanId == NULL) {
//
// Return all current VLAN configuration
//
*NumberOfVlan = (UINT16) MnpDeviceData->NumberOfVlan;
VlanData = AllocateZeroPool (*NumberOfVlan * sizeof (EFI_VLAN_FIND_DATA));
if (VlanData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*Entries = VlanData;
NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
VlanData->VlanId = MnpServiceData->VlanId;
VlanData->Priority = MnpServiceData->Priority;
VlanData++;
}
return EFI_SUCCESS;
}
//
// VlanId is specified, try to find it in current VLAN list
//
MnpServiceData = MnpFindServiceData (MnpDeviceData, *VlanId);
if (MnpServiceData == NULL) {
return EFI_NOT_FOUND;
}
VlanData = AllocateZeroPool (sizeof (EFI_VLAN_FIND_DATA));
if (VlanData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
VlanData->VlanId = MnpServiceData->VlanId;
VlanData->Priority = MnpServiceData->Priority;
*NumberOfVlan = 1;
*Entries = VlanData;
return EFI_SUCCESS;
}
/**
Remove the configured VLAN device.
The Remove() function is used to remove the specified VLAN device.
If the VlanId is out of the scope of (0-4094), EFI_INVALID_PARAMETER is returned.
If specified VLAN hasn't been previously configured, EFI_NOT_FOUND is returned.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId Identifier (0-4094) of the VLAN to be removed.
@retval EFI_SUCCESS The VLAN is successfully removed.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- VlanId is an invalid parameter.
@retval EFI_NOT_FOUND The to-be-removed VLAN does not exist.
**/
EFI_STATUS
EFIAPI
VlanConfigRemove (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 VlanId
)
{
EFI_STATUS Status;
MNP_DEVICE_DATA *MnpDeviceData;
MNP_SERVICE_DATA *MnpServiceData;
LIST_ENTRY *Entry;
VLAN_TCI *VlanVariable;
VLAN_TCI *VlanData;
if ((This == NULL) || (VlanId > 4094)) {
return EFI_INVALID_PARAMETER;
}
MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (This);
if (MnpDeviceData->NumberOfVlan == 0) {
return EFI_NOT_FOUND;
}
//
// Try to find the VlanId
//
MnpServiceData = MnpFindServiceData (MnpDeviceData, VlanId);
if (MnpServiceData == NULL) {
return EFI_NOT_FOUND;
}
MnpDeviceData->NumberOfVlan--;
if ((VlanId != 0) || (MnpDeviceData->NumberOfVlan != 0)) {
//
// If VlanId is not 0 or VlanId is 0 and it is not the last VLAN to remove,
// destroy its MNP service data
//
Status = MnpDestroyServiceChild (MnpServiceData);
if (EFI_ERROR (Status)) {
return Status;
}
Status = MnpDestroyServiceData (MnpServiceData);
if (EFI_ERROR (Status)) {
return Status;
}
}
if ((VlanId != 0) && (MnpDeviceData->NumberOfVlan == 0)) {
//
// This is the last VLAN to be removed, restore the default MNP service data
//
MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);
if (MnpServiceData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Update VLAN configuration variable
//
VlanVariable = NULL;
if (MnpDeviceData->NumberOfVlan != 0) {
VlanVariable = AllocatePool (MnpDeviceData->NumberOfVlan * sizeof (VLAN_TCI));
if (VlanVariable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
VlanData = VlanVariable;
NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {
MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);
VlanData->Bits.Vid = MnpServiceData->VlanId;
VlanData->Bits.Priority = MnpServiceData->Priority;
VlanData++;
}
}
Status = MnpSetVlanVariable (MnpDeviceData, MnpDeviceData->NumberOfVlan, VlanVariable);
if (VlanVariable != NULL) {
FreePool (VlanVariable);
}
return Status;
}

View File

@@ -1,205 +0,0 @@
/** @file
Header file to be included by MnpVlan.c.
Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __MNP_VLAN_H__
#define __MNP_VLAN_H__
#include "MnpDriver.h"
extern EFI_VLAN_CONFIG_PROTOCOL mVlanConfigProtocolTemplate;
/**
Create a child handle for the VLAN ID.
@param[in] ImageHandle The driver image handle.
@param[in] ControllerHandle Handle of device to bind driver to.
@param[in] VlanId The VLAN ID.
@param[out] Devicepath Pointer to returned device path for child handle.
@return The handle of VLAN child or NULL if failed to create VLAN child.
**/
EFI_HANDLE
MnpCreateVlanChild (
IN EFI_HANDLE ImageHandle,
IN EFI_HANDLE ControllerHandle,
IN UINT16 VlanId,
OUT EFI_DEVICE_PATH_PROTOCOL **Devicepath OPTIONAL
);
/**
Remove VLAN tag of a packet.
@param[in, out] MnpDeviceData Pointer to the mnp device context data.
@param[in, out] Nbuf Pointer to the NET_BUF to remove VLAN tag.
@param[out] VlanId Pointer to the returned VLAN ID.
@retval TRUE VLAN tag is removed from this packet.
@retval FALSE There is no VLAN tag in this packet.
**/
BOOLEAN
MnpRemoveVlanTag (
IN OUT MNP_DEVICE_DATA *MnpDeviceData,
IN OUT NET_BUF *Nbuf,
OUT UINT16 *VlanId
);
/**
Build the vlan packet to transmit from the TxData passed in.
@param MnpServiceData Pointer to the mnp service context data.
@param TxData Pointer to the transmit data containing the
information to build the packet.
@param ProtocolType Pointer to the Ethernet protocol type.
@param Packet Pointer to record the address of the packet.
@param Length Pointer to a UINT32 variable used to record the
packet's length.
**/
VOID
MnpInsertVlanTag (
IN MNP_SERVICE_DATA *MnpServiceData,
IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData,
OUT UINT16 *ProtocolType,
IN OUT UINT8 **Packet,
IN OUT UINT32 *Length
);
/**
Get VLAN configuration variable.
@param[in] MnpDeviceData Pointer to the MNP device context data.
@param[out] NumberOfVlan Pointer to number of VLAN to be returned.
@param[out] VlanVariable Pointer to the buffer to return requested
array of VLAN_TCI.
@retval EFI_SUCCESS The array of VLAN_TCI was returned in VlanVariable
and number of VLAN was returned in NumberOfVlan.
@retval EFI_NOT_FOUND VLAN configuration variable not found.
@retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the configuration.
**/
EFI_STATUS
MnpGetVlanVariable (
IN MNP_DEVICE_DATA *MnpDeviceData,
OUT UINTN *NumberOfVlan,
OUT VLAN_TCI **VlanVariable
);
/**
Set VLAN configuration variable.
@param[in] MnpDeviceData Pointer to the MNP device context data.
@param[in] NumberOfVlan Number of VLAN in array VlanVariable.
@param[in] VlanVariable Pointer to array of VLAN_TCI.
@retval EFI_SUCCESS The VLAN variable is successfully set.
@retval EFI_OUT_OF_RESOURCES There is not enough resource to set the configuration.
**/
EFI_STATUS
MnpSetVlanVariable (
IN MNP_DEVICE_DATA *MnpDeviceData,
IN UINTN NumberOfVlan,
IN VLAN_TCI *VlanVariable
);
/**
Create a VLAN device or modify the configuration parameter of an
already-configured VLAN.
The Set() function is used to create a new VLAN device or change the VLAN
configuration parameters. If the VlanId hasn't been configured in the
physical Ethernet device, a new VLAN device will be created. If a VLAN with
this VlanId is already configured, then related configuration will be updated
as the input parameters.
If VlanId is zero, the VLAN device will send and receive untagged frames.
Otherwise, the VLAN device will send and receive VLAN-tagged frames containing the VlanId.
If VlanId is out of scope of (0-4094), EFI_INVALID_PARAMETER is returned.
If Priority is out of the scope of (0-7), then EFI_INVALID_PARAMETER is returned.
If there is not enough system memory to perform the registration, then
EFI_OUT_OF_RESOURCES is returned.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId A unique identifier (1-4094) of the VLAN which is being created
or modified, or zero (0).
@param[in] Priority 3 bit priority in VLAN header. Priority 0 is default value. If
VlanId is zero (0), Priority is ignored.
@retval EFI_SUCCESS The VLAN is successfully configured.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- VlanId is an invalid VLAN Identifier.
- Priority is invalid.
@retval EFI_OUT_OF_RESOURCES There is not enough system memory to perform the registration.
**/
EFI_STATUS
EFIAPI
VlanConfigSet (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 VlanId,
IN UINT8 Priority
);
/**
Find configuration information for specified VLAN or all configured VLANs.
The Find() function is used to find the configuration information for matching
VLAN and allocate a buffer into which those entries are copied.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId Pointer to VLAN identifier. Set to NULL to find all
configured VLANs.
@param[out] NumberOfVlan The number of VLANs which is found by the specified criteria.
@param[out] Entries The buffer which receive the VLAN configuration.
@retval EFI_SUCCESS The VLAN is successfully found.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- Specified VlanId is invalid.
@retval EFI_NOT_FOUND No matching VLAN is found.
**/
EFI_STATUS
EFIAPI
VlanConfigFind (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 *VlanId OPTIONAL,
OUT UINT16 *NumberOfVlan,
OUT EFI_VLAN_FIND_DATA **Entries
);
/**
Remove the configured VLAN device.
The Remove() function is used to remove the specified VLAN device.
If the VlanId is out of the scope of (0-4094), EFI_INVALID_PARAMETER is returned.
If specified VLAN hasn't been previously configured, EFI_NOT_FOUND is returned.
@param[in] This Points to the EFI_VLAN_CONFIG_PROTOCOL.
@param[in] VlanId Identifier (0-4094) of the VLAN to be removed.
@retval EFI_SUCCESS The VLAN is successfully removed.
@retval EFI_INVALID_PARAMETER One or more of following conditions is TRUE:
- This is NULL.
- VlanId is an invalid parameter.
@retval EFI_NOT_FOUND The to-be-removed VLAN does not exist.
**/
EFI_STATUS
EFIAPI
VlanConfigRemove (
IN EFI_VLAN_CONFIG_PROTOCOL *This,
IN UINT16 VlanId
);
#endif

View File

@@ -1,425 +0,0 @@
/** @file
UEFI Component Name(2) protocol implementation for Mtftp4Dxe driver.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Mtftp4Impl.h"
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Mtftp4ComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Mtftp4ComponentNameGetControllerName (
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
///
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gMtftp4ComponentName = {
Mtftp4ComponentNameGetDriverName,
Mtftp4ComponentNameGetControllerName,
"eng"
};
///
/// EFI Component Name 2 Protocol
///
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gMtftp4ComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Mtftp4ComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Mtftp4ComponentNameGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMtftp4DriverNameTable[] = {
{
"eng;en",
L"MTFTP4 Network Service"
},
{
NULL,
NULL
}
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMtftp4ControllerNameTable = NULL;
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified
in RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Mtftp4ComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mMtftp4DriverNameTable,
DriverName,
(BOOLEAN)(This == &gMtftp4ComponentName)
);
}
/**
Update the component name for the Mtftp4 child handle.
@param Mtftp4[in] A pointer to the EFI_MTFTP4_PROTOCOL.
@retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
@retval EFI_INVALID_PARAMETER The input parameter is invalid.
**/
EFI_STATUS
UpdateName (
IN EFI_MTFTP4_PROTOCOL *Mtftp4
)
{
EFI_STATUS Status;
CHAR16 HandleName[80];
EFI_MTFTP4_MODE_DATA ModeData;
if (Mtftp4 == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Format the child name into the string buffer as:
// MTFTPv4 (ServerIp=192.168.1.10, ServerPort=69)
//
Status = Mtftp4->GetModeData (Mtftp4, &ModeData);
if (EFI_ERROR (Status)) {
return Status;
}
UnicodeSPrint (HandleName, sizeof (HandleName),
L"MTFTPv4 (ServerIp=%d.%d.%d.%d, ServerPort=%d)",
ModeData.ConfigData.ServerIp.Addr[0],
ModeData.ConfigData.ServerIp.Addr[1],
ModeData.ConfigData.ServerIp.Addr[2],
ModeData.ConfigData.ServerIp.Addr[3],
ModeData.ConfigData.InitialServerPort
);
if (gMtftp4ControllerNameTable != NULL) {
FreeUnicodeStringTable (gMtftp4ControllerNameTable);
gMtftp4ControllerNameTable = NULL;
}
Status = AddUnicodeString2 (
"eng",
gMtftp4ComponentName.SupportedLanguages,
&gMtftp4ControllerNameTable,
HandleName,
TRUE
);
if (EFI_ERROR (Status)) {
return Status;
}
return AddUnicodeString2 (
"en",
gMtftp4ComponentName2.SupportedLanguages,
&gMtftp4ControllerNameTable,
HandleName,
FALSE
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param[in] 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.
@param[in] 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.
@param[in] Language A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name 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. Language is specified in
RFC 4646 or ISO 639-2 language code format.
@param[out] 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.
@retval 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.
@retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
Mtftp4ComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_MTFTP4_PROTOCOL *Mtftp4;
//
// Only provide names for child handles.
//
if (ChildHandle == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver produced ChildHandle
//
Status = EfiTestChildHandle (
ControllerHandle,
ChildHandle,
&gEfiUdp4ProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Retrieve an instance of a produced protocol from ChildHandle
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiMtftp4ProtocolGuid,
(VOID **)&Mtftp4,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Update the component name for this child handle.
//
Status = UpdateName (Mtftp4);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
gMtftp4ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gMtftp4ComponentName)
);
}

View File

@@ -1,739 +0,0 @@
/** @file
Implementation of Mtftp drivers.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Mtftp4Impl.h"
EFI_DRIVER_BINDING_PROTOCOL gMtftp4DriverBinding = {
Mtftp4DriverBindingSupported,
Mtftp4DriverBindingStart,
Mtftp4DriverBindingStop,
0xa,
NULL,
NULL
};
EFI_SERVICE_BINDING_PROTOCOL gMtftp4ServiceBindingTemplete = {
Mtftp4ServiceBindingCreateChild,
Mtftp4ServiceBindingDestroyChild
};
/**
The driver entry point which installs multiple protocols to the ImageHandle.
@param ImageHandle The MTFTP's image handle.
@param SystemTable The system table.
@retval EFI_SUCCESS The handles are successfully installed on the image.
@retval others some EFI_ERROR occured.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gMtftp4DriverBinding,
ImageHandle,
&gMtftp4ComponentName,
&gMtftp4ComponentName2
);
}
/**
Test whether MTFTP driver support this controller.
@param This The MTFTP driver binding instance
@param Controller The controller to test
@param RemainingDevicePath The remaining device path
@retval EFI_SUCCESS The controller has UDP service binding protocol
installed, MTFTP can support it.
@retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by
the driver specified by This.
@retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
RemainingDevicePath is already being managed by a
different driver or an application that requires
exclusive access.
@retval EFI_UNSUPPORTED The device specified by ControllerHandle and
RemainingDevicePath is not supported by the driver
specified by This.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
Status = gBS->OpenProtocol (
Controller,
&gEfiUdp4ServiceBindingProtocolGuid,
NULL,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
return Status;
}
/**
Config a NULL UDP that is used to keep the connection between UDP and MTFTP.
Just leave the Udp child unconfigured. When UDP is unloaded,
MTFTP will be informed with DriverBinding Stop.
@param UdpIo The UDP_IO to configure
@param Context The opaque parameter to the callback
@retval EFI_SUCCESS It always return EFI_SUCCESS directly.
**/
EFI_STATUS
EFIAPI
Mtftp4ConfigNullUdp (
IN UDP_IO *UdpIo,
IN VOID *Context
)
{
return EFI_SUCCESS;
}
/**
Create then initialize a MTFTP service binding instance.
@param Controller The controller to install the MTFTP service
binding on
@param Image The driver binding image of the MTFTP driver
@param Service The variable to receive the created service
binding instance.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource to create the instance
@retval EFI_DEVICE_ERROR Failed to create a NULL UDP port to keep
connection with UDP.
@retval EFI_SUCCESS The service instance is created for the
controller.
**/
EFI_STATUS
Mtftp4CreateService (
IN EFI_HANDLE Controller,
IN EFI_HANDLE Image,
OUT MTFTP4_SERVICE **Service
)
{
MTFTP4_SERVICE *MtftpSb;
EFI_STATUS Status;
*Service = NULL;
MtftpSb = AllocatePool (sizeof (MTFTP4_SERVICE));
if (MtftpSb == NULL) {
return EFI_OUT_OF_RESOURCES;
}
MtftpSb->Signature = MTFTP4_SERVICE_SIGNATURE;
MtftpSb->ServiceBinding = gMtftp4ServiceBindingTemplete;
MtftpSb->ChildrenNum = 0;
InitializeListHead (&MtftpSb->Children);
MtftpSb->Timer = NULL;
MtftpSb->TimerNotifyLevel = NULL;
MtftpSb->TimerToGetMap = NULL;
MtftpSb->Controller = Controller;
MtftpSb->Image = Image;
MtftpSb->ConnectUdp = NULL;
//
// Create the timer and a udp to be notified when UDP is uninstalled
//
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_CALLBACK,
Mtftp4OnTimerTick,
MtftpSb,
&MtftpSb->Timer
);
if (EFI_ERROR (Status)) {
FreePool (MtftpSb);
return Status;
}
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL | EVT_TIMER,
TPL_NOTIFY,
Mtftp4OnTimerTickNotifyLevel,
MtftpSb,
&MtftpSb->TimerNotifyLevel
);
if (EFI_ERROR (Status)) {
gBS->CloseEvent (MtftpSb->Timer);
FreePool (MtftpSb);
return Status;
}
//
// Create the timer used to time out the procedure which is used to
// get the default IP address.
//
Status = gBS->CreateEvent (
EVT_TIMER,
TPL_CALLBACK,
NULL,
NULL,
&MtftpSb->TimerToGetMap
);
if (EFI_ERROR (Status)) {
gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
gBS->CloseEvent (MtftpSb->Timer);
FreePool (MtftpSb);
return Status;
}
MtftpSb->ConnectUdp = UdpIoCreateIo (
Controller,
Image,
Mtftp4ConfigNullUdp,
UDP_IO_UDP4_VERSION,
NULL
);
if (MtftpSb->ConnectUdp == NULL) {
gBS->CloseEvent (MtftpSb->TimerToGetMap);
gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
gBS->CloseEvent (MtftpSb->Timer);
FreePool (MtftpSb);
return EFI_DEVICE_ERROR;
}
*Service = MtftpSb;
return EFI_SUCCESS;
}
/**
Release all the resource used the MTFTP service binding instance.
@param MtftpSb The MTFTP service binding instance.
**/
VOID
Mtftp4CleanService (
IN MTFTP4_SERVICE *MtftpSb
)
{
UdpIoFreeIo (MtftpSb->ConnectUdp);
gBS->CloseEvent (MtftpSb->TimerToGetMap);
gBS->CloseEvent (MtftpSb->TimerNotifyLevel);
gBS->CloseEvent (MtftpSb->Timer);
}
/**
Start the MTFTP driver on this controller.
MTFTP driver will install a MTFTP SERVICE BINDING protocol on the supported
controller, which can be used to create/destroy MTFTP children.
@param This The MTFTP driver binding protocol.
@param Controller The controller to manage.
@param RemainingDevicePath Remaining device path.
@retval EFI_ALREADY_STARTED The MTFTP service binding protocol has been
started on the controller.
@retval EFI_SUCCESS The MTFTP service binding is installed on the
controller.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
MTFTP4_SERVICE *MtftpSb;
EFI_STATUS Status;
//
// Directly return if driver is already running.
//
Status = gBS->OpenProtocol (
Controller,
&gEfiMtftp4ServiceBindingProtocolGuid,
NULL,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (Status == EFI_SUCCESS) {
return EFI_ALREADY_STARTED;
}
Status = Mtftp4CreateService (Controller, This->DriverBindingHandle, &MtftpSb);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (MtftpSb != NULL);
Status = gBS->SetTimer (MtftpSb->Timer, TimerPeriodic, TICKS_PER_SECOND);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
Status = gBS->SetTimer (MtftpSb->TimerNotifyLevel, TimerPeriodic, TICKS_PER_SECOND);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
//
// Install the Mtftp4ServiceBinding Protocol onto Controller
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Controller,
&gEfiMtftp4ServiceBindingProtocolGuid,
&MtftpSb->ServiceBinding,
NULL
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
return EFI_SUCCESS;
ON_ERROR:
Mtftp4CleanService (MtftpSb);
FreePool (MtftpSb);
return Status;
}
/**
Callback function which provided by user to remove one node in NetDestroyLinkList process.
@param[in] Entry The entry to be removed.
@param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
@retval EFI_SUCCESS The entry has been removed successfully.
@retval Others Fail to remove the entry.
**/
EFI_STATUS
EFIAPI
Mtftp4DestroyChildEntryInHandleBuffer (
IN LIST_ENTRY *Entry,
IN VOID *Context
)
{
MTFTP4_PROTOCOL *Instance;
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
if (Entry == NULL || Context == NULL) {
return EFI_INVALID_PARAMETER;
}
Instance = NET_LIST_USER_STRUCT_S (Entry, MTFTP4_PROTOCOL, Link, MTFTP4_PROTOCOL_SIGNATURE);
ServiceBinding = ((MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;
NumberOfChildren = ((MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;
ChildHandleBuffer = ((MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;
if (!NetIsInHandleBuffer (Instance->Handle, NumberOfChildren, ChildHandleBuffer)) {
return EFI_SUCCESS;
}
return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
}
/**
Stop the MTFTP driver on controller. The controller is a UDP
child handle.
@param This The MTFTP driver binding protocol
@param Controller The controller to stop
@param NumberOfChildren The number of children
@param ChildHandleBuffer The array of the child handle.
@retval EFI_SUCCESS The driver is stopped on the controller.
@retval EFI_DEVICE_ERROR Failed to stop the driver on the controller.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
MTFTP4_SERVICE *MtftpSb;
EFI_HANDLE NicHandle;
EFI_STATUS Status;
LIST_ENTRY *List;
MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;
//
// MTFTP driver opens UDP child, So, Controller is a UDP
// child handle. Locate the Nic handle first. Then get the
// MTFTP private data back.
//
NicHandle = NetLibGetNicHandle (Controller, &gEfiUdp4ProtocolGuid);
if (NicHandle == NULL) {
return EFI_SUCCESS;
}
Status = gBS->OpenProtocol (
NicHandle,
&gEfiMtftp4ServiceBindingProtocolGuid,
(VOID **) &ServiceBinding,
This->DriverBindingHandle,
NicHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
MtftpSb = MTFTP4_SERVICE_FROM_THIS (ServiceBinding);
if (!IsListEmpty (&MtftpSb->Children)) {
//
// Destroy the Mtftp4 child instance in ChildHandleBuffer.
//
List = &MtftpSb->Children;
Context.ServiceBinding = ServiceBinding;
Context.NumberOfChildren = NumberOfChildren;
Context.ChildHandleBuffer = ChildHandleBuffer;
Status = NetDestroyLinkList (
List,
Mtftp4DestroyChildEntryInHandleBuffer,
&Context,
NULL
);
}
if (NumberOfChildren == 0 && IsListEmpty (&MtftpSb->Children)) {
gBS->UninstallProtocolInterface (
NicHandle,
&gEfiMtftp4ServiceBindingProtocolGuid,
ServiceBinding
);
Mtftp4CleanService (MtftpSb);
if (gMtftp4ControllerNameTable != NULL) {
FreeUnicodeStringTable (gMtftp4ControllerNameTable);
gMtftp4ControllerNameTable = NULL;
}
FreePool (MtftpSb);
Status = EFI_SUCCESS;
}
return Status;
}
/**
Initialize a MTFTP protocol instance which is the child of MtftpSb.
@param MtftpSb The MTFTP service binding protocol.
@param Instance The MTFTP instance to initialize.
**/
VOID
Mtftp4InitProtocol (
IN MTFTP4_SERVICE *MtftpSb,
OUT MTFTP4_PROTOCOL *Instance
)
{
ZeroMem (Instance, sizeof (MTFTP4_PROTOCOL));
Instance->Signature = MTFTP4_PROTOCOL_SIGNATURE;
InitializeListHead (&Instance->Link);
CopyMem (&Instance->Mtftp4, &gMtftp4ProtocolTemplate, sizeof (Instance->Mtftp4));
Instance->State = MTFTP4_STATE_UNCONFIGED;
Instance->Service = MtftpSb;
InitializeListHead (&Instance->Blocks);
}
/**
Create a MTFTP child for the service binding instance, then
install the MTFTP protocol to the ChildHandle.
@param This The MTFTP service binding instance.
@param ChildHandle The Child handle to install the MTFTP protocol.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the new child.
@retval EFI_SUCCESS The child is successfully create.
**/
EFI_STATUS
EFIAPI
Mtftp4ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE *ChildHandle
)
{
MTFTP4_SERVICE *MtftpSb;
MTFTP4_PROTOCOL *Instance;
EFI_STATUS Status;
EFI_TPL OldTpl;
VOID *Udp4;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
Instance = AllocatePool (sizeof (*Instance));
if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
MtftpSb = MTFTP4_SERVICE_FROM_THIS (This);
Mtftp4InitProtocol (MtftpSb, Instance);
Instance->UnicastPort = UdpIoCreateIo (
MtftpSb->Controller,
MtftpSb->Image,
Mtftp4ConfigNullUdp,
UDP_IO_UDP4_VERSION,
Instance
);
if (Instance->UnicastPort == NULL) {
FreePool (Instance);
return EFI_OUT_OF_RESOURCES;
}
//
// Install the MTFTP protocol onto ChildHandle
//
Status = gBS->InstallMultipleProtocolInterfaces (
ChildHandle,
&gEfiMtftp4ProtocolGuid,
&Instance->Mtftp4,
NULL
);
if (EFI_ERROR (Status)) {
UdpIoFreeIo (Instance->UnicastPort);
FreePool (Instance);
return Status;
}
Instance->Handle = *ChildHandle;
//
// Open the Udp4 protocol BY_CHILD.
//
Status = gBS->OpenProtocol (
MtftpSb->ConnectUdp->UdpHandle,
&gEfiUdp4ProtocolGuid,
(VOID **) &Udp4,
gMtftp4DriverBinding.DriverBindingHandle,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
goto ON_ERROR;
}
//
// Open the Udp4 protocol by child.
//
Status = gBS->OpenProtocol (
Instance->UnicastPort->UdpHandle,
&gEfiUdp4ProtocolGuid,
(VOID **) &Udp4,
gMtftp4DriverBinding.DriverBindingHandle,
Instance->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
//
// Close the Udp4 protocol.
//
gBS->CloseProtocol (
MtftpSb->ConnectUdp->UdpHandle,
&gEfiUdp4ProtocolGuid,
gMtftp4DriverBinding.DriverBindingHandle,
ChildHandle
);
goto ON_ERROR;
}
//
// Add it to the parent's child list.
//
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
InsertTailList (&MtftpSb->Children, &Instance->Link);
MtftpSb->ChildrenNum++;
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
ON_ERROR:
if (Instance->Handle != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
Instance->Handle,
&gEfiMtftp4ProtocolGuid,
&Instance->Mtftp4,
NULL
);
}
UdpIoFreeIo (Instance->UnicastPort);
FreePool (Instance);
return Status;
}
/**
Destroy one of the service binding's child.
@param This The service binding instance
@param ChildHandle The child handle to destroy
@retval EFI_INVALID_PARAMETER The parameter is invaid.
@retval EFI_UNSUPPORTED The child may have already been destroyed.
@retval EFI_SUCCESS The child is destroyed and removed from the
parent's child list.
**/
EFI_STATUS
EFIAPI
Mtftp4ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
)
{
MTFTP4_SERVICE *MtftpSb;
MTFTP4_PROTOCOL *Instance;
EFI_MTFTP4_PROTOCOL *Mtftp4;
EFI_STATUS Status;
EFI_TPL OldTpl;
if ((This == NULL) || (ChildHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
//
// Retrieve the private context data structures
//
Status = gBS->OpenProtocol (
ChildHandle,
&gEfiMtftp4ProtocolGuid,
(VOID **) &Mtftp4,
gMtftp4DriverBinding.DriverBindingHandle,
ChildHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Instance = MTFTP4_PROTOCOL_FROM_THIS (Mtftp4);
MtftpSb = MTFTP4_SERVICE_FROM_THIS (This);
if (Instance->Service != MtftpSb) {
return EFI_INVALID_PARAMETER;
}
if (Instance->InDestroy) {
return EFI_SUCCESS;
}
Instance->InDestroy = TRUE;
//
// Close the Udp4 protocol.
//
gBS->CloseProtocol (
MtftpSb->ConnectUdp->UdpHandle,
&gEfiUdp4ProtocolGuid,
gMtftp4DriverBinding.DriverBindingHandle,
ChildHandle
);
gBS->CloseProtocol (
Instance->UnicastPort->UdpHandle,
&gEfiUdp4ProtocolGuid,
gMtftp4DriverBinding.DriverBindingHandle,
ChildHandle
);
if (Instance->McastUdpPort != NULL) {
gBS->CloseProtocol (
Instance->McastUdpPort->UdpHandle,
&gEfiUdp4ProtocolGuid,
gMtftp4DriverBinding.DriverBindingHandle,
ChildHandle
);
}
//
// Uninstall the MTFTP4 protocol first to enable a top down destruction.
//
Status = gBS->UninstallProtocolInterface (
ChildHandle,
&gEfiMtftp4ProtocolGuid,
Mtftp4
);
if (EFI_ERROR (Status)) {
Instance->InDestroy = FALSE;
return Status;
}
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
Mtftp4CleanOperation (Instance, EFI_DEVICE_ERROR);
UdpIoFreeIo (Instance->UnicastPort);
RemoveEntryList (&Instance->Link);
MtftpSb->ChildrenNum--;
gBS->RestoreTPL (OldTpl);
FreePool (Instance);
return EFI_SUCCESS;
}

View File

@@ -1,131 +0,0 @@
/** @file
Mtftp drivers function header.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_MTFTP4_DRIVER_H__
#define __EFI_MTFTP4_DRIVER_H__
#include <Uefi.h>
#include <Protocol/ServiceBinding.h>
#include <Library/NetLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
extern EFI_COMPONENT_NAME_PROTOCOL gMtftp4ComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gMtftp4ComponentName2;
extern EFI_DRIVER_BINDING_PROTOCOL gMtftp4DriverBinding;
extern EFI_UNICODE_STRING_TABLE *gMtftp4ControllerNameTable;
/**
Test whether MTFTP driver support this controller.
@param This The MTFTP driver binding instance
@param Controller The controller to test
@param RemainingDevicePath The remaining device path
@retval EFI_SUCCESS The controller has UDP service binding protocol
installed, MTFTP can support it.
@retval Others MTFTP can't support the controller.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Start the MTFTP driver on this controller.
MTFTP driver will install a MTFTP SERVICE BINDING protocol on the supported
controller, which can be used to create/destroy MTFTP children.
@param This The MTFTP driver binding protocol.
@param Controller The controller to manage.
@param RemainingDevicePath Remaining device path.
@retval EFI_ALREADY_STARTED The MTFTP service binding protocol has been
started on the controller.
@retval EFI_SUCCESS The MTFTP service binding is installed on the
controller.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Stop the MTFTP driver on controller. The controller is a UDP
child handle.
@param This The MTFTP driver binding protocol
@param Controller The controller to stop
@param NumberOfChildren The number of children
@param ChildHandleBuffer The array of the child handle.
@retval EFI_SUCCESS The driver is stopped on the controller.
@retval EFI_DEVICE_ERROR Failed to stop the driver on the controller.
**/
EFI_STATUS
EFIAPI
Mtftp4DriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
Create a MTFTP child for the service binding instance, then
install the MTFTP protocol to the ChildHandle.
@param This The MTFTP service binding instance.
@param ChildHandle The Child handle to install the MTFTP protocol.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the new child.
@retval EFI_SUCCESS The child is successfully create.
**/
EFI_STATUS
EFIAPI
Mtftp4ServiceBindingCreateChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE *ChildHandle
);
/**
Destroy one of the service binding's child.
@param This The service binding instance
@param ChildHandle The child handle to destroy
@retval EFI_INVALID_PARAMETER The parameter is invaid.
@retval EFI_UNSUPPORTED The child may have already been destroyed.
@retval EFI_SUCCESS The child is destroyed and removed from the
parent's child list.
**/
EFI_STATUS
EFIAPI
Mtftp4ServiceBindingDestroyChild (
IN EFI_SERVICE_BINDING_PROTOCOL *This,
IN EFI_HANDLE ChildHandle
);
#endif

View File

@@ -1,69 +0,0 @@
## @file
# This module produces EFI MTFTPv4 Protocol and EFI MTFTPv4 Service Binding Protocol.
#
# This module produces EFI MTFTPv4 Protocol upon EFI UDPv4 Protocol, to provide
# basic services for client-side unicast and/or multicase TFTP operations.
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Mtftp4Dxe
MODULE_UNI_FILE = Mtftp4Dxe.uni
FILE_GUID = DC3641B8-2FA8-4ed3-BC1F-F9962A03454B
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = Mtftp4DriverEntryPoint
UNLOAD_IMAGE = NetLibDefaultUnload
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
#
# DRIVER_BINDING = gMtftp4DriverBinding
# COMPONENT_NAME = gMtftp4ComponentName
# COMPONENT_NAME2 = gMtftp4ComponentName2
#
[Sources]
Mtftp4Option.c
Mtftp4Rrq.c
Mtftp4Impl.h
ComponentName.c
Mtftp4Support.c
Mtftp4Impl.c
Mtftp4Option.h
Mtftp4Support.h
Mtftp4Driver.h
Mtftp4Driver.c
Mtftp4Wrq.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
DebugLib
NetLib
UdpIoLib
MemoryAllocationLib
BaseMemoryLib
[Protocols]
gEfiMtftp4ServiceBindingProtocolGuid ## BY_START
gEfiUdp4ServiceBindingProtocolGuid ## TO_START
gEfiMtftp4ProtocolGuid ## BY_START
gEfiUdp4ProtocolGuid ## TO_START
[UserExtensions.TianoCore."ExtraFiles"]
Mtftp4DxeExtra.uni

View File

@@ -1,17 +0,0 @@
// /** @file
// This module produces EFI MTFTPv4 Protocol and EFI MTFTPv4 Service Binding Protocol.
//
// This module produces EFI MTFTPv4 Protocol upon EFI UDPv4 Protocol, to provide
// basic services for client-side unicast and/or multicase TFTP operations.
//
// Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "Produces EFI MTFTPv4 Protocol and EFI MTFTPv4 Service Binding Protocol"
#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI MTFTPv4 Protocol upon EFI UDPv4 Protocol, to provide basic services for client-side unicast or multicase TFTP operations or both."

View File

@@ -1,14 +0,0 @@
// /** @file
// Mtftp4Dxe Localized Strings and Content
//
// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_PROPERTIES_MODULE_NAME
#language en-US
"MTFTP v4 DXE Driver"

File diff suppressed because it is too large Load Diff

View File

@@ -1,226 +0,0 @@
/** @file
Mtftp4 Implementation.
Mtftp4 Implementation, it supports the following RFCs:
RFC1350 - THE TFTP PROTOCOL (REVISION 2)
RFC2090 - TFTP Multicast Option
RFC2347 - TFTP Option Extension
RFC2348 - TFTP Blocksize Option
RFC2349 - TFTP Timeout Interval and Transfer Size Options
RFC7440 - TFTP Windowsize Option
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_MTFTP4_IMPL_H__
#define __EFI_MTFTP4_IMPL_H__
#include <Uefi.h>
#include <Protocol/Udp4.h>
#include <Protocol/Mtftp4.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UdpIoLib.h>
#include <Library/PrintLib.h>
extern EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate;
typedef struct _MTFTP4_SERVICE MTFTP4_SERVICE;
typedef struct _MTFTP4_PROTOCOL MTFTP4_PROTOCOL;
#include "Mtftp4Driver.h"
#include "Mtftp4Option.h"
#include "Mtftp4Support.h"
///
/// Some constant value of Mtftp service.
///
#define MTFTP4_SERVICE_SIGNATURE SIGNATURE_32 ('T', 'F', 'T', 'P')
#define MTFTP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('t', 'f', 't', 'p')
#define MTFTP4_DEFAULT_SERVER_PORT 69
#define MTFTP4_DEFAULT_TIMEOUT 3
#define MTFTP4_DEFAULT_RETRY 5
#define MTFTP4_DEFAULT_BLKSIZE 512
#define MTFTP4_DEFAULT_WINDOWSIZE 1
#define MTFTP4_TIME_TO_GETMAP 5
#define MTFTP4_STATE_UNCONFIGED 0
#define MTFTP4_STATE_CONFIGED 1
#define MTFTP4_STATE_DESTROY 2
///
/// Mtftp service block
///
struct _MTFTP4_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
UINT16 ChildrenNum;
LIST_ENTRY Children;
EFI_EVENT Timer; ///< Ticking timer for all the MTFTP clients to handle the packet timeout case.
EFI_EVENT TimerNotifyLevel; ///< Ticking timer for all the MTFTP clients to calculate the packet live time.
EFI_EVENT TimerToGetMap;
EFI_HANDLE Controller;
EFI_HANDLE Image;
//
// This UDP child is used to keep the connection between the UDP
// and MTFTP, so MTFTP will be notified when UDP is uninstalled.
//
UDP_IO *ConnectUdp;
};
typedef struct {
EFI_MTFTP4_PACKET **Packet;
UINT32 *PacketLen;
EFI_STATUS Status;
} MTFTP4_GETINFO_STATE;
struct _MTFTP4_PROTOCOL {
UINT32 Signature;
LIST_ENTRY Link;
EFI_MTFTP4_PROTOCOL Mtftp4;
INTN State;
BOOLEAN InDestroy;
MTFTP4_SERVICE *Service;
EFI_HANDLE Handle;
EFI_MTFTP4_CONFIG_DATA Config;
//
// Operation parameters: token and requested options.
//
EFI_MTFTP4_TOKEN *Token;
MTFTP4_OPTION RequestOption;
UINT16 Operation;
//
// Blocks is a list of MTFTP4_BLOCK_RANGE which contains
// holes in the file
//
UINT16 BlkSize;
UINT16 LastBlock;
LIST_ENTRY Blocks;
UINT16 WindowSize;
//
// Record the total received and saved block number.
//
UINT64 TotalBlock;
//
// Record the acked block number.
//
UINT64 AckedBlock;
//
// The server's communication end point: IP and two ports. one for
// initial request, one for its selected port.
//
IP4_ADDR ServerIp;
UINT16 ListeningPort;
UINT16 ConnectedPort;
IP4_ADDR Gateway;
UDP_IO *UnicastPort;
//
// Timeout and retransmit status
//
NET_BUF *LastPacket;
UINT32 PacketToLive;
BOOLEAN HasTimeout;
UINT32 CurRetry;
UINT32 MaxRetry;
UINT32 Timeout;
//
// Parameter used by RRQ's multicast download.
//
IP4_ADDR McastIp;
UINT16 McastPort;
BOOLEAN Master;
UDP_IO *McastUdpPort;
};
typedef struct {
EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
UINTN NumberOfChildren;
EFI_HANDLE *ChildHandleBuffer;
} MTFTP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
/**
Clean up the MTFTP session to get ready for new operation.
@param Instance The MTFTP session to clean up
@param Result The result to return to the caller who initiated
the operation.
**/
VOID
Mtftp4CleanOperation (
IN OUT MTFTP4_PROTOCOL *Instance,
IN EFI_STATUS Result
);
/**
Start the MTFTP session for upload.
It will first init some states, then send the WRQ request packet,
and start receiving the packet.
@param Instance The MTFTP session
@param Operation Redundant parameter, which is always
EFI_MTFTP4_OPCODE_WRQ here.
@retval EFI_SUCCESS The upload process has been started.
@retval Others Failed to start the upload.
**/
EFI_STATUS
Mtftp4WrqStart (
IN MTFTP4_PROTOCOL *Instance,
IN UINT16 Operation
);
/**
Start the MTFTP session to download.
It will first initialize some of the internal states then build and send a RRQ
reqeuest packet, at last, it will start receive for the downloading.
@param Instance The Mtftp session
@param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ
or EFI_MTFTP4_OPCODE_DIR.
@retval EFI_SUCCESS The mtftp download session is started.
@retval Others Failed to start downloading.
**/
EFI_STATUS
Mtftp4RrqStart (
IN MTFTP4_PROTOCOL *Instance,
IN UINT16 Operation
);
#define MTFTP4_SERVICE_FROM_THIS(a) \
CR (a, MTFTP4_SERVICE, ServiceBinding, MTFTP4_SERVICE_SIGNATURE)
#define MTFTP4_PROTOCOL_FROM_THIS(a) \
CR (a, MTFTP4_PROTOCOL, Mtftp4, MTFTP4_PROTOCOL_SIGNATURE)
#endif

View File

@@ -1,549 +0,0 @@
/** @file
Routines to process MTFTP4 options.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "Mtftp4Impl.h"
CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS] = {
"blksize",
"windowsize",
"timeout",
"tsize",
"multicast"
};
/**
Check whether two ascii strings are equel, ignore the case.
@param Str1 The first ascii string
@param Str2 The second ascii string
@retval TRUE Two strings are equal when case is ignored.
@retval FALSE Two string are not equal.
**/
BOOLEAN
NetStringEqualNoCase (
IN UINT8 *Str1,
IN UINT8 *Str2
)
{
UINT8 Ch1;
UINT8 Ch2;
ASSERT ((Str1 != NULL) && (Str2 != NULL));
for (; (*Str1 != '\0') && (*Str2 != '\0'); Str1++, Str2++) {
Ch1 = *Str1;
Ch2 = *Str2;
//
// Convert them to lower case then compare two
//
if (('A' <= Ch1) && (Ch1 <= 'Z')) {
Ch1 += 'a' - 'A';
}
if (('A' <= Ch2) && (Ch2 <= 'Z')) {
Ch2 += 'a' - 'A';
}
if (Ch1 != Ch2) {
return FALSE;
}
}
return (BOOLEAN) (*Str1 == *Str2);
}
/**
Convert a string to a UINT32 number.
@param Str The string to convert from
@return The number get from the string
**/
UINT32
NetStringToU32 (
IN UINT8 *Str
)
{
UINT32 Num;
ASSERT (Str != NULL);
Num = 0;
for (; NET_IS_DIGIT (*Str); Str++) {
Num = Num * 10 + (*Str - '0');
}
return Num;
}
/**
Convert a string of the format "192.168.0.1" to an IP address.
@param Str The string representation of IP
@param Ip The varible to get IP.
@retval EFI_INVALID_PARAMETER The IP string is invalid.
@retval EFI_SUCCESS The IP is parsed into the Ip
**/
EFI_STATUS
NetStringToIp (
IN UINT8 *Str,
OUT IP4_ADDR *Ip
)
{
UINT32 Byte;
UINT32 Addr;
UINTN Index;
*Ip = 0;
Addr = 0;
for (Index = 0; Index < 4; Index++) {
if (!NET_IS_DIGIT (*Str)) {
return EFI_INVALID_PARAMETER;
}
Byte = NetStringToU32 (Str);
if (Byte > 255) {
return EFI_INVALID_PARAMETER;
}
Addr = (Addr << 8) | Byte;
//
// Skip all the digitals and check whether the sepeator is the dot
//
while (NET_IS_DIGIT (*Str)) {
Str++;
}
if ((Index < 3) && (*Str != '.')) {
return EFI_INVALID_PARAMETER;
}
Str++;
}
*Ip = Addr;
return EFI_SUCCESS;
}
/**
Go through the packet to fill the Options array with the start
addresses of each MTFTP option name/value pair.
@param Packet The packet to check
@param PacketLen The packet's length
@param Count The size of the Options on input. The actual
options on output
@param Options The option array to fill in
@retval EFI_INVALID_PARAMETER The packet is mal-formated
@retval EFI_BUFFER_TOO_SMALL The Options array is too small
@retval EFI_SUCCESS The packet has been parsed into the Options array.
**/
EFI_STATUS
Mtftp4FillOptions (
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 PacketLen,
IN OUT UINT32 *Count,
OUT EFI_MTFTP4_OPTION *Options OPTIONAL
)
{
UINT8 *Cur;
UINT8 *Last;
UINT8 Num;
UINT8 *Name;
UINT8 *Value;
Num = 0;
Cur = (UINT8 *) Packet + MTFTP4_OPCODE_LEN;
Last = (UINT8 *) Packet + PacketLen - 1;
//
// process option name and value pairs. The last byte is always zero
//
while (Cur < Last) {
Name = Cur;
while (*Cur != 0) {
Cur++;
}
if (Cur == Last) {
return EFI_INVALID_PARAMETER;
}
Value = ++Cur;
while (*Cur != 0) {
Cur++;
}
Num++;
if ((Options != NULL) && (Num <= *Count)) {
Options[Num - 1].OptionStr = Name;
Options[Num - 1].ValueStr = Value;
}
Cur++;
}
if ((*Count < Num) || (Options == NULL)) {
*Count = Num;
return EFI_BUFFER_TOO_SMALL;
}
*Count = Num;
return EFI_SUCCESS;
}
/**
Allocate and fill in a array of Mtftp options from the Packet.
It first calls Mtftp4FillOption to get the option number, then allocate
the array, at last, call Mtftp4FillOption again to save the options.
@param Packet The packet to parse
@param PacketLen The length of the packet
@param OptionCount The number of options in the packet
@param OptionList The point to get the option array.
@retval EFI_INVALID_PARAMETER The parametera are invalid or packet isn't a
well-formated OACK packet.
@retval EFI_SUCCESS The option array is build
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the array
**/
EFI_STATUS
Mtftp4ExtractOptions (
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 PacketLen,
OUT UINT32 *OptionCount,
OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL
)
{
EFI_STATUS Status;
*OptionCount = 0;
if (OptionList != NULL) {
*OptionList = NULL;
}
if (NTOHS (Packet->OpCode) != EFI_MTFTP4_OPCODE_OACK) {
return EFI_INVALID_PARAMETER;
}
if (PacketLen == MTFTP4_OPCODE_LEN) {
return EFI_SUCCESS;
}
//
// The last byte must be zero to terminate the options
//
if (*((UINT8 *) Packet + PacketLen - 1) != 0) {
return EFI_INVALID_PARAMETER;
}
//
// Get the number of options
//
Status = Mtftp4FillOptions (Packet, PacketLen, OptionCount, NULL);
if ((Status == EFI_SUCCESS) || (Status != EFI_BUFFER_TOO_SMALL)) {
return Status;
}
//
// Allocate memory for the options, then call Mtftp4FillOptions to
// fill it if caller want that.
//
if (OptionList == NULL) {
return EFI_SUCCESS;
}
*OptionList = AllocatePool (*OptionCount * sizeof (EFI_MTFTP4_OPTION));
if (*OptionList == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Mtftp4FillOptions (Packet, PacketLen, OptionCount, *OptionList);
return EFI_SUCCESS;
}
/**
Parse the MTFTP multicast option.
@param Value The Mtftp multicast value string
@param Option The option to save the info into.
@retval EFI_INVALID_PARAMETER The multicast value string is invalid.
@retval EFI_SUCCESS The multicast value is parsed into the Option
**/
EFI_STATUS
Mtftp4ExtractMcast (
IN UINT8 *Value,
IN OUT MTFTP4_OPTION *Option
)
{
EFI_STATUS Status;
UINT32 Num;
//
// The multicast option is formated like "204.0.0.1,1857,1"
// The server can also omit the ip and port, use ",,1"
//
if (*Value == ',') {
Option->McastIp = 0;
} else {
Status = NetStringToIp (Value, &Option->McastIp);
if (EFI_ERROR (Status)) {
return Status;
}
while ((*Value != 0) && (*Value != ',')) {
Value++;
}
}
if (*Value != ',') {
return EFI_INVALID_PARAMETER;
}
Value++;
//
// Convert the port setting. the server can send us a port number or
// empty string. such as the port in ",,1"
//
if (*Value == ',') {
Option->McastPort = 0;
} else {
Num = NetStringToU32 (Value);
if (Num > 65535) {
return EFI_INVALID_PARAMETER;
}
Option->McastPort = (UINT16) Num;
while (NET_IS_DIGIT (*Value)) {
Value++;
}
}
if (*Value != ',') {
return EFI_INVALID_PARAMETER;
}
Value++;
//
// Check the master/slave setting, 1 for master, 0 for slave.
//
Num = NetStringToU32 (Value);
if ((Num != 0) && (Num != 1)) {
return EFI_INVALID_PARAMETER;
}
Option->Master = (BOOLEAN) (Num == 1);
while (NET_IS_DIGIT (*Value)) {
Value++;
}
if (*Value != '\0') {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Parse the option in Options array to MTFTP4_OPTION which program
can access directly.
@param Options The option array, which contains addresses of each
option's name/value string.
@param Count The number of options in the Options
@param Request Whether this is a request or OACK. The format of
multicast is different according to this setting.
@param Operation The current performed operation.
@param MtftpOption The MTFTP4_OPTION for easy access.
@retval EFI_INVALID_PARAMETER The option is mal-formated
@retval EFI_UNSUPPORTED Some option isn't supported
@retval EFI_SUCCESS The option are OK and has been parsed.
**/
EFI_STATUS
Mtftp4ParseOption (
IN EFI_MTFTP4_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN Request,
IN UINT16 Operation,
OUT MTFTP4_OPTION *MtftpOption
)
{
EFI_STATUS Status;
UINT32 Index;
UINT32 Value;
EFI_MTFTP4_OPTION *This;
MtftpOption->Exist = 0;
for (Index = 0; Index < Count; Index++) {
This = Options + Index;
if ((This->OptionStr == NULL) || (This->ValueStr == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "blksize")) {
//
// block size option, valid value is between [8, 65464]
//
Value = NetStringToU32 (This->ValueStr);
if ((Value < 8) || (Value > 65464)) {
return EFI_INVALID_PARAMETER;
}
MtftpOption->BlkSize = (UINT16) Value;
MtftpOption->Exist |= MTFTP4_BLKSIZE_EXIST;
} else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "timeout")) {
//
// timeout option, valid value is between [1, 255]
//
Value = NetStringToU32 (This->ValueStr);
if ((Value < 1) || (Value > 255)) {
return EFI_INVALID_PARAMETER;
}
MtftpOption->Timeout = (UINT8) Value;
} else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "tsize")) {
//
// tsize option, the biggest transfer supported is 4GB with block size option
//
MtftpOption->Tsize = NetStringToU32 (This->ValueStr);
MtftpOption->Exist |= MTFTP4_TSIZE_EXIST;
} else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "multicast")) {
//
// Multicast option, if it is a request, the value must be a zero
// length string, otherwise, it is formated like "204.0.0.1,1857,1\0"
//
if (Request) {
if (*(This->ValueStr) != '\0') {
return EFI_INVALID_PARAMETER;
}
} else {
Status = Mtftp4ExtractMcast (This->ValueStr, MtftpOption);
if (EFI_ERROR (Status)) {
return Status;
}
}
MtftpOption->Exist |= MTFTP4_MCAST_EXIST;
} else if (NetStringEqualNoCase (This->OptionStr, (UINT8 *) "windowsize")) {
if (Operation == EFI_MTFTP4_OPCODE_WRQ) {
//
// Currently, windowsize is not supported in the write operation.
//
return EFI_UNSUPPORTED;
}
Value = NetStringToU32 (This->ValueStr);
if (Value < 1) {
return EFI_INVALID_PARAMETER;
}
MtftpOption->WindowSize = (UINT16) Value;
MtftpOption->Exist |= MTFTP4_WINDOWSIZE_EXIST;
} else if (Request) {
//
// Ignore the unsupported option if it is a reply, and return
// EFI_UNSUPPORTED if it's a request according to the UEFI spec.
//
return EFI_UNSUPPORTED;
}
}
return EFI_SUCCESS;
}
/**
Parse the options in the OACK packet to MTFTP4_OPTION which program
can access directly.
@param Packet The OACK packet to parse
@param PacketLen The length of the packet
@param Operation The current performed operation.
@param MtftpOption The MTFTP_OPTION for easy access.
@retval EFI_INVALID_PARAMETER The packet option is mal-formated
@retval EFI_UNSUPPORTED Some option isn't supported
@retval EFI_SUCCESS The option are OK and has been parsed.
**/
EFI_STATUS
Mtftp4ParseOptionOack (
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 PacketLen,
IN UINT16 Operation,
OUT MTFTP4_OPTION *MtftpOption
)
{
EFI_MTFTP4_OPTION *OptionList;
EFI_STATUS Status;
UINT32 Count;
MtftpOption->Exist = 0;
Status = Mtftp4ExtractOptions (Packet, PacketLen, &Count, &OptionList);
if (EFI_ERROR (Status) || (Count == 0)) {
return Status;
}
ASSERT (OptionList != NULL);
Status = Mtftp4ParseOption (OptionList, Count, FALSE, Operation, MtftpOption);
FreePool (OptionList);
return Status;
}

View File

@@ -1,111 +0,0 @@
/** @file
Routines to process MTFTP4 options.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __EFI_MTFTP4_OPTION_H__
#define __EFI_MTFTP4_OPTION_H__
#define MTFTP4_SUPPORTED_OPTIONS 5
#define MTFTP4_OPCODE_LEN 2
#define MTFTP4_ERRCODE_LEN 2
#define MTFTP4_BLKNO_LEN 2
#define MTFTP4_DATA_HEAD_LEN 4
#define MTFTP4_BLKSIZE_EXIST 0x01
#define MTFTP4_TIMEOUT_EXIST 0x02
#define MTFTP4_TSIZE_EXIST 0x04
#define MTFTP4_MCAST_EXIST 0x08
#define MTFTP4_WINDOWSIZE_EXIST 0x10
typedef struct {
UINT16 BlkSize;
UINT16 WindowSize;
UINT8 Timeout;
UINT32 Tsize;
IP4_ADDR McastIp;
UINT16 McastPort;
BOOLEAN Master;
UINT32 Exist;
} MTFTP4_OPTION;
/**
Allocate and fill in a array of Mtftp options from the Packet.
It first calls Mtftp4FillOption to get the option number, then allocate
the array, at last, call Mtftp4FillOption again to save the options.
@param Packet The packet to parse
@param PacketLen The length of the packet
@param OptionCount The number of options in the packet
@param OptionList The point to get the option array.
@retval EFI_INVALID_PARAMETER The parametera are invalid or packet isn't a
well-formated OACK packet.
@retval EFI_SUCCESS The option array is build
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the array
**/
EFI_STATUS
Mtftp4ExtractOptions (
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 PacketLen,
OUT UINT32 *OptionCount,
OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL
);
/**
Parse the option in Options array to MTFTP4_OPTION which program
can access directly.
@param Options The option array, which contains addresses of each
option's name/value string.
@param Count The number of options in the Options
@param Request Whether this is a request or OACK. The format of
multicast is different according to this setting.
@param Operation The current performed operation.
@param MtftpOption The MTFTP4_OPTION for easy access.
@retval EFI_INVALID_PARAMETER The option is mal-formated
@retval EFI_UNSUPPORTED Some option isn't supported
@retval EFI_SUCCESS The option are OK and has been parsed.
**/
EFI_STATUS
Mtftp4ParseOption (
IN EFI_MTFTP4_OPTION *Options,
IN UINT32 Count,
IN BOOLEAN Request,
IN UINT16 Operation,
OUT MTFTP4_OPTION *MtftpOption
);
/**
Parse the options in the OACK packet to MTFTP4_OPTION which program
can access directly.
@param Packet The OACK packet to parse
@param PacketLen The length of the packet
@param Operation The current performed operation.
@param MtftpOption The MTFTP_OPTION for easy access.
@retval EFI_INVALID_PARAMETER The packet option is mal-formated
@retval EFI_UNSUPPORTED Some option isn't supported
@retval EFI_SUCCESS The option are OK and has been parsed.
**/
EFI_STATUS
Mtftp4ParseOptionOack (
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 PacketLen,
IN UINT16 Operation,
OUT MTFTP4_OPTION *MtftpOption
);
extern CHAR8 *mMtftp4SupportedOptions[MTFTP4_SUPPORTED_OPTIONS];
#endif

Some files were not shown because too many files have changed in this diff Show More