]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/SocketDxe/EntryUnload.c
StdLib: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / StdLib / SocketDxe / EntryUnload.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the entry and unload for the socket driver.\r
3\r
0a2530ea
MK
4 Copyright (c) 2011, Intel Corporation. All rights reserved.\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d7ce7006 6\r
7**/\r
8\r
9#include "Socket.h"\r
10\r
11\r
a88c3163 12/**\r
13 The following GUID values are only used by the SocketDxe driver. An\r
14 alternative set of values exists in EfiSocketLib\UseEfiSocketLib.c\r
15 which an application uses when it links against EfiSocketLib. These\r
16 two sets of values allow the SocketDxe driver to coexist with socket\r
17 applications.\r
18\r
19 Tag GUID - IPv4 in use by SocketDxe\r
20**/\r
21CONST EFI_GUID mEslIp4ServiceGuid = {\r
22 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }\r
d7ce7006 23};\r
24\r
a88c3163 25\r
3bdf9aae 26/**\r
27 Tag GUID - IPv6 in use by SocketDxe\r
28**/\r
29CONST EFI_GUID mEslIp6ServiceGuid = {\r
30 0x2fc3b2d3, 0x6eba, 0x42b0, { 0xa4, 0xa7, 0x14, 0xc7, 0xa8, 0x4b, 0x5d, 0x22 }\r
31};\r
32\r
33\r
a88c3163 34/**\r
35 Tag GUID - TCPv4 in use by SocketDxe\r
36**/\r
d7ce7006 37CONST EFI_GUID mEslTcp4ServiceGuid = {\r
3bdf9aae 38 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }\r
39};\r
40\r
41\r
42/**\r
43 Tag GUID - TCPv6 in use by SocketDxe\r
44**/\r
45CONST EFI_GUID mEslTcp6ServiceGuid = {\r
46 0xdd455a69, 0xec75, 0x456c, { 0x84, 0xd2, 0x95, 0xca, 0xe7, 0xd3, 0xc6, 0xd3 }\r
d7ce7006 47};\r
48\r
a88c3163 49\r
50/**\r
51 Tag GUID - UDPv4 in use by SocketDxe\r
52**/\r
d7ce7006 53CONST EFI_GUID mEslUdp4ServiceGuid = {\r
3bdf9aae 54 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }\r
55};\r
56\r
57\r
58/**\r
59 Tag GUID - UDPv6 in use by SocketDxe\r
60**/\r
61CONST EFI_GUID mEslUdp6ServiceGuid = {\r
62 0x32ff59cd, 0xc33, 0x48d0, { 0xa2, 0x44, 0x4b, 0xb8, 0x11, 0x33, 0x64, 0x3 }\r
d7ce7006 63};\r
64\r
65\r
66/**\r
67 Socket driver unload routine.\r
68\r
69 @param [in] ImageHandle Handle for the image.\r
70\r
71 @retval EFI_SUCCESS Image may be unloaded\r
72\r
73**/\r
74EFI_STATUS\r
75EFIAPI\r
76DriverUnload (\r
77 IN EFI_HANDLE ImageHandle\r
78 )\r
79{\r
80 UINTN BufferSize;\r
81 UINTN Index;\r
82 UINTN Max;\r
83 EFI_HANDLE * pHandle;\r
84 EFI_STATUS Status;\r
85\r
86 //\r
87 // Determine which devices are using this driver\r
88 //\r
89 BufferSize = 0;\r
90 pHandle = NULL;\r
91 Status = gBS->LocateHandle (\r
92 ByProtocol,\r
93 &gEfiCallerIdGuid,\r
94 NULL,\r
95 &BufferSize,\r
96 NULL );\r
97 if ( EFI_BUFFER_TOO_SMALL == Status ) {\r
98 for ( ; ; ) {\r
99 //\r
100 // One or more block IO devices are present\r
101 //\r
102 Status = gBS->AllocatePool (\r
103 EfiRuntimeServicesData,\r
104 BufferSize,\r
105 (VOID **) &pHandle\r
106 );\r
107 if ( EFI_ERROR ( Status )) {\r
108 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
109 "Insufficient memory, failed handle buffer allocation\r\n" ));\r
110 break;\r
111 }\r
112\r
113 //\r
114 // Locate the block IO devices\r
115 //\r
116 Status = gBS->LocateHandle (\r
117 ByProtocol,\r
118 &gEfiCallerIdGuid,\r
119 NULL,\r
120 &BufferSize,\r
121 pHandle );\r
122 if ( EFI_ERROR ( Status )) {\r
123 //\r
124 // Error getting handles\r
125 //\r
126 DEBUG (( DEBUG_ERROR | DEBUG_INIT | DEBUG_INFO,\r
127 "Failure getting Telnet handles\r\n" ));\r
128 break;\r
129 }\r
130 \r
131 //\r
132 // Remove any use of the driver\r
133 //\r
134 Max = BufferSize / sizeof ( pHandle[ 0 ]);\r
135 for ( Index = 0; Max > Index; Index++ ) {\r
a88c3163 136 Status = DriverStop ( &mDriverBinding,\r
d7ce7006 137 pHandle[ Index ],\r
138 0,\r
139 NULL );\r
140 if ( EFI_ERROR ( Status )) {\r
141 DEBUG (( DEBUG_WARN | DEBUG_INIT | DEBUG_INFO,\r
142 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));\r
143 break;\r
144 }\r
145 }\r
146 break;\r
147 }\r
148 }\r
149 else {\r
150 if ( EFI_NOT_FOUND == Status ) {\r
151 //\r
152 // No devices were found\r
153 //\r
154 Status = EFI_SUCCESS;\r
155 }\r
156 }\r
157\r
158 //\r
159 // Free the handle array\r
160 //\r
161 if ( NULL != pHandle ) {\r
162 gBS->FreePool ( pHandle );\r
163 }\r
164\r
165 //\r
166 // Done with the socket layer\r
167 //\r
168 if ( !EFI_ERROR ( Status )) {\r
a88c3163 169 Status = EslDxeUninstall ( ImageHandle );\r
d7ce7006 170 if ( !EFI_ERROR ( Status )) {\r
171 //\r
172 // Remove the protocols installed by the EntryPoint routine.\r
173 //\r
174 Status = gBS->UninstallMultipleProtocolInterfaces (\r
175 ImageHandle,\r
176 &gEfiDriverBindingProtocolGuid,\r
a88c3163 177 &mDriverBinding,\r
d7ce7006 178 &gEfiComponentNameProtocolGuid,\r
a88c3163 179 &mComponentName,\r
d7ce7006 180 &gEfiComponentName2ProtocolGuid,\r
a88c3163 181 &mComponentName2,\r
d7ce7006 182 NULL\r
183 );\r
184 if ( !EFI_ERROR ( Status )) {\r
185 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
186 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
187 ImageHandle ));\r
188 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
189 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
190 ImageHandle ));\r
191 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
192 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
193 ImageHandle ));\r
194 }\r
195 else {\r
196 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
197 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",\r
198 ImageHandle,\r
199 Status ));\r
200 }\r
201 }\r
202 }\r
203\r
204 //\r
205 // Disconnect the network services\r
206 //\r
207 if ( !EFI_ERROR ( Status )) {\r
208 EslServiceUnload ( );\r
209 }\r
210\r
211 //\r
212 // Return the unload status\r
213 //\r
214 return Status;\r
215}\r
216\r
217\r
218/**\r
219Socket driver entry point.\r
220\r
221@param [in] ImageHandle Handle for the image.\r
222@param [in] pSystemTable Address of the system table.\r
223\r
224@retval EFI_SUCCESS Image successfully loaded.\r
225\r
226**/\r
227EFI_STATUS\r
228EFIAPI\r
229EntryPoint (\r
230 IN EFI_HANDLE ImageHandle,\r
231 IN EFI_SYSTEM_TABLE * pSystemTable\r
232 )\r
233{\r
234 EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;\r
235 EFI_STATUS Status;\r
236\r
237 DBG_ENTER ( );\r
238\r
239 //\r
240 // Display the image handle\r
241 //\r
242 DEBUG (( DEBUG_INFO,\r
243 "ImageHandle: 0x%08x\r\n",\r
244 ImageHandle ));\r
245\r
246 //\r
247 // Enable unload support\r
248 //\r
249 Status = gBS->HandleProtocol (\r
250 gImageHandle,\r
251 &gEfiLoadedImageProtocolGuid,\r
252 (VOID **)&pLoadedImage\r
253 );\r
254 if (!EFI_ERROR (Status)) {\r
255 pLoadedImage->Unload = DriverUnload;\r
256\r
257 //\r
258 // Add the driver to the list of drivers\r
259 //\r
260 Status = EfiLibInstallDriverBindingComponentName2 (\r
261 ImageHandle,\r
262 pSystemTable,\r
a88c3163 263 &mDriverBinding,\r
d7ce7006 264 ImageHandle,\r
a88c3163 265 &mComponentName,\r
266 &mComponentName2\r
d7ce7006 267 );\r
268 if ( !EFI_ERROR ( Status )) {\r
269 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
270 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",\r
271 ImageHandle ));\r
272 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
273 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",\r
274 ImageHandle ));\r
275 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
276 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",\r
277 ImageHandle ));\r
278\r
279 //\r
280 // Initialize the service layer\r
281 //\r
282 EslServiceLoad ( ImageHandle );\r
283\r
284 //\r
285 // Make the socket serivces available to other drivers\r
286 // and applications\r
287 //\r
a88c3163 288 Status = EslDxeInstall ( &ImageHandle );\r
d7ce7006 289 if ( EFI_ERROR ( Status )) {\r
290 //\r
291 // Disconnect from the network\r
292 //\r
293 EslServiceUnload ( );\r
294\r
295 //\r
296 // Remove the driver bindings\r
297 //\r
298 gBS->UninstallMultipleProtocolInterfaces (\r
299 ImageHandle,\r
300 &gEfiDriverBindingProtocolGuid,\r
a88c3163 301 &mDriverBinding,\r
d7ce7006 302 &gEfiComponentNameProtocolGuid,\r
a88c3163 303 &mComponentName,\r
d7ce7006 304 &gEfiComponentName2ProtocolGuid,\r
a88c3163 305 &mComponentName2,\r
d7ce7006 306 NULL\r
307 );\r
308 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
309 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
310 ImageHandle ));\r
311 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
312 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
313 ImageHandle ));\r
314 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
315 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
316 ImageHandle ));\r
317 }\r
318 }\r
319 else {\r
320 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
321 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",\r
322 Status ));\r
323 }\r
324 }\r
325 DBG_EXIT_STATUS ( Status );\r
326 return Status;\r
327}\r
328\r
329\r
a88c3163 330/**\r
331 Socket layer's service binding protocol delcaration.\r
332**/\r
333CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {\r
334 EslDxeCreateChild,\r
335 EslDxeDestroyChild\r
336};\r
337\r
338\r
339/**\r
340 The following entries disable the constructor and destructor\r
341 for the SocketDxe driver. Note that socket applications linking\r
342 against EfiSocketLib use different redirection.\r
343**/\r
344PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL; ///< No EfiSocketLib constructor needed for SocketDxe\r
345PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL; ///< No EfiSocketLib destructor needed for SocketDxe\r