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