]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/HttpDxe/HttpImpl.c
IntelSiliconPkg/PlatformVTdSample: update ExceptionDevice
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
CommitLineData
47f51a06
YT
1/** @file\r
2 Implementation of EFI_HTTP_PROTOCOL protocol interfaces.\r
3\r
221463c2 4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
f58554fc 5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
47f51a06
YT
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "HttpDriver.h"\r
18\r
19EFI_HTTP_PROTOCOL mEfiHttpTemplate = {\r
20 EfiHttpGetModeData,\r
21 EfiHttpConfigure,\r
22 EfiHttpRequest,\r
23 EfiHttpCancel,\r
24 EfiHttpResponse,\r
25 EfiHttpPoll\r
26};\r
27\r
28/**\r
29 Returns the operational parameters for the current HTTP child instance.\r
30\r
31 The GetModeData() function is used to read the current mode data (operational\r
32 parameters) for this HTTP protocol instance.\r
33\r
34 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
35 @param[out] HttpConfigData Point to buffer for operational parameters of this\r
36 HTTP instance.\r
37\r
38 @retval EFI_SUCCESS Operation succeeded.\r
39 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
40 This is NULL.\r
41 HttpConfigData is NULL.\r
f0ab5a81
ZL
42 HttpInstance->LocalAddressIsIPv6 is FALSE and\r
43 HttpConfigData->IPv4Node is NULL.\r
44 HttpInstance->LocalAddressIsIPv6 is TRUE and\r
45 HttpConfigData->IPv6Node is NULL.\r
46 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
47f51a06
YT
47\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51EfiHttpGetModeData (\r
52 IN EFI_HTTP_PROTOCOL *This,\r
53 OUT EFI_HTTP_CONFIG_DATA *HttpConfigData\r
54 )\r
55{\r
56 HTTP_PROTOCOL *HttpInstance;\r
57\r
f0ab5a81
ZL
58 //\r
59 // Check input parameters.\r
60 //\r
47f51a06
YT
61 if ((This == NULL) || (HttpConfigData == NULL)) {\r
62 return EFI_INVALID_PARAMETER;\r
63 }\r
f0ab5a81 64\r
47f51a06
YT
65 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
66 ASSERT (HttpInstance != NULL);\r
f0ab5a81
ZL
67\r
68 if ((HttpInstance->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
69 (!HttpInstance->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv4Node == NULL)) {\r
70 return EFI_INVALID_PARAMETER;\r
71 }\r
72\r
47f51a06
YT
73 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {\r
74 return EFI_NOT_STARTED;\r
75 }\r
76\r
47f51a06
YT
77 HttpConfigData->HttpVersion = HttpInstance->HttpVersion;\r
78 HttpConfigData->TimeOutMillisec = HttpInstance->TimeOutMillisec;\r
79 HttpConfigData->LocalAddressIsIPv6 = HttpInstance->LocalAddressIsIPv6;\r
80\r
b659408b 81 if (HttpInstance->LocalAddressIsIPv6) {\r
b659408b 82 CopyMem (\r
f0ab5a81 83 HttpConfigData->AccessPoint.IPv6Node,\r
b659408b
ZL
84 &HttpInstance->Ipv6Node,\r
85 sizeof (HttpInstance->Ipv6Node)\r
47f51a06 86 );\r
b659408b 87 } else {\r
b659408b 88 CopyMem (\r
f0ab5a81 89 HttpConfigData->AccessPoint.IPv4Node,\r
b659408b
ZL
90 &HttpInstance->IPv4Node,\r
91 sizeof (HttpInstance->IPv4Node)\r
92 );\r
b659408b 93 }\r
47f51a06
YT
94\r
95 return EFI_SUCCESS;\r
96}\r
97\r
98/**\r
99 Initialize or brutally reset the operational parameters for this EFI HTTP instance.\r
100\r
101 The Configure() function does the following:\r
102 When HttpConfigData is not NULL Initialize this EFI HTTP instance by configuring\r
103 timeout, local address, port, etc.\r
104 When HttpConfigData is NULL, reset this EFI HTTP instance by closing all active\r
105 connections with remote hosts, canceling all asynchronous tokens, and flush request\r
106 and response buffers without informing the appropriate hosts.\r
107\r
f0ab5a81
ZL
108 No other EFI HTTP function can be executed by this instance until the Configure()\r
109 function is executed and returns successfully.\r
47f51a06
YT
110\r
111 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
112 @param[in] HttpConfigData Pointer to the configure data to configure the instance.\r
113\r
114 @retval EFI_SUCCESS Operation succeeded.\r
115 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
116 This is NULL.\r
117 HttpConfigData->LocalAddressIsIPv6 is FALSE and\r
118 HttpConfigData->IPv4Node is NULL.\r
119 HttpConfigData->LocalAddressIsIPv6 is TRUE and\r
120 HttpConfigData->IPv6Node is NULL.\r
121 @retval EFI_ALREADY_STARTED Reinitialize this HTTP instance without calling\r
122 Configure() with NULL to reset it.\r
123 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
124 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources when\r
125 executing Configure().\r
126 @retval EFI_UNSUPPORTED One or more options in HttpConfigData are not supported\r
127 in the implementation.\r
128**/\r
129EFI_STATUS\r
130EFIAPI\r
131EfiHttpConfigure (\r
132 IN EFI_HTTP_PROTOCOL *This,\r
30c9eaea 133 IN EFI_HTTP_CONFIG_DATA *HttpConfigData OPTIONAL\r
47f51a06
YT
134 ) \r
135{\r
136 HTTP_PROTOCOL *HttpInstance;\r
137 EFI_STATUS Status;\r
b659408b
ZL
138 \r
139 //\r
140 // Check input parameters.\r
141 //\r
f0ab5a81 142 if (This == NULL ||\r
6be1193f
JW
143 (HttpConfigData != NULL && \r
144 ((HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv6Node == NULL) ||\r
145 (!HttpConfigData->LocalAddressIsIPv6 && HttpConfigData->AccessPoint.IPv4Node == NULL)))) {\r
47f51a06
YT
146 return EFI_INVALID_PARAMETER;\r
147 }\r
148\r
149 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
150 ASSERT (HttpInstance != NULL && HttpInstance->Service != NULL);\r
151\r
152 if (HttpConfigData != NULL) {\r
b659408b 153\r
79de8c79
JW
154 if (HttpConfigData->HttpVersion >= HttpVersionUnsupported) {\r
155 return EFI_UNSUPPORTED;\r
156 }\r
157\r
47f51a06
YT
158 //\r
159 // Now configure this HTTP instance.\r
160 //\r
161 if (HttpInstance->State != HTTP_STATE_UNCONFIGED) {\r
162 return EFI_ALREADY_STARTED;\r
163 }\r
164\r
165 HttpInstance->HttpVersion = HttpConfigData->HttpVersion;\r
166 HttpInstance->TimeOutMillisec = HttpConfigData->TimeOutMillisec;\r
167 HttpInstance->LocalAddressIsIPv6 = HttpConfigData->LocalAddressIsIPv6;\r
b659408b
ZL
168 \r
169 if (HttpConfigData->LocalAddressIsIPv6) { \r
170 CopyMem (\r
171 &HttpInstance->Ipv6Node,\r
172 HttpConfigData->AccessPoint.IPv6Node,\r
173 sizeof (HttpInstance->Ipv6Node)\r
174 );\r
47f51a06
YT
175 } else {\r
176 CopyMem (\r
177 &HttpInstance->IPv4Node,\r
178 HttpConfigData->AccessPoint.IPv4Node,\r
179 sizeof (HttpInstance->IPv4Node)\r
180 );\r
47f51a06 181 }\r
b347a22a 182 \r
b659408b
ZL
183 //\r
184 // Creat Tcp child\r
185 //\r
186 Status = HttpInitProtocol (HttpInstance, HttpInstance->LocalAddressIsIPv6);\r
187 if (EFI_ERROR (Status)) {\r
188 return Status;\r
189 }\r
190 \r
191 HttpInstance->State = HTTP_STATE_HTTP_CONFIGED;\r
192 return EFI_SUCCESS;\r
47f51a06
YT
193\r
194 } else {\r
b659408b
ZL
195 //\r
196 // Reset all the resources related to HttpInsance.\r
197 //\r
198 HttpCleanProtocol (HttpInstance);\r
199 HttpInstance->State = HTTP_STATE_UNCONFIGED;\r
200 return EFI_SUCCESS;\r
47f51a06
YT
201 }\r
202}\r
203 \r
204\r
205/**\r
206 The Request() function queues an HTTP request to this HTTP instance.\r
207\r
208 Similar to Transmit() function in the EFI TCP driver. When the HTTP request is sent\r
209 successfully, or if there is an error, Status in token will be updated and Event will\r
210 be signaled.\r
211\r
212 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
213 @param[in] Token Pointer to storage containing HTTP request token.\r
214\r
215 @retval EFI_SUCCESS Outgoing data was processed.\r
216 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
217 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
218 @retval EFI_TIMEOUT Data was dropped out of the transmit or receive queue.\r
219 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
220 @retval EFI_UNSUPPORTED The HTTP method is not supported in current\r
221 implementation.\r
222 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
223 This is NULL.\r
f0ab5a81 224 Token is NULL.\r
47f51a06
YT
225 Token->Message is NULL.\r
226 Token->Message->Body is not NULL,\r
227 Token->Message->BodyLength is non-zero, and\r
228 Token->Message->Data is NULL, but a previous call to\r
229 Request()has not been completed successfully.\r
230**/\r
231EFI_STATUS\r
232EFIAPI\r
233EfiHttpRequest (\r
234 IN EFI_HTTP_PROTOCOL *This,\r
235 IN EFI_HTTP_TOKEN *Token\r
236 )\r
237{\r
238 EFI_HTTP_MESSAGE *HttpMsg;\r
239 EFI_HTTP_REQUEST_DATA *Request;\r
240 VOID *UrlParser;\r
241 EFI_STATUS Status;\r
242 CHAR8 *HostName;\r
b9679cd7 243 UINTN HostNameSize;\r
47f51a06
YT
244 UINT16 RemotePort;\r
245 HTTP_PROTOCOL *HttpInstance;\r
246 BOOLEAN Configure;\r
247 BOOLEAN ReConfigure;\r
dac45de3 248 BOOLEAN TlsConfigure;\r
19c25725 249 CHAR8 *RequestMsg;\r
47f51a06 250 CHAR8 *Url;\r
51b0450e 251 UINTN UrlLen;\r
47f51a06
YT
252 CHAR16 *HostNameStr;\r
253 HTTP_TOKEN_WRAP *Wrap;\r
b199d941 254 CHAR8 *FileUrl;\r
19c25725 255 UINTN RequestMsgSize;\r
7cf59c85 256 EFI_HANDLE ImageHandle;\r
d8293d31
NH
257\r
258 //\r
259 // Initializations\r
260 //\r
261 Url = NULL;\r
5646819f 262 UrlParser = NULL;\r
6be1193f 263 RemotePort = 0;\r
d8293d31
NH
264 HostName = NULL;\r
265 RequestMsg = NULL;\r
266 HostNameStr = NULL;\r
267 Wrap = NULL;\r
268 FileUrl = NULL;\r
dac45de3 269 TlsConfigure = FALSE;\r
d8293d31 270\r
47f51a06
YT
271 if ((This == NULL) || (Token == NULL)) {\r
272 return EFI_INVALID_PARAMETER;\r
273 }\r
274\r
275 HttpMsg = Token->Message;\r
d8293d31 276 if (HttpMsg == NULL) {\r
47f51a06
YT
277 return EFI_INVALID_PARAMETER;\r
278 }\r
279\r
47f51a06 280 Request = HttpMsg->Data.Request;\r
47f51a06
YT
281\r
282 //\r
97c567ef 283 // Only support GET, HEAD, PATCH, PUT and POST method in current implementation.\r
47f51a06 284 //\r
d8293d31 285 if ((Request != NULL) && (Request->Method != HttpMethodGet) &&\r
97c567ef
JW
286 (Request->Method != HttpMethodHead) && (Request->Method != HttpMethodPut) && \r
287 (Request->Method != HttpMethodPost) && (Request->Method != HttpMethodPatch)) {\r
47f51a06
YT
288 return EFI_UNSUPPORTED;\r
289 }\r
290\r
291 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
292 ASSERT (HttpInstance != NULL);\r
293\r
d8293d31
NH
294 //\r
295 // Capture the method into HttpInstance.\r
296 //\r
297 if (Request != NULL) {\r
298 HttpInstance->Method = Request->Method;\r
299 }\r
300\r
47f51a06
YT
301 if (HttpInstance->State < HTTP_STATE_HTTP_CONFIGED) {\r
302 return EFI_NOT_STARTED;\r
303 }\r
304\r
d8293d31
NH
305 if (Request == NULL) {\r
306 //\r
97c567ef 307 // Request would be NULL only for PUT/POST/PATCH operation (in the current implementation)\r
d8293d31 308 //\r
97c567ef
JW
309 if ((HttpInstance->Method != HttpMethodPut) && \r
310 (HttpInstance->Method != HttpMethodPost) && \r
311 (HttpInstance->Method != HttpMethodPatch)) {\r
d8293d31
NH
312 return EFI_INVALID_PARAMETER;\r
313 }\r
47f51a06 314\r
d8293d31 315 //\r
97c567ef 316 // For PUT/POST/PATCH, we need to have the TCP already configured. Bail out if it is not!\r
d8293d31
NH
317 //\r
318 if (HttpInstance->State < HTTP_STATE_TCP_CONFIGED) {\r
319 return EFI_INVALID_PARAMETER;\r
320 }\r
47f51a06 321\r
d8293d31
NH
322 //\r
323 // We need to have the Message Body for sending the HTTP message across in these cases.\r
324 //\r
325 if (HttpMsg->Body == NULL || HttpMsg->BodyLength == 0) {\r
326 return EFI_INVALID_PARAMETER;\r
51b0450e 327 }\r
b659408b 328\r
d8293d31
NH
329 //\r
330 // Use existing TCP instance to transmit the packet.\r
331 //\r
332 Configure = FALSE;\r
333 ReConfigure = FALSE;\r
334 } else {\r
335 //\r
336 // Check whether the token already existed.\r
337 //\r
338 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTokenExist, Token))) {\r
339 return EFI_ACCESS_DENIED;\r
340 }\r
47f51a06 341\r
d8293d31
NH
342 //\r
343 // Parse the URI of the remote host.\r
344 //\r
345 Url = HttpInstance->Url;\r
346 UrlLen = StrLen (Request->Url) + 1;\r
347 if (UrlLen > HTTP_URL_BUFFER_LEN) {\r
348 Url = AllocateZeroPool (UrlLen);\r
349 if (Url == NULL) {\r
350 return EFI_OUT_OF_RESOURCES;\r
351 }\r
352 FreePool (HttpInstance->Url);\r
353 HttpInstance->Url = Url;\r
354 }\r
47f51a06 355\r
47f51a06 356\r
b9679cd7 357 UnicodeStrToAsciiStrS (Request->Url, Url, UrlLen);\r
dac45de3
JW
358\r
359 //\r
360 // From the information in Url, the HTTP instance will \r
361 // be able to determine whether to use http or https.\r
362 //\r
363 HttpInstance->UseHttps = IsHttpsUrl (Url);\r
364\r
221463c2
JW
365 //\r
366 // HTTP is disabled, return directly if the URI is not HTTPS.\r
367 //\r
368 if (!PcdGetBool (PcdAllowHttpConnections) && !(HttpInstance->UseHttps)) {\r
369 \r
370 DEBUG ((EFI_D_ERROR, "EfiHttpRequest: HTTP is disabled.\n"));\r
371\r
372 return EFI_ACCESS_DENIED;\r
373 }\r
374\r
dac45de3
JW
375 //\r
376 // Check whether we need to create Tls child and open the TLS protocol.\r
377 //\r
378 if (HttpInstance->UseHttps && HttpInstance->TlsChildHandle == NULL) {\r
379 //\r
380 // Use TlsSb to create Tls child and open the TLS protocol.\r
381 //\r
7cf59c85
ZL
382 if (HttpInstance->LocalAddressIsIPv6) {\r
383 ImageHandle = HttpInstance->Service->Ip6DriverBindingHandle;\r
384 } else {\r
385 ImageHandle = HttpInstance->Service->Ip4DriverBindingHandle;\r
386 }\r
387\r
dac45de3 388 HttpInstance->TlsChildHandle = TlsCreateChild (\r
7cf59c85 389 ImageHandle,\r
45ea8a0c 390 &(HttpInstance->TlsSb),\r
dac45de3
JW
391 &(HttpInstance->Tls),\r
392 &(HttpInstance->TlsConfiguration)\r
393 );\r
394 if (HttpInstance->TlsChildHandle == NULL) {\r
395 return EFI_DEVICE_ERROR;\r
396 }\r
397\r
398 TlsConfigure = TRUE;\r
399 }\r
400\r
d8293d31
NH
401 UrlParser = NULL;\r
402 Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser);\r
403 if (EFI_ERROR (Status)) {\r
404 goto Error1;\r
405 }\r
47f51a06 406\r
d8293d31
NH
407 HostName = NULL;\r
408 Status = HttpUrlGetHostName (Url, UrlParser, &HostName);\r
409 if (EFI_ERROR (Status)) {\r
410 goto Error1;\r
411 }\r
412\r
413 Status = HttpUrlGetPort (Url, UrlParser, &RemotePort);\r
414 if (EFI_ERROR (Status)) {\r
dac45de3
JW
415 if (HttpInstance->UseHttps) {\r
416 RemotePort = HTTPS_DEFAULT_PORT;\r
417 } else {\r
418 RemotePort = HTTP_DEFAULT_PORT;\r
419 }\r
d8293d31 420 }\r
47f51a06 421 //\r
d8293d31
NH
422 // If Configure is TRUE, it indicates the first time to call Request();\r
423 // If ReConfigure is TRUE, it indicates the request URL is not same\r
424 // with the previous call to Request();\r
47f51a06 425 //\r
d8293d31
NH
426 Configure = TRUE;\r
427 ReConfigure = TRUE;\r
428\r
429 if (HttpInstance->RemoteHost == NULL) {\r
47f51a06 430 //\r
d8293d31 431 // Request() is called the first time.\r
47f51a06 432 //\r
d8293d31
NH
433 ReConfigure = FALSE;\r
434 } else {\r
435 if ((HttpInstance->RemotePort == RemotePort) &&\r
dac45de3
JW
436 (AsciiStrCmp (HttpInstance->RemoteHost, HostName) == 0) && \r
437 (!HttpInstance->UseHttps || (HttpInstance->UseHttps && \r
438 !TlsConfigure && \r
439 HttpInstance->TlsSessionState == EfiTlsSessionDataTransferring))) {\r
47f51a06 440 //\r
d8293d31 441 // Host Name and port number of the request URL are the same with previous call to Request().\r
dac45de3 442 // If Https protocol used, the corresponding SessionState is EfiTlsSessionDataTransferring.\r
d8293d31 443 // Check whether previous TCP packet sent out.\r
47f51a06 444 //\r
47f51a06 445\r
d8293d31
NH
446 if (EFI_ERROR (NetMapIterate (&HttpInstance->TxTokens, HttpTcpNotReady, NULL))) {\r
447 //\r
448 // Wrap the HTTP token in HTTP_TOKEN_WRAP\r
449 //\r
450 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
451 if (Wrap == NULL) {\r
452 Status = EFI_OUT_OF_RESOURCES;\r
453 goto Error1;\r
454 }\r
455\r
456 Wrap->HttpToken = Token;\r
457 Wrap->HttpInstance = HttpInstance;\r
458\r
459 Status = HttpCreateTcpTxEvent (Wrap);\r
460 if (EFI_ERROR (Status)) {\r
461 goto Error1;\r
462 }\r
463\r
464 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);\r
465 if (EFI_ERROR (Status)) {\r
466 goto Error1;\r
467 }\r
468\r
469 Wrap->TcpWrap.Method = Request->Method;\r
470\r
471 FreePool (HostName);\r
472\r
473 //\r
474 // Queue the HTTP token and return.\r
475 //\r
476 return EFI_SUCCESS;\r
477 } else {\r
478 //\r
479 // Use existing TCP instance to transmit the packet.\r
480 //\r
481 Configure = FALSE;\r
482 ReConfigure = FALSE;\r
47f51a06 483 }\r
47f51a06
YT
484 } else {\r
485 //\r
d8293d31 486 // Need close existing TCP instance and create a new TCP instance for data transmit.\r
47f51a06 487 //\r
d8293d31
NH
488 if (HttpInstance->RemoteHost != NULL) {\r
489 FreePool (HttpInstance->RemoteHost);\r
490 HttpInstance->RemoteHost = NULL;\r
491 HttpInstance->RemotePort = 0;\r
492 }\r
47f51a06
YT
493 }\r
494 }\r
495 } \r
496\r
497 if (Configure) {\r
498 //\r
b659408b 499 // Parse Url for IPv4 or IPv6 address, if failed, perform DNS resolution.\r
47f51a06 500 //\r
b659408b
ZL
501 if (!HttpInstance->LocalAddressIsIPv6) {\r
502 Status = NetLibAsciiStrToIp4 (HostName, &HttpInstance->RemoteAddr);\r
503 } else {\r
ac458853 504 Status = HttpUrlGetIp6 (Url, UrlParser, &HttpInstance->RemoteIpv6Addr);\r
b659408b
ZL
505 }\r
506\r
47f51a06 507 if (EFI_ERROR (Status)) {\r
b9679cd7
SZ
508 HostNameSize = AsciiStrSize (HostName);\r
509 HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));\r
47f51a06
YT
510 if (HostNameStr == NULL) {\r
511 Status = EFI_OUT_OF_RESOURCES;\r
512 goto Error1;\r
513 }\r
b659408b 514 \r
b9679cd7 515 AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
b659408b
ZL
516 if (!HttpInstance->LocalAddressIsIPv6) {\r
517 Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr);\r
518 } else {\r
519 Status = HttpDns6 (HttpInstance, HostNameStr, &HttpInstance->RemoteIpv6Addr);\r
520 }\r
521 \r
47f51a06
YT
522 FreePool (HostNameStr);\r
523 if (EFI_ERROR (Status)) {\r
524 goto Error1;\r
525 }\r
526 }\r
527\r
528 //\r
529 // Save the RemotePort and RemoteHost.\r
530 //\r
531 ASSERT (HttpInstance->RemoteHost == NULL);\r
532 HttpInstance->RemotePort = RemotePort;\r
533 HttpInstance->RemoteHost = HostName;\r
534 HostName = NULL;\r
535 }\r
536\r
537 if (ReConfigure) {\r
538 //\r
539 // The request URL is different from previous calls to Request(), close existing TCP instance.\r
540 //\r
a2e61982
ZL
541 if (!HttpInstance->LocalAddressIsIPv6) {\r
542 ASSERT (HttpInstance->Tcp4 != NULL);\r
543 } else {\r
544 ASSERT (HttpInstance->Tcp6 != NULL);\r
545 }\r
dac45de3
JW
546\r
547 if (HttpInstance->UseHttps && !TlsConfigure) {\r
548 Status = TlsCloseSession (HttpInstance);\r
549 if (EFI_ERROR (Status)) {\r
550 goto Error1;\r
551 }\r
552 \r
553 TlsCloseTxRxEvent (HttpInstance);\r
554 }\r
555 \r
47f51a06
YT
556 HttpCloseConnection (HttpInstance);\r
557 EfiHttpCancel (This, NULL);\r
558 }\r
559\r
560 //\r
561 // Wrap the HTTP token in HTTP_TOKEN_WRAP\r
562 //\r
563 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
564 if (Wrap == NULL) {\r
565 Status = EFI_OUT_OF_RESOURCES;\r
566 goto Error1;\r
567 }\r
568\r
569 Wrap->HttpToken = Token;\r
570 Wrap->HttpInstance = HttpInstance;\r
d8293d31
NH
571 if (Request != NULL) {\r
572 Wrap->TcpWrap.Method = Request->Method;\r
573 }\r
dac45de3
JW
574 \r
575 Status = HttpInitSession (\r
576 HttpInstance, \r
577 Wrap, \r
578 Configure || ReConfigure, \r
579 TlsConfigure\r
580 );\r
a2e61982
ZL
581 if (EFI_ERROR (Status)) {\r
582 goto Error2;\r
dac45de3 583 }\r
b659408b 584\r
dac45de3 585 if (!Configure && !ReConfigure && !TlsConfigure) {\r
47f51a06
YT
586 //\r
587 // For the new HTTP token, create TX TCP token events. \r
588 //\r
b659408b 589 Status = HttpCreateTcpTxEvent (Wrap);\r
47f51a06
YT
590 if (EFI_ERROR (Status)) {\r
591 goto Error1;\r
592 }\r
593 }\r
a2e61982 594 \r
47f51a06
YT
595 //\r
596 // Create request message.\r
597 //\r
b199d941 598 FileUrl = Url;\r
d8293d31 599 if (Url != NULL && *FileUrl != '/') {\r
b199d941
GCPL
600 //\r
601 // Convert the absolute-URI to the absolute-path\r
602 //\r
603 while (*FileUrl != ':') {\r
604 FileUrl++;\r
605 }\r
606 if ((*(FileUrl+1) == '/') && (*(FileUrl+2) == '/')) {\r
607 FileUrl += 3;\r
608 while (*FileUrl != '/') {\r
609 FileUrl++;\r
610 }\r
611 } else {\r
612 Status = EFI_INVALID_PARAMETER;\r
613 goto Error3;\r
614 }\r
615 }\r
f58554fc 616\r
19c25725 617 Status = HttpGenRequestMessage (HttpMsg, FileUrl, &RequestMsg, &RequestMsgSize);\r
f58554fc 618\r
63f1d6a4 619 if (EFI_ERROR (Status) || NULL == RequestMsg) {\r
47f51a06
YT
620 goto Error3;\r
621 }\r
622\r
63f1d6a4
JW
623 ASSERT (RequestMsg != NULL);\r
624\r
d8293d31
NH
625 //\r
626 // Every request we insert a TxToken and a response call would remove the TxToken.\r
97c567ef 627 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
628 // continuous request without a response call. So, in such cases, where Request\r
629 // structure is NULL, we would not insert a TxToken.\r
630 //\r
631 if (Request != NULL) {\r
632 Status = NetMapInsertTail (&HttpInstance->TxTokens, Token, Wrap);\r
633 if (EFI_ERROR (Status)) {\r
634 goto Error4;\r
635 }\r
47f51a06
YT
636 }\r
637\r
47f51a06
YT
638 //\r
639 // Transmit the request message.\r
640 //\r
b659408b 641 Status = HttpTransmitTcp (\r
47f51a06
YT
642 HttpInstance,\r
643 Wrap,\r
19c25725
NH
644 (UINT8*) RequestMsg,\r
645 RequestMsgSize\r
47f51a06
YT
646 );\r
647 if (EFI_ERROR (Status)) {\r
648 goto Error5; \r
649 }\r
650\r
49c9f74c 651 DispatchDpc ();\r
b659408b 652 \r
cdf8c32e
NH
653 if (HostName != NULL) {\r
654 FreePool (HostName);\r
655 }\r
b659408b 656 \r
47f51a06
YT
657 return EFI_SUCCESS;\r
658\r
659Error5:\r
30526a51
JW
660 //\r
661 // We would have inserted a TxToken only if Request structure is not NULL.\r
662 // Hence check before we do a remove in this error case.\r
663 //\r
664 if (Request != NULL) {\r
665 NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
666 }\r
47f51a06
YT
667\r
668Error4:\r
19c25725
NH
669 if (RequestMsg != NULL) {\r
670 FreePool (RequestMsg);\r
47f51a06
YT
671 } \r
672\r
673Error3:\r
dac45de3
JW
674 if (HttpInstance->UseHttps) {\r
675 TlsCloseSession (HttpInstance);\r
676 TlsCloseTxRxEvent (HttpInstance);\r
677 }\r
47f51a06 678\r
47f51a06 679Error2:\r
dac45de3
JW
680 HttpCloseConnection (HttpInstance);\r
681 \r
b659408b
ZL
682 HttpCloseTcpConnCloseEvent (HttpInstance);\r
683 if (NULL != Wrap->TcpWrap.Tx4Token.CompletionToken.Event) {\r
684 gBS->CloseEvent (Wrap->TcpWrap.Tx4Token.CompletionToken.Event);\r
685 Wrap->TcpWrap.Tx4Token.CompletionToken.Event = NULL;\r
686 }\r
687 if (NULL != Wrap->TcpWrap.Tx6Token.CompletionToken.Event) {\r
688 gBS->CloseEvent (Wrap->TcpWrap.Tx6Token.CompletionToken.Event);\r
689 Wrap->TcpWrap.Tx6Token.CompletionToken.Event = NULL;\r
47f51a06
YT
690 }\r
691\r
692Error1:\r
47f51a06
YT
693 if (HostName != NULL) {\r
694 FreePool (HostName);\r
695 }\r
696 if (Wrap != NULL) {\r
697 FreePool (Wrap);\r
698 }\r
699 if (UrlParser!= NULL) {\r
700 HttpUrlFreeParser (UrlParser);\r
701 }\r
702\r
703 return Status;\r
704 \r
705}\r
706\r
707/**\r
b659408b 708 Cancel a user's Token. \r
47f51a06
YT
709 \r
710 @param[in] Map The HTTP instance's token queue.\r
711 @param[in] Item Object container for one HTTP token and token's wrap.\r
712 @param[in] Context The user's token to cancel.\r
713\r
714 @retval EFI_SUCCESS Continue to check the next Item.\r
715 @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.\r
716\r
717**/\r
718EFI_STATUS\r
719EFIAPI\r
720HttpCancelTokens (\r
721 IN NET_MAP *Map,\r
722 IN NET_MAP_ITEM *Item,\r
723 IN VOID *Context\r
724 )\r
725{\r
47f51a06
YT
726 EFI_HTTP_TOKEN *Token;\r
727 HTTP_TOKEN_WRAP *Wrap;\r
b659408b 728 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
729\r
730 Token = (EFI_HTTP_TOKEN *) Context;\r
731\r
732 //\r
733 // Return EFI_SUCCESS to check the next item in the map if\r
734 // this one doesn't match.\r
735 //\r
736 if ((Token != NULL) && (Token != Item->Key)) {\r
737 return EFI_SUCCESS;\r
738 }\r
739\r
740 Wrap = (HTTP_TOKEN_WRAP *) Item->Value;\r
741 ASSERT (Wrap != NULL);\r
b659408b 742 HttpInstance = Wrap->HttpInstance;\r
47f51a06 743 \r
b659408b 744 if (!HttpInstance->LocalAddressIsIPv6) {\r
b659408b 745 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
30526a51
JW
746 //\r
747 // Cancle the Token before close its Event.\r
748 //\r
749 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &Wrap->TcpWrap.Rx4Token.CompletionToken);\r
47f51a06 750\r
30526a51
JW
751 //\r
752 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
753 //\r
754 DispatchDpc ();\r
b659408b 755 }\r
30526a51 756 } else {\r
b659408b 757 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
30526a51
JW
758 //\r
759 // Cancle the Token before close its Event.\r
760 //\r
761 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &Wrap->TcpWrap.Rx6Token.CompletionToken);\r
47f51a06 762\r
30526a51
JW
763 //\r
764 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
765 //\r
766 DispatchDpc ();\r
b659408b 767 }\r
47f51a06
YT
768 }\r
769\r
47f51a06
YT
770 //\r
771 // If only one item is to be cancel, return EFI_ABORTED to stop\r
772 // iterating the map any more.\r
773 //\r
774 if (Token != NULL) {\r
775 return EFI_ABORTED;\r
776 }\r
777\r
778 return EFI_SUCCESS; \r
779}\r
780\r
781/**\r
782 Cancel the user's receive/transmit request. It is the worker function of\r
783 EfiHttpCancel API. If a matching token is found, it will call HttpCancelTokens to cancel the\r
784 token.\r
785\r
786 @param[in] HttpInstance Pointer to HTTP_PROTOCOL structure.\r
787 @param[in] Token The token to cancel. If NULL, all token will be\r
788 cancelled.\r
789\r
790 @retval EFI_SUCCESS The token is cancelled.\r
791 @retval EFI_NOT_FOUND The asynchronous request or response token is not found. \r
792 @retval Others Other error as indicated.\r
793\r
794**/\r
795EFI_STATUS\r
796HttpCancel (\r
797 IN HTTP_PROTOCOL *HttpInstance,\r
798 IN EFI_HTTP_TOKEN *Token\r
799 )\r
800{\r
801 EFI_STATUS Status;\r
802\r
803 //\r
804 // First check the tokens queued by EfiHttpRequest().\r
805 //\r
806 Status = NetMapIterate (&HttpInstance->TxTokens, HttpCancelTokens, Token);\r
807 if (EFI_ERROR (Status)) {\r
808 if (Token != NULL) {\r
809 if (Status == EFI_ABORTED) {\r
810 return EFI_SUCCESS;\r
811 } \r
812 } else {\r
813 return Status;\r
814 }\r
815 }\r
816\r
dac45de3
JW
817 if (!HttpInstance->UseHttps) {\r
818 //\r
819 // Then check the tokens queued by EfiHttpResponse(), except for Https.\r
820 //\r
821 Status = NetMapIterate (&HttpInstance->RxTokens, HttpCancelTokens, Token);\r
822 if (EFI_ERROR (Status)) {\r
823 if (Token != NULL) {\r
824 if (Status == EFI_ABORTED) {\r
825 return EFI_SUCCESS;\r
826 } else {\r
827 return EFI_NOT_FOUND;\r
828 }\r
47f51a06 829 } else {\r
dac45de3 830 return Status;\r
47f51a06 831 }\r
dac45de3
JW
832 }\r
833 } else {\r
834 if (!HttpInstance->LocalAddressIsIPv6) {\r
835 HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &HttpInstance->Tcp4TlsRxToken.CompletionToken);\r
47f51a06 836 } else {\r
dac45de3 837 HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &HttpInstance->Tcp6TlsRxToken.CompletionToken);\r
47f51a06
YT
838 }\r
839 }\r
dac45de3 840 \r
47f51a06
YT
841 return EFI_SUCCESS;\r
842}\r
843\r
844\r
845/**\r
846 Abort an asynchronous HTTP request or response token.\r
847\r
848 The Cancel() function aborts a pending HTTP request or response transaction. If\r
849 Token is not NULL and the token is in transmit or receive queues when it is being\r
850 cancelled, its Token->Status will be set to EFI_ABORTED and then Token->Event will\r
851 be signaled. If the token is not in one of the queues, which usually means that the\r
852 asynchronous operation has completed, EFI_NOT_FOUND is returned. If Token is NULL,\r
853 all asynchronous tokens issued by Request() or Response() will be aborted.\r
854\r
855 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
856 @param[in] Token Point to storage containing HTTP request or response\r
857 token.\r
858\r
859 @retval EFI_SUCCESS Request and Response queues are successfully flushed.\r
860 @retval EFI_INVALID_PARAMETER This is NULL.\r
861 @retval EFI_NOT_STARTED This instance hasn't been configured.\r
47f51a06
YT
862 @retval EFI_NOT_FOUND The asynchronous request or response token is not\r
863 found.\r
864 @retval EFI_UNSUPPORTED The implementation does not support this function.\r
865\r
866**/\r
867EFI_STATUS\r
868EFIAPI\r
869EfiHttpCancel (\r
870 IN EFI_HTTP_PROTOCOL *This,\r
871 IN EFI_HTTP_TOKEN *Token\r
872 )\r
873{\r
874 HTTP_PROTOCOL *HttpInstance;\r
875\r
876 if (This == NULL) {\r
877 return EFI_INVALID_PARAMETER;\r
878 }\r
879\r
880 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
881 ASSERT (HttpInstance != NULL);\r
882\r
883 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
884 return EFI_NOT_STARTED;\r
885 }\r
886\r
887 return HttpCancel (HttpInstance, Token);\r
888\r
889}\r
890\r
891/**\r
892 A callback function to intercept events during message parser.\r
893\r
894 This function will be invoked during HttpParseMessageBody() with various events type. An error\r
895 return status of the callback function will cause the HttpParseMessageBody() aborted.\r
896\r
897 @param[in] EventType Event type of this callback call.\r
898 @param[in] Data A pointer to data buffer.\r
899 @param[in] Length Length in bytes of the Data.\r
900 @param[in] Context Callback context set by HttpInitMsgParser().\r
901\r
902 @retval EFI_SUCCESS Continue to parser the message body.\r
903\r
904**/\r
905EFI_STATUS\r
906EFIAPI\r
907HttpBodyParserCallback (\r
908 IN HTTP_BODY_PARSE_EVENT EventType,\r
909 IN CHAR8 *Data,\r
910 IN UINTN Length,\r
911 IN VOID *Context\r
912 )\r
913{\r
914 HTTP_TOKEN_WRAP *Wrap;\r
5ba9f065
ZL
915 UINTN BodyLength;\r
916 CHAR8 *Body;\r
47f51a06
YT
917\r
918 if (EventType != BodyParseEventOnComplete) {\r
919 return EFI_SUCCESS;\r
920 }\r
921\r
922 if (Data == NULL || Length != 0 || Context == NULL) {\r
923 return EFI_SUCCESS;\r
924 }\r
925\r
926 Wrap = (HTTP_TOKEN_WRAP *) Context;\r
5ba9f065
ZL
927 Body = Wrap->HttpToken->Message->Body;\r
928 BodyLength = Wrap->HttpToken->Message->BodyLength;\r
929 if (Data < Body + BodyLength) {\r
930 Wrap->HttpInstance->NextMsg = Data;\r
931 } else {\r
932 Wrap->HttpInstance->NextMsg = NULL;\r
933 }\r
934 \r
47f51a06
YT
935\r
936 //\r
b659408b 937 // Free Tx4Token or Tx6Token since already received corrsponding HTTP response.\r
47f51a06
YT
938 //\r
939 FreePool (Wrap);\r
940\r
941 return EFI_SUCCESS;\r
942}\r
943\r
944/**\r
945 The work function of EfiHttpResponse().\r
946\r
947 @param[in] Wrap Pointer to HTTP token's wrap data.\r
948\r
949 @retval EFI_SUCCESS Allocation succeeded.\r
950 @retval EFI_OUT_OF_RESOURCES Failed to complete the opration due to lack of resources.\r
b659408b 951 @retval EFI_NOT_READY Can't find a corresponding Tx4Token/Tx6Token or \r
5ca29abe 952 the EFI_HTTP_UTILITIES_PROTOCOL is not available.\r
47f51a06
YT
953\r
954**/\r
955EFI_STATUS\r
956HttpResponseWorker (\r
957 IN HTTP_TOKEN_WRAP *Wrap\r
958 )\r
959{\r
960 EFI_STATUS Status;\r
961 EFI_HTTP_MESSAGE *HttpMsg;\r
47f51a06
YT
962 CHAR8 *EndofHeader;\r
963 CHAR8 *HttpHeaders;\r
964 UINTN SizeofHeaders;\r
47f51a06
YT
965 UINTN BufferSize;\r
966 UINTN StatusCode;\r
967 CHAR8 *Tmp;\r
968 CHAR8 *HeaderTmp;\r
969 CHAR8 *StatusCodeStr;\r
970 UINTN BodyLen;\r
971 HTTP_PROTOCOL *HttpInstance;\r
972 EFI_HTTP_TOKEN *Token;\r
973 NET_MAP_ITEM *Item;\r
974 HTTP_TOKEN_WRAP *ValueInItem;\r
975 UINTN HdrLen;\r
dac45de3 976 NET_FRAGMENT Fragment;\r
47f51a06 977\r
3fd7bd08 978 if (Wrap == NULL || Wrap->HttpInstance == NULL) {\r
979 return EFI_INVALID_PARAMETER;\r
980 }\r
981 \r
47f51a06
YT
982 HttpInstance = Wrap->HttpInstance;\r
983 Token = Wrap->HttpToken;\r
47f51a06
YT
984 HttpMsg = Token->Message;\r
985\r
b659408b
ZL
986 HttpInstance->EndofHeader = NULL;\r
987 HttpInstance->HttpHeaders = NULL;\r
988 HttpMsg->Headers = NULL;\r
989 HttpHeaders = NULL;\r
990 SizeofHeaders = 0;\r
991 BufferSize = 0;\r
992 EndofHeader = NULL;\r
6be1193f 993 ValueInItem = NULL;\r
dac45de3
JW
994 Fragment.Len = 0;\r
995 Fragment.Bulk = NULL;\r
47f51a06
YT
996 \r
997 if (HttpMsg->Data.Response != NULL) {\r
47f51a06
YT
998 //\r
999 // Check whether we have cached header from previous call.\r
1000 //\r
1001 if ((HttpInstance->CacheBody != NULL) && (HttpInstance->NextMsg != NULL)) {\r
1002 //\r
1003 // The data is stored at [NextMsg, CacheBody + CacheLen].\r
1004 //\r
1005 HdrLen = HttpInstance->CacheBody + HttpInstance->CacheLen - HttpInstance->NextMsg;\r
1006 HttpHeaders = AllocateZeroPool (HdrLen);\r
1007 if (HttpHeaders == NULL) {\r
1008 Status = EFI_OUT_OF_RESOURCES;\r
1009 goto Error;\r
1010 }\r
1011\r
1012 CopyMem (HttpHeaders, HttpInstance->NextMsg, HdrLen);\r
1013 FreePool (HttpInstance->CacheBody);\r
1014 HttpInstance->CacheBody = NULL;\r
1015 HttpInstance->NextMsg = NULL;\r
1016 HttpInstance->CacheOffset = 0;\r
1017 SizeofHeaders = HdrLen;\r
1018 BufferSize = HttpInstance->CacheLen;\r
1019\r
1020 //\r
1021 // Check whether we cached the whole HTTP headers.\r
1022 //\r
1023 EndofHeader = AsciiStrStr (HttpHeaders, HTTP_END_OF_HDR_STR); \r
b659408b 1024 } \r
47f51a06 1025\r
b659408b
ZL
1026 HttpInstance->EndofHeader = &EndofHeader;\r
1027 HttpInstance->HttpHeaders = &HttpHeaders;\r
47f51a06 1028\r
b347a22a
JW
1029\r
1030 if (HttpInstance->TimeoutEvent == NULL) {\r
1031 //\r
1032 // Create TimeoutEvent for response\r
1033 //\r
1034 Status = gBS->CreateEvent (\r
1035 EVT_TIMER,\r
1036 TPL_CALLBACK,\r
1037 NULL,\r
1038 NULL,\r
1039 &HttpInstance->TimeoutEvent\r
1040 );\r
1041 if (EFI_ERROR (Status)) {\r
1042 goto Error;\r
1043 }\r
1044 }\r
1045\r
1046 //\r
1047 // Start the timer, and wait Timeout seconds to receive the header packet.\r
1048 //\r
1049 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1050 if (EFI_ERROR (Status)) {\r
1051 goto Error;\r
1052 }\r
1053\r
1054 Status = HttpTcpReceiveHeader (HttpInstance, &SizeofHeaders, &BufferSize, HttpInstance->TimeoutEvent);\r
1055\r
1056 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
1057\r
b659408b
ZL
1058 if (EFI_ERROR (Status)) {\r
1059 goto Error;\r
1060 }\r
47f51a06 1061\r
1b96428d
ZL
1062 ASSERT (HttpHeaders != NULL);\r
1063\r
47f51a06
YT
1064 //\r
1065 // Cache the part of body.\r
1066 //\r
1067 BodyLen = BufferSize - (EndofHeader - HttpHeaders);\r
1068 if (BodyLen > 0) {\r
1069 if (HttpInstance->CacheBody != NULL) {\r
1070 FreePool (HttpInstance->CacheBody);\r
1071 }\r
1072\r
1073 HttpInstance->CacheBody = AllocateZeroPool (BodyLen);\r
1074 if (HttpInstance->CacheBody == NULL) {\r
1075 Status = EFI_OUT_OF_RESOURCES;\r
1076 goto Error;\r
1077 }\r
1078\r
1079 CopyMem (HttpInstance->CacheBody, EndofHeader, BodyLen);\r
1080 HttpInstance->CacheLen = BodyLen;\r
1081 }\r
1082\r
47f51a06
YT
1083 //\r
1084 // Search for Status Code.\r
1085 //\r
1086 StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;\r
1087 if (StatusCodeStr == NULL) {\r
30526a51 1088 Status = EFI_NOT_READY;\r
47f51a06
YT
1089 goto Error;\r
1090 }\r
1091\r
1092 StatusCode = AsciiStrDecimalToUintn (StatusCodeStr);\r
1093\r
1094 //\r
1095 // Remove the first line of HTTP message, e.g. "HTTP/1.1 200 OK\r\n".\r
1096 //\r
1097 Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);\r
1098 if (Tmp == NULL) {\r
30526a51 1099 Status = EFI_NOT_READY;\r
47f51a06
YT
1100 goto Error;\r
1101 }\r
1102\r
47f51a06 1103 //\r
d8293d31
NH
1104 // We could have response with just a HTTP message and no headers. For Example,\r
1105 // "100 Continue". In such cases, we would not want to unnecessarily call a Parse\r
1106 // method. A "\r\n" following Tmp string again would indicate an end. Compare and\r
1107 // set SizeofHeaders to 0.\r
47f51a06 1108 //\r
d8293d31
NH
1109 Tmp = Tmp + AsciiStrLen (HTTP_CRLF_STR);\r
1110 if (CompareMem (Tmp, HTTP_CRLF_STR, AsciiStrLen (HTTP_CRLF_STR)) == 0) {\r
1111 SizeofHeaders = 0;\r
1112 } else {\r
1113 SizeofHeaders = SizeofHeaders - (Tmp - HttpHeaders);\r
47f51a06
YT
1114 }\r
1115\r
47f51a06 1116 HttpMsg->Data.Response->StatusCode = HttpMappingToStatusCode (StatusCode);\r
072289f4 1117 HttpInstance->StatusCode = StatusCode;\r
d8293d31 1118\r
47f51a06
YT
1119 Status = EFI_NOT_READY;\r
1120 ValueInItem = NULL;\r
47f51a06
YT
1121\r
1122 //\r
97c567ef 1123 // In cases of PUT/POST/PATCH, after an initial request-response pair, we would do a\r
d8293d31
NH
1124 // continuous request without a response call. So, we would not do an insert of\r
1125 // TxToken. After we have sent the complete file, we will call a response to get\r
1126 // a final response from server. In such a case, we would not have any TxTokens.\r
1127 // Hence, check that case before doing a NetMapRemoveHead.\r
47f51a06 1128 //\r
d8293d31
NH
1129 if (!NetMapIsEmpty (&HttpInstance->TxTokens)) {\r
1130 NetMapRemoveHead (&HttpInstance->TxTokens, (VOID**) &ValueInItem);\r
1131 if (ValueInItem == NULL) {\r
1132 goto Error;\r
1133 }\r
47f51a06 1134\r
d8293d31
NH
1135 //\r
1136 // The first Tx Token not transmitted yet, insert back and return error.\r
1137 //\r
1138 if (!ValueInItem->TcpWrap.IsTxDone) {\r
1139 goto Error2;\r
1140 }\r
47f51a06
YT
1141 }\r
1142\r
d8293d31
NH
1143 if (SizeofHeaders != 0) {\r
1144 HeaderTmp = AllocateZeroPool (SizeofHeaders);\r
1145 if (HeaderTmp == NULL) {\r
30526a51 1146 Status = EFI_OUT_OF_RESOURCES;\r
5646819f 1147 goto Error2;\r
d8293d31
NH
1148 }\r
1149\r
1150 CopyMem (HeaderTmp, Tmp, SizeofHeaders);\r
1151 FreePool (HttpHeaders);\r
1152 HttpHeaders = HeaderTmp;\r
1153\r
1154 //\r
1155 // Check whether the EFI_HTTP_UTILITIES_PROTOCOL is available.\r
1156 //\r
1157 if (mHttpUtilities == NULL) {\r
1158 Status = EFI_NOT_READY;\r
5646819f 1159 goto Error2;\r
d8293d31
NH
1160 }\r
1161\r
1162 //\r
1163 // Parse the HTTP header into array of key/value pairs.\r
1164 //\r
1165 Status = mHttpUtilities->Parse (\r
1166 mHttpUtilities,\r
1167 HttpHeaders,\r
1168 SizeofHeaders,\r
1169 &HttpMsg->Headers,\r
1170 &HttpMsg->HeaderCount\r
1171 );\r
1172 if (EFI_ERROR (Status)) {\r
5646819f 1173 goto Error2;\r
d8293d31
NH
1174 }\r
1175\r
1176 FreePool (HttpHeaders);\r
1177 HttpHeaders = NULL;\r
1178\r
1179\r
1180 //\r
1181 // Init message-body parser by header information.\r
1182 //\r
1183 Status = HttpInitMsgParser (\r
1184 HttpInstance->Method,\r
1185 HttpMsg->Data.Response->StatusCode,\r
1186 HttpMsg->HeaderCount,\r
1187 HttpMsg->Headers,\r
1188 HttpBodyParserCallback,\r
1189 (VOID *) ValueInItem,\r
1190 &HttpInstance->MsgParser\r
1191 );\r
47f51a06
YT
1192 if (EFI_ERROR (Status)) {\r
1193 goto Error2;\r
1194 }\r
1195\r
d8293d31
NH
1196 //\r
1197 // Check whether we received a complete HTTP message.\r
1198 //\r
1199 if (HttpInstance->CacheBody != NULL) {\r
1200 Status = HttpParseMessageBody (HttpInstance->MsgParser, HttpInstance->CacheLen, HttpInstance->CacheBody);\r
1201 if (EFI_ERROR (Status)) {\r
1202 goto Error2;\r
1203 }\r
1204\r
1205 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1206 //\r
1207 // Free the MsgParse since we already have a full HTTP message.\r
1208 //\r
1209 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1210 HttpInstance->MsgParser = NULL;\r
1211 }\r
47f51a06
YT
1212 }\r
1213 }\r
1214\r
d8293d31 1215 if ((HttpMsg->Body == NULL) || (HttpMsg->BodyLength == 0)) {\r
47f51a06
YT
1216 Status = EFI_SUCCESS;\r
1217 goto Exit;\r
1218 }\r
d8293d31 1219 }\r
47f51a06
YT
1220\r
1221 //\r
1222 // Receive the response body.\r
1223 //\r
1224 BodyLen = 0;\r
1225\r
1226 //\r
1227 // First check whether we cached some data.\r
1228 //\r
1229 if (HttpInstance->CacheBody != NULL) {\r
1230 //\r
1231 // Calculate the length of the cached data.\r
1232 //\r
1233 if (HttpInstance->NextMsg != NULL) {\r
1234 //\r
1235 // We have a cached HTTP message which includes a part of HTTP header of next message.\r
1236 //\r
1237 BodyLen = HttpInstance->NextMsg - (HttpInstance->CacheBody + HttpInstance->CacheOffset); \r
1238 } else {\r
1239 BodyLen = HttpInstance->CacheLen - HttpInstance->CacheOffset;\r
1240 }\r
1241\r
1242 if (BodyLen > 0) {\r
1243 //\r
1244 // We have some cached data. Just copy the data and return.\r
1245 //\r
1246 if (HttpMsg->BodyLength < BodyLen) {\r
1247 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, HttpMsg->BodyLength);\r
1248 HttpInstance->CacheOffset = HttpInstance->CacheOffset + HttpMsg->BodyLength;\r
1249 } else {\r
1250 //\r
1251 // Copy all cached data out.\r
1252 //\r
1253 CopyMem (HttpMsg->Body, HttpInstance->CacheBody + HttpInstance->CacheOffset, BodyLen);\r
1254 HttpInstance->CacheOffset = BodyLen + HttpInstance->CacheOffset;\r
1255 HttpMsg->BodyLength = BodyLen;\r
1256\r
1257 if (HttpInstance->NextMsg == NULL) {\r
1258 //\r
1259 // There is no HTTP header of next message. Just free the cache buffer.\r
1260 //\r
1261 FreePool (HttpInstance->CacheBody);\r
1262 HttpInstance->CacheBody = NULL;\r
1263 HttpInstance->NextMsg = NULL;\r
1264 HttpInstance->CacheOffset = 0;\r
1265 }\r
1266 }\r
1267 //\r
1268 // Return since we aready received required data.\r
1269 //\r
1270 Status = EFI_SUCCESS;\r
1271 goto Exit;\r
1272 } \r
1273\r
1274 if (BodyLen == 0 && HttpInstance->MsgParser == NULL) {\r
1275 //\r
1276 // We received a complete HTTP message, and we don't have more data to return to caller.\r
1277 //\r
1278 HttpMsg->BodyLength = 0;\r
1279 Status = EFI_SUCCESS;\r
1280 goto Exit; \r
1281 } \r
1282 }\r
1283\r
1284 ASSERT (HttpInstance->MsgParser != NULL);\r
1285\r
1286 //\r
1287 // We still need receive more data when there is no cache data and MsgParser is not NULL;\r
1288 //\r
dac45de3
JW
1289 if (!HttpInstance->UseHttps) {\r
1290 Status = HttpTcpReceiveBody (Wrap, HttpMsg);\r
1291\r
1292 if (EFI_ERROR (Status)) {\r
1293 goto Error2;\r
1294 }\r
1295 \r
1296 } else {\r
1297 if (HttpInstance->TimeoutEvent == NULL) {\r
1298 //\r
1299 // Create TimeoutEvent for response\r
1300 //\r
1301 Status = gBS->CreateEvent (\r
1302 EVT_TIMER,\r
1303 TPL_CALLBACK,\r
1304 NULL,\r
1305 NULL,\r
1306 &HttpInstance->TimeoutEvent\r
1307 );\r
1308 if (EFI_ERROR (Status)) {\r
1309 goto Error2;\r
1310 }\r
1311 }\r
1312\r
1313 //\r
1314 // Start the timer, and wait Timeout seconds to receive the body packet.\r
1315 //\r
1316 Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
1317 if (EFI_ERROR (Status)) {\r
1318 goto Error2;\r
1319 }\r
1320 \r
1321 Status = HttpsReceive (HttpInstance, &Fragment, HttpInstance->TimeoutEvent);\r
1322\r
1323 gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
1324 \r
1325 if (EFI_ERROR (Status)) {\r
1326 goto Error2;\r
1327 }\r
1328\r
1329 //\r
1330 // Check whether we receive a complete HTTP message.\r
1331 //\r
1332 Status = HttpParseMessageBody (\r
1333 HttpInstance->MsgParser,\r
1334 (UINTN) Fragment.Len,\r
1335 (CHAR8 *) Fragment.Bulk\r
1336 );\r
1337 if (EFI_ERROR (Status)) {\r
1338 goto Error2;\r
1339 }\r
1340\r
1341 if (HttpIsMessageComplete (HttpInstance->MsgParser)) {\r
1342 //\r
1343 // Free the MsgParse since we already have a full HTTP message.\r
1344 //\r
1345 HttpFreeMsgParser (HttpInstance->MsgParser);\r
1346 HttpInstance->MsgParser = NULL;\r
1347 }\r
1348\r
1349 //\r
1350 // We receive part of header of next HTTP msg.\r
1351 //\r
1352 if (HttpInstance->NextMsg != NULL) {\r
cb7dbc13 1353 HttpMsg->BodyLength = MIN ((UINTN) HttpInstance->NextMsg - (UINTN) Fragment.Bulk, HttpMsg->BodyLength);\r
dac45de3
JW
1354 CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
1355 \r
1356 HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
1357 if (HttpInstance->CacheLen != 0) {\r
1358 if (HttpInstance->CacheBody != NULL) {\r
1359 FreePool (HttpInstance->CacheBody);\r
1360 }\r
1361 \r
1362 HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen);\r
1363 if (HttpInstance->CacheBody == NULL) {\r
1364 Status = EFI_OUT_OF_RESOURCES;\r
1365 goto Error2;\r
1366 }\r
1367 \r
1368 CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
1369 HttpInstance->CacheOffset = 0;\r
1370\r
cb7dbc13 1371 HttpInstance->NextMsg = HttpInstance->CacheBody + ((UINTN) HttpInstance->NextMsg - (UINTN) (Fragment.Bulk + HttpMsg->BodyLength));\r
dac45de3
JW
1372 }\r
1373 } else {\r
1374 HttpMsg->BodyLength = MIN (Fragment.Len, (UINT32) HttpMsg->BodyLength);\r
1375 CopyMem (HttpMsg->Body, Fragment.Bulk, HttpMsg->BodyLength);\r
1376 HttpInstance->CacheLen = Fragment.Len - HttpMsg->BodyLength;\r
1377 if (HttpInstance->CacheLen != 0) {\r
1378 if (HttpInstance->CacheBody != NULL) {\r
1379 FreePool (HttpInstance->CacheBody);\r
1380 }\r
1381 \r
1382 HttpInstance->CacheBody = AllocateZeroPool (HttpInstance->CacheLen);\r
1383 if (HttpInstance->CacheBody == NULL) {\r
1384 Status = EFI_OUT_OF_RESOURCES;\r
1385 goto Error2;\r
1386 }\r
1387\r
1388 CopyMem (HttpInstance->CacheBody, Fragment.Bulk + HttpMsg->BodyLength, HttpInstance->CacheLen);\r
1389 HttpInstance->CacheOffset = 0;\r
1390 }\r
1391 }\r
1392\r
1393 if (Fragment.Bulk != NULL) {\r
1394 FreePool (Fragment.Bulk);\r
1395 Fragment.Bulk = NULL;\r
1396 }\r
1397\r
1398 goto Exit;\r
47f51a06
YT
1399 }\r
1400\r
1401 return Status;\r
1402\r
1403Exit:\r
1404 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1405 if (Item != NULL) {\r
1406 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1407 }\r
072289f4
ZL
1408\r
1409 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1410 Token->Status = EFI_HTTP_ERROR;\r
1411 } else {\r
1412 Token->Status = Status;\r
1413 }\r
1414\r
47f51a06 1415 gBS->SignalEvent (Token->Event);\r
b659408b 1416 HttpCloseTcpRxEvent (Wrap);\r
47f51a06
YT
1417 FreePool (Wrap);\r
1418 return Status;\r
1419\r
1420Error2:\r
5646819f
FS
1421 if (ValueInItem != NULL) {\r
1422 NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem);\r
1423 }\r
47f51a06
YT
1424\r
1425Error:\r
30526a51
JW
1426 Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
1427 if (Item != NULL) {\r
1428 NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
1429 }\r
dac45de3
JW
1430\r
1431 if (!HttpInstance->UseHttps) {\r
1432 HttpTcpTokenCleanup (Wrap);\r
1433 } else {\r
1434 FreePool (Wrap);\r
1435 }\r
47f51a06
YT
1436 \r
1437 if (HttpHeaders != NULL) {\r
1438 FreePool (HttpHeaders);\r
dac45de3
JW
1439 HttpHeaders = NULL;\r
1440 }\r
1441\r
1442 if (Fragment.Bulk != NULL) {\r
1443 FreePool (Fragment.Bulk);\r
1444 Fragment.Bulk = NULL;\r
47f51a06
YT
1445 }\r
1446\r
1447 if (HttpMsg->Headers != NULL) {\r
1448 FreePool (HttpMsg->Headers);\r
dac45de3 1449 HttpMsg->Headers = NULL;\r
47f51a06
YT
1450 }\r
1451\r
1452 if (HttpInstance->CacheBody != NULL) {\r
1453 FreePool (HttpInstance->CacheBody);\r
1454 HttpInstance->CacheBody = NULL;\r
1455 }\r
1456\r
072289f4
ZL
1457 if (HttpInstance->StatusCode >= HTTP_ERROR_OR_NOT_SUPPORT_STATUS_CODE) {\r
1458 Token->Status = EFI_HTTP_ERROR;\r
1459 } else {\r
1460 Token->Status = Status;\r
1461 }\r
1462\r
47f51a06
YT
1463 gBS->SignalEvent (Token->Event);\r
1464\r
1465 return Status; \r
1466\r
1467}\r
1468\r
1469\r
1470/**\r
1471 The Response() function queues an HTTP response to this HTTP instance, similar to\r
f0ab5a81 1472 Receive() function in the EFI TCP driver. When the HTTP response is received successfully,\r
47f51a06
YT
1473 or if there is an error, Status in token will be updated and Event will be signaled.\r
1474\r
1475 The HTTP driver will queue a receive token to the underlying TCP instance. When data\r
1476 is received in the underlying TCP instance, the data will be parsed and Token will\r
1477 be populated with the response data. If the data received from the remote host\r
1478 contains an incomplete or invalid HTTP header, the HTTP driver will continue waiting\r
1479 (asynchronously) for more data to be sent from the remote host before signaling\r
1480 Event in Token.\r
1481\r
1482 It is the responsibility of the caller to allocate a buffer for Body and specify the\r
1483 size in BodyLength. If the remote host provides a response that contains a content\r
1484 body, up to BodyLength bytes will be copied from the receive buffer into Body and\r
1485 BodyLength will be updated with the amount of bytes received and copied to Body. This\r
1486 allows the client to download a large file in chunks instead of into one contiguous\r
1487 block of memory. Similar to HTTP request, if Body is not NULL and BodyLength is\r
1488 non-zero and all other fields are NULL or 0, the HTTP driver will queue a receive\r
1489 token to underlying TCP instance. If data arrives in the receive buffer, up to\r
1490 BodyLength bytes of data will be copied to Body. The HTTP driver will then update\r
1491 BodyLength with the amount of bytes received and copied to Body.\r
1492\r
1493 If the HTTP driver does not have an open underlying TCP connection with the host\r
1494 specified in the response URL, Request() will return EFI_ACCESS_DENIED. This is\r
1495 consistent with RFC 2616 recommendation that HTTP clients should attempt to maintain\r
1496 an open TCP connection between client and host.\r
1497\r
1498 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1499 @param[in] Token Pointer to storage containing HTTP response token.\r
1500\r
1501 @retval EFI_SUCCESS Allocation succeeded.\r
1502 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been\r
1503 initialized.\r
1504 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
1505 This is NULL.\r
1506 Token is NULL.\r
1507 Token->Message->Headers is NULL.\r
1508 Token->Message is NULL.\r
1509 Token->Message->Body is not NULL,\r
1510 Token->Message->BodyLength is non-zero, and\r
1511 Token->Message->Data is NULL, but a previous call to\r
1512 Response() has not been completed successfully.\r
1513 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
1514 @retval EFI_ACCESS_DENIED An open TCP connection is not present with the host\r
1515 specified by response URL.\r
1516**/\r
1517EFI_STATUS\r
1518EFIAPI\r
1519EfiHttpResponse (\r
1520 IN EFI_HTTP_PROTOCOL *This,\r
1521 IN EFI_HTTP_TOKEN *Token\r
1522 )\r
1523{\r
1524 EFI_STATUS Status;\r
1525 EFI_HTTP_MESSAGE *HttpMsg;\r
1526 HTTP_PROTOCOL *HttpInstance;\r
1527 HTTP_TOKEN_WRAP *Wrap;\r
1528\r
1529 if ((This == NULL) || (Token == NULL)) {\r
1530 return EFI_INVALID_PARAMETER;\r
1531 }\r
1532\r
1533 HttpMsg = Token->Message;\r
1534 if (HttpMsg == NULL) {\r
1535 return EFI_INVALID_PARAMETER;\r
1536 }\r
1537 \r
1538 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
1539 ASSERT (HttpInstance != NULL);\r
1540\r
1541 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
1542 return EFI_NOT_STARTED;\r
1543 }\r
1544\r
47f51a06
YT
1545 //\r
1546 // Check whether the token already existed.\r
1547 //\r
1548 if (EFI_ERROR (NetMapIterate (&HttpInstance->RxTokens, HttpTokenExist, Token))) {\r
1549 return EFI_ACCESS_DENIED; \r
1550 }\r
1551\r
1552 Wrap = AllocateZeroPool (sizeof (HTTP_TOKEN_WRAP));\r
1553 if (Wrap == NULL) {\r
1554 return EFI_OUT_OF_RESOURCES;\r
1555 }\r
1556\r
1557 Wrap->HttpInstance = HttpInstance;\r
1558 Wrap->HttpToken = Token;\r
1559\r
dac45de3
JW
1560 //\r
1561 // Notes: For Https, receive token wrapped in HTTP_TOKEN_WRAP is not used to \r
1562 // receive the https response. A special TlsRxToken is used for receiving TLS \r
1563 // related messages. It should be a blocking response.\r
1564 //\r
1565 if (!HttpInstance->UseHttps) {\r
1566 Status = HttpCreateTcpRxEvent (Wrap);\r
1567 if (EFI_ERROR (Status)) {\r
1568 goto Error;\r
1569 }\r
47f51a06
YT
1570 }\r
1571\r
1572 Status = NetMapInsertTail (&HttpInstance->RxTokens, Token, Wrap);\r
1573 if (EFI_ERROR (Status)) {\r
1574 goto Error;\r
1575 }\r
1576\r
1577 //\r
1578 // If already have pending RxTokens, return directly.\r
1579 //\r
1580 if (NetMapGetCount (&HttpInstance->RxTokens) > 1) {\r
1581 return EFI_SUCCESS;\r
1582 }\r
1583\r
1584 return HttpResponseWorker (Wrap);\r
1585\r
1586Error:\r
1587 if (Wrap != NULL) {\r
b659408b
ZL
1588 if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
1589 gBS->CloseEvent (Wrap->TcpWrap.Rx4Token.CompletionToken.Event);\r
1590 }\r
1591\r
1592 if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
1593 gBS->CloseEvent (Wrap->TcpWrap.Rx6Token.CompletionToken.Event);\r
47f51a06
YT
1594 }\r
1595 FreePool (Wrap);\r
1596 } \r
1597\r
1598 return Status; \r
1599}\r
1600\r
1601/**\r
1602 The Poll() function can be used by network drivers and applications to increase the\r
1603 rate that data packets are moved between the communication devices and the transmit\r
1604 and receive queues.\r
1605\r
1606 In some systems, the periodic timer event in the managed network driver may not poll\r
1607 the underlying communications device fast enough to transmit and/or receive all data\r
1608 packets without missing incoming packets or dropping outgoing packets. Drivers and\r
1609 applications that are experiencing packet loss should try calling the Poll() function\r
1610 more often.\r
1611\r
1612 @param[in] This Pointer to EFI_HTTP_PROTOCOL instance.\r
1613\r
1614 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
1615 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1616 @retval EFI_INVALID_PARAMETER This is NULL.\r
1617 @retval EFI_NOT_READY No incoming or outgoing data is processed.\r
1618 @retval EFI_NOT_STARTED This EFI HTTP Protocol instance has not been started.\r
1619\r
1620**/\r
1621EFI_STATUS\r
1622EFIAPI\r
1623EfiHttpPoll (\r
1624 IN EFI_HTTP_PROTOCOL *This\r
1625 )\r
1626{\r
49c9f74c 1627 EFI_STATUS Status;\r
b659408b 1628 HTTP_PROTOCOL *HttpInstance;\r
47f51a06
YT
1629\r
1630 if (This == NULL) {\r
1631 return EFI_INVALID_PARAMETER;\r
1632 }\r
1633\r
1634 HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (This);\r
1635 ASSERT (HttpInstance != NULL);\r
1636\r
1b96428d 1637 if (HttpInstance->State != HTTP_STATE_TCP_CONNECTED) {\r
47f51a06
YT
1638 return EFI_NOT_STARTED;\r
1639 }\r
b659408b
ZL
1640 \r
1641 if (HttpInstance->LocalAddressIsIPv6) {\r
1b96428d
ZL
1642 if (HttpInstance->Tcp6 == NULL) {\r
1643 return EFI_NOT_STARTED;\r
1644 }\r
b659408b
ZL
1645 Status = HttpInstance->Tcp6->Poll (HttpInstance->Tcp6);\r
1646 } else {\r
1b96428d
ZL
1647 if (HttpInstance->Tcp4 == NULL) {\r
1648 return EFI_NOT_STARTED;\r
1649 }\r
b659408b
ZL
1650 Status = HttpInstance->Tcp4->Poll (HttpInstance->Tcp4);\r
1651 }\r
1652 \r
49c9f74c 1653 DispatchDpc ();\r
b659408b 1654 \r
49c9f74c 1655 return Status;\r
47f51a06 1656}\r