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 EFI socket library
28 This routine establishes a connection to the socket driver
29 and returns the API (::EFI_SOCKET_PROTOCOL address) to the
30 socket file system layer in BsdSocketLib. This routine looks for
31 the gEfiSocketServiceBindingProtocolGuid to locate the socket
32 driver. This routine then creates a child handle and locates
33 the gEfiSocketProtocolGuid protocol on that handle to get the
34 ::EFI_SOCKET_PROTOCOL structure address.
36 This routine is called from the ::socket routine in BsdSocketLib
37 to create the data structure and initialize the API for a socket.
38 Note that this implementation is only used by socket applications
39 that link directly to UseSocketDxe.
41 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
44 @return Value for ::errno, zero (0) indicates success.
48 EslServiceGetProtocol (
49 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
52 EFI_SERVICE_BINDING_PROTOCOL
* pServiceBinding
;
54 EFI_HANDLE SocketHandle
;
58 // Locate the socket protocol
60 Status
= gBS
->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid
,
62 (VOID
**)&pServiceBinding
);
63 if ( !EFI_ERROR ( Status
)) {
65 // Create a new socket
68 Status
= pServiceBinding
->CreateChild ( pServiceBinding
,
70 if ( !EFI_ERROR ( Status
)) {
72 // Get the socket protocol
74 Status
= gBS
->OpenProtocol ( SocketHandle
,
75 &gEfiSocketProtocolGuid
,
76 (VOID
**)ppSocketProtocol
,
79 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
);
80 if ( !EFI_ERROR ( Status
)) {
88 "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
96 // Translate the error
99 "ERROR - CreateChild failed, Status: %r\r\n",
106 case EFI_ACCESS_DENIED
:
107 case EFI_WRITE_PROTECTED
:
111 case EFI_NO_RESPONSE
:
112 RetVal
= EHOSTUNREACH
;
115 case EFI_BAD_BUFFER_SIZE
:
116 case EFI_BUFFER_TOO_SMALL
:
117 case EFI_INVALID_PARAMETER
:
121 case EFI_DEVICE_ERROR
:
122 case EFI_MEDIA_CHANGED
:
124 case EFI_VOLUME_CORRUPTED
:
133 case EFI_OUT_OF_RESOURCES
:
137 case EFI_VOLUME_FULL
:
141 case EFI_UNSUPPORTED
:
158 RetVal
= EWOULDBLOCK
;
164 DEBUG (( DEBUG_ERROR
,
165 "ERROR - Socket driver not loaded, Status: %r\r\n",
171 // Return the operation status