2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HttpDriver.h"
19 EFI_HTTP_PROTOCOL mEfiHttpTemplate
= {
29 Returns the operational parameters for the current HTTP child instance.
31 The GetModeData() function is used to read the current mode data (operational
32 parameters) for this HTTP protocol instance.
34 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
35 @param[out] HttpConfigData Point to buffer for operational parameters of this
36 HTTP instance. It is the responsibility of the caller
37 to allocate the memory for HttpConfigData and
38 HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,
39 it is recommended to allocate sufficient memory to record
40 IPv6Node since it is big enough for all possibilities.
42 @retval EFI_SUCCESS Operation succeeded.
43 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
45 HttpConfigData is NULL.
46 HttpConfigData->AccessPoint.IPv4Node or
47 HttpConfigData->AccessPoint.IPv6Node is NULL.
48 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
54 IN EFI_HTTP_PROTOCOL
*This
,
55 OUT EFI_HTTP_CONFIG_DATA
*HttpConfigData
58 HTTP_PROTOCOL
*HttpInstance
;
61 // Check input parameters.
63 if ((This
== NULL
) || (HttpConfigData
== NULL
)) {
64 return EFI_INVALID_PARAMETER
;
67 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
68 ASSERT (HttpInstance
!= NULL
);
70 if ((HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
71 (HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)) {
72 return EFI_INVALID_PARAMETER
;
75 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
76 return EFI_NOT_STARTED
;
79 HttpConfigData
->HttpVersion
= HttpInstance
->HttpVersion
;
80 HttpConfigData
->TimeOutMillisec
= HttpInstance
->TimeOutMillisec
;
81 HttpConfigData
->LocalAddressIsIPv6
= HttpInstance
->LocalAddressIsIPv6
;
83 if (HttpInstance
->LocalAddressIsIPv6
) {
85 HttpConfigData
->AccessPoint
.IPv6Node
,
86 &HttpInstance
->Ipv6Node
,
87 sizeof (HttpInstance
->Ipv6Node
)
91 HttpConfigData
->AccessPoint
.IPv4Node
,
92 &HttpInstance
->IPv4Node
,
93 sizeof (HttpInstance
->IPv4Node
)
101 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
103 The Configure() function does the following:
104 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
105 timeout, local address, port, etc.
106 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
107 connections with remote hosts, canceling all asynchronous tokens, and flush request
108 and response buffers without informing the appropriate hosts.
110 No other EFI HTTP function can be executed by this instance until the Configure()
111 function is executed and returns successfully.
113 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
114 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
116 @retval EFI_SUCCESS Operation succeeded.
117 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
119 HttpConfigData->LocalAddressIsIPv6 is FALSE and
120 HttpConfigData->AccessPoint.IPv4Node is NULL.
121 HttpConfigData->LocalAddressIsIPv6 is TRUE and
122 HttpConfigData->AccessPoint.IPv6Node is NULL.
123 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
124 Configure() with NULL to reset it.
125 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
126 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
127 executing Configure().
128 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
129 in the implementation.
134 IN EFI_HTTP_PROTOCOL
*This
,
135 IN EFI_HTTP_CONFIG_DATA
*HttpConfigData OPTIONAL
138 HTTP_PROTOCOL
*HttpInstance
;
142 // Check input parameters.
145 (HttpConfigData
!= NULL
&&
146 ((HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
147 (!HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)))) {
148 return EFI_INVALID_PARAMETER
;
151 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
152 ASSERT (HttpInstance
!= NULL
&& HttpInstance
->Service
!= NULL
);
154 if (HttpConfigData
!= NULL
) {
156 if (HttpConfigData
->HttpVersion
>= HttpVersionUnsupported
) {
157 return EFI_UNSUPPORTED
;
161 // Now configure this HTTP instance.
163 if (HttpInstance
->State
!= HTTP_STATE_UNCONFIGED
) {
164 return EFI_ALREADY_STARTED
;
167 HttpInstance
->HttpVersion
= HttpConfigData
->HttpVersion
;
168 HttpInstance
->TimeOutMillisec
= HttpConfigData
->TimeOutMillisec
;
169 HttpInstance
->LocalAddressIsIPv6
= HttpConfigData
->LocalAddressIsIPv6
;
171 if (HttpConfigData
->LocalAddressIsIPv6
) {
173 &HttpInstance
->Ipv6Node
,
174 HttpConfigData
->AccessPoint
.IPv6Node
,
175 sizeof (HttpInstance
->Ipv6Node
)
179 &HttpInstance
->IPv4Node
,
180 HttpConfigData
->AccessPoint
.IPv4Node
,
181 sizeof (HttpInstance
->IPv4Node
)
188 Status
= HttpInitProtocol (HttpInstance
, HttpInstance
->LocalAddressIsIPv6
);
189 if (EFI_ERROR (Status
)) {
193 HttpInstance
->State
= HTTP_STATE_HTTP_CONFIGED
;
198 // Reset all the resources related to HttpInsance.
200 HttpCleanProtocol (HttpInstance
);
201 HttpInstance
->State
= HTTP_STATE_UNCONFIGED
;
208 The Request() function queues an HTTP request to this HTTP instance.
210 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
211 successfully, or if there is an error, Status in token will be updated and Event will
214 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
215 @param[in] Token Pointer to storage containing HTTP request token.
217 @retval EFI_SUCCESS Outgoing data was processed.
218 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
219 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
220 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
221 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
222 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
224 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
227 Token->Message is NULL.
228 Token->Message->Body is not NULL,
229 Token->Message->BodyLength is non-zero, and
230 Token->Message->Data is NULL, but a previous call to
231 Request()has not been completed successfully.
236 IN EFI_HTTP_PROTOCOL
*This
,
237 IN EFI_HTTP_TOKEN
*Token
240 EFI_HTTP_MESSAGE
*HttpMsg
;
241 EFI_HTTP_REQUEST_DATA
*Request
;
247 HTTP_PROTOCOL
*HttpInstance
;
250 BOOLEAN TlsConfigure
;
255 HTTP_TOKEN_WRAP
*Wrap
;
257 UINTN RequestMsgSize
;
258 EFI_HANDLE ImageHandle
;
271 TlsConfigure
= FALSE
;
273 if ((This
== NULL
) || (Token
== NULL
)) {
274 return EFI_INVALID_PARAMETER
;
277 HttpMsg
= Token
->Message
;
278 if (HttpMsg
== NULL
) {
279 return EFI_INVALID_PARAMETER
;
282 Request
= HttpMsg
->Data
.Request
;
285 // Only support GET, HEAD, PATCH, PUT and POST method in current implementation.
287 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
288 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodPut
) &&
289 (Request
->Method
!= HttpMethodPost
) && (Request
->Method
!= HttpMethodPatch
)) {
290 return EFI_UNSUPPORTED
;
293 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
294 ASSERT (HttpInstance
!= NULL
);
297 // Capture the method into HttpInstance.
299 if (Request
!= NULL
) {
300 HttpInstance
->Method
= Request
->Method
;
303 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
304 return EFI_NOT_STARTED
;
307 if (Request
== NULL
) {
309 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)
311 if ((HttpInstance
->Method
!= HttpMethodPut
) &&
312 (HttpInstance
->Method
!= HttpMethodPost
) &&
313 (HttpInstance
->Method
!= HttpMethodPatch
)) {
314 return EFI_INVALID_PARAMETER
;
318 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!
320 if (HttpInstance
->State
< HTTP_STATE_TCP_CONFIGED
) {
321 return EFI_INVALID_PARAMETER
;
325 // We need to have the Message Body for sending the HTTP message across in these cases.
327 if (HttpMsg
->Body
== NULL
|| HttpMsg
->BodyLength
== 0) {
328 return EFI_INVALID_PARAMETER
;
332 // Use existing TCP instance to transmit the packet.
338 // Check whether the token already existed.
340 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTokenExist
, Token
))) {
341 return EFI_ACCESS_DENIED
;
345 // Parse the URI of the remote host.
347 Url
= HttpInstance
->Url
;
348 UrlLen
= StrLen (Request
->Url
) + 1;
349 if (UrlLen
> HTTP_URL_BUFFER_LEN
) {
350 Url
= AllocateZeroPool (UrlLen
);
352 return EFI_OUT_OF_RESOURCES
;
354 FreePool (HttpInstance
->Url
);
355 HttpInstance
->Url
= Url
;
359 UnicodeStrToAsciiStrS (Request
->Url
, Url
, UrlLen
);
362 // From the information in Url, the HTTP instance will
363 // be able to determine whether to use http or https.
365 HttpInstance
->UseHttps
= IsHttpsUrl (Url
);
368 // HTTP is disabled, return directly if the URI is not HTTPS.
370 if (!PcdGetBool (PcdAllowHttpConnections
) && !(HttpInstance
->UseHttps
)) {
372 DEBUG ((EFI_D_ERROR
, "EfiHttpRequest: HTTP is disabled.\n"));
374 return EFI_ACCESS_DENIED
;
378 // Check whether we need to create Tls child and open the TLS protocol.
380 if (HttpInstance
->UseHttps
&& HttpInstance
->TlsChildHandle
== NULL
) {
382 // Use TlsSb to create Tls child and open the TLS protocol.
384 if (HttpInstance
->LocalAddressIsIPv6
) {
385 ImageHandle
= HttpInstance
->Service
->Ip6DriverBindingHandle
;
387 ImageHandle
= HttpInstance
->Service
->Ip4DriverBindingHandle
;
390 HttpInstance
->TlsChildHandle
= TlsCreateChild (
392 &(HttpInstance
->TlsSb
),
393 &(HttpInstance
->Tls
),
394 &(HttpInstance
->TlsConfiguration
)
396 if (HttpInstance
->TlsChildHandle
== NULL
) {
397 return EFI_DEVICE_ERROR
;
404 Status
= HttpParseUrl (Url
, (UINT32
) AsciiStrLen (Url
), FALSE
, &UrlParser
);
405 if (EFI_ERROR (Status
)) {
410 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
411 if (EFI_ERROR (Status
)) {
415 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
416 if (EFI_ERROR (Status
)) {
417 if (HttpInstance
->UseHttps
) {
418 RemotePort
= HTTPS_DEFAULT_PORT
;
420 RemotePort
= HTTP_DEFAULT_PORT
;
424 // If Configure is TRUE, it indicates the first time to call Request();
425 // If ReConfigure is TRUE, it indicates the request URL is not same
426 // with the previous call to Request();
431 if (HttpInstance
->RemoteHost
== NULL
) {
433 // Request() is called the first time.
437 if ((HttpInstance
->RemotePort
== RemotePort
) &&
438 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
439 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
441 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
443 // Host Name and port number of the request URL are the same with previous call to Request().
444 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
445 // Check whether previous TCP packet sent out.
448 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
450 // Wrap the HTTP token in HTTP_TOKEN_WRAP
452 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
454 Status
= EFI_OUT_OF_RESOURCES
;
458 Wrap
->HttpToken
= Token
;
459 Wrap
->HttpInstance
= HttpInstance
;
461 Status
= HttpCreateTcpTxEvent (Wrap
);
462 if (EFI_ERROR (Status
)) {
466 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
467 if (EFI_ERROR (Status
)) {
471 Wrap
->TcpWrap
.Method
= Request
->Method
;
476 // Queue the HTTP token and return.
481 // Use existing TCP instance to transmit the packet.
488 // Need close existing TCP instance and create a new TCP instance for data transmit.
490 if (HttpInstance
->RemoteHost
!= NULL
) {
491 FreePool (HttpInstance
->RemoteHost
);
492 HttpInstance
->RemoteHost
= NULL
;
493 HttpInstance
->RemotePort
= 0;
501 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
503 if (!HttpInstance
->LocalAddressIsIPv6
) {
504 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
506 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
509 if (EFI_ERROR (Status
)) {
510 HostNameSize
= AsciiStrSize (HostName
);
511 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
512 if (HostNameStr
== NULL
) {
513 Status
= EFI_OUT_OF_RESOURCES
;
517 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
518 if (!HttpInstance
->LocalAddressIsIPv6
) {
519 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
521 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
524 FreePool (HostNameStr
);
525 if (EFI_ERROR (Status
)) {
531 // Save the RemotePort and RemoteHost.
533 ASSERT (HttpInstance
->RemoteHost
== NULL
);
534 HttpInstance
->RemotePort
= RemotePort
;
535 HttpInstance
->RemoteHost
= HostName
;
541 // The request URL is different from previous calls to Request(), close existing TCP instance.
543 if (!HttpInstance
->LocalAddressIsIPv6
) {
544 ASSERT (HttpInstance
->Tcp4
!= NULL
);
546 ASSERT (HttpInstance
->Tcp6
!= NULL
);
549 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
550 Status
= TlsCloseSession (HttpInstance
);
551 if (EFI_ERROR (Status
)) {
555 TlsCloseTxRxEvent (HttpInstance
);
558 HttpCloseConnection (HttpInstance
);
559 EfiHttpCancel (This
, NULL
);
563 // Wrap the HTTP token in HTTP_TOKEN_WRAP
565 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
567 Status
= EFI_OUT_OF_RESOURCES
;
571 Wrap
->HttpToken
= Token
;
572 Wrap
->HttpInstance
= HttpInstance
;
573 if (Request
!= NULL
) {
574 Wrap
->TcpWrap
.Method
= Request
->Method
;
577 Status
= HttpInitSession (
580 Configure
|| ReConfigure
,
583 if (EFI_ERROR (Status
)) {
587 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
589 // For the new HTTP token, create TX TCP token events.
591 Status
= HttpCreateTcpTxEvent (Wrap
);
592 if (EFI_ERROR (Status
)) {
598 // Create request message.
601 if (Url
!= NULL
&& *FileUrl
!= '/') {
603 // Convert the absolute-URI to the absolute-path
605 while (*FileUrl
!= ':') {
608 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
610 while (*FileUrl
!= '/') {
614 Status
= EFI_INVALID_PARAMETER
;
619 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
621 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
625 ASSERT (RequestMsg
!= NULL
);
628 // Every request we insert a TxToken and a response call would remove the TxToken.
629 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
630 // continuous request without a response call. So, in such cases, where Request
631 // structure is NULL, we would not insert a TxToken.
633 if (Request
!= NULL
) {
634 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
635 if (EFI_ERROR (Status
)) {
641 // Transmit the request message.
643 Status
= HttpTransmitTcp (
649 if (EFI_ERROR (Status
)) {
655 if (HostName
!= NULL
) {
663 // We would have inserted a TxToken only if Request structure is not NULL.
664 // Hence check before we do a remove in this error case.
666 if (Request
!= NULL
) {
667 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
671 if (RequestMsg
!= NULL
) {
672 FreePool (RequestMsg
);
676 if (HttpInstance
->UseHttps
) {
677 TlsCloseSession (HttpInstance
);
678 TlsCloseTxRxEvent (HttpInstance
);
682 HttpCloseConnection (HttpInstance
);
684 HttpCloseTcpConnCloseEvent (HttpInstance
);
685 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
686 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
687 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
689 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
690 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
691 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
695 if (HostName
!= NULL
) {
701 if (UrlParser
!= NULL
) {
702 HttpUrlFreeParser (UrlParser
);
710 Cancel a user's Token.
712 @param[in] Map The HTTP instance's token queue.
713 @param[in] Item Object container for one HTTP token and token's wrap.
714 @param[in] Context The user's token to cancel.
716 @retval EFI_SUCCESS Continue to check the next Item.
717 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
724 IN NET_MAP_ITEM
*Item
,
728 EFI_HTTP_TOKEN
*Token
;
729 HTTP_TOKEN_WRAP
*Wrap
;
730 HTTP_PROTOCOL
*HttpInstance
;
732 Token
= (EFI_HTTP_TOKEN
*) Context
;
735 // Return EFI_SUCCESS to check the next item in the map if
736 // this one doesn't match.
738 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
742 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
743 ASSERT (Wrap
!= NULL
);
744 HttpInstance
= Wrap
->HttpInstance
;
746 if (!HttpInstance
->LocalAddressIsIPv6
) {
747 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
749 // Cancle the Token before close its Event.
751 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
754 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
759 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
761 // Cancle the Token before close its Event.
763 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
766 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
773 // If only one item is to be cancel, return EFI_ABORTED to stop
774 // iterating the map any more.
784 Cancel the user's receive/transmit request. It is the worker function of
785 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
788 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
789 @param[in] Token The token to cancel. If NULL, all token will be
792 @retval EFI_SUCCESS The token is cancelled.
793 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
794 @retval Others Other error as indicated.
799 IN HTTP_PROTOCOL
*HttpInstance
,
800 IN EFI_HTTP_TOKEN
*Token
806 // First check the tokens queued by EfiHttpRequest().
808 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
809 if (EFI_ERROR (Status
)) {
811 if (Status
== EFI_ABORTED
) {
819 if (!HttpInstance
->UseHttps
) {
821 // Then check the tokens queued by EfiHttpResponse(), except for Https.
823 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
824 if (EFI_ERROR (Status
)) {
826 if (Status
== EFI_ABORTED
) {
829 return EFI_NOT_FOUND
;
836 if (!HttpInstance
->LocalAddressIsIPv6
) {
837 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
839 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
848 Abort an asynchronous HTTP request or response token.
850 The Cancel() function aborts a pending HTTP request or response transaction. If
851 Token is not NULL and the token is in transmit or receive queues when it is being
852 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
853 be signaled. If the token is not in one of the queues, which usually means that the
854 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
855 all asynchronous tokens issued by Request() or Response() will be aborted.
857 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
858 @param[in] Token Point to storage containing HTTP request or response
861 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
862 @retval EFI_INVALID_PARAMETER This is NULL.
863 @retval EFI_NOT_STARTED This instance hasn't been configured.
864 @retval EFI_NOT_FOUND The asynchronous request or response token is not
866 @retval EFI_UNSUPPORTED The implementation does not support this function.
872 IN EFI_HTTP_PROTOCOL
*This
,
873 IN EFI_HTTP_TOKEN
*Token
876 HTTP_PROTOCOL
*HttpInstance
;
879 return EFI_INVALID_PARAMETER
;
882 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
883 ASSERT (HttpInstance
!= NULL
);
885 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
886 return EFI_NOT_STARTED
;
889 return HttpCancel (HttpInstance
, Token
);
894 A callback function to intercept events during message parser.
896 This function will be invoked during HttpParseMessageBody() with various events type. An error
897 return status of the callback function will cause the HttpParseMessageBody() aborted.
899 @param[in] EventType Event type of this callback call.
900 @param[in] Data A pointer to data buffer.
901 @param[in] Length Length in bytes of the Data.
902 @param[in] Context Callback context set by HttpInitMsgParser().
904 @retval EFI_SUCCESS Continue to parser the message body.
909 HttpBodyParserCallback (
910 IN HTTP_BODY_PARSE_EVENT EventType
,
916 HTTP_TOKEN_WRAP
*Wrap
;
920 if (EventType
!= BodyParseEventOnComplete
) {
924 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
928 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
929 Body
= Wrap
->HttpToken
->Message
->Body
;
930 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
931 if (Data
< Body
+ BodyLength
) {
932 Wrap
->HttpInstance
->NextMsg
= Data
;
934 Wrap
->HttpInstance
->NextMsg
= NULL
;
939 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
947 The work function of EfiHttpResponse().
949 @param[in] Wrap Pointer to HTTP token's wrap data.
951 @retval EFI_SUCCESS Allocation succeeded.
952 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
953 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
954 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
959 IN HTTP_TOKEN_WRAP
*Wrap
963 EFI_HTTP_MESSAGE
*HttpMsg
;
971 CHAR8
*StatusCodeStr
;
973 HTTP_PROTOCOL
*HttpInstance
;
974 EFI_HTTP_TOKEN
*Token
;
976 HTTP_TOKEN_WRAP
*ValueInItem
;
978 NET_FRAGMENT Fragment
;
980 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
981 return EFI_INVALID_PARAMETER
;
984 HttpInstance
= Wrap
->HttpInstance
;
985 Token
= Wrap
->HttpToken
;
986 HttpMsg
= Token
->Message
;
988 HttpInstance
->EndofHeader
= NULL
;
989 HttpInstance
->HttpHeaders
= NULL
;
990 HttpMsg
->Headers
= NULL
;
997 Fragment
.Bulk
= NULL
;
999 if (HttpMsg
->Data
.Response
!= NULL
) {
1001 // Check whether we have cached header from previous call.
1003 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1005 // The data is stored at [NextMsg, CacheBody + CacheLen].
1007 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1008 HttpHeaders
= AllocateZeroPool (HdrLen
);
1009 if (HttpHeaders
== NULL
) {
1010 Status
= EFI_OUT_OF_RESOURCES
;
1014 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1015 FreePool (HttpInstance
->CacheBody
);
1016 HttpInstance
->CacheBody
= NULL
;
1017 HttpInstance
->NextMsg
= NULL
;
1018 HttpInstance
->CacheOffset
= 0;
1019 SizeofHeaders
= HdrLen
;
1020 BufferSize
= HttpInstance
->CacheLen
;
1023 // Check whether we cached the whole HTTP headers.
1025 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1028 HttpInstance
->EndofHeader
= &EndofHeader
;
1029 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1032 if (HttpInstance
->TimeoutEvent
== NULL
) {
1034 // Create TimeoutEvent for response
1036 Status
= gBS
->CreateEvent (
1041 &HttpInstance
->TimeoutEvent
1043 if (EFI_ERROR (Status
)) {
1049 // Start the timer, and wait Timeout seconds to receive the header packet.
1051 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1052 if (EFI_ERROR (Status
)) {
1056 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1058 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1060 if (EFI_ERROR (Status
)) {
1064 ASSERT (HttpHeaders
!= NULL
);
1067 // Cache the part of body.
1069 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1071 if (HttpInstance
->CacheBody
!= NULL
) {
1072 FreePool (HttpInstance
->CacheBody
);
1075 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1076 if (HttpInstance
->CacheBody
== NULL
) {
1077 Status
= EFI_OUT_OF_RESOURCES
;
1081 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1082 HttpInstance
->CacheLen
= BodyLen
;
1086 // Search for Status Code.
1088 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1089 if (StatusCodeStr
== NULL
) {
1090 Status
= EFI_NOT_READY
;
1094 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1097 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1099 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1101 Status
= EFI_NOT_READY
;
1106 // We could have response with just a HTTP message and no headers. For Example,
1107 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1108 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1109 // set SizeofHeaders to 0.
1111 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1112 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1115 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1118 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1119 HttpInstance
->StatusCode
= StatusCode
;
1121 Status
= EFI_NOT_READY
;
1125 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1126 // continuous request without a response call. So, we would not do an insert of
1127 // TxToken. After we have sent the complete file, we will call a response to get
1128 // a final response from server. In such a case, we would not have any TxTokens.
1129 // Hence, check that case before doing a NetMapRemoveHead.
1131 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1132 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1133 if (ValueInItem
== NULL
) {
1138 // The first Tx Token not transmitted yet, insert back and return error.
1140 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1145 if (SizeofHeaders
!= 0) {
1146 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1147 if (HeaderTmp
== NULL
) {
1148 Status
= EFI_OUT_OF_RESOURCES
;
1152 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1153 FreePool (HttpHeaders
);
1154 HttpHeaders
= HeaderTmp
;
1157 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1159 if (mHttpUtilities
== NULL
) {
1160 Status
= EFI_NOT_READY
;
1165 // Parse the HTTP header into array of key/value pairs.
1167 Status
= mHttpUtilities
->Parse (
1172 &HttpMsg
->HeaderCount
1174 if (EFI_ERROR (Status
)) {
1178 FreePool (HttpHeaders
);
1183 // Init message-body parser by header information.
1185 Status
= HttpInitMsgParser (
1186 HttpInstance
->Method
,
1187 HttpMsg
->Data
.Response
->StatusCode
,
1188 HttpMsg
->HeaderCount
,
1190 HttpBodyParserCallback
,
1191 (VOID
*) ValueInItem
,
1192 &HttpInstance
->MsgParser
1194 if (EFI_ERROR (Status
)) {
1199 // Check whether we received a complete HTTP message.
1201 if (HttpInstance
->CacheBody
!= NULL
) {
1202 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1203 if (EFI_ERROR (Status
)) {
1207 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1209 // Free the MsgParse since we already have a full HTTP message.
1211 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1212 HttpInstance
->MsgParser
= NULL
;
1217 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1218 Status
= EFI_SUCCESS
;
1224 // Receive the response body.
1229 // First check whether we cached some data.
1231 if (HttpInstance
->CacheBody
!= NULL
) {
1233 // Calculate the length of the cached data.
1235 if (HttpInstance
->NextMsg
!= NULL
) {
1237 // We have a cached HTTP message which includes a part of HTTP header of next message.
1239 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1241 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1246 // We have some cached data. Just copy the data and return.
1248 if (HttpMsg
->BodyLength
< BodyLen
) {
1249 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1250 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1253 // Copy all cached data out.
1255 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1256 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1257 HttpMsg
->BodyLength
= BodyLen
;
1259 if (HttpInstance
->NextMsg
== NULL
) {
1261 // There is no HTTP header of next message. Just free the cache buffer.
1263 FreePool (HttpInstance
->CacheBody
);
1264 HttpInstance
->CacheBody
= NULL
;
1265 HttpInstance
->NextMsg
= NULL
;
1266 HttpInstance
->CacheOffset
= 0;
1270 // Return since we aready received required data.
1272 Status
= EFI_SUCCESS
;
1276 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1278 // We received a complete HTTP message, and we don't have more data to return to caller.
1280 HttpMsg
->BodyLength
= 0;
1281 Status
= EFI_SUCCESS
;
1286 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1289 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1291 if (!HttpInstance
->UseHttps
) {
1292 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1294 if (EFI_ERROR (Status
)) {
1299 if (HttpInstance
->TimeoutEvent
== NULL
) {
1301 // Create TimeoutEvent for response
1303 Status
= gBS
->CreateEvent (
1308 &HttpInstance
->TimeoutEvent
1310 if (EFI_ERROR (Status
)) {
1316 // Start the timer, and wait Timeout seconds to receive the body packet.
1318 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1319 if (EFI_ERROR (Status
)) {
1323 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1325 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1327 if (EFI_ERROR (Status
)) {
1332 // Check whether we receive a complete HTTP message.
1334 Status
= HttpParseMessageBody (
1335 HttpInstance
->MsgParser
,
1336 (UINTN
) Fragment
.Len
,
1337 (CHAR8
*) Fragment
.Bulk
1339 if (EFI_ERROR (Status
)) {
1343 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1345 // Free the MsgParse since we already have a full HTTP message.
1347 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1348 HttpInstance
->MsgParser
= NULL
;
1352 // We receive part of header of next HTTP msg.
1354 if (HttpInstance
->NextMsg
!= NULL
) {
1355 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1356 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1358 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1359 if (HttpInstance
->CacheLen
!= 0) {
1360 if (HttpInstance
->CacheBody
!= NULL
) {
1361 FreePool (HttpInstance
->CacheBody
);
1364 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1365 if (HttpInstance
->CacheBody
== NULL
) {
1366 Status
= EFI_OUT_OF_RESOURCES
;
1370 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1371 HttpInstance
->CacheOffset
= 0;
1373 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1376 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1377 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1378 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1379 if (HttpInstance
->CacheLen
!= 0) {
1380 if (HttpInstance
->CacheBody
!= NULL
) {
1381 FreePool (HttpInstance
->CacheBody
);
1384 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1385 if (HttpInstance
->CacheBody
== NULL
) {
1386 Status
= EFI_OUT_OF_RESOURCES
;
1390 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1391 HttpInstance
->CacheOffset
= 0;
1395 if (Fragment
.Bulk
!= NULL
) {
1396 FreePool (Fragment
.Bulk
);
1397 Fragment
.Bulk
= NULL
;
1406 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1408 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1411 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1412 Token
->Status
= EFI_HTTP_ERROR
;
1414 Token
->Status
= Status
;
1417 gBS
->SignalEvent (Token
->Event
);
1418 HttpCloseTcpRxEvent (Wrap
);
1423 if (ValueInItem
!= NULL
) {
1424 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1428 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1430 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1433 if (!HttpInstance
->UseHttps
) {
1434 HttpTcpTokenCleanup (Wrap
);
1439 if (HttpHeaders
!= NULL
) {
1440 FreePool (HttpHeaders
);
1444 if (Fragment
.Bulk
!= NULL
) {
1445 FreePool (Fragment
.Bulk
);
1446 Fragment
.Bulk
= NULL
;
1449 if (HttpMsg
->Headers
!= NULL
) {
1450 FreePool (HttpMsg
->Headers
);
1451 HttpMsg
->Headers
= NULL
;
1454 if (HttpInstance
->CacheBody
!= NULL
) {
1455 FreePool (HttpInstance
->CacheBody
);
1456 HttpInstance
->CacheBody
= NULL
;
1459 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1460 Token
->Status
= EFI_HTTP_ERROR
;
1462 Token
->Status
= Status
;
1465 gBS
->SignalEvent (Token
->Event
);
1473 The Response() function queues an HTTP response to this HTTP instance, similar to
1474 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1475 or if there is an error, Status in token will be updated and Event will be signaled.
1477 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1478 is received in the underlying TCP instance, the data will be parsed and Token will
1479 be populated with the response data. If the data received from the remote host
1480 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1481 (asynchronously) for more data to be sent from the remote host before signaling
1484 It is the responsibility of the caller to allocate a buffer for Body and specify the
1485 size in BodyLength. If the remote host provides a response that contains a content
1486 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1487 BodyLength will be updated with the amount of bytes received and copied to Body. This
1488 allows the client to download a large file in chunks instead of into one contiguous
1489 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1490 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1491 token to underlying TCP instance. If data arrives in the receive buffer, up to
1492 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1493 BodyLength with the amount of bytes received and copied to Body.
1495 If the HTTP driver does not have an open underlying TCP connection with the host
1496 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1497 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1498 an open TCP connection between client and host.
1500 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1501 @param[in] Token Pointer to storage containing HTTP response token.
1503 @retval EFI_SUCCESS Allocation succeeded.
1504 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1506 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1509 Token->Message->Headers is NULL.
1510 Token->Message is NULL.
1511 Token->Message->Body is not NULL,
1512 Token->Message->BodyLength is non-zero, and
1513 Token->Message->Data is NULL, but a previous call to
1514 Response() has not been completed successfully.
1515 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1516 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1517 specified by response URL.
1522 IN EFI_HTTP_PROTOCOL
*This
,
1523 IN EFI_HTTP_TOKEN
*Token
1527 EFI_HTTP_MESSAGE
*HttpMsg
;
1528 HTTP_PROTOCOL
*HttpInstance
;
1529 HTTP_TOKEN_WRAP
*Wrap
;
1531 if ((This
== NULL
) || (Token
== NULL
)) {
1532 return EFI_INVALID_PARAMETER
;
1535 HttpMsg
= Token
->Message
;
1536 if (HttpMsg
== NULL
) {
1537 return EFI_INVALID_PARAMETER
;
1540 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1541 ASSERT (HttpInstance
!= NULL
);
1543 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1544 return EFI_NOT_STARTED
;
1548 // Check whether the token already existed.
1550 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1551 return EFI_ACCESS_DENIED
;
1554 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1556 return EFI_OUT_OF_RESOURCES
;
1559 Wrap
->HttpInstance
= HttpInstance
;
1560 Wrap
->HttpToken
= Token
;
1563 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1564 // receive the https response. A special TlsRxToken is used for receiving TLS
1565 // related messages. It should be a blocking response.
1567 if (!HttpInstance
->UseHttps
) {
1568 Status
= HttpCreateTcpRxEvent (Wrap
);
1569 if (EFI_ERROR (Status
)) {
1574 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1575 if (EFI_ERROR (Status
)) {
1580 // If already have pending RxTokens, return directly.
1582 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1586 return HttpResponseWorker (Wrap
);
1590 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1591 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1594 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1595 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1604 The Poll() function can be used by network drivers and applications to increase the
1605 rate that data packets are moved between the communication devices and the transmit
1608 In some systems, the periodic timer event in the managed network driver may not poll
1609 the underlying communications device fast enough to transmit and/or receive all data
1610 packets without missing incoming packets or dropping outgoing packets. Drivers and
1611 applications that are experiencing packet loss should try calling the Poll() function
1614 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1616 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1617 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1618 @retval EFI_INVALID_PARAMETER This is NULL.
1619 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1620 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1626 IN EFI_HTTP_PROTOCOL
*This
1630 HTTP_PROTOCOL
*HttpInstance
;
1633 return EFI_INVALID_PARAMETER
;
1636 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1637 ASSERT (HttpInstance
!= NULL
);
1639 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1640 return EFI_NOT_STARTED
;
1643 if (HttpInstance
->LocalAddressIsIPv6
) {
1644 if (HttpInstance
->Tcp6
== NULL
) {
1645 return EFI_NOT_STARTED
;
1647 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1649 if (HttpInstance
->Tcp4
== NULL
) {
1650 return EFI_NOT_STARTED
;
1652 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);