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