summaryrefslogtreecommitdiff
path: root/edk2/StdLib/UseSocketDxe
diff options
context:
space:
mode:
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-07-30 00:30:44 +0000
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-07-30 00:30:44 +0000
commitbb64bed6e0995b2f15cdc7b45c8d2c2b5401b66f (patch)
tree88cec7c47ab8439466cb8a284bbb2b7b6f3c7336 /edk2/StdLib/UseSocketDxe
parent20efe4ede0bf83a2034392f8334ee606f97fa01b (diff)
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@12061 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'edk2/StdLib/UseSocketDxe')
-rw-r--r--edk2/StdLib/UseSocketDxe/UseSocketDxe.c160
-rw-r--r--edk2/StdLib/UseSocketDxe/UseSocketDxe.inf45
2 files changed, 205 insertions, 0 deletions
diff --git a/edk2/StdLib/UseSocketDxe/UseSocketDxe.c b/edk2/StdLib/UseSocketDxe/UseSocketDxe.c
new file mode 100644
index 000000000..0b7194c23
--- /dev/null
+++ b/edk2/StdLib/UseSocketDxe/UseSocketDxe.c
@@ -0,0 +1,160 @@
+/** @file
+ Implement the connection to the socket driver
+
+ 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 <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/EfiSocket.h>
+#include <Protocol/ServiceBinding.h>
+
+
+/**
+ Connect to the socket driver
+
+ @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_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ int RetVal;
+ EFI_HANDLE SocketHandle;
+ EFI_STATUS Status;
+
+ //
+ // Locate the socket protocol
+ //
+ Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,
+ NULL,
+ (VOID **)&pServiceBinding );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Create a new socket
+ //
+ SocketHandle = NULL;
+ Status = pServiceBinding->CreateChild ( pServiceBinding,
+ &SocketHandle );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Get the socket protocol
+ //
+ Status = gBS->OpenProtocol ( SocketHandle,
+ &gEfiSocketProtocolGuid,
+ (VOID **)ppSocketProtocol,
+ NULL,
+ NULL,
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Success!
+ //
+ RetVal = 0;
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
+ SocketHandle,
+ Status ));
+ RetVal = ENODEV;
+ }
+ }
+ else {
+ //
+ // Translate the error
+ //
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - CreateChild failed, Status: %r\r\n",
+ Status ));
+ switch ( Status ) {
+ case EFI_SUCCESS:
+ RetVal = 0;
+ break;
+
+ case EFI_ACCESS_DENIED:
+ case EFI_WRITE_PROTECTED:
+ RetVal = EACCES;
+ break;
+
+ case EFI_NO_RESPONSE:
+ RetVal = EHOSTUNREACH;
+ break;
+
+ case EFI_BAD_BUFFER_SIZE:
+ case EFI_BUFFER_TOO_SMALL:
+ case EFI_INVALID_PARAMETER:
+ RetVal = EINVAL;
+ break;
+
+ case EFI_DEVICE_ERROR:
+ case EFI_MEDIA_CHANGED:
+ case EFI_NO_MEDIA:
+ case EFI_VOLUME_CORRUPTED:
+ RetVal = EIO;
+ break;
+
+ case EFI_NOT_FOUND:
+ RetVal = ENOENT;
+ break;
+
+ default:
+ case EFI_OUT_OF_RESOURCES:
+ RetVal = ENOMEM;
+ break;
+
+ case EFI_VOLUME_FULL:
+ RetVal = ENOSPC;
+ break;
+
+ case EFI_UNSUPPORTED:
+ RetVal = ENOSYS;
+ break;
+
+ case EFI_NO_MAPPING:
+ RetVal = ENXIO;
+ break;
+
+ case EFI_LOAD_ERROR:
+ RetVal = ESRCH;
+ break;
+
+ case EFI_TIMEOUT:
+ RetVal = ETIMEDOUT;
+ break;
+
+ case EFI_NOT_READY:
+ RetVal = EWOULDBLOCK;
+ break;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - No socket service binding protocol, Status: %r\r\n",
+ Status ));
+ RetVal = ENODEV;
+ }
+
+ //
+ // Return the operation status
+ //
+ return RetVal;
+}
diff --git a/edk2/StdLib/UseSocketDxe/UseSocketDxe.inf b/edk2/StdLib/UseSocketDxe/UseSocketDxe.inf
new file mode 100644
index 000000000..45fb70f29
--- /dev/null
+++ b/edk2/StdLib/UseSocketDxe/UseSocketDxe.inf
@@ -0,0 +1,45 @@
+#/** @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 = UseSocketDxe
+ FILE_GUID = 1A6853C8-F362-4f68-A77E-0B304A194C05
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UseSocketDxe
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UseSocketDxe.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ StdLib/StdLib.dec
+# SocketPkg/SocketPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ UefiBootServicesTableLib
+ BaseMemoryLib
+ DebugLib
+
+[Protocols]
+ gEfiSocketProtocolGuid
+ gEfiSocketServiceBindingProtocolGuid