]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg: Enhance the NULL pointer check before dereference it.
[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) {
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 HttpInstance->RemotePort = 0;
377 }
378 }
379 }
380
381 if (Configure) {
382 //
383 // Parse Url for IPv4 address, if failed, perform DNS resolution.
384 //
385 Status = NetLibAsciiStrToIp4 (HostName, &HttpInstance->RemoteAddr);
386 if (EFI_ERROR (Status)) {
387 HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (UINT16));
388 if (HostNameStr == NULL) {
389 Status = EFI_OUT_OF_RESOURCES;
390 goto Error1;
391 }
392
393 AsciiStrToUnicodeStr (HostName, HostNameStr);
394 Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr);
395 FreePool (HostNameStr);
396 if (EFI_ERROR (Status)) {
397 goto Error1;
398 }
399 }
400
401 //
402 // Save the RemotePort and RemoteHost.
403 //
404 ASSERT (HttpInstance->RemoteHost == NULL);
405 HttpInstance->RemotePort = RemotePort;
406 HttpInstance->RemoteHost = HostName;
407 HostName = NULL;
408 }
409
410 if (ReConfigure) {
411 //
412 // The request URL is different from previous calls to Request(), close existing TCP instance.
413 //
414 ASSERT (HttpInstance->Tcp4 != NULL);
415 HttpCloseConnection (HttpInstance);
416 EfiHttpCancel (This, NULL);
417 }
418
419 //
420 // Wrap the HTTP token in HTTP_TOKEN_WRAP
421 //
422 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));
423 if (Wrap == NULL) {
424 Status = EFI_OUT_OF_RESOURCES;
425 goto Error1;
426 }
427
428 Wrap->HttpToken = Token;
429 Wrap->HttpInstance = HttpInstance;
430 Wrap->TcpWrap.Method = Request->Method;
431
432 if (Configure) {
433 //
434 // Configure TCP instance.
435 //
436 Status = HttpConfigureTcp4 (HttpInstance, Wrap);
437 if (EFI_ERROR (Status)) {
438 goto Error1;
439 }
440 //
441 // Connect TCP.
442 //
443 Status = HttpConnectTcp4 (HttpInstance);
444 if (EFI_ERROR (Status)) {
445 goto Error2;
446 }
447 } else {
448 //
449 // For the new HTTP token, create TX TCP token events.
450 //
451 Status = HttpCreateTcp4TxEvent (Wrap);
452 if (EFI_ERROR (Status)) {
453 goto Error1;
454 }
455 }
456
457 //
458 // Create request message.
459 //
460 FileUrl = Url;
461 if (*FileUrl != '/') {
462 //
463 // Convert the absolute-URI to the absolute-path
464 //
465 while (*FileUrl != ':') {
466 FileUrl++;
467 }
468 if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {
469 FileUrl += 3;
470 while (*FileUrl != '/') {
471 FileUrl++;
472 }
473 } else {
474 Status = EFI_INVALID_PARAMETER;
475 goto Error3;
476 }
477 }
478 RequestStr = HttpGenRequestString (HttpInstance, HttpMsg, FileUrl);
479 if (RequestStr == NULL) {
480 Status = EFI_OUT_OF_RESOURCES;
481 goto Error3;
482 }
483
484 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);
485 if (EFI_ERROR (Status)) {
486 goto Error4;
487 }
488
489 if (HostName != NULL) {
490 FreePool (HostName);
491 }
492
493 //
494 // Transmit the request message.
495 //
496 Status = HttpTransmitTcp4 (
497 HttpInstance,
498 Wrap,
499 (UINT8*) RequestStr,
500 AsciiStrLen (RequestStr)
501 );
502 if (EFI_ERROR (Status)) {
503 goto Error5;
504 }
505
506 DispatchDpc ();
507
508 return EFI_SUCCESS;
509
510 Error5:
511 NetMapRemoveTail (&HttpInstance->TxTokens, NULL);
512
513 Error4:
514 if (RequestStr != NULL) {
515 FreePool (RequestStr);
516 }
517
518 Error3:
519 HttpCloseConnection (HttpInstance);
520
521
522 Error2:
523 HttpCloseTcp4ConnCloseEvent (HttpInstance);
524 if (NULL != Wrap->TcpWrap.TxToken.CompletionToken.Event) {
525 gBS->CloseEvent (Wrap->TcpWrap.TxToken.CompletionToken.Event);
526 Wrap->TcpWrap.TxToken.CompletionToken.Event = NULL;
527 }
528
529 Error1:
530 if (HostName != NULL) {
531 FreePool (HostName);
532 }
533 if (Wrap != NULL) {
534 FreePool (Wrap);
535 }
536 if (UrlParser!= NULL) {
537 HttpUrlFreeParser (UrlParser);
538 }
539
540 return Status;
541
542 }
543
544 /**
545 Cancel a TxToken or RxToken.
546
547 @param[in] Map The HTTP instance's token queue.
548 @param[in] Item Object container for one HTTP token and token's wrap.
549 @param[in] Context The user's token to cancel.
550
551 @retval EFI_SUCCESS Continue to check the next Item.
552 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.
553
554 **/
555 EFI_STATUS
556 EFIAPI
557 HttpCancelTokens (
558 IN NET_MAP *Map,
559 IN NET_MAP_ITEM *Item,
560 IN VOID *Context
561 )
562 {
563
564 EFI_HTTP_TOKEN *Token;
565 HTTP_TOKEN_WRAP *Wrap;
566
567 Token = (EFI_HTTP_TOKEN *) Context;
568
569 //
570 // Return EFI_SUCCESS to check the next item in the map if
571 // this one doesn't match.
572 //
573 if ((Token != NULL) && (Token != Item->Key)) {
574 return EFI_SUCCESS;
575 }
576
577 Wrap = (HTTP_TOKEN_WRAP *) Item->Value;
578 ASSERT (Wrap != NULL);
579
580 //
581 // Free resources.
582 //
583 NetMapRemoveItem (Map, Item, NULL);
584
585 if (Wrap->TcpWrap.TxToken.CompletionToken.Event != NULL) {
586 gBS->CloseEvent (Wrap->TcpWrap.TxToken.CompletionToken.Event);
587 }
588
589 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
590 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
591 }
592
593 if (Wrap->TcpWrap.RxToken.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
594 FreePool (Wrap->TcpWrap.RxToken.Packet.RxData->FragmentTable[0].FragmentBuffer);
595 }
596
597 FreePool (Wrap);
598
599 //
600 // If only one item is to be cancel, return EFI_ABORTED to stop
601 // iterating the map any more.
602 //
603 if (Token != NULL) {
604 return EFI_ABORTED;
605 }
606
607 return EFI_SUCCESS;
608 }
609
610 /**
611 Cancel the user's receive/transmit request. It is the worker function of
612 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the
613 token.
614
615 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.
616 @param[in] Token The token to cancel. If NULL, all token will be
617 cancelled.
618
619 @retval EFI_SUCCESS The token is cancelled.
620 @retval EFI_NOT_FOUND The asynchronous request or response token is not found.
621 @retval Others Other error as indicated.
622
623 **/
624 EFI_STATUS
625 HttpCancel (
626 IN HTTP_PROTOCOL *HttpInstance,
627 IN EFI_HTTP_TOKEN *Token
628 )
629 {
630 EFI_STATUS Status;
631
632 //
633 // First check the tokens queued by EfiHttpRequest().
634 //
635 Status = NetMapIterate (&HttpInstance->TxTokens, HttpCancelTokens, Token);
636 if (EFI_ERROR (Status)) {
637 if (Token != NULL) {
638 if (Status == EFI_ABORTED) {
639 return EFI_SUCCESS;
640 }
641 } else {
642 return Status;
643 }
644 }
645
646 //
647 // Then check the tokens queued by EfiHttpResponse().
648 //
649 Status = NetMapIterate (&HttpInstance->RxTokens, HttpCancelTokens, Token);
650 if (EFI_ERROR (Status)) {
651 if (Token != NULL) {
652 if (Status == EFI_ABORTED) {
653 return EFI_SUCCESS;
654 } else {
655 return EFI_NOT_FOUND;
656 }
657 } else {
658 return Status;
659 }
660 }
661
662 return EFI_SUCCESS;
663 }
664
665
666 /**
667 Abort an asynchronous HTTP request or response token.
668
669 The Cancel() function aborts a pending HTTP request or response transaction. If
670 Token is not NULL and the token is in transmit or receive queues when it is being
671 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will
672 be signaled. If the token is not in one of the queues, which usually means that the
673 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,
674 all asynchronous tokens issued by Request() or Response() will be aborted.
675
676 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
677 @param[in] Token Point to storage containing HTTP request or response
678 token.
679
680 @retval EFI_SUCCESS Request and Response queues are successfully flushed.
681 @retval EFI_INVALID_PARAMETER This is NULL.
682 @retval EFI_NOT_STARTED This instance hasn't been configured.
683 @retval EFI_NO_MAPPING When using the default address, configuration (DHCP,
684 BOOTP, RARP, etc.) hasn't finished yet.
685 @retval EFI_NOT_FOUND The asynchronous request or response token is not
686 found.
687 @retval EFI_UNSUPPORTED The implementation does not support this function.
688
689 **/
690 EFI_STATUS
691 EFIAPI
692 EfiHttpCancel (
693 IN EFI_HTTP_PROTOCOL *This,
694 IN EFI_HTTP_TOKEN *Token
695 )
696 {
697 HTTP_PROTOCOL *HttpInstance;
698
699 if (This == NULL) {
700 return EFI_INVALID_PARAMETER;
701 }
702
703 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
704 ASSERT (HttpInstance != NULL);
705
706 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
707 return EFI_NOT_STARTED;
708 }
709
710 return HttpCancel (HttpInstance, Token);
711
712 }
713
714 /**
715 A callback function to intercept events during message parser.
716
717 This function will be invoked during HttpParseMessageBody() with various events type. An error
718 return status of the callback function will cause the HttpParseMessageBody() aborted.
719
720 @param[in] EventType Event type of this callback call.
721 @param[in] Data A pointer to data buffer.
722 @param[in] Length Length in bytes of the Data.
723 @param[in] Context Callback context set by HttpInitMsgParser().
724
725 @retval EFI_SUCCESS Continue to parser the message body.
726
727 **/
728 EFI_STATUS
729 EFIAPI
730 HttpBodyParserCallback (
731 IN HTTP_BODY_PARSE_EVENT EventType,
732 IN CHAR8 *Data,
733 IN UINTN Length,
734 IN VOID *Context
735 )
736 {
737 HTTP_TOKEN_WRAP *Wrap;
738
739 if (EventType != BodyParseEventOnComplete) {
740 return EFI_SUCCESS;
741 }
742
743 if (Data == NULL || Length != 0 || Context == NULL) {
744 return EFI_SUCCESS;
745 }
746
747 Wrap = (HTTP_TOKEN_WRAP *) Context;
748 Wrap->HttpInstance->NextMsg = Data;
749
750 //
751 // Free TxToken since already received corrsponding HTTP response.
752 //
753 FreePool (Wrap);
754
755 return EFI_SUCCESS;
756 }
757
758 /**
759 The work function of EfiHttpResponse().
760
761 @param[in] Wrap Pointer to HTTP token's wrap data.
762
763 @retval EFI_SUCCESS Allocation succeeded.
764 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.
765 @retval EFI_NOT_READY Can't find a corresponding TxToken or
766 the EFI_HTTP_UTILITIES_PROTOCOL is not available.
767
768 **/
769 EFI_STATUS
770 HttpResponseWorker (
771 IN HTTP_TOKEN_WRAP *Wrap
772 )
773 {
774 EFI_STATUS Status;
775 EFI_HTTP_MESSAGE *HttpMsg;
776 EFI_TCP4_IO_TOKEN *RxToken;
777 EFI_TCP4_PROTOCOL *Tcp4;
778 CHAR8 *EndofHeader;
779 CHAR8 *HttpHeaders;
780 UINTN SizeofHeaders;
781 CHAR8 *Buffer;
782 UINTN BufferSize;
783 UINTN StatusCode;
784 CHAR8 *Tmp;
785 CHAR8 *HeaderTmp;
786 CHAR8 *StatusCodeStr;
787 UINTN BodyLen;
788 HTTP_PROTOCOL *HttpInstance;
789 EFI_HTTP_TOKEN *Token;
790 NET_MAP_ITEM *Item;
791 HTTP_TOKEN_WRAP *ValueInItem;
792 UINTN HdrLen;
793
794 if (Wrap == NULL || Wrap->HttpInstance == NULL) {
795 return EFI_INVALID_PARAMETER;
796 }
797
798 HttpInstance = Wrap->HttpInstance;
799 Token = Wrap->HttpToken;
800
801 HttpMsg = Token->Message;
802
803 Tcp4 = HttpInstance->Tcp4;
804 ASSERT (Tcp4 != NULL);
805 HttpMsg->Headers = NULL;
806 HttpHeaders = NULL;
807 SizeofHeaders = 0;
808 Buffer = NULL;
809 BufferSize = 0;
810 EndofHeader = NULL;
811
812 if (HttpMsg->Data.Response != NULL) {
813 //
814 // Need receive the HTTP headers, prepare buffer.
815 //
816 Status = HttpCreateTcp4RxEventForHeader (HttpInstance);
817 if (EFI_ERROR (Status)) {
818 goto Error;
819 }
820
821 //
822 // Check whether we have cached header from previous call.
823 //
824 if ((HttpInstance->CacheBody != NULL) && (HttpInstance->NextMsg != NULL)) {
825 //
826 // The data is stored at [NextMsg, CacheBody + CacheLen].
827 //
828 HdrLen = HttpInstance->CacheBody + HttpInstance->CacheLen - HttpInstance->NextMsg;
829 HttpHeaders = AllocateZeroPool (HdrLen);
830 if (HttpHeaders == NULL) {
831 Status = EFI_OUT_OF_RESOURCES;
832 goto Error;
833 }
834
835 CopyMem (HttpHeaders, HttpInstance->NextMsg, HdrLen);
836 FreePool (HttpInstance->CacheBody);
837 HttpInstance->CacheBody = NULL;
838 HttpInstance->NextMsg = NULL;
839 HttpInstance->CacheOffset = 0;
840 SizeofHeaders = HdrLen;
841 BufferSize = HttpInstance->CacheLen;
842
843 //
844 // Check whether we cached the whole HTTP headers.
845 //
846 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR);
847 }
848
849 RxToken = &HttpInstance->RxToken;
850 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = AllocateZeroPool (DEF_BUF_LEN);
851 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer == NULL) {
852 Status = EFI_OUT_OF_RESOURCES;
853 goto Error;
854 }
855
856 //
857 // Receive the HTTP headers only when EFI_HTTP_RESPONSE_DATA is not NULL.
858 //
859 while (EndofHeader == NULL) {
860 HttpInstance->IsRxDone = FALSE;
861 RxToken->Packet.RxData->DataLength = DEF_BUF_LEN;
862 RxToken->Packet.RxData->FragmentTable[0].FragmentLength = DEF_BUF_LEN;
863 Status = Tcp4->Receive (Tcp4, RxToken);
864 if (EFI_ERROR (Status)) {
865 DEBUG ((EFI_D_ERROR, "Tcp4 receive failed: %r\n", Status));
866 goto Error;
867 }
868
869 while (!HttpInstance->IsRxDone) {
870 Tcp4->Poll (Tcp4);
871 }
872
873 Status = RxToken->CompletionToken.Status;
874 if (EFI_ERROR (Status)) {
875 goto Error;
876 }
877
878 //
879 // Append the response string.
880 //
881 BufferSize = SizeofHeaders + RxToken->Packet.RxData->FragmentTable[0].FragmentLength;
882 Buffer = AllocateZeroPool (BufferSize);
883 if (Buffer == NULL) {
884 Status = EFI_OUT_OF_RESOURCES;
885 goto Error;
886 }
887
888 if (HttpHeaders != NULL) {
889 CopyMem (Buffer, HttpHeaders, SizeofHeaders);
890 FreePool (HttpHeaders);
891 }
892
893 CopyMem (
894 Buffer + SizeofHeaders,
895 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer,
896 RxToken->Packet.RxData->FragmentTable[0].FragmentLength
897 );
898 HttpHeaders = Buffer;
899 SizeofHeaders = BufferSize;
900
901 //
902 // Check whether we received end of HTTP headers.
903 //
904 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR);
905 };
906
907 //
908 // Skip the CRLF after the HTTP headers.
909 //
910 EndofHeader = EndofHeader + AsciiStrLen (HTTP_END_OF_HDR_STR);
911
912 //
913 // Cache the part of body.
914 //
915 BodyLen = BufferSize - (EndofHeader - HttpHeaders);
916 if (BodyLen > 0) {
917 if (HttpInstance->CacheBody != NULL) {
918 FreePool (HttpInstance->CacheBody);
919 }
920
921 HttpInstance->CacheBody = AllocateZeroPool (BodyLen);
922 if (HttpInstance->CacheBody == NULL) {
923 Status = EFI_OUT_OF_RESOURCES;
924 goto Error;
925 }
926
927 CopyMem (HttpInstance->CacheBody, EndofHeader, BodyLen);
928 HttpInstance->CacheLen = BodyLen;
929 }
930
931 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
932 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
933
934 //
935 // Search for Status Code.
936 //
937 StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;
938 if (StatusCodeStr == NULL) {
939 goto Error;
940 }
941
942 StatusCode = AsciiStrDecimalToUintn (StatusCodeStr);
943
944 //
945 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".
946 //
947 Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);
948 if (Tmp == NULL) {
949 goto Error;
950 }
951
952 Tmp = Tmp + AsciiStrLen (HTTP_CRLF_STR);
953 SizeofHeaders = SizeofHeaders - (Tmp - HttpHeaders);
954 HeaderTmp = AllocateZeroPool (SizeofHeaders);
955 if (HeaderTmp == NULL) {
956 goto Error;
957 }
958
959 CopyMem (HeaderTmp, Tmp, SizeofHeaders);
960 FreePool (HttpHeaders);
961 HttpHeaders = HeaderTmp;
962
963 //
964 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.
965 //
966 if (mHttpUtilities == NULL) {
967 Status = EFI_NOT_READY;
968 goto Error;
969 }
970
971 //
972 // Parse the HTTP header into array of key/value pairs.
973 //
974 Status = mHttpUtilities->Parse (
975 mHttpUtilities,
976 HttpHeaders,
977 SizeofHeaders,
978 &HttpMsg->Headers,
979 &HttpMsg->HeaderCount
980 );
981 if (EFI_ERROR (Status)) {
982 goto Error;
983 }
984
985 FreePool (HttpHeaders);
986 HttpHeaders = NULL;
987
988 HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);
989
990 //
991 // Init message-body parser by header information.
992 //
993 Status = EFI_NOT_READY;
994 ValueInItem = NULL;
995 NetMapRemoveHead (&HttpInstance->TxTokens, (VOID**) &ValueInItem);
996 if (ValueInItem == NULL) {
997 goto Error;
998 }
999
1000 //
1001 // The first TxToken not transmitted yet, insert back and return error.
1002 //
1003 if (!ValueInItem->TcpWrap.IsTxDone) {
1004 goto Error2;
1005 }
1006
1007 Status = HttpInitMsgParser (
1008 ValueInItem->TcpWrap.Method,
1009 HttpMsg->Data.Response->StatusCode,
1010 HttpMsg->HeaderCount,
1011 HttpMsg->Headers,
1012 HttpBodyParserCallback,
1013 (VOID *) ValueInItem,
1014 &HttpInstance->MsgParser
1015 );
1016 if (EFI_ERROR (Status)) {
1017 goto Error2;
1018 }
1019
1020 //
1021 // Check whether we received a complete HTTP message.
1022 //
1023 if (HttpInstance->CacheBody != NULL) {
1024 Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody);
1025 if (EFI_ERROR (Status)) {
1026 goto Error2;
1027 }
1028
1029 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {
1030 //
1031 // Free the MsgParse since we already have a full HTTP message.
1032 //
1033 HttpFreeMsgParser (HttpInstance->MsgParser);
1034 HttpInstance->MsgParser = NULL;
1035 }
1036 }
1037
1038 if ((HttpMsg->Body == NULL) || (HttpMsg->BodyLength == 0)) {
1039 Status = EFI_SUCCESS;
1040 goto Exit;
1041 }
1042 }
1043
1044 //
1045 // Receive the response body.
1046 //
1047 BodyLen = 0;
1048
1049 //
1050 // First check whether we cached some data.
1051 //
1052 if (HttpInstance->CacheBody != NULL) {
1053 //
1054 // Calculate the length of the cached data.
1055 //
1056 if (HttpInstance->NextMsg != NULL) {
1057 //
1058 // We have a cached HTTP message which includes a part of HTTP header of next message.
1059 //
1060 BodyLen = HttpInstance->NextMsg - (HttpInstance->CacheBody + HttpInstance->CacheOffset);
1061 } else {
1062 BodyLen = HttpInstance->CacheLen - HttpInstance->CacheOffset;
1063 }
1064
1065 if (BodyLen > 0) {
1066 //
1067 // We have some cached data. Just copy the data and return.
1068 //
1069 if (HttpMsg->BodyLength < BodyLen) {
1070 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, HttpMsg->BodyLength);
1071 HttpInstance->CacheOffset = HttpInstance->CacheOffset + HttpMsg->BodyLength;
1072 } else {
1073 //
1074 // Copy all cached data out.
1075 //
1076 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, BodyLen);
1077 HttpInstance->CacheOffset = BodyLen + HttpInstance->CacheOffset;
1078 HttpMsg->BodyLength = BodyLen;
1079
1080 if (HttpInstance->NextMsg == NULL) {
1081 //
1082 // There is no HTTP header of next message. Just free the cache buffer.
1083 //
1084 FreePool (HttpInstance->CacheBody);
1085 HttpInstance->CacheBody = NULL;
1086 HttpInstance->NextMsg = NULL;
1087 HttpInstance->CacheOffset = 0;
1088 }
1089 }
1090 //
1091 // Return since we aready received required data.
1092 //
1093 Status = EFI_SUCCESS;
1094 goto Exit;
1095 }
1096
1097 if (BodyLen == 0 && HttpInstance->MsgParser == NULL) {
1098 //
1099 // We received a complete HTTP message, and we don't have more data to return to caller.
1100 //
1101 HttpMsg->BodyLength = 0;
1102 Status = EFI_SUCCESS;
1103 goto Exit;
1104 }
1105 }
1106
1107 ASSERT (HttpInstance->MsgParser != NULL);
1108
1109 //
1110 // We still need receive more data when there is no cache data and MsgParser is not NULL;
1111 //
1112 RxToken = &Wrap->TcpWrap.RxToken;
1113
1114 RxToken->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
1115 RxToken->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
1116 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
1117
1118 RxToken->CompletionToken.Status = EFI_NOT_READY;
1119 Status = Tcp4->Receive (Tcp4, RxToken);
1120 if (EFI_ERROR (Status)) {
1121 DEBUG ((EFI_D_ERROR, "Tcp4 receive failed: %r\n", Status));
1122 goto Error;
1123 }
1124
1125 return Status;
1126
1127 Exit:
1128 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);
1129 if (Item != NULL) {
1130 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);
1131 }
1132 Token->Status = Status;
1133 gBS->SignalEvent (Token->Event);
1134 FreePool (Wrap);
1135 return Status;
1136
1137 Error2:
1138 NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem);
1139
1140 Error:
1141 if (Wrap != NULL) {
1142 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
1143 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
1144 }
1145 RxToken = &Wrap->TcpWrap.RxToken;
1146 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
1147 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
1148 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
1149 }
1150 FreePool (Wrap);
1151 }
1152
1153 if (HttpInstance->RxToken.CompletionToken.Event != NULL) {
1154 gBS->CloseEvent (HttpInstance->RxToken.CompletionToken.Event);
1155 HttpInstance->RxToken.CompletionToken.Event = NULL;
1156 }
1157
1158 RxToken = &HttpInstance->RxToken;
1159 if (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {
1160 FreePool (RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer);
1161 RxToken->Packet.RxData->FragmentTable[0].FragmentBuffer = NULL;
1162 }
1163
1164 if (HttpHeaders != NULL) {
1165 FreePool (HttpHeaders);
1166 }
1167
1168 if (HttpMsg->Headers != NULL) {
1169 FreePool (HttpMsg->Headers);
1170 }
1171
1172 if (HttpInstance->CacheBody != NULL) {
1173 FreePool (HttpInstance->CacheBody);
1174 HttpInstance->CacheBody = NULL;
1175 }
1176
1177 Token->Status = Status;
1178 gBS->SignalEvent (Token->Event);
1179
1180 return Status;
1181
1182 }
1183
1184
1185 /**
1186 The Response() function queues an HTTP response to this HTTP instance, similar to
1187 Receive() function in the EFI TCP driver. When the HTTP request is sent successfully,
1188 or if there is an error, Status in token will be updated and Event will be signaled.
1189
1190 The HTTP driver will queue a receive token to the underlying TCP instance. When data
1191 is received in the underlying TCP instance, the data will be parsed and Token will
1192 be populated with the response data. If the data received from the remote host
1193 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting
1194 (asynchronously) for more data to be sent from the remote host before signaling
1195 Event in Token.
1196
1197 It is the responsibility of the caller to allocate a buffer for Body and specify the
1198 size in BodyLength. If the remote host provides a response that contains a content
1199 body, up to BodyLength bytes will be copied from the receive buffer into Body and
1200 BodyLength will be updated with the amount of bytes received and copied to Body. This
1201 allows the client to download a large file in chunks instead of into one contiguous
1202 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is
1203 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive
1204 token to underlying TCP instance. If data arrives in the receive buffer, up to
1205 BodyLength bytes of data will be copied to Body. The HTTP driver will then update
1206 BodyLength with the amount of bytes received and copied to Body.
1207
1208 If the HTTP driver does not have an open underlying TCP connection with the host
1209 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is
1210 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain
1211 an open TCP connection between client and host.
1212
1213 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1214 @param[in] Token Pointer to storage containing HTTP response token.
1215
1216 @retval EFI_SUCCESS Allocation succeeded.
1217 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been
1218 initialized.
1219 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1220 This is NULL.
1221 Token is NULL.
1222 Token->Message->Headers is NULL.
1223 Token->Message is NULL.
1224 Token->Message->Body is not NULL,
1225 Token->Message->BodyLength is non-zero, and
1226 Token->Message->Data is NULL, but a previous call to
1227 Response() has not been completed successfully.
1228 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.
1229 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host
1230 specified by response URL.
1231 **/
1232 EFI_STATUS
1233 EFIAPI
1234 EfiHttpResponse (
1235 IN EFI_HTTP_PROTOCOL *This,
1236 IN EFI_HTTP_TOKEN *Token
1237 )
1238 {
1239 EFI_STATUS Status;
1240 EFI_HTTP_MESSAGE *HttpMsg;
1241 HTTP_PROTOCOL *HttpInstance;
1242 HTTP_TOKEN_WRAP *Wrap;
1243
1244 if ((This == NULL) || (Token == NULL)) {
1245 return EFI_INVALID_PARAMETER;
1246 }
1247
1248 HttpMsg = Token->Message;
1249 if (HttpMsg == NULL) {
1250 return EFI_INVALID_PARAMETER;
1251 }
1252
1253 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
1254 ASSERT (HttpInstance != NULL);
1255
1256 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
1257 return EFI_NOT_STARTED;
1258 }
1259
1260 if (HttpInstance->LocalAddressIsIPv6) {
1261 return EFI_UNSUPPORTED;
1262 }
1263
1264 //
1265 // Check whether the token already existed.
1266 //
1267 if (EFI_ERROR (NetMapIterate (&HttpInstance->RxTokens, HttpTokenExist, Token))) {
1268 return EFI_ACCESS_DENIED;
1269 }
1270
1271 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));
1272 if (Wrap == NULL) {
1273 return EFI_OUT_OF_RESOURCES;
1274 }
1275
1276 Wrap->HttpInstance = HttpInstance;
1277 Wrap->HttpToken = Token;
1278
1279 Status = HttpCreateTcp4RxEvent (Wrap);
1280 if (EFI_ERROR (Status)) {
1281 goto Error;
1282 }
1283
1284 Status = NetMapInsertTail (&HttpInstance->RxTokens, Token, Wrap);
1285 if (EFI_ERROR (Status)) {
1286 goto Error;
1287 }
1288
1289 //
1290 // If already have pending RxTokens, return directly.
1291 //
1292 if (NetMapGetCount (&HttpInstance->RxTokens) > 1) {
1293 return EFI_SUCCESS;
1294 }
1295
1296 return HttpResponseWorker (Wrap);
1297
1298 Error:
1299 if (Wrap != NULL) {
1300 if (Wrap->TcpWrap.RxToken.CompletionToken.Event != NULL) {
1301 gBS->CloseEvent (Wrap->TcpWrap.RxToken.CompletionToken.Event);
1302 }
1303 FreePool (Wrap);
1304 }
1305
1306 return Status;
1307 }
1308
1309 /**
1310 The Poll() function can be used by network drivers and applications to increase the
1311 rate that data packets are moved between the communication devices and the transmit
1312 and receive queues.
1313
1314 In some systems, the periodic timer event in the managed network driver may not poll
1315 the underlying communications device fast enough to transmit and/or receive all data
1316 packets without missing incoming packets or dropping outgoing packets. Drivers and
1317 applications that are experiencing packet loss should try calling the Poll() function
1318 more often.
1319
1320 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.
1321
1322 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1323 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1324 @retval EFI_INVALID_PARAMETER This is NULL.
1325 @retval EFI_NOT_READY No incoming or outgoing data is processed.
1326 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.
1327
1328 **/
1329 EFI_STATUS
1330 EFIAPI
1331 EfiHttpPoll (
1332 IN EFI_HTTP_PROTOCOL *This
1333 )
1334 {
1335 HTTP_PROTOCOL *HttpInstance;
1336 EFI_STATUS Status;
1337
1338 if (This == NULL) {
1339 return EFI_INVALID_PARAMETER;
1340 }
1341
1342 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);
1343 ASSERT (HttpInstance != NULL);
1344
1345 if (HttpInstance->LocalAddressIsIPv6) {
1346 return EFI_UNSUPPORTED;
1347 }
1348
1349 if (HttpInstance->Tcp4 == NULL || HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {
1350 return EFI_NOT_STARTED;
1351 }
1352
1353 Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);
1354
1355 DispatchDpc ();
1356
1357 return Status;
1358 }