2 Support functions implementation for UEFI HTTP boot driver.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "HttpBootDxe.h"
19 Get the Nic handle using any child handle in the IPv4 stack.
21 @param[in] ControllerHandle Pointer to child handle over IPv4.
23 @return NicHandle The pointer to the Nic handle.
24 @return NULL Can't find the Nic handle.
28 HttpBootGetNicByIp4Children (
29 IN EFI_HANDLE ControllerHandle
34 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiHttpProtocolGuid
);
35 if (NicHandle
== NULL
) {
36 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp4ProtocolGuid
);
37 if (NicHandle
== NULL
) {
46 Get the Nic handle using any child handle in the IPv6 stack.
48 @param[in] ControllerHandle Pointer to child handle over IPv6.
50 @return NicHandle The pointer to the Nic handle.
51 @return NULL Can't find the Nic handle.
55 HttpBootGetNicByIp6Children (
56 IN EFI_HANDLE ControllerHandle
60 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiHttpProtocolGuid
);
61 if (NicHandle
== NULL
) {
62 NicHandle
= NetLibGetNicHandle (ControllerHandle
, &gEfiDhcp6ProtocolGuid
);
63 if (NicHandle
== NULL
) {
72 This function is to convert UINTN to ASCII string with the required formatting.
74 @param[in] Number Numeric value to be converted.
75 @param[in] Buffer The pointer to the buffer for ASCII string.
76 @param[in] Length The length of the required format.
80 HttpBootUintnToAscDecWithFormat (
90 Remainder
= Number
% 10;
92 Buffer
[Length
] = (UINT8
) ('0' + Remainder
);
97 This function is to display the IPv4 address.
99 @param[in] Ip The pointer to the IPv4 address.
103 HttpBootShowIp4Addr (
104 IN EFI_IPv4_ADDRESS
*Ip
109 for (Index
= 0; Index
< 4; Index
++) {
110 AsciiPrint ("%d", Ip
->Addr
[Index
]);
118 This function is to display the IPv6 address.
120 @param[in] Ip The pointer to the IPv6 address.
124 HttpBootShowIp6Addr (
125 IN EFI_IPv6_ADDRESS
*Ip
130 for (Index
= 0; Index
< 16; Index
++) {
132 if (Ip
->Addr
[Index
] != 0) {
133 AsciiPrint ("%x", Ip
->Addr
[Index
]);
139 if (((Ip
->Addr
[Index
] & 0xf0) == 0) && (Ip
->Addr
[Index
- 1] != 0)) {
142 AsciiPrint ("%x", Ip
->Addr
[Index
]);
150 This function is to display the HTTP error status.
152 @param[in] StatusCode The status code value in HTTP message.
156 HttpBootPrintErrorMessage (
157 EFI_HTTP_STATUS_CODE StatusCode
162 switch (StatusCode
) {
163 case HTTP_STATUS_300_MULTIPLE_CHIOCES
:
164 AsciiPrint ("\n Redirection: 300 Multiple Choices");
167 case HTTP_STATUS_301_MOVED_PERMANENTLY
:
168 AsciiPrint ("\n Redirection: 301 Moved Permanently");
171 case HTTP_STATUS_302_FOUND
:
172 AsciiPrint ("\n Redirection: 302 Found");
175 case HTTP_STATUS_303_SEE_OTHER
:
176 AsciiPrint ("\n Redirection: 303 See Other");
179 case HTTP_STATUS_304_NOT_MODIFIED
:
180 AsciiPrint ("\n Redirection: 304 Not Modified");
183 case HTTP_STATUS_305_USE_PROXY
:
184 AsciiPrint ("\n Redirection: 305 Use Proxy");
187 case HTTP_STATUS_307_TEMPORARY_REDIRECT
:
188 AsciiPrint ("\n Redirection: 307 Temporary Redirect");
191 case HTTP_STATUS_400_BAD_REQUEST
:
192 AsciiPrint ("\n Client Error: 400 Bad Request");
195 case HTTP_STATUS_401_UNAUTHORIZED
:
196 AsciiPrint ("\n Client Error: 401 Unauthorized");
199 case HTTP_STATUS_402_PAYMENT_REQUIRED
:
200 AsciiPrint ("\n Client Error: 402 Payment Required");
203 case HTTP_STATUS_403_FORBIDDEN
:
204 AsciiPrint ("\n Client Error: 403 Forbidden");
207 case HTTP_STATUS_404_NOT_FOUND
:
208 AsciiPrint ("\n Client Error: 404 Not Found");
211 case HTTP_STATUS_405_METHOD_NOT_ALLOWED
:
212 AsciiPrint ("\n Client Error: 405 Method Not Allowed");
215 case HTTP_STATUS_406_NOT_ACCEPTABLE
:
216 AsciiPrint ("\n Client Error: 406 Not Acceptable");
219 case HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED
:
220 AsciiPrint ("\n Client Error: 407 Proxy Authentication Required");
223 case HTTP_STATUS_408_REQUEST_TIME_OUT
:
224 AsciiPrint ("\n Client Error: 408 Request Timeout");
227 case HTTP_STATUS_409_CONFLICT
:
228 AsciiPrint ("\n Client Error: 409 Conflict");
231 case HTTP_STATUS_410_GONE
:
232 AsciiPrint ("\n Client Error: 410 Gone");
235 case HTTP_STATUS_411_LENGTH_REQUIRED
:
236 AsciiPrint ("\n Client Error: 411 Length Required");
239 case HTTP_STATUS_412_PRECONDITION_FAILED
:
240 AsciiPrint ("\n Client Error: 412 Precondition Failed");
243 case HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE
:
244 AsciiPrint ("\n Client Error: 413 Request Entity Too Large");
247 case HTTP_STATUS_414_REQUEST_URI_TOO_LARGE
:
248 AsciiPrint ("\n Client Error: 414 Request URI Too Long");
251 case HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE
:
252 AsciiPrint ("\n Client Error: 415 Unsupported Media Type");
255 case HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED
:
256 AsciiPrint ("\n Client Error: 416 Requested Range Not Satisfiable");
259 case HTTP_STATUS_417_EXPECTATION_FAILED
:
260 AsciiPrint ("\n Client Error: 417 Expectation Failed");
263 case HTTP_STATUS_500_INTERNAL_SERVER_ERROR
:
264 AsciiPrint ("\n Server Error: 500 Internal Server Error");
267 case HTTP_STATUS_501_NOT_IMPLEMENTED
:
268 AsciiPrint ("\n Server Error: 501 Not Implemented");
271 case HTTP_STATUS_502_BAD_GATEWAY
:
272 AsciiPrint ("\n Server Error: 502 Bad Gateway");
275 case HTTP_STATUS_503_SERVICE_UNAVAILABLE
:
276 AsciiPrint ("\n Server Error: 503 Service Unavailable");
279 case HTTP_STATUS_504_GATEWAY_TIME_OUT
:
280 AsciiPrint ("\n Server Error: 504 Gateway Timeout");
283 case HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED
:
284 AsciiPrint ("\n Server Error: 505 HTTP Version Not Supported");
293 Notify the callback function when an event is triggered.
295 @param[in] Event The triggered event.
296 @param[in] Context The opaque parameter to the function.
301 HttpBootCommonNotify (
306 *((BOOLEAN
*) Context
) = TRUE
;
310 Retrieve the host address using the EFI_DNS6_PROTOCOL.
312 @param[in] Private The pointer to the driver's private data.
313 @param[in] HostName Pointer to buffer containing hostname.
314 @param[out] IpAddress On output, pointer to buffer containing IPv6 address.
316 @retval EFI_SUCCESS Operation succeeded.
317 @retval EFI_DEVICE_ERROR An unexpected network error occurred.
318 @retval Others Other errors as indicated.
322 IN HTTP_BOOT_PRIVATE_DATA
*Private
,
324 OUT EFI_IPv6_ADDRESS
*IpAddress
328 EFI_DNS6_PROTOCOL
*Dns6
;
329 EFI_DNS6_CONFIG_DATA Dns6ConfigData
;
330 EFI_DNS6_COMPLETION_TOKEN Token
;
331 EFI_HANDLE Dns6Handle
;
332 EFI_IP6_CONFIG_PROTOCOL
*Ip6Config
;
333 EFI_IPv6_ADDRESS
*DnsServerList
;
334 UINTN DnsServerListCount
;
338 DnsServerList
= NULL
;
339 DnsServerListCount
= 0;
342 ZeroMem (&Token
, sizeof (EFI_DNS6_COMPLETION_TOKEN
));
345 // Get DNS server list from EFI IPv6 Configuration protocol.
347 Status
= gBS
->HandleProtocol (Private
->Controller
, &gEfiIp6ConfigProtocolGuid
, (VOID
**) &Ip6Config
);
348 if (!EFI_ERROR (Status
)) {
350 // Get the required size.
353 Status
= Ip6Config
->GetData (Ip6Config
, Ip6ConfigDataTypeDnsServer
, &DataSize
, NULL
);
354 if (Status
== EFI_BUFFER_TOO_SMALL
) {
355 DnsServerList
= AllocatePool (DataSize
);
356 if (DnsServerList
== NULL
) {
357 return EFI_OUT_OF_RESOURCES
;
360 Status
= Ip6Config
->GetData (Ip6Config
, Ip6ConfigDataTypeDnsServer
, &DataSize
, DnsServerList
);
361 if (EFI_ERROR (Status
)) {
362 FreePool (DnsServerList
);
363 DnsServerList
= NULL
;
365 DnsServerListCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
370 // Create a DNSv6 child instance and get the protocol.
372 Status
= NetLibCreateServiceChild (
375 &gEfiDns6ServiceBindingProtocolGuid
,
378 if (EFI_ERROR (Status
)) {
382 Status
= gBS
->OpenProtocol (
384 &gEfiDns6ProtocolGuid
,
388 EFI_OPEN_PROTOCOL_BY_DRIVER
390 if (EFI_ERROR (Status
)) {
395 // Configure DNS6 instance for the DNS server address and protocol.
397 ZeroMem (&Dns6ConfigData
, sizeof (EFI_DNS6_CONFIG_DATA
));
398 Dns6ConfigData
.DnsServerCount
= (UINT32
)DnsServerListCount
;
399 Dns6ConfigData
.DnsServerList
= DnsServerList
;
400 Dns6ConfigData
.EnableDnsCache
= TRUE
;
401 Dns6ConfigData
.Protocol
= EFI_IP_PROTO_UDP
;
402 IP6_COPY_ADDRESS (&Dns6ConfigData
.StationIp
,&Private
->StationIp
.v6
);
403 Status
= Dns6
->Configure (
407 if (EFI_ERROR (Status
)) {
411 Token
.Status
= EFI_NOT_READY
;
414 // Create event to set the IsDone flag when name resolution is finished.
416 Status
= gBS
->CreateEvent (
419 HttpBootCommonNotify
,
423 if (EFI_ERROR (Status
)) {
428 // Start asynchronous name resolution.
430 Status
= Dns6
->HostNameToIp (Dns6
, HostName
, &Token
);
431 if (EFI_ERROR (Status
)) {
440 // Name resolution is done, check result.
442 Status
= Token
.Status
;
443 if (!EFI_ERROR (Status
)) {
444 if (Token
.RspData
.H2AData
== NULL
) {
445 Status
= EFI_DEVICE_ERROR
;
448 if (Token
.RspData
.H2AData
->IpCount
== 0 || Token
.RspData
.H2AData
->IpList
== NULL
) {
449 Status
= EFI_DEVICE_ERROR
;
453 // We just return the first IPv6 address from DNS protocol.
455 IP6_COPY_ADDRESS (IpAddress
, Token
.RspData
.H2AData
->IpList
);
456 Status
= EFI_SUCCESS
;
460 if (Token
.Event
!= NULL
) {
461 gBS
->CloseEvent (Token
.Event
);
463 if (Token
.RspData
.H2AData
!= NULL
) {
464 if (Token
.RspData
.H2AData
->IpList
!= NULL
) {
465 FreePool (Token
.RspData
.H2AData
->IpList
);
467 FreePool (Token
.RspData
.H2AData
);
471 Dns6
->Configure (Dns6
, NULL
);
475 &gEfiDns6ProtocolGuid
,
481 if (Dns6Handle
!= NULL
) {
482 NetLibDestroyServiceChild (
485 &gEfiDns6ServiceBindingProtocolGuid
,
490 if (DnsServerList
!= NULL
) {
491 FreePool (DnsServerList
);
497 Create a HTTP_IO_HEADER to hold the HTTP header items.
499 @param[in] MaxHeaderCount The maximun number of HTTP header in this holder.
501 @return A pointer of the HTTP header holder or NULL if failed.
505 HttpBootCreateHeader (
509 HTTP_IO_HEADER
*HttpIoHeader
;
511 if (MaxHeaderCount
== 0) {
515 HttpIoHeader
= AllocateZeroPool (sizeof (HTTP_IO_HEADER
) + MaxHeaderCount
* sizeof (EFI_HTTP_HEADER
));
516 if (HttpIoHeader
== NULL
) {
520 HttpIoHeader
->MaxHeaderCount
= MaxHeaderCount
;
521 HttpIoHeader
->Headers
= (EFI_HTTP_HEADER
*) (HttpIoHeader
+ 1);
527 Destroy the HTTP_IO_HEADER and release the resouces.
529 @param[in] HttpIoHeader Point to the HTTP header holder to be destroyed.
534 IN HTTP_IO_HEADER
*HttpIoHeader
539 if (HttpIoHeader
!= NULL
) {
540 if (HttpIoHeader
->HeaderCount
!= 0) {
541 for (Index
= 0; Index
< HttpIoHeader
->HeaderCount
; Index
++) {
542 FreePool (HttpIoHeader
->Headers
[Index
].FieldName
);
543 FreePool (HttpIoHeader
->Headers
[Index
].FieldValue
);
546 FreePool (HttpIoHeader
);
551 Find a specified header field according to the field name.
553 @param[in] HeaderCount Number of HTTP header structures in Headers list.
554 @param[in] Headers Array containing list of HTTP headers.
555 @param[in] FieldName Null terminated string which describes a field name.
557 @return Pointer to the found header or NULL.
562 IN UINTN HeaderCount
,
563 IN EFI_HTTP_HEADER
*Headers
,
569 if (HeaderCount
== 0 || Headers
== NULL
|| FieldName
== NULL
) {
573 for (Index
= 0; Index
< HeaderCount
; Index
++){
575 // Field names are case-insensitive (RFC 2616).
577 if (AsciiStriCmp (Headers
[Index
].FieldName
, FieldName
) == 0) {
578 return &Headers
[Index
];
585 Set or update a HTTP header with the field name and corresponding value.
587 @param[in] HttpIoHeader Point to the HTTP header holder.
588 @param[in] FieldName Null terminated string which describes a field name.
589 @param[in] FieldValue Null terminated string which describes the corresponding field value.
591 @retval EFI_SUCCESS The HTTP header has been set or updated.
592 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
593 @retval EFI_OUT_OF_RESOURCES Insufficient resource to complete the operation.
594 @retval Other Unexpected error happened.
599 IN HTTP_IO_HEADER
*HttpIoHeader
,
604 EFI_HTTP_HEADER
*Header
;
606 CHAR8
*NewFieldValue
;
608 if (HttpIoHeader
== NULL
|| FieldName
== NULL
|| FieldValue
== NULL
) {
609 return EFI_INVALID_PARAMETER
;
612 Header
= HttpBootFindHeader (HttpIoHeader
->HeaderCount
, HttpIoHeader
->Headers
, FieldName
);
613 if (Header
== NULL
) {
617 if (HttpIoHeader
->HeaderCount
>= HttpIoHeader
->MaxHeaderCount
) {
618 return EFI_OUT_OF_RESOURCES
;
620 Header
= &HttpIoHeader
->Headers
[HttpIoHeader
->HeaderCount
];
622 StrSize
= AsciiStrSize (FieldName
);
623 Header
->FieldName
= AllocatePool (StrSize
);
624 if (Header
->FieldName
== NULL
) {
625 return EFI_OUT_OF_RESOURCES
;
627 CopyMem (Header
->FieldName
, FieldName
, StrSize
);
628 Header
->FieldName
[StrSize
-1] = '\0';
630 StrSize
= AsciiStrSize (FieldValue
);
631 Header
->FieldValue
= AllocatePool (StrSize
);
632 if (Header
->FieldValue
== NULL
) {
633 FreePool (Header
->FieldName
);
634 return EFI_OUT_OF_RESOURCES
;
636 CopyMem (Header
->FieldValue
, FieldValue
, StrSize
);
637 Header
->FieldValue
[StrSize
-1] = '\0';
639 HttpIoHeader
->HeaderCount
++;
642 // Update an existing one.
644 StrSize
= AsciiStrSize (FieldValue
);
645 NewFieldValue
= AllocatePool (StrSize
);
646 if (NewFieldValue
== NULL
) {
647 return EFI_OUT_OF_RESOURCES
;
649 CopyMem (NewFieldValue
, FieldValue
, StrSize
);
650 NewFieldValue
[StrSize
-1] = '\0';
652 if (Header
->FieldValue
!= NULL
) {
653 FreePool (Header
->FieldValue
);
655 Header
->FieldValue
= NewFieldValue
;
662 Create a HTTP_IO to access the HTTP service. It will create and configure
665 @param[in] Image The handle of the driver image.
666 @param[in] Controller The handle of the controller.
667 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
668 @param[in] ConfigData The HTTP_IO configuration data.
669 @param[out] HttpIo The HTTP_IO.
671 @retval EFI_SUCCESS The HTTP_IO is created and configured.
672 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
673 @retval EFI_UNSUPPORTED One or more of the control options are not
674 supported in the implementation.
675 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
676 @retval Others Failed to create the HTTP_IO or configure it.
682 IN EFI_HANDLE Controller
,
684 IN HTTP_IO_CONFIG_DATA
*ConfigData
,
689 EFI_HTTP_CONFIG_DATA HttpConfigData
;
690 EFI_HTTPv4_ACCESS_POINT Http4AccessPoint
;
691 EFI_HTTPv6_ACCESS_POINT Http6AccessPoint
;
692 EFI_HTTP_PROTOCOL
*Http
;
695 if ((Image
== NULL
) || (Controller
== NULL
) || (ConfigData
== NULL
) || (HttpIo
== NULL
)) {
696 return EFI_INVALID_PARAMETER
;
699 if (IpVersion
!= IP_VERSION_4
&& IpVersion
!= IP_VERSION_6
) {
700 return EFI_UNSUPPORTED
;
703 ZeroMem (HttpIo
, sizeof (HTTP_IO
));
706 // Create the HTTP child instance and get the HTTP protocol.
708 Status
= NetLibCreateServiceChild (
711 &gEfiHttpServiceBindingProtocolGuid
,
714 if (EFI_ERROR (Status
)) {
718 Status
= gBS
->OpenProtocol (
720 &gEfiHttpProtocolGuid
,
724 EFI_OPEN_PROTOCOL_BY_DRIVER
726 if (EFI_ERROR (Status
) || (Http
== NULL
)) {
731 // Init the configuration data and configure the HTTP child.
733 HttpIo
->Image
= Image
;
734 HttpIo
->Controller
= Controller
;
735 HttpIo
->IpVersion
= IpVersion
;
738 ZeroMem (&HttpConfigData
, sizeof (EFI_HTTP_CONFIG_DATA
));
739 HttpConfigData
.HttpVersion
= HttpVersion11
;
740 HttpConfigData
.TimeOutMillisec
= ConfigData
->Config4
.RequestTimeOut
;
741 if (HttpIo
->IpVersion
== IP_VERSION_4
) {
742 HttpConfigData
.LocalAddressIsIPv6
= FALSE
;
744 Http4AccessPoint
.UseDefaultAddress
= ConfigData
->Config4
.UseDefaultAddress
;
745 Http4AccessPoint
.LocalPort
= ConfigData
->Config4
.LocalPort
;
746 IP4_COPY_ADDRESS (&Http4AccessPoint
.LocalAddress
, &ConfigData
->Config4
.LocalIp
);
747 IP4_COPY_ADDRESS (&Http4AccessPoint
.LocalSubnet
, &ConfigData
->Config4
.SubnetMask
);
748 HttpConfigData
.AccessPoint
.IPv4Node
= &Http4AccessPoint
;
750 HttpConfigData
.LocalAddressIsIPv6
= TRUE
;
751 Http6AccessPoint
.LocalPort
= ConfigData
->Config6
.LocalPort
;
752 IP6_COPY_ADDRESS (&Http6AccessPoint
.LocalAddress
, &ConfigData
->Config6
.LocalIp
);
753 HttpConfigData
.AccessPoint
.IPv6Node
= &Http6AccessPoint
;
756 Status
= Http
->Configure (Http
, &HttpConfigData
);
757 if (EFI_ERROR (Status
)) {
762 // Create events for variuos asynchronous operations.
764 Status
= gBS
->CreateEvent (
767 HttpBootCommonNotify
,
771 if (EFI_ERROR (Status
)) {
774 HttpIo
->ReqToken
.Event
= Event
;
775 HttpIo
->ReqToken
.Message
= &HttpIo
->ReqMessage
;
777 Status
= gBS
->CreateEvent (
780 HttpBootCommonNotify
,
784 if (EFI_ERROR (Status
)) {
787 HttpIo
->RspToken
.Event
= Event
;
788 HttpIo
->RspToken
.Message
= &HttpIo
->RspMessage
;
793 HttpIoDestroyIo (HttpIo
);
799 Destroy the HTTP_IO and release the resouces.
801 @param[in] HttpIo The HTTP_IO which wraps the HTTP service to be destroyed.
809 EFI_HTTP_PROTOCOL
*Http
;
812 if (HttpIo
== NULL
) {
816 Event
= HttpIo
->ReqToken
.Event
;
818 gBS
->CloseEvent (Event
);
821 Event
= HttpIo
->RspToken
.Event
;
823 gBS
->CloseEvent (Event
);
828 Http
->Configure (Http
, NULL
);
831 &gEfiHttpProtocolGuid
,
837 NetLibDestroyServiceChild (
840 &gEfiHttpServiceBindingProtocolGuid
,
846 Synchronously send a HTTP REQUEST message to the server.
848 @param[in] HttpIo The HttpIo wrapping the HTTP service.
849 @param[in] Request A pointer to storage such data as URL and HTTP method.
850 @param[in] HeaderCount Number of HTTP header structures in Headers list.
851 @param[in] Headers Array containing list of HTTP headers.
852 @param[in] BodyLength Length in bytes of the HTTP body.
853 @param[in] Body Body associated with the HTTP request.
855 @retval EFI_SUCCESS The HTTP request is trasmitted.
856 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
857 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
858 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
859 @retval Others Other errors as indicated.
865 IN EFI_HTTP_REQUEST_DATA
*Request
,
866 IN UINTN HeaderCount
,
867 IN EFI_HTTP_HEADER
*Headers
,
873 EFI_HTTP_PROTOCOL
*Http
;
875 if (HttpIo
== NULL
|| HttpIo
->Http
== NULL
) {
876 return EFI_INVALID_PARAMETER
;
879 HttpIo
->ReqToken
.Status
= EFI_NOT_READY
;
880 HttpIo
->ReqToken
.Message
->Data
.Request
= Request
;
881 HttpIo
->ReqToken
.Message
->HeaderCount
= HeaderCount
;
882 HttpIo
->ReqToken
.Message
->Headers
= Headers
;
883 HttpIo
->ReqToken
.Message
->BodyLength
= BodyLength
;
884 HttpIo
->ReqToken
.Message
->Body
= Body
;
887 // Queue the request token to HTTP instances.
890 HttpIo
->IsTxDone
= FALSE
;
891 Status
= Http
->Request (
895 if (EFI_ERROR (Status
)) {
900 // Poll the network until transmit finish.
902 while (!HttpIo
->IsTxDone
) {
906 return HttpIo
->ReqToken
.Status
;
910 Synchronously receive a HTTP RESPONSE message from the server.
912 @param[in] HttpIo The HttpIo wrapping the HTTP service.
913 @param[in] RecvMsgHeader TRUE to receive a new HTTP response (from message header).
914 FALSE to continue receive the previous response message.
915 @param[out] ResponseData Point to a wrapper of the received response data.
917 @retval EFI_SUCCESS The HTTP resopnse is received.
918 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
919 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
920 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
921 @retval Others Other errors as indicated.
927 IN BOOLEAN RecvMsgHeader
,
928 OUT HTTP_IO_RESOPNSE_DATA
*ResponseData
932 EFI_HTTP_PROTOCOL
*Http
;
933 EFI_HTTP_STATUS_CODE StatusCode
;
935 if (HttpIo
== NULL
|| HttpIo
->Http
== NULL
|| ResponseData
== NULL
) {
936 return EFI_INVALID_PARAMETER
;
940 // Queue the response token to HTTP instances.
942 HttpIo
->RspToken
.Status
= EFI_NOT_READY
;
944 HttpIo
->RspToken
.Message
->Data
.Response
= &ResponseData
->Response
;
946 HttpIo
->RspToken
.Message
->Data
.Response
= NULL
;
948 HttpIo
->RspToken
.Message
->HeaderCount
= 0;
949 HttpIo
->RspToken
.Message
->Headers
= NULL
;
950 HttpIo
->RspToken
.Message
->BodyLength
= ResponseData
->BodyLength
;
951 HttpIo
->RspToken
.Message
->Body
= ResponseData
->Body
;
954 HttpIo
->IsRxDone
= FALSE
;
955 Status
= Http
->Response (
960 if (EFI_ERROR (Status
)) {
965 // Poll the network until receive finish.
967 while (!HttpIo
->IsRxDone
) {
972 // Store the received data into the wrapper.
974 Status
= HttpIo
->RspToken
.Status
;
975 if (!EFI_ERROR (Status
)) {
976 ResponseData
->HeaderCount
= HttpIo
->RspToken
.Message
->HeaderCount
;
977 ResponseData
->Headers
= HttpIo
->RspToken
.Message
->Headers
;
978 ResponseData
->BodyLength
= HttpIo
->RspToken
.Message
->BodyLength
;
982 StatusCode
= HttpIo
->RspToken
.Message
->Data
.Response
->StatusCode
;
983 HttpBootPrintErrorMessage (StatusCode
);