2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
4 Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "HttpDriver.h"
13 EFI_HTTP_PROTOCOL mEfiHttpTemplate
= {
23 Returns the operational parameters for the current HTTP child instance.
25 The GetModeData() function is used to read the current mode data (operational
26 parameters) for this HTTP protocol instance.
28 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
29 @param[out] HttpConfigData Point to buffer for operational parameters of this
30 HTTP instance. It is the responsibility of the caller
31 to allocate the memory for HttpConfigData and
32 HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,
33 it is recommended to allocate sufficient memory to record
34 IPv6Node since it is big enough for all possibilities.
36 @retval EFI_SUCCESS Operation succeeded.
37 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
39 HttpConfigData is NULL.
40 HttpConfigData->AccessPoint.IPv4Node or
41 HttpConfigData->AccessPoint.IPv6Node is NULL.
42 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
48 IN EFI_HTTP_PROTOCOL
*This
,
49 OUT EFI_HTTP_CONFIG_DATA
*HttpConfigData
52 HTTP_PROTOCOL
*HttpInstance
;
55 // Check input parameters.
57 if ((This
== NULL
) || (HttpConfigData
== NULL
)) {
58 return EFI_INVALID_PARAMETER
;
61 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
63 if ((HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
64 (HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)) {
65 return EFI_INVALID_PARAMETER
;
68 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
69 return EFI_NOT_STARTED
;
72 HttpConfigData
->HttpVersion
= HttpInstance
->HttpVersion
;
73 HttpConfigData
->TimeOutMillisec
= HttpInstance
->TimeOutMillisec
;
74 HttpConfigData
->LocalAddressIsIPv6
= HttpInstance
->LocalAddressIsIPv6
;
76 if (HttpInstance
->LocalAddressIsIPv6
) {
78 HttpConfigData
->AccessPoint
.IPv6Node
,
79 &HttpInstance
->Ipv6Node
,
80 sizeof (HttpInstance
->Ipv6Node
)
84 HttpConfigData
->AccessPoint
.IPv4Node
,
85 &HttpInstance
->IPv4Node
,
86 sizeof (HttpInstance
->IPv4Node
)
94 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
96 The Configure() function does the following:
97 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
98 timeout, local address, port, etc.
99 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
100 connections with remote hosts, canceling all asynchronous tokens, and flush request
101 and response buffers without informing the appropriate hosts.
103 No other EFI HTTP function can be executed by this instance until the Configure()
104 function is executed and returns successfully.
106 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
107 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
109 @retval EFI_SUCCESS Operation succeeded.
110 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
112 HttpConfigData->LocalAddressIsIPv6 is FALSE and
113 HttpConfigData->AccessPoint.IPv4Node is NULL.
114 HttpConfigData->LocalAddressIsIPv6 is TRUE and
115 HttpConfigData->AccessPoint.IPv6Node is NULL.
116 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
117 Configure() with NULL to reset it.
118 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
119 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
120 executing Configure().
121 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
122 in the implementation.
127 IN EFI_HTTP_PROTOCOL
*This
,
128 IN EFI_HTTP_CONFIG_DATA
*HttpConfigData OPTIONAL
131 HTTP_PROTOCOL
*HttpInstance
;
135 // Check input parameters.
138 (HttpConfigData
!= NULL
&&
139 ((HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
140 (!HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)))) {
141 return EFI_INVALID_PARAMETER
;
144 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
145 ASSERT (HttpInstance
->Service
!= NULL
);
147 if (HttpConfigData
!= NULL
) {
149 if (HttpConfigData
->HttpVersion
>= HttpVersionUnsupported
) {
150 return EFI_UNSUPPORTED
;
154 // Now configure this HTTP instance.
156 if (HttpInstance
->State
!= HTTP_STATE_UNCONFIGED
) {
157 return EFI_ALREADY_STARTED
;
160 HttpInstance
->HttpVersion
= HttpConfigData
->HttpVersion
;
161 HttpInstance
->TimeOutMillisec
= HttpConfigData
->TimeOutMillisec
;
162 HttpInstance
->LocalAddressIsIPv6
= HttpConfigData
->LocalAddressIsIPv6
;
164 if (HttpConfigData
->LocalAddressIsIPv6
) {
166 &HttpInstance
->Ipv6Node
,
167 HttpConfigData
->AccessPoint
.IPv6Node
,
168 sizeof (HttpInstance
->Ipv6Node
)
172 &HttpInstance
->IPv4Node
,
173 HttpConfigData
->AccessPoint
.IPv4Node
,
174 sizeof (HttpInstance
->IPv4Node
)
181 Status
= HttpInitProtocol (HttpInstance
, HttpInstance
->LocalAddressIsIPv6
);
182 if (EFI_ERROR (Status
)) {
186 HttpInstance
->State
= HTTP_STATE_HTTP_CONFIGED
;
191 // Reset all the resources related to HttpInstance.
193 HttpCleanProtocol (HttpInstance
);
194 HttpInstance
->State
= HTTP_STATE_UNCONFIGED
;
201 The Request() function queues an HTTP request to this HTTP instance.
203 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
204 successfully, or if there is an error, Status in token will be updated and Event will
207 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
208 @param[in] Token Pointer to storage containing HTTP request token.
210 @retval EFI_SUCCESS Outgoing data was processed.
211 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
212 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
213 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
214 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
215 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
217 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
220 Token->Message is NULL.
221 Token->Message->Body is not NULL,
222 Token->Message->BodyLength is non-zero, and
223 Token->Message->Data is NULL, but a previous call to
224 Request()has not been completed successfully.
229 IN EFI_HTTP_PROTOCOL
*This
,
230 IN EFI_HTTP_TOKEN
*Token
233 EFI_HTTP_MESSAGE
*HttpMsg
;
234 EFI_HTTP_REQUEST_DATA
*Request
;
240 HTTP_PROTOCOL
*HttpInstance
;
243 BOOLEAN TlsConfigure
;
248 HTTP_TOKEN_WRAP
*Wrap
;
250 UINTN RequestMsgSize
;
251 EFI_HANDLE ImageHandle
;
264 TlsConfigure
= FALSE
;
266 if ((This
== NULL
) || (Token
== NULL
)) {
267 return EFI_INVALID_PARAMETER
;
270 HttpMsg
= Token
->Message
;
271 if (HttpMsg
== NULL
) {
272 return EFI_INVALID_PARAMETER
;
275 Request
= HttpMsg
->Data
.Request
;
278 // Only support GET, HEAD, DELETE, PATCH, PUT and POST method in current implementation.
280 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
281 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodDelete
) &&
282 (Request
->Method
!= HttpMethodPut
) && (Request
->Method
!= HttpMethodPost
) &&
283 (Request
->Method
!= HttpMethodPatch
)) {
284 return EFI_UNSUPPORTED
;
287 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
290 // Capture the method into HttpInstance.
292 if (Request
!= NULL
) {
293 HttpInstance
->Method
= Request
->Method
;
296 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
297 return EFI_NOT_STARTED
;
300 if (Request
== NULL
) {
302 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)
304 if ((HttpInstance
->Method
!= HttpMethodPut
) &&
305 (HttpInstance
->Method
!= HttpMethodPost
) &&
306 (HttpInstance
->Method
!= HttpMethodPatch
)) {
307 return EFI_INVALID_PARAMETER
;
311 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!
313 if (HttpInstance
->State
< HTTP_STATE_TCP_CONFIGED
) {
314 return EFI_INVALID_PARAMETER
;
318 // We need to have the Message Body for sending the HTTP message across in these cases.
320 if (HttpMsg
->Body
== NULL
|| HttpMsg
->BodyLength
== 0) {
321 return EFI_INVALID_PARAMETER
;
325 // Use existing TCP instance to transmit the packet.
331 // Check whether the token already existed.
333 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTokenExist
, Token
))) {
334 return EFI_ACCESS_DENIED
;
338 // Parse the URI of the remote host.
340 Url
= HttpInstance
->Url
;
341 UrlLen
= StrLen (Request
->Url
) + 1;
342 if (UrlLen
> HTTP_URL_BUFFER_LEN
) {
343 Url
= AllocateZeroPool (UrlLen
);
345 return EFI_OUT_OF_RESOURCES
;
347 FreePool (HttpInstance
->Url
);
348 HttpInstance
->Url
= Url
;
352 UnicodeStrToAsciiStrS (Request
->Url
, Url
, UrlLen
);
355 // From the information in Url, the HTTP instance will
356 // be able to determine whether to use http or https.
358 HttpInstance
->UseHttps
= IsHttpsUrl (Url
);
361 // HTTP is disabled, return directly if the URI is not HTTPS.
363 if (!PcdGetBool (PcdAllowHttpConnections
) && !(HttpInstance
->UseHttps
)) {
365 DEBUG ((EFI_D_ERROR
, "EfiHttpRequest: HTTP is disabled.\n"));
367 return EFI_ACCESS_DENIED
;
371 // Check whether we need to create Tls child and open the TLS protocol.
373 if (HttpInstance
->UseHttps
&& HttpInstance
->TlsChildHandle
== NULL
) {
375 // Use TlsSb to create Tls child and open the TLS protocol.
377 if (HttpInstance
->LocalAddressIsIPv6
) {
378 ImageHandle
= HttpInstance
->Service
->Ip6DriverBindingHandle
;
380 ImageHandle
= HttpInstance
->Service
->Ip4DriverBindingHandle
;
383 HttpInstance
->TlsChildHandle
= TlsCreateChild (
385 &(HttpInstance
->TlsSb
),
386 &(HttpInstance
->Tls
),
387 &(HttpInstance
->TlsConfiguration
)
389 if (HttpInstance
->TlsChildHandle
== NULL
) {
390 return EFI_DEVICE_ERROR
;
397 Status
= HttpParseUrl (Url
, (UINT32
) AsciiStrLen (Url
), FALSE
, &UrlParser
);
398 if (EFI_ERROR (Status
)) {
402 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
403 if (EFI_ERROR (Status
)) {
407 if (HttpInstance
->LocalAddressIsIPv6
) {
408 HostNameSize
= AsciiStrSize (HostName
);
410 if (HostNameSize
> 2 && HostName
[0] == '[' && HostName
[HostNameSize
- 2] == ']') {
412 // HostName format is expressed as IPv6, so, remove '[' and ']'.
415 CopyMem (HostName
, HostName
+ 1, HostNameSize
- 1);
416 HostName
[HostNameSize
- 1] = '\0';
420 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
421 if (EFI_ERROR (Status
)) {
422 if (HttpInstance
->UseHttps
) {
423 RemotePort
= HTTPS_DEFAULT_PORT
;
425 RemotePort
= HTTP_DEFAULT_PORT
;
429 // If Configure is TRUE, it indicates the first time to call Request();
430 // If ReConfigure is TRUE, it indicates the request URL is not same
431 // with the previous call to Request();
436 if (HttpInstance
->RemoteHost
== NULL
) {
438 // Request() is called the first time.
442 if ((HttpInstance
->RemotePort
== RemotePort
) &&
443 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
444 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
446 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
448 // Host Name and port number of the request URL are the same with previous call to Request().
449 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
450 // Check whether previous TCP packet sent out.
453 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
455 // Wrap the HTTP token in HTTP_TOKEN_WRAP
457 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
459 Status
= EFI_OUT_OF_RESOURCES
;
463 Wrap
->HttpToken
= Token
;
464 Wrap
->HttpInstance
= HttpInstance
;
466 Status
= HttpCreateTcpTxEvent (Wrap
);
467 if (EFI_ERROR (Status
)) {
471 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
472 if (EFI_ERROR (Status
)) {
476 Wrap
->TcpWrap
.Method
= Request
->Method
;
480 HttpUrlFreeParser (UrlParser
);
483 // Queue the HTTP token and return.
488 // Use existing TCP instance to transmit the packet.
495 // Need close existing TCP instance and create a new TCP instance for data transmit.
497 if (HttpInstance
->RemoteHost
!= NULL
) {
498 FreePool (HttpInstance
->RemoteHost
);
499 HttpInstance
->RemoteHost
= NULL
;
500 HttpInstance
->RemotePort
= 0;
508 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
510 if (!HttpInstance
->LocalAddressIsIPv6
) {
511 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
513 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
516 if (EFI_ERROR (Status
)) {
517 HostNameSize
= AsciiStrSize (HostName
);
518 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
519 if (HostNameStr
== NULL
) {
520 Status
= EFI_OUT_OF_RESOURCES
;
524 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
525 if (!HttpInstance
->LocalAddressIsIPv6
) {
526 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
528 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
531 FreePool (HostNameStr
);
532 if (EFI_ERROR (Status
)) {
533 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
539 // Save the RemotePort and RemoteHost.
541 ASSERT (HttpInstance
->RemoteHost
== NULL
);
542 HttpInstance
->RemotePort
= RemotePort
;
543 HttpInstance
->RemoteHost
= HostName
;
549 // The request URL is different from previous calls to Request(), close existing TCP instance.
551 if (!HttpInstance
->LocalAddressIsIPv6
) {
552 ASSERT (HttpInstance
->Tcp4
!= NULL
);
554 ASSERT (HttpInstance
->Tcp6
!= NULL
);
557 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
558 Status
= TlsCloseSession (HttpInstance
);
559 if (EFI_ERROR (Status
)) {
563 TlsCloseTxRxEvent (HttpInstance
);
566 HttpCloseConnection (HttpInstance
);
567 EfiHttpCancel (This
, NULL
);
571 // Wrap the HTTP token in HTTP_TOKEN_WRAP
573 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
575 Status
= EFI_OUT_OF_RESOURCES
;
579 Wrap
->HttpToken
= Token
;
580 Wrap
->HttpInstance
= HttpInstance
;
581 if (Request
!= NULL
) {
582 Wrap
->TcpWrap
.Method
= Request
->Method
;
585 Status
= HttpInitSession (
588 Configure
|| ReConfigure
,
591 if (EFI_ERROR (Status
)) {
595 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
597 // For the new HTTP token, create TX TCP token events.
599 Status
= HttpCreateTcpTxEvent (Wrap
);
600 if (EFI_ERROR (Status
)) {
606 // Create request message.
609 if (Url
!= NULL
&& *FileUrl
!= '/') {
611 // Convert the absolute-URI to the absolute-path
613 while (*FileUrl
!= ':') {
616 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
618 while (*FileUrl
!= '/') {
622 Status
= EFI_INVALID_PARAMETER
;
627 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
629 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
634 // Every request we insert a TxToken and a response call would remove the TxToken.
635 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
636 // continuous request without a response call. So, in such cases, where Request
637 // structure is NULL, we would not insert a TxToken.
639 if (Request
!= NULL
) {
640 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
641 if (EFI_ERROR (Status
)) {
647 // Transmit the request message.
649 Status
= HttpTransmitTcp (
655 if (EFI_ERROR (Status
)) {
661 if (HostName
!= NULL
) {
665 if (UrlParser
!= NULL
) {
666 HttpUrlFreeParser (UrlParser
);
673 // We would have inserted a TxToken only if Request structure is not NULL.
674 // Hence check before we do a remove in this error case.
676 if (Request
!= NULL
) {
677 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
681 if (RequestMsg
!= NULL
) {
682 FreePool (RequestMsg
);
686 if (HttpInstance
->UseHttps
) {
687 TlsCloseSession (HttpInstance
);
688 TlsCloseTxRxEvent (HttpInstance
);
692 HttpCloseConnection (HttpInstance
);
694 HttpCloseTcpConnCloseEvent (HttpInstance
);
695 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
696 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
697 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
699 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
700 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
701 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
705 if (HostName
!= NULL
) {
711 if (UrlParser
!= NULL
) {
712 HttpUrlFreeParser (UrlParser
);
720 Cancel a user's Token.
722 @param[in] Map The HTTP instance's token queue.
723 @param[in] Item Object container for one HTTP token and token's wrap.
724 @param[in] Context The user's token to cancel.
726 @retval EFI_SUCCESS Continue to check the next Item.
727 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
734 IN NET_MAP_ITEM
*Item
,
738 EFI_HTTP_TOKEN
*Token
;
739 HTTP_TOKEN_WRAP
*Wrap
;
740 HTTP_PROTOCOL
*HttpInstance
;
742 Token
= (EFI_HTTP_TOKEN
*) Context
;
745 // Return EFI_SUCCESS to check the next item in the map if
746 // this one doesn't match.
748 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
752 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
753 ASSERT (Wrap
!= NULL
);
754 HttpInstance
= Wrap
->HttpInstance
;
756 if (!HttpInstance
->LocalAddressIsIPv6
) {
757 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
759 // Cancel the Token before close its Event.
761 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
764 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
769 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
771 // Cancel the Token before close its Event.
773 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
776 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
783 // If only one item is to be cancel, return EFI_ABORTED to stop
784 // iterating the map any more.
794 Cancel the user's receive/transmit request. It is the worker function of
795 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
798 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
799 @param[in] Token The token to cancel. If NULL, all token will be
802 @retval EFI_SUCCESS The token is cancelled.
803 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
804 @retval Others Other error as indicated.
809 IN HTTP_PROTOCOL
*HttpInstance
,
810 IN EFI_HTTP_TOKEN
*Token
816 // First check the tokens queued by EfiHttpRequest().
818 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
819 if (EFI_ERROR (Status
)) {
821 if (Status
== EFI_ABORTED
) {
829 if (!HttpInstance
->UseHttps
) {
831 // Then check the tokens queued by EfiHttpResponse(), except for Https.
833 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
834 if (EFI_ERROR (Status
)) {
836 if (Status
== EFI_ABORTED
) {
839 return EFI_NOT_FOUND
;
846 if (!HttpInstance
->LocalAddressIsIPv6
) {
847 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
849 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
858 Abort an asynchronous HTTP request or response token.
860 The Cancel() function aborts a pending HTTP request or response transaction. If
861 Token is not NULL and the token is in transmit or receive queues when it is being
862 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
863 be signaled. If the token is not in one of the queues, which usually means that the
864 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
865 all asynchronous tokens issued by Request() or Response() will be aborted.
867 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
868 @param[in] Token Point to storage containing HTTP request or response
871 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
872 @retval EFI_INVALID_PARAMETER This is NULL.
873 @retval EFI_NOT_STARTED This instance hasn't been configured.
874 @retval EFI_NOT_FOUND The asynchronous request or response token is not
876 @retval EFI_UNSUPPORTED The implementation does not support this function.
882 IN EFI_HTTP_PROTOCOL
*This
,
883 IN EFI_HTTP_TOKEN
*Token
886 HTTP_PROTOCOL
*HttpInstance
;
889 return EFI_INVALID_PARAMETER
;
892 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
894 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
895 return EFI_NOT_STARTED
;
898 return HttpCancel (HttpInstance
, Token
);
903 A callback function to intercept events during message parser.
905 This function will be invoked during HttpParseMessageBody() with various events type. An error
906 return status of the callback function will cause the HttpParseMessageBody() aborted.
908 @param[in] EventType Event type of this callback call.
909 @param[in] Data A pointer to data buffer.
910 @param[in] Length Length in bytes of the Data.
911 @param[in] Context Callback context set by HttpInitMsgParser().
913 @retval EFI_SUCCESS Continue to parser the message body.
918 HttpBodyParserCallback (
919 IN HTTP_BODY_PARSE_EVENT EventType
,
925 HTTP_CALLBACK_DATA
*CallbackData
;
926 HTTP_TOKEN_WRAP
*Wrap
;
930 if (EventType
!= BodyParseEventOnComplete
) {
934 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
938 CallbackData
= (HTTP_CALLBACK_DATA
*) Context
;
940 Wrap
= (HTTP_TOKEN_WRAP
*) (CallbackData
->Wrap
);
941 Body
= CallbackData
->ParseData
;
942 BodyLength
= CallbackData
->ParseDataLength
;
944 if (Data
< Body
+ BodyLength
) {
945 Wrap
->HttpInstance
->NextMsg
= Data
;
947 Wrap
->HttpInstance
->NextMsg
= NULL
;
954 The work function of EfiHttpResponse().
956 @param[in] Wrap Pointer to HTTP token's wrap data.
958 @retval EFI_SUCCESS Allocation succeeded.
959 @retval EFI_OUT_OF_RESOURCES Failed to complete the operation due to lack of resources.
960 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
961 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
966 IN HTTP_TOKEN_WRAP
*Wrap
970 EFI_HTTP_MESSAGE
*HttpMsg
;
978 CHAR8
*StatusCodeStr
;
980 HTTP_PROTOCOL
*HttpInstance
;
981 EFI_HTTP_TOKEN
*Token
;
983 HTTP_TOKEN_WRAP
*ValueInItem
;
985 NET_FRAGMENT Fragment
;
988 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
989 return EFI_INVALID_PARAMETER
;
992 HttpInstance
= Wrap
->HttpInstance
;
993 Token
= Wrap
->HttpToken
;
994 HttpMsg
= Token
->Message
;
996 HttpInstance
->EndofHeader
= NULL
;
997 HttpInstance
->HttpHeaders
= NULL
;
998 HttpMsg
->Headers
= NULL
;
1005 Fragment
.Bulk
= NULL
;
1007 if (HttpMsg
->Data
.Response
!= NULL
) {
1009 // Check whether we have cached header from previous call.
1011 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1013 // The data is stored at [NextMsg, CacheBody + CacheLen].
1015 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1016 HttpHeaders
= AllocateZeroPool (HdrLen
);
1017 if (HttpHeaders
== NULL
) {
1018 Status
= EFI_OUT_OF_RESOURCES
;
1022 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1023 FreePool (HttpInstance
->CacheBody
);
1024 HttpInstance
->CacheBody
= NULL
;
1025 HttpInstance
->NextMsg
= NULL
;
1026 HttpInstance
->CacheOffset
= 0;
1027 SizeofHeaders
= HdrLen
;
1028 BufferSize
= HttpInstance
->CacheLen
;
1031 // Check whether we cached the whole HTTP headers.
1033 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1036 HttpInstance
->EndofHeader
= &EndofHeader
;
1037 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1040 if (HttpInstance
->TimeoutEvent
== NULL
) {
1042 // Create TimeoutEvent for response
1044 Status
= gBS
->CreateEvent (
1049 &HttpInstance
->TimeoutEvent
1051 if (EFI_ERROR (Status
)) {
1057 // Get HTTP timeout value
1059 TimeoutValue
= PcdGet32 (PcdHttpIoTimeout
);
1062 // Start the timer, and wait Timeout seconds to receive the header packet.
1064 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, TimeoutValue
* TICKS_PER_MS
);
1065 if (EFI_ERROR (Status
)) {
1069 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1071 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1073 if (EFI_ERROR (Status
)) {
1077 ASSERT (HttpHeaders
!= NULL
);
1080 // Cache the part of body.
1082 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1084 if (HttpInstance
->CacheBody
!= NULL
) {
1085 FreePool (HttpInstance
->CacheBody
);
1088 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1089 if (HttpInstance
->CacheBody
== NULL
) {
1090 Status
= EFI_OUT_OF_RESOURCES
;
1094 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1095 HttpInstance
->CacheLen
= BodyLen
;
1099 // Search for Status Code.
1101 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1102 if (StatusCodeStr
== NULL
) {
1103 Status
= EFI_NOT_READY
;
1107 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1110 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1112 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1114 Status
= EFI_NOT_READY
;
1119 // We could have response with just a HTTP message and no headers. For Example,
1120 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1121 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1122 // set SizeofHeaders to 0.
1124 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1125 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1128 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1131 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1132 HttpInstance
->StatusCode
= StatusCode
;
1134 Status
= EFI_NOT_READY
;
1138 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1139 // continuous request without a response call. So, we would not do an insert of
1140 // TxToken. After we have sent the complete file, we will call a response to get
1141 // a final response from server. In such a case, we would not have any TxTokens.
1142 // Hence, check that case before doing a NetMapRemoveHead.
1144 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1145 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1146 if (ValueInItem
== NULL
) {
1151 // The first Tx Token not transmitted yet, insert back and return error.
1153 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1158 if (SizeofHeaders
!= 0) {
1159 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1160 if (HeaderTmp
== NULL
) {
1161 Status
= EFI_OUT_OF_RESOURCES
;
1165 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1166 FreePool (HttpHeaders
);
1167 HttpHeaders
= HeaderTmp
;
1170 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1172 if (mHttpUtilities
== NULL
) {
1173 Status
= EFI_NOT_READY
;
1178 // Parse the HTTP header into array of key/value pairs.
1180 Status
= mHttpUtilities
->Parse (
1185 &HttpMsg
->HeaderCount
1187 if (EFI_ERROR (Status
)) {
1191 FreePool (HttpHeaders
);
1196 // Init message-body parser by header information.
1198 Status
= HttpInitMsgParser (
1199 HttpInstance
->Method
,
1200 HttpMsg
->Data
.Response
->StatusCode
,
1201 HttpMsg
->HeaderCount
,
1203 HttpBodyParserCallback
,
1204 (VOID
*) (&HttpInstance
->CallbackData
),
1205 &HttpInstance
->MsgParser
1207 if (EFI_ERROR (Status
)) {
1212 // Check whether we received a complete HTTP message.
1214 if (HttpInstance
->CacheBody
!= NULL
) {
1216 // Record the CallbackData data.
1218 HttpInstance
->CallbackData
.Wrap
= (VOID
*) Wrap
;
1219 HttpInstance
->CallbackData
.ParseData
= (VOID
*) HttpInstance
->CacheBody
;
1220 HttpInstance
->CallbackData
.ParseDataLength
= HttpInstance
->CacheLen
;
1223 // Parse message with CallbackData data.
1225 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1226 if (EFI_ERROR (Status
)) {
1231 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1233 // Free the MsgParse since we already have a full HTTP message.
1235 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1236 HttpInstance
->MsgParser
= NULL
;
1240 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1241 Status
= EFI_SUCCESS
;
1247 // Receive the response body.
1252 // First check whether we cached some data.
1254 if (HttpInstance
->CacheBody
!= NULL
) {
1256 // Calculate the length of the cached data.
1258 if (HttpInstance
->NextMsg
!= NULL
) {
1260 // We have a cached HTTP message which includes a part of HTTP header of next message.
1262 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1264 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1269 // We have some cached data. Just copy the data and return.
1271 if (HttpMsg
->BodyLength
< BodyLen
) {
1272 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1273 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1276 // Copy all cached data out.
1278 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1279 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1280 HttpMsg
->BodyLength
= BodyLen
;
1282 if (HttpInstance
->NextMsg
== NULL
) {
1284 // There is no HTTP header of next message. Just free the cache buffer.
1286 FreePool (HttpInstance
->CacheBody
);
1287 HttpInstance
->CacheBody
= NULL
;
1288 HttpInstance
->NextMsg
= NULL
;
1289 HttpInstance
->CacheOffset
= 0;
1293 // Return since we already received required data.
1295 Status
= EFI_SUCCESS
;
1299 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1301 // We received a complete HTTP message, and we don't have more data to return to caller.
1303 HttpMsg
->BodyLength
= 0;
1304 Status
= EFI_SUCCESS
;
1309 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1312 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1314 if (!HttpInstance
->UseHttps
) {
1315 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1317 if (EFI_ERROR (Status
)) {
1322 if (HttpInstance
->TimeoutEvent
== NULL
) {
1324 // Create TimeoutEvent for response
1326 Status
= gBS
->CreateEvent (
1331 &HttpInstance
->TimeoutEvent
1333 if (EFI_ERROR (Status
)) {
1339 // Get HTTP timeout value
1341 TimeoutValue
= PcdGet32 (PcdHttpIoTimeout
);
1344 // Start the timer, and wait Timeout seconds to receive the body packet.
1346 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, TimeoutValue
* TICKS_PER_MS
);
1347 if (EFI_ERROR (Status
)) {
1351 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1353 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1355 if (EFI_ERROR (Status
)) {
1360 // Process the received the body packet.
1362 HttpMsg
->BodyLength
= MIN ((UINTN
) Fragment
.Len
, HttpMsg
->BodyLength
);
1364 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1367 // Record the CallbackData data.
1369 HttpInstance
->CallbackData
.Wrap
= (VOID
*) Wrap
;
1370 HttpInstance
->CallbackData
.ParseData
= HttpMsg
->Body
;
1371 HttpInstance
->CallbackData
.ParseDataLength
= HttpMsg
->BodyLength
;
1374 // Parse Body with CallbackData data.
1376 Status
= HttpParseMessageBody (
1377 HttpInstance
->MsgParser
,
1378 HttpMsg
->BodyLength
,
1381 if (EFI_ERROR (Status
)) {
1385 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1387 // Free the MsgParse since we already have a full HTTP message.
1389 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1390 HttpInstance
->MsgParser
= NULL
;
1394 // Check whether there is the next message header in the HttpMsg->Body.
1396 if (HttpInstance
->NextMsg
!= NULL
) {
1397 HttpMsg
->BodyLength
= HttpInstance
->NextMsg
- (CHAR8
*) HttpMsg
->Body
;
1400 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1401 if (HttpInstance
->CacheLen
!= 0) {
1402 if (HttpInstance
->CacheBody
!= NULL
) {
1403 FreePool (HttpInstance
->CacheBody
);
1406 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1407 if (HttpInstance
->CacheBody
== NULL
) {
1408 Status
= EFI_OUT_OF_RESOURCES
;
1412 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1413 HttpInstance
->CacheOffset
= 0;
1414 if (HttpInstance
->NextMsg
!= NULL
) {
1415 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
;
1419 if (Fragment
.Bulk
!= NULL
) {
1420 FreePool (Fragment
.Bulk
);
1421 Fragment
.Bulk
= NULL
;
1430 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1432 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1435 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1436 Token
->Status
= EFI_HTTP_ERROR
;
1438 Token
->Status
= Status
;
1441 gBS
->SignalEvent (Token
->Event
);
1442 HttpCloseTcpRxEvent (Wrap
);
1447 if (ValueInItem
!= NULL
) {
1448 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1452 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1454 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1457 if (!HttpInstance
->UseHttps
) {
1458 HttpTcpTokenCleanup (Wrap
);
1463 if (HttpHeaders
!= NULL
) {
1464 FreePool (HttpHeaders
);
1468 if (Fragment
.Bulk
!= NULL
) {
1469 FreePool (Fragment
.Bulk
);
1470 Fragment
.Bulk
= NULL
;
1473 if (HttpMsg
->Headers
!= NULL
) {
1474 FreePool (HttpMsg
->Headers
);
1475 HttpMsg
->Headers
= NULL
;
1478 if (HttpInstance
->CacheBody
!= NULL
) {
1479 FreePool (HttpInstance
->CacheBody
);
1480 HttpInstance
->CacheBody
= NULL
;
1483 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1484 Token
->Status
= EFI_HTTP_ERROR
;
1486 Token
->Status
= Status
;
1489 gBS
->SignalEvent (Token
->Event
);
1497 The Response() function queues an HTTP response to this HTTP instance, similar to
1498 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1499 or if there is an error, Status in token will be updated and Event will be signaled.
1501 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1502 is received in the underlying TCP instance, the data will be parsed and Token will
1503 be populated with the response data. If the data received from the remote host
1504 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1505 (asynchronously) for more data to be sent from the remote host before signaling
1508 It is the responsibility of the caller to allocate a buffer for Body and specify the
1509 size in BodyLength. If the remote host provides a response that contains a content
1510 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1511 BodyLength will be updated with the amount of bytes received and copied to Body. This
1512 allows the client to download a large file in chunks instead of into one contiguous
1513 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1514 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1515 token to underlying TCP instance. If data arrives in the receive buffer, up to
1516 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1517 BodyLength with the amount of bytes received and copied to Body.
1519 If the HTTP driver does not have an open underlying TCP connection with the host
1520 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1521 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1522 an open TCP connection between client and host.
1524 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1525 @param[in] Token Pointer to storage containing HTTP response token.
1527 @retval EFI_SUCCESS Allocation succeeded.
1528 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1530 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1533 Token->Message->Headers is NULL.
1534 Token->Message is NULL.
1535 Token->Message->Body is not NULL,
1536 Token->Message->BodyLength is non-zero, and
1537 Token->Message->Data is NULL, but a previous call to
1538 Response() has not been completed successfully.
1539 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1540 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1541 specified by response URL.
1546 IN EFI_HTTP_PROTOCOL
*This
,
1547 IN EFI_HTTP_TOKEN
*Token
1551 EFI_HTTP_MESSAGE
*HttpMsg
;
1552 HTTP_PROTOCOL
*HttpInstance
;
1553 HTTP_TOKEN_WRAP
*Wrap
;
1555 if ((This
== NULL
) || (Token
== NULL
)) {
1556 return EFI_INVALID_PARAMETER
;
1559 HttpMsg
= Token
->Message
;
1560 if (HttpMsg
== NULL
) {
1561 return EFI_INVALID_PARAMETER
;
1564 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1566 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1567 return EFI_NOT_STARTED
;
1571 // Check whether the token already existed.
1573 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1574 return EFI_ACCESS_DENIED
;
1577 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1579 return EFI_OUT_OF_RESOURCES
;
1582 Wrap
->HttpInstance
= HttpInstance
;
1583 Wrap
->HttpToken
= Token
;
1586 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1587 // receive the https response. A special TlsRxToken is used for receiving TLS
1588 // related messages. It should be a blocking response.
1590 if (!HttpInstance
->UseHttps
) {
1591 Status
= HttpCreateTcpRxEvent (Wrap
);
1592 if (EFI_ERROR (Status
)) {
1597 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1598 if (EFI_ERROR (Status
)) {
1603 // If already have pending RxTokens, return directly.
1605 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1609 return HttpResponseWorker (Wrap
);
1613 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1614 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1617 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1618 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1627 The Poll() function can be used by network drivers and applications to increase the
1628 rate that data packets are moved between the communication devices and the transmit
1631 In some systems, the periodic timer event in the managed network driver may not poll
1632 the underlying communications device fast enough to transmit and/or receive all data
1633 packets without missing incoming packets or dropping outgoing packets. Drivers and
1634 applications that are experiencing packet loss should try calling the Poll() function
1637 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1639 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1640 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1641 @retval EFI_INVALID_PARAMETER This is NULL.
1642 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1643 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1649 IN EFI_HTTP_PROTOCOL
*This
1653 HTTP_PROTOCOL
*HttpInstance
;
1656 return EFI_INVALID_PARAMETER
;
1659 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1661 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1662 return EFI_NOT_STARTED
;
1665 if (HttpInstance
->LocalAddressIsIPv6
) {
1666 if (HttpInstance
->Tcp6
== NULL
) {
1667 return EFI_NOT_STARTED
;
1669 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1671 if (HttpInstance
->Tcp4
== NULL
) {
1672 return EFI_NOT_STARTED
;
1674 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);