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