2 Connect to and disconnect from the various network layers
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.
17 EFI_TCP4_PROTOCOL
* mpEfiTcpClose4
[ 1024 ];
21 Connect to the network service bindings
23 Walk the network service protocols on the controller handle and
24 locate any that are not in use. Create service structures to
25 manage the service binding for the socket driver.
27 @param [in] BindingHandle Handle for protocol binding.
28 @param [in] Controller Handle of device to work with.
30 @retval EFI_SUCCESS This driver is added to Controller.
31 @retval other This driver does not support this device.
37 IN EFI_HANDLE BindingHandle
,
38 IN EFI_HANDLE Controller
43 CONST DT_SOCKET_BINDING
* pEnd
;
46 DT_SERVICE
* pService
;
47 CONST DT_SOCKET_BINDING
* pSocketBinding
;
54 // Assume the list is empty
56 Status
= EFI_UNSUPPORTED
;
60 // Walk the list of network connection points
62 pSocketBinding
= &cEslSocketBinding
[0];
63 pEnd
= &pSocketBinding
[ cEslSocketBindingEntries
];
64 while ( pEnd
> pSocketBinding
) {
66 // Determine if the controller supports the network protocol
68 Status
= gBS
->OpenProtocol (
70 pSocketBinding
->pNetworkBinding
,
74 EFI_OPEN_PROTOCOL_GET_PROTOCOL
76 if ( !EFI_ERROR ( Status
)) {
78 // Determine if the socket layer is already connected
80 Status
= gBS
->OpenProtocol (
82 (EFI_GUID
*)pSocketBinding
->pTagGuid
,
86 EFI_OPEN_PROTOCOL_GET_PROTOCOL
88 if ( EFI_UNSUPPORTED
== Status
) {
90 // Allocate a service structure since the tag is not present
92 LengthInBytes
= sizeof ( *pService
);
93 Status
= gBS
->AllocatePool (
94 EfiRuntimeServicesData
,
98 if ( !EFI_ERROR ( Status
)) {
99 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
100 "0x%08x: Allocate pService, %d bytes\r\n",
105 // Set the structure signature and service binding
107 ZeroMem ( pService
, LengthInBytes
);
108 pService
->Signature
= SERVICE_SIGNATURE
;
109 pService
->pSocketBinding
= pSocketBinding
;
110 pService
->Controller
= Controller
;
111 pService
->pInterface
= pInterface
;
114 // Mark the controller in use
117 Status
= gBS
->InstallMultipleProtocolInterfaces (
123 if ( !EFI_ERROR ( Status
)) {
124 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
125 "Installed: gEfiCallerIdGuid on 0x%08x\r\n",
130 if ( EFI_INVALID_PARAMETER
== Status
) {
131 Status
= EFI_SUCCESS
;
135 if ( !EFI_ERROR ( Status
)) {
137 // Mark the network service protocol in use
139 Status
= gBS
->InstallMultipleProtocolInterfaces (
141 pSocketBinding
->pTagGuid
,
145 if ( !EFI_ERROR ( Status
)) {
146 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
147 "Installed: %s TagGuid on 0x%08x\r\n",
148 pSocketBinding
->pName
,
152 // Synchronize with the socket layer
154 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
157 // Initialize the service
159 Status
= pSocketBinding
->pfnInitialize ( pService
);
162 // Release the socket layer synchronization
164 RESTORE_TPL ( TplPrevious
);
167 // Determine if the initialization was successful
169 if ( EFI_ERROR ( Status
)) {
170 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
171 "ERROR - Failed to initialize service %s on 0x%08x, Status: %r\r\n",
172 pSocketBinding
->pName
,
177 // Free the network service binding if necessary
179 gBS
->UninstallMultipleProtocolInterfaces (
181 pSocketBinding
->pTagGuid
,
184 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
185 "Removed: %s TagGuid from 0x%08x\r\n",
186 pSocketBinding
->pName
,
191 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
192 "ERROR - Failed to install %s TagGuid on 0x%08x, Status: %r\r\n",
193 pSocketBinding
->pName
,
198 if ( EFI_ERROR ( Status
)) {
200 // The controller is no longer in use
203 gBS
->UninstallMultipleProtocolInterfaces (
208 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
209 "Removed: gEfiCallerIdGuid from 0x%08x\r\n",
215 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
,
216 "ERROR - Failed to install gEfiCallerIdGuid on 0x%08x, Status: %r\r\n",
222 // Release the service if necessary
224 if ( EFI_ERROR ( Status
)) {
225 gBS
->FreePool ( pService
);
226 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
227 "0x%08x: Free pService, %d bytes\r\n",
229 sizeof ( *pService
)));
234 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
,
235 "ERROR - Failed service allocation, Status: %r\r\n",
242 // Set the next network protocol
248 // Display the driver start status
250 DBG_EXIT_STATUS ( Status
);
256 Shutdown the network connections to this controller by removing
257 NetworkInterfaceIdentifier protocol and closing the DevicePath
258 and PciIo protocols on Controller.
260 @param [in] BindingHandle Handle for protocol binding.
261 @param [in] Controller Handle of device to stop driver on.
263 @retval EFI_SUCCESS This driver is removed Controller.
264 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
265 @retval other This driver was not removed from this device.
270 EslServiceDisconnect (
271 IN EFI_HANDLE BindingHandle
,
272 IN EFI_HANDLE Controller
275 CONST DT_SOCKET_BINDING
* pEnd
;
276 DT_SERVICE
* pService
;
277 CONST DT_SOCKET_BINDING
* pSocketBinding
;
284 // Walk the list of network connection points in reverse order
286 pEnd
= &cEslSocketBinding
[0];
287 pSocketBinding
= &pEnd
[ cEslSocketBindingEntries
];
288 while ( pEnd
< pSocketBinding
) {
290 // Set the next network protocol
295 // Determine if the driver connected
297 Status
= gBS
->OpenProtocol (
299 (EFI_GUID
*)pSocketBinding
->pTagGuid
,
303 EFI_OPEN_PROTOCOL_GET_PROTOCOL
305 if ( !EFI_ERROR ( Status
)) {
308 // Synchronize with the socket layer
310 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
313 // Shutdown the service
315 pSocketBinding
->pfnShutdown ( pService
);
318 // Release the socket layer synchronization
320 RESTORE_TPL ( TplPrevious
);
323 // Break the driver connection
325 Status
= gBS
->UninstallMultipleProtocolInterfaces (
327 pSocketBinding
->pTagGuid
,
330 if ( !EFI_ERROR ( Status
)) {
331 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
332 "Removed: %s TagGuid from 0x%08x\r\n",
333 pSocketBinding
->pName
,
337 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
338 "ERROR - Failed to removed %s TagGuid from 0x%08x, Status: %r\r\n",
339 pSocketBinding
->pName
,
345 // Free the service structure
347 Status
= gBS
->FreePool ( pService
);
348 if ( !EFI_ERROR ( Status
)) {
349 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
350 "0x%08x: Free pService, %d bytes\r\n",
352 sizeof ( *pService
)));
355 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
356 "ERROR - Failed to free pService 0x%08x, Status: %r\r\n",
365 // The controller is no longer in use
367 gBS
->UninstallMultipleProtocolInterfaces (
372 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
373 "Removed: gEfiCallerIdGuid from 0x%08x\r\n",
377 // The driver is disconnected from the network controller
379 Status
= EFI_SUCCESS
;
382 // Display the driver start status
384 DBG_EXIT_STATUS ( Status
);
391 Install the socket service
393 @param [in] pImageHandle Address of the image handle
395 @retval EFI_SUCCESS Service installed successfully
400 IN EFI_HANDLE
* pImageHandle
406 // Install the socket service binding protocol
408 Status
= gBS
->InstallMultipleProtocolInterfaces (
410 &gEfiSocketServiceBindingProtocolGuid
,
411 &mEslLayer
.ServiceBinding
,
414 if ( !EFI_ERROR ( Status
)) {
415 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
416 "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
420 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
421 "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
426 // Return the operation status
433 Initialize the service layer
435 @param [in] ImageHandle Handle for the image.
441 IN EFI_HANDLE ImageHandle
447 // Save the image handle
450 pLayer
->Signature
= LAYER_SIGNATURE
;
451 pLayer
->ImageHandle
= ImageHandle
;
454 // Initialize the TCP4 close
456 pLayer
->TcpCloseMax4
= DIM ( mpEfiTcpClose4
);
457 pLayer
->ppTcpClose4
= mpEfiTcpClose4
;
460 // Connect the service binding protocol to the image handle
462 pLayer
->ServiceBinding
.CreateChild
= EslSocketCreateChild
;
463 pLayer
->ServiceBinding
.DestroyChild
= EslSocketDestroyChild
;
468 Uninstall the socket service
470 @param [in] ImageHandle Handle for the image.
472 @retval EFI_SUCCESS Service installed successfully
476 EslServiceUninstall (
477 IN EFI_HANDLE ImageHandle
483 // Install the socket service binding protocol
485 Status
= gBS
->UninstallMultipleProtocolInterfaces (
487 &gEfiSocketServiceBindingProtocolGuid
,
488 &mEslLayer
.ServiceBinding
,
491 if ( !EFI_ERROR ( Status
)) {
492 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
493 "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
497 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
,
498 "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
504 // Return the operation status
511 Shutdown the service layer
523 // Undo the work by ServiceLoad
526 pLayer
->ImageHandle
= NULL
;
527 pLayer
->ServiceBinding
.CreateChild
= NULL
;
528 pLayer
->ServiceBinding
.DestroyChild
= NULL
;