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 - TCPv4 in use by SocketDxe
35 CONST EFI_GUID mEslTcp4ServiceGuid
= {
36 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
41 Tag GUID - UDPv4 in use by SocketDxe
43 CONST EFI_GUID mEslUdp4ServiceGuid
= {
44 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
49 Socket driver unload routine.
51 @param [in] ImageHandle Handle for the image.
53 @retval EFI_SUCCESS Image may be unloaded
59 IN EFI_HANDLE ImageHandle
69 // Determine which devices are using this driver
73 Status
= gBS
->LocateHandle (
79 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
82 // One or more block IO devices are present
84 Status
= gBS
->AllocatePool (
85 EfiRuntimeServicesData
,
89 if ( EFI_ERROR ( Status
)) {
90 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
91 "Insufficient memory, failed handle buffer allocation\r\n" ));
96 // Locate the block IO devices
98 Status
= gBS
->LocateHandle (
104 if ( EFI_ERROR ( Status
)) {
106 // Error getting handles
108 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
109 "Failure getting Telnet handles\r\n" ));
114 // Remove any use of the driver
116 Max
= BufferSize
/ sizeof ( pHandle
[ 0 ]);
117 for ( Index
= 0; Max
> Index
; Index
++ ) {
118 Status
= DriverStop ( &mDriverBinding
,
122 if ( EFI_ERROR ( Status
)) {
123 DEBUG (( DEBUG_WARN
| DEBUG_INIT
| DEBUG_INFO
,
124 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle
[ Index
]));
132 if ( EFI_NOT_FOUND
== Status
) {
134 // No devices were found
136 Status
= EFI_SUCCESS
;
141 // Free the handle array
143 if ( NULL
!= pHandle
) {
144 gBS
->FreePool ( pHandle
);
148 // Done with the socket layer
150 if ( !EFI_ERROR ( Status
)) {
151 Status
= EslDxeUninstall ( ImageHandle
);
152 if ( !EFI_ERROR ( Status
)) {
154 // Remove the protocols installed by the EntryPoint routine.
156 Status
= gBS
->UninstallMultipleProtocolInterfaces (
158 &gEfiDriverBindingProtocolGuid
,
160 &gEfiComponentNameProtocolGuid
,
162 &gEfiComponentName2ProtocolGuid
,
166 if ( !EFI_ERROR ( Status
)) {
167 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
168 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
170 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
171 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
173 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
174 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
178 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
179 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",
187 // Disconnect the network services
189 if ( !EFI_ERROR ( Status
)) {
190 EslServiceUnload ( );
194 // Return the unload status
201 Socket driver entry point.
203 @param [in] ImageHandle Handle for the image.
204 @param [in] pSystemTable Address of the system table.
206 @retval EFI_SUCCESS Image successfully loaded.
212 IN EFI_HANDLE ImageHandle
,
213 IN EFI_SYSTEM_TABLE
* pSystemTable
216 EFI_LOADED_IMAGE_PROTOCOL
* pLoadedImage
;
222 // Display the image handle
225 "ImageHandle: 0x%08x\r\n",
229 // Enable unload support
231 Status
= gBS
->HandleProtocol (
233 &gEfiLoadedImageProtocolGuid
,
234 (VOID
**)&pLoadedImage
236 if (!EFI_ERROR (Status
)) {
237 pLoadedImage
->Unload
= DriverUnload
;
240 // Add the driver to the list of drivers
242 Status
= EfiLibInstallDriverBindingComponentName2 (
250 if ( !EFI_ERROR ( Status
)) {
251 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
252 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
254 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
255 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
257 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
258 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
262 // Initialize the service layer
264 EslServiceLoad ( ImageHandle
);
267 // Make the socket serivces available to other drivers
270 Status
= EslDxeInstall ( &ImageHandle
);
271 if ( EFI_ERROR ( Status
)) {
273 // Disconnect from the network
275 EslServiceUnload ( );
278 // Remove the driver bindings
280 gBS
->UninstallMultipleProtocolInterfaces (
282 &gEfiDriverBindingProtocolGuid
,
284 &gEfiComponentNameProtocolGuid
,
286 &gEfiComponentName2ProtocolGuid
,
290 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
291 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
293 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
294 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
296 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
297 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
302 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
303 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",
307 DBG_EXIT_STATUS ( Status
);
313 Socket layer's service binding protocol delcaration.
315 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding
= {
322 The following entries disable the constructor and destructor
323 for the SocketDxe driver. Note that socket applications linking
324 against EfiSocketLib use different redirection.
326 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= NULL
; ///< No EfiSocketLib constructor needed for SocketDxe
327 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= NULL
; ///< No EfiSocketLib destructor needed for SocketDxe