]>
Commit | Line | Data |
---|---|---|
d933e70a JW |
1 | /** @file\r |
2 | Driver Binding functions implementation for UEFI HTTP boot.\r | |
3 | \r | |
fa848a40 | 4 | Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r |
d933e70a JW |
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 |
75372581 | 324 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);\r |
b659408b ZL |
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 | |
b659408b ZL |
335 | InitializeListHead (&Private->CacheList);\r |
336 | //\r | |
337 | // Get the NII interface if it exists, it's not required.\r | |
338 | //\r | |
339 | Status = gBS->OpenProtocol (\r | |
340 | ControllerHandle,\r | |
341 | &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r | |
342 | (VOID **) &Private->Nii,\r | |
343 | This->DriverBindingHandle,\r | |
344 | ControllerHandle,\r | |
345 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
346 | );\r | |
347 | if (EFI_ERROR (Status)) {\r | |
348 | Private->Nii = NULL;\r | |
349 | }\r | |
d933e70a | 350 | \r |
b659408b ZL |
351 | //\r |
352 | // Open Device Path Protocol to prepare for appending IP and URI node.\r | |
353 | //\r | |
354 | Status = gBS->OpenProtocol (\r | |
355 | ControllerHandle,\r | |
356 | &gEfiDevicePathProtocolGuid,\r | |
357 | (VOID **) &Private->ParentDevicePath,\r | |
358 | This->DriverBindingHandle,\r | |
359 | ControllerHandle,\r | |
360 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
361 | );\r | |
362 | if (EFI_ERROR (Status)) {\r | |
363 | goto ON_ERROR;\r | |
364 | }\r | |
365 | \r | |
fa848a40 FS |
366 | //\r |
367 | // Initialize the HII configuration form.\r | |
368 | //\r | |
369 | Status = HttpBootConfigFormInit (Private);\r | |
370 | if (EFI_ERROR (Status)) {\r | |
371 | goto ON_ERROR;\r | |
372 | }\r | |
373 | \r | |
b659408b ZL |
374 | //\r |
375 | // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r | |
376 | // NIC handle and the private data.\r | |
377 | //\r | |
378 | Status = gBS->InstallProtocolInterface (\r | |
379 | &ControllerHandle,\r | |
380 | &gEfiCallerIdGuid,\r | |
381 | EFI_NATIVE_INTERFACE,\r | |
382 | &Private->Id\r | |
383 | );\r | |
384 | if (EFI_ERROR (Status)) {\r | |
385 | goto ON_ERROR;\r | |
386 | }\r | |
387 | \r | |
388 | }\r | |
389 | \r | |
390 | if (Private->Ip4Nic != NULL) {\r | |
391 | //\r | |
392 | // Already created before\r | |
393 | //\r | |
394 | return EFI_SUCCESS;\r | |
395 | }\r | |
396 | \r | |
397 | Private->Ip4Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r | |
398 | if (Private->Ip4Nic == NULL) {\r | |
d933e70a JW |
399 | return EFI_OUT_OF_RESOURCES;\r |
400 | }\r | |
75372581 FS |
401 | Private->Ip4Nic->Private = Private;\r |
402 | Private->Ip4Nic->ImageHandle = This->DriverBindingHandle;\r | |
403 | Private->Ip4Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r | |
b659408b | 404 | \r |
d933e70a | 405 | //\r |
b659408b | 406 | // Create DHCP4 child instance.\r |
d933e70a JW |
407 | //\r |
408 | Status = NetLibCreateServiceChild (\r | |
409 | ControllerHandle,\r | |
410 | This->DriverBindingHandle,\r | |
411 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
412 | &Private->Dhcp4Child\r | |
413 | );\r | |
414 | if (EFI_ERROR (Status)) {\r | |
415 | goto ON_ERROR;\r | |
416 | }\r | |
b659408b | 417 | \r |
d933e70a JW |
418 | Status = gBS->OpenProtocol (\r |
419 | Private->Dhcp4Child,\r | |
420 | &gEfiDhcp4ProtocolGuid,\r | |
421 | (VOID **) &Private->Dhcp4,\r | |
422 | This->DriverBindingHandle,\r | |
423 | ControllerHandle,\r | |
424 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
425 | );\r | |
426 | if (EFI_ERROR (Status)) {\r | |
427 | goto ON_ERROR;\r | |
428 | }\r | |
b659408b | 429 | \r |
d933e70a JW |
430 | //\r |
431 | // Get the Ip4Config2 protocol, it's required to configure the default gateway address.\r | |
432 | //\r | |
433 | Status = gBS->OpenProtocol (\r | |
434 | ControllerHandle,\r | |
435 | &gEfiIp4Config2ProtocolGuid,\r | |
436 | (VOID **) &Private->Ip4Config2,\r | |
437 | This->DriverBindingHandle,\r | |
438 | ControllerHandle,\r | |
439 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
440 | );\r | |
441 | if (EFI_ERROR (Status)) {\r | |
442 | goto ON_ERROR;\r | |
443 | }\r | |
b659408b | 444 | \r |
d933e70a JW |
445 | //\r |
446 | // Append IPv4 device path node.\r | |
447 | //\r | |
448 | Node = AllocateZeroPool (sizeof (IPv4_DEVICE_PATH));\r | |
449 | if (Node == NULL) {\r | |
450 | Status = EFI_OUT_OF_RESOURCES;\r | |
451 | goto ON_ERROR;\r | |
452 | }\r | |
453 | Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;\r | |
454 | Node->Ipv4.Header.SubType = MSG_IPv4_DP;\r | |
455 | SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));\r | |
456 | Node->Ipv4.StaticIpAddress = FALSE;\r | |
457 | DevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r | |
458 | FreePool (Node);\r | |
459 | if (DevicePath == NULL) {\r | |
460 | Status = EFI_OUT_OF_RESOURCES;\r | |
461 | goto ON_ERROR;\r | |
462 | }\r | |
b659408b | 463 | \r |
d933e70a JW |
464 | //\r |
465 | // Append URI device path node.\r | |
466 | //\r | |
467 | Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
468 | if (Node == NULL) {\r | |
469 | Status = EFI_OUT_OF_RESOURCES;\r | |
470 | goto ON_ERROR;\r | |
471 | }\r | |
472 | Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r | |
473 | Node->DevPath.SubType = MSG_URI_DP;\r | |
474 | SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
b659408b | 475 | Private->Ip4Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r |
d933e70a JW |
476 | FreePool (Node);\r |
477 | FreePool (DevicePath);\r | |
b659408b | 478 | if (Private->Ip4Nic->DevicePath == NULL) {\r |
d933e70a JW |
479 | Status = EFI_OUT_OF_RESOURCES;\r |
480 | goto ON_ERROR;\r | |
481 | }\r | |
b659408b | 482 | \r |
d933e70a JW |
483 | //\r |
484 | // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r | |
485 | //\r | |
b659408b | 486 | CopyMem (&Private->Ip4Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (EFI_LOAD_FILE_PROTOCOL));\r |
d933e70a | 487 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
b659408b | 488 | &Private->Ip4Nic->Controller,\r |
d933e70a | 489 | &gEfiLoadFileProtocolGuid,\r |
b659408b | 490 | &Private->Ip4Nic->LoadFile,\r |
d933e70a | 491 | &gEfiDevicePathProtocolGuid,\r |
b659408b | 492 | Private->Ip4Nic->DevicePath,\r |
d933e70a JW |
493 | NULL\r |
494 | );\r | |
495 | if (EFI_ERROR (Status)) {\r | |
496 | goto ON_ERROR;\r | |
497 | }\r | |
b659408b | 498 | \r |
d933e70a JW |
499 | //\r |
500 | // Open the Caller Id child to setup a parent-child relationship between\r | |
b659408b | 501 | // real NIC handle and the HTTP boot Ipv4 NIC handle.\r |
d933e70a JW |
502 | //\r |
503 | Status = gBS->OpenProtocol (\r | |
504 | ControllerHandle,\r | |
505 | &gEfiCallerIdGuid,\r | |
506 | (VOID **) &Id,\r | |
507 | This->DriverBindingHandle,\r | |
b659408b | 508 | Private->Ip4Nic->Controller,\r |
d933e70a JW |
509 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r |
510 | );\r | |
511 | if (EFI_ERROR (Status)) {\r | |
512 | goto ON_ERROR;\r | |
513 | }\r | |
b659408b | 514 | \r |
d933e70a JW |
515 | return EFI_SUCCESS;\r |
516 | \r | |
b659408b | 517 | \r |
d933e70a | 518 | ON_ERROR:\r |
fa848a40 | 519 | \r |
d933e70a | 520 | HttpBootDestroyIp4Children (This, Private);\r |
fa848a40 | 521 | HttpBootConfigFormUnload (Private);\r |
d933e70a JW |
522 | FreePool (Private);\r |
523 | \r | |
524 | return Status;\r | |
525 | }\r | |
526 | \r | |
b659408b | 527 | \r |
d933e70a JW |
528 | /**\r |
529 | Stops a device controller or a bus controller.\r | |
530 | \r | |
531 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
532 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
533 | into this common boot service. It is legal to call Stop() from other locations, \r | |
534 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
535 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
536 | same driver's Start() function.\r | |
537 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
538 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
539 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
540 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
541 | \r | |
542 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
543 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
544 | support a bus specific I/O protocol for the driver \r | |
545 | to use to stop the device.\r | |
546 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
547 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
548 | if NumberOfChildren is 0.\r | |
549 | \r | |
550 | @retval EFI_SUCCESS The device was stopped.\r | |
551 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
552 | \r | |
553 | **/\r | |
554 | EFI_STATUS\r | |
555 | EFIAPI\r | |
556 | HttpBootIp4DxeDriverBindingStop (\r | |
557 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
558 | IN EFI_HANDLE ControllerHandle,\r | |
559 | IN UINTN NumberOfChildren,\r | |
560 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
561 | )\r | |
562 | {\r | |
563 | EFI_STATUS Status;\r | |
564 | EFI_LOAD_FILE_PROTOCOL *LoadFile;\r | |
565 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
566 | EFI_HANDLE NicHandle;\r | |
567 | UINT32 *Id;\r | |
568 | \r | |
569 | //\r | |
570 | // Try to get the Load File Protocol from the controller handle.\r | |
571 | //\r | |
572 | Status = gBS->OpenProtocol (\r | |
573 | ControllerHandle,\r | |
574 | &gEfiLoadFileProtocolGuid,\r | |
575 | (VOID **) &LoadFile,\r | |
576 | This->DriverBindingHandle,\r | |
577 | ControllerHandle,\r | |
578 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
579 | );\r | |
580 | if (EFI_ERROR (Status)) {\r | |
581 | //\r | |
582 | // If failed, try to find the NIC handle for this controller.\r | |
583 | //\r | |
584 | NicHandle = HttpBootGetNicByIp4Children (ControllerHandle);\r | |
585 | if (NicHandle == NULL) {\r | |
586 | return EFI_SUCCESS;\r | |
587 | }\r | |
588 | \r | |
589 | //\r | |
590 | // Try to retrieve the private data by the Caller Id Guid.\r | |
591 | //\r | |
592 | Status = gBS->OpenProtocol (\r | |
593 | NicHandle,\r | |
594 | &gEfiCallerIdGuid,\r | |
595 | (VOID **) &Id,\r | |
596 | This->DriverBindingHandle,\r | |
597 | ControllerHandle,\r | |
598 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
599 | );\r | |
600 | if (EFI_ERROR (Status)) {\r | |
601 | return Status;\r | |
602 | }\r | |
603 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r | |
604 | } else {\r | |
605 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r | |
606 | NicHandle = Private->Controller;\r | |
607 | }\r | |
608 | \r | |
609 | //\r | |
610 | // Disable the HTTP boot function.\r | |
611 | //\r | |
612 | Status = HttpBootStop (Private);\r | |
613 | if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r | |
614 | return Status;\r | |
615 | }\r | |
616 | \r | |
617 | //\r | |
618 | // Destory all child instance and uninstall protocol interface.\r | |
619 | //\r | |
620 | HttpBootDestroyIp4Children (This, Private);\r | |
b659408b ZL |
621 | \r |
622 | if (Private->Ip4Nic == NULL && Private->Ip6Nic == NULL) {\r | |
623 | //\r | |
624 | // Release the cached data.\r | |
625 | //\r | |
626 | HttpBootFreeCacheList (Private);\r | |
fa848a40 FS |
627 | \r |
628 | //\r | |
629 | // Unload the config form.\r | |
630 | //\r | |
631 | HttpBootConfigFormUnload (Private);\r | |
b659408b ZL |
632 | \r |
633 | gBS->UninstallProtocolInterface (\r | |
634 | NicHandle,\r | |
635 | &gEfiCallerIdGuid,\r | |
636 | &Private->Id\r | |
637 | );\r | |
638 | FreePool (Private);\r | |
d933e70a | 639 | \r |
b659408b | 640 | }\r |
d933e70a JW |
641 | \r |
642 | return EFI_SUCCESS;\r | |
643 | }\r | |
644 | \r | |
645 | /**\r | |
b659408b ZL |
646 | Tests to see if this driver supports a given controller. If a child device is provided, \r |
647 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
d933e70a | 648 | \r |
b659408b ZL |
649 | This function checks to see if the driver specified by This supports the device specified by \r |
650 | ControllerHandle. Drivers will typically use the device path attached to \r | |
651 | ControllerHandle and/or the services from the bus I/O abstraction attached to \r | |
652 | ControllerHandle to determine if the driver supports ControllerHandle. This function \r | |
653 | may be called many times during platform initialization. In order to reduce boot times, the tests \r | |
654 | performed by this function must be very small, and take as little time as possible to execute. This \r | |
655 | function must not change the state of any hardware devices, and this function must be aware that the \r | |
656 | device specified by ControllerHandle may already be managed by the same driver or a \r | |
657 | different driver. This function must match its calls to AllocatePages() with FreePages(), \r | |
658 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r | |
659 | Because ControllerHandle may have been previously started by the same driver, if a protocol is \r | |
660 | already in the opened state, then it must not be closed with CloseProtocol(). This is required \r | |
661 | to guarantee the state of ControllerHandle is not modified by this function.\r | |
d933e70a | 662 | \r |
b659408b ZL |
663 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
664 | @param[in] ControllerHandle The handle of the controller to test. This handle \r | |
665 | must support a protocol interface that supplies \r | |
666 | an I/O abstraction to the driver.\r | |
667 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
668 | parameter is ignored by device drivers, and is optional for bus \r | |
669 | drivers. For bus drivers, if this parameter is not NULL, then \r | |
670 | the bus driver must determine if the bus controller specified \r | |
671 | by ControllerHandle and the child controller specified \r | |
672 | by RemainingDevicePath are both supported by this \r | |
673 | bus driver.\r | |
d933e70a | 674 | \r |
b659408b ZL |
675 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r |
676 | RemainingDevicePath is supported by the driver specified by This.\r | |
677 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
678 | RemainingDevicePath is already being managed by the driver\r | |
679 | specified by This.\r | |
680 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
681 | RemainingDevicePath is already being managed by a different\r | |
682 | driver or an application that requires exclusive access.\r | |
683 | Currently not implemented.\r | |
684 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
685 | RemainingDevicePath is not supported by the driver specified by This.\r | |
d933e70a JW |
686 | **/\r |
687 | EFI_STATUS\r | |
688 | EFIAPI\r | |
b659408b ZL |
689 | HttpBootIp6DxeDriverBindingSupported (\r |
690 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
691 | IN EFI_HANDLE ControllerHandle,\r | |
692 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
d933e70a JW |
693 | )\r |
694 | {\r | |
b659408b ZL |
695 | EFI_STATUS Status;\r |
696 | \r | |
d933e70a | 697 | //\r |
b659408b | 698 | // Try to open the DHCP6, HTTP and Device Path protocol.\r |
d933e70a | 699 | //\r |
b659408b ZL |
700 | Status = gBS->OpenProtocol (\r |
701 | ControllerHandle,\r | |
702 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
703 | NULL,\r | |
704 | This->DriverBindingHandle,\r | |
705 | ControllerHandle,\r | |
706 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
707 | );\r | |
708 | if (EFI_ERROR (Status)) {\r | |
709 | return Status;\r | |
710 | }\r | |
711 | \r | |
712 | Status = gBS->OpenProtocol (\r | |
713 | ControllerHandle,\r | |
714 | &gEfiHttpServiceBindingProtocolGuid,\r | |
715 | NULL,\r | |
716 | This->DriverBindingHandle,\r | |
717 | ControllerHandle,\r | |
718 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
719 | );\r | |
720 | if (EFI_ERROR (Status)) {\r | |
721 | return Status;\r | |
722 | }\r | |
723 | \r | |
724 | Status = gBS->OpenProtocol (\r | |
725 | ControllerHandle,\r | |
726 | &gEfiDevicePathProtocolGuid,\r | |
727 | NULL,\r | |
728 | This->DriverBindingHandle,\r | |
729 | ControllerHandle,\r | |
730 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
731 | );\r | |
732 | \r | |
733 | return Status;\r | |
734 | \r | |
735 | }\r | |
736 | \r | |
737 | /**\r | |
738 | Starts a device controller or a bus controller.\r | |
739 | \r | |
740 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
741 | As a result, much of the error checking on the parameters to Start() has been moved into this \r | |
742 | common boot service. It is legal to call Start() from other locations, \r | |
743 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
744 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
745 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
746 | EFI_DEVICE_PATH_PROTOCOL.\r | |
747 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
748 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r | |
749 | \r | |
750 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
751 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
752 | must support a protocol interface that supplies \r | |
753 | an I/O abstraction to the driver.\r | |
754 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
755 | parameter is ignored by device drivers, and is optional for bus \r | |
756 | drivers. For a bus driver, if this parameter is NULL, then handles \r | |
757 | for all the children of Controller are created by this driver. \r | |
758 | If this parameter is not NULL and the first Device Path Node is \r | |
759 | not the End of Device Path Node, then only the handle for the \r | |
760 | child device specified by the first Device Path Node of \r | |
761 | RemainingDevicePath is created by this driver.\r | |
762 | If the first Device Path Node of RemainingDevicePath is \r | |
763 | the End of Device Path Node, no child handle is created by this\r | |
764 | driver.\r | |
765 | \r | |
766 | @retval EFI_SUCCESS The device was started.\r | |
767 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
768 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
769 | @retval Others The driver failded to start the device.\r | |
770 | \r | |
771 | **/\r | |
772 | EFI_STATUS\r | |
773 | EFIAPI\r | |
774 | HttpBootIp6DxeDriverBindingStart (\r | |
775 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
776 | IN EFI_HANDLE ControllerHandle,\r | |
777 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
778 | )\r | |
779 | {\r | |
780 | EFI_STATUS Status;\r | |
781 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
782 | EFI_DEV_PATH *Node;\r | |
783 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
784 | UINT32 *Id;\r | |
785 | \r | |
786 | Status = gBS->OpenProtocol (\r | |
787 | ControllerHandle,\r | |
788 | &gEfiCallerIdGuid,\r | |
789 | (VOID **) &Id,\r | |
790 | This->DriverBindingHandle,\r | |
791 | ControllerHandle,\r | |
792 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
793 | );\r | |
794 | \r | |
795 | if (!EFI_ERROR (Status)) {\r | |
75372581 | 796 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);\r |
b659408b ZL |
797 | } else {\r |
798 | //\r | |
799 | // Initialize the private data structure.\r | |
800 | //\r | |
801 | Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));\r | |
802 | if (Private == NULL) {\r | |
803 | return EFI_OUT_OF_RESOURCES;\r | |
804 | }\r | |
805 | Private->Signature = HTTP_BOOT_PRIVATE_DATA_SIGNATURE;\r | |
806 | Private->Controller = ControllerHandle;\r | |
b659408b ZL |
807 | InitializeListHead (&Private->CacheList);\r |
808 | //\r | |
809 | // Get the NII interface if it exists, it's not required.\r | |
810 | //\r | |
811 | Status = gBS->OpenProtocol (\r | |
812 | ControllerHandle,\r | |
813 | &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r | |
814 | (VOID **) &Private->Nii,\r | |
815 | This->DriverBindingHandle,\r | |
816 | ControllerHandle,\r | |
817 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
818 | );\r | |
819 | if (EFI_ERROR (Status)) {\r | |
820 | Private->Nii = NULL;\r | |
821 | }\r | |
822 | \r | |
823 | //\r | |
824 | // Open Device Path Protocol to prepare for appending IP and URI node.\r | |
825 | //\r | |
826 | Status = gBS->OpenProtocol (\r | |
827 | ControllerHandle,\r | |
828 | &gEfiDevicePathProtocolGuid,\r | |
829 | (VOID **) &Private->ParentDevicePath,\r | |
830 | This->DriverBindingHandle,\r | |
831 | ControllerHandle,\r | |
832 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
833 | );\r | |
834 | if (EFI_ERROR (Status)) {\r | |
835 | goto ON_ERROR;\r | |
836 | }\r | |
837 | \r | |
fa848a40 FS |
838 | //\r |
839 | // Initialize the HII configuration form.\r | |
840 | //\r | |
841 | Status = HttpBootConfigFormInit (Private);\r | |
842 | if (EFI_ERROR (Status)) {\r | |
843 | goto ON_ERROR;\r | |
844 | }\r | |
845 | \r | |
b659408b ZL |
846 | //\r |
847 | // Install a protocol with Caller Id Guid to the NIC, this is just to build the relationship between\r | |
848 | // NIC handle and the private data.\r | |
849 | //\r | |
850 | Status = gBS->InstallProtocolInterface (\r | |
851 | &ControllerHandle,\r | |
852 | &gEfiCallerIdGuid,\r | |
853 | EFI_NATIVE_INTERFACE,\r | |
854 | &Private->Id\r | |
855 | );\r | |
856 | if (EFI_ERROR (Status)) {\r | |
857 | goto ON_ERROR;\r | |
858 | }\r | |
859 | \r | |
860 | }\r | |
861 | \r | |
862 | if (Private->Ip6Nic != NULL) {\r | |
863 | //\r | |
864 | // Already created before\r | |
865 | //\r | |
866 | return EFI_SUCCESS;\r | |
867 | }\r | |
868 | \r | |
869 | Private->Ip6Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));\r | |
870 | if (Private->Ip6Nic == NULL) {\r | |
871 | return EFI_OUT_OF_RESOURCES;\r | |
872 | }\r | |
75372581 FS |
873 | Private->Ip6Nic->Private = Private;\r |
874 | Private->Ip6Nic->ImageHandle = This->DriverBindingHandle;\r | |
875 | Private->Ip6Nic->Signature = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;\r | |
876 | \r | |
b659408b ZL |
877 | //\r |
878 | // Create Dhcp6 child and open Dhcp6 protocol\r | |
879 | Status = NetLibCreateServiceChild (\r | |
880 | ControllerHandle,\r | |
881 | This->DriverBindingHandle,\r | |
882 | &gEfiDhcp6ServiceBindingProtocolGuid,\r | |
883 | &Private->Dhcp6Child\r | |
884 | );\r | |
885 | if (EFI_ERROR (Status)) {\r | |
886 | goto ON_ERROR;\r | |
887 | }\r | |
888 | \r | |
889 | Status = gBS->OpenProtocol (\r | |
890 | Private->Dhcp6Child,\r | |
891 | &gEfiDhcp6ProtocolGuid,\r | |
892 | (VOID **) &Private->Dhcp6,\r | |
893 | This->DriverBindingHandle,\r | |
894 | ControllerHandle,\r | |
895 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
896 | );\r | |
897 | if (EFI_ERROR (Status)) {\r | |
898 | goto ON_ERROR;\r | |
899 | }\r | |
900 | \r | |
901 | //\r | |
902 | // Create Ip6 child and open Ip6 protocol for background ICMP packets.\r | |
903 | //\r | |
904 | Status = NetLibCreateServiceChild (\r | |
905 | ControllerHandle,\r | |
906 | This->DriverBindingHandle,\r | |
907 | &gEfiIp6ServiceBindingProtocolGuid,\r | |
908 | &Private->Ip6Child\r | |
909 | );\r | |
910 | if (EFI_ERROR (Status)) {\r | |
911 | goto ON_ERROR;\r | |
912 | }\r | |
913 | \r | |
914 | Status = gBS->OpenProtocol (\r | |
915 | Private->Ip6Child,\r | |
916 | &gEfiIp6ProtocolGuid,\r | |
917 | (VOID **) &Private->Ip6,\r | |
918 | This->DriverBindingHandle,\r | |
919 | ControllerHandle,\r | |
920 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
921 | );\r | |
922 | if (EFI_ERROR (Status)) {\r | |
923 | goto ON_ERROR;\r | |
924 | }\r | |
925 | \r | |
926 | //\r | |
927 | // Locate Ip6Config protocol, it's required to configure the default gateway address.\r | |
928 | //\r | |
929 | Status = gBS->OpenProtocol (\r | |
930 | ControllerHandle,\r | |
931 | &gEfiIp6ConfigProtocolGuid,\r | |
932 | (VOID **) &Private->Ip6Config,\r | |
933 | This->DriverBindingHandle,\r | |
934 | ControllerHandle,\r | |
935 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
936 | );\r | |
937 | if (EFI_ERROR (Status)) {\r | |
938 | goto ON_ERROR;\r | |
939 | }\r | |
940 | \r | |
941 | //\r | |
942 | // Append IPv6 device path node.\r | |
943 | //\r | |
944 | Node = AllocateZeroPool (sizeof (IPv6_DEVICE_PATH));\r | |
945 | if (Node == NULL) {\r | |
946 | Status = EFI_OUT_OF_RESOURCES;\r | |
947 | goto ON_ERROR;\r | |
948 | }\r | |
949 | Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;\r | |
950 | Node->Ipv6.Header.SubType = MSG_IPv6_DP;\r | |
951 | Node->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;\r | |
952 | SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));\r | |
953 | DevicePath = AppendDevicePathNode(Private->ParentDevicePath, (EFI_DEVICE_PATH*) Node);\r | |
954 | FreePool(Node);\r | |
955 | if (DevicePath == NULL) {\r | |
956 | Status = EFI_OUT_OF_RESOURCES;\r | |
957 | goto ON_ERROR;\r | |
958 | }\r | |
959 | \r | |
960 | //\r | |
961 | // Append URI device path node.\r | |
962 | //\r | |
963 | Node = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
964 | if (Node == NULL) {\r | |
965 | Status = EFI_OUT_OF_RESOURCES;\r | |
966 | goto ON_ERROR;\r | |
967 | }\r | |
968 | Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r | |
969 | Node->DevPath.SubType = MSG_URI_DP;\r | |
970 | SetDevicePathNodeLength (Node, sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
971 | Private->Ip6Nic->DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);\r | |
972 | FreePool (Node);\r | |
973 | FreePool (DevicePath);\r | |
974 | if (Private->Ip6Nic->DevicePath == NULL) {\r | |
975 | Status = EFI_OUT_OF_RESOURCES;\r | |
976 | goto ON_ERROR;\r | |
977 | }\r | |
978 | \r | |
979 | //\r | |
980 | // Create a child handle for the HTTP boot and install DevPath and Load file protocol on it.\r | |
981 | //\r | |
982 | CopyMem (&Private->Ip6Nic->LoadFile, &gHttpBootDxeLoadFile, sizeof (Private->LoadFile));\r | |
983 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
984 | &Private->Ip6Nic->Controller,\r | |
985 | &gEfiLoadFileProtocolGuid,\r | |
986 | &Private->Ip6Nic->LoadFile,\r | |
987 | &gEfiDevicePathProtocolGuid,\r | |
988 | Private->Ip6Nic->DevicePath,\r | |
989 | NULL\r | |
990 | );\r | |
991 | if (EFI_ERROR (Status)) {\r | |
992 | goto ON_ERROR;\r | |
993 | }\r | |
994 | \r | |
995 | //\r | |
996 | // Open the Caller Id child to setup a parent-child relationship between\r | |
997 | // real NIC handle and the HTTP boot child handle.\r | |
998 | //\r | |
999 | Status = gBS->OpenProtocol (\r | |
1000 | ControllerHandle,\r | |
1001 | &gEfiCallerIdGuid,\r | |
1002 | (VOID **) &Id,\r | |
1003 | This->DriverBindingHandle,\r | |
1004 | Private->Ip6Nic->Controller,\r | |
1005 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
1006 | );\r | |
1007 | if (EFI_ERROR (Status)) {\r | |
1008 | goto ON_ERROR;\r | |
1009 | }\r | |
1010 | \r | |
1011 | return EFI_SUCCESS;\r | |
1012 | \r | |
1013 | ON_ERROR:\r | |
b659408b | 1014 | \r |
fa848a40 FS |
1015 | HttpBootDestroyIp6Children(This, Private);\r |
1016 | HttpBootConfigFormUnload (Private);\r | |
1017 | FreePool (Private);\r | |
1018 | \r | |
1019 | return Status;\r | |
b659408b ZL |
1020 | }\r |
1021 | \r | |
1022 | /**\r | |
1023 | Stops a device controller or a bus controller.\r | |
1024 | \r | |
1025 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
1026 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
1027 | into this common boot service. It is legal to call Stop() from other locations, \r | |
1028 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
1029 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
1030 | same driver's Start() function.\r | |
1031 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
1032 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
1033 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
1034 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
1035 | \r | |
1036 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
1037 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
1038 | support a bus specific I/O protocol for the driver \r | |
1039 | to use to stop the device.\r | |
1040 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
1041 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
1042 | if NumberOfChildren is 0.\r | |
1043 | \r | |
1044 | @retval EFI_SUCCESS The device was stopped.\r | |
1045 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
1046 | \r | |
1047 | **/\r | |
1048 | EFI_STATUS\r | |
1049 | EFIAPI\r | |
1050 | HttpBootIp6DxeDriverBindingStop (\r | |
1051 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
1052 | IN EFI_HANDLE ControllerHandle,\r | |
1053 | IN UINTN NumberOfChildren,\r | |
1054 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
1055 | )\r | |
1056 | {\r | |
1057 | EFI_STATUS Status;\r | |
1058 | EFI_LOAD_FILE_PROTOCOL *LoadFile;\r | |
1059 | HTTP_BOOT_PRIVATE_DATA *Private;\r | |
1060 | EFI_HANDLE NicHandle;\r | |
1061 | UINT32 *Id;\r | |
1062 | \r | |
1063 | //\r | |
1064 | // Try to get the Load File Protocol from the controller handle.\r | |
1065 | //\r | |
1066 | Status = gBS->OpenProtocol (\r | |
1067 | ControllerHandle,\r | |
1068 | &gEfiLoadFileProtocolGuid,\r | |
1069 | (VOID **) &LoadFile,\r | |
1070 | This->DriverBindingHandle,\r | |
1071 | ControllerHandle,\r | |
1072 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1073 | );\r | |
1074 | if (EFI_ERROR (Status)) {\r | |
1075 | //\r | |
1076 | // If failed, try to find the NIC handle for this controller.\r | |
1077 | //\r | |
1078 | NicHandle = HttpBootGetNicByIp6Children (ControllerHandle);\r | |
1079 | if (NicHandle == NULL) {\r | |
1080 | return EFI_SUCCESS;\r | |
1081 | }\r | |
1082 | \r | |
1083 | //\r | |
1084 | // Try to retrieve the private data by the Caller Id Guid.\r | |
1085 | //\r | |
1086 | Status = gBS->OpenProtocol (\r | |
1087 | NicHandle,\r | |
1088 | &gEfiCallerIdGuid,\r | |
1089 | (VOID **) &Id,\r | |
1090 | This->DriverBindingHandle,\r | |
1091 | ControllerHandle,\r | |
1092 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
1093 | );\r | |
1094 | if (EFI_ERROR (Status)) {\r | |
1095 | return Status;\r | |
1096 | }\r | |
1097 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID (Id);\r | |
1098 | } else {\r | |
1099 | Private = HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE (LoadFile);\r | |
1100 | NicHandle = Private->Controller;\r | |
1101 | }\r | |
1102 | \r | |
1103 | //\r | |
1104 | // Disable the HTTP boot function.\r | |
1105 | //\r | |
1106 | Status = HttpBootStop (Private);\r | |
1107 | if (Status != EFI_SUCCESS && Status != EFI_NOT_STARTED) {\r | |
1108 | return Status;\r | |
1109 | }\r | |
1110 | \r | |
1111 | //\r | |
1112 | // Destory all child instance and uninstall protocol interface.\r | |
1113 | //\r | |
1114 | HttpBootDestroyIp6Children (This, Private);\r | |
1115 | \r | |
1116 | if (Private->Ip4Nic == NULL && Private->Ip6Nic == NULL) {\r | |
1117 | //\r | |
1118 | // Release the cached data.\r | |
1119 | //\r | |
1120 | HttpBootFreeCacheList (Private);\r | |
fa848a40 FS |
1121 | \r |
1122 | //\r | |
1123 | // Unload the config form.\r | |
1124 | //\r | |
1125 | HttpBootConfigFormUnload (Private);\r | |
1126 | \r | |
b659408b ZL |
1127 | gBS->UninstallProtocolInterface (\r |
1128 | NicHandle,\r | |
1129 | &gEfiCallerIdGuid,\r | |
1130 | &Private->Id\r | |
1131 | );\r | |
1132 | FreePool (Private);\r | |
1133 | \r | |
1134 | }\r | |
1135 | \r | |
1136 | return EFI_SUCCESS;\r | |
1137 | }\r | |
1138 | /**\r | |
1139 | This is the declaration of an EFI image entry point. This entry point is\r | |
1140 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
1141 | both device drivers and bus drivers.\r | |
1142 | \r | |
1143 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r | |
1144 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1145 | \r | |
1146 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1147 | @retval Others An unexpected error occurred.\r | |
1148 | \r | |
1149 | **/\r | |
1150 | EFI_STATUS\r | |
1151 | EFIAPI\r | |
1152 | HttpBootDxeDriverEntryPoint (\r | |
1153 | IN EFI_HANDLE ImageHandle,\r | |
1154 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1155 | )\r | |
1156 | {\r | |
1157 | EFI_STATUS Status;\r | |
fa848a40 | 1158 | \r |
b659408b ZL |
1159 | //\r |
1160 | // Install UEFI Driver Model protocol(s).\r | |
1161 | //\r | |
1162 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1163 | ImageHandle,\r | |
1164 | SystemTable,\r | |
1165 | &gHttpBootIp4DxeDriverBinding,\r | |
1166 | ImageHandle,\r | |
1167 | &gHttpBootDxeComponentName,\r | |
1168 | &gHttpBootDxeComponentName2\r | |
1169 | );\r | |
1170 | if (EFI_ERROR (Status)) {\r | |
1171 | return Status;\r | |
1172 | }\r | |
1173 | \r | |
1174 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1175 | ImageHandle,\r | |
1176 | SystemTable,\r | |
1177 | &gHttpBootIp6DxeDriverBinding,\r | |
1178 | NULL,\r | |
1179 | &gHttpBootDxeComponentName,\r | |
1180 | &gHttpBootDxeComponentName2\r | |
1181 | );\r | |
1182 | if (EFI_ERROR (Status)) {\r | |
1183 | gBS->UninstallMultipleProtocolInterfaces(\r | |
1184 | ImageHandle,\r | |
1185 | &gEfiDriverBindingProtocolGuid,\r | |
1186 | &gHttpBootIp4DxeDriverBinding,\r | |
1187 | &gEfiComponentName2ProtocolGuid,\r | |
1188 | &gHttpBootDxeComponentName2,\r | |
1189 | &gEfiComponentNameProtocolGuid,\r | |
1190 | &gHttpBootDxeComponentName,\r | |
1191 | NULL\r | |
1192 | );\r | |
1193 | }\r | |
1194 | return Status;\r | |
d933e70a JW |
1195 | }\r |
1196 | \r |