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
)) {
408 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
409 if (EFI_ERROR (Status
)) {
413 if (HttpInstance
->LocalAddressIsIPv6
) {
414 HostNameSize
= AsciiStrSize (HostName
);
416 if (HostNameSize
> 2 && HostName
[0] == '[' && HostName
[HostNameSize
- 2] == ']') {
418 // HostName format is expressed as IPv6, so, remove '[' and ']'.
421 CopyMem (HostName
, HostName
+ 1, HostNameSize
- 1);
422 HostName
[HostNameSize
- 1] = '\0';
426 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
427 if (EFI_ERROR (Status
)) {
428 if (HttpInstance
->UseHttps
) {
429 RemotePort
= HTTPS_DEFAULT_PORT
;
431 RemotePort
= HTTP_DEFAULT_PORT
;
435 // If Configure is TRUE, it indicates the first time to call Request();
436 // If ReConfigure is TRUE, it indicates the request URL is not same
437 // with the previous call to Request();
442 if (HttpInstance
->RemoteHost
== NULL
) {
444 // Request() is called the first time.
448 if ((HttpInstance
->RemotePort
== RemotePort
) &&
449 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
450 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
452 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
454 // Host Name and port number of the request URL are the same with previous call to Request().
455 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
456 // Check whether previous TCP packet sent out.
459 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
461 // Wrap the HTTP token in HTTP_TOKEN_WRAP
463 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
465 Status
= EFI_OUT_OF_RESOURCES
;
469 Wrap
->HttpToken
= Token
;
470 Wrap
->HttpInstance
= HttpInstance
;
472 Status
= HttpCreateTcpTxEvent (Wrap
);
473 if (EFI_ERROR (Status
)) {
477 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
478 if (EFI_ERROR (Status
)) {
482 Wrap
->TcpWrap
.Method
= Request
->Method
;
486 HttpUrlFreeParser (UrlParser
);
489 // Queue the HTTP token and return.
494 // Use existing TCP instance to transmit the packet.
501 // Need close existing TCP instance and create a new TCP instance for data transmit.
503 if (HttpInstance
->RemoteHost
!= NULL
) {
504 FreePool (HttpInstance
->RemoteHost
);
505 HttpInstance
->RemoteHost
= NULL
;
506 HttpInstance
->RemotePort
= 0;
514 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
516 if (!HttpInstance
->LocalAddressIsIPv6
) {
517 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
519 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
522 if (EFI_ERROR (Status
)) {
523 HostNameSize
= AsciiStrSize (HostName
);
524 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
525 if (HostNameStr
== NULL
) {
526 Status
= EFI_OUT_OF_RESOURCES
;
530 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
531 if (!HttpInstance
->LocalAddressIsIPv6
) {
532 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
534 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
537 FreePool (HostNameStr
);
538 if (EFI_ERROR (Status
)) {
539 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
545 // Save the RemotePort and RemoteHost.
547 ASSERT (HttpInstance
->RemoteHost
== NULL
);
548 HttpInstance
->RemotePort
= RemotePort
;
549 HttpInstance
->RemoteHost
= HostName
;
555 // The request URL is different from previous calls to Request(), close existing TCP instance.
557 if (!HttpInstance
->LocalAddressIsIPv6
) {
558 ASSERT (HttpInstance
->Tcp4
!= NULL
);
560 ASSERT (HttpInstance
->Tcp6
!= NULL
);
563 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
564 Status
= TlsCloseSession (HttpInstance
);
565 if (EFI_ERROR (Status
)) {
569 TlsCloseTxRxEvent (HttpInstance
);
572 HttpCloseConnection (HttpInstance
);
573 EfiHttpCancel (This
, NULL
);
577 // Wrap the HTTP token in HTTP_TOKEN_WRAP
579 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
581 Status
= EFI_OUT_OF_RESOURCES
;
585 Wrap
->HttpToken
= Token
;
586 Wrap
->HttpInstance
= HttpInstance
;
587 if (Request
!= NULL
) {
588 Wrap
->TcpWrap
.Method
= Request
->Method
;
591 Status
= HttpInitSession (
594 Configure
|| ReConfigure
,
597 if (EFI_ERROR (Status
)) {
601 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
603 // For the new HTTP token, create TX TCP token events.
605 Status
= HttpCreateTcpTxEvent (Wrap
);
606 if (EFI_ERROR (Status
)) {
612 // Create request message.
615 if (Url
!= NULL
&& *FileUrl
!= '/') {
617 // Convert the absolute-URI to the absolute-path
619 while (*FileUrl
!= ':') {
622 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
624 while (*FileUrl
!= '/') {
628 Status
= EFI_INVALID_PARAMETER
;
633 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
635 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
640 // Every request we insert a TxToken and a response call would remove the TxToken.
641 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
642 // continuous request without a response call. So, in such cases, where Request
643 // structure is NULL, we would not insert a TxToken.
645 if (Request
!= NULL
) {
646 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
647 if (EFI_ERROR (Status
)) {
653 // Transmit the request message.
655 Status
= HttpTransmitTcp (
661 if (EFI_ERROR (Status
)) {
667 if (HostName
!= NULL
) {
671 if (UrlParser
!= NULL
) {
672 HttpUrlFreeParser (UrlParser
);
679 // We would have inserted a TxToken only if Request structure is not NULL.
680 // Hence check before we do a remove in this error case.
682 if (Request
!= NULL
) {
683 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
687 if (RequestMsg
!= NULL
) {
688 FreePool (RequestMsg
);
692 if (HttpInstance
->UseHttps
) {
693 TlsCloseSession (HttpInstance
);
694 TlsCloseTxRxEvent (HttpInstance
);
698 HttpCloseConnection (HttpInstance
);
700 HttpCloseTcpConnCloseEvent (HttpInstance
);
701 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
702 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
703 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
705 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
706 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
707 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
711 if (HostName
!= NULL
) {
717 if (UrlParser
!= NULL
) {
718 HttpUrlFreeParser (UrlParser
);
726 Cancel a user's Token.
728 @param[in] Map The HTTP instance's token queue.
729 @param[in] Item Object container for one HTTP token and token's wrap.
730 @param[in] Context The user's token to cancel.
732 @retval EFI_SUCCESS Continue to check the next Item.
733 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
740 IN NET_MAP_ITEM
*Item
,
744 EFI_HTTP_TOKEN
*Token
;
745 HTTP_TOKEN_WRAP
*Wrap
;
746 HTTP_PROTOCOL
*HttpInstance
;
748 Token
= (EFI_HTTP_TOKEN
*) Context
;
751 // Return EFI_SUCCESS to check the next item in the map if
752 // this one doesn't match.
754 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
758 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
759 ASSERT (Wrap
!= NULL
);
760 HttpInstance
= Wrap
->HttpInstance
;
762 if (!HttpInstance
->LocalAddressIsIPv6
) {
763 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
765 // Cancle the Token before close its Event.
767 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
770 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
775 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
777 // Cancle the Token before close its Event.
779 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
782 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
789 // If only one item is to be cancel, return EFI_ABORTED to stop
790 // iterating the map any more.
800 Cancel the user's receive/transmit request. It is the worker function of
801 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
804 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
805 @param[in] Token The token to cancel. If NULL, all token will be
808 @retval EFI_SUCCESS The token is cancelled.
809 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
810 @retval Others Other error as indicated.
815 IN HTTP_PROTOCOL
*HttpInstance
,
816 IN EFI_HTTP_TOKEN
*Token
822 // First check the tokens queued by EfiHttpRequest().
824 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
825 if (EFI_ERROR (Status
)) {
827 if (Status
== EFI_ABORTED
) {
835 if (!HttpInstance
->UseHttps
) {
837 // Then check the tokens queued by EfiHttpResponse(), except for Https.
839 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
840 if (EFI_ERROR (Status
)) {
842 if (Status
== EFI_ABORTED
) {
845 return EFI_NOT_FOUND
;
852 if (!HttpInstance
->LocalAddressIsIPv6
) {
853 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
855 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
864 Abort an asynchronous HTTP request or response token.
866 The Cancel() function aborts a pending HTTP request or response transaction. If
867 Token is not NULL and the token is in transmit or receive queues when it is being
868 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
869 be signaled. If the token is not in one of the queues, which usually means that the
870 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
871 all asynchronous tokens issued by Request() or Response() will be aborted.
873 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
874 @param[in] Token Point to storage containing HTTP request or response
877 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
878 @retval EFI_INVALID_PARAMETER This is NULL.
879 @retval EFI_NOT_STARTED This instance hasn't been configured.
880 @retval EFI_NOT_FOUND The asynchronous request or response token is not
882 @retval EFI_UNSUPPORTED The implementation does not support this function.
888 IN EFI_HTTP_PROTOCOL
*This
,
889 IN EFI_HTTP_TOKEN
*Token
892 HTTP_PROTOCOL
*HttpInstance
;
895 return EFI_INVALID_PARAMETER
;
898 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
900 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
901 return EFI_NOT_STARTED
;
904 return HttpCancel (HttpInstance
, Token
);
909 A callback function to intercept events during message parser.
911 This function will be invoked during HttpParseMessageBody() with various events type. An error
912 return status of the callback function will cause the HttpParseMessageBody() aborted.
914 @param[in] EventType Event type of this callback call.
915 @param[in] Data A pointer to data buffer.
916 @param[in] Length Length in bytes of the Data.
917 @param[in] Context Callback context set by HttpInitMsgParser().
919 @retval EFI_SUCCESS Continue to parser the message body.
924 HttpBodyParserCallback (
925 IN HTTP_BODY_PARSE_EVENT EventType
,
931 HTTP_CALLBACK_DATA
*CallbackData
;
932 HTTP_TOKEN_WRAP
*Wrap
;
936 if (EventType
!= BodyParseEventOnComplete
) {
940 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
944 CallbackData
= (HTTP_CALLBACK_DATA
*) Context
;
946 Wrap
= (HTTP_TOKEN_WRAP
*) (CallbackData
->Wrap
);
947 Body
= CallbackData
->ParseData
;
948 BodyLength
= CallbackData
->ParseDataLength
;
950 if (Data
< Body
+ BodyLength
) {
951 Wrap
->HttpInstance
->NextMsg
= Data
;
953 Wrap
->HttpInstance
->NextMsg
= NULL
;
960 The work function of EfiHttpResponse().
962 @param[in] Wrap Pointer to HTTP token's wrap data.
964 @retval EFI_SUCCESS Allocation succeeded.
965 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
966 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or
967 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
972 IN HTTP_TOKEN_WRAP
*Wrap
976 EFI_HTTP_MESSAGE
*HttpMsg
;
984 CHAR8
*StatusCodeStr
;
986 HTTP_PROTOCOL
*HttpInstance
;
987 EFI_HTTP_TOKEN
*Token
;
989 HTTP_TOKEN_WRAP
*ValueInItem
;
991 NET_FRAGMENT Fragment
;
993 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
994 return EFI_INVALID_PARAMETER
;
997 HttpInstance
= Wrap
->HttpInstance
;
998 Token
= Wrap
->HttpToken
;
999 HttpMsg
= Token
->Message
;
1001 HttpInstance
->EndofHeader
= NULL
;
1002 HttpInstance
->HttpHeaders
= NULL
;
1003 HttpMsg
->Headers
= NULL
;
1010 Fragment
.Bulk
= NULL
;
1012 if (HttpMsg
->Data
.Response
!= NULL
) {
1014 // Check whether we have cached header from previous call.
1016 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1018 // The data is stored at [NextMsg, CacheBody + CacheLen].
1020 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1021 HttpHeaders
= AllocateZeroPool (HdrLen
);
1022 if (HttpHeaders
== NULL
) {
1023 Status
= EFI_OUT_OF_RESOURCES
;
1027 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1028 FreePool (HttpInstance
->CacheBody
);
1029 HttpInstance
->CacheBody
= NULL
;
1030 HttpInstance
->NextMsg
= NULL
;
1031 HttpInstance
->CacheOffset
= 0;
1032 SizeofHeaders
= HdrLen
;
1033 BufferSize
= HttpInstance
->CacheLen
;
1036 // Check whether we cached the whole HTTP headers.
1038 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1041 HttpInstance
->EndofHeader
= &EndofHeader
;
1042 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1045 if (HttpInstance
->TimeoutEvent
== NULL
) {
1047 // Create TimeoutEvent for response
1049 Status
= gBS
->CreateEvent (
1054 &HttpInstance
->TimeoutEvent
1056 if (EFI_ERROR (Status
)) {
1062 // Start the timer, and wait Timeout seconds to receive the header packet.
1064 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
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 aready 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 // Start the timer, and wait Timeout seconds to receive the body packet.
1341 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1342 if (EFI_ERROR (Status
)) {
1346 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1348 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1350 if (EFI_ERROR (Status
)) {
1355 // Process the received the body packet.
1357 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1359 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1362 // Record the CallbackData data.
1364 HttpInstance
->CallbackData
.Wrap
= (VOID
*) Wrap
;
1365 HttpInstance
->CallbackData
.ParseData
= HttpMsg
->Body
;
1366 HttpInstance
->CallbackData
.ParseDataLength
= HttpMsg
->BodyLength
;
1369 // Parse Body with CallbackData data.
1371 Status
= HttpParseMessageBody (
1372 HttpInstance
->MsgParser
,
1373 HttpMsg
->BodyLength
,
1376 if (EFI_ERROR (Status
)) {
1380 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1382 // Free the MsgParse since we already have a full HTTP message.
1384 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1385 HttpInstance
->MsgParser
= NULL
;
1389 // Check whether there is the next message header in the HttpMsg->Body.
1391 if (HttpInstance
->NextMsg
!= NULL
) {
1392 HttpMsg
->BodyLength
= HttpInstance
->NextMsg
- (CHAR8
*) HttpMsg
->Body
;
1395 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1396 if (HttpInstance
->CacheLen
!= 0) {
1397 if (HttpInstance
->CacheBody
!= NULL
) {
1398 FreePool (HttpInstance
->CacheBody
);
1401 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1402 if (HttpInstance
->CacheBody
== NULL
) {
1403 Status
= EFI_OUT_OF_RESOURCES
;
1407 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1408 HttpInstance
->CacheOffset
= 0;
1409 if (HttpInstance
->NextMsg
!= NULL
) {
1410 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
;
1414 if (Fragment
.Bulk
!= NULL
) {
1415 FreePool (Fragment
.Bulk
);
1416 Fragment
.Bulk
= NULL
;
1425 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1427 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1430 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1431 Token
->Status
= EFI_HTTP_ERROR
;
1433 Token
->Status
= Status
;
1436 gBS
->SignalEvent (Token
->Event
);
1437 HttpCloseTcpRxEvent (Wrap
);
1442 if (ValueInItem
!= NULL
) {
1443 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1447 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1449 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1452 if (!HttpInstance
->UseHttps
) {
1453 HttpTcpTokenCleanup (Wrap
);
1458 if (HttpHeaders
!= NULL
) {
1459 FreePool (HttpHeaders
);
1463 if (Fragment
.Bulk
!= NULL
) {
1464 FreePool (Fragment
.Bulk
);
1465 Fragment
.Bulk
= NULL
;
1468 if (HttpMsg
->Headers
!= NULL
) {
1469 FreePool (HttpMsg
->Headers
);
1470 HttpMsg
->Headers
= NULL
;
1473 if (HttpInstance
->CacheBody
!= NULL
) {
1474 FreePool (HttpInstance
->CacheBody
);
1475 HttpInstance
->CacheBody
= NULL
;
1478 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1479 Token
->Status
= EFI_HTTP_ERROR
;
1481 Token
->Status
= Status
;
1484 gBS
->SignalEvent (Token
->Event
);
1492 The Response() function queues an HTTP response to this HTTP instance, similar to
1493 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1494 or if there is an error, Status in token will be updated and Event will be signaled.
1496 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1497 is received in the underlying TCP instance, the data will be parsed and Token will
1498 be populated with the response data. If the data received from the remote host
1499 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1500 (asynchronously) for more data to be sent from the remote host before signaling
1503 It is the responsibility of the caller to allocate a buffer for Body and specify the
1504 size in BodyLength. If the remote host provides a response that contains a content
1505 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1506 BodyLength will be updated with the amount of bytes received and copied to Body. This
1507 allows the client to download a large file in chunks instead of into one contiguous
1508 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1509 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1510 token to underlying TCP instance. If data arrives in the receive buffer, up to
1511 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1512 BodyLength with the amount of bytes received and copied to Body.
1514 If the HTTP driver does not have an open underlying TCP connection with the host
1515 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1516 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1517 an open TCP connection between client and host.
1519 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1520 @param[in] Token Pointer to storage containing HTTP response token.
1522 @retval EFI_SUCCESS Allocation succeeded.
1523 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1525 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1528 Token->Message->Headers is NULL.
1529 Token->Message is NULL.
1530 Token->Message->Body is not NULL,
1531 Token->Message->BodyLength is non-zero, and
1532 Token->Message->Data is NULL, but a previous call to
1533 Response() has not been completed successfully.
1534 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1535 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1536 specified by response URL.
1541 IN EFI_HTTP_PROTOCOL
*This
,
1542 IN EFI_HTTP_TOKEN
*Token
1546 EFI_HTTP_MESSAGE
*HttpMsg
;
1547 HTTP_PROTOCOL
*HttpInstance
;
1548 HTTP_TOKEN_WRAP
*Wrap
;
1550 if ((This
== NULL
) || (Token
== NULL
)) {
1551 return EFI_INVALID_PARAMETER
;
1554 HttpMsg
= Token
->Message
;
1555 if (HttpMsg
== NULL
) {
1556 return EFI_INVALID_PARAMETER
;
1559 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1561 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1562 return EFI_NOT_STARTED
;
1566 // Check whether the token already existed.
1568 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1569 return EFI_ACCESS_DENIED
;
1572 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1574 return EFI_OUT_OF_RESOURCES
;
1577 Wrap
->HttpInstance
= HttpInstance
;
1578 Wrap
->HttpToken
= Token
;
1581 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1582 // receive the https response. A special TlsRxToken is used for receiving TLS
1583 // related messages. It should be a blocking response.
1585 if (!HttpInstance
->UseHttps
) {
1586 Status
= HttpCreateTcpRxEvent (Wrap
);
1587 if (EFI_ERROR (Status
)) {
1592 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1593 if (EFI_ERROR (Status
)) {
1598 // If already have pending RxTokens, return directly.
1600 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1604 return HttpResponseWorker (Wrap
);
1608 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1609 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1612 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1613 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1622 The Poll() function can be used by network drivers and applications to increase the
1623 rate that data packets are moved between the communication devices and the transmit
1626 In some systems, the periodic timer event in the managed network driver may not poll
1627 the underlying communications device fast enough to transmit and/or receive all data
1628 packets without missing incoming packets or dropping outgoing packets. Drivers and
1629 applications that are experiencing packet loss should try calling the Poll() function
1632 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1634 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1635 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1636 @retval EFI_INVALID_PARAMETER This is NULL.
1637 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1638 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1644 IN EFI_HTTP_PROTOCOL
*This
1648 HTTP_PROTOCOL
*HttpInstance
;
1651 return EFI_INVALID_PARAMETER
;
1654 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1656 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1657 return EFI_NOT_STARTED
;
1660 if (HttpInstance
->LocalAddressIsIPv6
) {
1661 if (HttpInstance
->Tcp6
== NULL
) {
1662 return EFI_NOT_STARTED
;
1664 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1666 if (HttpInstance
->Tcp4
== NULL
) {
1667 return EFI_NOT_STARTED
;
1669 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);