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.
94 EFI_HTTP_METHOD Method
;
98 EFI_EVENT TimeoutEvent
;
100 EFI_HANDLE Tcp4ChildHandle
;
101 EFI_TCP4_PROTOCOL
*Tcp4
;
102 EFI_TCP4_CONFIG_DATA Tcp4CfgData
;
103 EFI_TCP4_OPTION Tcp4Option
;
105 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken
;
106 BOOLEAN IsTcp4ConnDone
;
107 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken
;
108 BOOLEAN IsTcp4CloseDone
;
111 EFI_IPv4_ADDRESS RemoteAddr
;
113 EFI_HANDLE Tcp6ChildHandle
;
114 EFI_TCP6_PROTOCOL
*Tcp6
;
115 EFI_TCP6_CONFIG_DATA Tcp6CfgData
;
116 EFI_TCP6_OPTION Tcp6Option
;
118 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken
;
119 BOOLEAN IsTcp6ConnDone
;
120 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken
;
121 BOOLEAN IsTcp6CloseDone
;
122 EFI_IPv6_ADDRESS RemoteIpv6Addr
;
125 // Rx4Token or Rx6Token used for receiving HTTP header.
127 EFI_TCP4_IO_TOKEN Rx4Token
;
128 EFI_TCP4_RECEIVE_DATA Rx4Data
;
129 EFI_TCP6_IO_TOKEN Rx6Token
;
130 EFI_TCP6_RECEIVE_DATA Rx6Data
;
141 // HTTP message-body parser.
145 EFI_HTTP_VERSION HttpVersion
;
146 UINT32 TimeOutMillisec
;
147 BOOLEAN LocalAddressIsIPv6
;
149 EFI_HTTPv4_ACCESS_POINT IPv4Node
;
150 EFI_HTTPv6_ACCESS_POINT Ipv6Node
;
159 EFI_HTTP_TOKEN
*HttpToken
;
160 HTTP_PROTOCOL
*HttpInstance
;
161 HTTP_TCP_TOKEN_WRAP TcpWrap
;
165 #define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')
167 #define HTTP_INSTANCE_FROM_PROTOCOL(a) \
172 HTTP_PROTOCOL_SIGNATURE \
176 The common notify function used in HTTP driver.
178 @param[in] Event The event signaled.
179 @param[in] Context The context.
190 Create events for the TCP connection token and TCP close token.
192 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
194 @retval EFI_SUCCESS The events are created successfully.
195 @retval others Other error as indicated.
199 HttpCreateTcpConnCloseEvent (
200 IN HTTP_PROTOCOL
*HttpInstance
204 Close events in the TCP connection token and TCP close token.
206 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
210 HttpCloseTcpConnCloseEvent (
211 IN HTTP_PROTOCOL
*HttpInstance
215 Create event for the TCP transmit token.
217 @param[in] Wrap Point to HTTP token's wrap data.
219 @retval EFI_SUCCESS The events is created successfully.
220 @retval others Other error as indicated.
224 HttpCreateTcpTxEvent (
225 IN HTTP_TOKEN_WRAP
*Wrap
229 Create event for the TCP receive token which is used to receive HTTP header.
231 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
233 @retval EFI_SUCCESS The events is created successfully.
234 @retval others Other error as indicated.
238 HttpCreateTcpRxEventForHeader (
239 IN HTTP_PROTOCOL
*HttpInstance
243 Create event for the TCP receive token which is used to receive HTTP body.
245 @param[in] Wrap Point to HTTP token's wrap data.
247 @retval EFI_SUCCESS The events is created successfully.
248 @retval others Other error as indicated.
252 HttpCreateTcpRxEvent (
253 IN HTTP_TOKEN_WRAP
*Wrap
257 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.
259 @param[in] Wrap Pointer to HTTP token's wrap data.
263 HttpCloseTcpRxEvent (
264 IN HTTP_TOKEN_WRAP
*Wrap
268 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.
270 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
271 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.
273 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully.
274 @retval Others Other error as indicated.
279 IN OUT HTTP_PROTOCOL
*HttpInstance
,
284 Clean up the HTTP child, release all the resources used by it.
286 @param[in] HttpInstance The HTTP child to clean up.
291 IN HTTP_PROTOCOL
*HttpInstance
295 Establish TCP connection with HTTP server.
297 @param[in] HttpInstance The HTTP instance private data.
299 @retval EFI_SUCCESS The TCP connection is established.
300 @retval Others Other error as indicated.
304 HttpCreateConnection (
305 IN HTTP_PROTOCOL
*HttpInstance
309 Close existing TCP connection.
311 @param[in] HttpInstance The HTTP instance private data.
313 @retval EFI_SUCCESS The TCP connection is closed.
314 @retval Others Other error as indicated.
318 HttpCloseConnection (
319 IN HTTP_PROTOCOL
*HttpInstance
323 Configure TCP4 protocol child.
325 @param[in] HttpInstance The HTTP instance private data.
326 @param[in] Wrap The HTTP token's wrap data.
328 @retval EFI_SUCCESS The TCP4 protocol child is configured.
329 @retval Others Other error as indicated.
334 IN HTTP_PROTOCOL
*HttpInstance
,
335 IN HTTP_TOKEN_WRAP
*Wrap
339 Configure TCP6 protocol child.
341 @param[in] HttpInstance The HTTP instance private data.
342 @param[in] Wrap The HTTP token's wrap data.
344 @retval EFI_SUCCESS The TCP6 protocol child is configured.
345 @retval Others Other error as indicated.
350 IN HTTP_PROTOCOL
*HttpInstance
,
351 IN HTTP_TOKEN_WRAP
*Wrap
355 Check existing TCP connection, if in error state, receover TCP4 connection.
357 @param[in] HttpInstance The HTTP instance private data.
359 @retval EFI_SUCCESS The TCP connection is established.
360 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.
361 @retval Others Other error as indicated.
366 IN HTTP_PROTOCOL
*HttpInstance
370 Check existing TCP connection, if in error state, recover TCP6 connection.
372 @param[in] HttpInstance The HTTP instance private data.
374 @retval EFI_SUCCESS The TCP connection is established.
375 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.
376 @retval Others Other error as indicated.
381 IN HTTP_PROTOCOL
*HttpInstance
385 Send the HTTP message through TCP4 or TCP6.
387 @param[in] HttpInstance The HTTP instance private data.
388 @param[in] Wrap The HTTP token's wrap data.
389 @param[in] TxString Buffer containing the HTTP message string.
390 @param[in] TxStringLen Length of the HTTP message string in bytes.
392 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.
393 @retval Others Other error as indicated.
398 IN HTTP_PROTOCOL
*HttpInstance
,
399 IN HTTP_TOKEN_WRAP
*Wrap
,
405 Check whether the user's token or event has already
406 been enqueue on HTTP Tx or Rx Token list.
408 @param[in] Map The container of either user's transmit or receive
410 @param[in] Item Current item to check against.
411 @param[in] Context The Token to check againist.
413 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
414 @retval EFI_SUCCESS The current item isn't the same token/event as the
422 IN NET_MAP_ITEM
*Item
,
427 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.
429 @param[in] Map The container of TxToken.
430 @param[in] Item Current item to check against.
431 @param[in] Context The Token to check againist.
433 @retval EFI_NOT_READY The HTTP message is still queued in the list.
434 @retval EFI_SUCCESS The HTTP message has been sent out.
441 IN NET_MAP_ITEM
*Item
,
446 Initialize TCP related data.
448 @param[in] HttpInstance The HTTP instance private data.
449 @param[in] Wrap The HTTP token's wrap data.
450 @param[in] Configure The Flag indicates whether the first time to initialize Tcp.
452 @retval EFI_SUCCESS The initialization of TCP instance is done.
453 @retval Others Other error as indicated.
458 IN HTTP_PROTOCOL
*HttpInstance
,
459 IN HTTP_TOKEN_WRAP
*Wrap
,
464 Transmit the HTTP mssage by processing the associated HTTP token.
466 @param[in] Map The container of TxToken or Tx6Token.
467 @param[in] Item Current item to check against.
468 @param[in] Context The Token to check againist.
470 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
471 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit
479 IN NET_MAP_ITEM
*Item
,
484 Receive the HTTP response by processing the associated HTTP token.
486 @param[in] Map The container of Rx4Token or Rx6Token.
487 @param[in] Item Current item to check against.
488 @param[in] Context The Token to check againist.
490 @retval EFI_SUCCESS The HTTP response is queued into TCP receive
492 @retval Others Other error as indicated.
499 IN NET_MAP_ITEM
*Item
,
504 Receive the HTTP header by processing the associated HTTP token.
506 @param[in] HttpInstance The HTTP instance private data.
507 @param[in, out] SizeofHeaders The HTTP header length.
508 @param[in, out] BufferSize The size of buffer to cacahe the header message.
509 @param[in] Timeout The time to wait for receiving the header packet.
511 @retval EFI_SUCCESS The HTTP header is received.
512 @retval Others Other errors as indicated.
516 HttpTcpReceiveHeader (
517 IN HTTP_PROTOCOL
*HttpInstance
,
518 IN OUT UINTN
*SizeofHeaders
,
519 IN OUT UINTN
*BufferSize
,
524 Receive the HTTP body by processing the associated HTTP token.
526 @param[in] Wrap The HTTP token's wrap data.
527 @param[in] HttpMsg The HTTP message data.
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
540 Clean up Tcp Tokens while the Tcp transmission error occurs.
542 @param[in] Wrap Pointer to HTTP token's wrap data.
546 HttpTcpTokenCleanup (
547 IN HTTP_TOKEN_WRAP
*Wrap
551 The work function of EfiHttpResponse().
553 @param[in] Wrap Pointer to HTTP token's wrap data.
555 @retval EFI_SUCCESS Allocation succeeded.
556 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
557 @retval EFI_NOT_READY Can't find a corresponding TxToken.
562 IN HTTP_TOKEN_WRAP
*Wrap