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
;
87 EFI_TLS_VERSION Version
;
88 EFI_TLS_CONNECTION_END ConnectionEnd
;
89 EFI_TLS_VERIFY VerifyMethod
;
90 EFI_TLS_SESSION_STATE SessionState
;
93 typedef struct _HTTP_PROTOCOL
{
95 EFI_HTTP_PROTOCOL Http
;
97 HTTP_SERVICE
*Service
;
98 LIST_ENTRY Link
; // Link to all HTTP instance from the service.
101 EFI_HTTP_METHOD Method
;
105 EFI_EVENT TimeoutEvent
;
107 EFI_HANDLE Tcp4ChildHandle
;
108 EFI_TCP4_PROTOCOL
*Tcp4
;
109 EFI_TCP4_CONFIG_DATA Tcp4CfgData
;
110 EFI_TCP4_OPTION Tcp4Option
;
112 EFI_TCP4_CONNECTION_TOKEN Tcp4ConnToken
;
113 BOOLEAN IsTcp4ConnDone
;
114 EFI_TCP4_CLOSE_TOKEN Tcp4CloseToken
;
115 BOOLEAN IsTcp4CloseDone
;
118 EFI_IPv4_ADDRESS RemoteAddr
;
120 EFI_HANDLE Tcp6ChildHandle
;
121 EFI_TCP6_PROTOCOL
*Tcp6
;
122 EFI_TCP6_CONFIG_DATA Tcp6CfgData
;
123 EFI_TCP6_OPTION Tcp6Option
;
125 EFI_TCP6_CONNECTION_TOKEN Tcp6ConnToken
;
126 BOOLEAN IsTcp6ConnDone
;
127 EFI_TCP6_CLOSE_TOKEN Tcp6CloseToken
;
128 BOOLEAN IsTcp6CloseDone
;
129 EFI_IPv6_ADDRESS RemoteIpv6Addr
;
132 // Rx4Token or Rx6Token used for receiving HTTP header.
134 EFI_TCP4_IO_TOKEN Rx4Token
;
135 EFI_TCP4_RECEIVE_DATA Rx4Data
;
136 EFI_TCP6_IO_TOKEN Rx6Token
;
137 EFI_TCP6_RECEIVE_DATA Rx6Data
;
148 // HTTP message-body parser.
152 EFI_HTTP_VERSION HttpVersion
;
153 UINT32 TimeOutMillisec
;
154 BOOLEAN LocalAddressIsIPv6
;
156 EFI_HTTPv4_ACCESS_POINT IPv4Node
;
157 EFI_HTTPv6_ACCESS_POINT Ipv6Node
;
169 EFI_HANDLE TlsChildHandle
; /// Tls ChildHandle
170 TLS_CONFIG_DATA TlsConfigData
;
171 EFI_TLS_PROTOCOL
*Tls
;
172 EFI_TLS_CONFIGURATION_PROTOCOL
*TlsConfiguration
;
173 EFI_TLS_SESSION_STATE TlsSessionState
;
176 // TlsTxData used for transmitting TLS related messages.
178 EFI_TCP4_IO_TOKEN Tcp4TlsTxToken
;
179 EFI_TCP4_TRANSMIT_DATA Tcp4TlsTxData
;
180 EFI_TCP6_IO_TOKEN Tcp6TlsTxToken
;
181 EFI_TCP6_TRANSMIT_DATA Tcp6TlsTxData
;
185 // TlsRxData used for receiving TLS related messages.
187 EFI_TCP4_IO_TOKEN Tcp4TlsRxToken
;
188 EFI_TCP4_RECEIVE_DATA Tcp4TlsRxData
;
189 EFI_TCP6_IO_TOKEN Tcp6TlsRxToken
;
190 EFI_TCP6_RECEIVE_DATA Tcp6TlsRxData
;
195 EFI_HTTP_TOKEN
*HttpToken
;
196 HTTP_PROTOCOL
*HttpInstance
;
197 HTTP_TCP_TOKEN_WRAP TcpWrap
;
201 #define HTTP_PROTOCOL_SIGNATURE SIGNATURE_32('H', 't', 't', 'P')
203 #define HTTP_INSTANCE_FROM_PROTOCOL(a) \
208 HTTP_PROTOCOL_SIGNATURE \
212 The common notify function used in HTTP driver.
214 @param[in] Event The event signaled.
215 @param[in] Context The context.
226 Create events for the TCP connection token and TCP close token.
228 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
230 @retval EFI_SUCCESS The events are created successfully.
231 @retval others Other error as indicated.
235 HttpCreateTcpConnCloseEvent (
236 IN HTTP_PROTOCOL
*HttpInstance
240 Close events in the TCP connection token and TCP close token.
242 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
246 HttpCloseTcpConnCloseEvent (
247 IN HTTP_PROTOCOL
*HttpInstance
251 Create event for the TCP transmit token.
253 @param[in] Wrap Point to HTTP token's wrap data.
255 @retval EFI_SUCCESS The events is created successfully.
256 @retval others Other error as indicated.
260 HttpCreateTcpTxEvent (
261 IN HTTP_TOKEN_WRAP
*Wrap
265 Create event for the TCP receive token which is used to receive HTTP header.
267 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
269 @retval EFI_SUCCESS The events is created successfully.
270 @retval others Other error as indicated.
274 HttpCreateTcpRxEventForHeader (
275 IN HTTP_PROTOCOL
*HttpInstance
279 Create event for the TCP receive token which is used to receive HTTP body.
281 @param[in] Wrap Point to HTTP token's wrap data.
283 @retval EFI_SUCCESS The events is created successfully.
284 @retval others Other error as indicated.
288 HttpCreateTcpRxEvent (
289 IN HTTP_TOKEN_WRAP
*Wrap
293 Close Events for Tcp Receive Tokens for HTTP body and HTTP header.
295 @param[in] Wrap Pointer to HTTP token's wrap data.
299 HttpCloseTcpRxEvent (
300 IN HTTP_TOKEN_WRAP
*Wrap
304 Intiialize the HTTP_PROTOCOL structure to the unconfigured state.
306 @param[in, out] HttpInstance Pointer to HTTP_PROTOCOL structure.
307 @param[in] IpVersion Indicate us TCP4 protocol or TCP6 protocol.
309 @retval EFI_SUCCESS HTTP_PROTOCOL structure is initialized successfully.
310 @retval Others Other error as indicated.
315 IN OUT HTTP_PROTOCOL
*HttpInstance
,
320 Clean up the HTTP child, release all the resources used by it.
322 @param[in] HttpInstance The HTTP child to clean up.
327 IN HTTP_PROTOCOL
*HttpInstance
331 Establish TCP connection with HTTP server.
333 @param[in] HttpInstance The HTTP instance private data.
335 @retval EFI_SUCCESS The TCP connection is established.
336 @retval Others Other error as indicated.
340 HttpCreateConnection (
341 IN HTTP_PROTOCOL
*HttpInstance
345 Close existing TCP connection.
347 @param[in] HttpInstance The HTTP instance private data.
349 @retval EFI_SUCCESS The TCP connection is closed.
350 @retval Others Other error as indicated.
354 HttpCloseConnection (
355 IN HTTP_PROTOCOL
*HttpInstance
359 Configure TCP4 protocol child.
361 @param[in] HttpInstance The HTTP instance private data.
362 @param[in] Wrap The HTTP token's wrap data.
364 @retval EFI_SUCCESS The TCP4 protocol child is configured.
365 @retval Others Other error as indicated.
370 IN HTTP_PROTOCOL
*HttpInstance
,
371 IN HTTP_TOKEN_WRAP
*Wrap
375 Configure TCP6 protocol child.
377 @param[in] HttpInstance The HTTP instance private data.
378 @param[in] Wrap The HTTP token's wrap data.
380 @retval EFI_SUCCESS The TCP6 protocol child is configured.
381 @retval Others Other error as indicated.
386 IN HTTP_PROTOCOL
*HttpInstance
,
387 IN HTTP_TOKEN_WRAP
*Wrap
391 Check existing TCP connection, if in error state, recover TCP4 connection. Then,
392 connect one TLS session if required.
394 @param[in] HttpInstance The HTTP instance private data.
396 @retval EFI_SUCCESS The TCP connection is established.
397 @retval EFI_NOT_READY TCP4 protocol child is not created or configured.
398 @retval Others Other error as indicated.
403 IN HTTP_PROTOCOL
*HttpInstance
407 Check existing TCP connection, if in error state, recover TCP6 connection. Then,
408 connect one TLS session if required.
410 @param[in] HttpInstance The HTTP instance private data.
412 @retval EFI_SUCCESS The TCP connection is established.
413 @retval EFI_NOT_READY TCP6 protocol child is not created or configured.
414 @retval Others Other error as indicated.
419 IN HTTP_PROTOCOL
*HttpInstance
423 Send the HTTP or HTTPS message through TCP4 or TCP6.
425 @param[in] HttpInstance The HTTP instance private data.
426 @param[in] Wrap The HTTP token's wrap data.
427 @param[in] TxString Buffer containing the HTTP message string.
428 @param[in] TxStringLen Length of the HTTP message string in bytes.
430 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit queue.
431 @retval Others Other error as indicated.
436 IN HTTP_PROTOCOL
*HttpInstance
,
437 IN HTTP_TOKEN_WRAP
*Wrap
,
443 Check whether the user's token or event has already
444 been enqueue on HTTP Tx or Rx Token list.
446 @param[in] Map The container of either user's transmit or receive
448 @param[in] Item Current item to check against.
449 @param[in] Context The Token to check againist.
451 @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP
452 @retval EFI_SUCCESS The current item isn't the same token/event as the
460 IN NET_MAP_ITEM
*Item
,
465 Check whether the HTTP message associated with TxToken or Tx6Token is already sent out.
467 @param[in] Map The container of TxToken.
468 @param[in] Item Current item to check against.
469 @param[in] Context The Token to check againist.
471 @retval EFI_NOT_READY The HTTP message is still queued in the list.
472 @retval EFI_SUCCESS The HTTP message has been sent out.
479 IN NET_MAP_ITEM
*Item
,
484 Initialize Http session.
486 @param[in] HttpInstance The HTTP instance private data.
487 @param[in] Wrap The HTTP token's wrap data.
488 @param[in] Configure The Flag indicates whether need to initialize session.
489 @param[in] TlsConfigure The Flag indicates whether it's the new Tls session.
491 @retval EFI_SUCCESS The initialization of session is done.
492 @retval Others Other error as indicated.
497 IN HTTP_PROTOCOL
*HttpInstance
,
498 IN HTTP_TOKEN_WRAP
*Wrap
,
499 IN BOOLEAN Configure
,
500 IN BOOLEAN TlsConfigure
504 Transmit the HTTP or HTTPS mssage by processing the associated HTTP token.
506 @param[in] Map The container of TxToken or Tx6Token.
507 @param[in] Item Current item to check against.
508 @param[in] Context The Token to check againist.
510 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
511 @retval EFI_SUCCESS The HTTP message is queued into TCP transmit
519 IN NET_MAP_ITEM
*Item
,
524 Receive the HTTP response by processing the associated HTTP token.
526 @param[in] Map The container of Rx4Token or Rx6Token.
527 @param[in] Item Current item to check against.
528 @param[in] Context The Token to check againist.
530 @retval EFI_SUCCESS The HTTP response is queued into TCP receive
532 @retval Others Other error as indicated.
539 IN NET_MAP_ITEM
*Item
,
544 Receive the HTTP header by processing the associated HTTP token.
546 @param[in] HttpInstance The HTTP instance private data.
547 @param[in, out] SizeofHeaders The HTTP header length.
548 @param[in, out] BufferSize The size of buffer to cacahe the header message.
549 @param[in] Timeout The time to wait for receiving the header packet.
551 @retval EFI_SUCCESS The HTTP header is received.
552 @retval Others Other errors as indicated.
556 HttpTcpReceiveHeader (
557 IN HTTP_PROTOCOL
*HttpInstance
,
558 IN OUT UINTN
*SizeofHeaders
,
559 IN OUT UINTN
*BufferSize
,
564 Receive the HTTP body by processing the associated HTTP token.
566 @param[in] Wrap The HTTP token's wrap data.
567 @param[in] HttpMsg The HTTP message data.
569 @retval EFI_SUCCESS The HTTP body is received.
570 @retval Others Other error as indicated.
575 IN HTTP_TOKEN_WRAP
*Wrap
,
576 IN EFI_HTTP_MESSAGE
*HttpMsg
580 Clean up Tcp Tokens while the Tcp transmission error occurs.
582 @param[in] Wrap Pointer to HTTP token's wrap data.
586 HttpTcpTokenCleanup (
587 IN HTTP_TOKEN_WRAP
*Wrap
591 The work function of EfiHttpResponse().
593 @param[in] Wrap Pointer to HTTP token's wrap data.
595 @retval EFI_SUCCESS Allocation succeeded.
596 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
597 @retval EFI_NOT_READY Can't find a corresponding TxToken.
602 IN HTTP_TOKEN_WRAP
*Wrap