Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/HttpBootDxe/HttpBootClient.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (22 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/HttpBootDxe/HttpBootClient.c
r89983 r99404 2 2 Implementation of the boot file download function. 3 3 4 Copyright (c) 2015 - 20 18, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR> 5 5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> 6 6 SPDX-License-Identifier: BSD-2-Clause-Patent … … 22 22 EFI_STATUS 23 23 HttpBootUpdateDevicePath ( 24 IN HTTP_BOOT_PRIVATE_DATA 24 IN HTTP_BOOT_PRIVATE_DATA *Private 25 25 ) 26 26 { 27 EFI_DEV_PATH 28 EFI_DEVICE_PATH_PROTOCOL 29 EFI_DEVICE_PATH_PROTOCOL 30 EFI_DEVICE_PATH_PROTOCOL 31 UINTN 32 EFI_STATUS 27 EFI_DEV_PATH *Node; 28 EFI_DEVICE_PATH_PROTOCOL *TmpIpDevicePath; 29 EFI_DEVICE_PATH_PROTOCOL *TmpDnsDevicePath; 30 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; 31 UINTN Length; 32 EFI_STATUS Status; 33 33 34 34 TmpIpDevicePath = NULL; … … 43 43 return EFI_OUT_OF_RESOURCES; 44 44 } 45 45 46 Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH; 46 47 Node->Ipv4.Header.SubType = MSG_IPv4_DP; … … 57 58 return EFI_OUT_OF_RESOURCES; 58 59 } 59 Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH; 60 Node->Ipv6.Header.SubType = MSG_IPv6_DP; 60 61 Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH; 62 Node->Ipv6.Header.SubType = MSG_IPv6_DP; 61 63 SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH)); 62 64 Node->Ipv6.PrefixLength = IP6_PREFIX_LENGTH; … … 69 71 } 70 72 71 TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);73 TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); 72 74 FreePool (Node); 73 75 if (TmpIpDevicePath == NULL) { … … 80 82 if (Private->DnsServerIp != NULL) { 81 83 Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6) + Private->DnsServerCount * sizeof (EFI_IP_ADDRESS); 82 Node = AllocatePool (Length);84 Node = AllocatePool (Length); 83 85 if (Node == NULL) { 84 86 FreePool (TmpIpDevicePath); 85 87 return EFI_OUT_OF_RESOURCES; 86 88 } 89 87 90 Node->DevPath.Type = MESSAGING_DEVICE_PATH; 88 91 Node->DevPath.SubType = MSG_DNS_DP; 89 92 SetDevicePathNodeLength (Node, Length); 90 93 Node->Dns.IsIPv6 = Private->UsingIpv6 ? 0x01 : 0x00; 91 CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (EFI_IP_ADDRESS));92 93 TmpDnsDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);94 CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6), Private->DnsServerIp, Private->DnsServerCount * sizeof (EFI_IP_ADDRESS)); 95 96 TmpDnsDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); 94 97 FreePool (Node); 95 98 FreePool (TmpIpDevicePath); … … 104 107 // 105 108 Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (Private->BootFileUri); 106 Node = AllocatePool (Length);109 Node = AllocatePool (Length); 107 110 if (Node == NULL) { 108 111 if (TmpIpDevicePath != NULL) { 109 112 FreePool (TmpIpDevicePath); 110 113 } 114 111 115 if (TmpDnsDevicePath != NULL) { 112 116 FreePool (TmpDnsDevicePath); 113 117 } 118 114 119 return EFI_OUT_OF_RESOURCES; 115 120 } 121 116 122 Node->DevPath.Type = MESSAGING_DEVICE_PATH; 117 123 Node->DevPath.SubType = MSG_URI_DP; 118 124 SetDevicePathNodeLength (Node, Length); 119 CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), Private->BootFileUri, AsciiStrSize (Private->BootFileUri));125 CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), Private->BootFileUri, AsciiStrSize (Private->BootFileUri)); 120 126 121 127 if (TmpDnsDevicePath != NULL) { 122 NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);128 NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); 123 129 FreePool (TmpDnsDevicePath); 124 130 } else { 125 131 ASSERT (TmpIpDevicePath != NULL); 126 NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);132 NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node); 127 133 FreePool (TmpIpDevicePath); 128 134 } 135 129 136 FreePool (Node); 130 137 if (NewDevicePath == NULL) { … … 161 168 return Status; 162 169 } 170 163 171 FreePool (Private->Ip6Nic->DevicePath); 164 172 Private->Ip6Nic->DevicePath = NewDevicePath; … … 179 187 EFI_STATUS 180 188 HttpBootDhcp4ExtractUriInfo ( 181 IN HTTP_BOOT_PRIVATE_DATA 189 IN HTTP_BOOT_PRIVATE_DATA *Private 182 190 ) 183 191 { 184 HTTP_BOOT_DHCP4_PACKET_CACHE 185 HTTP_BOOT_DHCP4_PACKET_CACHE 186 UINT32 187 UINT32 188 UINT32 189 EFI_DHCP4_PACKET_OPTION 190 EFI_STATUS 192 HTTP_BOOT_DHCP4_PACKET_CACHE *SelectOffer; 193 HTTP_BOOT_DHCP4_PACKET_CACHE *HttpOffer; 194 UINT32 SelectIndex; 195 UINT32 ProxyIndex; 196 UINT32 DnsServerIndex; 197 EFI_DHCP4_PACKET_OPTION *Option; 198 EFI_STATUS Status; 191 199 192 200 ASSERT (Private != NULL); … … 210 218 if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || 211 219 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) || 212 (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { 220 (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) 221 { 213 222 HttpOffer = SelectOffer; 214 223 } else { 215 224 ASSERT (Private->SelectProxyType != HttpOfferTypeMax); 216 225 ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; 217 HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4; 218 } 226 HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4; 227 } 228 219 229 Private->BootFileUriParser = HttpOffer->UriParser; 220 Private->BootFileUri = (CHAR8*)HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data;230 Private->BootFileUri = (CHAR8 *)HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data; 221 231 } else { 222 232 // … … 224 234 // 225 235 Private->BootFileUriParser = Private->FilePathUriParser; 226 Private->BootFileUri = Private->FilePathUri;236 Private->BootFileUri = Private->FilePathUri; 227 237 } 228 238 … … 232 242 Status = HttpBootCheckUriScheme (Private->BootFileUri); 233 243 if (EFI_ERROR (Status)) { 234 DEBUG (( EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status));244 DEBUG ((DEBUG_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status)); 235 245 if (Status == EFI_INVALID_PARAMETER) { 236 246 AsciiPrint ("\n Error: Invalid URI address.\n"); … … 238 248 AsciiPrint ("\n Error: Access forbidden, only HTTPS connection is allowed.\n"); 239 249 } 250 240 251 return Status; 241 252 } … … 243 254 if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || 244 255 (SelectOffer->OfferType == HttpOfferTypeDhcpDns) || 245 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) { 256 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) 257 { 246 258 Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER]; 247 259 ASSERT (Option != NULL); … … 258 270 259 271 for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) { 260 CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *) 272 CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *)Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS)); 261 273 } 262 274 … … 284 296 &Private->Port 285 297 ); 286 if (EFI_ERROR (Status) || Private->Port == 0) {298 if (EFI_ERROR (Status) || (Private->Port == 0)) { 287 299 Private->Port = 80; 288 300 } … … 296 308 // 297 309 Status = HttpBootUpdateDevicePath (Private); 298 if (EFI_ERROR (Status) && Private->DnsServerIp != NULL) {310 if (EFI_ERROR (Status) && (Private->DnsServerIp != NULL)) { 299 311 FreePool (Private->DnsServerIp); 300 312 Private->DnsServerIp = NULL; … … 315 327 EFI_STATUS 316 328 HttpBootDhcp6ExtractUriInfo ( 317 IN HTTP_BOOT_PRIVATE_DATA 329 IN HTTP_BOOT_PRIVATE_DATA *Private 318 330 ) 319 331 { 320 HTTP_BOOT_DHCP6_PACKET_CACHE 321 HTTP_BOOT_DHCP6_PACKET_CACHE 322 UINT32 323 UINT32 324 UINT32 325 EFI_DHCP6_PACKET_OPTION 326 EFI_IPv6_ADDRESS 327 CHAR8 328 UINTN 329 CHAR16 330 EFI_STATUS 332 HTTP_BOOT_DHCP6_PACKET_CACHE *SelectOffer; 333 HTTP_BOOT_DHCP6_PACKET_CACHE *HttpOffer; 334 UINT32 SelectIndex; 335 UINT32 ProxyIndex; 336 UINT32 DnsServerIndex; 337 EFI_DHCP6_PACKET_OPTION *Option; 338 EFI_IPv6_ADDRESS IpAddr; 339 CHAR8 *HostName; 340 UINTN HostNameSize; 341 CHAR16 *HostNameStr; 342 EFI_STATUS Status; 331 343 332 344 ASSERT (Private != NULL); … … 350 362 if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || 351 363 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) || 352 (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) { 364 (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) 365 { 353 366 HttpOffer = SelectOffer; 354 367 } else { 355 368 ASSERT (Private->SelectProxyType != HttpOfferTypeMax); 356 369 ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0]; 357 HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6; 358 } 370 HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6; 371 } 372 359 373 Private->BootFileUriParser = HttpOffer->UriParser; 360 Private->BootFileUri = (CHAR8*)HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data;374 Private->BootFileUri = (CHAR8 *)HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data; 361 375 } else { 362 376 // … … 364 378 // 365 379 Private->BootFileUriParser = Private->FilePathUriParser; 366 Private->BootFileUri = Private->FilePathUri;380 Private->BootFileUri = Private->FilePathUri; 367 381 } 368 382 … … 372 386 Status = HttpBootCheckUriScheme (Private->BootFileUri); 373 387 if (EFI_ERROR (Status)) { 374 DEBUG (( EFI_D_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status));388 DEBUG ((DEBUG_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status)); 375 389 if (Status == EFI_INVALID_PARAMETER) { 376 390 AsciiPrint ("\n Error: Invalid URI address.\n"); … … 378 392 AsciiPrint ("\n Error: Access forbidden, only HTTPS connection is allowed.\n"); 379 393 } 394 380 395 return Status; 381 396 } … … 399 414 if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || 400 415 (SelectOffer->OfferType == HttpOfferTypeDhcpDns) || 401 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) { 416 (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) 417 { 402 418 Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER]; 403 419 ASSERT (Option != NULL); … … 414 430 415 431 for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) { 416 CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *) 432 CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *)Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS)); 417 433 } 418 434 … … 454 470 455 471 HostNameSize = AsciiStrSize (HostName); 456 HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));472 HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16)); 457 473 if (HostNameStr == NULL) { 458 474 Status = EFI_OUT_OF_RESOURCES; … … 484 500 &Private->Port 485 501 ); 486 if (EFI_ERROR (Status) || Private->Port == 0) {502 if (EFI_ERROR (Status) || (Private->Port == 0)) { 487 503 Private->Port = 80; 488 504 } … … 511 527 } 512 528 513 514 529 /** 515 530 Discover all the boot information for boot file. … … 523 538 EFI_STATUS 524 539 HttpBootDiscoverBootInfo ( 525 IN OUT HTTP_BOOT_PRIVATE_DATA 540 IN OUT HTTP_BOOT_PRIVATE_DATA *Private 526 541 ) 527 542 { 528 EFI_STATUS 543 EFI_STATUS Status; 529 544 530 545 // … … 559 574 EFIAPI 560 575 HttpBootHttpIoCallback ( 561 IN HTTP_IO_CALLBACK_EVENT 562 IN EFI_HTTP_MESSAGE 563 IN VOID 576 IN HTTP_IO_CALLBACK_EVENT EventType, 577 IN EFI_HTTP_MESSAGE *Message, 578 IN VOID *Context 564 579 ) 565 580 { 566 HTTP_BOOT_PRIVATE_DATA *Private; 567 EFI_STATUS Status; 568 Private = (HTTP_BOOT_PRIVATE_DATA *) Context; 581 HTTP_BOOT_PRIVATE_DATA *Private; 582 EFI_STATUS Status; 583 584 Private = (HTTP_BOOT_PRIVATE_DATA *)Context; 569 585 if (Private->HttpBootCallback != NULL) { 570 586 Status = Private->HttpBootCallback->Callback ( 571 Private->HttpBootCallback,572 EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse,573 EventType == HttpIoRequest ? FALSE : TRUE,574 sizeof (EFI_HTTP_MESSAGE),575 (VOID *)Message576 );587 Private->HttpBootCallback, 588 EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse, 589 EventType == HttpIoRequest ? FALSE : TRUE, 590 sizeof (EFI_HTTP_MESSAGE), 591 (VOID *)Message 592 ); 577 593 return Status; 578 594 } 595 579 596 return EFI_SUCCESS; 580 597 } … … 591 608 EFI_STATUS 592 609 HttpBootCreateHttpIo ( 593 IN HTTP_BOOT_PRIVATE_DATA 610 IN HTTP_BOOT_PRIVATE_DATA *Private 594 611 ) 595 612 { 596 HTTP_IO_CONFIG_DATA ConfigData; 597 EFI_STATUS Status; 598 EFI_HANDLE ImageHandle; 613 HTTP_IO_CONFIG_DATA ConfigData; 614 EFI_STATUS Status; 615 EFI_HANDLE ImageHandle; 616 UINT32 TimeoutValue; 599 617 600 618 ASSERT (Private != NULL); 619 620 // 621 // Get HTTP timeout value 622 // 623 TimeoutValue = PcdGet32 (PcdHttpIoTimeout); 601 624 602 625 ZeroMem (&ConfigData, sizeof (HTTP_IO_CONFIG_DATA)); 603 626 if (!Private->UsingIpv6) { 604 627 ConfigData.Config4.HttpVersion = HttpVersion11; 605 ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;628 ConfigData.Config4.RequestTimeOut = TimeoutValue; 606 629 IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4); 607 630 IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4); … … 609 632 } else { 610 633 ConfigData.Config6.HttpVersion = HttpVersion11; 611 ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;634 ConfigData.Config6.RequestTimeOut = TimeoutValue; 612 635 IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6); 613 636 ImageHandle = Private->Ip6Nic->ImageHandle; … … 620 643 &ConfigData, 621 644 HttpBootHttpIoCallback, 622 (VOID *) 645 (VOID *)Private, 623 646 &Private->HttpIo 624 647 ); … … 639 662 VOID 640 663 HttpBootFreeCache ( 641 IN HTTP_BOOT_CACHE_CONTENT 664 IN HTTP_BOOT_CACHE_CONTENT *Cache 642 665 ) 643 666 { 644 UINTN 645 LIST_ENTRY 646 LIST_ENTRY 647 HTTP_BOOT_ENTITY_DATA 667 UINTN Index; 668 LIST_ENTRY *Entry; 669 LIST_ENTRY *NextEntry; 670 HTTP_BOOT_ENTITY_DATA *EntityData; 648 671 649 672 if (Cache != NULL) { … … 655 678 FreePool (Cache->RequestData->Url); 656 679 } 680 657 681 FreePool (Cache->RequestData); 658 682 } … … 667 691 FreePool (Cache->ResponseData->Headers[Index].FieldValue); 668 692 } 693 669 694 FreePool (Cache->ResponseData->Headers); 670 695 } … … 679 704 FreePool (EntityData->Block); 680 705 } 706 681 707 RemoveEntryList (&EntityData->Link); 682 708 FreePool (EntityData); … … 695 721 VOID 696 722 HttpBootFreeCacheList ( 697 IN HTTP_BOOT_PRIVATE_DATA 723 IN HTTP_BOOT_PRIVATE_DATA *Private 698 724 ) 699 725 { 700 LIST_ENTRY 701 LIST_ENTRY 702 HTTP_BOOT_CACHE_CONTENT 726 LIST_ENTRY *Entry; 727 LIST_ENTRY *NextEntry; 728 HTTP_BOOT_CACHE_CONTENT *Cache; 703 729 704 730 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->CacheList) { … … 729 755 EFI_STATUS 730 756 HttpBootGetFileFromCache ( 731 IN HTTP_BOOT_PRIVATE_DATA 732 IN CHAR16 733 IN OUT UINTN 734 OUT UINT8*Buffer,735 OUT HTTP_BOOT_IMAGE_TYPE*ImageType757 IN HTTP_BOOT_PRIVATE_DATA *Private, 758 IN CHAR16 *Uri, 759 IN OUT UINTN *BufferSize, 760 OUT UINT8 *Buffer, 761 OUT HTTP_BOOT_IMAGE_TYPE *ImageType 736 762 ) 737 763 { 738 LIST_ENTRY 739 LIST_ENTRY 740 HTTP_BOOT_CACHE_CONTENT 741 HTTP_BOOT_ENTITY_DATA 742 UINTN 743 744 if ( Uri == NULL || BufferSize == NULL || Buffer == NULL || ImageType == NULL) {764 LIST_ENTRY *Entry; 765 LIST_ENTRY *Entry2; 766 HTTP_BOOT_CACHE_CONTENT *Cache; 767 HTTP_BOOT_ENTITY_DATA *EntityData; 768 UINTN CopyedSize; 769 770 if ((Uri == NULL) || (BufferSize == NULL) || (Buffer == NULL) || (ImageType == NULL)) { 745 771 return EFI_INVALID_PARAMETER; 746 772 } … … 753 779 if ((Cache->RequestData != NULL) && 754 780 (Cache->RequestData->Url != NULL) && 755 (StrCmp (Uri, Cache->RequestData->Url) == 0)) { 781 (StrCmp (Uri, Cache->RequestData->Url) == 0)) 782 { 756 783 // 757 784 // Hit in cache, record image type. 758 785 // 759 *ImageType 786 *ImageType = Cache->ImageType; 760 787 761 788 // … … 808 835 EFIAPI 809 836 HttpBootGetBootFileCallback ( 810 IN HTTP_BODY_PARSE_EVENT 811 IN CHAR8 812 IN UINTN 813 IN VOID 837 IN HTTP_BODY_PARSE_EVENT EventType, 838 IN CHAR8 *Data, 839 IN UINTN Length, 840 IN VOID *Context 814 841 ) 815 842 { 816 HTTP_BOOT_CALLBACK_DATA *CallbackData;817 HTTP_BOOT_ENTITY_DATA *NewEntityData;818 EFI_STATUS Status;819 EFI_HTTP_BOOT_CALLBACK_PROTOCOL 843 HTTP_BOOT_CALLBACK_DATA *CallbackData; 844 HTTP_BOOT_ENTITY_DATA *NewEntityData; 845 EFI_STATUS Status; 846 EFI_HTTP_BOOT_CALLBACK_PROTOCOL *HttpBootCallback; 820 847 821 848 // … … 826 853 } 827 854 828 CallbackData = (HTTP_BOOT_CALLBACK_DATA *)Context;855 CallbackData = (HTTP_BOOT_CALLBACK_DATA *)Context; 829 856 HttpBootCallback = CallbackData->Private->HttpBootCallback; 830 857 if (HttpBootCallback != NULL) { 831 858 Status = HttpBootCallback->Callback ( 832 HttpBootCallback,833 HttpBootHttpEntityBody,834 TRUE,835 (UINT32)Length,836 Data837 );859 HttpBootCallback, 860 HttpBootHttpEntityBody, 861 TRUE, 862 (UINT32)Length, 863 Data 864 ); 838 865 if (EFI_ERROR (Status)) { 839 866 return Status; 840 867 } 841 868 } 869 842 870 // 843 871 // Copy data if caller has provided a buffer. … … 860 888 return EFI_OUT_OF_RESOURCES; 861 889 } 890 862 891 if (CallbackData->NewBlock) { 863 892 NewEntityData->Block = CallbackData->Block; 864 CallbackData->Block = NULL; 865 } 893 CallbackData->Block = NULL; 894 } 895 866 896 NewEntityData->DataLength = Length; 867 NewEntityData->DataStart = (UINT8 *)Data;897 NewEntityData->DataStart = (UINT8 *)Data; 868 898 InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link); 869 899 } 900 870 901 return EFI_SUCCESS; 871 902 } … … 892 923 BufferSize has been updated with the size needed to complete 893 924 the request. 925 @retval EFI_ACCESS_DENIED The server needs to authenticate the client. 894 926 @retval Others Unexpected error happened. 895 927 … … 897 929 EFI_STATUS 898 930 HttpBootGetBootFile ( 899 IN HTTP_BOOT_PRIVATE_DATA 900 IN BOOLEAN 901 IN OUT UINTN 902 OUT UINT8*Buffer,903 OUT HTTP_BOOT_IMAGE_TYPE*ImageType931 IN HTTP_BOOT_PRIVATE_DATA *Private, 932 IN BOOLEAN HeaderOnly, 933 IN OUT UINTN *BufferSize, 934 OUT UINT8 *Buffer, 935 OUT HTTP_BOOT_IMAGE_TYPE *ImageType 904 936 ) 905 937 { 906 EFI_STATUS Status; 907 EFI_HTTP_STATUS_CODE StatusCode; 908 CHAR8 *HostName; 909 EFI_HTTP_REQUEST_DATA *RequestData; 910 HTTP_IO_RESPONSE_DATA *ResponseData; 911 HTTP_IO_RESPONSE_DATA ResponseBody; 912 HTTP_IO *HttpIo; 913 HTTP_IO_HEADER *HttpIoHeader; 914 VOID *Parser; 915 HTTP_BOOT_CALLBACK_DATA Context; 916 UINTN ContentLength; 917 HTTP_BOOT_CACHE_CONTENT *Cache; 918 UINT8 *Block; 919 UINTN UrlSize; 920 CHAR16 *Url; 921 BOOLEAN IdentityMode; 922 UINTN ReceivedSize; 938 EFI_STATUS Status; 939 EFI_HTTP_STATUS_CODE StatusCode; 940 CHAR8 *HostName; 941 EFI_HTTP_REQUEST_DATA *RequestData; 942 HTTP_IO_RESPONSE_DATA *ResponseData; 943 HTTP_IO_RESPONSE_DATA ResponseBody; 944 HTTP_IO *HttpIo; 945 HTTP_IO_HEADER *HttpIoHeader; 946 VOID *Parser; 947 HTTP_BOOT_CALLBACK_DATA Context; 948 UINTN ContentLength; 949 HTTP_BOOT_CACHE_CONTENT *Cache; 950 UINT8 *Block; 951 UINTN UrlSize; 952 CHAR16 *Url; 953 BOOLEAN IdentityMode; 954 UINTN ReceivedSize; 955 CHAR8 BaseAuthValue[80]; 956 EFI_HTTP_HEADER *HttpHeader; 957 CHAR8 *Data; 923 958 924 959 ASSERT (Private != NULL); 925 960 ASSERT (Private->HttpCreated); 926 961 927 if ( BufferSize == NULL || ImageType == NULL) {962 if ((BufferSize == NULL) || (ImageType == NULL)) { 928 963 return EFI_INVALID_PARAMETER; 929 964 } 930 965 931 if ( *BufferSize != 0 && Buffer == NULL) {966 if ((*BufferSize != 0) && (Buffer == NULL)) { 932 967 return EFI_INVALID_PARAMETER; 933 968 } … … 937 972 // 938 973 UrlSize = AsciiStrSize (Private->BootFileUri); 939 Url = AllocatePool (UrlSize * sizeof (CHAR16));974 Url = AllocatePool (UrlSize * sizeof (CHAR16)); 940 975 if (Url == NULL) { 941 976 return EFI_OUT_OF_RESOURCES; 942 977 } 978 943 979 AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize); 944 if (!HeaderOnly && Buffer != NULL) {980 if (!HeaderOnly && (Buffer != NULL)) { 945 981 Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType); 946 982 if (Status != EFI_NOT_FOUND) { … … 964 1000 goto ERROR_1; 965 1001 } 1002 966 1003 Cache->ImageType = ImageTypeMax; 967 1004 InitializeListHead (&Cache->EntityDataList); … … 977 1014 // Accept 978 1015 // User-Agent 979 // 980 HttpIoHeader = HttpIoCreateHeader (3); 1016 // [Authorization] 1017 // 1018 HttpIoHeader = HttpIoCreateHeader ((Private->AuthData != NULL) ? 4 : 3); 981 1019 if (HttpIoHeader == NULL) { 982 1020 Status = EFI_OUT_OF_RESOURCES; … … 988 1026 // 989 1027 HostName = NULL; 990 Status = HttpUrlGetHostName (991 Private->BootFileUri,992 Private->BootFileUriParser,993 &HostName994 );1028 Status = HttpUrlGetHostName ( 1029 Private->BootFileUri, 1030 Private->BootFileUriParser, 1031 &HostName 1032 ); 995 1033 if (EFI_ERROR (Status)) { 996 1034 goto ERROR_3; 997 1035 } 1036 998 1037 Status = HttpIoSetHeader ( 999 1038 HttpIoHeader, … … 1031 1070 1032 1071 // 1072 // Add HTTP header field 4: Authorization 1073 // 1074 if (Private->AuthData != NULL) { 1075 ASSERT (HttpIoHeader->MaxHeaderCount == 4); 1076 1077 if ((Private->AuthScheme != NULL) && (CompareMem (Private->AuthScheme, "Basic", 5) != 0)) { 1078 Status = EFI_UNSUPPORTED; 1079 goto ERROR_3; 1080 } 1081 1082 AsciiSPrint ( 1083 BaseAuthValue, 1084 sizeof (BaseAuthValue), 1085 "%a %a", 1086 "Basic", 1087 Private->AuthData 1088 ); 1089 1090 Status = HttpIoSetHeader ( 1091 HttpIoHeader, 1092 HTTP_HEADER_AUTHORIZATION, 1093 BaseAuthValue 1094 ); 1095 if (EFI_ERROR (Status)) { 1096 goto ERROR_3; 1097 } 1098 } 1099 1100 // 1033 1101 // 2.2 Build the rest of HTTP request info. 1034 1102 // … … 1038 1106 goto ERROR_3; 1039 1107 } 1108 1040 1109 RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet; 1041 RequestData->Url = Url;1110 RequestData->Url = Url; 1042 1111 1043 1112 // … … 1059 1128 0, 1060 1129 NULL 1061 );1130 ); 1062 1131 if (EFI_ERROR (Status)) { 1063 1132 goto ERROR_4; … … 1071 1140 // 3.1 First step, use zero BodyLength to only receive the response headers. 1072 1141 // 1073 ResponseData = AllocateZeroPool (sizeof (HTTP_IO_RESPONSE_DATA));1142 ResponseData = AllocateZeroPool (sizeof (HTTP_IO_RESPONSE_DATA)); 1074 1143 if (ResponseData == NULL) { 1075 1144 Status = EFI_OUT_OF_RESOURCES; 1076 1145 goto ERROR_4; 1077 1146 } 1147 1148 Data = NULL; 1078 1149 Status = HttpIoRecvResponse ( 1079 1150 &Private->HttpIo, … … 1086 1157 HttpBootPrintErrorMessage (StatusCode); 1087 1158 Status = ResponseData->Status; 1088 } 1159 if ((StatusCode == HTTP_STATUS_401_UNAUTHORIZED) || \ 1160 (StatusCode == HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED)) 1161 { 1162 if ((Private->AuthData != NULL) || (Private->AuthScheme != NULL)) { 1163 if (Private->AuthData != NULL) { 1164 FreePool (Private->AuthData); 1165 Private->AuthData = NULL; 1166 } 1167 1168 if (Private->AuthScheme != NULL) { 1169 FreePool (Private->AuthScheme); 1170 Private->AuthScheme = NULL; 1171 } 1172 1173 Status = EFI_ACCESS_DENIED; 1174 goto ERROR_4; 1175 } 1176 1177 // 1178 // Server indicates the user has to provide a user-id and password as a means of identification. 1179 // 1180 if (Private->HttpBootCallback != NULL) { 1181 Data = AllocateZeroPool (sizeof (CHAR8) * HTTP_BOOT_AUTHENTICATION_INFO_MAX_LEN); 1182 if (Data == NULL) { 1183 Status = EFI_OUT_OF_RESOURCES; 1184 goto ERROR_4; 1185 } 1186 1187 Status = Private->HttpBootCallback->Callback ( 1188 Private->HttpBootCallback, 1189 HttpBootHttpAuthInfo, 1190 TRUE, 1191 HTTP_BOOT_AUTHENTICATION_INFO_MAX_LEN, 1192 Data 1193 ); 1194 if (EFI_ERROR (Status)) { 1195 if (Data != NULL) { 1196 FreePool (Data); 1197 } 1198 1199 goto ERROR_5; 1200 } 1201 1202 Private->AuthData = (CHAR8 *)Data; 1203 } 1204 1205 HttpHeader = HttpFindHeader ( 1206 ResponseData->HeaderCount, 1207 ResponseData->Headers, 1208 HTTP_HEADER_WWW_AUTHENTICATE 1209 ); 1210 if (HttpHeader != NULL) { 1211 Private->AuthScheme = AllocateZeroPool (AsciiStrLen (HttpHeader->FieldValue) + 1); 1212 if (Private->AuthScheme == NULL) { 1213 return EFI_OUT_OF_RESOURCES; 1214 } 1215 1216 CopyMem (Private->AuthScheme, HttpHeader->FieldValue, AsciiStrLen (HttpHeader->FieldValue)); 1217 } 1218 1219 Status = EFI_ACCESS_DENIED; 1220 } 1221 } 1222 1089 1223 goto ERROR_5; 1090 1224 } … … 1109 1243 if (Cache != NULL) { 1110 1244 Cache->ResponseData = ResponseData; 1111 Cache->ImageType = *ImageType;1245 Cache->ImageType = *ImageType; 1112 1246 } 1113 1247 … … 1115 1249 // 3.3 Init a message-body parser from the header information. 1116 1250 // 1117 Parser = NULL;1251 Parser = NULL; 1118 1252 Context.NewBlock = FALSE; 1119 1253 Context.Block = NULL; … … 1123 1257 Context.Cache = Cache; 1124 1258 Context.Private = Private; 1125 Status = HttpInitMsgParser (1126 HeaderOnly ? HttpMethodHead : HttpMethodGet,1127 ResponseData->Response.StatusCode,1128 ResponseData->HeaderCount,1129 ResponseData->Headers,1130 HttpBootGetBootFileCallback,1131 (VOID*)&Context,1132 &Parser1133 );1259 Status = HttpInitMsgParser ( 1260 HeaderOnly ? HttpMethodHead : HttpMethodGet, 1261 ResponseData->Response.StatusCode, 1262 ResponseData->HeaderCount, 1263 ResponseData->Headers, 1264 HttpBootGetBootFileCallback, 1265 (VOID *)&Context, 1266 &Parser 1267 ); 1134 1268 if (EFI_ERROR (Status)) { 1135 1269 goto ERROR_6; … … 1145 1279 // 1146 1280 ContentLength = 0; 1147 Status = HttpGetEntityLength (Parser, &ContentLength);1281 Status = HttpGetEntityLength (Parser, &ContentLength); 1148 1282 if (!EFI_ERROR (Status)) { 1149 1283 IdentityMode = TRUE; … … 1164 1298 ReceivedSize = 0; 1165 1299 while (ReceivedSize < ContentLength) { 1166 ResponseBody.Body = (CHAR8 *)Buffer + ReceivedSize;1300 ResponseBody.Body = (CHAR8 *)Buffer + ReceivedSize; 1167 1301 ResponseBody.BodyLength = *BufferSize - ReceivedSize; 1168 Status = HttpIoRecvResponse (1169 &Private->HttpIo,1170 FALSE,1171 &ResponseBody1172 );1302 Status = HttpIoRecvResponse ( 1303 &Private->HttpIo, 1304 FALSE, 1305 &ResponseBody 1306 ); 1173 1307 if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { 1174 1308 if (EFI_ERROR (ResponseBody.Status)) { 1175 1309 Status = ResponseBody.Status; 1176 1310 } 1311 1177 1312 goto ERROR_6; 1178 1313 } 1314 1179 1315 ReceivedSize += ResponseBody.BodyLength; 1180 1316 if (Private->HttpBootCallback != NULL) { 1181 1317 Status = Private->HttpBootCallback->Callback ( 1182 Private->HttpBootCallback,1183 HttpBootHttpEntityBody,1184 TRUE,1185 (UINT32)ResponseBody.BodyLength,1186 ResponseBody.Body1187 );1318 Private->HttpBootCallback, 1319 HttpBootHttpEntityBody, 1320 TRUE, 1321 (UINT32)ResponseBody.BodyLength, 1322 ResponseBody.Body 1323 ); 1188 1324 if (EFI_ERROR (Status)) { 1189 1325 goto ERROR_6; … … 1204 1340 // every HttpIoRecvResponse(). 1205 1341 // 1206 if ( Block == NULL || Context.BufferSize == 0) {1342 if ((Block == NULL) || (Context.BufferSize == 0)) { 1207 1343 Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE); 1208 1344 if (Block == NULL) { … … 1210 1346 goto ERROR_6; 1211 1347 } 1348 1212 1349 Context.NewBlock = TRUE; 1213 Context.Block = Block;1350 Context.Block = Block; 1214 1351 } else { 1215 1352 Context.NewBlock = FALSE; 1216 1353 } 1217 1354 1218 ResponseBody.Body = (CHAR8 *)Block;1355 ResponseBody.Body = (CHAR8 *)Block; 1219 1356 ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE; 1220 Status = HttpIoRecvResponse (1221 &Private->HttpIo,1222 FALSE,1223 &ResponseBody1224 );1357 Status = HttpIoRecvResponse ( 1358 &Private->HttpIo, 1359 FALSE, 1360 &ResponseBody 1361 ); 1225 1362 if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { 1226 1363 if (EFI_ERROR (ResponseBody.Status)) { 1227 1364 Status = ResponseBody.Status; 1228 1365 } 1366 1229 1367 goto ERROR_6; 1230 1368 } … … 1258 1396 Status = EFI_SUCCESS; 1259 1397 } 1398 1260 1399 *BufferSize = ContentLength; 1261 1400 … … 1278 1417 HttpFreeMsgParser (Parser); 1279 1418 } 1419 1280 1420 if (Context.Block != NULL) { 1281 1421 FreePool (Context.Block); 1282 1422 } 1423 1283 1424 HttpBootFreeCache (Cache); 1284 1425 … … 1287 1428 FreePool (ResponseData); 1288 1429 } 1430 1289 1431 ERROR_4: 1290 1432 if (RequestData != NULL) { 1291 1433 FreePool (RequestData); 1292 1434 } 1435 1293 1436 ERROR_3: 1294 1437 HttpIoFreeHeader (HttpIoHeader); … … 1297 1440 FreePool (Cache); 1298 1441 } 1442 1299 1443 ERROR_1: 1300 1444 if (Url != NULL) { … … 1304 1448 return Status; 1305 1449 } 1306
Note:
See TracChangeset
for help on using the changeset viewer.