2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
4 Copyright (c) 2015 - 2018, 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, DELETE, PATCH, PUT and POST method in current implementation.
286 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
287 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodDelete
) &&
288 (Request
->Method
!= HttpMethodPut
) && (Request
->Method
!= HttpMethodPost
) &&
289 (Request
->Method
!= HttpMethodPatch
)) {
290 return EFI_UNSUPPORTED
;
293 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
296 // Capture the method into HttpInstance.
298 if (Request
!= NULL
) {
299 HttpInstance
->Method
= Request
->Method
;
302 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
303 return EFI_NOT_STARTED
;
306 if (Request
== NULL
) {
308 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)
310 if ((HttpInstance
->Method
!= HttpMethodPut
) &&
311 (HttpInstance
->Method
!= HttpMethodPost
) &&
312 (HttpInstance
->Method
!= HttpMethodPatch
)) {
313 return EFI_INVALID_PARAMETER
;
317 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!
319 if (HttpInstance
->State
< HTTP_STATE_TCP_CONFIGED
) {
320 return EFI_INVALID_PARAMETER
;
324 // We need to have the Message Body for sending the HTTP message across in these cases.
326 if (HttpMsg
->Body
== NULL
|| HttpMsg
->BodyLength
== 0) {
327 return EFI_INVALID_PARAMETER
;
331 // Use existing TCP instance to transmit the packet.
337 // Check whether the token already existed.
339 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTokenExist
, Token
))) {
340 return EFI_ACCESS_DENIED
;
344 // Parse the URI of the remote host.
346 Url
= HttpInstance
->Url
;
347 UrlLen
= StrLen (Request
->Url
) + 1;
348 if (UrlLen
> HTTP_URL_BUFFER_LEN
) {
349 Url
= AllocateZeroPool (UrlLen
);
351 return EFI_OUT_OF_RESOURCES
;
353 FreePool (HttpInstance
->Url
);
354 HttpInstance
->Url
= Url
;
358 UnicodeStrToAsciiStrS (Request
->Url
, Url
, UrlLen
);
361 // From the information in Url, the HTTP instance will
362 // be able to determine whether to use http or https.
364 HttpInstance
->UseHttps
= IsHttpsUrl (Url
);
367 // HTTP is disabled, return directly if the URI is not HTTPS.
369 if (!PcdGetBool (PcdAllowHttpConnections
) && !(HttpInstance
->UseHttps
)) {
371 DEBUG ((EFI_D_ERROR
, "EfiHttpRequest: HTTP is disabled.\n"));
373 return EFI_ACCESS_DENIED
;
377 // Check whether we need to create Tls child and open the TLS protocol.
379 if (HttpInstance
->UseHttps
&& HttpInstance
->TlsChildHandle
== NULL
) {
381 // Use TlsSb to create Tls child and open the TLS protocol.
383 if (HttpInstance
->LocalAddressIsIPv6
) {
384 ImageHandle
= HttpInstance
->Service
->Ip6DriverBindingHandle
;
386 ImageHandle
= HttpInstance
->Service
->Ip4DriverBindingHandle
;
389 HttpInstance
->TlsChildHandle
= TlsCreateChild (
391 &(HttpInstance
->TlsSb
),
392 &(HttpInstance
->Tls
),
393 &(HttpInstance
->TlsConfiguration
)
395 if (HttpInstance
->TlsChildHandle
== NULL
) {
396 return EFI_DEVICE_ERROR
;
403 Status
= HttpParseUrl (Url
, (UINT32
) AsciiStrLen (Url
), FALSE
, &UrlParser
);
404 if (EFI_ERROR (Status
)) {
409 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
410 if (EFI_ERROR (Status
)) {
414 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
415 if (EFI_ERROR (Status
)) {
416 if (HttpInstance
->UseHttps
) {
417 RemotePort
= HTTPS_DEFAULT_PORT
;
419 RemotePort
= HTTP_DEFAULT_PORT
;
423 // If Configure is TRUE, it indicates the first time to call Request();
424 // If ReConfigure is TRUE, it indicates the request URL is not same
425 // with the previous call to Request();
430 if (HttpInstance
->RemoteHost
== NULL
) {
432 // Request() is called the first time.
436 if ((HttpInstance
->RemotePort
== RemotePort
) &&
437 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
438 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
440 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
442 // Host Name and port number of the request URL are the same with previous call to Request().
443 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
444 // Check whether previous TCP packet sent out.
447 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
449 // Wrap the HTTP token in HTTP_TOKEN_WRAP
451 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
453 Status
= EFI_OUT_OF_RESOURCES
;
457 Wrap
->HttpToken
= Token
;
458 Wrap
->HttpInstance
= HttpInstance
;
460 Status
= HttpCreateTcpTxEvent (Wrap
);
461 if (EFI_ERROR (Status
)) {
465 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
466 if (EFI_ERROR (Status
)) {
470 Wrap
->TcpWrap
.Method
= Request
->Method
;
474 HttpUrlFreeParser (UrlParser
);
477 // Queue the HTTP token and return.
482 // Use existing TCP instance to transmit the packet.
489 // Need close existing TCP instance and create a new TCP instance for data transmit.
491 if (HttpInstance
->RemoteHost
!= NULL
) {
492 FreePool (HttpInstance
->RemoteHost
);
493 HttpInstance
->RemoteHost
= NULL
;
494 HttpInstance
->RemotePort
= 0;
502 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
504 if (!HttpInstance
->LocalAddressIsIPv6
) {
505 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
507 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
510 if (EFI_ERROR (Status
)) {
511 HostNameSize
= AsciiStrSize (HostName
);
512 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
513 if (HostNameStr
== NULL
) {
514 Status
= EFI_OUT_OF_RESOURCES
;
518 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
519 if (!HttpInstance
->LocalAddressIsIPv6
) {
520 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
522 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
525 FreePool (HostNameStr
);
526 if (EFI_ERROR (Status
)) {
527 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
533 // Save the RemotePort and RemoteHost.
535 ASSERT (HttpInstance
->RemoteHost
== NULL
);
536 HttpInstance
->RemotePort
= RemotePort
;
537 HttpInstance
->RemoteHost
= HostName
;
543 // The request URL is different from previous calls to Request(), close existing TCP instance.
545 if (!HttpInstance
->LocalAddressIsIPv6
) {
546 ASSERT (HttpInstance
->Tcp4
!= NULL
);
548 ASSERT (HttpInstance
->Tcp6
!= NULL
);
551 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
552 Status
= TlsCloseSession (HttpInstance
);
553 if (EFI_ERROR (Status
)) {
557 TlsCloseTxRxEvent (HttpInstance
);
560 HttpCloseConnection (HttpInstance
);
561 EfiHttpCancel (This
, NULL
);
565 // Wrap the HTTP token in HTTP_TOKEN_WRAP
567 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
569 Status
= EFI_OUT_OF_RESOURCES
;
573 Wrap
->HttpToken
= Token
;
574 Wrap
->HttpInstance
= HttpInstance
;
575 if (Request
!= NULL
) {
576 Wrap
->TcpWrap
.Method
= Request
->Method
;
579 Status
= HttpInitSession (
582 Configure
|| ReConfigure
,
585 if (EFI_ERROR (Status
)) {
589 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
591 // For the new HTTP token, create TX TCP token events.
593 Status
= HttpCreateTcpTxEvent (Wrap
);
594 if (EFI_ERROR (Status
)) {
600 // Create request message.
603 if (Url
!= NULL
&& *FileUrl
!= '/') {
605 // Convert the absolute-URI to the absolute-path
607 while (*FileUrl
!= ':') {
610 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
612 while (*FileUrl
!= '/') {
616 Status
= EFI_INVALID_PARAMETER
;
621 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
623 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
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
) {
659 if (UrlParser
!= NULL
) {
660 HttpUrlFreeParser (UrlParser
);
667 // We would have inserted a TxToken only if Request structure is not NULL.
668 // Hence check before we do a remove in this error case.
670 if (Request
!= NULL
) {
671 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
675 if (RequestMsg
!= NULL
) {
676 FreePool (RequestMsg
);
680 if (HttpInstance
->UseHttps
) {
681 TlsCloseSession (HttpInstance
);
682 TlsCloseTxRxEvent (HttpInstance
);
686 HttpCloseConnection (HttpInstance
);
688 HttpCloseTcpConnCloseEvent (HttpInstance
);
689 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
690 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
691 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
693 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
694 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
695 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
699 if (HostName
!= NULL
) {
705 if (UrlParser
!= NULL
) {
706 HttpUrlFreeParser (UrlParser
);
714 Cancel a user's Token.
716 @param[in] Map The HTTP instance's token queue.
717 @param[in] Item Object container for one HTTP token and token's wrap.
718 @param[in] Context The user's token to cancel.
720 @retval EFI_SUCCESS Continue to check the next Item.
721 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
728 IN NET_MAP_ITEM
*Item
,
732 EFI_HTTP_TOKEN
*Token
;
733 HTTP_TOKEN_WRAP
*Wrap
;
734 HTTP_PROTOCOL
*HttpInstance
;
736 Token
= (EFI_HTTP_TOKEN
*) Context
;
739 // Return EFI_SUCCESS to check the next item in the map if
740 // this one doesn't match.
742 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
746 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
747 ASSERT (Wrap
!= NULL
);
748 HttpInstance
= Wrap
->HttpInstance
;
750 if (!HttpInstance
->LocalAddressIsIPv6
) {
751 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
753 // Cancle the Token before close its Event.
755 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
758 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
763 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
765 // Cancle the Token before close its Event.
767 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
770 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
777 // If only one item is to be cancel, return EFI_ABORTED to stop
778 // iterating the map any more.
788 Cancel the user's receive/transmit request. It is the worker function of
789 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
792 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
793 @param[in] Token The token to cancel. If NULL, all token will be
796 @retval EFI_SUCCESS The token is cancelled.
797 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
798 @retval Others Other error as indicated.
803 IN HTTP_PROTOCOL
*HttpInstance
,
804 IN EFI_HTTP_TOKEN
*Token
810 // First check the tokens queued by EfiHttpRequest().
812 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
813 if (EFI_ERROR (Status
)) {
815 if (Status
== EFI_ABORTED
) {
823 if (!HttpInstance
->UseHttps
) {
825 // Then check the tokens queued by EfiHttpResponse(), except for Https.
827 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
828 if (EFI_ERROR (Status
)) {
830 if (Status
== EFI_ABORTED
) {
833 return EFI_NOT_FOUND
;
840 if (!HttpInstance
->LocalAddressIsIPv6
) {
841 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
843 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
852 Abort an asynchronous HTTP request or response token.
854 The Cancel() function aborts a pending HTTP request or response transaction. If
855 Token is not NULL and the token is in transmit or receive queues when it is being
856 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
857 be signaled. If the token is not in one of the queues, which usually means that the
858 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
859 all asynchronous tokens issued by Request() or Response() will be aborted.
861 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
862 @param[in] Token Point to storage containing HTTP request or response
865 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
866 @retval EFI_INVALID_PARAMETER This is NULL.
867 @retval EFI_NOT_STARTED This instance hasn't been configured.
868 @retval EFI_NOT_FOUND The asynchronous request or response token is not
870 @retval EFI_UNSUPPORTED The implementation does not support this function.
876 IN EFI_HTTP_PROTOCOL
*This
,
877 IN EFI_HTTP_TOKEN
*Token
880 HTTP_PROTOCOL
*HttpInstance
;
883 return EFI_INVALID_PARAMETER
;
886 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
888 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
889 return EFI_NOT_STARTED
;
892 return HttpCancel (HttpInstance
, Token
);
897 A callback function to intercept events during message parser.
899 This function will be invoked during HttpParseMessageBody() with various events type. An error
900 return status of the callback function will cause the HttpParseMessageBody() aborted.
902 @param[in] EventType Event type of this callback call.
903 @param[in] Data A pointer to data buffer.
904 @param[in] Length Length in bytes of the Data.
905 @param[in] Context Callback context set by HttpInitMsgParser().
907 @retval EFI_SUCCESS Continue to parser the message body.
912 HttpBodyParserCallback (
913 IN HTTP_BODY_PARSE_EVENT EventType
,
919 HTTP_TOKEN_WRAP
*Wrap
;
923 if (EventType
!= BodyParseEventOnComplete
) {
927 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
931 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
932 Body
= Wrap
->HttpToken
->Message
->Body
;
933 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
934 if (Data
< Body
+ BodyLength
) {
935 Wrap
->HttpInstance
->NextMsg
= Data
;
937 Wrap
->HttpInstance
->NextMsg
= NULL
;
942 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
950 The work function of EfiHttpResponse().
952 @param[in] Wrap Pointer to HTTP token's wrap data.
954 @retval EFI_SUCCESS Allocation succeeded.
955 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
956 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
957 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
962 IN HTTP_TOKEN_WRAP
*Wrap
966 EFI_HTTP_MESSAGE
*HttpMsg
;
974 CHAR8
*StatusCodeStr
;
976 HTTP_PROTOCOL
*HttpInstance
;
977 EFI_HTTP_TOKEN
*Token
;
979 HTTP_TOKEN_WRAP
*ValueInItem
;
981 NET_FRAGMENT Fragment
;
983 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
984 return EFI_INVALID_PARAMETER
;
987 HttpInstance
= Wrap
->HttpInstance
;
988 Token
= Wrap
->HttpToken
;
989 HttpMsg
= Token
->Message
;
991 HttpInstance
->EndofHeader
= NULL
;
992 HttpInstance
->HttpHeaders
= NULL
;
993 HttpMsg
->Headers
= NULL
;
1000 Fragment
.Bulk
= NULL
;
1002 if (HttpMsg
->Data
.Response
!= NULL
) {
1004 // Check whether we have cached header from previous call.
1006 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1008 // The data is stored at [NextMsg, CacheBody + CacheLen].
1010 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1011 HttpHeaders
= AllocateZeroPool (HdrLen
);
1012 if (HttpHeaders
== NULL
) {
1013 Status
= EFI_OUT_OF_RESOURCES
;
1017 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1018 FreePool (HttpInstance
->CacheBody
);
1019 HttpInstance
->CacheBody
= NULL
;
1020 HttpInstance
->NextMsg
= NULL
;
1021 HttpInstance
->CacheOffset
= 0;
1022 SizeofHeaders
= HdrLen
;
1023 BufferSize
= HttpInstance
->CacheLen
;
1026 // Check whether we cached the whole HTTP headers.
1028 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1031 HttpInstance
->EndofHeader
= &EndofHeader
;
1032 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1035 if (HttpInstance
->TimeoutEvent
== NULL
) {
1037 // Create TimeoutEvent for response
1039 Status
= gBS
->CreateEvent (
1044 &HttpInstance
->TimeoutEvent
1046 if (EFI_ERROR (Status
)) {
1052 // Start the timer, and wait Timeout seconds to receive the header packet.
1054 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1055 if (EFI_ERROR (Status
)) {
1059 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1061 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1063 if (EFI_ERROR (Status
)) {
1067 ASSERT (HttpHeaders
!= NULL
);
1070 // Cache the part of body.
1072 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1074 if (HttpInstance
->CacheBody
!= NULL
) {
1075 FreePool (HttpInstance
->CacheBody
);
1078 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1079 if (HttpInstance
->CacheBody
== NULL
) {
1080 Status
= EFI_OUT_OF_RESOURCES
;
1084 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1085 HttpInstance
->CacheLen
= BodyLen
;
1089 // Search for Status Code.
1091 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1092 if (StatusCodeStr
== NULL
) {
1093 Status
= EFI_NOT_READY
;
1097 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1100 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1102 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1104 Status
= EFI_NOT_READY
;
1109 // We could have response with just a HTTP message and no headers. For Example,
1110 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1111 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1112 // set SizeofHeaders to 0.
1114 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1115 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1118 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1121 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1122 HttpInstance
->StatusCode
= StatusCode
;
1124 Status
= EFI_NOT_READY
;
1128 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1129 // continuous request without a response call. So, we would not do an insert of
1130 // TxToken. After we have sent the complete file, we will call a response to get
1131 // a final response from server. In such a case, we would not have any TxTokens.
1132 // Hence, check that case before doing a NetMapRemoveHead.
1134 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1135 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1136 if (ValueInItem
== NULL
) {
1141 // The first Tx Token not transmitted yet, insert back and return error.
1143 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1148 if (SizeofHeaders
!= 0) {
1149 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1150 if (HeaderTmp
== NULL
) {
1151 Status
= EFI_OUT_OF_RESOURCES
;
1155 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1156 FreePool (HttpHeaders
);
1157 HttpHeaders
= HeaderTmp
;
1160 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1162 if (mHttpUtilities
== NULL
) {
1163 Status
= EFI_NOT_READY
;
1168 // Parse the HTTP header into array of key/value pairs.
1170 Status
= mHttpUtilities
->Parse (
1175 &HttpMsg
->HeaderCount
1177 if (EFI_ERROR (Status
)) {
1181 FreePool (HttpHeaders
);
1186 // Init message-body parser by header information.
1188 Status
= HttpInitMsgParser (
1189 HttpInstance
->Method
,
1190 HttpMsg
->Data
.Response
->StatusCode
,
1191 HttpMsg
->HeaderCount
,
1193 HttpBodyParserCallback
,
1194 (VOID
*) ValueInItem
,
1195 &HttpInstance
->MsgParser
1197 if (EFI_ERROR (Status
)) {
1202 // Check whether we received a complete HTTP message.
1204 if (HttpInstance
->CacheBody
!= NULL
) {
1205 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1206 if (EFI_ERROR (Status
)) {
1210 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1212 // Free the MsgParse since we already have a full HTTP message.
1214 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1215 HttpInstance
->MsgParser
= NULL
;
1220 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1221 Status
= EFI_SUCCESS
;
1227 // Receive the response body.
1232 // First check whether we cached some data.
1234 if (HttpInstance
->CacheBody
!= NULL
) {
1236 // Calculate the length of the cached data.
1238 if (HttpInstance
->NextMsg
!= NULL
) {
1240 // We have a cached HTTP message which includes a part of HTTP header of next message.
1242 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1244 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1249 // We have some cached data. Just copy the data and return.
1251 if (HttpMsg
->BodyLength
< BodyLen
) {
1252 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1253 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1256 // Copy all cached data out.
1258 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1259 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1260 HttpMsg
->BodyLength
= BodyLen
;
1262 if (HttpInstance
->NextMsg
== NULL
) {
1264 // There is no HTTP header of next message. Just free the cache buffer.
1266 FreePool (HttpInstance
->CacheBody
);
1267 HttpInstance
->CacheBody
= NULL
;
1268 HttpInstance
->NextMsg
= NULL
;
1269 HttpInstance
->CacheOffset
= 0;
1273 // Return since we aready received required data.
1275 Status
= EFI_SUCCESS
;
1279 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1281 // We received a complete HTTP message, and we don't have more data to return to caller.
1283 HttpMsg
->BodyLength
= 0;
1284 Status
= EFI_SUCCESS
;
1289 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1292 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1294 if (!HttpInstance
->UseHttps
) {
1295 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1297 if (EFI_ERROR (Status
)) {
1302 if (HttpInstance
->TimeoutEvent
== NULL
) {
1304 // Create TimeoutEvent for response
1306 Status
= gBS
->CreateEvent (
1311 &HttpInstance
->TimeoutEvent
1313 if (EFI_ERROR (Status
)) {
1319 // Start the timer, and wait Timeout seconds to receive the body packet.
1321 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1322 if (EFI_ERROR (Status
)) {
1326 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1328 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1330 if (EFI_ERROR (Status
)) {
1335 // Check whether we receive a complete HTTP message.
1337 Status
= HttpParseMessageBody (
1338 HttpInstance
->MsgParser
,
1339 (UINTN
) Fragment
.Len
,
1340 (CHAR8
*) Fragment
.Bulk
1342 if (EFI_ERROR (Status
)) {
1346 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1348 // Free the MsgParse since we already have a full HTTP message.
1350 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1351 HttpInstance
->MsgParser
= NULL
;
1355 // We receive part of header of next HTTP msg.
1357 if (HttpInstance
->NextMsg
!= NULL
) {
1358 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1359 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1361 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1362 if (HttpInstance
->CacheLen
!= 0) {
1363 if (HttpInstance
->CacheBody
!= NULL
) {
1364 FreePool (HttpInstance
->CacheBody
);
1367 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1368 if (HttpInstance
->CacheBody
== NULL
) {
1369 Status
= EFI_OUT_OF_RESOURCES
;
1373 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1374 HttpInstance
->CacheOffset
= 0;
1376 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1379 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1380 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1381 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1382 if (HttpInstance
->CacheLen
!= 0) {
1383 if (HttpInstance
->CacheBody
!= NULL
) {
1384 FreePool (HttpInstance
->CacheBody
);
1387 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1388 if (HttpInstance
->CacheBody
== NULL
) {
1389 Status
= EFI_OUT_OF_RESOURCES
;
1393 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1394 HttpInstance
->CacheOffset
= 0;
1398 if (Fragment
.Bulk
!= NULL
) {
1399 FreePool (Fragment
.Bulk
);
1400 Fragment
.Bulk
= NULL
;
1409 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1411 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1414 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1415 Token
->Status
= EFI_HTTP_ERROR
;
1417 Token
->Status
= Status
;
1420 gBS
->SignalEvent (Token
->Event
);
1421 HttpCloseTcpRxEvent (Wrap
);
1426 if (ValueInItem
!= NULL
) {
1427 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1431 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1433 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1436 if (!HttpInstance
->UseHttps
) {
1437 HttpTcpTokenCleanup (Wrap
);
1442 if (HttpHeaders
!= NULL
) {
1443 FreePool (HttpHeaders
);
1447 if (Fragment
.Bulk
!= NULL
) {
1448 FreePool (Fragment
.Bulk
);
1449 Fragment
.Bulk
= NULL
;
1452 if (HttpMsg
->Headers
!= NULL
) {
1453 FreePool (HttpMsg
->Headers
);
1454 HttpMsg
->Headers
= NULL
;
1457 if (HttpInstance
->CacheBody
!= NULL
) {
1458 FreePool (HttpInstance
->CacheBody
);
1459 HttpInstance
->CacheBody
= NULL
;
1462 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1463 Token
->Status
= EFI_HTTP_ERROR
;
1465 Token
->Status
= Status
;
1468 gBS
->SignalEvent (Token
->Event
);
1476 The Response() function queues an HTTP response to this HTTP instance, similar to
1477 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1478 or if there is an error, Status in token will be updated and Event will be signaled.
1480 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1481 is received in the underlying TCP instance, the data will be parsed and Token will
1482 be populated with the response data. If the data received from the remote host
1483 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1484 (asynchronously) for more data to be sent from the remote host before signaling
1487 It is the responsibility of the caller to allocate a buffer for Body and specify the
1488 size in BodyLength. If the remote host provides a response that contains a content
1489 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1490 BodyLength will be updated with the amount of bytes received and copied to Body. This
1491 allows the client to download a large file in chunks instead of into one contiguous
1492 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1493 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1494 token to underlying TCP instance. If data arrives in the receive buffer, up to
1495 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1496 BodyLength with the amount of bytes received and copied to Body.
1498 If the HTTP driver does not have an open underlying TCP connection with the host
1499 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1500 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1501 an open TCP connection between client and host.
1503 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1504 @param[in] Token Pointer to storage containing HTTP response token.
1506 @retval EFI_SUCCESS Allocation succeeded.
1507 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1509 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1512 Token->Message->Headers is NULL.
1513 Token->Message is NULL.
1514 Token->Message->Body is not NULL,
1515 Token->Message->BodyLength is non-zero, and
1516 Token->Message->Data is NULL, but a previous call to
1517 Response() has not been completed successfully.
1518 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1519 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1520 specified by response URL.
1525 IN EFI_HTTP_PROTOCOL
*This
,
1526 IN EFI_HTTP_TOKEN
*Token
1530 EFI_HTTP_MESSAGE
*HttpMsg
;
1531 HTTP_PROTOCOL
*HttpInstance
;
1532 HTTP_TOKEN_WRAP
*Wrap
;
1534 if ((This
== NULL
) || (Token
== NULL
)) {
1535 return EFI_INVALID_PARAMETER
;
1538 HttpMsg
= Token
->Message
;
1539 if (HttpMsg
== NULL
) {
1540 return EFI_INVALID_PARAMETER
;
1543 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1545 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1546 return EFI_NOT_STARTED
;
1550 // Check whether the token already existed.
1552 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1553 return EFI_ACCESS_DENIED
;
1556 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1558 return EFI_OUT_OF_RESOURCES
;
1561 Wrap
->HttpInstance
= HttpInstance
;
1562 Wrap
->HttpToken
= Token
;
1565 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1566 // receive the https response. A special TlsRxToken is used for receiving TLS
1567 // related messages. It should be a blocking response.
1569 if (!HttpInstance
->UseHttps
) {
1570 Status
= HttpCreateTcpRxEvent (Wrap
);
1571 if (EFI_ERROR (Status
)) {
1576 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1577 if (EFI_ERROR (Status
)) {
1582 // If already have pending RxTokens, return directly.
1584 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1588 return HttpResponseWorker (Wrap
);
1592 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1593 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1596 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1597 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1606 The Poll() function can be used by network drivers and applications to increase the
1607 rate that data packets are moved between the communication devices and the transmit
1610 In some systems, the periodic timer event in the managed network driver may not poll
1611 the underlying communications device fast enough to transmit and/or receive all data
1612 packets without missing incoming packets or dropping outgoing packets. Drivers and
1613 applications that are experiencing packet loss should try calling the Poll() function
1616 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1618 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1619 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1620 @retval EFI_INVALID_PARAMETER This is NULL.
1621 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1622 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1628 IN EFI_HTTP_PROTOCOL
*This
1632 HTTP_PROTOCOL
*HttpInstance
;
1635 return EFI_INVALID_PARAMETER
;
1638 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1640 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1641 return EFI_NOT_STARTED
;
1644 if (HttpInstance
->LocalAddressIsIPv6
) {
1645 if (HttpInstance
->Tcp6
== NULL
) {
1646 return EFI_NOT_STARTED
;
1648 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1650 if (HttpInstance
->Tcp4
== NULL
) {
1651 return EFI_NOT_STARTED
;
1653 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);