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.
18 CONST EFI_GUID mEslRawServiceGuid
= {
19 0xf9f5d280, 0x8a4b, 0x48e2, { 0x96, 0x28, 0xda, 0xfa, 0xa7, 0x70, 0x54, 0x5d }
22 CONST EFI_GUID mEslTcp4ServiceGuid
= {
23 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
26 CONST EFI_GUID mEslUdp4ServiceGuid
= {
27 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
32 Socket driver unload routine.
34 @param [in] ImageHandle Handle for the image.
36 @retval EFI_SUCCESS Image may be unloaded
42 IN EFI_HANDLE ImageHandle
52 // Determine which devices are using this driver
56 Status
= gBS
->LocateHandle (
62 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
65 // One or more block IO devices are present
67 Status
= gBS
->AllocatePool (
68 EfiRuntimeServicesData
,
72 if ( EFI_ERROR ( Status
)) {
73 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
74 "Insufficient memory, failed handle buffer allocation\r\n" ));
79 // Locate the block IO devices
81 Status
= gBS
->LocateHandle (
87 if ( EFI_ERROR ( Status
)) {
89 // Error getting handles
91 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
92 "Failure getting Telnet handles\r\n" ));
97 // Remove any use of the driver
99 Max
= BufferSize
/ sizeof ( pHandle
[ 0 ]);
100 for ( Index
= 0; Max
> Index
; Index
++ ) {
101 Status
= DriverStop ( &gDriverBinding
,
105 if ( EFI_ERROR ( Status
)) {
106 DEBUG (( DEBUG_WARN
| DEBUG_INIT
| DEBUG_INFO
,
107 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle
[ Index
]));
115 if ( EFI_NOT_FOUND
== Status
) {
117 // No devices were found
119 Status
= EFI_SUCCESS
;
124 // Free the handle array
126 if ( NULL
!= pHandle
) {
127 gBS
->FreePool ( pHandle
);
131 // Done with the socket layer
133 if ( !EFI_ERROR ( Status
)) {
134 Status
= EslServiceUninstall ( ImageHandle
);
135 if ( !EFI_ERROR ( Status
)) {
137 // Remove the protocols installed by the EntryPoint routine.
139 Status
= gBS
->UninstallMultipleProtocolInterfaces (
141 &gEfiDriverBindingProtocolGuid
,
143 &gEfiComponentNameProtocolGuid
,
145 &gEfiComponentName2ProtocolGuid
,
149 if ( !EFI_ERROR ( Status
)) {
150 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
151 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
153 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
154 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
156 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
157 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
161 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
162 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",
170 // Disconnect the network services
172 if ( !EFI_ERROR ( Status
)) {
173 EslServiceUnload ( );
177 // Return the unload status
184 Socket driver entry point.
186 @param [in] ImageHandle Handle for the image.
187 @param [in] pSystemTable Address of the system table.
189 @retval EFI_SUCCESS Image successfully loaded.
195 IN EFI_HANDLE ImageHandle
,
196 IN EFI_SYSTEM_TABLE
* pSystemTable
199 EFI_LOADED_IMAGE_PROTOCOL
* pLoadedImage
;
205 // Display the image handle
208 "ImageHandle: 0x%08x\r\n",
212 // Enable unload support
214 Status
= gBS
->HandleProtocol (
216 &gEfiLoadedImageProtocolGuid
,
217 (VOID
**)&pLoadedImage
219 if (!EFI_ERROR (Status
)) {
220 pLoadedImage
->Unload
= DriverUnload
;
223 // Add the driver to the list of drivers
225 Status
= EfiLibInstallDriverBindingComponentName2 (
233 if ( !EFI_ERROR ( Status
)) {
234 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
235 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
237 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
238 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
240 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
241 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
245 // Initialize the service layer
247 EslServiceLoad ( ImageHandle
);
250 // Make the socket serivces available to other drivers
253 Status
= EslServiceInstall ( &ImageHandle
);
254 if ( EFI_ERROR ( Status
)) {
256 // Disconnect from the network
258 EslServiceUnload ( );
261 // Remove the driver bindings
263 gBS
->UninstallMultipleProtocolInterfaces (
265 &gEfiDriverBindingProtocolGuid
,
267 &gEfiComponentNameProtocolGuid
,
269 &gEfiComponentName2ProtocolGuid
,
273 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
274 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
276 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
277 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
279 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
280 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
285 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
286 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",
290 DBG_EXIT_STATUS ( Status
);
295 PFN_ESL_xSTRUCTOR mpfnEslConstructor
= NULL
;
296 PFN_ESL_xSTRUCTOR mpfnEslDestructor
= NULL
;