]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootSupport.h
NetworkPkg/HttpBootDxe: Fix various typos
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootSupport.h
CommitLineData
d933e70a
JW
1/** @file\r
2 Support functions declaration for UEFI HTTP boot driver.\r
3\r
f75a7f56 4Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
ecf98fbc 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
d933e70a
JW
6\r
7**/\r
8\r
9#ifndef __EFI_HTTP_BOOT_SUPPORT_H__\r
10#define __EFI_HTTP_BOOT_SUPPORT_H__\r
11\r
12/**\r
13 Get the Nic handle using any child handle in the IPv4 stack.\r
14\r
15 @param[in] ControllerHandle Pointer to child handle over IPv4.\r
16\r
17 @return NicHandle The pointer to the Nic handle.\r
18 @return NULL Can't find the Nic handle.\r
19\r
20**/\r
21EFI_HANDLE\r
22HttpBootGetNicByIp4Children (\r
23 IN EFI_HANDLE ControllerHandle\r
24 );\r
25\r
b659408b
ZL
26/**\r
27 Get the Nic handle using any child handle in the IPv6 stack.\r
28\r
29 @param[in] ControllerHandle Pointer to child handle over IPv6.\r
30\r
31 @return NicHandle The pointer to the Nic handle.\r
32 @return NULL Can't find the Nic handle.\r
33\r
34**/\r
35EFI_HANDLE\r
36HttpBootGetNicByIp6Children (\r
37 IN EFI_HANDLE ControllerHandle\r
38 );\r
39\r
d933e70a
JW
40/**\r
41 This function is to convert UINTN to ASCII string with the required formatting.\r
42\r
43 @param[in] Number Numeric value to be converted.\r
44 @param[in] Buffer The pointer to the buffer for ASCII string.\r
45 @param[in] Length The length of the required format.\r
46\r
47**/\r
48VOID\r
49HttpBootUintnToAscDecWithFormat (\r
50 IN UINTN Number,\r
51 IN UINT8 *Buffer,\r
52 IN INTN Length\r
53 );\r
54\r
55\r
56/**\r
57 This function is to display the IPv4 address.\r
58\r
59 @param[in] Ip The pointer to the IPv4 address.\r
60\r
61**/\r
62VOID\r
63HttpBootShowIp4Addr (\r
64 IN EFI_IPv4_ADDRESS *Ip\r
65 );\r
66\r
b659408b
ZL
67/**\r
68 This function is to display the IPv6 address.\r
69\r
70 @param[in] Ip The pointer to the IPv6 address.\r
71\r
72**/\r
73VOID\r
74HttpBootShowIp6Addr (\r
75 IN EFI_IPv6_ADDRESS *Ip\r
76 );\r
77\r
072289f4
ZL
78/**\r
79 This function is to display the HTTP error status.\r
80\r
81 @param[in] StatusCode The status code value in HTTP message.\r
82\r
83**/\r
84VOID\r
85HttpBootPrintErrorMessage (\r
86 EFI_HTTP_STATUS_CODE StatusCode\r
87 );\r
88\r
d933e70a
JW
89//\r
90// A wrapper structure to hold the HTTP headers.\r
91//\r
92typedef struct {\r
93 UINTN MaxHeaderCount;\r
94 UINTN HeaderCount;\r
95 EFI_HTTP_HEADER *Headers;\r
96} HTTP_IO_HEADER;\r
97\r
98/**\r
99 Create a HTTP_IO_HEADER to hold the HTTP header items.\r
100\r
c36b7b51 101 @param[in] MaxHeaderCount The maximum number of HTTP header in this holder.\r
d933e70a
JW
102\r
103 @return A pointer of the HTTP header holder or NULL if failed.\r
f75a7f56 104\r
d933e70a
JW
105**/\r
106HTTP_IO_HEADER *\r
107HttpBootCreateHeader (\r
108 IN UINTN MaxHeaderCount\r
109 );\r
110\r
111/**\r
c36b7b51 112 Destroy the HTTP_IO_HEADER and release the resources.\r
d933e70a
JW
113\r
114 @param[in] HttpIoHeader Point to the HTTP header holder to be destroyed.\r
115\r
116**/\r
117VOID\r
118HttpBootFreeHeader (\r
119 IN HTTP_IO_HEADER *HttpIoHeader\r
120 );\r
121\r
122/**\r
123 Set or update a HTTP header with the field name and corresponding value.\r
124\r
125 @param[in] HttpIoHeader Point to the HTTP header holder.\r
f75a7f56 126 @param[in] FieldName Null terminated string which describes a field name.\r
d933e70a
JW
127 @param[in] FieldValue Null terminated string which describes the corresponding field value.\r
128\r
129 @retval EFI_SUCCESS The HTTP header has been set or updated.\r
130 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
131 @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the operation.\r
132 @retval Other Unexpected error happened.\r
f75a7f56 133\r
d933e70a
JW
134**/\r
135EFI_STATUS\r
136HttpBootSetHeader (\r
137 IN HTTP_IO_HEADER *HttpIoHeader,\r
138 IN CHAR8 *FieldName,\r
139 IN CHAR8 *FieldValue\r
140 );\r
141\r
95b5c32f
FS
142///\r
143/// HTTP_IO_CALLBACK_EVENT\r
144///\r
145typedef enum {\r
146 HttpIoRequest,\r
147 HttpIoResponse\r
148} HTTP_IO_CALLBACK_EVENT;\r
149\r
150/**\r
151 HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened.\r
152\r
153 @param[in] EventType Indicate the Event type that occurs in the current callback.\r
154 @param[in] Message HTTP message which will be send to, or just received from HTTP server.\r
155 @param[in] Context The Callback Context pointer.\r
f75a7f56 156\r
95b5c32f
FS
157 @retval EFI_SUCCESS Tells the HttpIo to continue the HTTP process.\r
158 @retval Others Tells the HttpIo to abort the current HTTP process.\r
159**/\r
160typedef\r
161EFI_STATUS\r
162(EFIAPI * HTTP_IO_CALLBACK) (\r
163 IN HTTP_IO_CALLBACK_EVENT EventType,\r
164 IN EFI_HTTP_MESSAGE *Message,\r
165 IN VOID *Context\r
166 );\r
167\r
d933e70a
JW
168//\r
169// HTTP_IO configuration data for IPv4\r
170//\r
171typedef struct {\r
172 EFI_HTTP_VERSION HttpVersion;\r
173 UINT32 RequestTimeOut; // In milliseconds.\r
174 UINT32 ResponseTimeOut; // In milliseconds.\r
175 BOOLEAN UseDefaultAddress;\r
176 EFI_IPv4_ADDRESS LocalIp;\r
177 EFI_IPv4_ADDRESS SubnetMask;\r
178 UINT16 LocalPort;\r
179} HTTP4_IO_CONFIG_DATA;\r
180\r
b659408b
ZL
181//\r
182// HTTP_IO configuration data for IPv6\r
183//\r
184typedef struct {\r
185 EFI_HTTP_VERSION HttpVersion;\r
186 UINT32 RequestTimeOut; // In milliseconds.\r
187 BOOLEAN UseDefaultAddress;\r
188 EFI_IPv6_ADDRESS LocalIp;\r
189 UINT16 LocalPort;\r
190} HTTP6_IO_CONFIG_DATA;\r
191\r
192\r
d933e70a
JW
193//\r
194// HTTP_IO configuration\r
195//\r
196typedef union {\r
197 HTTP4_IO_CONFIG_DATA Config4;\r
b659408b 198 HTTP6_IO_CONFIG_DATA Config6;\r
d933e70a
JW
199} HTTP_IO_CONFIG_DATA;\r
200\r
201//\r
ef422fc5 202// HTTP_IO wrapper of the EFI HTTP service.\r
d933e70a
JW
203//\r
204typedef struct {\r
205 UINT8 IpVersion;\r
206 EFI_HANDLE Image;\r
207 EFI_HANDLE Controller;\r
208 EFI_HANDLE Handle;\r
f75a7f56 209\r
d933e70a
JW
210 EFI_HTTP_PROTOCOL *Http;\r
211\r
95b5c32f
FS
212 HTTP_IO_CALLBACK Callback;\r
213 VOID *Context;\r
214\r
d933e70a
JW
215 EFI_HTTP_TOKEN ReqToken;\r
216 EFI_HTTP_MESSAGE ReqMessage;\r
217 EFI_HTTP_TOKEN RspToken;\r
218 EFI_HTTP_MESSAGE RspMessage;\r
219\r
220 BOOLEAN IsTxDone;\r
221 BOOLEAN IsRxDone;\r
7570696c
JW
222\r
223 EFI_EVENT TimeoutEvent;\r
d933e70a
JW
224} HTTP_IO;\r
225\r
226//\r
227// A wrapper structure to hold the received HTTP response data.\r
228//\r
229typedef struct {\r
230 EFI_HTTP_RESPONSE_DATA Response;\r
231 UINTN HeaderCount;\r
232 EFI_HTTP_HEADER *Headers;\r
233 UINTN BodyLength;\r
234 CHAR8 *Body;\r
072289f4 235 EFI_STATUS Status;\r
ef422fc5 236} HTTP_IO_RESPONSE_DATA;\r
d933e70a 237\r
b659408b
ZL
238/**\r
239 Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
240\r
241 @param[in] Private The pointer to the driver's private data.\r
242 @param[in] HostName Pointer to buffer containing hostname.\r
243 @param[out] IpAddress On output, pointer to buffer containing IPv6 address.\r
244\r
245 @retval EFI_SUCCESS Operation succeeded.\r
246 @retval EFI_DEVICE_ERROR An unexpected network error occurred.\r
f75a7f56 247 @retval Others Other errors as indicated.\r
b659408b
ZL
248**/\r
249EFI_STATUS\r
250HttpBootDns (\r
251 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
252 IN CHAR16 *HostName,\r
f75a7f56 253 OUT EFI_IPv6_ADDRESS *IpAddress\r
b659408b
ZL
254 );\r
255\r
256/**\r
257 Notify the callback function when an event is triggered.\r
258\r
259 @param[in] Event The triggered event.\r
260 @param[in] Context The opaque parameter to the function.\r
261\r
262**/\r
263VOID\r
264EFIAPI\r
265HttpBootCommonNotify (\r
266 IN EFI_EVENT Event,\r
267 IN VOID *Context\r
268 );\r
269\r
d933e70a
JW
270/**\r
271 Create a HTTP_IO to access the HTTP service. It will create and configure\r
272 a HTTP child handle.\r
273\r
274 @param[in] Image The handle of the driver image.\r
275 @param[in] Controller The handle of the controller.\r
276 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
277 @param[in] ConfigData The HTTP_IO configuration data.\r
95b5c32f
FS
278 @param[in] Callback Callback function which will be invoked when specified\r
279 HTTP_IO_CALLBACK_EVENT happened.\r
280 @param[in] Context The Context data which will be passed to the Callback function.\r
d933e70a 281 @param[out] HttpIo The HTTP_IO.\r
f75a7f56 282\r
d933e70a
JW
283 @retval EFI_SUCCESS The HTTP_IO is created and configured.\r
284 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
285 @retval EFI_UNSUPPORTED One or more of the control options are not\r
286 supported in the implementation.\r
287 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
288 @retval Others Failed to create the HTTP_IO or configure it.\r
289\r
290**/\r
291EFI_STATUS\r
292HttpIoCreateIo (\r
293 IN EFI_HANDLE Image,\r
294 IN EFI_HANDLE Controller,\r
295 IN UINT8 IpVersion,\r
296 IN HTTP_IO_CONFIG_DATA *ConfigData,\r
95b5c32f
FS
297 IN HTTP_IO_CALLBACK Callback,\r
298 IN VOID *Context,\r
d933e70a
JW
299 OUT HTTP_IO *HttpIo\r
300 );\r
301\r
302/**\r
c36b7b51 303 Destroy the HTTP_IO and release the resources.\r
d933e70a
JW
304\r
305 @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.\r
306\r
307**/\r
308VOID\r
309HttpIoDestroyIo (\r
310 IN HTTP_IO *HttpIo\r
311 );\r
312\r
313/**\r
314 Synchronously send a HTTP REQUEST message to the server.\r
f75a7f56 315\r
d933e70a
JW
316 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
317 @param[in] Request A pointer to storage such data as URL and HTTP method.\r
f75a7f56 318 @param[in] HeaderCount Number of HTTP header structures in Headers list.\r
d933e70a
JW
319 @param[in] Headers Array containing list of HTTP headers.\r
320 @param[in] BodyLength Length in bytes of the HTTP body.\r
f75a7f56
LG
321 @param[in] Body Body associated with the HTTP request.\r
322\r
c36b7b51 323 @retval EFI_SUCCESS The HTTP request is transmitted.\r
d933e70a
JW
324 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
325 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
326 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
327 @retval Others Other errors as indicated.\r
328\r
329**/\r
330EFI_STATUS\r
331HttpIoSendRequest (\r
332 IN HTTP_IO *HttpIo,\r
333 IN EFI_HTTP_REQUEST_DATA *Request, OPTIONAL\r
334 IN UINTN HeaderCount,\r
335 IN EFI_HTTP_HEADER *Headers, OPTIONAL\r
336 IN UINTN BodyLength,\r
337 IN VOID *Body OPTIONAL\r
338 );\r
339\r
340/**\r
341 Synchronously receive a HTTP RESPONSE message from the server.\r
f75a7f56 342\r
d933e70a
JW
343 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
344 @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).\r
345 FALSE to continue receive the previous response message.\r
346 @param[out] ResponseData Point to a wrapper of the received response data.\r
f75a7f56 347\r
ef422fc5 348 @retval EFI_SUCCESS The HTTP response is received.\r
d933e70a
JW
349 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
350 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
351 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
352 @retval Others Other errors as indicated.\r
353\r
354**/\r
355EFI_STATUS\r
356HttpIoRecvResponse (\r
357 IN HTTP_IO *HttpIo,\r
358 IN BOOLEAN RecvMsgHeader,\r
ef422fc5 359 OUT HTTP_IO_RESPONSE_DATA *ResponseData\r
d933e70a
JW
360 );\r
361\r
221463c2
JW
362/**\r
363 This function checks the HTTP(S) URI scheme.\r
364\r
365 @param[in] Uri The pointer to the URI string.\r
f75a7f56 366\r
221463c2
JW
367 @retval EFI_SUCCESS The URI scheme is valid.\r
368 @retval EFI_INVALID_PARAMETER The URI scheme is not HTTP or HTTPS.\r
369 @retval EFI_ACCESS_DENIED HTTP is disabled and the URI is HTTP.\r
370\r
371**/\r
372EFI_STATUS\r
373HttpBootCheckUriScheme (\r
374 IN CHAR8 *Uri\r
375 );\r
376\r
fa848a40
FS
377/**\r
378 Get the URI address string from the input device path.\r
379\r
380 Caller need to free the buffer in the UriAddress pointer.\r
f75a7f56 381\r
fa848a40 382 @param[in] FilePath Pointer to the device path which contains a URI device path node.\r
73617fa6 383 @param[out] UriAddress The URI address string extract from the device path.\r
f75a7f56 384\r
fa848a40
FS
385 @retval EFI_SUCCESS The URI string is returned.\r
386 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
387\r
388**/\r
389EFI_STATUS\r
390HttpBootParseFilePath (\r
391 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
392 OUT CHAR8 **UriAddress\r
393 );\r
394\r
587d204c
FS
395/**\r
396 This function returns the image type according to server replied HTTP message\r
397 and also the image's URI info.\r
398\r
399 @param[in] Uri The pointer to the image's URI string.\r
f75a7f56
LG
400 @param[in] UriParser URI Parse result returned by NetHttpParseUrl().\r
401 @param[in] HeaderCount Number of HTTP header structures in Headers list.\r
587d204c
FS
402 @param[in] Headers Array containing list of HTTP headers.\r
403 @param[out] ImageType The image type of the downloaded file.\r
f75a7f56 404\r
587d204c
FS
405 @retval EFI_SUCCESS The image type is returned in ImageType.\r
406 @retval EFI_INVALID_PARAMETER ImageType, Uri or UriParser is NULL.\r
407 @retval EFI_INVALID_PARAMETER HeaderCount is not zero, and Headers is NULL.\r
408 @retval EFI_NOT_FOUND Failed to identify the image type.\r
c36b7b51 409 @retval Others Unexpected error happened.\r
587d204c
FS
410\r
411**/\r
412EFI_STATUS\r
413HttpBootCheckImageType (\r
414 IN CHAR8 *Uri,\r
415 IN VOID *UriParser,\r
416 IN UINTN HeaderCount,\r
417 IN EFI_HTTP_HEADER *Headers,\r
418 OUT HTTP_BOOT_IMAGE_TYPE *ImageType\r
419 );\r
420\r
421/**\r
422 This function register the RAM disk info to the system.\r
f75a7f56 423\r
587d204c
FS
424 @param[in] Private The pointer to the driver's private data.\r
425 @param[in] BufferSize The size of Buffer in bytes.\r
426 @param[in] Buffer The base address of the RAM disk.\r
427 @param[in] ImageType The image type of the file in Buffer.\r
428\r
429 @retval EFI_SUCCESS The RAM disk has been registered.\r
430 @retval EFI_NOT_FOUND No RAM disk protocol instances were found.\r
431 @retval EFI_UNSUPPORTED The ImageType is not supported.\r
432 @retval Others Unexpected error happened.\r
433\r
434**/\r
435EFI_STATUS\r
436HttpBootRegisterRamDisk (\r
437 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
438 IN UINTN BufferSize,\r
439 IN VOID *Buffer,\r
440 IN HTTP_BOOT_IMAGE_TYPE ImageType\r
441 );\r
bb4831c0
FS
442\r
443/**\r
444 Indicate if the HTTP status code indicates a redirection.\r
f75a7f56 445\r
bb4831c0
FS
446 @param[in] StatusCode HTTP status code from server.\r
447\r
448 @return TRUE if it's redirection.\r
449\r
450**/\r
451BOOLEAN\r
452HttpBootIsHttpRedirectStatusCode (\r
453 IN EFI_HTTP_STATUS_CODE StatusCode\r
2913ebb2 454 );\r
d933e70a 455#endif\r