--- /dev/null
+/** @file\r
+ Implement the connection to the socket driver\r
+\r
+ Copyright (c) 2011, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/EfiSocket.h>\r
+#include <Protocol/ServiceBinding.h>\r
+\r
+\r
+/**\r
+ Connect to the socket driver\r
+\r
+ @param [in] ppSocketProtocol Address to receive the socket protocol address\r
+\r
+ @retval 0 Successfully returned the socket protocol\r
+ @retval other Value for errno\r
+ **/\r
+int\r
+EslServiceGetProtocol (\r
+ IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r
+ )\r
+{\r
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;\r
+ int RetVal;\r
+ EFI_HANDLE SocketHandle;\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Locate the socket protocol\r
+ //\r
+ Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,\r
+ NULL,\r
+ (VOID **)&pServiceBinding );\r
+ if ( !EFI_ERROR ( Status )) {\r
+ //\r
+ // Create a new socket\r
+ //\r
+ SocketHandle = NULL;\r
+ Status = pServiceBinding->CreateChild ( pServiceBinding,\r
+ &SocketHandle );\r
+ if ( !EFI_ERROR ( Status )) {\r
+ //\r
+ // Get the socket protocol\r
+ //\r
+ Status = gBS->OpenProtocol ( SocketHandle,\r
+ &gEfiSocketProtocolGuid,\r
+ (VOID **)ppSocketProtocol,\r
+ NULL,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );\r
+ if ( !EFI_ERROR ( Status )) {\r
+ //\r
+ // Success!\r
+ //\r
+ RetVal = 0;\r
+ }\r
+ else {\r
+ DEBUG (( DEBUG_ERROR,\r
+ "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",\r
+ SocketHandle,\r
+ Status ));\r
+ RetVal = ENODEV;\r
+ }\r
+ }\r
+ else {\r
+ //\r
+ // Translate the error\r
+ //\r
+ DEBUG (( DEBUG_ERROR,\r
+ "ERROR - CreateChild failed, Status: %r\r\n",\r
+ Status ));\r
+ switch ( Status ) {\r
+ case EFI_SUCCESS:\r
+ RetVal = 0;\r
+ break;\r
+\r
+ case EFI_ACCESS_DENIED:\r
+ case EFI_WRITE_PROTECTED:\r
+ RetVal = EACCES;\r
+ break;\r
+\r
+ case EFI_NO_RESPONSE:\r
+ RetVal = EHOSTUNREACH;\r
+ break;\r
+\r
+ case EFI_BAD_BUFFER_SIZE:\r
+ case EFI_BUFFER_TOO_SMALL:\r
+ case EFI_INVALID_PARAMETER:\r
+ RetVal = EINVAL;\r
+ break;\r
+\r
+ case EFI_DEVICE_ERROR:\r
+ case EFI_MEDIA_CHANGED:\r
+ case EFI_NO_MEDIA:\r
+ case EFI_VOLUME_CORRUPTED:\r
+ RetVal = EIO;\r
+ break;\r
+\r
+ case EFI_NOT_FOUND:\r
+ RetVal = ENOENT;\r
+ break;\r
+\r
+ default:\r
+ case EFI_OUT_OF_RESOURCES:\r
+ RetVal = ENOMEM;\r
+ break;\r
+\r
+ case EFI_VOLUME_FULL:\r
+ RetVal = ENOSPC;\r
+ break;\r
+\r
+ case EFI_UNSUPPORTED:\r
+ RetVal = ENOSYS;\r
+ break;\r
+\r
+ case EFI_NO_MAPPING:\r
+ RetVal = ENXIO;\r
+ break;\r
+\r
+ case EFI_LOAD_ERROR:\r
+ RetVal = ESRCH;\r
+ break;\r
+\r
+ case EFI_TIMEOUT:\r
+ RetVal = ETIMEDOUT;\r
+ break;\r
+\r
+ case EFI_NOT_READY:\r
+ RetVal = EWOULDBLOCK;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ DEBUG (( DEBUG_ERROR,\r
+ "ERROR - No socket service binding protocol, Status: %r\r\n",\r
+ Status ));\r
+ RetVal = ENODEV;\r
+ }\r
+\r
+ //\r
+ // Return the operation status\r
+ //\r
+ return RetVal;\r
+}\r