]>
Commit | Line | Data |
---|---|---|
d933e70a JW |
1 | /** @file\r |
2 | Driver Binding functions implementation for UEFI HTTP boot.\r | |
3 | \r | |
4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are licensed and made available under \r | |
6 | the terms and conditions of the BSD License that accompanies this distribution. \r | |
7 | 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 "HttpBootDxe.h"\r | |
16 | \r | |
17 | ///\r | |
18 | /// Driver Binding Protocol instance\r | |
19 | ///\r | |
20 | EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp4DxeDriverBinding = {\r | |
21 | HttpBootIp4DxeDriverBindingSupported,\r | |
22 | HttpBootIp4DxeDriverBindingStart,\r | |
23 | HttpBootIp4DxeDriverBindingStop,\r | |
24 | HTTP_BOOT_DXE_VERSION,\r | |
25 | NULL,\r | |
26 | NULL\r | |
27 | };\r | |
28 | \r | |
b659408b ZL |
29 | EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding = {\r |
30 | HttpBootIp6DxeDriverBindingSupported,\r | |
31 | HttpBootIp6DxeDriverBindingStart,\r | |
32 | HttpBootIp6DxeDriverBindingStop,\r | |
33 | HTTP_BOOT_DXE_VERSION,\r | |
34 | NULL,\r | |
35 | NULL\r | |
36 | };\r | |
37 | \r | |
d933e70a JW |
38 | /**\r |
39 | Destroy the HTTP child based on IPv4 stack.\r | |
40 | \r | |
41 | @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.\r | |
42 | @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.\r | |
43 | \r | |
44 | **/\r | |
45 | VOID\r | |
46 | HttpBootDestroyIp4Children (\r | |
47 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
48 | IN HTTP_BOOT_PRIVATE_DATA *Private\r | |
49 | )\r | |
50 | {\r | |
51 | ASSERT (This != NULL);\r | |
52 | ASSERT (Private != NULL);\r | |
d933e70a JW |
53 | \r |
54 | if (Private->Dhcp4Child != NULL) {\r | |
55 | gBS->CloseProtocol (\r | |
b659408b ZL |
56 | Private->Dhcp4Child,\r |
57 | &gEfiDhcp4ProtocolGuid,\r | |
58 | This->DriverBindingHandle,\r | |
59 | Private->Controller\r | |
60 | );\r | |
d933e70a JW |
61 | \r |
62 | NetLibDestroyServiceChild (\r | |
63 | Private->Controller,\r | |
64 | This->DriverBindingHandle,\r | |
65 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
66 | Private->Dhcp4Child\r | |
67 | );\r | |
68 | }\r | |
69 | \r | |
70 | if (Private->HttpCreated) {\r | |
71 | HttpIoDestroyIo (&Private->HttpIo);\r | |
72 | Private->HttpCreated = FALSE;\r | |
73 | }\r | |
74 | \r | |
b659408b ZL |
75 | if (Private->Ip4Nic != NULL) {\r |
76 | \r | |
77 | gBS->CloseProtocol (\r | |
78 | Private->Controller,\r | |
79 | &gEfiCallerIdGuid,\r | |
80 | This->DriverBindingHandle,\r | |
81 | Private->Ip4Nic->Controller\r | |
82 | );\r | |
83 | \r | |
84 | gBS->UninstallMultipleProtocolInterfaces (\r | |
85 | Private->Ip4Nic->Controller,\r | |
86 | &gEfiLoadFileProtocolGuid,\r | |
87 | &Private->Ip4Nic->LoadFile,\r | |
88 | &gEfiDevicePathProtocolGuid,\r | |
89 | Private->Ip4Nic->DevicePath,\r | |
90 | NULL\r | |
91 | );\r | |
92 | FreePool (Private->Ip4Nic);\r | |
93 | Private->Ip4Nic = NULL;\r | |
94 | }\r | |
95 | \r | |
96 | }\r | |
97 | \r | |
98 | /**\r | |
99 | Destroy the HTTP child based on IPv6 stack.\r | |
100 | \r | |
101 | @param[in] This Pointer to the EFI_DRIVER_BINDING_PROTOCOL.\r | |
102 | @param[in] Private Pointer to HTTP_BOOT_PRIVATE_DATA.\r | |
103 | \r | |
104 | **/\r | |
105 | VOID\r | |
106 | HttpBootDestroyIp6Children (\r | |
107 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
108 | IN HTTP_BOOT_PRIVATE_DATA *Private\r | |
109 | )\r | |
110 | {\r | |
111 | ASSERT (This != NULL);\r | |
112 | ASSERT (Private != NULL);\r | |
b659408b ZL |
113 | \r |
114 | if (Private->Ip6Child != NULL) {\r | |
115 | gBS->CloseProtocol (\r | |
116 | Private->Ip6Child,\r | |
117 | &gEfiIp6ProtocolGuid,\r | |
118 | This->DriverBindingHandle,\r | |
119 | Private->Controller\r | |
120 | );\r | |
121 | \r | |
122 | NetLibDestroyServiceChild (\r | |
123 | Private->Controller,\r | |
124 | This->DriverBindingHandle,\r | |
125 | &gEfiIp6ServiceBindingProtocolGuid,\r | |
126 | Private->Ip6Child\r | |
127 | );\r | |
128 | }\r | |
129 | \r | |
130 | if (Private->Dhcp6Child != NULL) {\r | |
131 | gBS->CloseProtocol (\r | |
132 | Private->Dhcp6Child,\r | |
133 | &gEfiDhcp6ProtocolGuid,\r | |
134 | This->DriverBindingHandle,\r | |
135 | Private->Controller\r | |
136 | );\r | |
d933e70a | 137 | \r |
b659408b ZL |
138 | NetLibDestroyServiceChild (\r |
139 | Private->Controller,\r | |
140 | This->DriverBindingHandle,\r | |
141 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
142 | Private->Dhcp6Child\r | |
143 | );\r | |
144 | }\r | |
d933e70a | 145 | \r |
b659408b ZL |
146 | if (Private->HttpCreated) {\r |
147 | HttpIoDestroyIo(&Private->HttpIo);\r | |
148 | Private->HttpCreated = FALSE;\r | |
149 | }\r | |
150 | \r | |
151 | if (Private->Ip6Nic != NULL) {\r | |
152 | \r | |
153 | gBS->CloseProtocol (\r | |
154 | Private->Controller,\r | |
155 | &gEfiCallerIdGuid,\r | |
156 | This->DriverBindingHandle,\r | |
157 | Private->Ip6Nic->Controller\r | |
158 | );\r | |
159 | \r | |
160 | gBS->UninstallMultipleProtocolInterfaces (\r | |
161 | Private->Ip6Nic->Controller,\r | |
162 | &gEfiLoadFileProtocolGuid,\r | |
163 | &Private->Ip6Nic->LoadFile,\r | |
164 | &gEfiDevicePathProtocolGuid,\r | |
165 | Private->Ip6Nic->DevicePath,\r | |
166 | NULL\r | |
167 | );\r | |
168 | FreePool (Private->Ip6Nic);\r | |
169 | Private->Ip6Nic = NULL;\r | |
d933e70a JW |
170 | }\r |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | Tests to see if this driver supports a given controller. If a child device is provided, \r | |
175 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
176 | \r | |
177 | This function checks to see if the driver specified by This supports the device specified by \r | |
178 | ControllerHandle. Drivers will typically use the device path attached to \r | |
179 | ControllerHandle and/or the services from the bus I/O abstraction attached to \r | |
180 | ControllerHandle to determine if the driver supports ControllerHandle. This function \r | |
181 | may be called many times during platform initialization. In order to reduce boot times, the tests \r | |
182 | performed by this function must be very small, and take as little time as possible to execute. This \r | |
183 | function must not change the state of any hardware devices, and this function must be aware that the \r | |
184 | device specified by ControllerHandle may already be managed by the same driver or a \r | |
185 | different driver. This function must match its calls to AllocatePages() with FreePages(), \r | |
186 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r | |
187 | Because ControllerHandle may have been previously started by the same driver, if a protocol is \r | |
188 | already in the opened state, then it must not be closed with CloseProtocol(). This is required \r | |
189 | to guarantee the state of ControllerHandle is not modified by this function.\r | |
190 | \r | |
191 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
192 | @param[in] ControllerHandle The handle of the controller to test. This handle \r | |
193 | must support a protocol interface that supplies \r | |
194 | an I/O abstraction to the driver.\r | |
195 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
196 | parameter is ignored by device drivers, and is optional for bus \r | |
197 | drivers. For bus drivers, if this parameter is not NULL, then \r | |
198 | the bus driver must determine if the bus controller specified \r | |
199 | by ControllerHandle and the child controller specified \r | |
200 | by RemainingDevicePath are both supported by this \r | |
201 | bus driver.\r | |
202 | \r | |
203 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
204 | RemainingDevicePath is supported by the driver specified by This.\r | |
205 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
206 | RemainingDevicePath is already being managed by the driver\r | |
207 | specified by This.\r | |
208 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
209 | RemainingDevicePath is already being managed by a different\r | |
210 | driver or an application that requires exclusive access.\r | |
211 | Currently not implemented.\r | |
212 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
213 | RemainingDevicePath is not supported by the driver specified by This.\r | |
214 | **/\r | |
215 | EFI_STATUS\r | |
216 | EFIAPI\r | |
217 | HttpBootIp4DxeDriverBindingSupported (\r | |
218 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
219 | IN EFI_HANDLE ControllerHandle,\r | |
220 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
221 | )\r | |
222 | {\r | |
223 | EFI_STATUS Status;\r | |
224 | \r | |
225 | //\r | |
226 | // Try to open the DHCP4, HTTP4 and Device Path protocol.\r | |
227 | //\r | |
228 | Status = gBS->OpenProtocol (\r | |
b659408b ZL |
229 | ControllerHandle,\r |
230 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
231 | NULL,\r | |
232 | This->DriverBindingHandle,\r | |
233 | ControllerHandle,\r | |
234 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
235 | );\r | |
d933e70a JW |
236 | if (EFI_ERROR (Status)) {\r |
237 | return Status;\r | |
238 | }\r | |
239 | \r | |
240 | Status = gBS->OpenProtocol (\r | |
b659408b ZL |
241 | ControllerHandle,\r |
242 | &gEfiHttpServiceBindingProtocolGuid,\r | |
243 | NULL,\r | |
244 | This->DriverBindingHandle,\r | |
245 | ControllerHandle,\r | |
246 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
247 | );\r | |
d933e70a JW |
248 | if (EFI_ERROR (Status)) {\r |
249 | return Status;\r | |
250 | }\r | |
251 | \r | |
252 | Status = gBS->OpenProtocol (\r | |
b659408b ZL |
253 | ControllerHandle,\r |
254 | &gEfiDevicePathProtocolGuid,\r | |
255 | NULL,\r | |
256 | This->DriverBindingHandle,\r | |
257 | ControllerHandle,\r | |
258 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
259 | );\r | |
d933e70a JW |
260 | \r |
261 | return Status;\r | |
262 | }\r | |
263 | \r | |
264 | \r | |
265 | /**\r | |
266 | Starts a device controller or a bus controller.\r | |
267 | \r | |
268 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
269 | As a result, much of the error checking on the parameters to Start() has been moved into this \r | |
270 | common boot service. It is legal to call Start() from other locations, \r | |
271 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
272 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
273 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
274 | EFI_DEVICE_PATH_PROTOCOL.\r | |
275 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
276 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r | |
277 | \r | |
278 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
279 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
280 | must support a protocol interface that supplies \r | |
281 | an I/O abstraction to the driver.\r | |
282 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
283 | parameter is ignored by device drivers, and is optional for bus \r | |
284 | drivers. For a bus driver, if this parameter is NULL, then handles \r | |
285 | for all the children of Controller are created by this driver. \r | |
286 | If this parameter is not NULL and the first Device Path Node is \r | |
287 | not the End of Device Path Node, then only the handle for the \r | |
288 | child device specified by the first Device Path Node of \r | |
289 | RemainingDevicePath is created by this driver.\r | |
290 | If the first Device Path Node of RemainingDevicePath is \r | |
291 | the End of Device Path Node, no child handle is created by this\r | |
292 | driver.\r | |
293 | \r | |
294 | @retval EFI_SUCCESS The device was started.\r | |
295 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
296 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
297 | @retval Others The driver failded to start the device.\r | |
298 | \r | |
299 | **/\r | |
300 | EFI_STATUS\r | |
301 | EFIAPI\r | |
302 | HttpBootIp4DxeDriverBindingStart (\r | |
303 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
304 | IN EFI_HANDLE ControllerHandle,\r | |
305 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
306 | )\r | |
307 | {\r | |
308 | EFI_STATUS Status;\r | |
309 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
310 | EFI_DEV_PATH *Node;\r | |
311 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
312 | UINT32 *Id;\r | |
313 | \r | |
314 | Status = gBS->OpenProtocol (\r | |
315 | ControllerHandle,\r | |
316 | &gEfiCallerIdGuid,\r | |
317 | (VOID **) &Id,\r | |
318 | This->DriverBindingHandle,\r | |
319 | ControllerHandle,\r | |
320 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
321 | );\r | |
b659408b | 322 | \r |
d933e70a | 323 | if (!EFI_ERROR (Status)) {\r |
b659408b ZL |
324 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);\r |
325 | } else {\r | |
326 | //\r | |
327 | // Initialize the private data structure.\r | |
328 | //\r | |
329 | Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));\r | |
330 | if (Private == NULL) {\r | |
331 | return EFI_OUT_OF_RESOURCES;\r | |
332 | }\r | |
333 | Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r | |
334 | Private->Controller = ControllerHandle;\r | |
335 | Private->Image = This->ImageHandle;\r | |
336 | InitializeListHead (&Private->CacheList);\r | |
337 | //\r | |
338 | // Get the NII interface if it exists, it's not required.\r | |
339 | //\r | |
340 | Status = gBS->OpenProtocol (\r | |
341 | ControllerHandle,\r | |
342 | &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r | |
343 | (VOID **) &Private->Nii,\r | |
344 | This->DriverBindingHandle,\r | |
345 | ControllerHandle,\r | |
346 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
347 | );\r | |
348 | if (EFI_ERROR (Status)) {\r | |
349 | Private->Nii = NULL;\r | |
350 | }\r | |
d933e70a | 351 | \r |
b659408b ZL |
352 | //\r |
353 | // Open Device Path Protocol to prepare for appending IP and URI node.\r | |
354 | //\r | |
355 | Status = gBS->OpenProtocol (\r | |
356 | ControllerHandle,\r | |
357 | &gEfiDevicePathProtocolGuid,\r | |
358 | (VOID **) &Private->ParentDevicePath,\r | |
359 | This->DriverBindingHandle,\r | |
360 | ControllerHandle,\r | |
361 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
362 | );\r | |
363 | if (EFI_ERROR (Status)) {\r | |
364 | goto ON_ERROR;\r | |
365 | }\r | |
366 | \r | |
367 | //\r | |
368 | // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r | |
369 | // NIC handle and the private data.\r | |
370 | //\r | |
371 | Status = gBS->InstallProtocolInterface (\r | |
372 | &ControllerHandle,\r | |
373 | &gEfiCallerIdGuid,\r | |
374 | EFI_NATIVE_INTERFACE,\r | |
375 | &Private->Id\r | |
376 | );\r | |
377 | if (EFI_ERROR (Status)) {\r | |
378 | goto ON_ERROR;\r | |
379 | }\r | |
380 | \r | |
381 | }\r | |
382 | \r | |
383 | if (Private->Ip4Nic != NULL) {\r | |
384 | //\r | |
385 | // Already created before\r | |
386 | //\r | |
387 | return EFI_SUCCESS;\r | |
388 | }\r | |
389 | \r | |
390 | Private->Ip4Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r | |
391 | if (Private->Ip4Nic == NULL) {\r | |
d933e70a JW |
392 | return EFI_OUT_OF_RESOURCES;\r |
393 | }\r | |
b659408b ZL |
394 | Private->Ip4Nic->Private = Private;\r |
395 | Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r | |
396 | \r | |
d933e70a | 397 | //\r |
b659408b | 398 | // Create DHCP4 child instance.\r |
d933e70a JW |
399 | //\r |
400 | Status = NetLibCreateServiceChild (\r | |
401 | ControllerHandle,\r | |
402 | This->DriverBindingHandle,\r | |
403 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
404 | &Private->Dhcp4Child\r | |
405 | );\r | |
406 | if (EFI_ERROR (Status)) {\r | |
407 | goto ON_ERROR;\r | |
408 | }\r | |
b659408b | 409 | \r |
d933e70a JW |
410 | Status = gBS->OpenProtocol (\r |
411 | Private->Dhcp4Child,\r | |
412 | &gEfiDhcp4ProtocolGuid,\r | |
413 | (VOID **) &Private->Dhcp4,\r | |
414 | This->DriverBindingHandle,\r | |
415 | ControllerHandle,\r | |
416 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
417 | );\r | |
418 | if (EFI_ERROR (Status)) {\r | |
419 | goto ON_ERROR;\r | |
420 | }\r | |
b659408b | 421 | \r |
d933e70a JW |
422 | //\r |
423 | // Get the Ip4Config2 protocol, it's required to configure the default gateway address.\r | |
424 | //\r | |
425 | Status = gBS->OpenProtocol (\r | |
426 | ControllerHandle,\r | |
427 | &gEfiIp4Config2ProtocolGuid,\r | |
428 | (VOID **) &Private->Ip4Config2,\r | |
429 | This->DriverBindingHandle,\r | |
430 | ControllerHandle,\r | |
431 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
432 | );\r | |
433 | if (EFI_ERROR (Status)) {\r | |
434 | goto ON_ERROR;\r | |
435 | }\r | |
b659408b | 436 | \r |
d933e70a JW |
437 | //\r |
438 | // Append IPv4 device path node.\r | |
439 | //\r | |
440 | Node = AllocateZeroPool (sizeof (IPv4_DEVICE_PATH));\r | |
441 | if (Node == NULL) {\r | |
442 | Status = EFI_OUT_OF_RESOURCES;\r | |
443 | goto ON_ERROR;\r | |
444 | }\r | |
445 | Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;\r | |
446 | Node->Ipv4.Header.SubType = MSG_IPv4_DP;\r | |
447 | SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));\r | |
448 | Node->Ipv4.StaticIpAddress = FALSE;\r | |
449 | DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r | |
450 | FreePool (Node);\r | |
451 | if (DevicePath == NULL) {\r | |
452 | Status = EFI_OUT_OF_RESOURCES;\r | |
453 | goto ON_ERROR;\r | |
454 | }\r | |
b659408b | 455 | \r |
d933e70a JW |
456 | //\r |
457 | // Append URI device path node.\r | |
458 | //\r | |
459 | Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
460 | if (Node == NULL) {\r | |
461 | Status = EFI_OUT_OF_RESOURCES;\r | |
462 | goto ON_ERROR;\r | |
463 | }\r | |
464 | Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r | |
465 | Node->DevPath.SubType = MSG_URI_DP;\r | |
466 | SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
b659408b | 467 | Private->Ip4Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r |
d933e70a JW |
468 | FreePool (Node);\r |
469 | FreePool (DevicePath);\r | |
b659408b | 470 | if (Private->Ip4Nic->DevicePath == NULL) {\r |
d933e70a JW |
471 | Status = EFI_OUT_OF_RESOURCES;\r |
472 | goto ON_ERROR;\r | |
473 | }\r | |
b659408b | 474 | \r |
d933e70a JW |
475 | //\r |
476 | // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r | |
477 | //\r | |
b659408b | 478 | CopyMem (&Private->Ip4Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (EFI_LOAD_FILE_PROTOCOL));\r |
d933e70a | 479 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
b659408b | 480 | &Private->Ip4Nic->Controller,\r |
d933e70a | 481 | &gEfiLoadFileProtocolGuid,\r |
b659408b | 482 | &Private->Ip4Nic->LoadFile,\r |
d933e70a | 483 | &gEfiDevicePathProtocolGuid,\r |
b659408b | 484 | Private->Ip4Nic->DevicePath,\r |
d933e70a JW |
485 | NULL\r |
486 | );\r | |
487 | if (EFI_ERROR (Status)) {\r | |
488 | goto ON_ERROR;\r | |
489 | }\r | |
b659408b | 490 | \r |
d933e70a JW |
491 | //\r |
492 | // Open the Caller Id child to setup a parent-child relationship between\r | |
b659408b | 493 | // real NIC handle and the HTTP boot Ipv4 NIC handle.\r |
d933e70a JW |
494 | //\r |
495 | Status = gBS->OpenProtocol (\r | |
496 | ControllerHandle,\r | |
497 | &gEfiCallerIdGuid,\r | |
498 | (VOID **) &Id,\r | |
499 | This->DriverBindingHandle,\r | |
b659408b | 500 | Private->Ip4Nic->Controller,\r |
d933e70a JW |
501 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r |
502 | );\r | |
503 | if (EFI_ERROR (Status)) {\r | |
504 | goto ON_ERROR;\r | |
505 | }\r | |
b659408b | 506 | \r |
d933e70a JW |
507 | return EFI_SUCCESS;\r |
508 | \r | |
b659408b | 509 | \r |
d933e70a JW |
510 | ON_ERROR:\r |
511 | \r | |
512 | HttpBootDestroyIp4Children (This, Private);\r | |
513 | FreePool (Private);\r | |
514 | \r | |
515 | return Status;\r | |
516 | }\r | |
517 | \r | |
b659408b | 518 | \r |
d933e70a JW |
519 | /**\r |
520 | Stops a device controller or a bus controller.\r | |
521 | \r | |
522 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
523 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
524 | into this common boot service. It is legal to call Stop() from other locations, \r | |
525 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
526 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
527 | same driver's Start() function.\r | |
528 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
529 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
530 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
531 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
532 | \r | |
533 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
534 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
535 | support a bus specific I/O protocol for the driver \r | |
536 | to use to stop the device.\r | |
537 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
538 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
539 | if NumberOfChildren is 0.\r | |
540 | \r | |
541 | @retval EFI_SUCCESS The device was stopped.\r | |
542 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
543 | \r | |
544 | **/\r | |
545 | EFI_STATUS\r | |
546 | EFIAPI\r | |
547 | HttpBootIp4DxeDriverBindingStop (\r | |
548 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
549 | IN EFI_HANDLE ControllerHandle,\r | |
550 | IN UINTN NumberOfChildren,\r | |
551 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
552 | )\r | |
553 | {\r | |
554 | EFI_STATUS Status;\r | |
555 | EFI_LOAD_FILE_PROTOCOL *LoadFile;\r | |
556 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
557 | EFI_HANDLE NicHandle;\r | |
558 | UINT32 *Id;\r | |
559 | \r | |
560 | //\r | |
561 | // Try to get the Load File Protocol from the controller handle.\r | |
562 | //\r | |
563 | Status = gBS->OpenProtocol (\r | |
564 | ControllerHandle,\r | |
565 | &gEfiLoadFileProtocolGuid,\r | |
566 | (VOID **) &LoadFile,\r | |
567 | This->DriverBindingHandle,\r | |
568 | ControllerHandle,\r | |
569 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
570 | );\r | |
571 | if (EFI_ERROR (Status)) {\r | |
572 | //\r | |
573 | // If failed, try to find the NIC handle for this controller.\r | |
574 | //\r | |
575 | NicHandle = HttpBootGetNicByIp4Children (ControllerHandle);\r | |
576 | if (NicHandle == NULL) {\r | |
577 | return EFI_SUCCESS;\r | |
578 | }\r | |
579 | \r | |
580 | //\r | |
581 | // Try to retrieve the private data by the Caller Id Guid.\r | |
582 | //\r | |
583 | Status = gBS->OpenProtocol (\r | |
584 | NicHandle,\r | |
585 | &gEfiCallerIdGuid,\r | |
586 | (VOID **) &Id,\r | |
587 | This->DriverBindingHandle,\r | |
588 | ControllerHandle,\r | |
589 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
590 | );\r | |
591 | if (EFI_ERROR (Status)) {\r | |
592 | return Status;\r | |
593 | }\r | |
594 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r | |
595 | } else {\r | |
596 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r | |
597 | NicHandle = Private->Controller;\r | |
598 | }\r | |
599 | \r | |
600 | //\r | |
601 | // Disable the HTTP boot function.\r | |
602 | //\r | |
603 | Status = HttpBootStop (Private);\r | |
604 | if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r | |
605 | return Status;\r | |
606 | }\r | |
607 | \r | |
608 | //\r | |
609 | // Destory all child instance and uninstall protocol interface.\r | |
610 | //\r | |
611 | HttpBootDestroyIp4Children (This, Private);\r | |
b659408b ZL |
612 | \r |
613 | if (Private->Ip4Nic == NULL && Private->Ip6Nic == NULL) {\r | |
614 | //\r | |
615 | // Release the cached data.\r | |
616 | //\r | |
617 | HttpBootFreeCacheList (Private);\r | |
618 | \r | |
619 | gBS->UninstallProtocolInterface (\r | |
620 | NicHandle,\r | |
621 | &gEfiCallerIdGuid,\r | |
622 | &Private->Id\r | |
623 | );\r | |
624 | FreePool (Private);\r | |
d933e70a | 625 | \r |
b659408b | 626 | }\r |
d933e70a JW |
627 | \r |
628 | return EFI_SUCCESS;\r | |
629 | }\r | |
630 | \r | |
631 | /**\r | |
b659408b ZL |
632 | Tests to see if this driver supports a given controller. If a child device is provided, \r |
633 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
d933e70a | 634 | \r |
b659408b ZL |
635 | This function checks to see if the driver specified by This supports the device specified by \r |
636 | ControllerHandle. Drivers will typically use the device path attached to \r | |
637 | ControllerHandle and/or the services from the bus I/O abstraction attached to \r | |
638 | ControllerHandle to determine if the driver supports ControllerHandle. This function \r | |
639 | may be called many times during platform initialization. In order to reduce boot times, the tests \r | |
640 | performed by this function must be very small, and take as little time as possible to execute. This \r | |
641 | function must not change the state of any hardware devices, and this function must be aware that the \r | |
642 | device specified by ControllerHandle may already be managed by the same driver or a \r | |
643 | different driver. This function must match its calls to AllocatePages() with FreePages(), \r | |
644 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r | |
645 | Because ControllerHandle may have been previously started by the same driver, if a protocol is \r | |
646 | already in the opened state, then it must not be closed with CloseProtocol(). This is required \r | |
647 | to guarantee the state of ControllerHandle is not modified by this function.\r | |
d933e70a | 648 | \r |
b659408b ZL |
649 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
650 | @param[in] ControllerHandle The handle of the controller to test. This handle \r | |
651 | must support a protocol interface that supplies \r | |
652 | an I/O abstraction to the driver.\r | |
653 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
654 | parameter is ignored by device drivers, and is optional for bus \r | |
655 | drivers. For bus drivers, if this parameter is not NULL, then \r | |
656 | the bus driver must determine if the bus controller specified \r | |
657 | by ControllerHandle and the child controller specified \r | |
658 | by RemainingDevicePath are both supported by this \r | |
659 | bus driver.\r | |
d933e70a | 660 | \r |
b659408b ZL |
661 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r |
662 | RemainingDevicePath is supported by the driver specified by This.\r | |
663 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
664 | RemainingDevicePath is already being managed by the driver\r | |
665 | specified by This.\r | |
666 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
667 | RemainingDevicePath is already being managed by a different\r | |
668 | driver or an application that requires exclusive access.\r | |
669 | Currently not implemented.\r | |
670 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
671 | RemainingDevicePath is not supported by the driver specified by This.\r | |
d933e70a JW |
672 | **/\r |
673 | EFI_STATUS\r | |
674 | EFIAPI\r | |
b659408b ZL |
675 | HttpBootIp6DxeDriverBindingSupported (\r |
676 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
677 | IN EFI_HANDLE ControllerHandle,\r | |
678 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
d933e70a JW |
679 | )\r |
680 | {\r | |
b659408b ZL |
681 | EFI_STATUS Status;\r |
682 | \r | |
d933e70a | 683 | //\r |
b659408b | 684 | // Try to open the DHCP6, HTTP and Device Path protocol.\r |
d933e70a | 685 | //\r |
b659408b ZL |
686 | Status = gBS->OpenProtocol (\r |
687 | ControllerHandle,\r | |
688 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
689 | NULL,\r | |
690 | This->DriverBindingHandle,\r | |
691 | ControllerHandle,\r | |
692 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
693 | );\r | |
694 | if (EFI_ERROR (Status)) {\r | |
695 | return Status;\r | |
696 | }\r | |
697 | \r | |
698 | Status = gBS->OpenProtocol (\r | |
699 | ControllerHandle,\r | |
700 | &gEfiHttpServiceBindingProtocolGuid,\r | |
701 | NULL,\r | |
702 | This->DriverBindingHandle,\r | |
703 | ControllerHandle,\r | |
704 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
705 | );\r | |
706 | if (EFI_ERROR (Status)) {\r | |
707 | return Status;\r | |
708 | }\r | |
709 | \r | |
710 | Status = gBS->OpenProtocol (\r | |
711 | ControllerHandle,\r | |
712 | &gEfiDevicePathProtocolGuid,\r | |
713 | NULL,\r | |
714 | This->DriverBindingHandle,\r | |
715 | ControllerHandle,\r | |
716 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
717 | );\r | |
718 | \r | |
719 | return Status;\r | |
720 | \r | |
721 | }\r | |
722 | \r | |
723 | /**\r | |
724 | Starts a device controller or a bus controller.\r | |
725 | \r | |
726 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
727 | As a result, much of the error checking on the parameters to Start() has been moved into this \r | |
728 | common boot service. It is legal to call Start() from other locations, \r | |
729 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
730 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
731 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
732 | EFI_DEVICE_PATH_PROTOCOL.\r | |
733 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
734 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r | |
735 | \r | |
736 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
737 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
738 | must support a protocol interface that supplies \r | |
739 | an I/O abstraction to the driver.\r | |
740 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
741 | parameter is ignored by device drivers, and is optional for bus \r | |
742 | drivers. For a bus driver, if this parameter is NULL, then handles \r | |
743 | for all the children of Controller are created by this driver. \r | |
744 | If this parameter is not NULL and the first Device Path Node is \r | |
745 | not the End of Device Path Node, then only the handle for the \r | |
746 | child device specified by the first Device Path Node of \r | |
747 | RemainingDevicePath is created by this driver.\r | |
748 | If the first Device Path Node of RemainingDevicePath is \r | |
749 | the End of Device Path Node, no child handle is created by this\r | |
750 | driver.\r | |
751 | \r | |
752 | @retval EFI_SUCCESS The device was started.\r | |
753 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
754 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
755 | @retval Others The driver failded to start the device.\r | |
756 | \r | |
757 | **/\r | |
758 | EFI_STATUS\r | |
759 | EFIAPI\r | |
760 | HttpBootIp6DxeDriverBindingStart (\r | |
761 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
762 | IN EFI_HANDLE ControllerHandle,\r | |
763 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
764 | )\r | |
765 | {\r | |
766 | EFI_STATUS Status;\r | |
767 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
768 | EFI_DEV_PATH *Node;\r | |
769 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
770 | UINT32 *Id;\r | |
771 | \r | |
772 | Status = gBS->OpenProtocol (\r | |
773 | ControllerHandle,\r | |
774 | &gEfiCallerIdGuid,\r | |
775 | (VOID **) &Id,\r | |
776 | This->DriverBindingHandle,\r | |
777 | ControllerHandle,\r | |
778 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
779 | );\r | |
780 | \r | |
781 | if (!EFI_ERROR (Status)) {\r | |
782 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);\r | |
783 | } else {\r | |
784 | //\r | |
785 | // Initialize the private data structure.\r | |
786 | //\r | |
787 | Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));\r | |
788 | if (Private == NULL) {\r | |
789 | return EFI_OUT_OF_RESOURCES;\r | |
790 | }\r | |
791 | Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r | |
792 | Private->Controller = ControllerHandle;\r | |
793 | Private->Image = This->ImageHandle;\r | |
794 | InitializeListHead (&Private->CacheList);\r | |
795 | //\r | |
796 | // Get the NII interface if it exists, it's not required.\r | |
797 | //\r | |
798 | Status = gBS->OpenProtocol (\r | |
799 | ControllerHandle,\r | |
800 | &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r | |
801 | (VOID **) &Private->Nii,\r | |
802 | This->DriverBindingHandle,\r | |
803 | ControllerHandle,\r | |
804 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
805 | );\r | |
806 | if (EFI_ERROR (Status)) {\r | |
807 | Private->Nii = NULL;\r | |
808 | }\r | |
809 | \r | |
810 | //\r | |
811 | // Open Device Path Protocol to prepare for appending IP and URI node.\r | |
812 | //\r | |
813 | Status = gBS->OpenProtocol (\r | |
814 | ControllerHandle,\r | |
815 | &gEfiDevicePathProtocolGuid,\r | |
816 | (VOID **) &Private->ParentDevicePath,\r | |
817 | This->DriverBindingHandle,\r | |
818 | ControllerHandle,\r | |
819 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
820 | );\r | |
821 | if (EFI_ERROR (Status)) {\r | |
822 | goto ON_ERROR;\r | |
823 | }\r | |
824 | \r | |
825 | //\r | |
826 | // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r | |
827 | // NIC handle and the private data.\r | |
828 | //\r | |
829 | Status = gBS->InstallProtocolInterface (\r | |
830 | &ControllerHandle,\r | |
831 | &gEfiCallerIdGuid,\r | |
832 | EFI_NATIVE_INTERFACE,\r | |
833 | &Private->Id\r | |
834 | );\r | |
835 | if (EFI_ERROR (Status)) {\r | |
836 | goto ON_ERROR;\r | |
837 | }\r | |
838 | \r | |
839 | }\r | |
840 | \r | |
841 | if (Private->Ip6Nic != NULL) {\r | |
842 | //\r | |
843 | // Already created before\r | |
844 | //\r | |
845 | return EFI_SUCCESS;\r | |
846 | }\r | |
847 | \r | |
848 | Private->Ip6Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r | |
849 | if (Private->Ip6Nic == NULL) {\r | |
850 | return EFI_OUT_OF_RESOURCES;\r | |
851 | }\r | |
852 | Private->Ip6Nic->Private = Private;\r | |
853 | Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r | |
854 | \r | |
855 | //\r | |
856 | // Create Dhcp6 child and open Dhcp6 protocol\r | |
857 | Status = NetLibCreateServiceChild (\r | |
858 | ControllerHandle,\r | |
859 | This->DriverBindingHandle,\r | |
860 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
861 | &Private->Dhcp6Child\r | |
862 | );\r | |
863 | if (EFI_ERROR (Status)) {\r | |
864 | goto ON_ERROR;\r | |
865 | }\r | |
866 | \r | |
867 | Status = gBS->OpenProtocol (\r | |
868 | Private->Dhcp6Child,\r | |
869 | &gEfiDhcp6ProtocolGuid,\r | |
870 | (VOID **) &Private->Dhcp6,\r | |
871 | This->DriverBindingHandle,\r | |
872 | ControllerHandle,\r | |
873 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
874 | );\r | |
875 | if (EFI_ERROR (Status)) {\r | |
876 | goto ON_ERROR;\r | |
877 | }\r | |
878 | \r | |
879 | //\r | |
880 | // Create Ip6 child and open Ip6 protocol for background ICMP packets.\r | |
881 | //\r | |
882 | Status = NetLibCreateServiceChild (\r | |
883 | ControllerHandle,\r | |
884 | This->DriverBindingHandle,\r | |
885 | &gEfiIp6ServiceBindingProtocolGuid,\r | |
886 | &Private->Ip6Child\r | |
887 | );\r | |
888 | if (EFI_ERROR (Status)) {\r | |
889 | goto ON_ERROR;\r | |
890 | }\r | |
891 | \r | |
892 | Status = gBS->OpenProtocol (\r | |
893 | Private->Ip6Child,\r | |
894 | &gEfiIp6ProtocolGuid,\r | |
895 | (VOID **) &Private->Ip6,\r | |
896 | This->DriverBindingHandle,\r | |
897 | ControllerHandle,\r | |
898 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
899 | );\r | |
900 | if (EFI_ERROR (Status)) {\r | |
901 | goto ON_ERROR;\r | |
902 | }\r | |
903 | \r | |
904 | //\r | |
905 | // Locate Ip6Config protocol, it's required to configure the default gateway address.\r | |
906 | //\r | |
907 | Status = gBS->OpenProtocol (\r | |
908 | ControllerHandle,\r | |
909 | &gEfiIp6ConfigProtocolGuid,\r | |
910 | (VOID **) &Private->Ip6Config,\r | |
911 | This->DriverBindingHandle,\r | |
912 | ControllerHandle,\r | |
913 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
914 | );\r | |
915 | if (EFI_ERROR (Status)) {\r | |
916 | goto ON_ERROR;\r | |
917 | }\r | |
918 | \r | |
919 | //\r | |
920 | // Append IPv6 device path node.\r | |
921 | //\r | |
922 | Node = AllocateZeroPool (sizeof (IPv6_DEVICE_PATH));\r | |
923 | if (Node == NULL) {\r | |
924 | Status = EFI_OUT_OF_RESOURCES;\r | |
925 | goto ON_ERROR;\r | |
926 | }\r | |
927 | Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;\r | |
928 | Node->Ipv6.Header.SubType = MSG_IPv6_DP;\r | |
929 | Node->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;\r | |
930 | SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r | |
931 | DevicePath = AppendDevicePathNode(Private->ParentDevicePath, (EFI_DEVICE_PATH*) Node);\r | |
932 | FreePool(Node);\r | |
933 | if (DevicePath == NULL) {\r | |
934 | Status = EFI_OUT_OF_RESOURCES;\r | |
935 | goto ON_ERROR;\r | |
936 | }\r | |
937 | \r | |
938 | //\r | |
939 | // Append URI device path node.\r | |
940 | //\r | |
941 | Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
942 | if (Node == NULL) {\r | |
943 | Status = EFI_OUT_OF_RESOURCES;\r | |
944 | goto ON_ERROR;\r | |
945 | }\r | |
946 | Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r | |
947 | Node->DevPath.SubType = MSG_URI_DP;\r | |
948 | SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
949 | Private->Ip6Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r | |
950 | FreePool (Node);\r | |
951 | FreePool (DevicePath);\r | |
952 | if (Private->Ip6Nic->DevicePath == NULL) {\r | |
953 | Status = EFI_OUT_OF_RESOURCES;\r | |
954 | goto ON_ERROR;\r | |
955 | }\r | |
956 | \r | |
957 | //\r | |
958 | // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r | |
959 | //\r | |
960 | CopyMem (&Private->Ip6Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (Private->LoadFile));\r | |
961 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
962 | &Private->Ip6Nic->Controller,\r | |
963 | &gEfiLoadFileProtocolGuid,\r | |
964 | &Private->Ip6Nic->LoadFile,\r | |
965 | &gEfiDevicePathProtocolGuid,\r | |
966 | Private->Ip6Nic->DevicePath,\r | |
967 | NULL\r | |
968 | );\r | |
969 | if (EFI_ERROR (Status)) {\r | |
970 | goto ON_ERROR;\r | |
971 | }\r | |
972 | \r | |
973 | //\r | |
974 | // Open the Caller Id child to setup a parent-child relationship between\r | |
975 | // real NIC handle and the HTTP boot child handle.\r | |
976 | //\r | |
977 | Status = gBS->OpenProtocol (\r | |
978 | ControllerHandle,\r | |
979 | &gEfiCallerIdGuid,\r | |
980 | (VOID **) &Id,\r | |
981 | This->DriverBindingHandle,\r | |
982 | Private->Ip6Nic->Controller,\r | |
983 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
984 | );\r | |
985 | if (EFI_ERROR (Status)) {\r | |
986 | goto ON_ERROR;\r | |
987 | }\r | |
988 | \r | |
989 | return EFI_SUCCESS;\r | |
990 | \r | |
991 | ON_ERROR:\r | |
992 | \r | |
993 | HttpBootDestroyIp6Children(This, Private);\r | |
994 | FreePool (Private);\r | |
995 | \r | |
996 | return Status;\r | |
997 | \r | |
998 | }\r | |
999 | \r | |
1000 | /**\r | |
1001 | Stops a device controller or a bus controller.\r | |
1002 | \r | |
1003 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
1004 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
1005 | into this common boot service. It is legal to call Stop() from other locations, \r | |
1006 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
1007 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
1008 | same driver's Start() function.\r | |
1009 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
1010 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
1011 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
1012 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
1013 | \r | |
1014 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
1015 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
1016 | support a bus specific I/O protocol for the driver \r | |
1017 | to use to stop the device.\r | |
1018 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
1019 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
1020 | if NumberOfChildren is 0.\r | |
1021 | \r | |
1022 | @retval EFI_SUCCESS The device was stopped.\r | |
1023 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
1024 | \r | |
1025 | **/\r | |
1026 | EFI_STATUS\r | |
1027 | EFIAPI\r | |
1028 | HttpBootIp6DxeDriverBindingStop (\r | |
1029 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
1030 | IN EFI_HANDLE ControllerHandle,\r | |
1031 | IN UINTN NumberOfChildren,\r | |
1032 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
1033 | )\r | |
1034 | {\r | |
1035 | EFI_STATUS Status;\r | |
1036 | EFI_LOAD_FILE_PROTOCOL *LoadFile;\r | |
1037 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
1038 | EFI_HANDLE NicHandle;\r | |
1039 | UINT32 *Id;\r | |
1040 | \r | |
1041 | //\r | |
1042 | // Try to get the Load File Protocol from the controller handle.\r | |
1043 | //\r | |
1044 | Status = gBS->OpenProtocol (\r | |
1045 | ControllerHandle,\r | |
1046 | &gEfiLoadFileProtocolGuid,\r | |
1047 | (VOID **) &LoadFile,\r | |
1048 | This->DriverBindingHandle,\r | |
1049 | ControllerHandle,\r | |
1050 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1051 | );\r | |
1052 | if (EFI_ERROR (Status)) {\r | |
1053 | //\r | |
1054 | // If failed, try to find the NIC handle for this controller.\r | |
1055 | //\r | |
1056 | NicHandle = HttpBootGetNicByIp6Children (ControllerHandle);\r | |
1057 | if (NicHandle == NULL) {\r | |
1058 | return EFI_SUCCESS;\r | |
1059 | }\r | |
1060 | \r | |
1061 | //\r | |
1062 | // Try to retrieve the private data by the Caller Id Guid.\r | |
1063 | //\r | |
1064 | Status = gBS->OpenProtocol (\r | |
1065 | NicHandle,\r | |
1066 | &gEfiCallerIdGuid,\r | |
1067 | (VOID **) &Id,\r | |
1068 | This->DriverBindingHandle,\r | |
1069 | ControllerHandle,\r | |
1070 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1071 | );\r | |
1072 | if (EFI_ERROR (Status)) {\r | |
1073 | return Status;\r | |
1074 | }\r | |
1075 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r | |
1076 | } else {\r | |
1077 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r | |
1078 | NicHandle = Private->Controller;\r | |
1079 | }\r | |
1080 | \r | |
1081 | //\r | |
1082 | // Disable the HTTP boot function.\r | |
1083 | //\r | |
1084 | Status = HttpBootStop (Private);\r | |
1085 | if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r | |
1086 | return Status;\r | |
1087 | }\r | |
1088 | \r | |
1089 | //\r | |
1090 | // Destory all child instance and uninstall protocol interface.\r | |
1091 | //\r | |
1092 | HttpBootDestroyIp6Children (This, Private);\r | |
1093 | \r | |
1094 | if (Private->Ip4Nic == NULL && Private->Ip6Nic == NULL) {\r | |
1095 | //\r | |
1096 | // Release the cached data.\r | |
1097 | //\r | |
1098 | HttpBootFreeCacheList (Private);\r | |
1099 | \r | |
1100 | gBS->UninstallProtocolInterface (\r | |
1101 | NicHandle,\r | |
1102 | &gEfiCallerIdGuid,\r | |
1103 | &Private->Id\r | |
1104 | );\r | |
1105 | FreePool (Private);\r | |
1106 | \r | |
1107 | }\r | |
1108 | \r | |
1109 | return EFI_SUCCESS;\r | |
1110 | }\r | |
1111 | /**\r | |
1112 | This is the declaration of an EFI image entry point. This entry point is\r | |
1113 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
1114 | both device drivers and bus drivers.\r | |
1115 | \r | |
1116 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r | |
1117 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1118 | \r | |
1119 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1120 | @retval Others An unexpected error occurred.\r | |
1121 | \r | |
1122 | **/\r | |
1123 | EFI_STATUS\r | |
1124 | EFIAPI\r | |
1125 | HttpBootDxeDriverEntryPoint (\r | |
1126 | IN EFI_HANDLE ImageHandle,\r | |
1127 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1128 | )\r | |
1129 | {\r | |
1130 | EFI_STATUS Status;\r | |
1131 | //\r | |
1132 | // Install UEFI Driver Model protocol(s).\r | |
1133 | //\r | |
1134 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1135 | ImageHandle,\r | |
1136 | SystemTable,\r | |
1137 | &gHttpBootIp4DxeDriverBinding,\r | |
1138 | ImageHandle,\r | |
1139 | &gHttpBootDxeComponentName,\r | |
1140 | &gHttpBootDxeComponentName2\r | |
1141 | );\r | |
1142 | if (EFI_ERROR (Status)) {\r | |
1143 | return Status;\r | |
1144 | }\r | |
1145 | \r | |
1146 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1147 | ImageHandle,\r | |
1148 | SystemTable,\r | |
1149 | &gHttpBootIp6DxeDriverBinding,\r | |
1150 | NULL,\r | |
1151 | &gHttpBootDxeComponentName,\r | |
1152 | &gHttpBootDxeComponentName2\r | |
1153 | );\r | |
1154 | if (EFI_ERROR (Status)) {\r | |
1155 | gBS->UninstallMultipleProtocolInterfaces(\r | |
1156 | ImageHandle,\r | |
1157 | &gEfiDriverBindingProtocolGuid,\r | |
1158 | &gHttpBootIp4DxeDriverBinding,\r | |
1159 | &gEfiComponentName2ProtocolGuid,\r | |
1160 | &gHttpBootDxeComponentName2,\r | |
1161 | &gEfiComponentNameProtocolGuid,\r | |
1162 | &gHttpBootDxeComponentName,\r | |
1163 | NULL\r | |
1164 | );\r | |
1165 | }\r | |
1166 | return Status;\r | |
d933e70a JW |
1167 | }\r |
1168 | \r |