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
);
69 if ((HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
70 (HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)) {
71 return EFI_INVALID_PARAMETER
;
74 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
75 return EFI_NOT_STARTED
;
78 HttpConfigData
->HttpVersion
= HttpInstance
->HttpVersion
;
79 HttpConfigData
->TimeOutMillisec
= HttpInstance
->TimeOutMillisec
;
80 HttpConfigData
->LocalAddressIsIPv6
= HttpInstance
->LocalAddressIsIPv6
;
82 if (HttpInstance
->LocalAddressIsIPv6
) {
84 HttpConfigData
->AccessPoint
.IPv6Node
,
85 &HttpInstance
->Ipv6Node
,
86 sizeof (HttpInstance
->Ipv6Node
)
90 HttpConfigData
->AccessPoint
.IPv4Node
,
91 &HttpInstance
->IPv4Node
,
92 sizeof (HttpInstance
->IPv4Node
)
100 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
102 The Configure() function does the following:
103 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
104 timeout, local address, port, etc.
105 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
106 connections with remote hosts, canceling all asynchronous tokens, and flush request
107 and response buffers without informing the appropriate hosts.
109 No other EFI HTTP function can be executed by this instance until the Configure()
110 function is executed and returns successfully.
112 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
113 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
115 @retval EFI_SUCCESS Operation succeeded.
116 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
118 HttpConfigData->LocalAddressIsIPv6 is FALSE and
119 HttpConfigData->AccessPoint.IPv4Node is NULL.
120 HttpConfigData->LocalAddressIsIPv6 is TRUE and
121 HttpConfigData->AccessPoint.IPv6Node is NULL.
122 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
123 Configure() with NULL to reset it.
124 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
125 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
126 executing Configure().
127 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
128 in the implementation.
133 IN EFI_HTTP_PROTOCOL
*This
,
134 IN EFI_HTTP_CONFIG_DATA
*HttpConfigData OPTIONAL
137 HTTP_PROTOCOL
*HttpInstance
;
141 // Check input parameters.
144 (HttpConfigData
!= NULL
&&
145 ((HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
146 (!HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)))) {
147 return EFI_INVALID_PARAMETER
;
150 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
151 ASSERT (HttpInstance
->Service
!= NULL
);
153 if (HttpConfigData
!= NULL
) {
155 if (HttpConfigData
->HttpVersion
>= HttpVersionUnsupported
) {
156 return EFI_UNSUPPORTED
;
160 // Now configure this HTTP instance.
162 if (HttpInstance
->State
!= HTTP_STATE_UNCONFIGED
) {
163 return EFI_ALREADY_STARTED
;
166 HttpInstance
->HttpVersion
= HttpConfigData
->HttpVersion
;
167 HttpInstance
->TimeOutMillisec
= HttpConfigData
->TimeOutMillisec
;
168 HttpInstance
->LocalAddressIsIPv6
= HttpConfigData
->LocalAddressIsIPv6
;
170 if (HttpConfigData
->LocalAddressIsIPv6
) {
172 &HttpInstance
->Ipv6Node
,
173 HttpConfigData
->AccessPoint
.IPv6Node
,
174 sizeof (HttpInstance
->Ipv6Node
)
178 &HttpInstance
->IPv4Node
,
179 HttpConfigData
->AccessPoint
.IPv4Node
,
180 sizeof (HttpInstance
->IPv4Node
)
187 Status
= HttpInitProtocol (HttpInstance
, HttpInstance
->LocalAddressIsIPv6
);
188 if (EFI_ERROR (Status
)) {
192 HttpInstance
->State
= HTTP_STATE_HTTP_CONFIGED
;
197 // Reset all the resources related to HttpInsance.
199 HttpCleanProtocol (HttpInstance
);
200 HttpInstance
->State
= HTTP_STATE_UNCONFIGED
;
207 The Request() function queues an HTTP request to this HTTP instance.
209 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
210 successfully, or if there is an error, Status in token will be updated and Event will
213 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
214 @param[in] Token Pointer to storage containing HTTP request token.
216 @retval EFI_SUCCESS Outgoing data was processed.
217 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
218 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
219 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
220 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
221 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
223 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
226 Token->Message is NULL.
227 Token->Message->Body is not NULL,
228 Token->Message->BodyLength is non-zero, and
229 Token->Message->Data is NULL, but a previous call to
230 Request()has not been completed successfully.
235 IN EFI_HTTP_PROTOCOL
*This
,
236 IN EFI_HTTP_TOKEN
*Token
239 EFI_HTTP_MESSAGE
*HttpMsg
;
240 EFI_HTTP_REQUEST_DATA
*Request
;
246 HTTP_PROTOCOL
*HttpInstance
;
249 BOOLEAN TlsConfigure
;
254 HTTP_TOKEN_WRAP
*Wrap
;
256 UINTN RequestMsgSize
;
257 EFI_HANDLE ImageHandle
;
270 TlsConfigure
= FALSE
;
272 if ((This
== NULL
) || (Token
== NULL
)) {
273 return EFI_INVALID_PARAMETER
;
276 HttpMsg
= Token
->Message
;
277 if (HttpMsg
== NULL
) {
278 return EFI_INVALID_PARAMETER
;
281 Request
= HttpMsg
->Data
.Request
;
284 // Only support GET, HEAD, PATCH, PUT and POST method in current implementation.
286 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
287 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodPut
) &&
288 (Request
->Method
!= HttpMethodPost
) && (Request
->Method
!= HttpMethodPatch
)) {
289 return EFI_UNSUPPORTED
;
292 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
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
;
473 HttpUrlFreeParser (UrlParser
);
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
)) {
526 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
532 // Save the RemotePort and RemoteHost.
534 ASSERT (HttpInstance
->RemoteHost
== NULL
);
535 HttpInstance
->RemotePort
= RemotePort
;
536 HttpInstance
->RemoteHost
= HostName
;
542 // The request URL is different from previous calls to Request(), close existing TCP instance.
544 if (!HttpInstance
->LocalAddressIsIPv6
) {
545 ASSERT (HttpInstance
->Tcp4
!= NULL
);
547 ASSERT (HttpInstance
->Tcp6
!= NULL
);
550 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
551 Status
= TlsCloseSession (HttpInstance
);
552 if (EFI_ERROR (Status
)) {
556 TlsCloseTxRxEvent (HttpInstance
);
559 HttpCloseConnection (HttpInstance
);
560 EfiHttpCancel (This
, NULL
);
564 // Wrap the HTTP token in HTTP_TOKEN_WRAP
566 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
568 Status
= EFI_OUT_OF_RESOURCES
;
572 Wrap
->HttpToken
= Token
;
573 Wrap
->HttpInstance
= HttpInstance
;
574 if (Request
!= NULL
) {
575 Wrap
->TcpWrap
.Method
= Request
->Method
;
578 Status
= HttpInitSession (
581 Configure
|| ReConfigure
,
584 if (EFI_ERROR (Status
)) {
588 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
590 // For the new HTTP token, create TX TCP token events.
592 Status
= HttpCreateTcpTxEvent (Wrap
);
593 if (EFI_ERROR (Status
)) {
599 // Create request message.
602 if (Url
!= NULL
&& *FileUrl
!= '/') {
604 // Convert the absolute-URI to the absolute-path
606 while (*FileUrl
!= ':') {
609 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
611 while (*FileUrl
!= '/') {
615 Status
= EFI_INVALID_PARAMETER
;
620 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
622 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
627 // Every request we insert a TxToken and a response call would remove the TxToken.
628 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
629 // continuous request without a response call. So, in such cases, where Request
630 // structure is NULL, we would not insert a TxToken.
632 if (Request
!= NULL
) {
633 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
634 if (EFI_ERROR (Status
)) {
640 // Transmit the request message.
642 Status
= HttpTransmitTcp (
648 if (EFI_ERROR (Status
)) {
654 if (HostName
!= NULL
) {
658 if (UrlParser
!= NULL
) {
659 HttpUrlFreeParser (UrlParser
);
666 // We would have inserted a TxToken only if Request structure is not NULL.
667 // Hence check before we do a remove in this error case.
669 if (Request
!= NULL
) {
670 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
674 if (RequestMsg
!= NULL
) {
675 FreePool (RequestMsg
);
679 if (HttpInstance
->UseHttps
) {
680 TlsCloseSession (HttpInstance
);
681 TlsCloseTxRxEvent (HttpInstance
);
685 HttpCloseConnection (HttpInstance
);
687 HttpCloseTcpConnCloseEvent (HttpInstance
);
688 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
689 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
690 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
692 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
693 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
694 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
698 if (HostName
!= NULL
) {
704 if (UrlParser
!= NULL
) {
705 HttpUrlFreeParser (UrlParser
);
713 Cancel a user's Token.
715 @param[in] Map The HTTP instance's token queue.
716 @param[in] Item Object container for one HTTP token and token's wrap.
717 @param[in] Context The user's token to cancel.
719 @retval EFI_SUCCESS Continue to check the next Item.
720 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
727 IN NET_MAP_ITEM
*Item
,
731 EFI_HTTP_TOKEN
*Token
;
732 HTTP_TOKEN_WRAP
*Wrap
;
733 HTTP_PROTOCOL
*HttpInstance
;
735 Token
= (EFI_HTTP_TOKEN
*) Context
;
738 // Return EFI_SUCCESS to check the next item in the map if
739 // this one doesn't match.
741 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
745 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
746 ASSERT (Wrap
!= NULL
);
747 HttpInstance
= Wrap
->HttpInstance
;
749 if (!HttpInstance
->LocalAddressIsIPv6
) {
750 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
752 // Cancle the Token before close its Event.
754 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
757 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
762 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
764 // Cancle the Token before close its Event.
766 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
769 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
776 // If only one item is to be cancel, return EFI_ABORTED to stop
777 // iterating the map any more.
787 Cancel the user's receive/transmit request. It is the worker function of
788 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
791 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
792 @param[in] Token The token to cancel. If NULL, all token will be
795 @retval EFI_SUCCESS The token is cancelled.
796 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
797 @retval Others Other error as indicated.
802 IN HTTP_PROTOCOL
*HttpInstance
,
803 IN EFI_HTTP_TOKEN
*Token
809 // First check the tokens queued by EfiHttpRequest().
811 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
812 if (EFI_ERROR (Status
)) {
814 if (Status
== EFI_ABORTED
) {
822 if (!HttpInstance
->UseHttps
) {
824 // Then check the tokens queued by EfiHttpResponse(), except for Https.
826 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
827 if (EFI_ERROR (Status
)) {
829 if (Status
== EFI_ABORTED
) {
832 return EFI_NOT_FOUND
;
839 if (!HttpInstance
->LocalAddressIsIPv6
) {
840 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
842 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
851 Abort an asynchronous HTTP request or response token.
853 The Cancel() function aborts a pending HTTP request or response transaction. If
854 Token is not NULL and the token is in transmit or receive queues when it is being
855 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
856 be signaled. If the token is not in one of the queues, which usually means that the
857 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
858 all asynchronous tokens issued by Request() or Response() will be aborted.
860 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
861 @param[in] Token Point to storage containing HTTP request or response
864 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
865 @retval EFI_INVALID_PARAMETER This is NULL.
866 @retval EFI_NOT_STARTED This instance hasn't been configured.
867 @retval EFI_NOT_FOUND The asynchronous request or response token is not
869 @retval EFI_UNSUPPORTED The implementation does not support this function.
875 IN EFI_HTTP_PROTOCOL
*This
,
876 IN EFI_HTTP_TOKEN
*Token
879 HTTP_PROTOCOL
*HttpInstance
;
882 return EFI_INVALID_PARAMETER
;
885 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
887 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
888 return EFI_NOT_STARTED
;
891 return HttpCancel (HttpInstance
, Token
);
896 A callback function to intercept events during message parser.
898 This function will be invoked during HttpParseMessageBody() with various events type. An error
899 return status of the callback function will cause the HttpParseMessageBody() aborted.
901 @param[in] EventType Event type of this callback call.
902 @param[in] Data A pointer to data buffer.
903 @param[in] Length Length in bytes of the Data.
904 @param[in] Context Callback context set by HttpInitMsgParser().
906 @retval EFI_SUCCESS Continue to parser the message body.
911 HttpBodyParserCallback (
912 IN HTTP_BODY_PARSE_EVENT EventType
,
918 HTTP_TOKEN_WRAP
*Wrap
;
922 if (EventType
!= BodyParseEventOnComplete
) {
926 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
930 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
931 Body
= Wrap
->HttpToken
->Message
->Body
;
932 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
933 if (Data
< Body
+ BodyLength
) {
934 Wrap
->HttpInstance
->NextMsg
= Data
;
936 Wrap
->HttpInstance
->NextMsg
= NULL
;
941 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
949 The work function of EfiHttpResponse().
951 @param[in] Wrap Pointer to HTTP token's wrap data.
953 @retval EFI_SUCCESS Allocation succeeded.
954 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
955 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
956 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
961 IN HTTP_TOKEN_WRAP
*Wrap
965 EFI_HTTP_MESSAGE
*HttpMsg
;
973 CHAR8
*StatusCodeStr
;
975 HTTP_PROTOCOL
*HttpInstance
;
976 EFI_HTTP_TOKEN
*Token
;
978 HTTP_TOKEN_WRAP
*ValueInItem
;
980 NET_FRAGMENT Fragment
;
982 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
983 return EFI_INVALID_PARAMETER
;
986 HttpInstance
= Wrap
->HttpInstance
;
987 Token
= Wrap
->HttpToken
;
988 HttpMsg
= Token
->Message
;
990 HttpInstance
->EndofHeader
= NULL
;
991 HttpInstance
->HttpHeaders
= NULL
;
992 HttpMsg
->Headers
= NULL
;
999 Fragment
.Bulk
= NULL
;
1001 if (HttpMsg
->Data
.Response
!= NULL
) {
1003 // Check whether we have cached header from previous call.
1005 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1007 // The data is stored at [NextMsg, CacheBody + CacheLen].
1009 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1010 HttpHeaders
= AllocateZeroPool (HdrLen
);
1011 if (HttpHeaders
== NULL
) {
1012 Status
= EFI_OUT_OF_RESOURCES
;
1016 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1017 FreePool (HttpInstance
->CacheBody
);
1018 HttpInstance
->CacheBody
= NULL
;
1019 HttpInstance
->NextMsg
= NULL
;
1020 HttpInstance
->CacheOffset
= 0;
1021 SizeofHeaders
= HdrLen
;
1022 BufferSize
= HttpInstance
->CacheLen
;
1025 // Check whether we cached the whole HTTP headers.
1027 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1030 HttpInstance
->EndofHeader
= &EndofHeader
;
1031 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1034 if (HttpInstance
->TimeoutEvent
== NULL
) {
1036 // Create TimeoutEvent for response
1038 Status
= gBS
->CreateEvent (
1043 &HttpInstance
->TimeoutEvent
1045 if (EFI_ERROR (Status
)) {
1051 // Start the timer, and wait Timeout seconds to receive the header packet.
1053 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1054 if (EFI_ERROR (Status
)) {
1058 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1060 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1062 if (EFI_ERROR (Status
)) {
1066 ASSERT (HttpHeaders
!= NULL
);
1069 // Cache the part of body.
1071 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1073 if (HttpInstance
->CacheBody
!= NULL
) {
1074 FreePool (HttpInstance
->CacheBody
);
1077 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1078 if (HttpInstance
->CacheBody
== NULL
) {
1079 Status
= EFI_OUT_OF_RESOURCES
;
1083 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1084 HttpInstance
->CacheLen
= BodyLen
;
1088 // Search for Status Code.
1090 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1091 if (StatusCodeStr
== NULL
) {
1092 Status
= EFI_NOT_READY
;
1096 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1099 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1101 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1103 Status
= EFI_NOT_READY
;
1108 // We could have response with just a HTTP message and no headers. For Example,
1109 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1110 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1111 // set SizeofHeaders to 0.
1113 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1114 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1117 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1120 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1121 HttpInstance
->StatusCode
= StatusCode
;
1123 Status
= EFI_NOT_READY
;
1127 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1128 // continuous request without a response call. So, we would not do an insert of
1129 // TxToken. After we have sent the complete file, we will call a response to get
1130 // a final response from server. In such a case, we would not have any TxTokens.
1131 // Hence, check that case before doing a NetMapRemoveHead.
1133 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1134 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1135 if (ValueInItem
== NULL
) {
1140 // The first Tx Token not transmitted yet, insert back and return error.
1142 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1147 if (SizeofHeaders
!= 0) {
1148 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1149 if (HeaderTmp
== NULL
) {
1150 Status
= EFI_OUT_OF_RESOURCES
;
1154 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1155 FreePool (HttpHeaders
);
1156 HttpHeaders
= HeaderTmp
;
1159 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1161 if (mHttpUtilities
== NULL
) {
1162 Status
= EFI_NOT_READY
;
1167 // Parse the HTTP header into array of key/value pairs.
1169 Status
= mHttpUtilities
->Parse (
1174 &HttpMsg
->HeaderCount
1176 if (EFI_ERROR (Status
)) {
1180 FreePool (HttpHeaders
);
1185 // Init message-body parser by header information.
1187 Status
= HttpInitMsgParser (
1188 HttpInstance
->Method
,
1189 HttpMsg
->Data
.Response
->StatusCode
,
1190 HttpMsg
->HeaderCount
,
1192 HttpBodyParserCallback
,
1193 (VOID
*) ValueInItem
,
1194 &HttpInstance
->MsgParser
1196 if (EFI_ERROR (Status
)) {
1201 // Check whether we received a complete HTTP message.
1203 if (HttpInstance
->CacheBody
!= NULL
) {
1204 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1205 if (EFI_ERROR (Status
)) {
1209 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1211 // Free the MsgParse since we already have a full HTTP message.
1213 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1214 HttpInstance
->MsgParser
= NULL
;
1219 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1220 Status
= EFI_SUCCESS
;
1226 // Receive the response body.
1231 // First check whether we cached some data.
1233 if (HttpInstance
->CacheBody
!= NULL
) {
1235 // Calculate the length of the cached data.
1237 if (HttpInstance
->NextMsg
!= NULL
) {
1239 // We have a cached HTTP message which includes a part of HTTP header of next message.
1241 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1243 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1248 // We have some cached data. Just copy the data and return.
1250 if (HttpMsg
->BodyLength
< BodyLen
) {
1251 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1252 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1255 // Copy all cached data out.
1257 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1258 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1259 HttpMsg
->BodyLength
= BodyLen
;
1261 if (HttpInstance
->NextMsg
== NULL
) {
1263 // There is no HTTP header of next message. Just free the cache buffer.
1265 FreePool (HttpInstance
->CacheBody
);
1266 HttpInstance
->CacheBody
= NULL
;
1267 HttpInstance
->NextMsg
= NULL
;
1268 HttpInstance
->CacheOffset
= 0;
1272 // Return since we aready received required data.
1274 Status
= EFI_SUCCESS
;
1278 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1280 // We received a complete HTTP message, and we don't have more data to return to caller.
1282 HttpMsg
->BodyLength
= 0;
1283 Status
= EFI_SUCCESS
;
1288 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1291 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1293 if (!HttpInstance
->UseHttps
) {
1294 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1296 if (EFI_ERROR (Status
)) {
1301 if (HttpInstance
->TimeoutEvent
== NULL
) {
1303 // Create TimeoutEvent for response
1305 Status
= gBS
->CreateEvent (
1310 &HttpInstance
->TimeoutEvent
1312 if (EFI_ERROR (Status
)) {
1318 // Start the timer, and wait Timeout seconds to receive the body packet.
1320 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1321 if (EFI_ERROR (Status
)) {
1325 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1327 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1329 if (EFI_ERROR (Status
)) {
1334 // Check whether we receive a complete HTTP message.
1336 Status
= HttpParseMessageBody (
1337 HttpInstance
->MsgParser
,
1338 (UINTN
) Fragment
.Len
,
1339 (CHAR8
*) Fragment
.Bulk
1341 if (EFI_ERROR (Status
)) {
1345 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1347 // Free the MsgParse since we already have a full HTTP message.
1349 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1350 HttpInstance
->MsgParser
= NULL
;
1354 // We receive part of header of next HTTP msg.
1356 if (HttpInstance
->NextMsg
!= NULL
) {
1357 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1358 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1360 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1361 if (HttpInstance
->CacheLen
!= 0) {
1362 if (HttpInstance
->CacheBody
!= NULL
) {
1363 FreePool (HttpInstance
->CacheBody
);
1366 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1367 if (HttpInstance
->CacheBody
== NULL
) {
1368 Status
= EFI_OUT_OF_RESOURCES
;
1372 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1373 HttpInstance
->CacheOffset
= 0;
1375 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1378 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1379 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1380 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1381 if (HttpInstance
->CacheLen
!= 0) {
1382 if (HttpInstance
->CacheBody
!= NULL
) {
1383 FreePool (HttpInstance
->CacheBody
);
1386 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1387 if (HttpInstance
->CacheBody
== NULL
) {
1388 Status
= EFI_OUT_OF_RESOURCES
;
1392 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1393 HttpInstance
->CacheOffset
= 0;
1397 if (Fragment
.Bulk
!= NULL
) {
1398 FreePool (Fragment
.Bulk
);
1399 Fragment
.Bulk
= NULL
;
1408 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1410 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1413 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1414 Token
->Status
= EFI_HTTP_ERROR
;
1416 Token
->Status
= Status
;
1419 gBS
->SignalEvent (Token
->Event
);
1420 HttpCloseTcpRxEvent (Wrap
);
1425 if (ValueInItem
!= NULL
) {
1426 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1430 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1432 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1435 if (!HttpInstance
->UseHttps
) {
1436 HttpTcpTokenCleanup (Wrap
);
1441 if (HttpHeaders
!= NULL
) {
1442 FreePool (HttpHeaders
);
1446 if (Fragment
.Bulk
!= NULL
) {
1447 FreePool (Fragment
.Bulk
);
1448 Fragment
.Bulk
= NULL
;
1451 if (HttpMsg
->Headers
!= NULL
) {
1452 FreePool (HttpMsg
->Headers
);
1453 HttpMsg
->Headers
= NULL
;
1456 if (HttpInstance
->CacheBody
!= NULL
) {
1457 FreePool (HttpInstance
->CacheBody
);
1458 HttpInstance
->CacheBody
= NULL
;
1461 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1462 Token
->Status
= EFI_HTTP_ERROR
;
1464 Token
->Status
= Status
;
1467 gBS
->SignalEvent (Token
->Event
);
1475 The Response() function queues an HTTP response to this HTTP instance, similar to
1476 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1477 or if there is an error, Status in token will be updated and Event will be signaled.
1479 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1480 is received in the underlying TCP instance, the data will be parsed and Token will
1481 be populated with the response data. If the data received from the remote host
1482 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1483 (asynchronously) for more data to be sent from the remote host before signaling
1486 It is the responsibility of the caller to allocate a buffer for Body and specify the
1487 size in BodyLength. If the remote host provides a response that contains a content
1488 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1489 BodyLength will be updated with the amount of bytes received and copied to Body. This
1490 allows the client to download a large file in chunks instead of into one contiguous
1491 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1492 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1493 token to underlying TCP instance. If data arrives in the receive buffer, up to
1494 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1495 BodyLength with the amount of bytes received and copied to Body.
1497 If the HTTP driver does not have an open underlying TCP connection with the host
1498 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1499 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1500 an open TCP connection between client and host.
1502 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1503 @param[in] Token Pointer to storage containing HTTP response token.
1505 @retval EFI_SUCCESS Allocation succeeded.
1506 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1508 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1511 Token->Message->Headers is NULL.
1512 Token->Message is NULL.
1513 Token->Message->Body is not NULL,
1514 Token->Message->BodyLength is non-zero, and
1515 Token->Message->Data is NULL, but a previous call to
1516 Response() has not been completed successfully.
1517 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1518 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1519 specified by response URL.
1524 IN EFI_HTTP_PROTOCOL
*This
,
1525 IN EFI_HTTP_TOKEN
*Token
1529 EFI_HTTP_MESSAGE
*HttpMsg
;
1530 HTTP_PROTOCOL
*HttpInstance
;
1531 HTTP_TOKEN_WRAP
*Wrap
;
1533 if ((This
== NULL
) || (Token
== NULL
)) {
1534 return EFI_INVALID_PARAMETER
;
1537 HttpMsg
= Token
->Message
;
1538 if (HttpMsg
== NULL
) {
1539 return EFI_INVALID_PARAMETER
;
1542 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1544 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1545 return EFI_NOT_STARTED
;
1549 // Check whether the token already existed.
1551 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1552 return EFI_ACCESS_DENIED
;
1555 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1557 return EFI_OUT_OF_RESOURCES
;
1560 Wrap
->HttpInstance
= HttpInstance
;
1561 Wrap
->HttpToken
= Token
;
1564 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1565 // receive the https response. A special TlsRxToken is used for receiving TLS
1566 // related messages. It should be a blocking response.
1568 if (!HttpInstance
->UseHttps
) {
1569 Status
= HttpCreateTcpRxEvent (Wrap
);
1570 if (EFI_ERROR (Status
)) {
1575 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1576 if (EFI_ERROR (Status
)) {
1581 // If already have pending RxTokens, return directly.
1583 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1587 return HttpResponseWorker (Wrap
);
1591 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1592 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1595 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1596 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1605 The Poll() function can be used by network drivers and applications to increase the
1606 rate that data packets are moved between the communication devices and the transmit
1609 In some systems, the periodic timer event in the managed network driver may not poll
1610 the underlying communications device fast enough to transmit and/or receive all data
1611 packets without missing incoming packets or dropping outgoing packets. Drivers and
1612 applications that are experiencing packet loss should try calling the Poll() function
1615 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1617 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1618 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1619 @retval EFI_INVALID_PARAMETER This is NULL.
1620 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1621 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1627 IN EFI_HTTP_PROTOCOL
*This
1631 HTTP_PROTOCOL
*HttpInstance
;
1634 return EFI_INVALID_PARAMETER
;
1637 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
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
);