2 The header files of miscellaneous routines for HttpDxe driver.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __EFI_HTTP_PROTO_H__
16 #define __EFI_HTTP_PROTO_H__
18 #define DEF_BUF_LEN 2048
20 #define HTTP_SERVICE_SIGNATURE SIGNATURE_32('H', 't', 't', 'S')
22 #define HTTP_SERVICE_FROM_PROTOCOL(a) \
27 HTTP_SERVICE_SIGNATURE \
32 // The state of HTTP protocol. It starts from UNCONFIGED.
34 #define HTTP_STATE_UNCONFIGED 0
35 #define HTTP_STATE_HTTP_CONFIGED 1
36 #define HTTP_STATE_TCP_CONFIGED 2
37 #define HTTP_STATE_TCP_UNCONFIGED 3
38 #define HTTP_STATE_TCP_CONNECTED 4
39 #define HTTP_STATE_TCP_CLOSED 5
42 // TCP configured data.
44 #define HTTP_TOS_DEAULT 8
45 #define HTTP_TTL_DEAULT 255
46 #define HTTP_BUFFER_SIZE_DEAULT 65535
47 #define HTTP_MAX_SYN_BACK_LOG 5
48 #define HTTP_CONNECTION_TIMEOUT 60
49 #define HTTP_DATA_RETRIES 12
50 #define HTTP_FIN_TIMEOUT 2
51 #define HTTP_KEEP_ALIVE_PROBES 6
52 #define HTTP_KEEP_ALIVE_TIME 7200
53 #define HTTP_KEEP_ALIVE_INTERVAL 30
55 #define HTTP_URL_BUFFER_LEN 4096
57 typedef struct _HTTP_SERVICE
{
59 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
60 EFI_HANDLE ImageHandle
;
61 EFI_HANDLE ControllerHandle
;
62 EFI_HANDLE Tcp4ChildHandle
;
63 EFI_HANDLE Tcp6ChildHandle
;
64 LIST_ENTRY ChildrenList
;
70 EFI_TCP4_IO_TOKEN Tx4Token
;
71 EFI_TCP4_TRANSMIT_DATA Tx4Data
;
72 EFI_TCP6_IO_TOKEN Tx6Token
;
73 EFI_TCP6_TRANSMIT_DATA Tx6Data
;
74 EFI_TCP4_IO_TOKEN Rx4Token
;
75 EFI_TCP4_RECEIVE_DATA Rx4Data
;
76 EFI_TCP6_IO_TOKEN Rx6Token
;
77 EFI_TCP6_RECEIVE_DATA Rx6Data
;
81 EFI_HTTP_METHOD Method
;
82 } HTTP_TCP_TOKEN_WRAP
;
84 typedef struct _HTTP_PROTOCOL
{
86 EFI_HTTP_PROTOCOL Http
;
88 HTTP_SERVICE
*Service
;
89 LIST_ENTRY Link
; // Link to all HTTP instance from the service.
95 EFI_HANDLE Tcp4ChildHandle
;
96 EFI_TCP4_PROTOCOL
*Tcp4
;
97 EFI_TCP4_CONFIG_DATA Tcp4CfgData
;
98 EFI_TCP4_OPTION Tcp4Option
;
100 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken
;
101 BOOLEAN IsTcp4ConnDone
;
102 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken
;
103 BOOLEAN IsTcp4CloseDone
;
106 EFI_IPv4_ADDRESS RemoteAddr
;
108 EFI_HANDLE Tcp6ChildHandle
;
109 EFI_TCP6_PROTOCOL
*Tcp6
;
110 EFI_TCP6_CONFIG_DATA Tcp6CfgData
;
111 EFI_TCP6_OPTION Tcp6Option
;
113 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken
;
114 BOOLEAN IsTcp6ConnDone
;
115 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken
;
116 BOOLEAN IsTcp6CloseDone
;
117 EFI_IPv6_ADDRESS RemoteIpv6Addr
;
122 // Rx4Token or Rx6Token used for receiving HTTP header.
124 EFI_TCP4_IO_TOKEN Rx4Token
;
125 EFI_TCP4_RECEIVE_DATA Rx4Data
;
126 EFI_TCP6_IO_TOKEN Rx6Token
;
127 EFI_TCP6_RECEIVE_DATA Rx6Data
;
138 // HTTP message-body parser.
142 EFI_HTTP_VERSION HttpVersion
;
143 UINT32 TimeOutMillisec
;
144 BOOLEAN LocalAddressIsIPv6
;
146 EFI_HTTPv4_ACCESS_POINT IPv4Node
;
147 EFI_HTTPv6_ACCESS_POINT Ipv6Node
;
156 EFI_HTTP_TOKEN
*HttpToken
;
157 HTTP_PROTOCOL
*HttpInstance
;
158 HTTP_TCP_TOKEN_WRAP TcpWrap
;
162 #define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')
164 #define HTTP_INSTANCE_FROM_PROTOCOL(a) \
169 HTTP_PROTOCOL_SIGNATURE \
173 The common notify function used in HTTP driver.
175 @param[in] Event The event signaled.
176 @param[in] Context The context.
187 Create events for the TCP connection token and TCP close token.
189 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
191 @retval EFI_SUCCESS The events are created successfully.
192 @retval others Other error as indicated.
196 HttpCreateTcpConnCloseEvent (
197 IN HTTP_PROTOCOL
*HttpInstance
201 Close events in the TCP connection token and TCP close token.
203 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
207 HttpCloseTcpConnCloseEvent (
208 IN HTTP_PROTOCOL
*HttpInstance
212 Create event for the TCP transmit token.
214 @param[in] Wrap Point to HTTP token's wrap data.
216 @retval EFI_SUCCESS The events is created successfully.
217 @retval others Other error as indicated.
221 HttpCreateTcpTxEvent (
222 IN HTTP_TOKEN_WRAP
*Wrap
226 Create event for the TCP receive token which is used to receive HTTP header.
228 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
230 @retval EFI_SUCCESS The events is created successfully.
231 @retval others Other error as indicated.
235 HttpCreateTcpRxEventForHeader (
236 IN HTTP_PROTOCOL
*HttpInstance
240 Create event for the TCP receive token which is used to receive HTTP body.
242 @param[in] Wrap Point to HTTP token's wrap data.
244 @retval EFI_SUCCESS The events is created successfully.
245 @retval others Other error as indicated.
249 HttpCreateTcpRxEvent (
250 IN HTTP_TOKEN_WRAP
*Wrap
254 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.
256 @param[in] Wrap Pointer to HTTP token's wrap data.
260 HttpCloseTcpRxEvent (
261 IN HTTP_TOKEN_WRAP
*Wrap
265 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.
267 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
268 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.
270 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully.
271 @retval Others Other error as indicated.
276 IN OUT HTTP_PROTOCOL
*HttpInstance
,
281 Clean up the HTTP child, release all the resources used by it.
283 @param[in] HttpInstance The HTTP child to clean up.
288 IN HTTP_PROTOCOL
*HttpInstance
292 Establish TCP connection with HTTP server.
294 @param[in] HttpInstance The HTTP instance private data.
296 @retval EFI_SUCCESS The TCP connection is established.
297 @retval Others Other error as indicated.
301 HttpCreateConnection (
302 IN HTTP_PROTOCOL
*HttpInstance
306 Close existing TCP connection.
308 @param[in] HttpInstance The HTTP instance private data.
310 @retval EFI_SUCCESS The TCP connection is closed.
311 @retval Others Other error as indicated.
315 HttpCloseConnection (
316 IN HTTP_PROTOCOL
*HttpInstance
320 Configure TCP4 protocol child.
322 @param[in] HttpInstance The HTTP instance private data.
323 @param[in] Wrap The HTTP token's wrap data.
325 @retval EFI_SUCCESS The TCP4 protocol child is configured.
326 @retval Others Other error as indicated.
331 IN HTTP_PROTOCOL
*HttpInstance
,
332 IN HTTP_TOKEN_WRAP
*Wrap
336 Configure TCP6 protocol child.
338 @param[in] HttpInstance The HTTP instance private data.
339 @param[in] Wrap The HTTP token's wrap data.
341 @retval EFI_SUCCESS The TCP6 protocol child is configured.
342 @retval Others Other error as indicated.
347 IN HTTP_PROTOCOL
*HttpInstance
,
348 IN HTTP_TOKEN_WRAP
*Wrap
352 Check existing TCP connection, if in error state, receover TCP4 connection.
354 @param[in] HttpInstance The HTTP instance private data.
356 @retval EFI_SUCCESS The TCP connection is established.
357 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.
358 @retval Others Other error as indicated.
363 IN HTTP_PROTOCOL
*HttpInstance
367 Check existing TCP connection, if in error state, recover TCP6 connection.
369 @param[in] HttpInstance The HTTP instance private data.
371 @retval EFI_SUCCESS The TCP connection is established.
372 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.
373 @retval Others Other error as indicated.
378 IN HTTP_PROTOCOL
*HttpInstance
382 Send the HTTP message through TCP4 or TCP6.
384 @param[in] HttpInstance The HTTP instance private data.
385 @param[in] Wrap The HTTP token's wrap data.
386 @param[in] TxString Buffer containing the HTTP message string.
387 @param[in] TxStringLen Length of the HTTP message string in bytes.
389 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.
390 @retval Others Other error as indicated.
395 IN HTTP_PROTOCOL
*HttpInstance
,
396 IN HTTP_TOKEN_WRAP
*Wrap
,
402 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
403 in UEFI 2.5 specification.
405 @param[in] StatusCode The status code value in HTTP message.
407 @return Value defined in EFI_HTTP_STATUS_CODE .
411 HttpMappingToStatusCode (
416 Check whether the user's token or event has already
417 been enqueue on HTTP Tx or Rx Token list.
419 @param[in] Map The container of either user's transmit or receive
421 @param[in] Item Current item to check against.
422 @param[in] Context The Token to check againist.
424 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
425 @retval EFI_SUCCESS The current item isn't the same token/event as the
433 IN NET_MAP_ITEM
*Item
,
438 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.
440 @param[in] Map The container of TxToken.
441 @param[in] Item Current item to check against.
442 @param[in] Context The Token to check againist.
444 @retval EFI_NOT_READY The HTTP message is still queued in the list.
445 @retval EFI_SUCCESS The HTTP message has been sent out.
452 IN NET_MAP_ITEM
*Item
,
457 Initialize TCP related data.
459 @param[in] HttpInstance The HTTP instance private data.
460 @param[in] Wrap The HTTP token's wrap data.
461 @param[in] Configure The Flag indicates whether the first time to initialize Tcp.
463 @retval EFI_SUCCESS The initialization of TCP instance is done.
464 @retval Others Other error as indicated.
469 IN HTTP_PROTOCOL
*HttpInstance
,
470 IN HTTP_TOKEN_WRAP
*Wrap
,
475 Transmit the HTTP mssage by processing the associated HTTP token.
477 @param[in] Map The container of TxToken or Tx6Token.
478 @param[in] Item Current item to check against.
479 @param[in] Context The Token to check againist.
481 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
482 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit
490 IN NET_MAP_ITEM
*Item
,
495 Receive the HTTP response by processing the associated HTTP token.
497 @param[in] Map The container of Rx4Token or Rx6Token.
498 @param[in] Item Current item to check against.
499 @param[in] Context The Token to check againist.
501 @retval EFI_SUCCESS The HTTP response is queued into TCP receive
503 @retval Others Other error as indicated.
510 IN NET_MAP_ITEM
*Item
,
515 Receive the HTTP header by processing the associated HTTP token.
517 @param[in] HttpInstance The HTTP instance private data.
518 @param[in, out] SizeofHeaders The HTTP header length.
519 @param[in, out] BufferSize The size of buffer to cacahe the header message.
521 @retval EFI_SUCCESS The HTTP header is received.
522 @retval Others Other errors as indicated.
526 HttpTcpReceiveHeader (
527 IN HTTP_PROTOCOL
*HttpInstance
,
528 IN OUT UINTN
*SizeofHeaders
,
529 IN OUT UINTN
*BufferSize
533 Receive the HTTP body by processing the associated HTTP token.
535 @param[in] Wrap The HTTP token's wrap data.
536 @param[in] HttpMsg The HTTP message data.
538 @retval EFI_SUCCESS The HTTP body is received.
539 @retval Others Other error as indicated.
544 IN HTTP_TOKEN_WRAP
*Wrap
,
545 IN EFI_HTTP_MESSAGE
*HttpMsg
549 Clean up Tcp Tokens while the Tcp transmission error occurs.
551 @param[in] Wrap Pointer to HTTP token's wrap data.
555 HttpTcpTokenCleanup (
556 IN HTTP_TOKEN_WRAP
*Wrap
560 Generate HTTP request string.
562 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
563 @param[in] Message Pointer to storage containing HTTP message data.
564 @param[in] Url The URL of a remote host.
566 @return Pointer to the created HTTP request string.
567 @return NULL if any error occured.
571 HttpGenRequestString (
572 IN HTTP_PROTOCOL
*HttpInstance
,
573 IN EFI_HTTP_MESSAGE
*Message
,
578 The work function of EfiHttpResponse().
580 @param[in] Wrap Pointer to HTTP token's wrap data.
582 @retval EFI_SUCCESS Allocation succeeded.
583 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
584 @retval EFI_NOT_READY Can't find a corresponding TxToken.
589 IN HTTP_TOKEN_WRAP
*Wrap