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
;
476 // Queue the HTTP token and return.
481 // Use existing TCP instance to transmit the packet.
488 // Need close existing TCP instance and create a new TCP instance for data transmit.
490 if (HttpInstance
->RemoteHost
!= NULL
) {
491 FreePool (HttpInstance
->RemoteHost
);
492 HttpInstance
->RemoteHost
= NULL
;
493 HttpInstance
->RemotePort
= 0;
501 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.
503 if (!HttpInstance
->LocalAddressIsIPv6
) {
504 Status
= NetLibAsciiStrToIp4 (HostName
, &HttpInstance
->RemoteAddr
);
506 Status
= HttpUrlGetIp6 (Url
, UrlParser
, &HttpInstance
->RemoteIpv6Addr
);
509 if (EFI_ERROR (Status
)) {
510 HostNameSize
= AsciiStrSize (HostName
);
511 HostNameStr
= AllocateZeroPool (HostNameSize
* sizeof (CHAR16
));
512 if (HostNameStr
== NULL
) {
513 Status
= EFI_OUT_OF_RESOURCES
;
517 AsciiStrToUnicodeStrS (HostName
, HostNameStr
, HostNameSize
);
518 if (!HttpInstance
->LocalAddressIsIPv6
) {
519 Status
= HttpDns4 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteAddr
);
521 Status
= HttpDns6 (HttpInstance
, HostNameStr
, &HttpInstance
->RemoteIpv6Addr
);
524 FreePool (HostNameStr
);
525 if (EFI_ERROR (Status
)) {
526 DEBUG ((EFI_D_ERROR
, "Error: Could not retrieve the host address from DNS server.\n"));
532 // Save the RemotePort and RemoteHost.
534 ASSERT (HttpInstance
->RemoteHost
== NULL
);
535 HttpInstance
->RemotePort
= RemotePort
;
536 HttpInstance
->RemoteHost
= HostName
;
542 // The request URL is different from previous calls to Request(), close existing TCP instance.
544 if (!HttpInstance
->LocalAddressIsIPv6
) {
545 ASSERT (HttpInstance
->Tcp4
!= NULL
);
547 ASSERT (HttpInstance
->Tcp6
!= NULL
);
550 if (HttpInstance
->UseHttps
&& !TlsConfigure
) {
551 Status
= TlsCloseSession (HttpInstance
);
552 if (EFI_ERROR (Status
)) {
556 TlsCloseTxRxEvent (HttpInstance
);
559 HttpCloseConnection (HttpInstance
);
560 EfiHttpCancel (This
, NULL
);
564 // Wrap the HTTP token in HTTP_TOKEN_WRAP
566 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
568 Status
= EFI_OUT_OF_RESOURCES
;
572 Wrap
->HttpToken
= Token
;
573 Wrap
->HttpInstance
= HttpInstance
;
574 if (Request
!= NULL
) {
575 Wrap
->TcpWrap
.Method
= Request
->Method
;
578 Status
= HttpInitSession (
581 Configure
|| ReConfigure
,
584 if (EFI_ERROR (Status
)) {
588 if (!Configure
&& !ReConfigure
&& !TlsConfigure
) {
590 // For the new HTTP token, create TX TCP token events.
592 Status
= HttpCreateTcpTxEvent (Wrap
);
593 if (EFI_ERROR (Status
)) {
599 // Create request message.
602 if (Url
!= NULL
&& *FileUrl
!= '/') {
604 // Convert the absolute-URI to the absolute-path
606 while (*FileUrl
!= ':') {
609 if ((*(FileUrl
+1) == '/') && (*(FileUrl
+2) == '/')) {
611 while (*FileUrl
!= '/') {
615 Status
= EFI_INVALID_PARAMETER
;
620 Status
= HttpGenRequestMessage (HttpMsg
, FileUrl
, &RequestMsg
, &RequestMsgSize
);
622 if (EFI_ERROR (Status
) || NULL
== RequestMsg
) {
626 ASSERT (RequestMsg
!= NULL
);
629 // Every request we insert a TxToken and a response call would remove the TxToken.
630 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a
631 // continuous request without a response call. So, in such cases, where Request
632 // structure is NULL, we would not insert a TxToken.
634 if (Request
!= NULL
) {
635 Status
= NetMapInsertTail (&HttpInstance
->TxTokens
, Token
, Wrap
);
636 if (EFI_ERROR (Status
)) {
642 // Transmit the request message.
644 Status
= HttpTransmitTcp (
650 if (EFI_ERROR (Status
)) {
656 if (HostName
!= NULL
) {
664 // We would have inserted a TxToken only if Request structure is not NULL.
665 // Hence check before we do a remove in this error case.
667 if (Request
!= NULL
) {
668 NetMapRemoveTail (&HttpInstance
->TxTokens
, NULL
);
672 if (RequestMsg
!= NULL
) {
673 FreePool (RequestMsg
);
677 if (HttpInstance
->UseHttps
) {
678 TlsCloseSession (HttpInstance
);
679 TlsCloseTxRxEvent (HttpInstance
);
683 HttpCloseConnection (HttpInstance
);
685 HttpCloseTcpConnCloseEvent (HttpInstance
);
686 if (NULL
!= Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
) {
687 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
);
688 Wrap
->TcpWrap
.Tx4Token
.CompletionToken
.Event
= NULL
;
690 if (NULL
!= Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
) {
691 gBS
->CloseEvent (Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
);
692 Wrap
->TcpWrap
.Tx6Token
.CompletionToken
.Event
= NULL
;
696 if (HostName
!= NULL
) {
702 if (UrlParser
!= NULL
) {
703 HttpUrlFreeParser (UrlParser
);
711 Cancel a user's Token.
713 @param[in] Map The HTTP instance's token queue.
714 @param[in] Item Object container for one HTTP token and token's wrap.
715 @param[in] Context The user's token to cancel.
717 @retval EFI_SUCCESS Continue to check the next Item.
718 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
725 IN NET_MAP_ITEM
*Item
,
729 EFI_HTTP_TOKEN
*Token
;
730 HTTP_TOKEN_WRAP
*Wrap
;
731 HTTP_PROTOCOL
*HttpInstance
;
733 Token
= (EFI_HTTP_TOKEN
*) Context
;
736 // Return EFI_SUCCESS to check the next item in the map if
737 // this one doesn't match.
739 if ((Token
!= NULL
) && (Token
!= Item
->Key
)) {
743 Wrap
= (HTTP_TOKEN_WRAP
*) Item
->Value
;
744 ASSERT (Wrap
!= NULL
);
745 HttpInstance
= Wrap
->HttpInstance
;
747 if (!HttpInstance
->LocalAddressIsIPv6
) {
748 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
750 // Cancle the Token before close its Event.
752 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &Wrap
->TcpWrap
.Rx4Token
.CompletionToken
);
755 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
760 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
762 // Cancle the Token before close its Event.
764 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &Wrap
->TcpWrap
.Rx6Token
.CompletionToken
);
767 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
774 // If only one item is to be cancel, return EFI_ABORTED to stop
775 // iterating the map any more.
785 Cancel the user's receive/transmit request. It is the worker function of
786 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
789 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
790 @param[in] Token The token to cancel. If NULL, all token will be
793 @retval EFI_SUCCESS The token is cancelled.
794 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
795 @retval Others Other error as indicated.
800 IN HTTP_PROTOCOL
*HttpInstance
,
801 IN EFI_HTTP_TOKEN
*Token
807 // First check the tokens queued by EfiHttpRequest().
809 Status
= NetMapIterate (&HttpInstance
->TxTokens
, HttpCancelTokens
, Token
);
810 if (EFI_ERROR (Status
)) {
812 if (Status
== EFI_ABORTED
) {
820 if (!HttpInstance
->UseHttps
) {
822 // Then check the tokens queued by EfiHttpResponse(), except for Https.
824 Status
= NetMapIterate (&HttpInstance
->RxTokens
, HttpCancelTokens
, Token
);
825 if (EFI_ERROR (Status
)) {
827 if (Status
== EFI_ABORTED
) {
830 return EFI_NOT_FOUND
;
837 if (!HttpInstance
->LocalAddressIsIPv6
) {
838 HttpInstance
->Tcp4
->Cancel (HttpInstance
->Tcp4
, &HttpInstance
->Tcp4TlsRxToken
.CompletionToken
);
840 HttpInstance
->Tcp6
->Cancel (HttpInstance
->Tcp6
, &HttpInstance
->Tcp6TlsRxToken
.CompletionToken
);
849 Abort an asynchronous HTTP request or response token.
851 The Cancel() function aborts a pending HTTP request or response transaction. If
852 Token is not NULL and the token is in transmit or receive queues when it is being
853 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
854 be signaled. If the token is not in one of the queues, which usually means that the
855 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
856 all asynchronous tokens issued by Request() or Response() will be aborted.
858 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
859 @param[in] Token Point to storage containing HTTP request or response
862 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
863 @retval EFI_INVALID_PARAMETER This is NULL.
864 @retval EFI_NOT_STARTED This instance hasn't been configured.
865 @retval EFI_NOT_FOUND The asynchronous request or response token is not
867 @retval EFI_UNSUPPORTED The implementation does not support this function.
873 IN EFI_HTTP_PROTOCOL
*This
,
874 IN EFI_HTTP_TOKEN
*Token
877 HTTP_PROTOCOL
*HttpInstance
;
880 return EFI_INVALID_PARAMETER
;
883 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
884 ASSERT (HttpInstance
!= NULL
);
886 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
887 return EFI_NOT_STARTED
;
890 return HttpCancel (HttpInstance
, Token
);
895 A callback function to intercept events during message parser.
897 This function will be invoked during HttpParseMessageBody() with various events type. An error
898 return status of the callback function will cause the HttpParseMessageBody() aborted.
900 @param[in] EventType Event type of this callback call.
901 @param[in] Data A pointer to data buffer.
902 @param[in] Length Length in bytes of the Data.
903 @param[in] Context Callback context set by HttpInitMsgParser().
905 @retval EFI_SUCCESS Continue to parser the message body.
910 HttpBodyParserCallback (
911 IN HTTP_BODY_PARSE_EVENT EventType
,
917 HTTP_TOKEN_WRAP
*Wrap
;
921 if (EventType
!= BodyParseEventOnComplete
) {
925 if (Data
== NULL
|| Length
!= 0 || Context
== NULL
) {
929 Wrap
= (HTTP_TOKEN_WRAP
*) Context
;
930 Body
= Wrap
->HttpToken
->Message
->Body
;
931 BodyLength
= Wrap
->HttpToken
->Message
->BodyLength
;
932 if (Data
< Body
+ BodyLength
) {
933 Wrap
->HttpInstance
->NextMsg
= Data
;
935 Wrap
->HttpInstance
->NextMsg
= NULL
;
940 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.
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
*) ValueInItem
,
1193 &HttpInstance
->MsgParser
1195 if (EFI_ERROR (Status
)) {
1200 // Check whether we received a complete HTTP message.
1202 if (HttpInstance
->CacheBody
!= NULL
) {
1203 Status
= HttpParseMessageBody (HttpInstance
->MsgParser
, HttpInstance
->CacheLen
, HttpInstance
->CacheBody
);
1204 if (EFI_ERROR (Status
)) {
1208 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1210 // Free the MsgParse since we already have a full HTTP message.
1212 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1213 HttpInstance
->MsgParser
= NULL
;
1218 if ((HttpMsg
->Body
== NULL
) || (HttpMsg
->BodyLength
== 0)) {
1219 Status
= EFI_SUCCESS
;
1225 // Receive the response body.
1230 // First check whether we cached some data.
1232 if (HttpInstance
->CacheBody
!= NULL
) {
1234 // Calculate the length of the cached data.
1236 if (HttpInstance
->NextMsg
!= NULL
) {
1238 // We have a cached HTTP message which includes a part of HTTP header of next message.
1240 BodyLen
= HttpInstance
->NextMsg
- (HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
);
1242 BodyLen
= HttpInstance
->CacheLen
- HttpInstance
->CacheOffset
;
1247 // We have some cached data. Just copy the data and return.
1249 if (HttpMsg
->BodyLength
< BodyLen
) {
1250 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, HttpMsg
->BodyLength
);
1251 HttpInstance
->CacheOffset
= HttpInstance
->CacheOffset
+ HttpMsg
->BodyLength
;
1254 // Copy all cached data out.
1256 CopyMem (HttpMsg
->Body
, HttpInstance
->CacheBody
+ HttpInstance
->CacheOffset
, BodyLen
);
1257 HttpInstance
->CacheOffset
= BodyLen
+ HttpInstance
->CacheOffset
;
1258 HttpMsg
->BodyLength
= BodyLen
;
1260 if (HttpInstance
->NextMsg
== NULL
) {
1262 // There is no HTTP header of next message. Just free the cache buffer.
1264 FreePool (HttpInstance
->CacheBody
);
1265 HttpInstance
->CacheBody
= NULL
;
1266 HttpInstance
->NextMsg
= NULL
;
1267 HttpInstance
->CacheOffset
= 0;
1271 // Return since we aready received required data.
1273 Status
= EFI_SUCCESS
;
1277 if (BodyLen
== 0 && HttpInstance
->MsgParser
== NULL
) {
1279 // We received a complete HTTP message, and we don't have more data to return to caller.
1281 HttpMsg
->BodyLength
= 0;
1282 Status
= EFI_SUCCESS
;
1287 ASSERT (HttpInstance
->MsgParser
!= NULL
);
1290 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1292 if (!HttpInstance
->UseHttps
) {
1293 Status
= HttpTcpReceiveBody (Wrap
, HttpMsg
);
1295 if (EFI_ERROR (Status
)) {
1300 if (HttpInstance
->TimeoutEvent
== NULL
) {
1302 // Create TimeoutEvent for response
1304 Status
= gBS
->CreateEvent (
1309 &HttpInstance
->TimeoutEvent
1311 if (EFI_ERROR (Status
)) {
1317 // Start the timer, and wait Timeout seconds to receive the body packet.
1319 Status
= gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerRelative
, HTTP_RESPONSE_TIMEOUT
* TICKS_PER_SECOND
);
1320 if (EFI_ERROR (Status
)) {
1324 Status
= HttpsReceive (HttpInstance
, &Fragment
, HttpInstance
->TimeoutEvent
);
1326 gBS
->SetTimer (HttpInstance
->TimeoutEvent
, TimerCancel
, 0);
1328 if (EFI_ERROR (Status
)) {
1333 // Check whether we receive a complete HTTP message.
1335 Status
= HttpParseMessageBody (
1336 HttpInstance
->MsgParser
,
1337 (UINTN
) Fragment
.Len
,
1338 (CHAR8
*) Fragment
.Bulk
1340 if (EFI_ERROR (Status
)) {
1344 if (HttpIsMessageComplete (HttpInstance
->MsgParser
)) {
1346 // Free the MsgParse since we already have a full HTTP message.
1348 HttpFreeMsgParser (HttpInstance
->MsgParser
);
1349 HttpInstance
->MsgParser
= NULL
;
1353 // We receive part of header of next HTTP msg.
1355 if (HttpInstance
->NextMsg
!= NULL
) {
1356 HttpMsg
->BodyLength
= MIN ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) Fragment
.Bulk
, HttpMsg
->BodyLength
);
1357 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1359 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1360 if (HttpInstance
->CacheLen
!= 0) {
1361 if (HttpInstance
->CacheBody
!= NULL
) {
1362 FreePool (HttpInstance
->CacheBody
);
1365 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1366 if (HttpInstance
->CacheBody
== NULL
) {
1367 Status
= EFI_OUT_OF_RESOURCES
;
1371 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1372 HttpInstance
->CacheOffset
= 0;
1374 HttpInstance
->NextMsg
= HttpInstance
->CacheBody
+ ((UINTN
) HttpInstance
->NextMsg
- (UINTN
) (Fragment
.Bulk
+ HttpMsg
->BodyLength
));
1377 HttpMsg
->BodyLength
= MIN (Fragment
.Len
, (UINT32
) HttpMsg
->BodyLength
);
1378 CopyMem (HttpMsg
->Body
, Fragment
.Bulk
, HttpMsg
->BodyLength
);
1379 HttpInstance
->CacheLen
= Fragment
.Len
- HttpMsg
->BodyLength
;
1380 if (HttpInstance
->CacheLen
!= 0) {
1381 if (HttpInstance
->CacheBody
!= NULL
) {
1382 FreePool (HttpInstance
->CacheBody
);
1385 HttpInstance
->CacheBody
= AllocateZeroPool (HttpInstance
->CacheLen
);
1386 if (HttpInstance
->CacheBody
== NULL
) {
1387 Status
= EFI_OUT_OF_RESOURCES
;
1391 CopyMem (HttpInstance
->CacheBody
, Fragment
.Bulk
+ HttpMsg
->BodyLength
, HttpInstance
->CacheLen
);
1392 HttpInstance
->CacheOffset
= 0;
1396 if (Fragment
.Bulk
!= NULL
) {
1397 FreePool (Fragment
.Bulk
);
1398 Fragment
.Bulk
= NULL
;
1407 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1409 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1412 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1413 Token
->Status
= EFI_HTTP_ERROR
;
1415 Token
->Status
= Status
;
1418 gBS
->SignalEvent (Token
->Event
);
1419 HttpCloseTcpRxEvent (Wrap
);
1424 if (ValueInItem
!= NULL
) {
1425 NetMapInsertHead (&HttpInstance
->TxTokens
, ValueInItem
->HttpToken
, ValueInItem
);
1429 Item
= NetMapFindKey (&Wrap
->HttpInstance
->RxTokens
, Wrap
->HttpToken
);
1431 NetMapRemoveItem (&Wrap
->HttpInstance
->RxTokens
, Item
, NULL
);
1434 if (!HttpInstance
->UseHttps
) {
1435 HttpTcpTokenCleanup (Wrap
);
1440 if (HttpHeaders
!= NULL
) {
1441 FreePool (HttpHeaders
);
1445 if (Fragment
.Bulk
!= NULL
) {
1446 FreePool (Fragment
.Bulk
);
1447 Fragment
.Bulk
= NULL
;
1450 if (HttpMsg
->Headers
!= NULL
) {
1451 FreePool (HttpMsg
->Headers
);
1452 HttpMsg
->Headers
= NULL
;
1455 if (HttpInstance
->CacheBody
!= NULL
) {
1456 FreePool (HttpInstance
->CacheBody
);
1457 HttpInstance
->CacheBody
= NULL
;
1460 if (HttpInstance
->StatusCode
>= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE
) {
1461 Token
->Status
= EFI_HTTP_ERROR
;
1463 Token
->Status
= Status
;
1466 gBS
->SignalEvent (Token
->Event
);
1474 The Response() function queues an HTTP response to this HTTP instance, similar to
1475 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,
1476 or if there is an error, Status in token will be updated and Event will be signaled.
1478 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1479 is received in the underlying TCP instance, the data will be parsed and Token will
1480 be populated with the response data. If the data received from the remote host
1481 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1482 (asynchronously) for more data to be sent from the remote host before signaling
1485 It is the responsibility of the caller to allocate a buffer for Body and specify the
1486 size in BodyLength. If the remote host provides a response that contains a content
1487 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1488 BodyLength will be updated with the amount of bytes received and copied to Body. This
1489 allows the client to download a large file in chunks instead of into one contiguous
1490 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1491 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1492 token to underlying TCP instance. If data arrives in the receive buffer, up to
1493 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1494 BodyLength with the amount of bytes received and copied to Body.
1496 If the HTTP driver does not have an open underlying TCP connection with the host
1497 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1498 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1499 an open TCP connection between client and host.
1501 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1502 @param[in] Token Pointer to storage containing HTTP response token.
1504 @retval EFI_SUCCESS Allocation succeeded.
1505 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1507 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1510 Token->Message->Headers is NULL.
1511 Token->Message is NULL.
1512 Token->Message->Body is not NULL,
1513 Token->Message->BodyLength is non-zero, and
1514 Token->Message->Data is NULL, but a previous call to
1515 Response() has not been completed successfully.
1516 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1517 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1518 specified by response URL.
1523 IN EFI_HTTP_PROTOCOL
*This
,
1524 IN EFI_HTTP_TOKEN
*Token
1528 EFI_HTTP_MESSAGE
*HttpMsg
;
1529 HTTP_PROTOCOL
*HttpInstance
;
1530 HTTP_TOKEN_WRAP
*Wrap
;
1532 if ((This
== NULL
) || (Token
== NULL
)) {
1533 return EFI_INVALID_PARAMETER
;
1536 HttpMsg
= Token
->Message
;
1537 if (HttpMsg
== NULL
) {
1538 return EFI_INVALID_PARAMETER
;
1541 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1542 ASSERT (HttpInstance
!= NULL
);
1544 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1545 return EFI_NOT_STARTED
;
1549 // Check whether the token already existed.
1551 if (EFI_ERROR (NetMapIterate (&HttpInstance
->RxTokens
, HttpTokenExist
, Token
))) {
1552 return EFI_ACCESS_DENIED
;
1555 Wrap
= AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP
));
1557 return EFI_OUT_OF_RESOURCES
;
1560 Wrap
->HttpInstance
= HttpInstance
;
1561 Wrap
->HttpToken
= Token
;
1564 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to
1565 // receive the https response. A special TlsRxToken is used for receiving TLS
1566 // related messages. It should be a blocking response.
1568 if (!HttpInstance
->UseHttps
) {
1569 Status
= HttpCreateTcpRxEvent (Wrap
);
1570 if (EFI_ERROR (Status
)) {
1575 Status
= NetMapInsertTail (&HttpInstance
->RxTokens
, Token
, Wrap
);
1576 if (EFI_ERROR (Status
)) {
1581 // If already have pending RxTokens, return directly.
1583 if (NetMapGetCount (&HttpInstance
->RxTokens
) > 1) {
1587 return HttpResponseWorker (Wrap
);
1591 if (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
!= NULL
) {
1592 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx4Token
.CompletionToken
.Event
);
1595 if (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
!= NULL
) {
1596 gBS
->CloseEvent (Wrap
->TcpWrap
.Rx6Token
.CompletionToken
.Event
);
1605 The Poll() function can be used by network drivers and applications to increase the
1606 rate that data packets are moved between the communication devices and the transmit
1609 In some systems, the periodic timer event in the managed network driver may not poll
1610 the underlying communications device fast enough to transmit and/or receive all data
1611 packets without missing incoming packets or dropping outgoing packets. Drivers and
1612 applications that are experiencing packet loss should try calling the Poll() function
1615 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1617 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1618 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1619 @retval EFI_INVALID_PARAMETER This is NULL.
1620 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1621 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1627 IN EFI_HTTP_PROTOCOL
*This
1631 HTTP_PROTOCOL
*HttpInstance
;
1634 return EFI_INVALID_PARAMETER
;
1637 HttpInstance
= HTTP_INSTANCE_FROM_PROTOCOL (This
);
1638 ASSERT (HttpInstance
!= NULL
);
1640 if (HttpInstance
->State
!= HTTP_STATE_TCP_CONNECTED
) {
1641 return EFI_NOT_STARTED
;
1644 if (HttpInstance
->LocalAddressIsIPv6
) {
1645 if (HttpInstance
->Tcp6
== NULL
) {
1646 return EFI_NOT_STARTED
;
1648 Status
= HttpInstance
->Tcp6
->Poll (HttpInstance
->Tcp6
);
1650 if (HttpInstance
->Tcp4
== NULL
) {
1651 return EFI_NOT_STARTED
;
1653 Status
= HttpInstance
->Tcp4
->Poll (HttpInstance
->Tcp4
);