Add Socket Libraries.
Add Posix functions for porting compatibility. Fix compliance issues with ISO/IEC 9899:199409 New Functions: setenv(), fparseln(), GetFileNameFromPath(), rename(), realpath(), setprogname(), getprogname(), strlcat(), strlcpy(), strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(), mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(), writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(), bcopy(), git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
56
StdLib/EfiSocketLib/EfiSocketLib.inf
Normal file
56
StdLib/EfiSocketLib/EfiSocketLib.inf
Normal file
@@ -0,0 +1,56 @@
|
||||
#/** @file
|
||||
# Component description file for the EFI socket library.
|
||||
#
|
||||
# This module implements the socket layer.
|
||||
# Copyright (c) 2011, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = EfiSocketLib
|
||||
FILE_GUID = C33E0B7C-9D0F-41df-BDFD-08F5E4C39EE8
|
||||
MODULE_TYPE = BASE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = EfiSocketLib
|
||||
CONSTRUCTOR = EslConstructor
|
||||
DESTRUCTOR = EslDestructor
|
||||
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources.common]
|
||||
Init.c
|
||||
Service.c
|
||||
Socket.c
|
||||
Tcp4.c
|
||||
Udp4.c
|
||||
UseEfiSocketLib.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
StdLib/StdLib.dec
|
||||
# SocketPkg/SocketPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
||||
|
||||
[Protocols]
|
||||
gEfiTcp4ProtocolGuid
|
||||
gEfiTcp4ServiceBindingProtocolGuid
|
||||
gEfiUdp4ProtocolGuid
|
||||
gEfiUdp4ServiceBindingProtocolGuid
|
||||
gEfiSocketProtocolGuid
|
||||
gEfiSocketServiceBindingProtocolGuid
|
87
StdLib/EfiSocketLib/Init.c
Normal file
87
StdLib/EfiSocketLib/Init.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/** @file
|
||||
Implement the constructor and destructor for the EFI socket library
|
||||
|
||||
Copyright (c) 2011, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <socket.h>
|
||||
|
||||
|
||||
/**
|
||||
EFI Socket Library Constructor
|
||||
|
||||
@retval EFI_SUCCESS The initialization was successful
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslConstructor (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Assume success
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// Call the image dependent constructor if available
|
||||
//
|
||||
if ( NULL != mpfnEslConstructor ) {
|
||||
Status = mpfnEslConstructor ( );
|
||||
}
|
||||
|
||||
//
|
||||
// Return the constructor status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
EFI Socket Library Destructor
|
||||
|
||||
@retval EFI_SUCCESS The shutdown was successful
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslDestructor (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Assume success
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// Call the image dependent destructor if available
|
||||
//
|
||||
if ( NULL != mpfnEslDestructor ) {
|
||||
Status = mpfnEslDestructor ( );
|
||||
}
|
||||
|
||||
//
|
||||
// Return the constructor status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
529
StdLib/EfiSocketLib/Service.c
Normal file
529
StdLib/EfiSocketLib/Service.c
Normal file
@@ -0,0 +1,529 @@
|
||||
/** @file
|
||||
Connect to and disconnect from the various network layers
|
||||
|
||||
Copyright (c) 2011, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
EFI_TCP4_PROTOCOL * mpEfiTcpClose4 [ 1024 ];
|
||||
|
||||
|
||||
/**
|
||||
Connect to the network service bindings
|
||||
|
||||
Walk the network service protocols on the controller handle and
|
||||
locate any that are not in use. Create service structures to
|
||||
manage the service binding for the socket driver.
|
||||
|
||||
@param [in] BindingHandle Handle for protocol binding.
|
||||
@param [in] Controller Handle of device to work with.
|
||||
|
||||
@retval EFI_SUCCESS This driver is added to Controller.
|
||||
@retval other This driver does not support this device.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslServiceConnect (
|
||||
IN EFI_HANDLE BindingHandle,
|
||||
IN EFI_HANDLE Controller
|
||||
)
|
||||
{
|
||||
BOOLEAN bInUse;
|
||||
UINTN LengthInBytes;
|
||||
CONST DT_SOCKET_BINDING * pEnd;
|
||||
VOID * pJunk;
|
||||
VOID * pInterface;
|
||||
DT_SERVICE * pService;
|
||||
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||
EFI_STATUS Status;
|
||||
EFI_TPL TplPrevious;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Assume the list is empty
|
||||
//
|
||||
Status = EFI_UNSUPPORTED;
|
||||
bInUse = FALSE;
|
||||
|
||||
//
|
||||
// Walk the list of network connection points
|
||||
//
|
||||
pSocketBinding = &cEslSocketBinding[0];
|
||||
pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
|
||||
while ( pEnd > pSocketBinding ) {
|
||||
//
|
||||
// Determine if the controller supports the network protocol
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
Controller,
|
||||
pSocketBinding->pNetworkBinding,
|
||||
&pInterface,
|
||||
BindingHandle,
|
||||
Controller,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
//
|
||||
// Determine if the socket layer is already connected
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
Controller,
|
||||
(EFI_GUID *)pSocketBinding->pTagGuid,
|
||||
&pJunk,
|
||||
BindingHandle,
|
||||
Controller,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if ( EFI_UNSUPPORTED == Status ) {
|
||||
//
|
||||
// Allocate a service structure since the tag is not present
|
||||
//
|
||||
LengthInBytes = sizeof ( *pService );
|
||||
Status = gBS->AllocatePool (
|
||||
EfiRuntimeServicesData,
|
||||
LengthInBytes,
|
||||
(VOID **) &pService
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"0x%08x: Allocate pService, %d bytes\r\n",
|
||||
pService,
|
||||
LengthInBytes ));
|
||||
|
||||
//
|
||||
// Set the structure signature and service binding
|
||||
//
|
||||
ZeroMem ( pService, LengthInBytes );
|
||||
pService->Signature = SERVICE_SIGNATURE;
|
||||
pService->pSocketBinding = pSocketBinding;
|
||||
pService->Controller = Controller;
|
||||
pService->pInterface = pInterface;
|
||||
|
||||
//
|
||||
// Mark the controller in use
|
||||
//
|
||||
if ( !bInUse ) {
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Controller,
|
||||
&gEfiCallerIdGuid,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Installed: gEfiCallerIdGuid on 0x%08x\r\n",
|
||||
Controller ));
|
||||
bInUse = TRUE;
|
||||
}
|
||||
else {
|
||||
if ( EFI_INVALID_PARAMETER == Status ) {
|
||||
Status = EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
//
|
||||
// Mark the network service protocol in use
|
||||
//
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Controller,
|
||||
pSocketBinding->pTagGuid,
|
||||
pService,
|
||||
NULL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Installed: %s TagGuid on 0x%08x\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller ));
|
||||
|
||||
//
|
||||
// Synchronize with the socket layer
|
||||
//
|
||||
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
|
||||
|
||||
//
|
||||
// Initialize the service
|
||||
//
|
||||
Status = pSocketBinding->pfnInitialize ( pService );
|
||||
|
||||
//
|
||||
// Release the socket layer synchronization
|
||||
//
|
||||
RESTORE_TPL ( TplPrevious );
|
||||
|
||||
//
|
||||
// Determine if the initialization was successful
|
||||
//
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - Failed to initialize service %s on 0x%08x, Status: %r\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller,
|
||||
Status ));
|
||||
|
||||
//
|
||||
// Free the network service binding if necessary
|
||||
//
|
||||
gBS->UninstallMultipleProtocolInterfaces (
|
||||
Controller,
|
||||
pSocketBinding->pTagGuid,
|
||||
pService,
|
||||
NULL );
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Removed: %s TagGuid from 0x%08x\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller ));
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - Failed to install %s TagGuid on 0x%08x, Status: %r\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller,
|
||||
Status ));
|
||||
}
|
||||
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
//
|
||||
// The controller is no longer in use
|
||||
//
|
||||
if ( bInUse ) {
|
||||
gBS->UninstallMultipleProtocolInterfaces (
|
||||
Controller,
|
||||
&gEfiCallerIdGuid,
|
||||
NULL,
|
||||
NULL );
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Removed: gEfiCallerIdGuid from 0x%08x\r\n",
|
||||
Controller ));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_INIT,
|
||||
"ERROR - Failed to install gEfiCallerIdGuid on 0x%08x, Status: %r\r\n",
|
||||
Controller,
|
||||
Status ));
|
||||
}
|
||||
|
||||
//
|
||||
// Release the service if necessary
|
||||
//
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
gBS->FreePool ( pService );
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"0x%08x: Free pService, %d bytes\r\n",
|
||||
pService,
|
||||
sizeof ( *pService )));
|
||||
pService = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_INIT,
|
||||
"ERROR - Failed service allocation, Status: %r\r\n",
|
||||
Status ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Set the next network protocol
|
||||
//
|
||||
pSocketBinding += 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Display the driver start status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Shutdown the network connections to this controller by removing
|
||||
NetworkInterfaceIdentifier protocol and closing the DevicePath
|
||||
and PciIo protocols on Controller.
|
||||
|
||||
@param [in] BindingHandle Handle for protocol binding.
|
||||
@param [in] Controller Handle of device to stop driver on.
|
||||
|
||||
@retval EFI_SUCCESS This driver is removed Controller.
|
||||
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
||||
@retval other This driver was not removed from this device.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslServiceDisconnect (
|
||||
IN EFI_HANDLE BindingHandle,
|
||||
IN EFI_HANDLE Controller
|
||||
)
|
||||
{
|
||||
CONST DT_SOCKET_BINDING * pEnd;
|
||||
DT_SERVICE * pService;
|
||||
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||
EFI_STATUS Status;
|
||||
EFI_TPL TplPrevious;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Walk the list of network connection points in reverse order
|
||||
//
|
||||
pEnd = &cEslSocketBinding[0];
|
||||
pSocketBinding = &pEnd[ cEslSocketBindingEntries ];
|
||||
while ( pEnd < pSocketBinding ) {
|
||||
//
|
||||
// Set the next network protocol
|
||||
//
|
||||
pSocketBinding -= 1;
|
||||
|
||||
//
|
||||
// Determine if the driver connected
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
Controller,
|
||||
(EFI_GUID *)pSocketBinding->pTagGuid,
|
||||
(VOID **)&pService,
|
||||
BindingHandle,
|
||||
Controller,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
|
||||
//
|
||||
// Synchronize with the socket layer
|
||||
//
|
||||
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
|
||||
|
||||
//
|
||||
// Shutdown the service
|
||||
//
|
||||
pSocketBinding->pfnShutdown ( pService );
|
||||
|
||||
//
|
||||
// Release the socket layer synchronization
|
||||
//
|
||||
RESTORE_TPL ( TplPrevious );
|
||||
|
||||
//
|
||||
// Break the driver connection
|
||||
//
|
||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||
Controller,
|
||||
pSocketBinding->pTagGuid,
|
||||
pService,
|
||||
NULL );
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"Removed: %s TagGuid from 0x%08x\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller ));
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - Failed to removed %s TagGuid from 0x%08x, Status: %r\r\n",
|
||||
pSocketBinding->pName,
|
||||
Controller,
|
||||
Status ));
|
||||
}
|
||||
|
||||
//
|
||||
// Free the service structure
|
||||
//
|
||||
Status = gBS->FreePool ( pService );
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"0x%08x: Free pService, %d bytes\r\n",
|
||||
pService,
|
||||
sizeof ( *pService )));
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - Failed to free pService 0x%08x, Status: %r\r\n",
|
||||
pService,
|
||||
Status ));
|
||||
}
|
||||
pService = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The controller is no longer in use
|
||||
//
|
||||
gBS->UninstallMultipleProtocolInterfaces (
|
||||
Controller,
|
||||
&gEfiCallerIdGuid,
|
||||
NULL,
|
||||
NULL );
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Removed: gEfiCallerIdGuid from 0x%08x\r\n",
|
||||
Controller ));
|
||||
|
||||
//
|
||||
// The driver is disconnected from the network controller
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// Display the driver start status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Install the socket service
|
||||
|
||||
@param [in] pImageHandle Address of the image handle
|
||||
|
||||
@retval EFI_SUCCESS Service installed successfully
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslServiceInstall (
|
||||
IN EFI_HANDLE * pImageHandle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Install the socket service binding protocol
|
||||
//
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
pImageHandle,
|
||||
&gEfiSocketServiceBindingProtocolGuid,
|
||||
&mEslLayer.ServiceBinding,
|
||||
NULL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||
"Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
|
||||
*pImageHandle ));
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
|
||||
Status ));
|
||||
}
|
||||
|
||||
//
|
||||
// Return the operation status
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Initialize the service layer
|
||||
|
||||
@param [in] ImageHandle Handle for the image.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
EslServiceLoad (
|
||||
IN EFI_HANDLE ImageHandle
|
||||
)
|
||||
{
|
||||
DT_LAYER * pLayer;
|
||||
|
||||
//
|
||||
// Save the image handle
|
||||
//
|
||||
pLayer = &mEslLayer;
|
||||
pLayer->Signature = LAYER_SIGNATURE;
|
||||
pLayer->ImageHandle = ImageHandle;
|
||||
|
||||
//
|
||||
// Initialize the TCP4 close
|
||||
//
|
||||
pLayer->TcpCloseMax4 = DIM ( mpEfiTcpClose4 );
|
||||
pLayer->ppTcpClose4 = mpEfiTcpClose4;
|
||||
|
||||
//
|
||||
// Connect the service binding protocol to the image handle
|
||||
//
|
||||
pLayer->ServiceBinding.CreateChild = EslSocketCreateChild;
|
||||
pLayer->ServiceBinding.DestroyChild = EslSocketDestroyChild;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Uninstall the socket service
|
||||
|
||||
@param [in] ImageHandle Handle for the image.
|
||||
|
||||
@retval EFI_SUCCESS Service installed successfully
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
EslServiceUninstall (
|
||||
IN EFI_HANDLE ImageHandle
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Install the socket service binding protocol
|
||||
//
|
||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||
ImageHandle,
|
||||
&gEfiSocketServiceBindingProtocolGuid,
|
||||
&mEslLayer.ServiceBinding,
|
||||
NULL
|
||||
);
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||
"Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
|
||||
ImageHandle ));
|
||||
}
|
||||
else {
|
||||
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||
"ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
|
||||
ImageHandle,
|
||||
Status ));
|
||||
}
|
||||
|
||||
//
|
||||
// Return the operation status
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Shutdown the service layer
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
EslServiceUnload (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
DT_LAYER * pLayer;
|
||||
|
||||
//
|
||||
// Undo the work by ServiceLoad
|
||||
//
|
||||
pLayer = &mEslLayer;
|
||||
pLayer->ImageHandle = NULL;
|
||||
pLayer->ServiceBinding.CreateChild = NULL;
|
||||
pLayer->ServiceBinding.DestroyChild = NULL;
|
||||
}
|
3091
StdLib/EfiSocketLib/Socket.c
Normal file
3091
StdLib/EfiSocketLib/Socket.c
Normal file
File diff suppressed because it is too large
Load Diff
1337
StdLib/EfiSocketLib/Socket.h
Normal file
1337
StdLib/EfiSocketLib/Socket.h
Normal file
File diff suppressed because it is too large
Load Diff
3415
StdLib/EfiSocketLib/Tcp4.c
Normal file
3415
StdLib/EfiSocketLib/Tcp4.c
Normal file
File diff suppressed because it is too large
Load Diff
2408
StdLib/EfiSocketLib/Udp4.c
Normal file
2408
StdLib/EfiSocketLib/Udp4.c
Normal file
File diff suppressed because it is too large
Load Diff
242
StdLib/EfiSocketLib/UseEfiSocketLib.c
Normal file
242
StdLib/EfiSocketLib/UseEfiSocketLib.c
Normal file
@@ -0,0 +1,242 @@
|
||||
/** @file
|
||||
Implement the connection to the EFI socket library
|
||||
|
||||
Copyright (c) 2011, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <socket.h>
|
||||
|
||||
|
||||
CONST EFI_GUID mEslRawServiceGuid = {
|
||||
0xc31bf4a5, 0x2c7, 0x49d2, { 0xa5, 0x58, 0xfe, 0x62, 0x6f, 0x7e, 0xd4, 0x77 }
|
||||
};
|
||||
|
||||
CONST EFI_GUID mEslTcp4ServiceGuid = {
|
||||
0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
|
||||
};
|
||||
|
||||
CONST EFI_GUID mEslUdp4ServiceGuid = {
|
||||
0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Connect to the EFI socket library
|
||||
|
||||
@param [in] ppSocketProtocol Address to receive the socket protocol address
|
||||
|
||||
@retval 0 Successfully returned the socket protocol
|
||||
@retval other Value for errno
|
||||
**/
|
||||
int
|
||||
EslServiceGetProtocol (
|
||||
IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
|
||||
)
|
||||
{
|
||||
EFI_HANDLE ChildHandle;
|
||||
DT_SOCKET * pSocket;
|
||||
int RetVal;
|
||||
EFI_STATUS Status;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Assume success
|
||||
//
|
||||
RetVal = 0;
|
||||
|
||||
//
|
||||
// Locate the socket protocol
|
||||
//
|
||||
ChildHandle = NULL;
|
||||
Status = EslSocketAllocate ( &ChildHandle,
|
||||
DEBUG_SOCKET,
|
||||
&pSocket );
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
*ppSocketProtocol = &pSocket->SocketProtocol;
|
||||
}
|
||||
else {
|
||||
//
|
||||
// No resources
|
||||
//
|
||||
RetVal = ENOMEM;
|
||||
}
|
||||
|
||||
//
|
||||
// Return the operation status
|
||||
//
|
||||
DBG_EXIT_DEC ( RetVal );
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Connect to the network layer
|
||||
|
||||
@retval EFI_SUCCESS Successfully connected to the network layer
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EslServiceNetworkConnect (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE * pHandles;
|
||||
UINTN Index;
|
||||
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||
CONST DT_SOCKET_BINDING * pEnd;
|
||||
EFI_STATUS Status;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Initialize the socket layer
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
EslServiceLoad ( gImageHandle );
|
||||
|
||||
//
|
||||
// Connect the network devices
|
||||
//
|
||||
pSocketBinding = &cEslSocketBinding [0];
|
||||
pEnd = &pSocketBinding [ cEslSocketBindingEntries ];
|
||||
while ( pEnd > pSocketBinding ) {
|
||||
//
|
||||
// Attempt to locate the network adapters
|
||||
//
|
||||
HandleCount = 0;
|
||||
pHandles = NULL;
|
||||
Status = gBS->LocateHandleBuffer ( ByProtocol,
|
||||
pSocketBinding->pNetworkBinding,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&pHandles );
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
break;
|
||||
}
|
||||
if ( NULL != pHandles ) {
|
||||
//
|
||||
// Attempt to connect to this network adapter
|
||||
//
|
||||
for ( Index = 0; HandleCount > Index; Index++ ) {
|
||||
Status = EslServiceConnect ( gImageHandle,
|
||||
pHandles [ Index ]);
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Done with the handles
|
||||
//
|
||||
gBS->FreePool ( pHandles );
|
||||
}
|
||||
|
||||
//
|
||||
// Set the next network protocol
|
||||
//
|
||||
pSocketBinding += 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Return the network connection status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Disconnect from the network layer
|
||||
|
||||
@retval EFI_SUCCESS Successfully disconnected from the network layer
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EslServiceNetworkDisconnect (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE * pHandles;
|
||||
UINTN Index;
|
||||
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||
CONST DT_SOCKET_BINDING * pEnd;
|
||||
EFI_STATUS Status;
|
||||
|
||||
DBG_ENTER ( );
|
||||
|
||||
//
|
||||
// Assume success
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
//
|
||||
// Disconnect the network devices
|
||||
//
|
||||
pSocketBinding = &cEslSocketBinding [0];
|
||||
pEnd = &pSocketBinding [ cEslSocketBindingEntries ];
|
||||
while ( pEnd > pSocketBinding ) {
|
||||
//
|
||||
// Attempt to locate the network adapters
|
||||
//
|
||||
HandleCount = 0;
|
||||
pHandles = NULL;
|
||||
Status = gBS->LocateHandleBuffer ( ByProtocol,
|
||||
pSocketBinding->pNetworkBinding,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&pHandles );
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
break;
|
||||
}
|
||||
if ( NULL != pHandles ) {
|
||||
//
|
||||
// Attempt to disconnect from this network adapter
|
||||
//
|
||||
for ( Index = 0; HandleCount > Index; Index++ ) {
|
||||
Status = EslServiceDisconnect ( gImageHandle,
|
||||
pHandles [ Index ]);
|
||||
if ( EFI_ERROR ( Status )) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Done with the handles
|
||||
//
|
||||
gBS->FreePool ( pHandles );
|
||||
}
|
||||
|
||||
//
|
||||
// Set the next network protocol
|
||||
//
|
||||
pSocketBinding += 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Finish the disconnect operation
|
||||
//
|
||||
if ( !EFI_ERROR ( Status )) {
|
||||
EslServiceUnload ( );
|
||||
}
|
||||
|
||||
//
|
||||
// Return the network connection status
|
||||
//
|
||||
DBG_EXIT_STATUS ( Status );
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect;
|
||||
PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;
|
Reference in New Issue
Block a user