2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HttpDriver.h"
19 EFI_HTTP_PROTOCOL mEfiHttpTemplate
= {
29 Returns the operational parameters for the current HTTP child instance.
31 The GetModeData() function is used to read the current mode data (operational
32 parameters) for this HTTP protocol instance.
34 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
35 @param[out] HttpConfigData Point to buffer for operational parameters of this
36 HTTP instance. It is the responsibility of the caller
37 to allocate the memory for HttpConfigData and
38 HttpConfigData->AccessPoint.IPv6Node/IPv4Node. In fact,
39 it is recommended to allocate sufficient memory to record
40 IPv6Node since it is big enough for all possibilities.
42 @retval EFI_SUCCESS Operation succeeded.
43 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
45 HttpConfigData is NULL.
46 HttpConfigData->AccessPoint.IPv4Node or
47 HttpConfigData->AccessPoint.IPv6Node is NULL.
48 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
54 IN EFI_HTTP_PROTOCOL
*This
,
55 OUT EFI_HTTP_CONFIG_DATA
*HttpConfigData
58 HTTP_PROTOCOL
*HttpInstance
;
61 // Check input parameters.
63 if ((This
== NULL
) || (HttpConfigData
== NULL
)) {
64 return EFI_INVALID_PARAMETER
;
67 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
68 ASSERT (HttpInstance
!= NULL
);
70 if ((HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
71 (HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)) {
72 return EFI_INVALID_PARAMETER
;
75 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
76 return EFI_NOT_STARTED
;
79 HttpConfigData
->HttpVersion
= HttpInstance
->HttpVersion
;
80 HttpConfigData
->TimeOutMillisec
= HttpInstance
->TimeOutMillisec
;
81 HttpConfigData
->LocalAddressIsIPv6
= HttpInstance
->LocalAddressIsIPv6
;
83 if (HttpInstance
->LocalAddressIsIPv6
) {
85 HttpConfigData
->AccessPoint
.IPv6Node
,
86 &HttpInstance
->Ipv6Node
,
87 sizeof (HttpInstance
->Ipv6Node
)
91 HttpConfigData
->AccessPoint
.IPv4Node
,
92 &HttpInstance
->IPv4Node
,
93 sizeof (HttpInstance
->IPv4Node
)
101 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
103 The Configure() function does the following:
104 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
105 timeout, local address, port, etc.
106 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
107 connections with remote hosts, canceling all asynchronous tokens, and flush request
108 and response buffers without informing the appropriate hosts.
110 No other EFI HTTP function can be executed by this instance until the Configure()
111 function is executed and returns successfully.
113 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
114 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
116 @retval EFI_SUCCESS Operation succeeded.
117 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
119 HttpConfigData->LocalAddressIsIPv6 is FALSE and
120 HttpConfigData->AccessPoint.IPv4Node is NULL.
121 HttpConfigData->LocalAddressIsIPv6 is TRUE and
122 HttpConfigData->AccessPoint.IPv6Node is NULL.
123 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
124 Configure() with NULL to reset it.
125 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
126 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
127 executing Configure().
128 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
129 in the implementation.
134 IN EFI_HTTP_PROTOCOL
*This
,
135 IN EFI_HTTP_CONFIG_DATA
*HttpConfigData OPTIONAL
138 HTTP_PROTOCOL
*HttpInstance
;
142 // Check input parameters.
145 (HttpConfigData
!= NULL
&&
146 ((HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv6Node
== NULL
) ||
147 (!HttpConfigData
->LocalAddressIsIPv6
&& HttpConfigData
->AccessPoint
.IPv4Node
== NULL
)))) {
148 return EFI_INVALID_PARAMETER
;
151 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
152 ASSERT (HttpInstance
!= NULL
&& HttpInstance
->Service
!= NULL
);
154 if (HttpConfigData
!= NULL
) {
156 if (HttpConfigData
->HttpVersion
>= HttpVersionUnsupported
) {
157 return EFI_UNSUPPORTED
;
161 // Now configure this HTTP instance.
163 if (HttpInstance
->State
!= HTTP_STATE_UNCONFIGED
) {
164 return EFI_ALREADY_STARTED
;
167 HttpInstance
->HttpVersion
= HttpConfigData
->HttpVersion
;
168 HttpInstance
->TimeOutMillisec
= HttpConfigData
->TimeOutMillisec
;
169 HttpInstance
->LocalAddressIsIPv6
= HttpConfigData
->LocalAddressIsIPv6
;
171 if (HttpConfigData
->LocalAddressIsIPv6
) {
173 &HttpInstance
->Ipv6Node
,
174 HttpConfigData
->AccessPoint
.IPv6Node
,
175 sizeof (HttpInstance
->Ipv6Node
)
179 &HttpInstance
->IPv4Node
,
180 HttpConfigData
->AccessPoint
.IPv4Node
,
181 sizeof (HttpInstance
->IPv4Node
)
188 Status
= HttpInitProtocol (HttpInstance
, HttpInstance
->LocalAddressIsIPv6
);
189 if (EFI_ERROR (Status
)) {
193 HttpInstance
->State
= HTTP_STATE_HTTP_CONFIGED
;
198 // Reset all the resources related to HttpInsance.
200 HttpCleanProtocol (HttpInstance
);
201 HttpInstance
->State
= HTTP_STATE_UNCONFIGED
;
208 The Request() function queues an HTTP request to this HTTP instance.
210 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
211 successfully, or if there is an error, Status in token will be updated and Event will
214 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
215 @param[in] Token Pointer to storage containing HTTP request token.
217 @retval EFI_SUCCESS Outgoing data was processed.
218 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
219 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
220 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
221 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
222 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
224 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
227 Token->Message is NULL.
228 Token->Message->Body is not NULL,
229 Token->Message->BodyLength is non-zero, and
230 Token->Message->Data is NULL, but a previous call to
231 Request()has not been completed successfully.
236 IN EFI_HTTP_PROTOCOL
*This
,
237 IN EFI_HTTP_TOKEN
*Token
240 EFI_HTTP_MESSAGE
*HttpMsg
;
241 EFI_HTTP_REQUEST_DATA
*Request
;
247 HTTP_PROTOCOL
*HttpInstance
;
250 BOOLEAN TlsConfigure
;
255 HTTP_TOKEN_WRAP
*Wrap
;
257 UINTN RequestMsgSize
;
258 EFI_HANDLE ImageHandle
;
271 TlsConfigure
= FALSE
;
273 if ((This
== NULL
) || (Token
== NULL
)) {
274 return EFI_INVALID_PARAMETER
;
277 HttpMsg
= Token
->Message
;
278 if (HttpMsg
== NULL
) {
279 return EFI_INVALID_PARAMETER
;
282 Request
= HttpMsg
->Data
.Request
;
285 // Only support GET, HEAD, PATCH, PUT and POST method in current implementation.
287 if ((Request
!= NULL
) && (Request
->Method
!= HttpMethodGet
) &&
288 (Request
->Method
!= HttpMethodHead
) && (Request
->Method
!= HttpMethodPut
) &&
289 (Request
->Method
!= HttpMethodPost
) && (Request
->Method
!= HttpMethodPatch
)) {
290 return EFI_UNSUPPORTED
;
293 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
294 ASSERT (HttpInstance
!= NULL
);
297 // Capture the method into HttpInstance.
299 if (Request
!= NULL
) {
300 HttpInstance
->Method
= Request
->Method
;
303 if (HttpInstance
->State
< HTTP_STATE_HTTP_CONFIGED
) {
304 return EFI_NOT_STARTED
;
307 if (Request
== NULL
) {
309 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)
311 if ((HttpInstance
->Method
!= HttpMethodPut
) &&
312 (HttpInstance
->Method
!= HttpMethodPost
) &&
313 (HttpInstance
->Method
!= HttpMethodPatch
)) {
314 return EFI_INVALID_PARAMETER
;
318 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!
320 if (HttpInstance
->State
< HTTP_STATE_TCP_CONFIGED
) {
321 return EFI_INVALID_PARAMETER
;
325 // We need to have the Message Body for sending the HTTP message across in these cases.
327 if (HttpMsg
->Body
== NULL
|| HttpMsg
->BodyLength
== 0) {
328 return EFI_INVALID_PARAMETER
;
332 // Use existing TCP instance to transmit the packet.
338 // Check whether the token already existed.
340 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTokenExist
, Token
))) {
341 return EFI_ACCESS_DENIED
;
345 // Parse the URI of the remote host.
347 Url
= HttpInstance
->Url
;
348 UrlLen
= StrLen (Request
->Url
) + 1;
349 if (UrlLen
> HTTP_URL_BUFFER_LEN
) {
350 Url
= AllocateZeroPool (UrlLen
);
352 return EFI_OUT_OF_RESOURCES
;
354 FreePool (HttpInstance
->Url
);
355 HttpInstance
->Url
= Url
;
359 UnicodeStrToAsciiStrS (Request
->Url
, Url
, UrlLen
);
362 // From the information in Url, the HTTP instance will
363 // be able to determine whether to use http or https.
365 HttpInstance
->UseHttps
= IsHttpsUrl (Url
);
368 // HTTP is disabled, return directly if the URI is not HTTPS.
370 if (!PcdGetBool (PcdAllowHttpConnections
) && !(HttpInstance
->UseHttps
)) {
372 DEBUG ((EFI_D_ERROR
, "EfiHttpRequest: HTTP is disabled.\n"));
374 return EFI_ACCESS_DENIED
;
378 // Check whether we need to create Tls child and open the TLS protocol.
380 if (HttpInstance
->UseHttps
&& HttpInstance
->TlsChildHandle
== NULL
) {
382 // Use TlsSb to create Tls child and open the TLS protocol.
384 if (HttpInstance
->LocalAddressIsIPv6
) {
385 ImageHandle
= HttpInstance
->Service
->Ip6DriverBindingHandle
;
387 ImageHandle
= HttpInstance
->Service
->Ip4DriverBindingHandle
;
390 HttpInstance
->TlsChildHandle
= TlsCreateChild (
392 &(HttpInstance
->TlsSb
),
393 &(HttpInstance
->Tls
),
394 &(HttpInstance
->TlsConfiguration
)
396 if (HttpInstance
->TlsChildHandle
== NULL
) {
397 return EFI_DEVICE_ERROR
;
404 Status
= HttpParseUrl (Url
, (UINT32
) AsciiStrLen (Url
), FALSE
, &UrlParser
);
405 if (EFI_ERROR (Status
)) {
410 Status
= HttpUrlGetHostName (Url
, UrlParser
, &HostName
);
411 if (EFI_ERROR (Status
)) {
415 Status
= HttpUrlGetPort (Url
, UrlParser
, &RemotePort
);
416 if (EFI_ERROR (Status
)) {
417 if (HttpInstance
->UseHttps
) {
418 RemotePort
= HTTPS_DEFAULT_PORT
;
420 RemotePort
= HTTP_DEFAULT_PORT
;
424 // If Configure is TRUE, it indicates the first time to call Request();
425 // If ReConfigure is TRUE, it indicates the request URL is not same
426 // with the previous call to Request();
431 if (HttpInstance
->RemoteHost
== NULL
) {
433 // Request() is called the first time.
437 if ((HttpInstance
->RemotePort
== RemotePort
) &&
438 (AsciiStrCmp (HttpInstance
->RemoteHost
, HostName
) == 0) &&
439 (!HttpInstance
->UseHttps
|| (HttpInstance
->UseHttps
&&
441 HttpInstance
->TlsSessionState
== EfiTlsSessionDataTransferring
))) {
443 // Host Name and port number of the request URL are the same with previous call to Request().
444 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.
445 // Check whether previous TCP packet sent out.
448 if (EFI_ERROR (NetMapIterate (&HttpInstance
->TxTokens
, HttpTcpNotReady
, NULL
))) {
450 // Wrap the HTTP token in HTTP_TOKEN_WRAP
452 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
454 Status
= EFI_OUT_OF_RESOURCES
;
458 Wrap
->HttpToken
= Token
;
459 Wrap
->HttpInstance
= HttpInstance
;
461 Status
= HttpCreateTcpTxEvent (Wrap
);
462 if (EFI_ERROR (Status
)) {
466 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
467 if (EFI_ERROR (Status
)) {
471 Wrap
->TcpWrap
.Method
= Request
->Method
;
475 HttpUrlFreeParser (UrlParser
);
478 // Queue the HTTP token and return.
483 // Use existing TCP instance to transmit the packet.
490 // Need close existing TCP instance and create a new TCP instance for data transmit.
492 if (HttpInstance
->RemoteHost
!= NULL
) {
493 FreePool (HttpInstance
->RemoteHost
);
494 HttpInstance
->RemoteHost
= NULL
;
495 HttpInstance
->RemotePort
= 0;
503 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
505 if (!HttpInstance
->LocalAddressIsIPv6
) {
506 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
508 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
511 if (EFI_ERROR (Status
)) {
512 HostNameSize
= AsciiStrSize (HostName
);
513 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
514 if (HostNameStr
== NULL
) {
515 Status
= EFI_OUT_OF_RESOURCES
;
519 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
520 if (!HttpInstance
->LocalAddressIsIPv6
) {
521 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
523 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
526 FreePool (HostNameStr
);
527 if (EFI_ERROR (Status
)) {
528 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
534 // Save the RemotePort and RemoteHost.
536 ASSERT (HttpInstance
->RemoteHost
== NULL
);
537 HttpInstance
->RemotePort
= RemotePort
;
538 HttpInstance
->RemoteHost
= HostName
;
544 // The request URL is different from previous calls to Request(), close existing TCP instance.
546 if (!HttpInstance
->LocalAddressIsIPv6
) {
547 ASSERT (HttpInstance
->Tcp4
!= NULL
);
549 ASSERT (HttpInstance
->Tcp6
!= NULL
);
552 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
553 Status
= TlsCloseSession (HttpInstance
);
554 if (EFI_ERROR (Status
)) {
558 TlsCloseTxRxEvent (HttpInstance
);
561 HttpCloseConnection (HttpInstance
);
562 EfiHttpCancel (This
, NULL
);
566 // Wrap the HTTP token in HTTP_TOKEN_WRAP
568 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
570 Status
= EFI_OUT_OF_RESOURCES
;
574 Wrap
->HttpToken
= Token
;
575 Wrap
->HttpInstance
= HttpInstance
;
576 if (Request
!= NULL
) {
577 Wrap
->TcpWrap
.Method
= Request
->Method
;
580 Status
= HttpInitSession (
583 Configure
|| ReConfigure
,
586 if (EFI_ERROR (Status
)) {
590 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
592 // For the new HTTP token, create TX TCP token events.
594 Status
= HttpCreateTcpTxEvent (Wrap
);
595 if (EFI_ERROR (Status
)) {
601 // Create request message.
604 if (Url
!= NULL
&& *FileUrl
!= '/') {
606 // Convert the absolute-URI to the absolute-path
608 while (*FileUrl
!= ':') {
611 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
613 while (*FileUrl
!= '/') {
617 Status
= EFI_INVALID_PARAMETER
;
622 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
624 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
628 ASSERT (RequestMsg
!= NULL
);
631 // Every request we insert a TxToken and a response call would remove the TxToken.
632 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
633 // continuous request without a response call. So, in such cases, where Request
634 // structure is NULL, we would not insert a TxToken.
636 if (Request
!= NULL
) {
637 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
638 if (EFI_ERROR (Status
)) {
644 // Transmit the request message.
646 Status
= HttpTransmitTcp (
652 if (EFI_ERROR (Status
)) {
658 if (HostName
!= NULL
) {
662 if (UrlParser
!= NULL
) {
663 HttpUrlFreeParser (UrlParser
);
670 // We would have inserted a TxToken only if Request structure is not NULL.
671 // Hence check before we do a remove in this error case.
673 if (Request
!= NULL
) {
674 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
678 if (RequestMsg
!= NULL
) {
679 FreePool (RequestMsg
);
683 if (HttpInstance
->UseHttps
) {
684 TlsCloseSession (HttpInstance
);
685 TlsCloseTxRxEvent (HttpInstance
);
689 HttpCloseConnection (HttpInstance
);
691 HttpCloseTcpConnCloseEvent (HttpInstance
);
692 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
693 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
694 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
696 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
697 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
698 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
702 if (HostName
!= NULL
) {
708 if (UrlParser
!= NULL
) {
709 HttpUrlFreeParser (UrlParser
);
717 Cancel a user's Token.
719 @param[in] Map The HTTP instance's token queue.
720 @param[in] Item Object container for one HTTP token and token's wrap.
721 @param[in] Context The user's token to cancel.
723 @retval EFI_SUCCESS Continue to check the next Item.
724 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
731 IN NET_MAP_ITEM
*Item
,
735 EFI_HTTP_TOKEN
*Token
;
736 HTTP_TOKEN_WRAP
*Wrap
;
737 HTTP_PROTOCOL
*HttpInstance
;
739 Token
= (EFI_HTTP_TOKEN
*) Context
;
742 // Return EFI_SUCCESS to check the next item in the map if
743 // this one doesn't match.
745 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
749 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
750 ASSERT (Wrap
!= NULL
);
751 HttpInstance
= Wrap
->HttpInstance
;
753 if (!HttpInstance
->LocalAddressIsIPv6
) {
754 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
756 // Cancle the Token before close its Event.
758 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
761 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
766 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
768 // Cancle the Token before close its Event.
770 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
773 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
780 // If only one item is to be cancel, return EFI_ABORTED to stop
781 // iterating the map any more.
791 Cancel the user's receive/transmit request. It is the worker function of
792 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
795 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
796 @param[in] Token The token to cancel. If NULL, all token will be
799 @retval EFI_SUCCESS The token is cancelled.
800 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
801 @retval Others Other error as indicated.
806 IN HTTP_PROTOCOL
*HttpInstance
,
807 IN EFI_HTTP_TOKEN
*Token
813 // First check the tokens queued by EfiHttpRequest().
815 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
816 if (EFI_ERROR (Status
)) {
818 if (Status
== EFI_ABORTED
) {
826 if (!HttpInstance
->UseHttps
) {
828 // Then check the tokens queued by EfiHttpResponse(), except for Https.
830 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
831 if (EFI_ERROR (Status
)) {
833 if (Status
== EFI_ABORTED
) {
836 return EFI_NOT_FOUND
;
843 if (!HttpInstance
->LocalAddressIsIPv6
) {
844 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
846 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
855 Abort an asynchronous HTTP request or response token.
857 The Cancel() function aborts a pending HTTP request or response transaction. If
858 Token is not NULL and the token is in transmit or receive queues when it is being
859 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
860 be signaled. If the token is not in one of the queues, which usually means that the
861 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
862 all asynchronous tokens issued by Request() or Response() will be aborted.
864 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
865 @param[in] Token Point to storage containing HTTP request or response
868 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
869 @retval EFI_INVALID_PARAMETER This is NULL.
870 @retval EFI_NOT_STARTED This instance hasn't been configured.
871 @retval EFI_NOT_FOUND The asynchronous request or response token is not
873 @retval EFI_UNSUPPORTED The implementation does not support this function.
879 IN EFI_HTTP_PROTOCOL
*This
,
880 IN EFI_HTTP_TOKEN
*Token
883 HTTP_PROTOCOL
*HttpInstance
;
886 return EFI_INVALID_PARAMETER
;
889 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
890 ASSERT (HttpInstance
!= NULL
);
892 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
893 return EFI_NOT_STARTED
;
896 return HttpCancel (HttpInstance
, Token
);
901 A callback function to intercept events during message parser.
903 This function will be invoked during HttpParseMessageBody() with various events type. An error
904 return status of the callback function will cause the HttpParseMessageBody() aborted.
906 @param[in] EventType Event type of this callback call.
907 @param[in] Data A pointer to data buffer.
908 @param[in] Length Length in bytes of the Data.
909 @param[in] Context Callback context set by HttpInitMsgParser().
911 @retval EFI_SUCCESS Continue to parser the message body.
916 HttpBodyParserCallback (
917 IN HTTP_BODY_PARSE_EVENT EventType
,
923 HTTP_TOKEN_WRAP
*Wrap
;
927 if (EventType
!= BodyParseEventOnComplete
) {
931 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
935 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
936 Body
= Wrap
->HttpToken
->Message
->Body
;
937 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
938 if (Data
< Body
+ BodyLength
) {
939 Wrap
->HttpInstance
->NextMsg
= Data
;
941 Wrap
->HttpInstance
->NextMsg
= NULL
;
946 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
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 opration 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
;
987 if (Wrap
== NULL
|| Wrap
->HttpInstance
== NULL
) {
988 return EFI_INVALID_PARAMETER
;
991 HttpInstance
= Wrap
->HttpInstance
;
992 Token
= Wrap
->HttpToken
;
993 HttpMsg
= Token
->Message
;
995 HttpInstance
->EndofHeader
= NULL
;
996 HttpInstance
->HttpHeaders
= NULL
;
997 HttpMsg
->Headers
= NULL
;
1004 Fragment
.Bulk
= NULL
;
1006 if (HttpMsg
->Data
.Response
!= NULL
) {
1008 // Check whether we have cached header from previous call.
1010 if ((HttpInstance
->CacheBody
!= NULL
) && (HttpInstance
->NextMsg
!= NULL
)) {
1012 // The data is stored at [NextMsg, CacheBody + CacheLen].
1014 HdrLen
= HttpInstance
->CacheBody
+ HttpInstance
->CacheLen
- HttpInstance
->NextMsg
;
1015 HttpHeaders
= AllocateZeroPool (HdrLen
);
1016 if (HttpHeaders
== NULL
) {
1017 Status
= EFI_OUT_OF_RESOURCES
;
1021 CopyMem (HttpHeaders
, HttpInstance
->NextMsg
, HdrLen
);
1022 FreePool (HttpInstance
->CacheBody
);
1023 HttpInstance
->CacheBody
= NULL
;
1024 HttpInstance
->NextMsg
= NULL
;
1025 HttpInstance
->CacheOffset
= 0;
1026 SizeofHeaders
= HdrLen
;
1027 BufferSize
= HttpInstance
->CacheLen
;
1030 // Check whether we cached the whole HTTP headers.
1032 EndofHeader
= AsciiStrStr (HttpHeaders
, HTTP_END_OF_HDR_STR
);
1035 HttpInstance
->EndofHeader
= &EndofHeader
;
1036 HttpInstance
->HttpHeaders
= &HttpHeaders
;
1039 if (HttpInstance
->TimeoutEvent
== NULL
) {
1041 // Create TimeoutEvent for response
1043 Status
= gBS
->CreateEvent (
1048 &HttpInstance
->TimeoutEvent
1050 if (EFI_ERROR (Status
)) {
1056 // Start the timer, and wait Timeout seconds to receive the header packet.
1058 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1059 if (EFI_ERROR (Status
)) {
1063 Status
= HttpTcpReceiveHeader (HttpInstance
, &SizeofHeaders
, &BufferSize
, HttpInstance
->TimeoutEvent
);
1065 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1067 if (EFI_ERROR (Status
)) {
1071 ASSERT (HttpHeaders
!= NULL
);
1074 // Cache the part of body.
1076 BodyLen
= BufferSize
- (EndofHeader
- HttpHeaders
);
1078 if (HttpInstance
->CacheBody
!= NULL
) {
1079 FreePool (HttpInstance
->CacheBody
);
1082 HttpInstance
->CacheBody
= AllocateZeroPool (BodyLen
);
1083 if (HttpInstance
->CacheBody
== NULL
) {
1084 Status
= EFI_OUT_OF_RESOURCES
;
1088 CopyMem (HttpInstance
->CacheBody
, EndofHeader
, BodyLen
);
1089 HttpInstance
->CacheLen
= BodyLen
;
1093 // Search for Status Code.
1095 StatusCodeStr
= HttpHeaders
+ AsciiStrLen (HTTP_VERSION_STR
) + 1;
1096 if (StatusCodeStr
== NULL
) {
1097 Status
= EFI_NOT_READY
;
1101 StatusCode
= AsciiStrDecimalToUintn (StatusCodeStr
);
1104 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
1106 Tmp
= AsciiStrStr (HttpHeaders
, HTTP_CRLF_STR
);
1108 Status
= EFI_NOT_READY
;
1113 // We could have response with just a HTTP message and no headers. For Example,
1114 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse
1115 // method. A "\r\n" following Tmp string again would indicate an end. Compare and
1116 // set SizeofHeaders to 0.
1118 Tmp
= Tmp
+ AsciiStrLen (HTTP_CRLF_STR
);
1119 if (CompareMem (Tmp
, HTTP_CRLF_STR
, AsciiStrLen (HTTP_CRLF_STR
)) == 0) {
1122 SizeofHeaders
= SizeofHeaders
- (Tmp
- HttpHeaders
);
1125 HttpMsg
->Data
.Response
->StatusCode
= HttpMappingToStatusCode (StatusCode
);
1126 HttpInstance
->StatusCode
= StatusCode
;
1128 Status
= EFI_NOT_READY
;
1132 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
1133 // continuous request without a response call. So, we would not do an insert of
1134 // TxToken. After we have sent the complete file, we will call a response to get
1135 // a final response from server. In such a case, we would not have any TxTokens.
1136 // Hence, check that case before doing a NetMapRemoveHead.
1138 if (!NetMapIsEmpty (&HttpInstance
->TxTokens
)) {
1139 NetMapRemoveHead (&HttpInstance
->TxTokens
, (VOID
**) &ValueInItem
);
1140 if (ValueInItem
== NULL
) {
1145 // The first Tx Token not transmitted yet, insert back and return error.
1147 if (!ValueInItem
->TcpWrap
.IsTxDone
) {
1152 if (SizeofHeaders
!= 0) {
1153 HeaderTmp
= AllocateZeroPool (SizeofHeaders
);
1154 if (HeaderTmp
== NULL
) {
1155 Status
= EFI_OUT_OF_RESOURCES
;
1159 CopyMem (HeaderTmp
, Tmp
, SizeofHeaders
);
1160 FreePool (HttpHeaders
);
1161 HttpHeaders
= HeaderTmp
;
1164 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
1166 if (mHttpUtilities
== NULL
) {
1167 Status
= EFI_NOT_READY
;
1172 // Parse the HTTP header into array of key/value pairs.
1174 Status
= mHttpUtilities
->Parse (
1179 &HttpMsg
->HeaderCount
1181 if (EFI_ERROR (Status
)) {
1185 FreePool (HttpHeaders
);
1190 // Init message-body parser by header information.
1192 Status
= HttpInitMsgParser (
1193 HttpInstance
->Method
,
1194 HttpMsg
->Data
.Response
->StatusCode
,
1195 HttpMsg
->HeaderCount
,
1197 HttpBodyParserCallback
,
1198 (VOID
*) ValueInItem
,
1199 &HttpInstance
->MsgParser
1201 if (EFI_ERROR (Status
)) {
1206 // Check whether we received a complete HTTP message.
1208 if (HttpInstance
->CacheBody
!= NULL
) {
1209 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1210 if (EFI_ERROR (Status
)) {
1214 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1216 // Free the MsgParse since we already have a full HTTP message.
1218 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1219 HttpInstance
->MsgParser
= NULL
;
1224 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1225 Status
= EFI_SUCCESS
;
1231 // Receive the response body.
1236 // First check whether we cached some data.
1238 if (HttpInstance
->CacheBody
!= NULL
) {
1240 // Calculate the length of the cached data.
1242 if (HttpInstance
->NextMsg
!= NULL
) {
1244 // We have a cached HTTP message which includes a part of HTTP header of next message.
1246 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1248 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1253 // We have some cached data. Just copy the data and return.
1255 if (HttpMsg
->BodyLength
< BodyLen
) {
1256 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1257 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1260 // Copy all cached data out.
1262 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1263 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1264 HttpMsg
->BodyLength
= BodyLen
;
1266 if (HttpInstance
->NextMsg
== NULL
) {
1268 // There is no HTTP header of next message. Just free the cache buffer.
1270 FreePool (HttpInstance
->CacheBody
);
1271 HttpInstance
->CacheBody
= NULL
;
1272 HttpInstance
->NextMsg
= NULL
;
1273 HttpInstance
->CacheOffset
= 0;
1277 // Return since we aready received required data.
1279 Status
= EFI_SUCCESS
;
1283 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1285 // We received a complete HTTP message, and we don't have more data to return to caller.
1287 HttpMsg
->BodyLength
= 0;
1288 Status
= EFI_SUCCESS
;
1293 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1296 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1298 if (!HttpInstance
->UseHttps
) {
1299 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1301 if (EFI_ERROR (Status
)) {
1306 if (HttpInstance
->TimeoutEvent
== NULL
) {
1308 // Create TimeoutEvent for response
1310 Status
= gBS
->CreateEvent (
1315 &HttpInstance
->TimeoutEvent
1317 if (EFI_ERROR (Status
)) {
1323 // Start the timer, and wait Timeout seconds to receive the body packet.
1325 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1326 if (EFI_ERROR (Status
)) {
1330 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1332 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1334 if (EFI_ERROR (Status
)) {
1339 // Check whether we receive a complete HTTP message.
1341 Status
= HttpParseMessageBody (
1342 HttpInstance
->MsgParser
,
1343 (UINTN
) Fragment
.Len
,
1344 (CHAR8
*) Fragment
.Bulk
1346 if (EFI_ERROR (Status
)) {
1350 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1352 // Free the MsgParse since we already have a full HTTP message.
1354 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1355 HttpInstance
->MsgParser
= NULL
;
1359 // We receive part of header of next HTTP msg.
1361 if (HttpInstance
->NextMsg
!= NULL
) {
1362 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1363 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1365 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1366 if (HttpInstance
->CacheLen
!= 0) {
1367 if (HttpInstance
->CacheBody
!= NULL
) {
1368 FreePool (HttpInstance
->CacheBody
);
1371 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1372 if (HttpInstance
->CacheBody
== NULL
) {
1373 Status
= EFI_OUT_OF_RESOURCES
;
1377 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1378 HttpInstance
->CacheOffset
= 0;
1380 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1383 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1384 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1385 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1386 if (HttpInstance
->CacheLen
!= 0) {
1387 if (HttpInstance
->CacheBody
!= NULL
) {
1388 FreePool (HttpInstance
->CacheBody
);
1391 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1392 if (HttpInstance
->CacheBody
== NULL
) {
1393 Status
= EFI_OUT_OF_RESOURCES
;
1397 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1398 HttpInstance
->CacheOffset
= 0;
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
);
1548 ASSERT (HttpInstance
!= NULL
);
1550 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1551 return EFI_NOT_STARTED
;
1555 // Check whether the token already existed.
1557 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1558 return EFI_ACCESS_DENIED
;
1561 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1563 return EFI_OUT_OF_RESOURCES
;
1566 Wrap
->HttpInstance
= HttpInstance
;
1567 Wrap
->HttpToken
= Token
;
1570 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1571 // receive the https response. A special TlsRxToken is used for receiving TLS
1572 // related messages. It should be a blocking response.
1574 if (!HttpInstance
->UseHttps
) {
1575 Status
= HttpCreateTcpRxEvent (Wrap
);
1576 if (EFI_ERROR (Status
)) {
1581 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1582 if (EFI_ERROR (Status
)) {
1587 // If already have pending RxTokens, return directly.
1589 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1593 return HttpResponseWorker (Wrap
);
1597 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1598 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1601 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1602 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1611 The Poll() function can be used by network drivers and applications to increase the
1612 rate that data packets are moved between the communication devices and the transmit
1615 In some systems, the periodic timer event in the managed network driver may not poll
1616 the underlying communications device fast enough to transmit and/or receive all data
1617 packets without missing incoming packets or dropping outgoing packets. Drivers and
1618 applications that are experiencing packet loss should try calling the Poll() function
1621 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1623 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1624 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1625 @retval EFI_INVALID_PARAMETER This is NULL.
1626 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1627 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1633 IN EFI_HTTP_PROTOCOL
*This
1637 HTTP_PROTOCOL
*HttpInstance
;
1640 return EFI_INVALID_PARAMETER
;
1643 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1644 ASSERT (HttpInstance
!= NULL
);
1646 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1647 return EFI_NOT_STARTED
;
1650 if (HttpInstance
->LocalAddressIsIPv6
) {
1651 if (HttpInstance
->Tcp6
== NULL
) {
1652 return EFI_NOT_STARTED
;
1654 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1656 if (HttpInstance
->Tcp4
== NULL
) {
1657 return EFI_NOT_STARTED
;
1659 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);