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