]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpBootDxe/HttpBootSupport.h
NetworkPkg: Use the New Functions from HttpLib
[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
072289f4 4Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
d933e70a
JW
5This program and the accompanying materials are licensed and made available under \r
6the terms and conditions of the BSD License that accompanies this distribution. \r
7The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php. \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT 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
27EFI_HANDLE\r
28HttpBootGetNicByIp4Children (\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
41EFI_HANDLE\r
42HttpBootGetNicByIp6Children (\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
54VOID\r
55HttpBootUintnToAscDecWithFormat (\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
68VOID\r
69HttpBootShowIp4Addr (\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
79VOID\r
80HttpBootShowIp6Addr (\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
90VOID\r
91HttpBootPrintErrorMessage (\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
98typedef 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
112HTTP_IO_HEADER *\r
113HttpBootCreateHeader (\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
123VOID\r
124HttpBootFreeHeader (\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
141EFI_STATUS\r
142HttpBootSetHeader (\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
151typedef 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
164typedef 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
176typedef 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
184typedef 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
199} HTTP_IO;\r
200\r
201//\r
202// A wrapper structure to hold the received HTTP response data.\r
203//\r
204typedef struct {\r
205 EFI_HTTP_RESPONSE_DATA Response;\r
206 UINTN HeaderCount;\r
207 EFI_HTTP_HEADER *Headers;\r
208 UINTN BodyLength;\r
209 CHAR8 *Body;\r
072289f4 210 EFI_STATUS Status;\r
ef422fc5 211} HTTP_IO_RESPONSE_DATA;\r
d933e70a 212\r
b659408b
ZL
213/**\r
214 Retrieve the host address using the EFI_DNS6_PROTOCOL.\r
215\r
216 @param[in] Private The pointer to the driver's private data.\r
217 @param[in] HostName Pointer to buffer containing hostname.\r
218 @param[out] IpAddress On output, pointer to buffer containing IPv6 address.\r
219\r
220 @retval EFI_SUCCESS Operation succeeded.\r
221 @retval EFI_DEVICE_ERROR An unexpected network error occurred.\r
222 @retval Others Other errors as indicated. \r
223**/\r
224EFI_STATUS\r
225HttpBootDns (\r
226 IN HTTP_BOOT_PRIVATE_DATA *Private,\r
227 IN CHAR16 *HostName,\r
228 OUT EFI_IPv6_ADDRESS *IpAddress \r
229 );\r
230\r
231/**\r
232 Notify the callback function when an event is triggered.\r
233\r
234 @param[in] Event The triggered event.\r
235 @param[in] Context The opaque parameter to the function.\r
236\r
237**/\r
238VOID\r
239EFIAPI\r
240HttpBootCommonNotify (\r
241 IN EFI_EVENT Event,\r
242 IN VOID *Context\r
243 );\r
244\r
d933e70a
JW
245/**\r
246 Create a HTTP_IO to access the HTTP service. It will create and configure\r
247 a HTTP child handle.\r
248\r
249 @param[in] Image The handle of the driver image.\r
250 @param[in] Controller The handle of the controller.\r
251 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
252 @param[in] ConfigData The HTTP_IO configuration data.\r
253 @param[out] HttpIo The HTTP_IO.\r
254 \r
255 @retval EFI_SUCCESS The HTTP_IO is created and configured.\r
256 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
257 @retval EFI_UNSUPPORTED One or more of the control options are not\r
258 supported in the implementation.\r
259 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
260 @retval Others Failed to create the HTTP_IO or configure it.\r
261\r
262**/\r
263EFI_STATUS\r
264HttpIoCreateIo (\r
265 IN EFI_HANDLE Image,\r
266 IN EFI_HANDLE Controller,\r
267 IN UINT8 IpVersion,\r
268 IN HTTP_IO_CONFIG_DATA *ConfigData,\r
269 OUT HTTP_IO *HttpIo\r
270 );\r
271\r
272/**\r
273 Destroy the HTTP_IO and release the resouces. \r
274\r
275 @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.\r
276\r
277**/\r
278VOID\r
279HttpIoDestroyIo (\r
280 IN HTTP_IO *HttpIo\r
281 );\r
282\r
283/**\r
284 Synchronously send a HTTP REQUEST message to the server.\r
285 \r
286 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
287 @param[in] Request A pointer to storage such data as URL and HTTP method.\r
288 @param[in] HeaderCount Number of HTTP header structures in Headers list. \r
289 @param[in] Headers Array containing list of HTTP headers.\r
290 @param[in] BodyLength Length in bytes of the HTTP body.\r
291 @param[in] Body Body associated with the HTTP request. \r
292 \r
293 @retval EFI_SUCCESS The HTTP request is trasmitted.\r
294 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
295 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
296 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
297 @retval Others Other errors as indicated.\r
298\r
299**/\r
300EFI_STATUS\r
301HttpIoSendRequest (\r
302 IN HTTP_IO *HttpIo,\r
303 IN EFI_HTTP_REQUEST_DATA *Request, OPTIONAL\r
304 IN UINTN HeaderCount,\r
305 IN EFI_HTTP_HEADER *Headers, OPTIONAL\r
306 IN UINTN BodyLength,\r
307 IN VOID *Body OPTIONAL\r
308 );\r
309\r
310/**\r
311 Synchronously receive a HTTP RESPONSE message from the server.\r
312 \r
313 @param[in] HttpIo The HttpIo wrapping the HTTP service.\r
314 @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).\r
315 FALSE to continue receive the previous response message.\r
316 @param[out] ResponseData Point to a wrapper of the received response data.\r
317 \r
ef422fc5 318 @retval EFI_SUCCESS The HTTP response is received.\r
d933e70a
JW
319 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
320 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
321 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
322 @retval Others Other errors as indicated.\r
323\r
324**/\r
325EFI_STATUS\r
326HttpIoRecvResponse (\r
327 IN HTTP_IO *HttpIo,\r
328 IN BOOLEAN RecvMsgHeader,\r
ef422fc5 329 OUT HTTP_IO_RESPONSE_DATA *ResponseData\r
d933e70a
JW
330 );\r
331\r
fa848a40
FS
332/**\r
333 Get the URI address string from the input device path.\r
334\r
335 Caller need to free the buffer in the UriAddress pointer.\r
336 \r
337 @param[in] FilePath Pointer to the device path which contains a URI device path node.\r
338 @param[in] UriAddress The URI address string extract from the device path.\r
339 \r
340 @retval EFI_SUCCESS The URI string is returned.\r
341 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
342\r
343**/\r
344EFI_STATUS\r
345HttpBootParseFilePath (\r
346 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
347 OUT CHAR8 **UriAddress\r
348 );\r
349\r
d933e70a 350#endif\r