2 The header files of miscellaneous routines for HttpDxe driver.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef __EFI_HTTP_PROTO_H__
17 #define __EFI_HTTP_PROTO_H__
19 #define DEF_BUF_LEN 2048
21 #define HTTP_SERVICE_SIGNATURE SIGNATURE_32('H', 't', 't', 'S')
23 #define HTTP_SERVICE_FROM_PROTOCOL(a) \
28 HTTP_SERVICE_SIGNATURE \
33 // The state of HTTP protocol. It starts from UNCONFIGED.
35 #define HTTP_STATE_UNCONFIGED 0
36 #define HTTP_STATE_HTTP_CONFIGED 1
37 #define HTTP_STATE_TCP_CONFIGED 2
38 #define HTTP_STATE_TCP_UNCONFIGED 3
39 #define HTTP_STATE_TCP_CONNECTED 4
40 #define HTTP_STATE_TCP_CLOSED 5
43 // TCP configured data.
45 #define HTTP_TOS_DEAULT 8
46 #define HTTP_TTL_DEAULT 255
47 #define HTTP_BUFFER_SIZE_DEAULT 65535
48 #define HTTP_MAX_SYN_BACK_LOG 5
49 #define HTTP_CONNECTION_TIMEOUT 60
50 #define HTTP_RESPONSE_TIMEOUT 5
51 #define HTTP_DATA_RETRIES 12
52 #define HTTP_FIN_TIMEOUT 2
53 #define HTTP_KEEP_ALIVE_PROBES 6
54 #define HTTP_KEEP_ALIVE_TIME 7200
55 #define HTTP_KEEP_ALIVE_INTERVAL 30
57 #define HTTP_URL_BUFFER_LEN 4096
59 typedef struct _HTTP_SERVICE
{
61 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
62 EFI_HANDLE ImageHandle
;
63 EFI_HANDLE ControllerHandle
;
64 EFI_HANDLE Tcp4ChildHandle
;
65 EFI_HANDLE Tcp6ChildHandle
;
66 LIST_ENTRY ChildrenList
;
72 EFI_TCP4_IO_TOKEN Tx4Token
;
73 EFI_TCP4_TRANSMIT_DATA Tx4Data
;
74 EFI_TCP6_IO_TOKEN Tx6Token
;
75 EFI_TCP6_TRANSMIT_DATA Tx6Data
;
76 EFI_TCP4_IO_TOKEN Rx4Token
;
77 EFI_TCP4_RECEIVE_DATA Rx4Data
;
78 EFI_TCP6_IO_TOKEN Rx6Token
;
79 EFI_TCP6_RECEIVE_DATA Rx6Data
;
83 EFI_HTTP_METHOD Method
;
84 } HTTP_TCP_TOKEN_WRAP
;
86 typedef struct _HTTP_PROTOCOL
{
88 EFI_HTTP_PROTOCOL Http
;
90 HTTP_SERVICE
*Service
;
91 LIST_ENTRY Link
; // Link to all HTTP instance from the service.
97 EFI_EVENT TimeoutEvent
;
99 EFI_HANDLE Tcp4ChildHandle
;
100 EFI_TCP4_PROTOCOL
*Tcp4
;
101 EFI_TCP4_CONFIG_DATA Tcp4CfgData
;
102 EFI_TCP4_OPTION Tcp4Option
;
104 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken
;
105 BOOLEAN IsTcp4ConnDone
;
106 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken
;
107 BOOLEAN IsTcp4CloseDone
;
110 EFI_IPv4_ADDRESS RemoteAddr
;
112 EFI_HANDLE Tcp6ChildHandle
;
113 EFI_TCP6_PROTOCOL
*Tcp6
;
114 EFI_TCP6_CONFIG_DATA Tcp6CfgData
;
115 EFI_TCP6_OPTION Tcp6Option
;
117 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken
;
118 BOOLEAN IsTcp6ConnDone
;
119 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken
;
120 BOOLEAN IsTcp6CloseDone
;
121 EFI_IPv6_ADDRESS RemoteIpv6Addr
;
124 // Rx4Token or Rx6Token used for receiving HTTP header.
126 EFI_TCP4_IO_TOKEN Rx4Token
;
127 EFI_TCP4_RECEIVE_DATA Rx4Data
;
128 EFI_TCP6_IO_TOKEN Rx6Token
;
129 EFI_TCP6_RECEIVE_DATA Rx6Data
;
140 // HTTP message-body parser.
144 EFI_HTTP_VERSION HttpVersion
;
145 UINT32 TimeOutMillisec
;
146 BOOLEAN LocalAddressIsIPv6
;
148 EFI_HTTPv4_ACCESS_POINT IPv4Node
;
149 EFI_HTTPv6_ACCESS_POINT Ipv6Node
;
158 EFI_HTTP_TOKEN
*HttpToken
;
159 HTTP_PROTOCOL
*HttpInstance
;
160 HTTP_TCP_TOKEN_WRAP TcpWrap
;
164 #define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')
166 #define HTTP_INSTANCE_FROM_PROTOCOL(a) \
171 HTTP_PROTOCOL_SIGNATURE \
175 The common notify function used in HTTP driver.
177 @param[in] Event The event signaled.
178 @param[in] Context The context.
189 Create events for the TCP connection token and TCP close token.
191 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
193 @retval EFI_SUCCESS The events are created successfully.
194 @retval others Other error as indicated.
198 HttpCreateTcpConnCloseEvent (
199 IN HTTP_PROTOCOL
*HttpInstance
203 Close events in the TCP connection token and TCP close token.
205 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
209 HttpCloseTcpConnCloseEvent (
210 IN HTTP_PROTOCOL
*HttpInstance
214 Create event for the TCP transmit token.
216 @param[in] Wrap Point to HTTP token's wrap data.
218 @retval EFI_SUCCESS The events is created successfully.
219 @retval others Other error as indicated.
223 HttpCreateTcpTxEvent (
224 IN HTTP_TOKEN_WRAP
*Wrap
228 Create event for the TCP receive token which is used to receive HTTP header.
230 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
232 @retval EFI_SUCCESS The events is created successfully.
233 @retval others Other error as indicated.
237 HttpCreateTcpRxEventForHeader (
238 IN HTTP_PROTOCOL
*HttpInstance
242 Create event for the TCP receive token which is used to receive HTTP body.
244 @param[in] Wrap Point to HTTP token's wrap data.
246 @retval EFI_SUCCESS The events is created successfully.
247 @retval others Other error as indicated.
251 HttpCreateTcpRxEvent (
252 IN HTTP_TOKEN_WRAP
*Wrap
256 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.
258 @param[in] Wrap Pointer to HTTP token's wrap data.
262 HttpCloseTcpRxEvent (
263 IN HTTP_TOKEN_WRAP
*Wrap
267 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.
269 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
270 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.
272 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully.
273 @retval Others Other error as indicated.
278 IN OUT HTTP_PROTOCOL
*HttpInstance
,
283 Clean up the HTTP child, release all the resources used by it.
285 @param[in] HttpInstance The HTTP child to clean up.
290 IN HTTP_PROTOCOL
*HttpInstance
294 Establish TCP connection with HTTP server.
296 @param[in] HttpInstance The HTTP instance private data.
298 @retval EFI_SUCCESS The TCP connection is established.
299 @retval Others Other error as indicated.
303 HttpCreateConnection (
304 IN HTTP_PROTOCOL
*HttpInstance
308 Close existing TCP connection.
310 @param[in] HttpInstance The HTTP instance private data.
312 @retval EFI_SUCCESS The TCP connection is closed.
313 @retval Others Other error as indicated.
317 HttpCloseConnection (
318 IN HTTP_PROTOCOL
*HttpInstance
322 Configure TCP4 protocol child.
324 @param[in] HttpInstance The HTTP instance private data.
325 @param[in] Wrap The HTTP token's wrap data.
327 @retval EFI_SUCCESS The TCP4 protocol child is configured.
328 @retval Others Other error as indicated.
333 IN HTTP_PROTOCOL
*HttpInstance
,
334 IN HTTP_TOKEN_WRAP
*Wrap
338 Configure TCP6 protocol child.
340 @param[in] HttpInstance The HTTP instance private data.
341 @param[in] Wrap The HTTP token's wrap data.
343 @retval EFI_SUCCESS The TCP6 protocol child is configured.
344 @retval Others Other error as indicated.
349 IN HTTP_PROTOCOL
*HttpInstance
,
350 IN HTTP_TOKEN_WRAP
*Wrap
354 Check existing TCP connection, if in error state, receover TCP4 connection.
356 @param[in] HttpInstance The HTTP instance private data.
358 @retval EFI_SUCCESS The TCP connection is established.
359 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.
360 @retval Others Other error as indicated.
365 IN HTTP_PROTOCOL
*HttpInstance
369 Check existing TCP connection, if in error state, recover TCP6 connection.
371 @param[in] HttpInstance The HTTP instance private data.
373 @retval EFI_SUCCESS The TCP connection is established.
374 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.
375 @retval Others Other error as indicated.
380 IN HTTP_PROTOCOL
*HttpInstance
384 Send the HTTP message through TCP4 or TCP6.
386 @param[in] HttpInstance The HTTP instance private data.
387 @param[in] Wrap The HTTP token's wrap data.
388 @param[in] TxString Buffer containing the HTTP message string.
389 @param[in] TxStringLen Length of the HTTP message string in bytes.
391 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.
392 @retval Others Other error as indicated.
397 IN HTTP_PROTOCOL
*HttpInstance
,
398 IN HTTP_TOKEN_WRAP
*Wrap
,
404 Check whether the user's token or event has already
405 been enqueue on HTTP Tx or Rx Token list.
407 @param[in] Map The container of either user's transmit or receive
409 @param[in] Item Current item to check against.
410 @param[in] Context The Token to check againist.
412 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
413 @retval EFI_SUCCESS The current item isn't the same token/event as the
421 IN NET_MAP_ITEM
*Item
,
426 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.
428 @param[in] Map The container of TxToken.
429 @param[in] Item Current item to check against.
430 @param[in] Context The Token to check againist.
432 @retval EFI_NOT_READY The HTTP message is still queued in the list.
433 @retval EFI_SUCCESS The HTTP message has been sent out.
440 IN NET_MAP_ITEM
*Item
,
445 Initialize TCP related data.
447 @param[in] HttpInstance The HTTP instance private data.
448 @param[in] Wrap The HTTP token's wrap data.
449 @param[in] Configure The Flag indicates whether the first time to initialize Tcp.
451 @retval EFI_SUCCESS The initialization of TCP instance is done.
452 @retval Others Other error as indicated.
457 IN HTTP_PROTOCOL
*HttpInstance
,
458 IN HTTP_TOKEN_WRAP
*Wrap
,
463 Transmit the HTTP mssage by processing the associated HTTP token.
465 @param[in] Map The container of TxToken or Tx6Token.
466 @param[in] Item Current item to check against.
467 @param[in] Context The Token to check againist.
469 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
470 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit
478 IN NET_MAP_ITEM
*Item
,
483 Receive the HTTP response by processing the associated HTTP token.
485 @param[in] Map The container of Rx4Token or Rx6Token.
486 @param[in] Item Current item to check against.
487 @param[in] Context The Token to check againist.
489 @retval EFI_SUCCESS The HTTP response is queued into TCP receive
491 @retval Others Other error as indicated.
498 IN NET_MAP_ITEM
*Item
,
503 Receive the HTTP header by processing the associated HTTP token.
505 @param[in] HttpInstance The HTTP instance private data.
506 @param[in, out] SizeofHeaders The HTTP header length.
507 @param[in, out] BufferSize The size of buffer to cacahe the header message.
508 @param[in] Timeout The time to wait for receiving the header packet.
510 @retval EFI_SUCCESS The HTTP header is received.
511 @retval Others Other errors as indicated.
515 HttpTcpReceiveHeader (
516 IN HTTP_PROTOCOL
*HttpInstance
,
517 IN OUT UINTN
*SizeofHeaders
,
518 IN OUT UINTN
*BufferSize
,
523 Receive the HTTP body by processing the associated HTTP token.
525 @param[in] Wrap The HTTP token's wrap data.
526 @param[in] HttpMsg The HTTP message data.
527 @param[in] Timeout The time to wait for receiving the body packet.
529 @retval EFI_SUCCESS The HTTP body is received.
530 @retval Others Other error as indicated.
535 IN HTTP_TOKEN_WRAP
*Wrap
,
536 IN EFI_HTTP_MESSAGE
*HttpMsg
,
541 Clean up Tcp Tokens while the Tcp transmission error occurs.
543 @param[in] Wrap Pointer to HTTP token's wrap data.
547 HttpTcpTokenCleanup (
548 IN HTTP_TOKEN_WRAP
*Wrap
552 The work function of EfiHttpResponse().
554 @param[in] Wrap Pointer to HTTP token's wrap data.
556 @retval EFI_SUCCESS Allocation succeeded.
557 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
558 @retval EFI_NOT_READY Can't find a corresponding TxToken.
563 IN HTTP_TOKEN_WRAP
*Wrap