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 Free the socket resources
28 This releases the socket resources allocated by calling
29 EslServiceGetProtocol.
31 This routine is called from the ::close routine in BsdSocketLib
32 to release the socket resources.
34 @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL
37 @return Value for ::errno, zero (0) indicates success.
41 EslServiceFreeProtocol (
42 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
45 EFI_SERVICE_BINDING_PROTOCOL
* pServiceBinding
;
55 // Locate the socket protocol
57 Status
= gBS
->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid
,
59 (VOID
**) &pServiceBinding
);
60 if ( !EFI_ERROR ( Status
)) {
64 Status
= pServiceBinding
->DestroyChild ( pServiceBinding
,
65 pSocketProtocol
->SocketHandle
);
67 if ( EFI_ERROR ( Status
)) {
72 // Return the operation status
79 Connect to the EFI socket library
81 This routine establishes a connection to the socket driver
82 and returns the API (::EFI_SOCKET_PROTOCOL address) to the
83 socket file system layer in BsdSocketLib. This routine looks for
84 the gEfiSocketServiceBindingProtocolGuid to locate the socket
85 driver. This routine then creates a child handle and locates
86 the gEfiSocketProtocolGuid protocol on that handle to get the
87 ::EFI_SOCKET_PROTOCOL structure address.
89 This routine is called from the ::socket routine in BsdSocketLib
90 to create the data structure and initialize the API for a socket.
91 Note that this implementation is only used by socket applications
92 that link directly to UseSocketDxe.
94 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
97 @return Value for ::errno, zero (0) indicates success.
101 EslServiceGetProtocol (
102 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
105 EFI_SERVICE_BINDING_PROTOCOL
* pServiceBinding
;
107 EFI_HANDLE SocketHandle
;
111 // Locate the socket protocol
113 Status
= gBS
->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid
,
115 (VOID
**)&pServiceBinding
);
116 if ( !EFI_ERROR ( Status
)) {
118 // Create a new socket
121 Status
= pServiceBinding
->CreateChild ( pServiceBinding
,
123 if ( !EFI_ERROR ( Status
)) {
125 // Get the socket protocol
127 Status
= gBS
->OpenProtocol ( SocketHandle
,
128 &gEfiSocketProtocolGuid
,
129 (VOID
**)ppSocketProtocol
,
132 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
);
133 if ( !EFI_ERROR ( Status
)) {
140 DEBUG (( DEBUG_ERROR
,
141 "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
149 // Translate the error
151 DEBUG (( DEBUG_ERROR
,
152 "ERROR - CreateChild failed, Status: %r\r\n",
159 case EFI_ACCESS_DENIED
:
160 case EFI_WRITE_PROTECTED
:
164 case EFI_NO_RESPONSE
:
165 RetVal
= EHOSTUNREACH
;
168 case EFI_BAD_BUFFER_SIZE
:
169 case EFI_BUFFER_TOO_SMALL
:
170 case EFI_INVALID_PARAMETER
:
174 case EFI_DEVICE_ERROR
:
175 case EFI_MEDIA_CHANGED
:
177 case EFI_VOLUME_CORRUPTED
:
186 case EFI_OUT_OF_RESOURCES
:
190 case EFI_VOLUME_FULL
:
194 case EFI_UNSUPPORTED
:
211 RetVal
= EWOULDBLOCK
;
217 DEBUG (( DEBUG_ERROR
,
218 "ERROR - Socket driver not loaded, Status: %r\r\n",
224 // Return the operation status