]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpBootDxe/HttpBootDxe.h
a1e67925145e8128ebef5e741bceffff6b2ff1a2
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootDxe.h
1 /** @file
2 UEFI HTTP boot driver's private data structure and interfaces declaration.
3
4 Copyright (c) 2015 - 2017, 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.
10
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.
13
14 **/
15
16 #ifndef __EFI_HTTP_BOOT_DXE_H__
17 #define __EFI_HTTP_BOOT_DXE_H__
18
19 #include <Uefi.h>
20
21 #include <IndustryStandard/Http11.h>
22 #include <IndustryStandard/Dhcp.h>
23
24 //
25 // Libraries
26 //
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiHiiServicesLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/NetLib.h>
36 #include <Library/HttpLib.h>
37 #include <Library/HiiLib.h>
38 #include <Library/PrintLib.h>
39 #include <Library/DpcLib.h>
40
41 //
42 // UEFI Driver Model Protocols
43 //
44 #include <Protocol/DriverBinding.h>
45 #include <Protocol/ComponentName2.h>
46 #include <Protocol/ComponentName.h>
47
48 //
49 // Consumed Protocols
50 //
51 #include <Protocol/ServiceBinding.h>
52 #include <Protocol/HiiConfigAccess.h>
53 #include <Protocol/NetworkInterfaceIdentifier.h>
54 #include <Protocol/Dhcp4.h>
55 #include <Protocol/Dhcp6.h>
56 #include <Protocol/Dns6.h>
57 #include <Protocol/Http.h>
58 #include <Protocol/Ip4Config2.h>
59 #include <Protocol/Ip6Config.h>
60 #include <Protocol/RamDisk.h>
61 //
62 // Produced Protocols
63 //
64 #include <Protocol/LoadFile.h>
65
66 //
67 // Consumed Guids
68 //
69 #include <Guid/HttpBootConfigHii.h>
70
71 //
72 // Driver Version
73 //
74 #define HTTP_BOOT_DXE_VERSION 0xa
75
76 //
77 // Standard Media Types defined in
78 // http://www.iana.org/assignments/media-types
79 //
80 #define HTTP_CONTENT_TYPE_APP_EFI "application/efi"
81 #define HTTP_CONTENT_TYPE_APP_IMG "application/vnd.efi-img"
82 #define HTTP_CONTENT_TYPE_APP_ISO "application/vnd.efi-iso"
83
84 //
85 // Protocol instances
86 //
87 extern EFI_DRIVER_BINDING_PROTOCOL gHttpBootDxeDriverBinding;
88 extern EFI_COMPONENT_NAME2_PROTOCOL gHttpBootDxeComponentName2;
89 extern EFI_COMPONENT_NAME_PROTOCOL gHttpBootDxeComponentName;
90
91 //
92 // Private data structure
93 //
94 typedef struct _HTTP_BOOT_PRIVATE_DATA HTTP_BOOT_PRIVATE_DATA;
95 typedef struct _HTTP_BOOT_VIRTUAL_NIC HTTP_BOOT_VIRTUAL_NIC;
96
97 typedef enum {
98 ImageTypeEfi,
99 ImageTypeVirtualCd,
100 ImageTypeVirtualDisk,
101 ImageTypeMax
102 } HTTP_BOOT_IMAGE_TYPE;
103
104 //
105 // Include files with internal function prototypes
106 //
107 #include "HttpBootComponentName.h"
108 #include "HttpBootDhcp4.h"
109 #include "HttpBootDhcp6.h"
110 #include "HttpBootImpl.h"
111 #include "HttpBootSupport.h"
112 #include "HttpBootClient.h"
113 #include "HttpBootConfig.h"
114
115 typedef union {
116 HTTP_BOOT_DHCP4_PACKET_CACHE Dhcp4;
117 HTTP_BOOT_DHCP6_PACKET_CACHE Dhcp6;
118 } HTTP_BOOT_DHCP_PACKET_CACHE;
119
120 struct _HTTP_BOOT_VIRTUAL_NIC {
121 UINT32 Signature;
122 EFI_HANDLE Controller;
123 EFI_HANDLE ImageHandle;
124 EFI_LOAD_FILE_PROTOCOL LoadFile;
125 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
126 HTTP_BOOT_PRIVATE_DATA *Private;
127 };
128
129 #define HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_INFO(Callback) \
130 CR ( \
131 Callback, \
132 HTTP_BOOT_PRIVATE_DATA, \
133 CallbackInfo, \
134 HTTP_BOOT_PRIVATE_DATA_SIGNATURE \
135 )
136
137 struct _HTTP_BOOT_PRIVATE_DATA {
138 UINT32 Signature;
139 EFI_HANDLE Controller;
140
141 HTTP_BOOT_VIRTUAL_NIC *Ip4Nic;
142 HTTP_BOOT_VIRTUAL_NIC *Ip6Nic;
143
144 //
145 // Cousumed children
146 //
147 EFI_HANDLE Ip6Child;
148 EFI_HANDLE Dhcp4Child;
149 EFI_HANDLE Dhcp6Child;
150 HTTP_IO HttpIo;
151 BOOLEAN HttpCreated;
152
153 //
154 // Consumed protocol
155 //
156 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
157 EFI_IP6_PROTOCOL *Ip6;
158 EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2;
159 EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
160 EFI_DHCP4_PROTOCOL *Dhcp4;
161 EFI_DHCP6_PROTOCOL *Dhcp6;
162 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
163
164
165 //
166 // Produced protocol
167 //
168 EFI_LOAD_FILE_PROTOCOL LoadFile;
169 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
170 UINT32 Id;
171
172 //
173 // HII callback info block
174 //
175 HTTP_BOOT_FORM_CALLBACK_INFO CallbackInfo;
176
177 //
178 // Mode data
179 //
180 BOOLEAN UsingIpv6;
181 BOOLEAN Started;
182 EFI_IP_ADDRESS StationIp;
183 EFI_IP_ADDRESS SubnetMask;
184 EFI_IP_ADDRESS GatewayIp;
185 EFI_IP_ADDRESS ServerIp;
186 UINT16 Port;
187
188 //
189 // The URI string attempt to download through HTTP, may point to
190 // the memory in cached DHCP offer, or to the memory in FilePathUri.
191 //
192 CHAR8 *BootFileUri;
193 VOID *BootFileUriParser;
194 UINTN BootFileSize;
195 BOOLEAN NoGateway;
196 HTTP_BOOT_IMAGE_TYPE ImageType;
197
198 //
199 // URI string extracted from the input FilePath parameter.
200 //
201 CHAR8 *FilePathUri;
202 VOID *FilePathUriParser;
203
204 //
205 // Cached HTTP data
206 //
207 LIST_ENTRY CacheList;
208
209 //
210 // Cached DHCP offer
211 //
212 // OfferIndex records the index of DhcpOffer[] buffer, and OfferCount records the num of each type of offer.
213 //
214 // It supposed that
215 //
216 // OfferNum: 8
217 // OfferBuffer: [ProxyNameUri, DhcpNameUri, DhcpIpUri, ProxyNameUri, ProxyIpUri, DhcpOnly, DhcpIpUri, DhcpNameUriDns]
218 // (OfferBuffer is 0-based.)
219 //
220 // And assume that (DhcpIpUri is the first priority actually.)
221 //
222 // SelectIndex: 5
223 // SelectProxyType: HttpOfferTypeProxyIpUri
224 // (SelectIndex is 1-based, and 0 means no one is selected.)
225 //
226 // So it should be
227 //
228 // DhcpIpUri DhcpNameUriDns DhcpDns DhcpOnly ProxyNameUri ProxyIpUri DhcpNameUri
229 // OfferCount: [ 2, 1, 0, 1, 2, 1, 1]
230 //
231 // OfferIndex: {[ 2, 7, 0, 5, 0, *4, 1]
232 // [ 6, 0, 0, 0, 3, 0, 0]
233 // [ 0, 0, 0, 0, 0, 0, 0]
234 // ... ]}
235 // (OfferIndex is 0-based.)
236 //
237 //
238 UINT32 SelectIndex;
239 UINT32 SelectProxyType;
240 HTTP_BOOT_DHCP_PACKET_CACHE OfferBuffer[HTTP_BOOT_OFFER_MAX_NUM];
241 UINT32 OfferNum;
242 UINT32 OfferCount[HttpOfferTypeMax];
243 UINT32 OfferIndex[HttpOfferTypeMax][HTTP_BOOT_OFFER_MAX_NUM];
244 };
245
246 #define HTTP_BOOT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('H', 'B', 'P', 'D')
247 #define HTTP_BOOT_VIRTUAL_NIC_SIGNATURE SIGNATURE_32 ('H', 'B', 'V', 'N')
248 #define HTTP_BOOT_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, HTTP_BOOT_PRIVATE_DATA, LoadFile, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
249 #define HTTP_BOOT_PRIVATE_DATA_FROM_ID(a) CR (a, HTTP_BOOT_PRIVATE_DATA, Id, HTTP_BOOT_PRIVATE_DATA_SIGNATURE)
250 #define HTTP_BOOT_VIRTUAL_NIC_FROM_LOADFILE(a) CR (a, HTTP_BOOT_VIRTUAL_NIC, LoadFile, HTTP_BOOT_VIRTUAL_NIC_SIGNATURE)
251 extern EFI_LOAD_FILE_PROTOCOL gHttpBootDxeLoadFile;
252
253 /**
254 Tests to see if this driver supports a given controller. If a child device is provided,
255 it further tests to see if this driver supports creating a handle for the specified child device.
256
257 This function checks to see if the driver specified by This supports the device specified by
258 ControllerHandle. Drivers will typically use the device path attached to
259 ControllerHandle and/or the services from the bus I/O abstraction attached to
260 ControllerHandle to determine if the driver supports ControllerHandle. This function
261 may be called many times during platform initialization. In order to reduce boot times, the tests
262 performed by this function must be very small, and take as little time as possible to execute. This
263 function must not change the state of any hardware devices, and this function must be aware that the
264 device specified by ControllerHandle may already be managed by the same driver or a
265 different driver. This function must match its calls to AllocatePages() with FreePages(),
266 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
267 Because ControllerHandle may have been previously started by the same driver, if a protocol is
268 already in the opened state, then it must not be closed with CloseProtocol(). This is required
269 to guarantee the state of ControllerHandle is not modified by this function.
270
271 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
272 @param[in] ControllerHandle The handle of the controller to test. This handle
273 must support a protocol interface that supplies
274 an I/O abstraction to the driver.
275 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
276 parameter is ignored by device drivers, and is optional for bus
277 drivers. For bus drivers, if this parameter is not NULL, then
278 the bus driver must determine if the bus controller specified
279 by ControllerHandle and the child controller specified
280 by RemainingDevicePath are both supported by this
281 bus driver.
282
283 @retval EFI_SUCCESS The device specified by ControllerHandle and
284 RemainingDevicePath is supported by the driver specified by This.
285 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
286 RemainingDevicePath is already being managed by the driver
287 specified by This.
288 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
289 RemainingDevicePath is already being managed by a different
290 driver or an application that requires exclusive access.
291 Currently not implemented.
292 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
293 RemainingDevicePath is not supported by the driver specified by This.
294 **/
295 EFI_STATUS
296 EFIAPI
297 HttpBootIp4DxeDriverBindingSupported (
298 IN EFI_DRIVER_BINDING_PROTOCOL *This,
299 IN EFI_HANDLE ControllerHandle,
300 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
301 );
302
303 /**
304 Starts a device controller or a bus controller.
305
306 The Start() function is designed to be invoked from the EFI boot service ConnectController().
307 As a result, much of the error checking on the parameters to Start() has been moved into this
308 common boot service. It is legal to call Start() from other locations,
309 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
310 1. ControllerHandle must be a valid EFI_HANDLE.
311 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
312 EFI_DEVICE_PATH_PROTOCOL.
313 3. Prior to calling Start(), the Supported() function for the driver specified by This must
314 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
315
316 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
317 @param[in] ControllerHandle The handle of the controller to start. This handle
318 must support a protocol interface that supplies
319 an I/O abstraction to the driver.
320 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
321 parameter is ignored by device drivers, and is optional for bus
322 drivers. For a bus driver, if this parameter is NULL, then handles
323 for all the children of Controller are created by this driver.
324 If this parameter is not NULL and the first Device Path Node is
325 not the End of Device Path Node, then only the handle for the
326 child device specified by the first Device Path Node of
327 RemainingDevicePath is created by this driver.
328 If the first Device Path Node of RemainingDevicePath is
329 the End of Device Path Node, no child handle is created by this
330 driver.
331
332 @retval EFI_SUCCESS The device was started.
333 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
334 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
335 @retval Others The driver failded to start the device.
336
337 **/
338 EFI_STATUS
339 EFIAPI
340 HttpBootIp4DxeDriverBindingStart (
341 IN EFI_DRIVER_BINDING_PROTOCOL *This,
342 IN EFI_HANDLE ControllerHandle,
343 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
344 );
345
346 /**
347 Stops a device controller or a bus controller.
348
349 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
350 As a result, much of the error checking on the parameters to Stop() has been moved
351 into this common boot service. It is legal to call Stop() from other locations,
352 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
353 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
354 same driver's Start() function.
355 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
356 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
357 Start() function, and the Start() function must have called OpenProtocol() on
358 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
359
360 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
361 @param[in] ControllerHandle A handle to the device being stopped. The handle must
362 support a bus specific I/O protocol for the driver
363 to use to stop the device.
364 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
365 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
366 if NumberOfChildren is 0.
367
368 @retval EFI_SUCCESS The device was stopped.
369 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
370
371 **/
372 EFI_STATUS
373 EFIAPI
374 HttpBootIp4DxeDriverBindingStop (
375 IN EFI_DRIVER_BINDING_PROTOCOL *This,
376 IN EFI_HANDLE ControllerHandle,
377 IN UINTN NumberOfChildren,
378 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
379 );
380
381 /**
382 Tests to see if this driver supports a given controller. If a child device is provided,
383 it further tests to see if this driver supports creating a handle for the specified child device.
384
385 This function checks to see if the driver specified by This supports the device specified by
386 ControllerHandle. Drivers will typically use the device path attached to
387 ControllerHandle and/or the services from the bus I/O abstraction attached to
388 ControllerHandle to determine if the driver supports ControllerHandle. This function
389 may be called many times during platform initialization. In order to reduce boot times, the tests
390 performed by this function must be very small, and take as little time as possible to execute. This
391 function must not change the state of any hardware devices, and this function must be aware that the
392 device specified by ControllerHandle may already be managed by the same driver or a
393 different driver. This function must match its calls to AllocatePages() with FreePages(),
394 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
395 Because ControllerHandle may have been previously started by the same driver, if a protocol is
396 already in the opened state, then it must not be closed with CloseProtocol(). This is required
397 to guarantee the state of ControllerHandle is not modified by this function.
398
399 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
400 @param[in] ControllerHandle The handle of the controller to test. This handle
401 must support a protocol interface that supplies
402 an I/O abstraction to the driver.
403 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
404 parameter is ignored by device drivers, and is optional for bus
405 drivers. For bus drivers, if this parameter is not NULL, then
406 the bus driver must determine if the bus controller specified
407 by ControllerHandle and the child controller specified
408 by RemainingDevicePath are both supported by this
409 bus driver.
410
411 @retval EFI_SUCCESS The device specified by ControllerHandle and
412 RemainingDevicePath is supported by the driver specified by This.
413 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
414 RemainingDevicePath is already being managed by the driver
415 specified by This.
416 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
417 RemainingDevicePath is already being managed by a different
418 driver or an application that requires exclusive access.
419 Currently not implemented.
420 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
421 RemainingDevicePath is not supported by the driver specified by This.
422 **/
423 EFI_STATUS
424 EFIAPI
425 HttpBootIp6DxeDriverBindingSupported (
426 IN EFI_DRIVER_BINDING_PROTOCOL *This,
427 IN EFI_HANDLE ControllerHandle,
428 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
429 );
430
431 /**
432 Starts a device controller or a bus controller.
433
434 The Start() function is designed to be invoked from the EFI boot service ConnectController().
435 As a result, much of the error checking on the parameters to Start() has been moved into this
436 common boot service. It is legal to call Start() from other locations,
437 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
438 1. ControllerHandle must be a valid EFI_HANDLE.
439 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
440 EFI_DEVICE_PATH_PROTOCOL.
441 3. Prior to calling Start(), the Supported() function for the driver specified by This must
442 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
443
444 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
445 @param[in] ControllerHandle The handle of the controller to start. This handle
446 must support a protocol interface that supplies
447 an I/O abstraction to the driver.
448 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
449 parameter is ignored by device drivers, and is optional for bus
450 drivers. For a bus driver, if this parameter is NULL, then handles
451 for all the children of Controller are created by this driver.
452 If this parameter is not NULL and the first Device Path Node is
453 not the End of Device Path Node, then only the handle for the
454 child device specified by the first Device Path Node of
455 RemainingDevicePath is created by this driver.
456 If the first Device Path Node of RemainingDevicePath is
457 the End of Device Path Node, no child handle is created by this
458 driver.
459
460 @retval EFI_SUCCESS The device was started.
461 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
462 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
463 @retval Others The driver failded to start the device.
464
465 **/
466 EFI_STATUS
467 EFIAPI
468 HttpBootIp6DxeDriverBindingStart (
469 IN EFI_DRIVER_BINDING_PROTOCOL *This,
470 IN EFI_HANDLE ControllerHandle,
471 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
472 );
473
474 /**
475 Stops a device controller or a bus controller.
476
477 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
478 As a result, much of the error checking on the parameters to Stop() has been moved
479 into this common boot service. It is legal to call Stop() from other locations,
480 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
481 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
482 same driver's Start() function.
483 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
484 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
485 Start() function, and the Start() function must have called OpenProtocol() on
486 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
487
488 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
489 @param[in] ControllerHandle A handle to the device being stopped. The handle must
490 support a bus specific I/O protocol for the driver
491 to use to stop the device.
492 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
493 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
494 if NumberOfChildren is 0.
495
496 @retval EFI_SUCCESS The device was stopped.
497 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
498
499 **/
500 EFI_STATUS
501 EFIAPI
502 HttpBootIp6DxeDriverBindingStop (
503 IN EFI_DRIVER_BINDING_PROTOCOL *This,
504 IN EFI_HANDLE ControllerHandle,
505 IN UINTN NumberOfChildren,
506 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
507 );
508 #endif