]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/EfiSocketLib/DxeSupport.c
StdLib: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / StdLib / EfiSocketLib / DxeSupport.c
CommitLineData
a88c3163 1/** @file\r
2 SocketDxe support routines\r
3\r
0a2530ea
MK
4 Copyright (c) 2011, Intel Corporation. All rights reserved.\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a88c3163 6\r
7**/\r
8\r
9#include "Socket.h"\r
10\r
11\r
12/**\r
13 Creates a child handle and installs gEfiSocketProtocolGuid.\r
14\r
15 This routine creates a child handle for the socket driver and\r
16 installs the ::gEfiSocketProtocolGuid on that handle with a pointer\r
17 to the ::EFI_SOCKET_PROTOCOL structure address.\r
18\r
19 This routine is called by ::EslServiceGetProtocol in UseSocketDxe\r
20 when the socket application is linked with UseSocketDxe.\r
21\r
22 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.\r
23 @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,\r
24 then a new handle is created. If it is a pointer to an existing UEFI handle, \r
25 then the protocol is added to the existing UEFI handle.\r
26\r
27 @retval EFI_SUCCESS The protocol was added to ChildHandle.\r
28 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
b6173a3a 29 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r
a88c3163 30 the child\r
31 @retval other The child handle was not created\r
32\r
33**/\r
34EFI_STATUS\r
35EFIAPI\r
36EslDxeCreateChild (\r
37 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,\r
38 IN OUT EFI_HANDLE * pChildHandle\r
39 )\r
40{\r
41 ESL_SOCKET * pSocket;\r
42 EFI_STATUS Status;\r
43\r
44 DBG_ENTER ( );\r
45\r
46 //\r
47 // Create a socket structure\r
48 //\r
49 Status = EslSocketAllocate ( pChildHandle,\r
50 DEBUG_SOCKET,\r
51 &pSocket );\r
52\r
53 //\r
54 // Return the operation status\r
55 //\r
56 DBG_EXIT_STATUS ( Status );\r
57 return Status;\r
58}\r
59\r
60\r
61/**\r
62 Removes gEfiSocketProtocolGuid and destroys the child handle.\r
63\r
64 This routine uninstalls ::gEfiSocketProtocolGuid from the child handle\r
65 and destroys the child handle if necessary.\r
66\r
67 This routine is called from ???.\r
68 \r
69 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.\r
70 @param [in] ChildHandle Handle of the child to destroy\r
71\r
72 @retval EFI_SUCCESS The protocol was removed from ChildHandle.\r
73 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r
74 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.\r
75 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r
76 because its services are being used.\r
77 @retval other The child handle was not destroyed\r
78\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82EslDxeDestroyChild (\r
83 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,\r
84 IN EFI_HANDLE ChildHandle\r
85 )\r
86{\r
87 ESL_LAYER * pLayer;\r
a88c3163 88 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
89 EFI_STATUS Status;\r
a88c3163 90\r
91 DBG_ENTER ( );\r
92\r
93 //\r
94 // Locate the socket control structure\r
95 //\r
96 pLayer = &mEslLayer;\r
97 Status = gBS->OpenProtocol (\r
98 ChildHandle,\r
99 &gEfiSocketProtocolGuid,\r
100 (VOID **)&pSocketProtocol,\r
101 pLayer->ImageHandle,\r
102 NULL,\r
103 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
104 );\r
105 if ( !EFI_ERROR ( Status )) {\r
a88c3163 106 //\r
4652be0c 107 // Free the socket resources\r
a88c3163 108 //\r
4652be0c 109 Status = EslSocketFree ( pSocketProtocol, NULL );\r
a88c3163 110 }\r
111 else {\r
112 DEBUG (( DEBUG_ERROR,\r
113 "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",\r
114 ChildHandle,\r
115 Status ));\r
116 }\r
117\r
118 //\r
119 // Return the operation status\r
120 //\r
121 DBG_EXIT_STATUS ( Status );\r
122 return Status;\r
123}\r
124\r
125\r
126/**\r
127Install the socket service\r
128\r
129This routine installs the ::gEfiSocketServiceBindingProtocolGuid\r
130on the SocketDxe image handle to announce the availability\r
131of the socket layer to the rest of EFI.\r
132\r
133SocketDxe's EntryPoint routine calls this routine to\r
134make the socket layer available.\r
135\r
136@param [in] pImageHandle Address of the image handle\r
137\r
138@retval EFI_SUCCESS Service installed successfully\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142EslDxeInstall (\r
143 IN EFI_HANDLE * pImageHandle\r
144 )\r
145{\r
146 EFI_STATUS Status;\r
147\r
148 //\r
149 // Install the socket service binding protocol\r
150 //\r
151 Status = gBS->InstallMultipleProtocolInterfaces (\r
152 pImageHandle,\r
153 &gEfiSocketServiceBindingProtocolGuid,\r
154 mEslLayer.pServiceBinding,\r
155 NULL\r
156 );\r
157 if ( !EFI_ERROR ( Status )) {\r
158 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
159 "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",\r
160 *pImageHandle ));\r
161 }\r
162 else {\r
163 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
164 "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",\r
165 Status ));\r
166 }\r
167\r
168 //\r
169 // Return the operation status\r
170 //\r
171 return Status;\r
172}\r
173\r
174\r
175/**\r
176Uninstall the socket service\r
177\r
178This routine removes the gEfiSocketServiceBindingProtocolGuid from\r
179the SocketDxe image handle to notify EFI that the socket layer\r
180is no longer available.\r
181\r
182SocketDxe's DriverUnload routine calls this routine to remove the\r
183socket layer.\r
184\r
185@param [in] ImageHandle Handle for the image.\r
186\r
187@retval EFI_SUCCESS Service installed successfully\r
188**/\r
189EFI_STATUS\r
190EFIAPI\r
191EslDxeUninstall (\r
192 IN EFI_HANDLE ImageHandle\r
193 )\r
194{\r
195 EFI_STATUS Status;\r
196\r
197 //\r
198 // Install the socket service binding protocol\r
199 //\r
200 Status = gBS->UninstallMultipleProtocolInterfaces (\r
201 ImageHandle,\r
202 &gEfiSocketServiceBindingProtocolGuid,\r
203 mEslLayer.pServiceBinding,\r
204 NULL\r
205 );\r
206 if ( !EFI_ERROR ( Status )) {\r
207 DEBUG (( DEBUG_POOL | DEBUG_INIT,\r
208 "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",\r
209 ImageHandle ));\r
210 }\r
211 else {\r
212 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
213 "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",\r
214 ImageHandle,\r
215 Status ));\r
216 }\r
217\r
218 //\r
219 // Return the operation status\r
220 //\r
221 return Status;\r
222}\r