2 Implement the entry and unload for the socket driver.
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 The following GUID values are only used by the SocketDxe driver. An
20 alternative set of values exists in EfiSocketLib\UseEfiSocketLib.c
21 which an application uses when it links against EfiSocketLib. These
22 two sets of values allow the SocketDxe driver to coexist with socket
25 Tag GUID - IPv4 in use by SocketDxe
27 CONST EFI_GUID mEslIp4ServiceGuid
= {
28 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }
33 Tag GUID - IPv6 in use by SocketDxe
35 CONST EFI_GUID mEslIp6ServiceGuid
= {
36 0x2fc3b2d3, 0x6eba, 0x42b0, { 0xa4, 0xa7, 0x14, 0xc7, 0xa8, 0x4b, 0x5d, 0x22 }
41 Tag GUID - TCPv4 in use by SocketDxe
43 CONST EFI_GUID mEslTcp4ServiceGuid
= {
44 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
49 Tag GUID - TCPv6 in use by SocketDxe
51 CONST EFI_GUID mEslTcp6ServiceGuid
= {
52 0xdd455a69, 0xec75, 0x456c, { 0x84, 0xd2, 0x95, 0xca, 0xe7, 0xd3, 0xc6, 0xd3 }
57 Tag GUID - UDPv4 in use by SocketDxe
59 CONST EFI_GUID mEslUdp4ServiceGuid
= {
60 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
65 Tag GUID - UDPv6 in use by SocketDxe
67 CONST EFI_GUID mEslUdp6ServiceGuid
= {
68 0x32ff59cd, 0xc33, 0x48d0, { 0xa2, 0x44, 0x4b, 0xb8, 0x11, 0x33, 0x64, 0x3 }
73 Socket driver unload routine.
75 @param [in] ImageHandle Handle for the image.
77 @retval EFI_SUCCESS Image may be unloaded
83 IN EFI_HANDLE ImageHandle
93 // Determine which devices are using this driver
97 Status
= gBS
->LocateHandle (
103 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
106 // One or more block IO devices are present
108 Status
= gBS
->AllocatePool (
109 EfiRuntimeServicesData
,
113 if ( EFI_ERROR ( Status
)) {
114 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
115 "Insufficient memory, failed handle buffer allocation\r\n" ));
120 // Locate the block IO devices
122 Status
= gBS
->LocateHandle (
128 if ( EFI_ERROR ( Status
)) {
130 // Error getting handles
132 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
133 "Failure getting Telnet handles\r\n" ));
138 // Remove any use of the driver
140 Max
= BufferSize
/ sizeof ( pHandle
[ 0 ]);
141 for ( Index
= 0; Max
> Index
; Index
++ ) {
142 Status
= DriverStop ( &mDriverBinding
,
146 if ( EFI_ERROR ( Status
)) {
147 DEBUG (( DEBUG_WARN
| DEBUG_INIT
| DEBUG_INFO
,
148 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle
[ Index
]));
156 if ( EFI_NOT_FOUND
== Status
) {
158 // No devices were found
160 Status
= EFI_SUCCESS
;
165 // Free the handle array
167 if ( NULL
!= pHandle
) {
168 gBS
->FreePool ( pHandle
);
172 // Done with the socket layer
174 if ( !EFI_ERROR ( Status
)) {
175 Status
= EslDxeUninstall ( ImageHandle
);
176 if ( !EFI_ERROR ( Status
)) {
178 // Remove the protocols installed by the EntryPoint routine.
180 Status
= gBS
->UninstallMultipleProtocolInterfaces (
182 &gEfiDriverBindingProtocolGuid
,
184 &gEfiComponentNameProtocolGuid
,
186 &gEfiComponentName2ProtocolGuid
,
190 if ( !EFI_ERROR ( Status
)) {
191 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
192 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
194 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
195 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
197 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
198 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
202 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
203 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",
211 // Disconnect the network services
213 if ( !EFI_ERROR ( Status
)) {
214 EslServiceUnload ( );
218 // Return the unload status
225 Socket driver entry point.
227 @param [in] ImageHandle Handle for the image.
228 @param [in] pSystemTable Address of the system table.
230 @retval EFI_SUCCESS Image successfully loaded.
236 IN EFI_HANDLE ImageHandle
,
237 IN EFI_SYSTEM_TABLE
* pSystemTable
240 EFI_LOADED_IMAGE_PROTOCOL
* pLoadedImage
;
246 // Display the image handle
249 "ImageHandle: 0x%08x\r\n",
253 // Enable unload support
255 Status
= gBS
->HandleProtocol (
257 &gEfiLoadedImageProtocolGuid
,
258 (VOID
**)&pLoadedImage
260 if (!EFI_ERROR (Status
)) {
261 pLoadedImage
->Unload
= DriverUnload
;
264 // Add the driver to the list of drivers
266 Status
= EfiLibInstallDriverBindingComponentName2 (
274 if ( !EFI_ERROR ( Status
)) {
275 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
276 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
278 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
279 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
281 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
282 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
286 // Initialize the service layer
288 EslServiceLoad ( ImageHandle
);
291 // Make the socket serivces available to other drivers
294 Status
= EslDxeInstall ( &ImageHandle
);
295 if ( EFI_ERROR ( Status
)) {
297 // Disconnect from the network
299 EslServiceUnload ( );
302 // Remove the driver bindings
304 gBS
->UninstallMultipleProtocolInterfaces (
306 &gEfiDriverBindingProtocolGuid
,
308 &gEfiComponentNameProtocolGuid
,
310 &gEfiComponentName2ProtocolGuid
,
314 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
315 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
317 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
318 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
320 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
321 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
326 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
327 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",
331 DBG_EXIT_STATUS ( Status
);
337 Socket layer's service binding protocol delcaration.
339 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
= {
346 The following entries disable the constructor and destructor
347 for the SocketDxe driver. Note that socket applications linking
348 against EfiSocketLib use different redirection.
350 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= NULL
; ///< No EfiSocketLib constructor needed for SocketDxe
351 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= NULL
; ///< No EfiSocketLib destructor needed for SocketDxe