]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpDxe/HttpImpl.c
76c95b2bb66a3be299c56a321770168493ec939e
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
1 /** @file
2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "HttpDriver.h"
17
18 EFI_HTTP_PROTOCOL mEfiHttpTemplate = {
19 EfiHttpGetModeData,
20 EfiHttpConfigure,
21 EfiHttpRequest,
22 EfiHttpCancel,
23 EfiHttpResponse,
24 EfiHttpPoll
25 };
26
27 /**
28 Returns the operational parameters for the current HTTP child instance.
29
30 The GetModeData() function is used to read the current mode data (operational
31 parameters) for this HTTP protocol instance.
32
33 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
34 @param[out] HttpConfigData Point to buffer for operational parameters of this
35 HTTP instance.
36
37 @retval EFI_SUCCESS Operation succeeded.
38 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
39 This is NULL.
40 HttpConfigData is NULL.
41 HttpConfigData->AccessPoint is NULL.
42 @retval EFI_NOT_STARTED The HTTP instance is not configured.
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 EfiHttpGetModeData (
48 IN EFI_HTTP_PROTOCOL *This,
49 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData
50 )
51 {
52 HTTP_PROTOCOL *HttpInstance;
53
54 if ((This == NULL) || (HttpConfigData == NULL)) {
55 return EFI_INVALID_PARAMETER;
56 }
57
58 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
59 ASSERT (HttpInstance != NULL);
60
61 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {
62 return EFI_NOT_STARTED;
63 }
64
65 if (HttpConfigData->AccessPoint.IPv4Node == NULL) {
66 return EFI_INVALID_PARAMETER;
67 }
68
69 HttpConfigData->HttpVersion = HttpInstance->HttpVersion;
70 HttpConfigData->TimeOutMillisec = HttpInstance->TimeOutMillisec;
71 HttpConfigData->LocalAddressIsIPv6 = HttpInstance->LocalAddressIsIPv6;
72
73 CopyMem (
74 HttpConfigData->AccessPoint.IPv4Node,
75 &HttpInstance->IPv4Node,
76 sizeof (HttpInstance->IPv4Node)
77 );
78
79 return EFI_SUCCESS;
80 }
81
82 /**
83 Initialize or brutally reset the operational parameters for this EFI HTTP instance.
84
85 The Configure() function does the following:
86 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring
87 timeout, local address, port, etc.
88 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active
89 connections with remote hosts, canceling all asynchronous tokens, and flush request
90 and response buffers without informing the appropriate hosts.
91
92 Except for GetModeData() and Configure(), No other EFI HTTP function can be executed
93 by this instance until the Configure() function is executed and returns successfully.
94
95 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
96 @param[in] HttpConfigData Pointer to the configure data to configure the instance.
97
98 @retval EFI_SUCCESS Operation succeeded.
99 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
100 This is NULL.
101 HttpConfigData->LocalAddressIsIPv6 is FALSE and
102 HttpConfigData->IPv4Node is NULL.
103 HttpConfigData->LocalAddressIsIPv6 is TRUE and
104 HttpConfigData->IPv6Node is NULL.
105 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling
106 Configure() with NULL to reset it.
107 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
108 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when
109 executing Configure().
110 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported
111 in the implementation.
112 **/
113 EFI_STATUS
114 EFIAPI
115 EfiHttpConfigure (
116 IN EFI_HTTP_PROTOCOL *This,
117 IN EFI_HTTP_CONFIG_DATA *HttpConfigData
118 )
119 {
120 HTTP_PROTOCOL *HttpInstance;
121 EFI_STATUS Status;
122
123 if (This == NULL) {
124 return EFI_INVALID_PARAMETER;
125 }
126
127 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
128 ASSERT (HttpInstance != NULL && HttpInstance->Service != NULL);
129
130 if (HttpConfigData != NULL) {
131 //
132 // Check input parameters.
133 //
134 if (HttpConfigData->LocalAddressIsIPv6) {
135 if (HttpConfigData->AccessPoint.IPv6Node == NULL) {
136 return EFI_INVALID_PARAMETER;
137 }
138 } else {
139 if (HttpConfigData->AccessPoint.IPv4Node == NULL) {
140 return EFI_INVALID_PARAMETER;
141 }
142 }
143 //
144 // Now configure this HTTP instance.
145 //
146 if (HttpInstance->State != HTTP_STATE_UNCONFIGED) {
147 return EFI_ALREADY_STARTED;
148 }
149
150 HttpInstance->HttpVersion = HttpConfigData->HttpVersion;
151 HttpInstance->TimeOutMillisec = HttpConfigData->TimeOutMillisec;
152 HttpInstance->LocalAddressIsIPv6 = HttpConfigData->LocalAddressIsIPv6;
153
154 if (HttpConfigData->LocalAddressIsIPv6) {
155 return EFI_UNSUPPORTED;
156 } else {
157 CopyMem (
158 &HttpInstance->IPv4Node,
159 HttpConfigData->AccessPoint.IPv4Node,
160 sizeof (HttpInstance->IPv4Node)
161 );
162
163 HttpInstance->State = HTTP_STATE_HTTP_CONFIGED;
164 return EFI_SUCCESS;
165 }
166
167 } else {
168 if (HttpInstance->LocalAddressIsIPv6) {
169 return EFI_UNSUPPORTED;
170 } else {
171 HttpCleanProtocol (HttpInstance);
172 Status = HttpInitProtocol (HttpInstance->Service, HttpInstance);
173 if (EFI_ERROR (Status)) {
174 return Status;
175 }
176
177 HttpInstance->State = HTTP_STATE_UNCONFIGED;
178 return EFI_SUCCESS;
179 }
180 }
181 }
182
183
184 /**
185 The Request() function queues an HTTP request to this HTTP instance.
186
187 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent
188 successfully, or if there is an error, Status in token will be updated and Event will
189 be signaled.
190
191 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
192 @param[in] Token Pointer to storage containing HTTP request token.
193
194 @retval EFI_SUCCESS Outgoing data was processed.
195 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
196 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
197 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.
198 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
199 @retval EFI_UNSUPPORTED The HTTP method is not supported in current
200 implementation.
201 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
202 This is NULL.
203 Token->Message is NULL.
204 Token->Message->Body is not NULL,
205 Token->Message->BodyLength is non-zero, and
206 Token->Message->Data is NULL, but a previous call to
207 Request()has not been completed successfully.
208 **/
209 EFI_STATUS
210 EFIAPI
211 EfiHttpRequest (
212 IN EFI_HTTP_PROTOCOL *This,
213 IN EFI_HTTP_TOKEN *Token
214 )
215 {
216 EFI_HTTP_MESSAGE *HttpMsg;
217 EFI_HTTP_REQUEST_DATA *Request;
218 VOID *UrlParser;
219 EFI_STATUS Status;
220 CHAR8 *HostName;
221 UINT16 RemotePort;
222 HTTP_PROTOCOL *HttpInstance;
223 BOOLEAN Configure;
224 BOOLEAN ReConfigure;
225 CHAR8 *RequestStr;
226 CHAR8 *Url;
227 UINTN UrlLen;
228 CHAR16 *HostNameStr;
229 HTTP_TOKEN_WRAP *Wrap;
230 HTTP_TCP_TOKEN_WRAP *TcpWrap;
231 CHAR8 *FileUrl;
232
233 if ((This == NULL) || (Token == NULL)) {
234 return EFI_INVALID_PARAMETER;
235 }
236
237 HttpMsg = Token->Message;
238 if ((HttpMsg == NULL) || (HttpMsg->Headers == NULL)) {
239 return EFI_INVALID_PARAMETER;
240 }
241
242 //
243 // Current implementation does not support POST/PUT method.
244 // If future version supports these two methods, Request could be NULL for a special case that to send large amounts
245 // of data. For this case, the implementation need check whether previous call to Request() has been completed or not.
246 //
247 //
248 Request = HttpMsg->Data.Request;
249 if ((Request == NULL) || (Request->Url == NULL)) {
250 return EFI_INVALID_PARAMETER;
251 }
252
253 //
254 // Only support GET and HEAD method in current implementation.
255 //
256 if ((Request->Method != HttpMethodGet) && (Request->Method != HttpMethodHead)) {
257 return EFI_UNSUPPORTED;
258 }
259
260 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
261 ASSERT (HttpInstance != NULL);
262
263 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {
264 return EFI_NOT_STARTED;
265 }
266
267 if (HttpInstance->LocalAddressIsIPv6) {
268 return EFI_UNSUPPORTED;
269 }
270
271 //
272 // Check whether the token already existed.
273 //
274 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTokenExist, Token))) {
275 return EFI_ACCESS_DENIED;
276 }
277
278 HostName = NULL;
279 Wrap = NULL;
280 HostNameStr = NULL;
281 TcpWrap = NULL;
282
283 //
284 // Parse the URI of the remote host.
285 //
286 Url = HttpInstance->Url;
287 UrlLen = StrLen (Request->Url) + 1;
288 if (UrlLen > HTTP_URL_BUFFER_LEN) {
289 Url = AllocateZeroPool (UrlLen);
290 if (Url == NULL) {
291 return EFI_OUT_OF_RESOURCES;
292 }
293 FreePool (HttpInstance->Url);
294 HttpInstance->Url = Url;
295 }
296
297 UnicodeStrToAsciiStr (Request->Url, Url);
298 UrlParser = NULL;
299 Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser);
300 if (EFI_ERROR (Status)) {
301 goto Error1;
302 }
303
304 RequestStr = NULL;
305 HostName = NULL;
306 Status = HttpUrlGetHostName (Url, UrlParser, &HostName);
307 if (EFI_ERROR (Status)) {
308 goto Error1;
309 }
310
311 Status = HttpUrlGetPort (Url, UrlParser, &RemotePort);
312 if (EFI_ERROR (Status)) {
313 RemotePort = HTTP_DEFAULT_PORT;
314 }
315
316 Configure = TRUE;
317 ReConfigure = TRUE;
318
319 if (HttpInstance->RemoteHost == NULL && HttpInstance->RemotePort == 0) {
320 //
321 // Request() is called the first time.
322 //
323 ReConfigure = FALSE;
324 } else {
325 if ((HttpInstance->RemotePort == RemotePort) &&
326 (AsciiStrCmp (HttpInstance->RemoteHost, HostName) == 0)) {
327 //
328 // Host Name and port number of the request URL are the same with previous call to Request().
329 // Check whether previous TCP packet sent out.
330 //
331 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTcpNotReady, NULL))) {
332 //
333 // Wrap the HTTP token in HTTP_TOKEN_WRAP
334 //
335 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));
336 if (Wrap == NULL) {
337 Status = EFI_OUT_OF_RESOURCES;
338 goto Error1;
339 }
340
341 Wrap->HttpToken = Token;
342 Wrap->HttpInstance = HttpInstance;
343
344 Status = HttpCreateTcp4TxEvent (Wrap);
345 if (EFI_ERROR (Status)) {
346 goto Error1;
347 }
348
349 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);
350 if (EFI_ERROR (Status)) {
351 goto Error1;
352 }
353
354 Wrap->TcpWrap.Method = Request->Method;
355
356 FreePool (HostName);
357
358 //
359 // Queue the HTTP token and return.
360 //
361 return EFI_SUCCESS;
362 } else {
363 //
364 // Use existing TCP instance to transmit the packet.
365 //
366 Configure = FALSE;
367 ReConfigure = FALSE;
368 }
369 } else {
370 //
371 // Need close existing TCP instance and create a new TCP instance for data transmit.
372 //
373 if (HttpInstance->RemoteHost != NULL) {
374 FreePool (HttpInstance->RemoteHost);
375 HttpInstance->RemoteHost = NULL;
376 }
377 }
378 }
379
380 if (Configure) {
381 //
382 // Parse Url for IPv4 address, if failed, perform DNS resolution.
383 //
384 Status = NetLibAsciiStrToIp4 (HostName, &HttpInstance->RemoteAddr);
385 if (EFI_ERROR (Status)) {
386 HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (UINT16));
387 if (HostNameStr == NULL) {
388 Status = EFI_OUT_OF_RESOURCES;
389 goto Error1;
390 }
391
392 AsciiStrToUnicodeStr (HostName, HostNameStr);
393 Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr);
394 FreePool (HostNameStr);
395 if (EFI_ERROR (Status)) {
396 goto Error1;
397 }
398 }
399
400 //
401 // Save the RemotePort and RemoteHost.
402 //
403 ASSERT (HttpInstance->RemoteHost == NULL);
404 HttpInstance->RemotePort = RemotePort;
405 HttpInstance->RemoteHost = HostName;
406 HostName = NULL;
407 }
408
409 if (ReConfigure) {
410 //
411 // The request URL is different from previous calls to Request(), close existing TCP instance.
412 //
413 ASSERT (HttpInstance->Tcp4 != NULL);
414 HttpCloseConnection (HttpInstance);
415 EfiHttpCancel (This, NULL);
416 }
417
418 //
419 // Wrap the HTTP token in HTTP_TOKEN_WRAP
420 //
421 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));
422 if (Wrap == NULL) {
423 Status = EFI_OUT_OF_RESOURCES;
424 goto Error1;
425 }
426
427 Wrap->HttpToken = Token;
428 Wrap->HttpInstance = HttpInstance;
429 Wrap->TcpWrap.Method = Request->Method;
430
431 if (Configure) {
432 //
433 // Configure TCP instance.
434 //
435 Status = HttpConfigureTcp4 (HttpInstance, Wrap);
436 if (EFI_ERROR (Status)) {
437 goto Error1;
438 }
439 //
440 // Connect TCP.
441 //
442 Status = HttpConnectTcp4 (HttpInstance);
443 if (EFI_ERROR (Status)) {
444 goto Error2;
445 }
446 } else {
447 //
448 // For the new HTTP token, create TX TCP token events.
449 //
450 Status = HttpCreateTcp4TxEvent (Wrap);
451 if (EFI_ERROR (Status)) {
452 goto Error1;
453 }
454 }
455
456 //
457 // Create request message.
458 //
459 FileUrl = Url;
460 if (*FileUrl != '/') {
461 //
462 // Convert the absolute-URI to the absolute-path
463 //
464 while (*FileUrl != ':') {
465 FileUrl++;
466 }
467 if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {
468 FileUrl += 3;
469 while (*FileUrl != '/') {
470 FileUrl++;
471 }
472 } else {
473 Status = EFI_INVALID_PARAMETER;
474 goto Error3;
475 }
476 }
477 RequestStr = HttpGenRequestString (HttpInstance, HttpMsg, FileUrl);
478 if (RequestStr == NULL) {
479 Status = EFI_OUT_OF_RESOURCES;
480 goto Error3;
481 }
482
483 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);
484 if (EFI_ERROR (Status)) {
485 goto Error4;
486 }
487
488 if (HostName != NULL) {
489 FreePool (HostName);
490 }
491
492 //
493 // Transmit the request message.
494 //
495 Status = HttpTransmitTcp4 (
496 HttpInstance,
497 Wrap,
498 (UINT8*) RequestStr,
499 AsciiStrLen (RequestStr)
500 );
501 if (EFI_ERROR (Status)) {
502 goto Error5;
503 }
504
505 DispatchDpc ();
506
507 return EFI_SUCCESS;
508
509 Error5:
510 NetMapRemoveTail (&HttpInstance->TxTokens, NULL);
511
512 Error4:
513 if (RequestStr != NULL) {
514 FreePool (RequestStr);
515 }
516
517 Error3:
518 HttpCloseConnection (HttpInstance);
519
520
521 Error2:
522 HttpCloseTcp4ConnCloseEvent (HttpInstance);
523 if (NULL != Wrap->TcpWrap.TxToken.CompletionToken.Event) {
524 gBS->CloseEvent (Wrap->TcpWrap.TxToken.CompletionToken.Event);
525 Wrap->TcpWrap.TxToken.CompletionToken.Event = NULL;
526 }
527
528 Error1:
529 if (HostName != NULL) {
530 FreePool (HostName);
531 }
532 if (Wrap != NULL) {
533 FreePool (Wrap);
534 }
535 if (UrlParser!= NULL) {
536 HttpUrlFreeParser (UrlParser);
537 }
538
539 return Status;
540
541 }
542
543 /**
544 Cancel a TxToken or RxToken.
545
546 @param[in] Map The HTTP instance's token queue.
547 @param[in] Item Object container for one HTTP token and token's wrap.
548 @param[in] Context The user's token to cancel.
549
550 @retval EFI_SUCCESS Continue to check the next Item.
551 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
552
553 **/
554 EFI_STATUS
555 EFIAPI
556 HttpCancelTokens (
557 IN NET_MAP *Map,
558 IN NET_MAP_ITEM *Item,
559 IN VOID *Context
560 )
561 {
562
563 EFI_HTTP_TOKEN *Token;
564 HTTP_TOKEN_WRAP *Wrap;
565
566 Token = (EFI_HTTP_TOKEN *) Context;
567
568 //
569 // Return EFI_SUCCESS to check the next item in the map if
570 // this one doesn't match.
571 //
572 if ((Token != NULL) && (Token != Item->Key)) {
573 return EFI_SUCCESS;
574 }
575
576 Wrap = (HTTP_TOKEN_WRAP *) Item->Value;
577 ASSERT (Wrap != NULL);
578
579 //
580 // Free resources.
581 //
582 NetMapRemoveItem (Map, Item, NULL);
583
584 if (Wrap->TcpWrap.TxToken.CompletionToken.Event != NULL) {
585 gBS->CloseEvent (Wrap->TcpWrap.TxToken.CompletionToken.Event);
586 }
587
588 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
589 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
590 }
591
592 if (Wrap->TcpWrap.RxToken.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
593 FreePool (Wrap->TcpWrap.RxToken.Packet.RxData->FragmentTable[0].FragmentBuffer);
594 }
595
596 FreePool (Wrap);
597
598 //
599 // If only one item is to be cancel, return EFI_ABORTED to stop
600 // iterating the map any more.
601 //
602 if (Token != NULL) {
603 return EFI_ABORTED;
604 }
605
606 return EFI_SUCCESS;
607 }
608
609 /**
610 Cancel the user's receive/transmit request. It is the worker function of
611 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
612 token.
613
614 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
615 @param[in] Token The token to cancel. If NULL, all token will be
616 cancelled.
617
618 @retval EFI_SUCCESS The token is cancelled.
619 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
620 @retval Others Other error as indicated.
621
622 **/
623 EFI_STATUS
624 HttpCancel (
625 IN HTTP_PROTOCOL *HttpInstance,
626 IN EFI_HTTP_TOKEN *Token
627 )
628 {
629 EFI_STATUS Status;
630
631 //
632 // First check the tokens queued by EfiHttpRequest().
633 //
634 Status = NetMapIterate (&HttpInstance->TxTokens, HttpCancelTokens, Token);
635 if (EFI_ERROR (Status)) {
636 if (Token != NULL) {
637 if (Status == EFI_ABORTED) {
638 return EFI_SUCCESS;
639 }
640 } else {
641 return Status;
642 }
643 }
644
645 //
646 // Then check the tokens queued by EfiHttpResponse().
647 //
648 Status = NetMapIterate (&HttpInstance->RxTokens, HttpCancelTokens, Token);
649 if (EFI_ERROR (Status)) {
650 if (Token != NULL) {
651 if (Status == EFI_ABORTED) {
652 return EFI_SUCCESS;
653 } else {
654 return EFI_NOT_FOUND;
655 }
656 } else {
657 return Status;
658 }
659 }
660
661 return EFI_SUCCESS;
662 }
663
664
665 /**
666 Abort an asynchronous HTTP request or response token.
667
668 The Cancel() function aborts a pending HTTP request or response transaction. If
669 Token is not NULL and the token is in transmit or receive queues when it is being
670 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
671 be signaled. If the token is not in one of the queues, which usually means that the
672 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
673 all asynchronous tokens issued by Request() or Response() will be aborted.
674
675 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
676 @param[in] Token Point to storage containing HTTP request or response
677 token.
678
679 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
680 @retval EFI_INVALID_PARAMETER This is NULL.
681 @retval EFI_NOT_STARTED This instance hasn't been configured.
682 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP,
683 BOOTP, RARP, etc.) hasn't finished yet.
684 @retval EFI_NOT_FOUND The asynchronous request or response token is not
685 found.
686 @retval EFI_UNSUPPORTED The implementation does not support this function.
687
688 **/
689 EFI_STATUS
690 EFIAPI
691 EfiHttpCancel (
692 IN EFI_HTTP_PROTOCOL *This,
693 IN EFI_HTTP_TOKEN *Token
694 )
695 {
696 HTTP_PROTOCOL *HttpInstance;
697
698 if (This == NULL) {
699 return EFI_INVALID_PARAMETER;
700 }
701
702 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
703 ASSERT (HttpInstance != NULL);
704
705 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
706 return EFI_NOT_STARTED;
707 }
708
709 return HttpCancel (HttpInstance, Token);
710
711 }
712
713 /**
714 A callback function to intercept events during message parser.
715
716 This function will be invoked during HttpParseMessageBody() with various events type. An error
717 return status of the callback function will cause the HttpParseMessageBody() aborted.
718
719 @param[in] EventType Event type of this callback call.
720 @param[in] Data A pointer to data buffer.
721 @param[in] Length Length in bytes of the Data.
722 @param[in] Context Callback context set by HttpInitMsgParser().
723
724 @retval EFI_SUCCESS Continue to parser the message body.
725
726 **/
727 EFI_STATUS
728 EFIAPI
729 HttpBodyParserCallback (
730 IN HTTP_BODY_PARSE_EVENT EventType,
731 IN CHAR8 *Data,
732 IN UINTN Length,
733 IN VOID *Context
734 )
735 {
736 HTTP_TOKEN_WRAP *Wrap;
737
738 if (EventType != BodyParseEventOnComplete) {
739 return EFI_SUCCESS;
740 }
741
742 if (Data == NULL || Length != 0 || Context == NULL) {
743 return EFI_SUCCESS;
744 }
745
746 Wrap = (HTTP_TOKEN_WRAP *) Context;
747 Wrap->HttpInstance->NextMsg = Data;
748
749 //
750 // Free TxToken since already received corrsponding HTTP response.
751 //
752 FreePool (Wrap);
753
754 return EFI_SUCCESS;
755 }
756
757 /**
758 The work function of EfiHttpResponse().
759
760 @param[in] Wrap Pointer to HTTP token's wrap data.
761
762 @retval EFI_SUCCESS Allocation succeeded.
763 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
764 @retval EFI_NOT_READY Can't find a corresponding TxToken or
765 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
766
767 **/
768 EFI_STATUS
769 HttpResponseWorker (
770 IN HTTP_TOKEN_WRAP *Wrap
771 )
772 {
773 EFI_STATUS Status;
774 EFI_HTTP_MESSAGE *HttpMsg;
775 EFI_TCP4_IO_TOKEN *RxToken;
776 EFI_TCP4_PROTOCOL *Tcp4;
777 CHAR8 *EndofHeader;
778 CHAR8 *HttpHeaders;
779 UINTN SizeofHeaders;
780 CHAR8 *Buffer;
781 UINTN BufferSize;
782 UINTN StatusCode;
783 CHAR8 *Tmp;
784 CHAR8 *HeaderTmp;
785 CHAR8 *StatusCodeStr;
786 UINTN BodyLen;
787 HTTP_PROTOCOL *HttpInstance;
788 EFI_HTTP_TOKEN *Token;
789 NET_MAP_ITEM *Item;
790 HTTP_TOKEN_WRAP *ValueInItem;
791 UINTN HdrLen;
792
793 if (Wrap == NULL || Wrap->HttpInstance == NULL) {
794 return EFI_INVALID_PARAMETER;
795 }
796
797 HttpInstance = Wrap->HttpInstance;
798 Token = Wrap->HttpToken;
799
800 HttpMsg = Token->Message;
801
802 Tcp4 = HttpInstance->Tcp4;
803 ASSERT (Tcp4 != NULL);
804 HttpMsg->Headers = NULL;
805 HttpHeaders = NULL;
806 SizeofHeaders = 0;
807 Buffer = NULL;
808 BufferSize = 0;
809 EndofHeader = NULL;
810
811 if (HttpMsg->Data.Response != NULL) {
812 //
813 // Need receive the HTTP headers, prepare buffer.
814 //
815 Status = HttpCreateTcp4RxEventForHeader (HttpInstance);
816 if (EFI_ERROR (Status)) {
817 goto Error;
818 }
819
820 //
821 // Check whether we have cached header from previous call.
822 //
823 if ((HttpInstance->CacheBody != NULL) && (HttpInstance->NextMsg != NULL)) {
824 //
825 // The data is stored at [NextMsg, CacheBody + CacheLen].
826 //
827 HdrLen = HttpInstance->CacheBody + HttpInstance->CacheLen - HttpInstance->NextMsg;
828 HttpHeaders = AllocateZeroPool (HdrLen);
829 if (HttpHeaders == NULL) {
830 Status = EFI_OUT_OF_RESOURCES;
831 goto Error;
832 }
833
834 CopyMem (HttpHeaders, HttpInstance->NextMsg, HdrLen);
835 FreePool (HttpInstance->CacheBody);
836 HttpInstance->CacheBody = NULL;
837 HttpInstance->NextMsg = NULL;
838 HttpInstance->CacheOffset = 0;
839 SizeofHeaders = HdrLen;
840 BufferSize = HttpInstance->CacheLen;
841
842 //
843 // Check whether we cached the whole HTTP headers.
844 //
845 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR);
846 }
847
848 RxToken = &HttpInstance->RxToken;
849 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = AllocateZeroPool (DEF_BUF_LEN);
850 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer == NULL) {
851 Status = EFI_OUT_OF_RESOURCES;
852 goto Error;
853 }
854
855 //
856 // Receive the HTTP headers only when EFI_HTTP_RESPONSE_DATA is not NULL.
857 //
858 while (EndofHeader == NULL) {
859 HttpInstance->IsRxDone = FALSE;
860 RxToken->Packet.RxData->DataLength = DEF_BUF_LEN;
861 RxToken->Packet.RxData->FragmentTable[0].FragmentLength = DEF_BUF_LEN;
862 Status = Tcp4->Receive (Tcp4, RxToken);
863 if (EFI_ERROR (Status)) {
864 DEBUG ((EFI_D_ERROR, "Tcp4 receive failed: %r\n", Status));
865 goto Error;
866 }
867
868 while (!HttpInstance->IsRxDone) {
869 Tcp4->Poll (Tcp4);
870 }
871
872 Status = RxToken->CompletionToken.Status;
873 if (EFI_ERROR (Status)) {
874 goto Error;
875 }
876
877 //
878 // Append the response string.
879 //
880 BufferSize = SizeofHeaders + RxToken->Packet.RxData->FragmentTable[0].FragmentLength;
881 Buffer = AllocateZeroPool (BufferSize);
882 if (Buffer == NULL) {
883 Status = EFI_OUT_OF_RESOURCES;
884 goto Error;
885 }
886
887 if (HttpHeaders != NULL) {
888 CopyMem (Buffer, HttpHeaders, SizeofHeaders);
889 FreePool (HttpHeaders);
890 }
891
892 CopyMem (
893 Buffer + SizeofHeaders,
894 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer,
895 RxToken->Packet.RxData->FragmentTable[0].FragmentLength
896 );
897 HttpHeaders = Buffer;
898 SizeofHeaders = BufferSize;
899
900 //
901 // Check whether we received end of HTTP headers.
902 //
903 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR);
904 };
905
906 //
907 // Skip the CRLF after the HTTP headers.
908 //
909 EndofHeader = EndofHeader + AsciiStrLen (HTTP_END_OF_HDR_STR);
910
911 //
912 // Cache the part of body.
913 //
914 BodyLen = BufferSize - (EndofHeader - HttpHeaders);
915 if (BodyLen > 0) {
916 if (HttpInstance->CacheBody != NULL) {
917 FreePool (HttpInstance->CacheBody);
918 }
919
920 HttpInstance->CacheBody = AllocateZeroPool (BodyLen);
921 if (HttpInstance->CacheBody == NULL) {
922 Status = EFI_OUT_OF_RESOURCES;
923 goto Error;
924 }
925
926 CopyMem (HttpInstance->CacheBody, EndofHeader, BodyLen);
927 HttpInstance->CacheLen = BodyLen;
928 }
929
930 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
931 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
932
933 //
934 // Search for Status Code.
935 //
936 StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;
937 if (StatusCodeStr == NULL) {
938 goto Error;
939 }
940
941 StatusCode = AsciiStrDecimalToUintn (StatusCodeStr);
942
943 //
944 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
945 //
946 Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);
947 if (Tmp == NULL) {
948 goto Error;
949 }
950
951 Tmp = Tmp + AsciiStrLen (HTTP_CRLF_STR);
952 SizeofHeaders = SizeofHeaders - (Tmp - HttpHeaders);
953 HeaderTmp = AllocateZeroPool (SizeofHeaders);
954 if (HeaderTmp == NULL) {
955 goto Error;
956 }
957
958 CopyMem (HeaderTmp, Tmp, SizeofHeaders);
959 FreePool (HttpHeaders);
960 HttpHeaders = HeaderTmp;
961
962 //
963 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
964 //
965 if (mHttpUtilities == NULL) {
966 Status = EFI_NOT_READY;
967 goto Error;
968 }
969
970 //
971 // Parse the HTTP header into array of key/value pairs.
972 //
973 Status = mHttpUtilities->Parse (
974 mHttpUtilities,
975 HttpHeaders,
976 SizeofHeaders,
977 &HttpMsg->Headers,
978 &HttpMsg->HeaderCount
979 );
980 if (EFI_ERROR (Status)) {
981 goto Error;
982 }
983
984 FreePool (HttpHeaders);
985 HttpHeaders = NULL;
986
987 HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);
988
989 //
990 // Init message-body parser by header information.
991 //
992 Status = EFI_NOT_READY;
993 ValueInItem = NULL;
994 NetMapRemoveHead (&HttpInstance->TxTokens, (VOID**) &ValueInItem);
995 if (ValueInItem == NULL) {
996 goto Error;
997 }
998
999 //
1000 // The first TxToken not transmitted yet, insert back and return error.
1001 //
1002 if (!ValueInItem->TcpWrap.IsTxDone) {
1003 goto Error2;
1004 }
1005
1006 Status = HttpInitMsgParser (
1007 ValueInItem->TcpWrap.Method,
1008 HttpMsg->Data.Response->StatusCode,
1009 HttpMsg->HeaderCount,
1010 HttpMsg->Headers,
1011 HttpBodyParserCallback,
1012 (VOID *) ValueInItem,
1013 &HttpInstance->MsgParser
1014 );
1015 if (EFI_ERROR (Status)) {
1016 goto Error2;
1017 }
1018
1019 //
1020 // Check whether we received a complete HTTP message.
1021 //
1022 if (HttpInstance->CacheBody != NULL) {
1023 Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody);
1024 if (EFI_ERROR (Status)) {
1025 goto Error2;
1026 }
1027
1028 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {
1029 //
1030 // Free the MsgParse since we already have a full HTTP message.
1031 //
1032 HttpFreeMsgParser (HttpInstance->MsgParser);
1033 HttpInstance->MsgParser = NULL;
1034 }
1035 }
1036
1037 if ((HttpMsg->Body == NULL) || (HttpMsg->BodyLength == 0)) {
1038 Status = EFI_SUCCESS;
1039 goto Exit;
1040 }
1041 }
1042
1043 //
1044 // Receive the response body.
1045 //
1046 BodyLen = 0;
1047
1048 //
1049 // First check whether we cached some data.
1050 //
1051 if (HttpInstance->CacheBody != NULL) {
1052 //
1053 // Calculate the length of the cached data.
1054 //
1055 if (HttpInstance->NextMsg != NULL) {
1056 //
1057 // We have a cached HTTP message which includes a part of HTTP header of next message.
1058 //
1059 BodyLen = HttpInstance->NextMsg - (HttpInstance->CacheBody + HttpInstance->CacheOffset);
1060 } else {
1061 BodyLen = HttpInstance->CacheLen - HttpInstance->CacheOffset;
1062 }
1063
1064 if (BodyLen > 0) {
1065 //
1066 // We have some cached data. Just copy the data and return.
1067 //
1068 if (HttpMsg->BodyLength < BodyLen) {
1069 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, HttpMsg->BodyLength);
1070 HttpInstance->CacheOffset = HttpInstance->CacheOffset + HttpMsg->BodyLength;
1071 } else {
1072 //
1073 // Copy all cached data out.
1074 //
1075 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, BodyLen);
1076 HttpInstance->CacheOffset = BodyLen + HttpInstance->CacheOffset;
1077 HttpMsg->BodyLength = BodyLen;
1078
1079 if (HttpInstance->NextMsg == NULL) {
1080 //
1081 // There is no HTTP header of next message. Just free the cache buffer.
1082 //
1083 FreePool (HttpInstance->CacheBody);
1084 HttpInstance->CacheBody = NULL;
1085 HttpInstance->NextMsg = NULL;
1086 HttpInstance->CacheOffset = 0;
1087 }
1088 }
1089 //
1090 // Return since we aready received required data.
1091 //
1092 Status = EFI_SUCCESS;
1093 goto Exit;
1094 }
1095
1096 if (BodyLen == 0 && HttpInstance->MsgParser == NULL) {
1097 //
1098 // We received a complete HTTP message, and we don't have more data to return to caller.
1099 //
1100 HttpMsg->BodyLength = 0;
1101 Status = EFI_SUCCESS;
1102 goto Exit;
1103 }
1104 }
1105
1106 ASSERT (HttpInstance->MsgParser != NULL);
1107
1108 //
1109 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1110 //
1111 RxToken = &Wrap->TcpWrap.RxToken;
1112
1113 RxToken->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
1114 RxToken->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
1115 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
1116
1117 RxToken->CompletionToken.Status = EFI_NOT_READY;
1118 Status = Tcp4->Receive (Tcp4, RxToken);
1119 if (EFI_ERROR (Status)) {
1120 DEBUG ((EFI_D_ERROR, "Tcp4 receive failed: %r\n", Status));
1121 goto Error;
1122 }
1123
1124 return Status;
1125
1126 Exit:
1127 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);
1128 if (Item != NULL) {
1129 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);
1130 }
1131 Token->Status = Status;
1132 gBS->SignalEvent (Token->Event);
1133 FreePool (Wrap);
1134 return Status;
1135
1136 Error2:
1137 NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem);
1138
1139 Error:
1140 if (Wrap != NULL) {
1141 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
1142 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
1143 }
1144 RxToken = &Wrap->TcpWrap.RxToken;
1145 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
1146 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
1147 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
1148 }
1149 FreePool (Wrap);
1150 }
1151
1152 if (HttpInstance->RxToken.CompletionToken.Event != NULL) {
1153 gBS->CloseEvent (HttpInstance->RxToken.CompletionToken.Event);
1154 HttpInstance->RxToken.CompletionToken.Event = NULL;
1155 }
1156
1157 RxToken = &HttpInstance->RxToken;
1158 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
1159 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
1160 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
1161 }
1162
1163 if (HttpHeaders != NULL) {
1164 FreePool (HttpHeaders);
1165 }
1166
1167 if (HttpMsg->Headers != NULL) {
1168 FreePool (HttpMsg->Headers);
1169 }
1170
1171 if (HttpInstance->CacheBody != NULL) {
1172 FreePool (HttpInstance->CacheBody);
1173 HttpInstance->CacheBody = NULL;
1174 }
1175
1176 Token->Status = Status;
1177 gBS->SignalEvent (Token->Event);
1178
1179 return Status;
1180
1181 }
1182
1183
1184 /**
1185 The Response() function queues an HTTP response to this HTTP instance, similar to
1186 Receive() function in the EFI TCP driver. When the HTTP request is sent successfully,
1187 or if there is an error, Status in token will be updated and Event will be signaled.
1188
1189 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1190 is received in the underlying TCP instance, the data will be parsed and Token will
1191 be populated with the response data. If the data received from the remote host
1192 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1193 (asynchronously) for more data to be sent from the remote host before signaling
1194 Event in Token.
1195
1196 It is the responsibility of the caller to allocate a buffer for Body and specify the
1197 size in BodyLength. If the remote host provides a response that contains a content
1198 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1199 BodyLength will be updated with the amount of bytes received and copied to Body. This
1200 allows the client to download a large file in chunks instead of into one contiguous
1201 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1202 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1203 token to underlying TCP instance. If data arrives in the receive buffer, up to
1204 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1205 BodyLength with the amount of bytes received and copied to Body.
1206
1207 If the HTTP driver does not have an open underlying TCP connection with the host
1208 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1209 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1210 an open TCP connection between client and host.
1211
1212 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1213 @param[in] Token Pointer to storage containing HTTP response token.
1214
1215 @retval EFI_SUCCESS Allocation succeeded.
1216 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1217 initialized.
1218 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1219 This is NULL.
1220 Token is NULL.
1221 Token->Message->Headers is NULL.
1222 Token->Message is NULL.
1223 Token->Message->Body is not NULL,
1224 Token->Message->BodyLength is non-zero, and
1225 Token->Message->Data is NULL, but a previous call to
1226 Response() has not been completed successfully.
1227 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1228 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1229 specified by response URL.
1230 **/
1231 EFI_STATUS
1232 EFIAPI
1233 EfiHttpResponse (
1234 IN EFI_HTTP_PROTOCOL *This,
1235 IN EFI_HTTP_TOKEN *Token
1236 )
1237 {
1238 EFI_STATUS Status;
1239 EFI_HTTP_MESSAGE *HttpMsg;
1240 HTTP_PROTOCOL *HttpInstance;
1241 HTTP_TOKEN_WRAP *Wrap;
1242
1243 if ((This == NULL) || (Token == NULL)) {
1244 return EFI_INVALID_PARAMETER;
1245 }
1246
1247 HttpMsg = Token->Message;
1248 if (HttpMsg == NULL) {
1249 return EFI_INVALID_PARAMETER;
1250 }
1251
1252 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
1253 ASSERT (HttpInstance != NULL);
1254
1255 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
1256 return EFI_NOT_STARTED;
1257 }
1258
1259 if (HttpInstance->LocalAddressIsIPv6) {
1260 return EFI_UNSUPPORTED;
1261 }
1262
1263 //
1264 // Check whether the token already existed.
1265 //
1266 if (EFI_ERROR (NetMapIterate (&HttpInstance->RxTokens, HttpTokenExist, Token))) {
1267 return EFI_ACCESS_DENIED;
1268 }
1269
1270 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));
1271 if (Wrap == NULL) {
1272 return EFI_OUT_OF_RESOURCES;
1273 }
1274
1275 Wrap->HttpInstance = HttpInstance;
1276 Wrap->HttpToken = Token;
1277
1278 Status = HttpCreateTcp4RxEvent (Wrap);
1279 if (EFI_ERROR (Status)) {
1280 goto Error;
1281 }
1282
1283 Status = NetMapInsertTail (&HttpInstance->RxTokens, Token, Wrap);
1284 if (EFI_ERROR (Status)) {
1285 goto Error;
1286 }
1287
1288 //
1289 // If already have pending RxTokens, return directly.
1290 //
1291 if (NetMapGetCount (&HttpInstance->RxTokens) > 1) {
1292 return EFI_SUCCESS;
1293 }
1294
1295 return HttpResponseWorker (Wrap);
1296
1297 Error:
1298 if (Wrap != NULL) {
1299 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
1300 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
1301 }
1302 FreePool (Wrap);
1303 }
1304
1305 return Status;
1306 }
1307
1308 /**
1309 The Poll() function can be used by network drivers and applications to increase the
1310 rate that data packets are moved between the communication devices and the transmit
1311 and receive queues.
1312
1313 In some systems, the periodic timer event in the managed network driver may not poll
1314 the underlying communications device fast enough to transmit and/or receive all data
1315 packets without missing incoming packets or dropping outgoing packets. Drivers and
1316 applications that are experiencing packet loss should try calling the Poll() function
1317 more often.
1318
1319 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1320
1321 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1322 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1323 @retval EFI_INVALID_PARAMETER This is NULL.
1324 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1325 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1326
1327 **/
1328 EFI_STATUS
1329 EFIAPI
1330 EfiHttpPoll (
1331 IN EFI_HTTP_PROTOCOL *This
1332 )
1333 {
1334 HTTP_PROTOCOL *HttpInstance;
1335 EFI_STATUS Status;
1336
1337 if (This == NULL) {
1338 return EFI_INVALID_PARAMETER;
1339 }
1340
1341 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
1342 ASSERT (HttpInstance != NULL);
1343
1344 if (HttpInstance->LocalAddressIsIPv6) {
1345 return EFI_UNSUPPORTED;
1346 }
1347
1348 if (HttpInstance->Tcp4 == NULL || HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
1349 return EFI_NOT_STARTED;
1350 }
1351
1352 Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);
1353
1354 DispatchDpc ();
1355
1356 return Status;
1357 }