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
38 @retval EFI_SUCCESS Operation succeeded.
39 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
41 HttpConfigData is NULL.
42 HttpInstance->LocalAddressIsIPv6 is FALSE and
43 HttpConfigData->IPv4Node is NULL.
44 HttpInstance->LocalAddressIsIPv6 is TRUE and
45 HttpConfigData->IPv6Node is NULL.
46 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
52 IN EFI_HTTP_PROTOCOL
*This
,
53 OUT EFI_HTTP_CONFIG_DATA
*HttpConfigData
56 HTTP_PROTOCOL
*HttpInstance
;
59 // Check input parameters.
61 if ((This
== NULL
) || (HttpConfigData
== NULL
)) {
62 return EFI_INVALID_PARAMETER
;
65 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
66 ASSERT (HttpInstance
!= NULL
);
68 if ((HttpInstance
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
69 (!HttpInstance
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)) {
70 return EFI_INVALID_PARAMETER
;
73 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
74 return EFI_NOT_STARTED
;
77 HttpConfigData
->HttpVersion
= HttpInstance
->HttpVersion
;
78 HttpConfigData
->TimeOutMillisec
= HttpInstance
->TimeOutMillisec
;
79 HttpConfigData
->LocalAddressIsIPv6
= HttpInstance
->LocalAddressIsIPv6
;
81 if (HttpInstance
->LocalAddressIsIPv6
) {
83 HttpConfigData
->AccessPoint
.IPv6Node
,
84 &HttpInstance
->Ipv6Node
,
85 sizeof (HttpInstance
->Ipv6Node
)
89 HttpConfigData
->AccessPoint
.IPv4Node
,
90 &HttpInstance
->IPv4Node
,
91 sizeof (HttpInstance
->IPv4Node
)
99 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
101 The Configure() function does the following:
102 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
103 timeout, local address, port, etc.
104 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
105 connections with remote hosts, canceling all asynchronous tokens, and flush request
106 and response buffers without informing the appropriate hosts.
108 No other EFI HTTP function can be executed by this instance until the Configure()
109 function is executed and returns successfully.
111 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
112 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
114 @retval EFI_SUCCESS Operation succeeded.
115 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
117 HttpConfigData->LocalAddressIsIPv6 is FALSE and
118 HttpConfigData->IPv4Node is NULL.
119 HttpConfigData->LocalAddressIsIPv6 is TRUE and
120 HttpConfigData->IPv6Node is NULL.
121 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
122 Configure() with NULL to reset it.
123 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
124 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
125 executing Configure().
126 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
127 in the implementation.
132 IN EFI_HTTP_PROTOCOL
*This
,
133 IN EFI_HTTP_CONFIG_DATA
*HttpConfigData OPTIONAL
136 HTTP_PROTOCOL
*HttpInstance
;
140 // Check input parameters.
143 (HttpConfigData
!= NULL
&&
144 ((HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
145 (!HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)))) {
146 return EFI_INVALID_PARAMETER
;
149 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
150 ASSERT (HttpInstance
!= NULL
&& HttpInstance
->Service
!= NULL
);
152 if (HttpConfigData
!= NULL
) {
154 if (HttpConfigData
->HttpVersion
>= HttpVersionUnsupported
) {
155 return EFI_UNSUPPORTED
;
159 // Now configure this HTTP instance.
161 if (HttpInstance
->State
!= HTTP_STATE_UNCONFIGED
) {
162 return EFI_ALREADY_STARTED
;
165 HttpInstance
->HttpVersion
= HttpConfigData
->HttpVersion
;
166 HttpInstance
->TimeOutMillisec
= HttpConfigData
->TimeOutMillisec
;
167 HttpInstance
->LocalAddressIsIPv6
= HttpConfigData
->LocalAddressIsIPv6
;
169 if (HttpConfigData
->LocalAddressIsIPv6
) {
171 &HttpInstance
->Ipv6Node
,
172 HttpConfigData
->AccessPoint
.IPv6Node
,
173 sizeof (HttpInstance
->Ipv6Node
)
177 &HttpInstance
->IPv4Node
,
178 HttpConfigData
->AccessPoint
.IPv4Node
,
179 sizeof (HttpInstance
->IPv4Node
)
186 Status
= HttpInitProtocol (HttpInstance
, HttpInstance
->LocalAddressIsIPv6
);
187 if (EFI_ERROR (Status
)) {
191 HttpInstance
->State
= HTTP_STATE_HTTP_CONFIGED
;
196 // Reset all the resources related to HttpInsance.
198 HttpCleanProtocol (HttpInstance
);
199 HttpInstance
->State
= HTTP_STATE_UNCONFIGED
;
206 The Request() function queues an HTTP request to this HTTP instance.
208 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
209 successfully, or if there is an error, Status in token will be updated and Event will
212 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
213 @param[in] Token Pointer to storage containing HTTP request token.
215 @retval EFI_SUCCESS Outgoing data was processed.
216 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
217 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
218 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
219 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
220 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
222 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
225 Token->Message is NULL.
226 Token->Message->Body is not NULL,
227 Token->Message->BodyLength is non-zero, and
228 Token->Message->Data is NULL, but a previous call to
229 Request()has not been completed successfully.
234 IN EFI_HTTP_PROTOCOL
*This
,
235 IN EFI_HTTP_TOKEN
*Token
238 EFI_HTTP_MESSAGE
*HttpMsg
;
239 EFI_HTTP_REQUEST_DATA
*Request
;
245 HTTP_PROTOCOL
*HttpInstance
;
248 BOOLEAN TlsConfigure
;
253 HTTP_TOKEN_WRAP
*Wrap
;
255 UINTN RequestMsgSize
;
256 EFI_HANDLE ImageHandle
;
269 TlsConfigure
= FALSE
;
271 if ((This
== NULL
) || (Token
== NULL
)) {
272 return EFI_INVALID_PARAMETER
;
275 HttpMsg
= Token
->Message
;
276 if (HttpMsg
== NULL
) {
277 return EFI_INVALID_PARAMETER
;
280 Request
= HttpMsg
->Data
.Request
;
283 // Only support GET, HEAD, PATCH, PUT and POST method in current implementation.
285 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
286 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodPut
) &&
287 (Request
->Method
!= HttpMethodPost
) && (Request
->Method
!= HttpMethodPatch
)) {
288 return EFI_UNSUPPORTED
;
291 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
292 ASSERT (HttpInstance
!= NULL
);
295 // Capture the method into HttpInstance.
297 if (Request
!= NULL
) {
298 HttpInstance
->Method
= Request
->Method
;
301 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
302 return EFI_NOT_STARTED
;
305 if (Request
== NULL
) {
307 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)
309 if ((HttpInstance
->Method
!= HttpMethodPut
) &&
310 (HttpInstance
->Method
!= HttpMethodPost
) &&
311 (HttpInstance
->Method
!= HttpMethodPatch
)) {
312 return EFI_INVALID_PARAMETER
;
316 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!
318 if (HttpInstance
->State
< HTTP_STATE_TCP_CONFIGED
) {
319 return EFI_INVALID_PARAMETER
;
323 // We need to have the Message Body for sending the HTTP message across in these cases.
325 if (HttpMsg
->Body
== NULL
|| HttpMsg
->BodyLength
== 0) {
326 return EFI_INVALID_PARAMETER
;
330 // Use existing TCP instance to transmit the packet.
336 // Check whether the token already existed.
338 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTokenExist
, Token
))) {
339 return EFI_ACCESS_DENIED
;
343 // Parse the URI of the remote host.
345 Url
= HttpInstance
->Url
;
346 UrlLen
= StrLen (Request
->Url
) + 1;
347 if (UrlLen
> HTTP_URL_BUFFER_LEN
) {
348 Url
= AllocateZeroPool (UrlLen
);
350 return EFI_OUT_OF_RESOURCES
;
352 FreePool (HttpInstance
->Url
);
353 HttpInstance
->Url
= Url
;
357 UnicodeStrToAsciiStrS (Request
->Url
, Url
, UrlLen
);
360 // From the information in Url, the HTTP instance will
361 // be able to determine whether to use http or https.
363 HttpInstance
->UseHttps
= IsHttpsUrl (Url
);
366 // HTTP is disabled, return directly if the URI is not HTTPS.
368 if (!PcdGetBool (PcdAllowHttpConnections
) && !(HttpInstance
->UseHttps
)) {
370 DEBUG ((EFI_D_ERROR
, "EfiHttpRequest: HTTP is disabled.\n"));
372 return EFI_ACCESS_DENIED
;
376 // Check whether we need to create Tls child and open the TLS protocol.
378 if (HttpInstance
->UseHttps
&& HttpInstance
->TlsChildHandle
== NULL
) {
380 // Use TlsSb to create Tls child and open the TLS protocol.
382 if (HttpInstance
->LocalAddressIsIPv6
) {
383 ImageHandle
= HttpInstance
->Service
->Ip6DriverBindingHandle
;
385 ImageHandle
= HttpInstance
->Service
->Ip4DriverBindingHandle
;
388 HttpInstance
->TlsChildHandle
= TlsCreateChild (
390 &(HttpInstance
->TlsSb
),
391 &(HttpInstance
->Tls
),
392 &(HttpInstance
->TlsConfiguration
)
394 if (HttpInstance
->TlsChildHandle
== NULL
) {
395 return EFI_DEVICE_ERROR
;
402 Status
= HttpParseUrl (Url
, (UINT32
) AsciiStrLen (Url
), FALSE
, &UrlParser
);
403 if (EFI_ERROR (Status
)) {
408 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
409 if (EFI_ERROR (Status
)) {
413 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
414 if (EFI_ERROR (Status
)) {
415 if (HttpInstance
->UseHttps
) {
416 RemotePort
= HTTPS_DEFAULT_PORT
;
418 RemotePort
= HTTP_DEFAULT_PORT
;
422 // If Configure is TRUE, it indicates the first time to call Request();
423 // If ReConfigure is TRUE, it indicates the request URL is not same
424 // with the previous call to Request();
429 if (HttpInstance
->RemoteHost
== NULL
) {
431 // Request() is called the first time.
435 if ((HttpInstance
->RemotePort
== RemotePort
) &&
436 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
437 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
439 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
441 // Host Name and port number of the request URL are the same with previous call to Request().
442 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
443 // Check whether previous TCP packet sent out.
446 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
448 // Wrap the HTTP token in HTTP_TOKEN_WRAP
450 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
452 Status
= EFI_OUT_OF_RESOURCES
;
456 Wrap
->HttpToken
= Token
;
457 Wrap
->HttpInstance
= HttpInstance
;
459 Status
= HttpCreateTcpTxEvent (Wrap
);
460 if (EFI_ERROR (Status
)) {
464 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
465 if (EFI_ERROR (Status
)) {
469 Wrap
->TcpWrap
.Method
= Request
->Method
;
474 // Queue the HTTP token and return.
479 // Use existing TCP instance to transmit the packet.
486 // Need close existing TCP instance and create a new TCP instance for data transmit.
488 if (HttpInstance
->RemoteHost
!= NULL
) {
489 FreePool (HttpInstance
->RemoteHost
);
490 HttpInstance
->RemoteHost
= NULL
;
491 HttpInstance
->RemotePort
= 0;
499 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
501 if (!HttpInstance
->LocalAddressIsIPv6
) {
502 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
504 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
507 if (EFI_ERROR (Status
)) {
508 HostNameSize
= AsciiStrSize (HostName
);
509 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
510 if (HostNameStr
== NULL
) {
511 Status
= EFI_OUT_OF_RESOURCES
;
515 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
516 if (!HttpInstance
->LocalAddressIsIPv6
) {
517 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
519 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
522 FreePool (HostNameStr
);
523 if (EFI_ERROR (Status
)) {
529 // Save the RemotePort and RemoteHost.
531 ASSERT (HttpInstance
->RemoteHost
== NULL
);
532 HttpInstance
->RemotePort
= RemotePort
;
533 HttpInstance
->RemoteHost
= HostName
;
539 // The request URL is different from previous calls to Request(), close existing TCP instance.
541 if (!HttpInstance
->LocalAddressIsIPv6
) {
542 ASSERT (HttpInstance
->Tcp4
!= NULL
);
544 ASSERT (HttpInstance
->Tcp6
!= NULL
);
547 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
548 Status
= TlsCloseSession (HttpInstance
);
549 if (EFI_ERROR (Status
)) {
553 TlsCloseTxRxEvent (HttpInstance
);
556 HttpCloseConnection (HttpInstance
);
557 EfiHttpCancel (This
, NULL
);
561 // Wrap the HTTP token in HTTP_TOKEN_WRAP
563 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
565 Status
= EFI_OUT_OF_RESOURCES
;
569 Wrap
->HttpToken
= Token
;
570 Wrap
->HttpInstance
= HttpInstance
;
571 if (Request
!= NULL
) {
572 Wrap
->TcpWrap
.Method
= Request
->Method
;
575 Status
= HttpInitSession (
578 Configure
|| ReConfigure
,
581 if (EFI_ERROR (Status
)) {
585 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
587 // For the new HTTP token, create TX TCP token events.
589 Status
= HttpCreateTcpTxEvent (Wrap
);
590 if (EFI_ERROR (Status
)) {
596 // Create request message.
599 if (Url
!= NULL
&& *FileUrl
!= '/') {
601 // Convert the absolute-URI to the absolute-path
603 while (*FileUrl
!= ':') {
606 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
608 while (*FileUrl
!= '/') {
612 Status
= EFI_INVALID_PARAMETER
;
617 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
619 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
623 ASSERT (RequestMsg
!= NULL
);
626 // Every request we insert a TxToken and a response call would remove the TxToken.
627 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
628 // continuous request without a response call. So, in such cases, where Request
629 // structure is NULL, we would not insert a TxToken.
631 if (Request
!= NULL
) {
632 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
633 if (EFI_ERROR (Status
)) {
639 // Transmit the request message.
641 Status
= HttpTransmitTcp (
647 if (EFI_ERROR (Status
)) {
653 if (HostName
!= NULL
) {
661 // We would have inserted a TxToken only if Request structure is not NULL.
662 // Hence check before we do a remove in this error case.
664 if (Request
!= NULL
) {
665 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
669 if (RequestMsg
!= NULL
) {
670 FreePool (RequestMsg
);
674 if (HttpInstance
->UseHttps
) {
675 TlsCloseSession (HttpInstance
);
676 TlsCloseTxRxEvent (HttpInstance
);
680 HttpCloseConnection (HttpInstance
);
682 HttpCloseTcpConnCloseEvent (HttpInstance
);
683 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
684 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
685 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
687 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
688 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
689 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
693 if (HostName
!= NULL
) {
699 if (UrlParser
!= NULL
) {
700 HttpUrlFreeParser (UrlParser
);
708 Cancel a user's Token.
710 @param[in] Map The HTTP instance's token queue.
711 @param[in] Item Object container for one HTTP token and token's wrap.
712 @param[in] Context The user's token to cancel.
714 @retval EFI_SUCCESS Continue to check the next Item.
715 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
722 IN NET_MAP_ITEM
*Item
,
726 EFI_HTTP_TOKEN
*Token
;
727 HTTP_TOKEN_WRAP
*Wrap
;
728 HTTP_PROTOCOL
*HttpInstance
;
730 Token
= (EFI_HTTP_TOKEN
*) Context
;
733 // Return EFI_SUCCESS to check the next item in the map if
734 // this one doesn't match.
736 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
740 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
741 ASSERT (Wrap
!= NULL
);
742 HttpInstance
= Wrap
->HttpInstance
;
744 if (!HttpInstance
->LocalAddressIsIPv6
) {
745 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
747 // Cancle the Token before close its Event.
749 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
752 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
757 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
759 // Cancle the Token before close its Event.
761 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
764 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
771 // If only one item is to be cancel, return EFI_ABORTED to stop
772 // iterating the map any more.
782 Cancel the user's receive/transmit request. It is the worker function of
783 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
786 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
787 @param[in] Token The token to cancel. If NULL, all token will be
790 @retval EFI_SUCCESS The token is cancelled.
791 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
792 @retval Others Other error as indicated.
797 IN HTTP_PROTOCOL
*HttpInstance
,
798 IN EFI_HTTP_TOKEN
*Token
804 // First check the tokens queued by EfiHttpRequest().
806 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
807 if (EFI_ERROR (Status
)) {
809 if (Status
== EFI_ABORTED
) {
817 if (!HttpInstance
->UseHttps
) {
819 // Then check the tokens queued by EfiHttpResponse(), except for Https.
821 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
822 if (EFI_ERROR (Status
)) {
824 if (Status
== EFI_ABORTED
) {
827 return EFI_NOT_FOUND
;
834 if (!HttpInstance
->LocalAddressIsIPv6
) {
835 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
837 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
846 Abort an asynchronous HTTP request or response token.
848 The Cancel() function aborts a pending HTTP request or response transaction. If
849 Token is not NULL and the token is in transmit or receive queues when it is being
850 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
851 be signaled. If the token is not in one of the queues, which usually means that the
852 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
853 all asynchronous tokens issued by Request() or Response() will be aborted.
855 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
856 @param[in] Token Point to storage containing HTTP request or response
859 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
860 @retval EFI_INVALID_PARAMETER This is NULL.
861 @retval EFI_NOT_STARTED This instance hasn't been configured.
862 @retval EFI_NOT_FOUND The asynchronous request or response token is not
864 @retval EFI_UNSUPPORTED The implementation does not support this function.
870 IN EFI_HTTP_PROTOCOL
*This
,
871 IN EFI_HTTP_TOKEN
*Token
874 HTTP_PROTOCOL
*HttpInstance
;
877 return EFI_INVALID_PARAMETER
;
880 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
881 ASSERT (HttpInstance
!= NULL
);
883 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
884 return EFI_NOT_STARTED
;
887 return HttpCancel (HttpInstance
, Token
);
892 A callback function to intercept events during message parser.
894 This function will be invoked during HttpParseMessageBody() with various events type. An error
895 return status of the callback function will cause the HttpParseMessageBody() aborted.
897 @param[in] EventType Event type of this callback call.
898 @param[in] Data A pointer to data buffer.
899 @param[in] Length Length in bytes of the Data.
900 @param[in] Context Callback context set by HttpInitMsgParser().
902 @retval EFI_SUCCESS Continue to parser the message body.
907 HttpBodyParserCallback (
908 IN HTTP_BODY_PARSE_EVENT EventType
,
914 HTTP_TOKEN_WRAP
*Wrap
;
918 if (EventType
!= BodyParseEventOnComplete
) {
922 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
926 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
927 Body
= Wrap
->HttpToken
->Message
->Body
;
928 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
929 if (Data
< Body
+ BodyLength
) {
930 Wrap
->HttpInstance
->NextMsg
= Data
;
932 Wrap
->HttpInstance
->NextMsg
= NULL
;
937 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
945 The work function of EfiHttpResponse().
947 @param[in] Wrap Pointer to HTTP token's wrap data.
949 @retval EFI_SUCCESS Allocation succeeded.
950 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
951 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
952 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
957 IN HTTP_TOKEN_WRAP
*Wrap
961 EFI_HTTP_MESSAGE
*HttpMsg
;
969 CHAR8
*StatusCodeStr
;
971 HTTP_PROTOCOL
*HttpInstance
;
972 EFI_HTTP_TOKEN
*Token
;
974 HTTP_TOKEN_WRAP
*ValueInItem
;
976 NET_FRAGMENT Fragment
;
978 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
979 return EFI_INVALID_PARAMETER
;
982 HttpInstance
= Wrap
->HttpInstance
;
983 Token
= Wrap
->HttpToken
;
984 HttpMsg
= Token
->Message
;
986 HttpInstance
->EndofHeader
= NULL
;
987 HttpInstance
->HttpHeaders
= NULL
;
988 HttpMsg
->Headers
= NULL
;
995 Fragment
.Bulk
= NULL
;
997 if (HttpMsg
->Data
.Response
!= NULL
) {
999 // Check whether we have cached header from previous call.
1001 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1003 // The data is stored at [NextMsg, CacheBody + CacheLen].
1005 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1006 HttpHeaders
= AllocateZeroPool (HdrLen
);
1007 if (HttpHeaders
== NULL
) {
1008 Status
= EFI_OUT_OF_RESOURCES
;
1012 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1013 FreePool (HttpInstance
->CacheBody
);
1014 HttpInstance
->CacheBody
= NULL
;
1015 HttpInstance
->NextMsg
= NULL
;
1016 HttpInstance
->CacheOffset
= 0;
1017 SizeofHeaders
= HdrLen
;
1018 BufferSize
= HttpInstance
->CacheLen
;
1021 // Check whether we cached the whole HTTP headers.
1023 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1026 HttpInstance
->EndofHeader
= &EndofHeader
;
1027 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1030 if (HttpInstance
->TimeoutEvent
== NULL
) {
1032 // Create TimeoutEvent for response
1034 Status
= gBS
->CreateEvent (
1039 &HttpInstance
->TimeoutEvent
1041 if (EFI_ERROR (Status
)) {
1047 // Start the timer, and wait Timeout seconds to receive the header packet.
1049 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1050 if (EFI_ERROR (Status
)) {
1054 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1056 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1058 if (EFI_ERROR (Status
)) {
1062 ASSERT (HttpHeaders
!= NULL
);
1065 // Cache the part of body.
1067 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1069 if (HttpInstance
->CacheBody
!= NULL
) {
1070 FreePool (HttpInstance
->CacheBody
);
1073 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1074 if (HttpInstance
->CacheBody
== NULL
) {
1075 Status
= EFI_OUT_OF_RESOURCES
;
1079 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1080 HttpInstance
->CacheLen
= BodyLen
;
1084 // Search for Status Code.
1086 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1087 if (StatusCodeStr
== NULL
) {
1088 Status
= EFI_NOT_READY
;
1092 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1095 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1097 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1099 Status
= EFI_NOT_READY
;
1104 // We could have response with just a HTTP message and no headers. For Example,
1105 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1106 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1107 // set SizeofHeaders to 0.
1109 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1110 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1113 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1116 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1117 HttpInstance
->StatusCode
= StatusCode
;
1119 Status
= EFI_NOT_READY
;
1123 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1124 // continuous request without a response call. So, we would not do an insert of
1125 // TxToken. After we have sent the complete file, we will call a response to get
1126 // a final response from server. In such a case, we would not have any TxTokens.
1127 // Hence, check that case before doing a NetMapRemoveHead.
1129 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1130 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1131 if (ValueInItem
== NULL
) {
1136 // The first Tx Token not transmitted yet, insert back and return error.
1138 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1143 if (SizeofHeaders
!= 0) {
1144 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1145 if (HeaderTmp
== NULL
) {
1146 Status
= EFI_OUT_OF_RESOURCES
;
1150 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1151 FreePool (HttpHeaders
);
1152 HttpHeaders
= HeaderTmp
;
1155 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1157 if (mHttpUtilities
== NULL
) {
1158 Status
= EFI_NOT_READY
;
1163 // Parse the HTTP header into array of key/value pairs.
1165 Status
= mHttpUtilities
->Parse (
1170 &HttpMsg
->HeaderCount
1172 if (EFI_ERROR (Status
)) {
1176 FreePool (HttpHeaders
);
1181 // Init message-body parser by header information.
1183 Status
= HttpInitMsgParser (
1184 HttpInstance
->Method
,
1185 HttpMsg
->Data
.Response
->StatusCode
,
1186 HttpMsg
->HeaderCount
,
1188 HttpBodyParserCallback
,
1189 (VOID
*) ValueInItem
,
1190 &HttpInstance
->MsgParser
1192 if (EFI_ERROR (Status
)) {
1197 // Check whether we received a complete HTTP message.
1199 if (HttpInstance
->CacheBody
!= NULL
) {
1200 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1201 if (EFI_ERROR (Status
)) {
1205 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1207 // Free the MsgParse since we already have a full HTTP message.
1209 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1210 HttpInstance
->MsgParser
= NULL
;
1215 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1216 Status
= EFI_SUCCESS
;
1222 // Receive the response body.
1227 // First check whether we cached some data.
1229 if (HttpInstance
->CacheBody
!= NULL
) {
1231 // Calculate the length of the cached data.
1233 if (HttpInstance
->NextMsg
!= NULL
) {
1235 // We have a cached HTTP message which includes a part of HTTP header of next message.
1237 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1239 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1244 // We have some cached data. Just copy the data and return.
1246 if (HttpMsg
->BodyLength
< BodyLen
) {
1247 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1248 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1251 // Copy all cached data out.
1253 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1254 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1255 HttpMsg
->BodyLength
= BodyLen
;
1257 if (HttpInstance
->NextMsg
== NULL
) {
1259 // There is no HTTP header of next message. Just free the cache buffer.
1261 FreePool (HttpInstance
->CacheBody
);
1262 HttpInstance
->CacheBody
= NULL
;
1263 HttpInstance
->NextMsg
= NULL
;
1264 HttpInstance
->CacheOffset
= 0;
1268 // Return since we aready received required data.
1270 Status
= EFI_SUCCESS
;
1274 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1276 // We received a complete HTTP message, and we don't have more data to return to caller.
1278 HttpMsg
->BodyLength
= 0;
1279 Status
= EFI_SUCCESS
;
1284 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1287 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1289 if (!HttpInstance
->UseHttps
) {
1290 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1292 if (EFI_ERROR (Status
)) {
1297 if (HttpInstance
->TimeoutEvent
== NULL
) {
1299 // Create TimeoutEvent for response
1301 Status
= gBS
->CreateEvent (
1306 &HttpInstance
->TimeoutEvent
1308 if (EFI_ERROR (Status
)) {
1314 // Start the timer, and wait Timeout seconds to receive the body packet.
1316 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1317 if (EFI_ERROR (Status
)) {
1321 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1323 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1325 if (EFI_ERROR (Status
)) {
1330 // Check whether we receive a complete HTTP message.
1332 Status
= HttpParseMessageBody (
1333 HttpInstance
->MsgParser
,
1334 (UINTN
) Fragment
.Len
,
1335 (CHAR8
*) Fragment
.Bulk
1337 if (EFI_ERROR (Status
)) {
1341 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1343 // Free the MsgParse since we already have a full HTTP message.
1345 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1346 HttpInstance
->MsgParser
= NULL
;
1350 // We receive part of header of next HTTP msg.
1352 if (HttpInstance
->NextMsg
!= NULL
) {
1353 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1354 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1356 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1357 if (HttpInstance
->CacheLen
!= 0) {
1358 if (HttpInstance
->CacheBody
!= NULL
) {
1359 FreePool (HttpInstance
->CacheBody
);
1362 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1363 if (HttpInstance
->CacheBody
== NULL
) {
1364 Status
= EFI_OUT_OF_RESOURCES
;
1368 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1369 HttpInstance
->CacheOffset
= 0;
1371 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1374 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1375 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1376 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1377 if (HttpInstance
->CacheLen
!= 0) {
1378 if (HttpInstance
->CacheBody
!= NULL
) {
1379 FreePool (HttpInstance
->CacheBody
);
1382 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1383 if (HttpInstance
->CacheBody
== NULL
) {
1384 Status
= EFI_OUT_OF_RESOURCES
;
1388 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1389 HttpInstance
->CacheOffset
= 0;
1393 if (Fragment
.Bulk
!= NULL
) {
1394 FreePool (Fragment
.Bulk
);
1395 Fragment
.Bulk
= NULL
;
1404 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1406 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1409 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1410 Token
->Status
= EFI_HTTP_ERROR
;
1412 Token
->Status
= Status
;
1415 gBS
->SignalEvent (Token
->Event
);
1416 HttpCloseTcpRxEvent (Wrap
);
1421 if (ValueInItem
!= NULL
) {
1422 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1426 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1428 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1431 if (!HttpInstance
->UseHttps
) {
1432 HttpTcpTokenCleanup (Wrap
);
1437 if (HttpHeaders
!= NULL
) {
1438 FreePool (HttpHeaders
);
1442 if (Fragment
.Bulk
!= NULL
) {
1443 FreePool (Fragment
.Bulk
);
1444 Fragment
.Bulk
= NULL
;
1447 if (HttpMsg
->Headers
!= NULL
) {
1448 FreePool (HttpMsg
->Headers
);
1449 HttpMsg
->Headers
= NULL
;
1452 if (HttpInstance
->CacheBody
!= NULL
) {
1453 FreePool (HttpInstance
->CacheBody
);
1454 HttpInstance
->CacheBody
= NULL
;
1457 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1458 Token
->Status
= EFI_HTTP_ERROR
;
1460 Token
->Status
= Status
;
1463 gBS
->SignalEvent (Token
->Event
);
1471 The Response() function queues an HTTP response to this HTTP instance, similar to
1472 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1473 or if there is an error, Status in token will be updated and Event will be signaled.
1475 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1476 is received in the underlying TCP instance, the data will be parsed and Token will
1477 be populated with the response data. If the data received from the remote host
1478 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1479 (asynchronously) for more data to be sent from the remote host before signaling
1482 It is the responsibility of the caller to allocate a buffer for Body and specify the
1483 size in BodyLength. If the remote host provides a response that contains a content
1484 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1485 BodyLength will be updated with the amount of bytes received and copied to Body. This
1486 allows the client to download a large file in chunks instead of into one contiguous
1487 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1488 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1489 token to underlying TCP instance. If data arrives in the receive buffer, up to
1490 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1491 BodyLength with the amount of bytes received and copied to Body.
1493 If the HTTP driver does not have an open underlying TCP connection with the host
1494 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1495 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1496 an open TCP connection between client and host.
1498 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1499 @param[in] Token Pointer to storage containing HTTP response token.
1501 @retval EFI_SUCCESS Allocation succeeded.
1502 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1504 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1507 Token->Message->Headers is NULL.
1508 Token->Message is NULL.
1509 Token->Message->Body is not NULL,
1510 Token->Message->BodyLength is non-zero, and
1511 Token->Message->Data is NULL, but a previous call to
1512 Response() has not been completed successfully.
1513 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1514 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1515 specified by response URL.
1520 IN EFI_HTTP_PROTOCOL
*This
,
1521 IN EFI_HTTP_TOKEN
*Token
1525 EFI_HTTP_MESSAGE
*HttpMsg
;
1526 HTTP_PROTOCOL
*HttpInstance
;
1527 HTTP_TOKEN_WRAP
*Wrap
;
1529 if ((This
== NULL
) || (Token
== NULL
)) {
1530 return EFI_INVALID_PARAMETER
;
1533 HttpMsg
= Token
->Message
;
1534 if (HttpMsg
== NULL
) {
1535 return EFI_INVALID_PARAMETER
;
1538 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1539 ASSERT (HttpInstance
!= NULL
);
1541 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1542 return EFI_NOT_STARTED
;
1546 // Check whether the token already existed.
1548 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1549 return EFI_ACCESS_DENIED
;
1552 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1554 return EFI_OUT_OF_RESOURCES
;
1557 Wrap
->HttpInstance
= HttpInstance
;
1558 Wrap
->HttpToken
= Token
;
1561 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1562 // receive the https response. A special TlsRxToken is used for receiving TLS
1563 // related messages. It should be a blocking response.
1565 if (!HttpInstance
->UseHttps
) {
1566 Status
= HttpCreateTcpRxEvent (Wrap
);
1567 if (EFI_ERROR (Status
)) {
1572 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1573 if (EFI_ERROR (Status
)) {
1578 // If already have pending RxTokens, return directly.
1580 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1584 return HttpResponseWorker (Wrap
);
1588 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1589 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1592 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1593 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1602 The Poll() function can be used by network drivers and applications to increase the
1603 rate that data packets are moved between the communication devices and the transmit
1606 In some systems, the periodic timer event in the managed network driver may not poll
1607 the underlying communications device fast enough to transmit and/or receive all data
1608 packets without missing incoming packets or dropping outgoing packets. Drivers and
1609 applications that are experiencing packet loss should try calling the Poll() function
1612 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1614 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1615 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1616 @retval EFI_INVALID_PARAMETER This is NULL.
1617 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1618 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1624 IN EFI_HTTP_PROTOCOL
*This
1628 HTTP_PROTOCOL
*HttpInstance
;
1631 return EFI_INVALID_PARAMETER
;
1634 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1635 ASSERT (HttpInstance
!= NULL
);
1637 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1638 return EFI_NOT_STARTED
;
1641 if (HttpInstance
->LocalAddressIsIPv6
) {
1642 if (HttpInstance
->Tcp6
== NULL
) {
1643 return EFI_NOT_STARTED
;
1645 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1647 if (HttpInstance
->Tcp4
== NULL
) {
1648 return EFI_NOT_STARTED
;
1650 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);