2 UEFI HTTP boot driver's private data structure and interfaces declaration.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef __EFI_HTTP_BOOT_DXE_H__
17 #define __EFI_HTTP_BOOT_DXE_H__
21 #include <IndustryStandard/Http11.h>
26 #include <Library/UefiBootServicesTableLib.h>
27 #include <Library/UefiHiiServicesLib.h>
28 #include <Library/UefiRuntimeServicesTableLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/DevicePathLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/NetLib.h>
35 #include <Library/HttpLib.h>
36 #include <Library/HiiLib.h>
37 #include <Library/PrintLib.h>
40 // UEFI Driver Model Protocols
42 #include <Protocol/DriverBinding.h>
43 #include <Protocol/ComponentName2.h>
44 #include <Protocol/ComponentName.h>
49 #include <Protocol/ServiceBinding.h>
50 #include <Protocol/HiiConfigAccess.h>
51 #include <Protocol/NetworkInterfaceIdentifier.h>
52 #include <Protocol/Dhcp4.h>
53 #include <Protocol/Dhcp6.h>
54 #include <Protocol/Dns6.h>
55 #include <Protocol/Http.h>
56 #include <Protocol/Ip4Config2.h>
57 #include <Protocol/Ip6Config.h>
58 #include <Protocol/RamDisk.h>
62 #include <Protocol/LoadFile.h>
67 #include <Guid/HttpBootConfigHii.h>
72 #define HTTP_BOOT_DXE_VERSION 0xa
75 // Provisional Standard Media Types defined in
76 // http://www.iana.org/assignments/provisional-standard-media-types/provisional-standard-media-types.xhtml
78 #define HTTP_CONTENT_TYPE_APP_EFI "application/efi"
83 extern EFI_DRIVER_BINDING_PROTOCOL gHttpBootDxeDriverBinding
;
84 extern EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2
;
85 extern EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName
;
88 // Private data structure
90 typedef struct _HTTP_BOOT_PRIVATE_DATA HTTP_BOOT_PRIVATE_DATA
;
91 typedef struct _HTTP_BOOT_VIRTUAL_NIC HTTP_BOOT_VIRTUAL_NIC
;
98 } HTTP_BOOT_IMAGE_TYPE
;
101 // Include files with internal function prototypes
103 #include "HttpBootComponentName.h"
104 #include "HttpBootDhcp4.h"
105 #include "HttpBootDhcp6.h"
106 #include "HttpBootImpl.h"
107 #include "HttpBootSupport.h"
108 #include "HttpBootClient.h"
109 #include "HttpBootConfig.h"
112 HTTP_BOOT_DHCP4_PACKET_CACHE Dhcp4
;
113 HTTP_BOOT_DHCP6_PACKET_CACHE Dhcp6
;
114 } HTTP_BOOT_DHCP_PACKET_CACHE
;
116 struct _HTTP_BOOT_VIRTUAL_NIC
{
118 EFI_HANDLE Controller
;
119 EFI_HANDLE ImageHandle
;
120 EFI_LOAD_FILE_PROTOCOL LoadFile
;
121 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
122 HTTP_BOOT_PRIVATE_DATA
*Private
;
125 #define HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_INFO(Callback) \
128 HTTP_BOOT_PRIVATE_DATA, \
130 HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
133 struct _HTTP_BOOT_PRIVATE_DATA
{
135 EFI_HANDLE Controller
;
137 HTTP_BOOT_VIRTUAL_NIC
*Ip4Nic
;
138 HTTP_BOOT_VIRTUAL_NIC
*Ip6Nic
;
144 EFI_HANDLE Dhcp4Child
;
145 EFI_HANDLE Dhcp6Child
;
152 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL
*Nii
;
153 EFI_IP6_PROTOCOL
*Ip6
;
154 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Config2
;
155 EFI_IP6_CONFIG_PROTOCOL
*Ip6Config
;
156 EFI_DHCP4_PROTOCOL
*Dhcp4
;
157 EFI_DHCP6_PROTOCOL
*Dhcp6
;
158 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
164 EFI_LOAD_FILE_PROTOCOL LoadFile
;
165 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
169 // HII callback info block
171 HTTP_BOOT_FORM_CALLBACK_INFO CallbackInfo
;
178 EFI_IP_ADDRESS StationIp
;
179 EFI_IP_ADDRESS SubnetMask
;
180 EFI_IP_ADDRESS GatewayIp
;
181 EFI_IP_ADDRESS ServerIp
;
185 // The URI string attempt to download through HTTP, may point to
186 // the memory in cached DHCP offer, or to the memory in FilePathUri.
189 VOID
*BootFileUriParser
;
194 // URI string extracted from the input FilePath parameter.
197 VOID
*FilePathUriParser
;
202 LIST_ENTRY CacheList
;
207 // OfferIndex records the index of DhcpOffer[] buffer, and OfferCount records the num of each type of offer.
212 // OfferBuffer: [ProxyNameUri, DhcpNameUri, DhcpIpUri, ProxyNameUri, ProxyIpUri, DhcpOnly, DhcpIpUri, DhcpNameUriDns]
213 // (OfferBuffer is 0-based.)
215 // And assume that (DhcpIpUri is the first priority actually.)
218 // SelectProxyType: HttpOfferTypeProxyIpUri
219 // (SelectIndex is 1-based, and 0 means no one is selected.)
223 // DhcpIpUri DhcpNameUriDns DhcpDns DhcpOnly ProxyNameUri ProxyIpUri DhcpNameUri
224 // OfferCount: [ 2, 1, 0, 1, 2, 1, 1]
226 // OfferIndex: {[ 2, 7, 0, 5, 0, *4, 1]
227 // [ 6, 0, 0, 0, 3, 0, 0]
228 // [ 0, 0, 0, 0, 0, 0, 0]
230 // (OfferIndex is 0-based.)
234 UINT32 SelectProxyType
;
235 HTTP_BOOT_DHCP_PACKET_CACHE OfferBuffer
[HTTP_BOOT_OFFER_MAX_NUM
];
237 UINT32 OfferCount
[HttpOfferTypeMax
];
238 UINT32 OfferIndex
[HttpOfferTypeMax
][HTTP_BOOT_OFFER_MAX_NUM
];
241 #define HTTP_BOOT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('H', 'B', 'P', 'D')
242 #define HTTP_BOOT_VIRTUAL_NIC_SIGNATURE SIGNATURE_32 ('H', 'B', 'V', 'N')
243 #define HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, HTTP_BOOT_PRIVATE_DATA, LoadFile, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
244 #define HTTP_BOOT_PRIVATE_DATA_FROM_ID(a) CR (a, HTTP_BOOT_PRIVATE_DATA, Id, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
245 #define HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE(a) CR (a, HTTP_BOOT_VIRTUAL_NIC, LoadFile, HTTP_BOOT_VIRTUAL_NIC_SIGNATURE)
246 extern EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile
;
249 Tests to see if this driver supports a given controller. If a child device is provided,
250 it further tests to see if this driver supports creating a handle for the specified child device.
252 This function checks to see if the driver specified by This supports the device specified by
253 ControllerHandle. Drivers will typically use the device path attached to
254 ControllerHandle and/or the services from the bus I/O abstraction attached to
255 ControllerHandle to determine if the driver supports ControllerHandle. This function
256 may be called many times during platform initialization. In order to reduce boot times, the tests
257 performed by this function must be very small, and take as little time as possible to execute. This
258 function must not change the state of any hardware devices, and this function must be aware that the
259 device specified by ControllerHandle may already be managed by the same driver or a
260 different driver. This function must match its calls to AllocatePages() with FreePages(),
261 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
262 Because ControllerHandle may have been previously started by the same driver, if a protocol is
263 already in the opened state, then it must not be closed with CloseProtocol(). This is required
264 to guarantee the state of ControllerHandle is not modified by this function.
266 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
267 @param[in] ControllerHandle The handle of the controller to test. This handle
268 must support a protocol interface that supplies
269 an I/O abstraction to the driver.
270 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
271 parameter is ignored by device drivers, and is optional for bus
272 drivers. For bus drivers, if this parameter is not NULL, then
273 the bus driver must determine if the bus controller specified
274 by ControllerHandle and the child controller specified
275 by RemainingDevicePath are both supported by this
278 @retval EFI_SUCCESS The device specified by ControllerHandle and
279 RemainingDevicePath is supported by the driver specified by This.
280 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
281 RemainingDevicePath is already being managed by the driver
283 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
284 RemainingDevicePath is already being managed by a different
285 driver or an application that requires exclusive access.
286 Currently not implemented.
287 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
288 RemainingDevicePath is not supported by the driver specified by This.
292 HttpBootIp4DxeDriverBindingSupported (
293 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
294 IN EFI_HANDLE ControllerHandle
,
295 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
299 Starts a device controller or a bus controller.
301 The Start() function is designed to be invoked from the EFI boot service ConnectController().
302 As a result, much of the error checking on the parameters to Start() has been moved into this
303 common boot service. It is legal to call Start() from other locations,
304 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
305 1. ControllerHandle must be a valid EFI_HANDLE.
306 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
307 EFI_DEVICE_PATH_PROTOCOL.
308 3. Prior to calling Start(), the Supported() function for the driver specified by This must
309 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
311 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
312 @param[in] ControllerHandle The handle of the controller to start. This handle
313 must support a protocol interface that supplies
314 an I/O abstraction to the driver.
315 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
316 parameter is ignored by device drivers, and is optional for bus
317 drivers. For a bus driver, if this parameter is NULL, then handles
318 for all the children of Controller are created by this driver.
319 If this parameter is not NULL and the first Device Path Node is
320 not the End of Device Path Node, then only the handle for the
321 child device specified by the first Device Path Node of
322 RemainingDevicePath is created by this driver.
323 If the first Device Path Node of RemainingDevicePath is
324 the End of Device Path Node, no child handle is created by this
327 @retval EFI_SUCCESS The device was started.
328 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
329 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
330 @retval Others The driver failded to start the device.
335 HttpBootIp4DxeDriverBindingStart (
336 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
337 IN EFI_HANDLE ControllerHandle
,
338 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
342 Stops a device controller or a bus controller.
344 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
345 As a result, much of the error checking on the parameters to Stop() has been moved
346 into this common boot service. It is legal to call Stop() from other locations,
347 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
348 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
349 same driver's Start() function.
350 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
351 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
352 Start() function, and the Start() function must have called OpenProtocol() on
353 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
355 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
356 @param[in] ControllerHandle A handle to the device being stopped. The handle must
357 support a bus specific I/O protocol for the driver
358 to use to stop the device.
359 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
360 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
361 if NumberOfChildren is 0.
363 @retval EFI_SUCCESS The device was stopped.
364 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
369 HttpBootIp4DxeDriverBindingStop (
370 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
371 IN EFI_HANDLE ControllerHandle
,
372 IN UINTN NumberOfChildren
,
373 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
377 Tests to see if this driver supports a given controller. If a child device is provided,
378 it further tests to see if this driver supports creating a handle for the specified child device.
380 This function checks to see if the driver specified by This supports the device specified by
381 ControllerHandle. Drivers will typically use the device path attached to
382 ControllerHandle and/or the services from the bus I/O abstraction attached to
383 ControllerHandle to determine if the driver supports ControllerHandle. This function
384 may be called many times during platform initialization. In order to reduce boot times, the tests
385 performed by this function must be very small, and take as little time as possible to execute. This
386 function must not change the state of any hardware devices, and this function must be aware that the
387 device specified by ControllerHandle may already be managed by the same driver or a
388 different driver. This function must match its calls to AllocatePages() with FreePages(),
389 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
390 Because ControllerHandle may have been previously started by the same driver, if a protocol is
391 already in the opened state, then it must not be closed with CloseProtocol(). This is required
392 to guarantee the state of ControllerHandle is not modified by this function.
394 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
395 @param[in] ControllerHandle The handle of the controller to test. This handle
396 must support a protocol interface that supplies
397 an I/O abstraction to the driver.
398 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
399 parameter is ignored by device drivers, and is optional for bus
400 drivers. For bus drivers, if this parameter is not NULL, then
401 the bus driver must determine if the bus controller specified
402 by ControllerHandle and the child controller specified
403 by RemainingDevicePath are both supported by this
406 @retval EFI_SUCCESS The device specified by ControllerHandle and
407 RemainingDevicePath is supported by the driver specified by This.
408 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
409 RemainingDevicePath is already being managed by the driver
411 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
412 RemainingDevicePath is already being managed by a different
413 driver or an application that requires exclusive access.
414 Currently not implemented.
415 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
416 RemainingDevicePath is not supported by the driver specified by This.
420 HttpBootIp6DxeDriverBindingSupported (
421 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
422 IN EFI_HANDLE ControllerHandle
,
423 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
427 Starts a device controller or a bus controller.
429 The Start() function is designed to be invoked from the EFI boot service ConnectController().
430 As a result, much of the error checking on the parameters to Start() has been moved into this
431 common boot service. It is legal to call Start() from other locations,
432 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
433 1. ControllerHandle must be a valid EFI_HANDLE.
434 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
435 EFI_DEVICE_PATH_PROTOCOL.
436 3. Prior to calling Start(), the Supported() function for the driver specified by This must
437 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
439 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
440 @param[in] ControllerHandle The handle of the controller to start. This handle
441 must support a protocol interface that supplies
442 an I/O abstraction to the driver.
443 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
444 parameter is ignored by device drivers, and is optional for bus
445 drivers. For a bus driver, if this parameter is NULL, then handles
446 for all the children of Controller are created by this driver.
447 If this parameter is not NULL and the first Device Path Node is
448 not the End of Device Path Node, then only the handle for the
449 child device specified by the first Device Path Node of
450 RemainingDevicePath is created by this driver.
451 If the first Device Path Node of RemainingDevicePath is
452 the End of Device Path Node, no child handle is created by this
455 @retval EFI_SUCCESS The device was started.
456 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
457 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
458 @retval Others The driver failded to start the device.
463 HttpBootIp6DxeDriverBindingStart (
464 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
465 IN EFI_HANDLE ControllerHandle
,
466 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
470 Stops a device controller or a bus controller.
472 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
473 As a result, much of the error checking on the parameters to Stop() has been moved
474 into this common boot service. It is legal to call Stop() from other locations,
475 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
476 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
477 same driver's Start() function.
478 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
479 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
480 Start() function, and the Start() function must have called OpenProtocol() on
481 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
483 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
484 @param[in] ControllerHandle A handle to the device being stopped. The handle must
485 support a bus specific I/O protocol for the driver
486 to use to stop the device.
487 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
488 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
489 if NumberOfChildren is 0.
491 @retval EFI_SUCCESS The device was stopped.
492 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
497 HttpBootIp6DxeDriverBindingStop (
498 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
499 IN EFI_HANDLE ControllerHandle
,
500 IN UINTN NumberOfChildren
,
501 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL