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_CALLBACK_DATA
*CallbackData
;
920 HTTP_TOKEN_WRAP
*Wrap
;
924 if (EventType
!= BodyParseEventOnComplete
) {
928 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
932 CallbackData
= (HTTP_CALLBACK_DATA
*) Context
;
934 Wrap
= (HTTP_TOKEN_WRAP
*) (CallbackData
->Wrap
);
935 Body
= CallbackData
->ParseData
;
936 BodyLength
= CallbackData
->ParseDataLength
;
938 if (Data
< Body
+ BodyLength
) {
939 Wrap
->HttpInstance
->NextMsg
= Data
;
941 Wrap
->HttpInstance
->NextMsg
= NULL
;
948 The work function of EfiHttpResponse().
950 @param[in] Wrap Pointer to HTTP token's wrap data.
952 @retval EFI_SUCCESS Allocation succeeded.
953 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
954 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
955 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
960 IN HTTP_TOKEN_WRAP
*Wrap
964 EFI_HTTP_MESSAGE
*HttpMsg
;
972 CHAR8
*StatusCodeStr
;
974 HTTP_PROTOCOL
*HttpInstance
;
975 EFI_HTTP_TOKEN
*Token
;
977 HTTP_TOKEN_WRAP
*ValueInItem
;
979 NET_FRAGMENT Fragment
;
981 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
982 return EFI_INVALID_PARAMETER
;
985 HttpInstance
= Wrap
->HttpInstance
;
986 Token
= Wrap
->HttpToken
;
987 HttpMsg
= Token
->Message
;
989 HttpInstance
->EndofHeader
= NULL
;
990 HttpInstance
->HttpHeaders
= NULL
;
991 HttpMsg
->Headers
= NULL
;
998 Fragment
.Bulk
= NULL
;
1000 if (HttpMsg
->Data
.Response
!= NULL
) {
1002 // Check whether we have cached header from previous call.
1004 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1006 // The data is stored at [NextMsg, CacheBody + CacheLen].
1008 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1009 HttpHeaders
= AllocateZeroPool (HdrLen
);
1010 if (HttpHeaders
== NULL
) {
1011 Status
= EFI_OUT_OF_RESOURCES
;
1015 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1016 FreePool (HttpInstance
->CacheBody
);
1017 HttpInstance
->CacheBody
= NULL
;
1018 HttpInstance
->NextMsg
= NULL
;
1019 HttpInstance
->CacheOffset
= 0;
1020 SizeofHeaders
= HdrLen
;
1021 BufferSize
= HttpInstance
->CacheLen
;
1024 // Check whether we cached the whole HTTP headers.
1026 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1029 HttpInstance
->EndofHeader
= &EndofHeader
;
1030 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1033 if (HttpInstance
->TimeoutEvent
== NULL
) {
1035 // Create TimeoutEvent for response
1037 Status
= gBS
->CreateEvent (
1042 &HttpInstance
->TimeoutEvent
1044 if (EFI_ERROR (Status
)) {
1050 // Start the timer, and wait Timeout seconds to receive the header packet.
1052 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1053 if (EFI_ERROR (Status
)) {
1057 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1059 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1061 if (EFI_ERROR (Status
)) {
1065 ASSERT (HttpHeaders
!= NULL
);
1068 // Cache the part of body.
1070 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1072 if (HttpInstance
->CacheBody
!= NULL
) {
1073 FreePool (HttpInstance
->CacheBody
);
1076 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1077 if (HttpInstance
->CacheBody
== NULL
) {
1078 Status
= EFI_OUT_OF_RESOURCES
;
1082 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1083 HttpInstance
->CacheLen
= BodyLen
;
1087 // Search for Status Code.
1089 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1090 if (StatusCodeStr
== NULL
) {
1091 Status
= EFI_NOT_READY
;
1095 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1098 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1100 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1102 Status
= EFI_NOT_READY
;
1107 // We could have response with just a HTTP message and no headers. For Example,
1108 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1109 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1110 // set SizeofHeaders to 0.
1112 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1113 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1116 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1119 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1120 HttpInstance
->StatusCode
= StatusCode
;
1122 Status
= EFI_NOT_READY
;
1126 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1127 // continuous request without a response call. So, we would not do an insert of
1128 // TxToken. After we have sent the complete file, we will call a response to get
1129 // a final response from server. In such a case, we would not have any TxTokens.
1130 // Hence, check that case before doing a NetMapRemoveHead.
1132 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1133 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1134 if (ValueInItem
== NULL
) {
1139 // The first Tx Token not transmitted yet, insert back and return error.
1141 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1146 if (SizeofHeaders
!= 0) {
1147 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1148 if (HeaderTmp
== NULL
) {
1149 Status
= EFI_OUT_OF_RESOURCES
;
1153 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1154 FreePool (HttpHeaders
);
1155 HttpHeaders
= HeaderTmp
;
1158 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1160 if (mHttpUtilities
== NULL
) {
1161 Status
= EFI_NOT_READY
;
1166 // Parse the HTTP header into array of key/value pairs.
1168 Status
= mHttpUtilities
->Parse (
1173 &HttpMsg
->HeaderCount
1175 if (EFI_ERROR (Status
)) {
1179 FreePool (HttpHeaders
);
1184 // Init message-body parser by header information.
1186 Status
= HttpInitMsgParser (
1187 HttpInstance
->Method
,
1188 HttpMsg
->Data
.Response
->StatusCode
,
1189 HttpMsg
->HeaderCount
,
1191 HttpBodyParserCallback
,
1192 (VOID
*) (&HttpInstance
->CallbackData
),
1193 &HttpInstance
->MsgParser
1195 if (EFI_ERROR (Status
)) {
1200 // Check whether we received a complete HTTP message.
1202 if (HttpInstance
->CacheBody
!= NULL
) {
1204 // Record the CallbackData data.
1206 HttpInstance
->CallbackData
.Wrap
= (VOID
*) Wrap
;
1207 HttpInstance
->CallbackData
.ParseData
= (VOID
*) HttpInstance
->CacheBody
;
1208 HttpInstance
->CallbackData
.ParseDataLength
= HttpInstance
->CacheLen
;
1211 // Parse message with CallbackData data.
1213 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1214 if (EFI_ERROR (Status
)) {
1219 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1221 // Free the MsgParse since we already have a full HTTP message.
1223 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1224 HttpInstance
->MsgParser
= NULL
;
1228 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1229 Status
= EFI_SUCCESS
;
1235 // Receive the response body.
1240 // First check whether we cached some data.
1242 if (HttpInstance
->CacheBody
!= NULL
) {
1244 // Calculate the length of the cached data.
1246 if (HttpInstance
->NextMsg
!= NULL
) {
1248 // We have a cached HTTP message which includes a part of HTTP header of next message.
1250 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1252 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1257 // We have some cached data. Just copy the data and return.
1259 if (HttpMsg
->BodyLength
< BodyLen
) {
1260 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1261 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1264 // Copy all cached data out.
1266 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1267 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1268 HttpMsg
->BodyLength
= BodyLen
;
1270 if (HttpInstance
->NextMsg
== NULL
) {
1272 // There is no HTTP header of next message. Just free the cache buffer.
1274 FreePool (HttpInstance
->CacheBody
);
1275 HttpInstance
->CacheBody
= NULL
;
1276 HttpInstance
->NextMsg
= NULL
;
1277 HttpInstance
->CacheOffset
= 0;
1281 // Return since we aready received required data.
1283 Status
= EFI_SUCCESS
;
1287 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1289 // We received a complete HTTP message, and we don't have more data to return to caller.
1291 HttpMsg
->BodyLength
= 0;
1292 Status
= EFI_SUCCESS
;
1297 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1300 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1302 if (!HttpInstance
->UseHttps
) {
1303 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1305 if (EFI_ERROR (Status
)) {
1310 if (HttpInstance
->TimeoutEvent
== NULL
) {
1312 // Create TimeoutEvent for response
1314 Status
= gBS
->CreateEvent (
1319 &HttpInstance
->TimeoutEvent
1321 if (EFI_ERROR (Status
)) {
1327 // Start the timer, and wait Timeout seconds to receive the body packet.
1329 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1330 if (EFI_ERROR (Status
)) {
1334 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1336 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1338 if (EFI_ERROR (Status
)) {
1343 // Process the received the body packet.
1345 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1347 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1350 // Record the CallbackData data.
1352 HttpInstance
->CallbackData
.Wrap
= (VOID
*) Wrap
;
1353 HttpInstance
->CallbackData
.ParseData
= HttpMsg
->Body
;
1354 HttpInstance
->CallbackData
.ParseDataLength
= HttpMsg
->BodyLength
;
1357 // Parse Body with CallbackData data.
1359 Status
= HttpParseMessageBody (
1360 HttpInstance
->MsgParser
,
1361 HttpMsg
->BodyLength
,
1364 if (EFI_ERROR (Status
)) {
1368 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1370 // Free the MsgParse since we already have a full HTTP message.
1372 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1373 HttpInstance
->MsgParser
= NULL
;
1377 // Check whether there is the next message header in the HttpMsg->Body.
1379 if (HttpInstance
->NextMsg
!= NULL
) {
1380 HttpMsg
->BodyLength
= HttpInstance
->NextMsg
- (CHAR8
*) HttpMsg
->Body
;
1383 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1384 if (HttpInstance
->CacheLen
!= 0) {
1385 if (HttpInstance
->CacheBody
!= NULL
) {
1386 FreePool (HttpInstance
->CacheBody
);
1389 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1390 if (HttpInstance
->CacheBody
== NULL
) {
1391 Status
= EFI_OUT_OF_RESOURCES
;
1395 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1396 HttpInstance
->CacheOffset
= 0;
1397 if (HttpInstance
->NextMsg
!= NULL
) {
1398 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
;
1402 if (Fragment
.Bulk
!= NULL
) {
1403 FreePool (Fragment
.Bulk
);
1404 Fragment
.Bulk
= NULL
;
1413 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1415 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1418 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1419 Token
->Status
= EFI_HTTP_ERROR
;
1421 Token
->Status
= Status
;
1424 gBS
->SignalEvent (Token
->Event
);
1425 HttpCloseTcpRxEvent (Wrap
);
1430 if (ValueInItem
!= NULL
) {
1431 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1435 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1437 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1440 if (!HttpInstance
->UseHttps
) {
1441 HttpTcpTokenCleanup (Wrap
);
1446 if (HttpHeaders
!= NULL
) {
1447 FreePool (HttpHeaders
);
1451 if (Fragment
.Bulk
!= NULL
) {
1452 FreePool (Fragment
.Bulk
);
1453 Fragment
.Bulk
= NULL
;
1456 if (HttpMsg
->Headers
!= NULL
) {
1457 FreePool (HttpMsg
->Headers
);
1458 HttpMsg
->Headers
= NULL
;
1461 if (HttpInstance
->CacheBody
!= NULL
) {
1462 FreePool (HttpInstance
->CacheBody
);
1463 HttpInstance
->CacheBody
= NULL
;
1466 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1467 Token
->Status
= EFI_HTTP_ERROR
;
1469 Token
->Status
= Status
;
1472 gBS
->SignalEvent (Token
->Event
);
1480 The Response() function queues an HTTP response to this HTTP instance, similar to
1481 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1482 or if there is an error, Status in token will be updated and Event will be signaled.
1484 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1485 is received in the underlying TCP instance, the data will be parsed and Token will
1486 be populated with the response data. If the data received from the remote host
1487 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1488 (asynchronously) for more data to be sent from the remote host before signaling
1491 It is the responsibility of the caller to allocate a buffer for Body and specify the
1492 size in BodyLength. If the remote host provides a response that contains a content
1493 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1494 BodyLength will be updated with the amount of bytes received and copied to Body. This
1495 allows the client to download a large file in chunks instead of into one contiguous
1496 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1497 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1498 token to underlying TCP instance. If data arrives in the receive buffer, up to
1499 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1500 BodyLength with the amount of bytes received and copied to Body.
1502 If the HTTP driver does not have an open underlying TCP connection with the host
1503 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1504 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1505 an open TCP connection between client and host.
1507 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1508 @param[in] Token Pointer to storage containing HTTP response token.
1510 @retval EFI_SUCCESS Allocation succeeded.
1511 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1513 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1516 Token->Message->Headers is NULL.
1517 Token->Message is NULL.
1518 Token->Message->Body is not NULL,
1519 Token->Message->BodyLength is non-zero, and
1520 Token->Message->Data is NULL, but a previous call to
1521 Response() has not been completed successfully.
1522 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1523 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1524 specified by response URL.
1529 IN EFI_HTTP_PROTOCOL
*This
,
1530 IN EFI_HTTP_TOKEN
*Token
1534 EFI_HTTP_MESSAGE
*HttpMsg
;
1535 HTTP_PROTOCOL
*HttpInstance
;
1536 HTTP_TOKEN_WRAP
*Wrap
;
1538 if ((This
== NULL
) || (Token
== NULL
)) {
1539 return EFI_INVALID_PARAMETER
;
1542 HttpMsg
= Token
->Message
;
1543 if (HttpMsg
== NULL
) {
1544 return EFI_INVALID_PARAMETER
;
1547 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1549 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1550 return EFI_NOT_STARTED
;
1554 // Check whether the token already existed.
1556 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1557 return EFI_ACCESS_DENIED
;
1560 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1562 return EFI_OUT_OF_RESOURCES
;
1565 Wrap
->HttpInstance
= HttpInstance
;
1566 Wrap
->HttpToken
= Token
;
1569 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1570 // receive the https response. A special TlsRxToken is used for receiving TLS
1571 // related messages. It should be a blocking response.
1573 if (!HttpInstance
->UseHttps
) {
1574 Status
= HttpCreateTcpRxEvent (Wrap
);
1575 if (EFI_ERROR (Status
)) {
1580 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1581 if (EFI_ERROR (Status
)) {
1586 // If already have pending RxTokens, return directly.
1588 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1592 return HttpResponseWorker (Wrap
);
1596 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1597 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1600 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1601 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1610 The Poll() function can be used by network drivers and applications to increase the
1611 rate that data packets are moved between the communication devices and the transmit
1614 In some systems, the periodic timer event in the managed network driver may not poll
1615 the underlying communications device fast enough to transmit and/or receive all data
1616 packets without missing incoming packets or dropping outgoing packets. Drivers and
1617 applications that are experiencing packet loss should try calling the Poll() function
1620 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1622 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1623 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1624 @retval EFI_INVALID_PARAMETER This is NULL.
1625 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1626 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1632 IN EFI_HTTP_PROTOCOL
*This
1636 HTTP_PROTOCOL
*HttpInstance
;
1639 return EFI_INVALID_PARAMETER
;
1642 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1644 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1645 return EFI_NOT_STARTED
;
1648 if (HttpInstance
->LocalAddressIsIPv6
) {
1649 if (HttpInstance
->Tcp6
== NULL
) {
1650 return EFI_NOT_STARTED
;
1652 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1654 if (HttpInstance
->Tcp4
== NULL
) {
1655 return EFI_NOT_STARTED
;
1657 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);