2 SocketDxe support routines
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.
19 Creates a child handle and installs gEfiSocketProtocolGuid.
21 This routine creates a child handle for the socket driver and
22 installs the ::gEfiSocketProtocolGuid on that handle with a pointer
23 to the ::EFI_SOCKET_PROTOCOL structure address.
25 This routine is called by ::EslServiceGetProtocol in UseSocketDxe
26 when the socket application is linked with UseSocketDxe.
28 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
29 @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
30 then a new handle is created. If it is a pointer to an existing UEFI handle,
31 then the protocol is added to the existing UEFI handle.
33 @retval EFI_SUCCESS The protocol was added to ChildHandle.
34 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
35 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
37 @retval other The child handle was not created
43 IN EFI_SERVICE_BINDING_PROTOCOL
* pThis
,
44 IN OUT EFI_HANDLE
* pChildHandle
53 // Create a socket structure
55 Status
= EslSocketAllocate ( pChildHandle
,
60 // Return the operation status
62 DBG_EXIT_STATUS ( Status
);
68 Removes gEfiSocketProtocolGuid and destroys the child handle.
70 This routine uninstalls ::gEfiSocketProtocolGuid from the child handle
71 and destroys the child handle if necessary.
73 This routine is called from ???.
75 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
76 @param [in] ChildHandle Handle of the child to destroy
78 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
79 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
80 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
81 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
82 because its services are being used.
83 @retval other The child handle was not destroyed
89 IN EFI_SERVICE_BINDING_PROTOCOL
* pThis
,
90 IN EFI_HANDLE ChildHandle
95 ESL_SOCKET
* pSocketPrevious
;
96 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
103 // Locate the socket control structure
106 Status
= gBS
->OpenProtocol (
108 &gEfiSocketProtocolGuid
,
109 (VOID
**)&pSocketProtocol
,
112 EFI_OPEN_PROTOCOL_GET_PROTOCOL
114 if ( !EFI_ERROR ( Status
)) {
115 pSocket
= SOCKET_FROM_PROTOCOL ( pSocketProtocol
);
118 // Synchronize with the socket layer
120 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
123 // Walk the socket list
125 pSocketPrevious
= pLayer
->pSocketList
;
126 if ( NULL
!= pSocketPrevious
) {
127 if ( pSocket
== pSocketPrevious
) {
129 // Remove the socket from the head of the list
131 pLayer
->pSocketList
= pSocket
->pNext
;
135 // Find the socket in the middle of the list
137 while (( NULL
!= pSocketPrevious
)
138 && ( pSocket
!= pSocketPrevious
->pNext
)) {
140 // Set the next socket
142 pSocketPrevious
= pSocketPrevious
->pNext
;
144 if ( NULL
!= pSocketPrevious
) {
146 // Remove the socket from the middle of the list
148 pSocketPrevious
= pSocket
->pNext
;
153 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
,
154 "ERROR - Socket list is empty!\r\n" ));
158 // Release the socket layer synchronization
160 RESTORE_TPL ( TplPrevious
);
163 // Determine if the socket was found
165 if ( NULL
!= pSocketPrevious
) {
166 pSocket
->pNext
= NULL
;
169 // Remove the socket protocol
171 Status
= gBS
->UninstallMultipleProtocolInterfaces (
173 &gEfiSocketProtocolGuid
,
174 &pSocket
->SocketProtocol
,
176 if ( !EFI_ERROR ( Status
)) {
177 DEBUG (( DEBUG_POOL
| DEBUG_INFO
,
178 "Removed: gEfiSocketProtocolGuid from 0x%08x\r\n",
182 // Free the socket structure
184 Status
= gBS
->FreePool ( pSocket
);
185 if ( !EFI_ERROR ( Status
)) {
187 "0x%08x: Free pSocket, %d bytes\r\n",
189 sizeof ( *pSocket
)));
192 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
,
193 "ERROR - Failed to free pSocket 0x%08x, Status: %r\r\n",
199 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INFO
,
200 "ERROR - Failed to remove gEfiSocketProtocolGuid from 0x%08x, Status: %r\r\n",
206 DEBUG (( DEBUG_ERROR
| DEBUG_INFO
,
207 "ERROR - The socket was not in the socket list!\r\n" ));
208 Status
= EFI_NOT_FOUND
;
212 DEBUG (( DEBUG_ERROR
,
213 "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",
219 // Return the operation status
221 DBG_EXIT_STATUS ( Status
);
227 Install the socket service
229 This routine installs the ::gEfiSocketServiceBindingProtocolGuid
230 on the SocketDxe image handle to announce the availability
231 of the socket layer to the rest of EFI.
233 SocketDxe's EntryPoint routine calls this routine to
234 make the socket layer available.
236 @param [in] pImageHandle Address of the image handle
238 @retval EFI_SUCCESS Service installed successfully
243 IN EFI_HANDLE
* pImageHandle
249 // Install the socket service binding protocol
251 Status
= gBS
->InstallMultipleProtocolInterfaces (
253 &gEfiSocketServiceBindingProtocolGuid
,
254 mEslLayer
.pServiceBinding
,
257 if ( !EFI_ERROR ( Status
)) {
258 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
259 "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
263 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
264 "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
269 // Return the operation status
276 Uninstall the socket service
278 This routine removes the gEfiSocketServiceBindingProtocolGuid from
279 the SocketDxe image handle to notify EFI that the socket layer
280 is no longer available.
282 SocketDxe's DriverUnload routine calls this routine to remove the
285 @param [in] ImageHandle Handle for the image.
287 @retval EFI_SUCCESS Service installed successfully
292 IN EFI_HANDLE ImageHandle
298 // Install the socket service binding protocol
300 Status
= gBS
->UninstallMultipleProtocolInterfaces (
302 &gEfiSocketServiceBindingProtocolGuid
,
303 mEslLayer
.pServiceBinding
,
306 if ( !EFI_ERROR ( Status
)) {
307 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
308 "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
312 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
313 "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
319 // Return the operation status