]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/EfiSocketLib/DxeSupport.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / EfiSocketLib / DxeSupport.c
1 /** @file
2 SocketDxe support routines
3
4 Copyright (c) 2011, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "Socket.h"
10
11
12 /**
13 Creates a child handle and installs gEfiSocketProtocolGuid.
14
15 This routine creates a child handle for the socket driver and
16 installs the ::gEfiSocketProtocolGuid on that handle with a pointer
17 to the ::EFI_SOCKET_PROTOCOL structure address.
18
19 This routine is called by ::EslServiceGetProtocol in UseSocketDxe
20 when the socket application is linked with UseSocketDxe.
21
22 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
23 @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
24 then a new handle is created. If it is a pointer to an existing UEFI handle,
25 then the protocol is added to the existing UEFI handle.
26
27 @retval EFI_SUCCESS The protocol was added to ChildHandle.
28 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
29 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
30 the child
31 @retval other The child handle was not created
32
33 **/
34 EFI_STATUS
35 EFIAPI
36 EslDxeCreateChild (
37 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
38 IN OUT EFI_HANDLE * pChildHandle
39 )
40 {
41 ESL_SOCKET * pSocket;
42 EFI_STATUS Status;
43
44 DBG_ENTER ( );
45
46 //
47 // Create a socket structure
48 //
49 Status = EslSocketAllocate ( pChildHandle,
50 DEBUG_SOCKET,
51 &pSocket );
52
53 //
54 // Return the operation status
55 //
56 DBG_EXIT_STATUS ( Status );
57 return Status;
58 }
59
60
61 /**
62 Removes gEfiSocketProtocolGuid and destroys the child handle.
63
64 This routine uninstalls ::gEfiSocketProtocolGuid from the child handle
65 and destroys the child handle if necessary.
66
67 This routine is called from ???.
68
69 @param [in] pThis Address of the EFI_SERVICE_BINDING_PROTOCOL structure.
70 @param [in] ChildHandle Handle of the child to destroy
71
72 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
73 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
74 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
75 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
76 because its services are being used.
77 @retval other The child handle was not destroyed
78
79 **/
80 EFI_STATUS
81 EFIAPI
82 EslDxeDestroyChild (
83 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
84 IN EFI_HANDLE ChildHandle
85 )
86 {
87 ESL_LAYER * pLayer;
88 EFI_SOCKET_PROTOCOL * pSocketProtocol;
89 EFI_STATUS Status;
90
91 DBG_ENTER ( );
92
93 //
94 // Locate the socket control structure
95 //
96 pLayer = &mEslLayer;
97 Status = gBS->OpenProtocol (
98 ChildHandle,
99 &gEfiSocketProtocolGuid,
100 (VOID **)&pSocketProtocol,
101 pLayer->ImageHandle,
102 NULL,
103 EFI_OPEN_PROTOCOL_GET_PROTOCOL
104 );
105 if ( !EFI_ERROR ( Status )) {
106 //
107 // Free the socket resources
108 //
109 Status = EslSocketFree ( pSocketProtocol, NULL );
110 }
111 else {
112 DEBUG (( DEBUG_ERROR,
113 "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",
114 ChildHandle,
115 Status ));
116 }
117
118 //
119 // Return the operation status
120 //
121 DBG_EXIT_STATUS ( Status );
122 return Status;
123 }
124
125
126 /**
127 Install the socket service
128
129 This routine installs the ::gEfiSocketServiceBindingProtocolGuid
130 on the SocketDxe image handle to announce the availability
131 of the socket layer to the rest of EFI.
132
133 SocketDxe's EntryPoint routine calls this routine to
134 make the socket layer available.
135
136 @param [in] pImageHandle Address of the image handle
137
138 @retval EFI_SUCCESS Service installed successfully
139 **/
140 EFI_STATUS
141 EFIAPI
142 EslDxeInstall (
143 IN EFI_HANDLE * pImageHandle
144 )
145 {
146 EFI_STATUS Status;
147
148 //
149 // Install the socket service binding protocol
150 //
151 Status = gBS->InstallMultipleProtocolInterfaces (
152 pImageHandle,
153 &gEfiSocketServiceBindingProtocolGuid,
154 mEslLayer.pServiceBinding,
155 NULL
156 );
157 if ( !EFI_ERROR ( Status )) {
158 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
159 "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
160 *pImageHandle ));
161 }
162 else {
163 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
164 "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
165 Status ));
166 }
167
168 //
169 // Return the operation status
170 //
171 return Status;
172 }
173
174
175 /**
176 Uninstall the socket service
177
178 This routine removes the gEfiSocketServiceBindingProtocolGuid from
179 the SocketDxe image handle to notify EFI that the socket layer
180 is no longer available.
181
182 SocketDxe's DriverUnload routine calls this routine to remove the
183 socket layer.
184
185 @param [in] ImageHandle Handle for the image.
186
187 @retval EFI_SUCCESS Service installed successfully
188 **/
189 EFI_STATUS
190 EFIAPI
191 EslDxeUninstall (
192 IN EFI_HANDLE ImageHandle
193 )
194 {
195 EFI_STATUS Status;
196
197 //
198 // Install the socket service binding protocol
199 //
200 Status = gBS->UninstallMultipleProtocolInterfaces (
201 ImageHandle,
202 &gEfiSocketServiceBindingProtocolGuid,
203 mEslLayer.pServiceBinding,
204 NULL
205 );
206 if ( !EFI_ERROR ( Status )) {
207 DEBUG (( DEBUG_POOL | DEBUG_INIT,
208 "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
209 ImageHandle ));
210 }
211 else {
212 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
213 "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
214 ImageHandle,
215 Status ));
216 }
217
218 //
219 // Return the operation status
220 //
221 return Status;
222 }