]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the entry and unload for the socket driver.\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "Socket.h"\r | |
16 | \r | |
17 | \r | |
a88c3163 | 18 | /**\r |
19 | The following GUID values are only used by the SocketDxe driver. An\r | |
20 | alternative set of values exists in EfiSocketLib\UseEfiSocketLib.c\r | |
21 | which an application uses when it links against EfiSocketLib. These\r | |
22 | two sets of values allow the SocketDxe driver to coexist with socket\r | |
23 | applications.\r | |
24 | \r | |
25 | Tag GUID - IPv4 in use by SocketDxe\r | |
26 | **/\r | |
27 | CONST EFI_GUID mEslIp4ServiceGuid = {\r | |
28 | 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }\r | |
d7ce7006 | 29 | };\r |
30 | \r | |
a88c3163 | 31 | \r |
32 | /**\r | |
33 | Tag GUID - TCPv4 in use by SocketDxe\r | |
34 | **/\r | |
d7ce7006 | 35 | CONST EFI_GUID mEslTcp4ServiceGuid = {\r |
36 | 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }\r | |
37 | };\r | |
38 | \r | |
a88c3163 | 39 | \r |
40 | /**\r | |
41 | Tag GUID - UDPv4 in use by SocketDxe\r | |
42 | **/\r | |
d7ce7006 | 43 | CONST EFI_GUID mEslUdp4ServiceGuid = {\r |
44 | 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }\r | |
45 | };\r | |
46 | \r | |
47 | \r | |
48 | /**\r | |
49 | Socket driver unload routine.\r | |
50 | \r | |
51 | @param [in] ImageHandle Handle for the image.\r | |
52 | \r | |
53 | @retval EFI_SUCCESS Image may be unloaded\r | |
54 | \r | |
55 | **/\r | |
56 | EFI_STATUS\r | |
57 | EFIAPI\r | |
58 | DriverUnload (\r | |
59 | IN EFI_HANDLE ImageHandle\r | |
60 | )\r | |
61 | {\r | |
62 | UINTN BufferSize;\r | |
63 | UINTN Index;\r | |
64 | UINTN Max;\r | |
65 | EFI_HANDLE * pHandle;\r | |
66 | EFI_STATUS Status;\r | |
67 | \r | |
68 | //\r | |
69 | // Determine which devices are using this driver\r | |
70 | //\r | |
71 | BufferSize = 0;\r | |
72 | pHandle = NULL;\r | |
73 | Status = gBS->LocateHandle (\r | |
74 | ByProtocol,\r | |
75 | &gEfiCallerIdGuid,\r | |
76 | NULL,\r | |
77 | &BufferSize,\r | |
78 | NULL );\r | |
79 | if ( EFI_BUFFER_TOO_SMALL == Status ) {\r | |
80 | for ( ; ; ) {\r | |
81 | //\r | |
82 | // One or more block IO devices are present\r | |
83 | //\r | |
84 | Status = gBS->AllocatePool (\r | |
85 | EfiRuntimeServicesData,\r | |
86 | BufferSize,\r | |
87 | (VOID **) &pHandle\r | |
88 | );\r | |
89 | if ( EFI_ERROR ( Status )) {\r | |
90 | DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
91 | "Insufficient memory, failed handle buffer allocation\r\n" ));\r | |
92 | break;\r | |
93 | }\r | |
94 | \r | |
95 | //\r | |
96 | // Locate the block IO devices\r | |
97 | //\r | |
98 | Status = gBS->LocateHandle (\r | |
99 | ByProtocol,\r | |
100 | &gEfiCallerIdGuid,\r | |
101 | NULL,\r | |
102 | &BufferSize,\r | |
103 | pHandle );\r | |
104 | if ( EFI_ERROR ( Status )) {\r | |
105 | //\r | |
106 | // Error getting handles\r | |
107 | //\r | |
108 | DEBUG (( DEBUG_ERROR | DEBUG_INIT | DEBUG_INFO,\r | |
109 | "Failure getting Telnet handles\r\n" ));\r | |
110 | break;\r | |
111 | }\r | |
112 | \r | |
113 | //\r | |
114 | // Remove any use of the driver\r | |
115 | //\r | |
116 | Max = BufferSize / sizeof ( pHandle[ 0 ]);\r | |
117 | for ( Index = 0; Max > Index; Index++ ) {\r | |
a88c3163 | 118 | Status = DriverStop ( &mDriverBinding,\r |
d7ce7006 | 119 | pHandle[ Index ],\r |
120 | 0,\r | |
121 | NULL );\r | |
122 | if ( EFI_ERROR ( Status )) {\r | |
123 | DEBUG (( DEBUG_WARN | DEBUG_INIT | DEBUG_INFO,\r | |
124 | "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));\r | |
125 | break;\r | |
126 | }\r | |
127 | }\r | |
128 | break;\r | |
129 | }\r | |
130 | }\r | |
131 | else {\r | |
132 | if ( EFI_NOT_FOUND == Status ) {\r | |
133 | //\r | |
134 | // No devices were found\r | |
135 | //\r | |
136 | Status = EFI_SUCCESS;\r | |
137 | }\r | |
138 | }\r | |
139 | \r | |
140 | //\r | |
141 | // Free the handle array\r | |
142 | //\r | |
143 | if ( NULL != pHandle ) {\r | |
144 | gBS->FreePool ( pHandle );\r | |
145 | }\r | |
146 | \r | |
147 | //\r | |
148 | // Done with the socket layer\r | |
149 | //\r | |
150 | if ( !EFI_ERROR ( Status )) {\r | |
a88c3163 | 151 | Status = EslDxeUninstall ( ImageHandle );\r |
d7ce7006 | 152 | if ( !EFI_ERROR ( Status )) {\r |
153 | //\r | |
154 | // Remove the protocols installed by the EntryPoint routine.\r | |
155 | //\r | |
156 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
157 | ImageHandle,\r | |
158 | &gEfiDriverBindingProtocolGuid,\r | |
a88c3163 | 159 | &mDriverBinding,\r |
d7ce7006 | 160 | &gEfiComponentNameProtocolGuid,\r |
a88c3163 | 161 | &mComponentName,\r |
d7ce7006 | 162 | &gEfiComponentName2ProtocolGuid,\r |
a88c3163 | 163 | &mComponentName2,\r |
d7ce7006 | 164 | NULL\r |
165 | );\r | |
166 | if ( !EFI_ERROR ( Status )) {\r | |
167 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
168 | "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r | |
169 | ImageHandle ));\r | |
170 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
171 | "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r | |
172 | ImageHandle ));\r | |
173 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
174 | "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r | |
175 | ImageHandle ));\r | |
176 | }\r | |
177 | else {\r | |
178 | DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r | |
179 | "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",\r | |
180 | ImageHandle,\r | |
181 | Status ));\r | |
182 | }\r | |
183 | }\r | |
184 | }\r | |
185 | \r | |
186 | //\r | |
187 | // Disconnect the network services\r | |
188 | //\r | |
189 | if ( !EFI_ERROR ( Status )) {\r | |
190 | EslServiceUnload ( );\r | |
191 | }\r | |
192 | \r | |
193 | //\r | |
194 | // Return the unload status\r | |
195 | //\r | |
196 | return Status;\r | |
197 | }\r | |
198 | \r | |
199 | \r | |
200 | /**\r | |
201 | Socket driver entry point.\r | |
202 | \r | |
203 | @param [in] ImageHandle Handle for the image.\r | |
204 | @param [in] pSystemTable Address of the system table.\r | |
205 | \r | |
206 | @retval EFI_SUCCESS Image successfully loaded.\r | |
207 | \r | |
208 | **/\r | |
209 | EFI_STATUS\r | |
210 | EFIAPI\r | |
211 | EntryPoint (\r | |
212 | IN EFI_HANDLE ImageHandle,\r | |
213 | IN EFI_SYSTEM_TABLE * pSystemTable\r | |
214 | )\r | |
215 | {\r | |
216 | EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;\r | |
217 | EFI_STATUS Status;\r | |
218 | \r | |
219 | DBG_ENTER ( );\r | |
220 | \r | |
221 | //\r | |
222 | // Display the image handle\r | |
223 | //\r | |
224 | DEBUG (( DEBUG_INFO,\r | |
225 | "ImageHandle: 0x%08x\r\n",\r | |
226 | ImageHandle ));\r | |
227 | \r | |
228 | //\r | |
229 | // Enable unload support\r | |
230 | //\r | |
231 | Status = gBS->HandleProtocol (\r | |
232 | gImageHandle,\r | |
233 | &gEfiLoadedImageProtocolGuid,\r | |
234 | (VOID **)&pLoadedImage\r | |
235 | );\r | |
236 | if (!EFI_ERROR (Status)) {\r | |
237 | pLoadedImage->Unload = DriverUnload;\r | |
238 | \r | |
239 | //\r | |
240 | // Add the driver to the list of drivers\r | |
241 | //\r | |
242 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
243 | ImageHandle,\r | |
244 | pSystemTable,\r | |
a88c3163 | 245 | &mDriverBinding,\r |
d7ce7006 | 246 | ImageHandle,\r |
a88c3163 | 247 | &mComponentName,\r |
248 | &mComponentName2\r | |
d7ce7006 | 249 | );\r |
250 | if ( !EFI_ERROR ( Status )) {\r | |
251 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
252 | "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",\r | |
253 | ImageHandle ));\r | |
254 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
255 | "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",\r | |
256 | ImageHandle ));\r | |
257 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
258 | "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",\r | |
259 | ImageHandle ));\r | |
260 | \r | |
261 | //\r | |
262 | // Initialize the service layer\r | |
263 | //\r | |
264 | EslServiceLoad ( ImageHandle );\r | |
265 | \r | |
266 | //\r | |
267 | // Make the socket serivces available to other drivers\r | |
268 | // and applications\r | |
269 | //\r | |
a88c3163 | 270 | Status = EslDxeInstall ( &ImageHandle );\r |
d7ce7006 | 271 | if ( EFI_ERROR ( Status )) {\r |
272 | //\r | |
273 | // Disconnect from the network\r | |
274 | //\r | |
275 | EslServiceUnload ( );\r | |
276 | \r | |
277 | //\r | |
278 | // Remove the driver bindings\r | |
279 | //\r | |
280 | gBS->UninstallMultipleProtocolInterfaces (\r | |
281 | ImageHandle,\r | |
282 | &gEfiDriverBindingProtocolGuid,\r | |
a88c3163 | 283 | &mDriverBinding,\r |
d7ce7006 | 284 | &gEfiComponentNameProtocolGuid,\r |
a88c3163 | 285 | &mComponentName,\r |
d7ce7006 | 286 | &gEfiComponentName2ProtocolGuid,\r |
a88c3163 | 287 | &mComponentName2,\r |
d7ce7006 | 288 | NULL\r |
289 | );\r | |
290 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
291 | "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r | |
292 | ImageHandle ));\r | |
293 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
294 | "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r | |
295 | ImageHandle ));\r | |
296 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
297 | "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r | |
298 | ImageHandle ));\r | |
299 | }\r | |
300 | }\r | |
301 | else {\r | |
302 | DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r | |
303 | "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",\r | |
304 | Status ));\r | |
305 | }\r | |
306 | }\r | |
307 | DBG_EXIT_STATUS ( Status );\r | |
308 | return Status;\r | |
309 | }\r | |
310 | \r | |
311 | \r | |
a88c3163 | 312 | /**\r |
313 | Socket layer's service binding protocol delcaration.\r | |
314 | **/\r | |
315 | CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {\r | |
316 | EslDxeCreateChild,\r | |
317 | EslDxeDestroyChild\r | |
318 | };\r | |
319 | \r | |
320 | \r | |
321 | /**\r | |
322 | The following entries disable the constructor and destructor\r | |
323 | for the SocketDxe driver. Note that socket applications linking\r | |
324 | against EfiSocketLib use different redirection.\r | |
325 | **/\r | |
326 | PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL; ///< No EfiSocketLib constructor needed for SocketDxe\r | |
327 | PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL; ///< No EfiSocketLib destructor needed for SocketDxe\r |