]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpDxe/HttpProto.h
MdePkg:Add a new error status code EFI_HTTP_ERROR.
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpProto.h
CommitLineData
47f51a06
YT
1/** @file\r
2 The header files of miscellaneous routines for HttpDxe driver.\r
3\r
4Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The 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_PROTO_H__\r
16#define __EFI_HTTP_PROTO_H__\r
17\r
18#define DEF_BUF_LEN 2048\r
19\r
20#define HTTP_SERVICE_SIGNATURE SIGNATURE_32('H', 't', 't', 'S')\r
21\r
22#define HTTP_SERVICE_FROM_PROTOCOL(a) \\r
23 CR ( \\r
24 (a), \\r
25 HTTP_SERVICE, \\r
26 ServiceBinding, \\r
27 HTTP_SERVICE_SIGNATURE \\r
28 )\r
29\r
b659408b 30\r
47f51a06
YT
31//\r
32// The state of HTTP protocol. It starts from UNCONFIGED.\r
33//\r
34#define HTTP_STATE_UNCONFIGED 0\r
35#define HTTP_STATE_HTTP_CONFIGED 1\r
36#define HTTP_STATE_TCP_CONFIGED 2\r
37#define HTTP_STATE_TCP_UNCONFIGED 3\r
38#define HTTP_STATE_TCP_CONNECTED 4\r
39#define HTTP_STATE_TCP_CLOSED 5\r
40\r
41//\r
42// TCP configured data.\r
43//\r
44#define HTTP_TOS_DEAULT 8\r
45#define HTTP_TTL_DEAULT 255\r
46#define HTTP_BUFFER_SIZE_DEAULT 65535\r
47#define HTTP_MAX_SYN_BACK_LOG 5\r
48#define HTTP_CONNECTION_TIMEOUT 60\r
49#define HTTP_DATA_RETRIES 12\r
50#define HTTP_FIN_TIMEOUT 2\r
51#define HTTP_KEEP_ALIVE_PROBES 6\r
52#define HTTP_KEEP_ALIVE_TIME 7200\r
53#define HTTP_KEEP_ALIVE_INTERVAL 30\r
54\r
51b0450e
FS
55#define HTTP_URL_BUFFER_LEN 4096\r
56\r
47f51a06
YT
57typedef struct _HTTP_SERVICE {\r
58 UINT32 Signature;\r
59 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
60 EFI_HANDLE ImageHandle;\r
61 EFI_HANDLE ControllerHandle;\r
b659408b
ZL
62 EFI_HANDLE Tcp4ChildHandle;\r
63 EFI_HANDLE Tcp6ChildHandle;\r
47f51a06
YT
64 LIST_ENTRY ChildrenList;\r
65 UINTN ChildrenNumber;\r
47f51a06
YT
66 INTN State;\r
67} HTTP_SERVICE;\r
68\r
69typedef struct {\r
b659408b
ZL
70 EFI_TCP4_IO_TOKEN Tx4Token;\r
71 EFI_TCP4_TRANSMIT_DATA Tx4Data;\r
72 EFI_TCP6_IO_TOKEN Tx6Token;\r
73 EFI_TCP6_TRANSMIT_DATA Tx6Data;\r
74 EFI_TCP4_IO_TOKEN Rx4Token;\r
75 EFI_TCP4_RECEIVE_DATA Rx4Data;\r
76 EFI_TCP6_IO_TOKEN Rx6Token;\r
77 EFI_TCP6_RECEIVE_DATA Rx6Data;\r
47f51a06 78 BOOLEAN IsTxDone;\r
47f51a06
YT
79 BOOLEAN IsRxDone;\r
80 UINTN BodyLen;\r
81 EFI_HTTP_METHOD Method;\r
82} HTTP_TCP_TOKEN_WRAP;\r
83\r
84typedef struct _HTTP_PROTOCOL {\r
85 UINT32 Signature;\r
86 EFI_HTTP_PROTOCOL Http;\r
87 EFI_HANDLE Handle;\r
88 HTTP_SERVICE *Service;\r
89 LIST_ENTRY Link; // Link to all HTTP instance from the service.\r
90 BOOLEAN InDestroy;\r
91 INTN State;\r
92\r
b659408b 93 EFI_HANDLE Tcp4ChildHandle;\r
47f51a06
YT
94 EFI_TCP4_PROTOCOL *Tcp4;\r
95 EFI_TCP4_CONFIG_DATA Tcp4CfgData;\r
96 EFI_TCP4_OPTION Tcp4Option;\r
97\r
b659408b
ZL
98 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken;\r
99 BOOLEAN IsTcp4ConnDone;\r
100 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken;\r
101 BOOLEAN IsTcp4CloseDone;\r
47f51a06
YT
102 CHAR8 *RemoteHost;\r
103 UINT16 RemotePort;\r
104 EFI_IPv4_ADDRESS RemoteAddr;\r
b659408b
ZL
105 \r
106 EFI_HANDLE Tcp6ChildHandle;\r
107 EFI_TCP6_PROTOCOL *Tcp6;\r
108 EFI_TCP6_CONFIG_DATA Tcp6CfgData;\r
109 EFI_TCP6_OPTION Tcp6Option;\r
110 \r
111 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken;\r
112 BOOLEAN IsTcp6ConnDone;\r
113 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken;\r
114 BOOLEAN IsTcp6CloseDone;\r
115 EFI_IPv6_ADDRESS RemoteIpv6Addr;\r
116\r
117\r
118 \r
47f51a06 119 //\r
b659408b 120 // Rx4Token or Rx6Token used for receiving HTTP header.\r
47f51a06 121 //\r
b659408b
ZL
122 EFI_TCP4_IO_TOKEN Rx4Token;\r
123 EFI_TCP4_RECEIVE_DATA Rx4Data;\r
124 EFI_TCP6_IO_TOKEN Rx6Token;\r
125 EFI_TCP6_RECEIVE_DATA Rx6Data;\r
47f51a06
YT
126 BOOLEAN IsRxDone;\r
127\r
b659408b
ZL
128 CHAR8 **EndofHeader;\r
129 CHAR8 **HttpHeaders;\r
47f51a06
YT
130 CHAR8 *CacheBody;\r
131 CHAR8 *NextMsg;\r
132 UINTN CacheLen;\r
133 UINTN CacheOffset;\r
134\r
135 //\r
136 // HTTP message-body parser.\r
137 //\r
138 VOID *MsgParser;\r
139 \r
140 EFI_HTTP_VERSION HttpVersion;\r
141 UINT32 TimeOutMillisec;\r
142 BOOLEAN LocalAddressIsIPv6;\r
143\r
144 EFI_HTTPv4_ACCESS_POINT IPv4Node;\r
b659408b 145 EFI_HTTPv6_ACCESS_POINT Ipv6Node;\r
47f51a06
YT
146\r
147 NET_MAP TxTokens;\r
148 NET_MAP RxTokens;\r
51b0450e
FS
149\r
150 CHAR8 *Url;\r
47f51a06
YT
151} HTTP_PROTOCOL;\r
152\r
153typedef struct {\r
154 EFI_HTTP_TOKEN *HttpToken;\r
155 HTTP_PROTOCOL *HttpInstance;\r
156 HTTP_TCP_TOKEN_WRAP TcpWrap;\r
157} HTTP_TOKEN_WRAP;\r
158\r
159\r
160#define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')\r
161\r
162#define HTTP_INSTANCE_FROM_PROTOCOL(a) \\r
163 CR ( \\r
164 (a), \\r
165 HTTP_PROTOCOL, \\r
166 Http, \\r
167 HTTP_PROTOCOL_SIGNATURE \\r
168 )\r
169\r
170/**\r
171 The common notify function used in HTTP driver. \r
172\r
173 @param[in] Event The event signaled.\r
174 @param[in] Context The context.\r
175\r
176**/\r
177VOID\r
178EFIAPI\r
179HttpCommonNotify (\r
180 IN EFI_EVENT Event,\r
181 IN VOID *Context\r
182 );\r
183\r
184/**\r
b659408b 185 Create events for the TCP connection token and TCP close token.\r
47f51a06
YT
186\r
187 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
188\r
189 @retval EFI_SUCCESS The events are created successfully.\r
190 @retval others Other error as indicated.\r
191\r
192**/\r
193EFI_STATUS\r
b659408b 194HttpCreateTcpConnCloseEvent (\r
47f51a06
YT
195 IN HTTP_PROTOCOL *HttpInstance\r
196 );\r
197\r
198/**\r
b659408b 199 Close events in the TCP connection token and TCP close token.\r
47f51a06
YT
200\r
201 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
202\r
203**/\r
204VOID\r
b659408b 205HttpCloseTcpConnCloseEvent (\r
47f51a06
YT
206 IN HTTP_PROTOCOL *HttpInstance\r
207 );\r
208\r
209/**\r
b659408b 210 Create event for the TCP transmit token.\r
47f51a06
YT
211\r
212 @param[in] Wrap Point to HTTP token's wrap data.\r
213\r
214 @retval EFI_SUCCESS The events is created successfully.\r
215 @retval others Other error as indicated.\r
216\r
217**/\r
218EFI_STATUS\r
b659408b 219HttpCreateTcpTxEvent (\r
47f51a06
YT
220 IN HTTP_TOKEN_WRAP *Wrap\r
221 );\r
222\r
223/**\r
b659408b 224 Create event for the TCP receive token which is used to receive HTTP header.\r
47f51a06
YT
225\r
226 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
227\r
228 @retval EFI_SUCCESS The events is created successfully.\r
229 @retval others Other error as indicated.\r
230\r
231**/\r
232EFI_STATUS\r
b659408b 233HttpCreateTcpRxEventForHeader (\r
47f51a06
YT
234 IN HTTP_PROTOCOL *HttpInstance\r
235 );\r
236\r
237/**\r
b659408b 238 Create event for the TCP receive token which is used to receive HTTP body.\r
47f51a06
YT
239\r
240 @param[in] Wrap Point to HTTP token's wrap data.\r
241\r
242 @retval EFI_SUCCESS The events is created successfully.\r
243 @retval others Other error as indicated.\r
244\r
245**/\r
246EFI_STATUS\r
b659408b 247HttpCreateTcpRxEvent (\r
47f51a06
YT
248 IN HTTP_TOKEN_WRAP *Wrap \r
249 );\r
250\r
b659408b
ZL
251/**\r
252 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.\r
253\r
254 @param[in] Wrap Pointer to HTTP token's wrap data.\r
255 \r
256**/\r
257VOID\r
258HttpCloseTcpRxEvent (\r
259 IN HTTP_TOKEN_WRAP *Wrap\r
260 );\r
261\r
47f51a06
YT
262/**\r
263 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.\r
264\r
47f51a06 265 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
b659408b 266 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.\r
47f51a06
YT
267\r
268 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully. \r
269 @retval Others Other error as indicated.\r
270\r
271**/\r
272EFI_STATUS\r
273HttpInitProtocol (\r
b659408b
ZL
274 IN OUT HTTP_PROTOCOL *HttpInstance,\r
275 IN BOOLEAN IpVersion\r
47f51a06
YT
276 );\r
277\r
278/**\r
279 Clean up the HTTP child, release all the resources used by it.\r
280\r
281 @param[in] HttpInstance The HTTP child to clean up.\r
282\r
283**/\r
284VOID\r
285HttpCleanProtocol (\r
286 IN HTTP_PROTOCOL *HttpInstance\r
287 );\r
288\r
289/**\r
290 Establish TCP connection with HTTP server.\r
291\r
292 @param[in] HttpInstance The HTTP instance private data.\r
293\r
294 @retval EFI_SUCCESS The TCP connection is established.\r
295 @retval Others Other error as indicated.\r
296\r
297**/\r
298EFI_STATUS\r
299HttpCreateConnection (\r
300 IN HTTP_PROTOCOL *HttpInstance\r
301 );\r
302\r
303/**\r
304 Close existing TCP connection.\r
305\r
306 @param[in] HttpInstance The HTTP instance private data.\r
307\r
308 @retval EFI_SUCCESS The TCP connection is closed.\r
309 @retval Others Other error as indicated.\r
310\r
311**/\r
312EFI_STATUS\r
313HttpCloseConnection (\r
314 IN HTTP_PROTOCOL *HttpInstance\r
315 );\r
316\r
317/**\r
318 Configure TCP4 protocol child.\r
319\r
320 @param[in] HttpInstance The HTTP instance private data.\r
321 @param[in] Wrap The HTTP token's wrap data.\r
322\r
323 @retval EFI_SUCCESS The TCP4 protocol child is configured.\r
324 @retval Others Other error as indicated.\r
325\r
326**/\r
327EFI_STATUS\r
328HttpConfigureTcp4 (\r
329 IN HTTP_PROTOCOL *HttpInstance,\r
330 IN HTTP_TOKEN_WRAP *Wrap\r
331 );\r
332\r
b659408b
ZL
333/**\r
334 Configure TCP6 protocol child.\r
335\r
336 @param[in] HttpInstance The HTTP instance private data.\r
337 @param[in] Wrap The HTTP token's wrap data.\r
338\r
339 @retval EFI_SUCCESS The TCP6 protocol child is configured.\r
340 @retval Others Other error as indicated.\r
341\r
342**/\r
343EFI_STATUS\r
344HttpConfigureTcp6 (\r
345 IN HTTP_PROTOCOL *HttpInstance,\r
346 IN HTTP_TOKEN_WRAP *Wrap\r
347 );\r
348\r
47f51a06
YT
349/**\r
350 Check existing TCP connection, if in error state, receover TCP4 connection.\r
351\r
352 @param[in] HttpInstance The HTTP instance private data.\r
353\r
354 @retval EFI_SUCCESS The TCP connection is established.\r
355 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.\r
356 @retval Others Other error as indicated.\r
357\r
358**/\r
359EFI_STATUS\r
360HttpConnectTcp4 (\r
361 IN HTTP_PROTOCOL *HttpInstance\r
362 );\r
363\r
364/**\r
b659408b
ZL
365 Check existing TCP connection, if in error state, recover TCP6 connection.\r
366\r
367 @param[in] HttpInstance The HTTP instance private data.\r
368\r
369 @retval EFI_SUCCESS The TCP connection is established.\r
370 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.\r
371 @retval Others Other error as indicated.\r
372\r
373**/\r
374EFI_STATUS\r
375HttpConnectTcp6 (\r
376 IN HTTP_PROTOCOL *HttpInstance\r
377 );\r
378\r
379/**\r
380 Send the HTTP message through TCP4 or TCP6.\r
47f51a06
YT
381\r
382 @param[in] HttpInstance The HTTP instance private data.\r
383 @param[in] Wrap The HTTP token's wrap data.\r
384 @param[in] TxString Buffer containing the HTTP message string.\r
385 @param[in] TxStringLen Length of the HTTP message string in bytes.\r
386\r
387 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.\r
388 @retval Others Other error as indicated.\r
389\r
390**/\r
391EFI_STATUS\r
b659408b 392HttpTransmitTcp (\r
47f51a06
YT
393 IN HTTP_PROTOCOL *HttpInstance,\r
394 IN HTTP_TOKEN_WRAP *Wrap,\r
395 IN UINT8 *TxString,\r
396 IN UINTN TxStringLen\r
397 );\r
398\r
399/**\r
400 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined \r
401 in UEFI 2.5 specification.\r
402\r
403 @param[in] StatusCode The status code value in HTTP message.\r
404\r
405 @return Value defined in EFI_HTTP_STATUS_CODE .\r
406\r
407**/\r
408EFI_HTTP_STATUS_CODE\r
409HttpMappingToStatusCode (\r
410 IN UINTN StatusCode\r
411 );\r
412\r
413/**\r
414 Check whether the user's token or event has already\r
b659408b 415 been enqueue on HTTP Tx or Rx Token list.\r
47f51a06
YT
416\r
417 @param[in] Map The container of either user's transmit or receive\r
418 token.\r
419 @param[in] Item Current item to check against.\r
420 @param[in] Context The Token to check againist.\r
421\r
422 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP\r
423 @retval EFI_SUCCESS The current item isn't the same token/event as the\r
424 context.\r
425\r
426**/\r
427EFI_STATUS\r
428EFIAPI\r
429HttpTokenExist (\r
430 IN NET_MAP *Map,\r
431 IN NET_MAP_ITEM *Item,\r
432 IN VOID *Context\r
433 );\r
434\r
435/**\r
b659408b 436 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.\r
47f51a06
YT
437\r
438 @param[in] Map The container of TxToken.\r
439 @param[in] Item Current item to check against.\r
440 @param[in] Context The Token to check againist.\r
441\r
442 @retval EFI_NOT_READY The HTTP message is still queued in the list.\r
443 @retval EFI_SUCCESS The HTTP message has been sent out.\r
444\r
445**/\r
446EFI_STATUS\r
447EFIAPI\r
448HttpTcpNotReady (\r
449 IN NET_MAP *Map,\r
450 IN NET_MAP_ITEM *Item,\r
451 IN VOID *Context\r
452 );\r
453\r
b659408b
ZL
454/**\r
455 Initialize TCP related data.\r
456\r
457 @param[in] HttpInstance The HTTP instance private data.\r
458 @param[in] Wrap The HTTP token's wrap data.\r
a2e61982 459 @param[in] Configure The Flag indicates whether the first time to initialize Tcp.\r
b659408b
ZL
460\r
461 @retval EFI_SUCCESS The initialization of TCP instance is done. \r
462 @retval Others Other error as indicated.\r
463\r
464**/\r
465EFI_STATUS\r
466HttpInitTcp (\r
467 IN HTTP_PROTOCOL *HttpInstance,\r
a2e61982
ZL
468 IN HTTP_TOKEN_WRAP *Wrap,\r
469 IN BOOLEAN Configure\r
b659408b
ZL
470 );\r
471\r
47f51a06
YT
472/**\r
473 Transmit the HTTP mssage by processing the associated HTTP token.\r
474\r
b659408b 475 @param[in] Map The container of TxToken or Tx6Token.\r
47f51a06
YT
476 @param[in] Item Current item to check against.\r
477 @param[in] Context The Token to check againist.\r
478\r
479 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
480 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit\r
481 queue.\r
482\r
483**/\r
484EFI_STATUS\r
485EFIAPI\r
486HttpTcpTransmit (\r
487 IN NET_MAP *Map,\r
488 IN NET_MAP_ITEM *Item,\r
489 IN VOID *Context\r
490 );\r
491\r
492/**\r
493 Receive the HTTP response by processing the associated HTTP token.\r
494\r
b659408b 495 @param[in] Map The container of Rx4Token or Rx6Token.\r
47f51a06
YT
496 @param[in] Item Current item to check against.\r
497 @param[in] Context The Token to check againist.\r
498\r
499 @retval EFI_SUCCESS The HTTP response is queued into TCP receive\r
500 queue.\r
501 @retval Others Other error as indicated.\r
502\r
503**/\r
504EFI_STATUS\r
505EFIAPI\r
506HttpTcpReceive (\r
507 IN NET_MAP *Map,\r
508 IN NET_MAP_ITEM *Item,\r
509 IN VOID *Context\r
510 );\r
511\r
b659408b
ZL
512/**\r
513 Receive the HTTP header by processing the associated HTTP token.\r
514\r
515 @param[in] HttpInstance The HTTP instance private data.\r
516 @param[in, out] SizeofHeaders The HTTP header length.\r
517 @param[in, out] BufferSize The size of buffer to cacahe the header message.\r
518\r
519 @retval EFI_SUCCESS The HTTP header is received. \r
520 @retval Others Other errors as indicated.\r
521\r
522**/\r
523EFI_STATUS\r
524HttpTcpReceiveHeader (\r
525 IN HTTP_PROTOCOL *HttpInstance,\r
526 IN OUT UINTN *SizeofHeaders,\r
527 IN OUT UINTN *BufferSize\r
528 );\r
529\r
530/**\r
531 Receive the HTTP body by processing the associated HTTP token.\r
532\r
533 @param[in] Wrap The HTTP token's wrap data.\r
534 @param[in] HttpMsg The HTTP message data.\r
535\r
536 @retval EFI_SUCCESS The HTTP body is received. \r
537 @retval Others Other error as indicated.\r
538\r
539**/\r
540EFI_STATUS\r
541HttpTcpReceiveBody (\r
542 IN HTTP_TOKEN_WRAP *Wrap,\r
543 IN EFI_HTTP_MESSAGE *HttpMsg\r
544 );\r
545\r
546/**\r
547 Clean up Tcp Tokens while the Tcp transmission error occurs.\r
548\r
549 @param[in] Wrap Pointer to HTTP token's wrap data.\r
550 \r
551**/\r
552VOID\r
553HttpTcpTokenCleanup (\r
554 IN HTTP_TOKEN_WRAP *Wrap\r
555 );\r
556\r
47f51a06
YT
557/**\r
558 Generate HTTP request string.\r
559\r
560 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
561 @param[in] Message Pointer to storage containing HTTP message data.\r
562 @param[in] Url The URL of a remote host.\r
563\r
564 @return Pointer to the created HTTP request string.\r
565 @return NULL if any error occured.\r
566\r
567**/\r
568CHAR8 *\r
569HttpGenRequestString (\r
570 IN HTTP_PROTOCOL *HttpInstance,\r
571 IN EFI_HTTP_MESSAGE *Message,\r
572 IN CHAR8 *Url\r
573 );\r
574\r
575/**\r
576 The work function of EfiHttpResponse().\r
577\r
578 @param[in] Wrap Pointer to HTTP token's wrap data.\r
579\r
580 @retval EFI_SUCCESS Allocation succeeded.\r
581 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.\r
582 @retval EFI_NOT_READY Can't find a corresponding TxToken.\r
583\r
584**/\r
585EFI_STATUS\r
586HttpResponseWorker (\r
587 IN HTTP_TOKEN_WRAP *Wrap\r
588 );\r
589\r
590#endif\r