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