]>
Commit | Line | Data |
---|---|---|
d933e70a JW |
1 | /** @file\r |
2 | Support functions declaration for UEFI HTTP boot driver.\r | |
3 | \r | |
072289f4 | 4 | Copyright (c) 2015 - 2016, 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 | |
148 | //\r | |
149 | // HTTP_IO configuration data for IPv4\r | |
150 | //\r | |
151 | typedef struct {\r | |
152 | EFI_HTTP_VERSION HttpVersion;\r | |
153 | UINT32 RequestTimeOut; // In milliseconds.\r | |
154 | UINT32 ResponseTimeOut; // In milliseconds.\r | |
155 | BOOLEAN UseDefaultAddress;\r | |
156 | EFI_IPv4_ADDRESS LocalIp;\r | |
157 | EFI_IPv4_ADDRESS SubnetMask;\r | |
158 | UINT16 LocalPort;\r | |
159 | } HTTP4_IO_CONFIG_DATA;\r | |
160 | \r | |
b659408b ZL |
161 | //\r |
162 | // HTTP_IO configuration data for IPv6\r | |
163 | //\r | |
164 | typedef struct {\r | |
165 | EFI_HTTP_VERSION HttpVersion;\r | |
166 | UINT32 RequestTimeOut; // In milliseconds.\r | |
167 | BOOLEAN UseDefaultAddress;\r | |
168 | EFI_IPv6_ADDRESS LocalIp;\r | |
169 | UINT16 LocalPort;\r | |
170 | } HTTP6_IO_CONFIG_DATA;\r | |
171 | \r | |
172 | \r | |
d933e70a JW |
173 | //\r |
174 | // HTTP_IO configuration\r | |
175 | //\r | |
176 | typedef union {\r | |
177 | HTTP4_IO_CONFIG_DATA Config4;\r | |
b659408b | 178 | HTTP6_IO_CONFIG_DATA Config6;\r |
d933e70a JW |
179 | } HTTP_IO_CONFIG_DATA;\r |
180 | \r | |
181 | //\r | |
ef422fc5 | 182 | // HTTP_IO wrapper of the EFI HTTP service.\r |
d933e70a JW |
183 | //\r |
184 | typedef struct {\r | |
185 | UINT8 IpVersion;\r | |
186 | EFI_HANDLE Image;\r | |
187 | EFI_HANDLE Controller;\r | |
188 | EFI_HANDLE Handle;\r | |
189 | \r | |
190 | EFI_HTTP_PROTOCOL *Http;\r | |
191 | \r | |
192 | EFI_HTTP_TOKEN ReqToken;\r | |
193 | EFI_HTTP_MESSAGE ReqMessage;\r | |
194 | EFI_HTTP_TOKEN RspToken;\r | |
195 | EFI_HTTP_MESSAGE RspMessage;\r | |
196 | \r | |
197 | BOOLEAN IsTxDone;\r | |
198 | BOOLEAN IsRxDone;\r | |
7570696c JW |
199 | \r |
200 | EFI_EVENT TimeoutEvent;\r | |
d933e70a JW |
201 | } HTTP_IO;\r |
202 | \r | |
203 | //\r | |
204 | // A wrapper structure to hold the received HTTP response data.\r | |
205 | //\r | |
206 | typedef struct {\r | |
207 | EFI_HTTP_RESPONSE_DATA Response;\r | |
208 | UINTN HeaderCount;\r | |
209 | EFI_HTTP_HEADER *Headers;\r | |
210 | UINTN BodyLength;\r | |
211 | CHAR8 *Body;\r | |
072289f4 | 212 | EFI_STATUS Status;\r |
ef422fc5 | 213 | } HTTP_IO_RESPONSE_DATA;\r |
d933e70a | 214 | \r |
b659408b ZL |
215 | /**\r |
216 | Retrieve the host address using the EFI_DNS6_PROTOCOL.\r | |
217 | \r | |
218 | @param[in] Private The pointer to the driver's private data.\r | |
219 | @param[in] HostName Pointer to buffer containing hostname.\r | |
220 | @param[out] IpAddress On output, pointer to buffer containing IPv6 address.\r | |
221 | \r | |
222 | @retval EFI_SUCCESS Operation succeeded.\r | |
223 | @retval EFI_DEVICE_ERROR An unexpected network error occurred.\r | |
224 | @retval Others Other errors as indicated. \r | |
225 | **/\r | |
226 | EFI_STATUS\r | |
227 | HttpBootDns (\r | |
228 | IN HTTP_BOOT_PRIVATE_DATA *Private,\r | |
229 | IN CHAR16 *HostName,\r | |
230 | OUT EFI_IPv6_ADDRESS *IpAddress \r | |
231 | );\r | |
232 | \r | |
233 | /**\r | |
234 | Notify the callback function when an event is triggered.\r | |
235 | \r | |
236 | @param[in] Event The triggered event.\r | |
237 | @param[in] Context The opaque parameter to the function.\r | |
238 | \r | |
239 | **/\r | |
240 | VOID\r | |
241 | EFIAPI\r | |
242 | HttpBootCommonNotify (\r | |
243 | IN EFI_EVENT Event,\r | |
244 | IN VOID *Context\r | |
245 | );\r | |
246 | \r | |
d933e70a JW |
247 | /**\r |
248 | Create a HTTP_IO to access the HTTP service. It will create and configure\r | |
249 | a HTTP child handle.\r | |
250 | \r | |
251 | @param[in] Image The handle of the driver image.\r | |
252 | @param[in] Controller The handle of the controller.\r | |
253 | @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r | |
254 | @param[in] ConfigData The HTTP_IO configuration data.\r | |
255 | @param[out] HttpIo The HTTP_IO.\r | |
256 | \r | |
257 | @retval EFI_SUCCESS The HTTP_IO is created and configured.\r | |
258 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
259 | @retval EFI_UNSUPPORTED One or more of the control options are not\r | |
260 | supported in the implementation.\r | |
261 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
262 | @retval Others Failed to create the HTTP_IO or configure it.\r | |
263 | \r | |
264 | **/\r | |
265 | EFI_STATUS\r | |
266 | HttpIoCreateIo (\r | |
267 | IN EFI_HANDLE Image,\r | |
268 | IN EFI_HANDLE Controller,\r | |
269 | IN UINT8 IpVersion,\r | |
270 | IN HTTP_IO_CONFIG_DATA *ConfigData,\r | |
271 | OUT HTTP_IO *HttpIo\r | |
272 | );\r | |
273 | \r | |
274 | /**\r | |
275 | Destroy the HTTP_IO and release the resouces. \r | |
276 | \r | |
277 | @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.\r | |
278 | \r | |
279 | **/\r | |
280 | VOID\r | |
281 | HttpIoDestroyIo (\r | |
282 | IN HTTP_IO *HttpIo\r | |
283 | );\r | |
284 | \r | |
285 | /**\r | |
286 | Synchronously send a HTTP REQUEST message to the server.\r | |
287 | \r | |
288 | @param[in] HttpIo The HttpIo wrapping the HTTP service.\r | |
289 | @param[in] Request A pointer to storage such data as URL and HTTP method.\r | |
290 | @param[in] HeaderCount Number of HTTP header structures in Headers list. \r | |
291 | @param[in] Headers Array containing list of HTTP headers.\r | |
292 | @param[in] BodyLength Length in bytes of the HTTP body.\r | |
293 | @param[in] Body Body associated with the HTTP request. \r | |
294 | \r | |
295 | @retval EFI_SUCCESS The HTTP request is trasmitted.\r | |
296 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
297 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
298 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
299 | @retval Others Other errors as indicated.\r | |
300 | \r | |
301 | **/\r | |
302 | EFI_STATUS\r | |
303 | HttpIoSendRequest (\r | |
304 | IN HTTP_IO *HttpIo,\r | |
305 | IN EFI_HTTP_REQUEST_DATA *Request, OPTIONAL\r | |
306 | IN UINTN HeaderCount,\r | |
307 | IN EFI_HTTP_HEADER *Headers, OPTIONAL\r | |
308 | IN UINTN BodyLength,\r | |
309 | IN VOID *Body OPTIONAL\r | |
310 | );\r | |
311 | \r | |
312 | /**\r | |
313 | Synchronously receive a HTTP RESPONSE message from the server.\r | |
314 | \r | |
315 | @param[in] HttpIo The HttpIo wrapping the HTTP service.\r | |
316 | @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).\r | |
317 | FALSE to continue receive the previous response message.\r | |
318 | @param[out] ResponseData Point to a wrapper of the received response data.\r | |
319 | \r | |
ef422fc5 | 320 | @retval EFI_SUCCESS The HTTP response is received.\r |
d933e70a JW |
321 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
322 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
323 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
324 | @retval Others Other errors as indicated.\r | |
325 | \r | |
326 | **/\r | |
327 | EFI_STATUS\r | |
328 | HttpIoRecvResponse (\r | |
329 | IN HTTP_IO *HttpIo,\r | |
330 | IN BOOLEAN RecvMsgHeader,\r | |
ef422fc5 | 331 | OUT HTTP_IO_RESPONSE_DATA *ResponseData\r |
d933e70a JW |
332 | );\r |
333 | \r | |
fa848a40 FS |
334 | /**\r |
335 | Get the URI address string from the input device path.\r | |
336 | \r | |
337 | Caller need to free the buffer in the UriAddress pointer.\r | |
338 | \r | |
339 | @param[in] FilePath Pointer to the device path which contains a URI device path node.\r | |
73617fa6 | 340 | @param[out] UriAddress The URI address string extract from the device path.\r |
fa848a40 FS |
341 | \r |
342 | @retval EFI_SUCCESS The URI string is returned.\r | |
343 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
344 | \r | |
345 | **/\r | |
346 | EFI_STATUS\r | |
347 | HttpBootParseFilePath (\r | |
348 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
349 | OUT CHAR8 **UriAddress\r | |
350 | );\r | |
351 | \r | |
587d204c FS |
352 | /**\r |
353 | This function returns the image type according to server replied HTTP message\r | |
354 | and also the image's URI info.\r | |
355 | \r | |
356 | @param[in] Uri The pointer to the image's URI string.\r | |
357 | @param[in] UriParser URI Parse result returned by NetHttpParseUrl(). \r | |
358 | @param[in] HeaderCount Number of HTTP header structures in Headers list. \r | |
359 | @param[in] Headers Array containing list of HTTP headers.\r | |
360 | @param[out] ImageType The image type of the downloaded file.\r | |
361 | \r | |
362 | @retval EFI_SUCCESS The image type is returned in ImageType.\r | |
363 | @retval EFI_INVALID_PARAMETER ImageType, Uri or UriParser is NULL.\r | |
364 | @retval EFI_INVALID_PARAMETER HeaderCount is not zero, and Headers is NULL.\r | |
365 | @retval EFI_NOT_FOUND Failed to identify the image type.\r | |
366 | @retval Others Unexpect error happened.\r | |
367 | \r | |
368 | **/\r | |
369 | EFI_STATUS\r | |
370 | HttpBootCheckImageType (\r | |
371 | IN CHAR8 *Uri,\r | |
372 | IN VOID *UriParser,\r | |
373 | IN UINTN HeaderCount,\r | |
374 | IN EFI_HTTP_HEADER *Headers,\r | |
375 | OUT HTTP_BOOT_IMAGE_TYPE *ImageType\r | |
376 | );\r | |
377 | \r | |
378 | /**\r | |
379 | This function register the RAM disk info to the system.\r | |
380 | \r | |
381 | @param[in] Private The pointer to the driver's private data.\r | |
382 | @param[in] BufferSize The size of Buffer in bytes.\r | |
383 | @param[in] Buffer The base address of the RAM disk.\r | |
384 | @param[in] ImageType The image type of the file in Buffer.\r | |
385 | \r | |
386 | @retval EFI_SUCCESS The RAM disk has been registered.\r | |
387 | @retval EFI_NOT_FOUND No RAM disk protocol instances were found.\r | |
388 | @retval EFI_UNSUPPORTED The ImageType is not supported.\r | |
389 | @retval Others Unexpected error happened.\r | |
390 | \r | |
391 | **/\r | |
392 | EFI_STATUS\r | |
393 | HttpBootRegisterRamDisk (\r | |
394 | IN HTTP_BOOT_PRIVATE_DATA *Private,\r | |
395 | IN UINTN BufferSize,\r | |
396 | IN VOID *Buffer,\r | |
397 | IN HTTP_BOOT_IMAGE_TYPE ImageType\r | |
398 | );\r | |
d933e70a | 399 | #endif\r |