2 Implement the connection to the socket driver
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiLib.h>
21 #include <Protocol/EfiSocket.h>
22 #include <Protocol/ServiceBinding.h>
26 Connect to the socket driver
28 @param [in] ppSocketProtocol Address to receive the socket protocol address
30 @retval 0 Successfully returned the socket protocol
31 @retval other Value for errno
34 EslServiceGetProtocol (
35 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
38 EFI_SERVICE_BINDING_PROTOCOL
* pServiceBinding
;
40 EFI_HANDLE SocketHandle
;
44 // Locate the socket protocol
46 Status
= gBS
->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid
,
48 (VOID
**)&pServiceBinding
);
49 if ( !EFI_ERROR ( Status
)) {
51 // Create a new socket
54 Status
= pServiceBinding
->CreateChild ( pServiceBinding
,
56 if ( !EFI_ERROR ( Status
)) {
58 // Get the socket protocol
60 Status
= gBS
->OpenProtocol ( SocketHandle
,
61 &gEfiSocketProtocolGuid
,
62 (VOID
**)ppSocketProtocol
,
65 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
);
66 if ( !EFI_ERROR ( Status
)) {
74 "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
82 // Translate the error
85 "ERROR - CreateChild failed, Status: %r\r\n",
92 case EFI_ACCESS_DENIED
:
93 case EFI_WRITE_PROTECTED
:
98 RetVal
= EHOSTUNREACH
;
101 case EFI_BAD_BUFFER_SIZE
:
102 case EFI_BUFFER_TOO_SMALL
:
103 case EFI_INVALID_PARAMETER
:
107 case EFI_DEVICE_ERROR
:
108 case EFI_MEDIA_CHANGED
:
110 case EFI_VOLUME_CORRUPTED
:
119 case EFI_OUT_OF_RESOURCES
:
123 case EFI_VOLUME_FULL
:
127 case EFI_UNSUPPORTED
:
144 RetVal
= EWOULDBLOCK
;
150 DEBUG (( DEBUG_ERROR
,
151 "ERROR - No socket service binding protocol, Status: %r\r\n",
157 // Return the operation status