2 Implement the entry and unload for the socket driver.
4 Copyright (c) 2011, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
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
19 Tag GUID - IPv4 in use by SocketDxe
21 CONST EFI_GUID mEslIp4ServiceGuid
= {
22 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }
27 Tag GUID - IPv6 in use by SocketDxe
29 CONST EFI_GUID mEslIp6ServiceGuid
= {
30 0x2fc3b2d3, 0x6eba, 0x42b0, { 0xa4, 0xa7, 0x14, 0xc7, 0xa8, 0x4b, 0x5d, 0x22 }
35 Tag GUID - TCPv4 in use by SocketDxe
37 CONST EFI_GUID mEslTcp4ServiceGuid
= {
38 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
43 Tag GUID - TCPv6 in use by SocketDxe
45 CONST EFI_GUID mEslTcp6ServiceGuid
= {
46 0xdd455a69, 0xec75, 0x456c, { 0x84, 0xd2, 0x95, 0xca, 0xe7, 0xd3, 0xc6, 0xd3 }
51 Tag GUID - UDPv4 in use by SocketDxe
53 CONST EFI_GUID mEslUdp4ServiceGuid
= {
54 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
59 Tag GUID - UDPv6 in use by SocketDxe
61 CONST EFI_GUID mEslUdp6ServiceGuid
= {
62 0x32ff59cd, 0xc33, 0x48d0, { 0xa2, 0x44, 0x4b, 0xb8, 0x11, 0x33, 0x64, 0x3 }
67 Socket driver unload routine.
69 @param [in] ImageHandle Handle for the image.
71 @retval EFI_SUCCESS Image may be unloaded
77 IN EFI_HANDLE ImageHandle
87 // Determine which devices are using this driver
91 Status
= gBS
->LocateHandle (
97 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
100 // One or more block IO devices are present
102 Status
= gBS
->AllocatePool (
103 EfiRuntimeServicesData
,
107 if ( EFI_ERROR ( Status
)) {
108 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
109 "Insufficient memory, failed handle buffer allocation\r\n" ));
114 // Locate the block IO devices
116 Status
= gBS
->LocateHandle (
122 if ( EFI_ERROR ( Status
)) {
124 // Error getting handles
126 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
127 "Failure getting Telnet handles\r\n" ));
132 // Remove any use of the driver
134 Max
= BufferSize
/ sizeof ( pHandle
[ 0 ]);
135 for ( Index
= 0; Max
> Index
; Index
++ ) {
136 Status
= DriverStop ( &mDriverBinding
,
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
]));
150 if ( EFI_NOT_FOUND
== Status
) {
152 // No devices were found
154 Status
= EFI_SUCCESS
;
159 // Free the handle array
161 if ( NULL
!= pHandle
) {
162 gBS
->FreePool ( pHandle
);
166 // Done with the socket layer
168 if ( !EFI_ERROR ( Status
)) {
169 Status
= EslDxeUninstall ( ImageHandle
);
170 if ( !EFI_ERROR ( Status
)) {
172 // Remove the protocols installed by the EntryPoint routine.
174 Status
= gBS
->UninstallMultipleProtocolInterfaces (
176 &gEfiDriverBindingProtocolGuid
,
178 &gEfiComponentNameProtocolGuid
,
180 &gEfiComponentName2ProtocolGuid
,
184 if ( !EFI_ERROR ( Status
)) {
185 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
186 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
188 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
189 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
191 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
192 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
196 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
197 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",
205 // Disconnect the network services
207 if ( !EFI_ERROR ( Status
)) {
208 EslServiceUnload ( );
212 // Return the unload status
219 Socket driver entry point.
221 @param [in] ImageHandle Handle for the image.
222 @param [in] pSystemTable Address of the system table.
224 @retval EFI_SUCCESS Image successfully loaded.
230 IN EFI_HANDLE ImageHandle
,
231 IN EFI_SYSTEM_TABLE
* pSystemTable
234 EFI_LOADED_IMAGE_PROTOCOL
* pLoadedImage
;
240 // Display the image handle
243 "ImageHandle: 0x%08x\r\n",
247 // Enable unload support
249 Status
= gBS
->HandleProtocol (
251 &gEfiLoadedImageProtocolGuid
,
252 (VOID
**)&pLoadedImage
254 if (!EFI_ERROR (Status
)) {
255 pLoadedImage
->Unload
= DriverUnload
;
258 // Add the driver to the list of drivers
260 Status
= EfiLibInstallDriverBindingComponentName2 (
268 if ( !EFI_ERROR ( Status
)) {
269 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
270 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
272 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
273 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
275 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
276 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
280 // Initialize the service layer
282 EslServiceLoad ( ImageHandle
);
285 // Make the socket serivces available to other drivers
288 Status
= EslDxeInstall ( &ImageHandle
);
289 if ( EFI_ERROR ( Status
)) {
291 // Disconnect from the network
293 EslServiceUnload ( );
296 // Remove the driver bindings
298 gBS
->UninstallMultipleProtocolInterfaces (
300 &gEfiDriverBindingProtocolGuid
,
302 &gEfiComponentNameProtocolGuid
,
304 &gEfiComponentName2ProtocolGuid
,
308 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
309 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
311 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
312 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
314 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
315 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
320 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
321 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",
325 DBG_EXIT_STATUS ( Status
);
331 Socket layer's service binding protocol delcaration.
333 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
= {
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.
344 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= NULL
; ///< No EfiSocketLib constructor needed for SocketDxe
345 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= NULL
; ///< No EfiSocketLib destructor needed for SocketDxe