VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (22 months ago)
Author:
vboxsync
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/HttpBootDxe/HttpBootClient.c

    r89983 r99404  
    22  Implementation of the boot file download function.
    33
    4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
    55(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
    66SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2222EFI_STATUS
    2323HttpBootUpdateDevicePath (
    24   IN   HTTP_BOOT_PRIVATE_DATA   *Private
     24  IN   HTTP_BOOT_PRIVATE_DATA  *Private
    2525  )
    2626{
    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;
     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;
    3333
    3434  TmpIpDevicePath  = NULL;
     
    4343      return EFI_OUT_OF_RESOURCES;
    4444    }
     45
    4546    Node->Ipv4.Header.Type    = MESSAGING_DEVICE_PATH;
    4647    Node->Ipv4.Header.SubType = MSG_IPv4_DP;
     
    5758      return EFI_OUT_OF_RESOURCES;
    5859    }
    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;
    6163    SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));
    6264    Node->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;
     
    6971  }
    7072
    71   TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
     73  TmpIpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
    7274  FreePool (Node);
    7375  if (TmpIpDevicePath == NULL) {
     
    8082  if (Private->DnsServerIp != NULL) {
    8183    Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (Node->Dns.IsIPv6) + Private->DnsServerCount * sizeof (EFI_IP_ADDRESS);
    82     Node = AllocatePool (Length);
     84    Node   = AllocatePool (Length);
    8385    if (Node == NULL) {
    8486      FreePool (TmpIpDevicePath);
    8587      return EFI_OUT_OF_RESOURCES;
    8688    }
     89
    8790    Node->DevPath.Type    = MESSAGING_DEVICE_PATH;
    8891    Node->DevPath.SubType = MSG_DNS_DP;
    8992    SetDevicePathNodeLength (Node, Length);
    9093    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);
    9497    FreePool (Node);
    9598    FreePool (TmpIpDevicePath);
     
    104107  //
    105108  Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (Private->BootFileUri);
    106   Node = AllocatePool (Length);
     109  Node   = AllocatePool (Length);
    107110  if (Node == NULL) {
    108111    if (TmpIpDevicePath != NULL) {
    109112      FreePool (TmpIpDevicePath);
    110113    }
     114
    111115    if (TmpDnsDevicePath != NULL) {
    112116      FreePool (TmpDnsDevicePath);
    113117    }
     118
    114119    return EFI_OUT_OF_RESOURCES;
    115120  }
     121
    116122  Node->DevPath.Type    = MESSAGING_DEVICE_PATH;
    117123  Node->DevPath.SubType = MSG_URI_DP;
    118124  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));
    120126
    121127  if (TmpDnsDevicePath != NULL) {
    122     NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
     128    NewDevicePath = AppendDevicePathNode (TmpDnsDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
    123129    FreePool (TmpDnsDevicePath);
    124130  } else {
    125131    ASSERT (TmpIpDevicePath != NULL);
    126     NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL*) Node);
     132    NewDevicePath = AppendDevicePathNode (TmpIpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
    127133    FreePool (TmpIpDevicePath);
    128134  }
     135
    129136  FreePool (Node);
    130137  if (NewDevicePath == NULL) {
     
    161168      return Status;
    162169    }
     170
    163171    FreePool (Private->Ip6Nic->DevicePath);
    164172    Private->Ip6Nic->DevicePath = NewDevicePath;
     
    179187EFI_STATUS
    180188HttpBootDhcp4ExtractUriInfo (
    181   IN     HTTP_BOOT_PRIVATE_DATA   *Private
     189  IN     HTTP_BOOT_PRIVATE_DATA  *Private
    182190  )
    183191{
    184   HTTP_BOOT_DHCP4_PACKET_CACHE    *SelectOffer;
    185   HTTP_BOOT_DHCP4_PACKET_CACHE    *HttpOffer;
    186   UINT32                          SelectIndex;
    187   UINT32                          ProxyIndex;
    188   UINT32                          DnsServerIndex;
    189   EFI_DHCP4_PACKET_OPTION         *Option;
    190   EFI_STATUS                      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;
    191199
    192200  ASSERT (Private != NULL);
     
    210218    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) ||
    211219        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||
    212         (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {
     220        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns))
     221    {
    213222      HttpOffer = SelectOffer;
    214223    } else {
    215224      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);
    216225      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];
    217       HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4;
    218     }
     226      HttpOffer  = &Private->OfferBuffer[ProxyIndex].Dhcp4;
     227    }
     228
    219229    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;
    221231  } else {
    222232    //
     
    224234    //
    225235    Private->BootFileUriParser = Private->FilePathUriParser;
    226     Private->BootFileUri = Private->FilePathUri;
     236    Private->BootFileUri       = Private->FilePathUri;
    227237  }
    228238
     
    232242  Status = HttpBootCheckUriScheme (Private->BootFileUri);
    233243  if (EFI_ERROR (Status)) {
    234     DEBUG ((EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status));
     244    DEBUG ((DEBUG_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status));
    235245    if (Status == EFI_INVALID_PARAMETER) {
    236246      AsciiPrint ("\n  Error: Invalid URI address.\n");
     
    238248      AsciiPrint ("\n  Error: Access forbidden, only HTTPS connection is allowed.\n");
    239249    }
     250
    240251    return Status;
    241252  }
     
    243254  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) ||
    244255      (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||
    245       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {
     256      (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns))
     257  {
    246258    Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER];
    247259    ASSERT (Option != NULL);
     
    258270
    259271    for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) {
    260       CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS));
     272      CopyMem (&(Private->DnsServerIp[DnsServerIndex].v4), &(((EFI_IPv4_ADDRESS *)Option->Data)[DnsServerIndex]), sizeof (EFI_IPv4_ADDRESS));
    261273    }
    262274
     
    284296             &Private->Port
    285297             );
    286   if (EFI_ERROR (Status) || Private->Port == 0) {
     298  if (EFI_ERROR (Status) || (Private->Port == 0)) {
    287299    Private->Port = 80;
    288300  }
     
    296308  //
    297309  Status = HttpBootUpdateDevicePath (Private);
    298   if (EFI_ERROR (Status) && Private->DnsServerIp != NULL) {
     310  if (EFI_ERROR (Status) && (Private->DnsServerIp != NULL)) {
    299311    FreePool (Private->DnsServerIp);
    300312    Private->DnsServerIp = NULL;
     
    315327EFI_STATUS
    316328HttpBootDhcp6ExtractUriInfo (
    317   IN     HTTP_BOOT_PRIVATE_DATA   *Private
     329  IN     HTTP_BOOT_PRIVATE_DATA  *Private
    318330  )
    319331{
    320   HTTP_BOOT_DHCP6_PACKET_CACHE    *SelectOffer;
    321   HTTP_BOOT_DHCP6_PACKET_CACHE    *HttpOffer;
    322   UINT32                          SelectIndex;
    323   UINT32                          ProxyIndex;
    324   UINT32                          DnsServerIndex;
    325   EFI_DHCP6_PACKET_OPTION         *Option;
    326   EFI_IPv6_ADDRESS                IpAddr;
    327   CHAR8                           *HostName;
    328   UINTN                           HostNameSize;
    329   CHAR16                          *HostNameStr;
    330   EFI_STATUS                      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;
    331343
    332344  ASSERT (Private != NULL);
     
    350362    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) ||
    351363        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||
    352         (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {
     364        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns))
     365    {
    353366      HttpOffer = SelectOffer;
    354367    } else {
    355368      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);
    356369      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];
    357       HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6;
    358     }
     370      HttpOffer  = &Private->OfferBuffer[ProxyIndex].Dhcp6;
     371    }
     372
    359373    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;
    361375  } else {
    362376    //
     
    364378    //
    365379    Private->BootFileUriParser = Private->FilePathUriParser;
    366     Private->BootFileUri = Private->FilePathUri;
     380    Private->BootFileUri       = Private->FilePathUri;
    367381  }
    368382
     
    372386  Status = HttpBootCheckUriScheme (Private->BootFileUri);
    373387  if (EFI_ERROR (Status)) {
    374     DEBUG ((EFI_D_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status));
     388    DEBUG ((DEBUG_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status));
    375389    if (Status == EFI_INVALID_PARAMETER) {
    376390      AsciiPrint ("\n  Error: Invalid URI address.\n");
     
    378392      AsciiPrint ("\n  Error: Access forbidden, only HTTPS connection is allowed.\n");
    379393    }
     394
    380395    return Status;
    381396  }
     
    399414  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) ||
    400415      (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||
    401       (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {
     416      (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns))
     417  {
    402418    Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER];
    403419    ASSERT (Option != NULL);
     
    414430
    415431    for (DnsServerIndex = 0; DnsServerIndex < Private->DnsServerCount; DnsServerIndex++) {
    416       CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *) Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS));
     432      CopyMem (&(Private->DnsServerIp[DnsServerIndex].v6), &(((EFI_IPv6_ADDRESS *)Option->Data)[DnsServerIndex]), sizeof (EFI_IPv6_ADDRESS));
    417433    }
    418434
     
    454470
    455471    HostNameSize = AsciiStrSize (HostName);
    456     HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));
     472    HostNameStr  = AllocateZeroPool (HostNameSize * sizeof (CHAR16));
    457473    if (HostNameStr == NULL) {
    458474      Status = EFI_OUT_OF_RESOURCES;
     
    484500             &Private->Port
    485501             );
    486   if (EFI_ERROR (Status) || Private->Port == 0) {
     502  if (EFI_ERROR (Status) || (Private->Port == 0)) {
    487503    Private->Port = 80;
    488504  }
     
    511527}
    512528
    513 
    514529/**
    515530  Discover all the boot information for boot file.
     
    523538EFI_STATUS
    524539HttpBootDiscoverBootInfo (
    525   IN OUT HTTP_BOOT_PRIVATE_DATA   *Private
     540  IN OUT HTTP_BOOT_PRIVATE_DATA  *Private
    526541  )
    527542{
    528   EFI_STATUS              Status;
     543  EFI_STATUS  Status;
    529544
    530545  //
     
    559574EFIAPI
    560575HttpBootHttpIoCallback (
    561   IN  HTTP_IO_CALLBACK_EVENT    EventType,
    562   IN  EFI_HTTP_MESSAGE          *Message,
    563   IN  VOID                      *Context
     576  IN  HTTP_IO_CALLBACK_EVENT  EventType,
     577  IN  EFI_HTTP_MESSAGE        *Message,
     578  IN  VOID                    *Context
    564579  )
    565580{
    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;
    569585  if (Private->HttpBootCallback != NULL) {
    570586    Status = Private->HttpBootCallback->Callback (
    571                Private->HttpBootCallback,
    572                EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse,
    573                EventType == HttpIoRequest ? FALSE : TRUE,
    574                sizeof (EFI_HTTP_MESSAGE),
    575                (VOID *) Message
    576                );
     587                                          Private->HttpBootCallback,
     588                                          EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse,
     589                                          EventType == HttpIoRequest ? FALSE : TRUE,
     590                                          sizeof (EFI_HTTP_MESSAGE),
     591                                          (VOID *)Message
     592                                          );
    577593    return Status;
    578594  }
     595
    579596  return EFI_SUCCESS;
    580597}
     
    591608EFI_STATUS
    592609HttpBootCreateHttpIo (
    593   IN     HTTP_BOOT_PRIVATE_DATA       *Private
     610  IN     HTTP_BOOT_PRIVATE_DATA  *Private
    594611  )
    595612{
    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;
    599617
    600618  ASSERT (Private != NULL);
     619
     620  //
     621  // Get HTTP timeout value
     622  //
     623  TimeoutValue = PcdGet32 (PcdHttpIoTimeout);
    601624
    602625  ZeroMem (&ConfigData, sizeof (HTTP_IO_CONFIG_DATA));
    603626  if (!Private->UsingIpv6) {
    604627    ConfigData.Config4.HttpVersion    = HttpVersion11;
    605     ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;
     628    ConfigData.Config4.RequestTimeOut = TimeoutValue;
    606629    IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4);
    607630    IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4);
     
    609632  } else {
    610633    ConfigData.Config6.HttpVersion    = HttpVersion11;
    611     ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;
     634    ConfigData.Config6.RequestTimeOut = TimeoutValue;
    612635    IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6);
    613636    ImageHandle = Private->Ip6Nic->ImageHandle;
     
    620643             &ConfigData,
    621644             HttpBootHttpIoCallback,
    622              (VOID *) Private,
     645             (VOID *)Private,
    623646             &Private->HttpIo
    624647             );
     
    639662VOID
    640663HttpBootFreeCache (
    641   IN  HTTP_BOOT_CACHE_CONTENT    *Cache
     664  IN  HTTP_BOOT_CACHE_CONTENT  *Cache
    642665  )
    643666{
    644   UINTN                       Index;
    645   LIST_ENTRY                  *Entry;
    646   LIST_ENTRY                  *NextEntry;
    647   HTTP_BOOT_ENTITY_DATA       *EntityData;
     667  UINTN                  Index;
     668  LIST_ENTRY             *Entry;
     669  LIST_ENTRY             *NextEntry;
     670  HTTP_BOOT_ENTITY_DATA  *EntityData;
    648671
    649672  if (Cache != NULL) {
     
    655678        FreePool (Cache->RequestData->Url);
    656679      }
     680
    657681      FreePool (Cache->RequestData);
    658682    }
     
    667691          FreePool (Cache->ResponseData->Headers[Index].FieldValue);
    668692        }
     693
    669694        FreePool (Cache->ResponseData->Headers);
    670695      }
     
    679704        FreePool (EntityData->Block);
    680705      }
     706
    681707      RemoveEntryList (&EntityData->Link);
    682708      FreePool (EntityData);
     
    695721VOID
    696722HttpBootFreeCacheList (
    697   IN     HTTP_BOOT_PRIVATE_DATA   *Private
     723  IN     HTTP_BOOT_PRIVATE_DATA  *Private
    698724  )
    699725{
    700   LIST_ENTRY                  *Entry;
    701   LIST_ENTRY                  *NextEntry;
    702   HTTP_BOOT_CACHE_CONTENT     *Cache;
     726  LIST_ENTRY               *Entry;
     727  LIST_ENTRY               *NextEntry;
     728  HTTP_BOOT_CACHE_CONTENT  *Cache;
    703729
    704730  NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->CacheList) {
     
    729755EFI_STATUS
    730756HttpBootGetFileFromCache (
    731   IN     HTTP_BOOT_PRIVATE_DATA   *Private,
    732   IN     CHAR16                   *Uri,
    733   IN OUT UINTN                    *BufferSize,
    734      OUT UINT8                    *Buffer,
    735      OUT HTTP_BOOT_IMAGE_TYPE     *ImageType
     757  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
    736762  )
    737763{
    738   LIST_ENTRY                  *Entry;
    739   LIST_ENTRY                  *Entry2;
    740   HTTP_BOOT_CACHE_CONTENT     *Cache;
    741   HTTP_BOOT_ENTITY_DATA       *EntityData;
    742   UINTN                       CopyedSize;
    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)) {
    745771    return EFI_INVALID_PARAMETER;
    746772  }
     
    753779    if ((Cache->RequestData != NULL) &&
    754780        (Cache->RequestData->Url != NULL) &&
    755         (StrCmp (Uri, Cache->RequestData->Url) == 0)) {
     781        (StrCmp (Uri, Cache->RequestData->Url) == 0))
     782    {
    756783      //
    757784      // Hit in cache, record image type.
    758785      //
    759       *ImageType  = Cache->ImageType;
     786      *ImageType = Cache->ImageType;
    760787
    761788      //
     
    808835EFIAPI
    809836HttpBootGetBootFileCallback (
    810   IN HTTP_BODY_PARSE_EVENT      EventType,
    811   IN CHAR8                      *Data,
    812   IN UINTN                      Length,
    813   IN VOID                       *Context
     837  IN HTTP_BODY_PARSE_EVENT  EventType,
     838  IN CHAR8                  *Data,
     839  IN UINTN                  Length,
     840  IN VOID                   *Context
    814841  )
    815842{
    816   HTTP_BOOT_CALLBACK_DATA      *CallbackData;
    817   HTTP_BOOT_ENTITY_DATA        *NewEntityData;
    818   EFI_STATUS                   Status;
    819   EFI_HTTP_BOOT_CALLBACK_PROTOCOL   *HttpBootCallback;
     843  HTTP_BOOT_CALLBACK_DATA          *CallbackData;
     844  HTTP_BOOT_ENTITY_DATA            *NewEntityData;
     845  EFI_STATUS                       Status;
     846  EFI_HTTP_BOOT_CALLBACK_PROTOCOL  *HttpBootCallback;
    820847
    821848  //
     
    826853  }
    827854
    828   CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;
     855  CallbackData     = (HTTP_BOOT_CALLBACK_DATA *)Context;
    829856  HttpBootCallback = CallbackData->Private->HttpBootCallback;
    830857  if (HttpBootCallback != NULL) {
    831858    Status = HttpBootCallback->Callback (
    832                HttpBootCallback,
    833                HttpBootHttpEntityBody,
    834                TRUE,
    835                (UINT32)Length,
    836                Data
    837                );
     859                                 HttpBootCallback,
     860                                 HttpBootHttpEntityBody,
     861                                 TRUE,
     862                                 (UINT32)Length,
     863                                 Data
     864                                 );
    838865    if (EFI_ERROR (Status)) {
    839866      return Status;
    840867    }
    841868  }
     869
    842870  //
    843871  // Copy data if caller has provided a buffer.
     
    860888      return EFI_OUT_OF_RESOURCES;
    861889    }
     890
    862891    if (CallbackData->NewBlock) {
    863892      NewEntityData->Block = CallbackData->Block;
    864       CallbackData->Block = NULL;
    865     }
     893      CallbackData->Block  = NULL;
     894    }
     895
    866896    NewEntityData->DataLength = Length;
    867     NewEntityData->DataStart  = (UINT8*) Data;
     897    NewEntityData->DataStart  = (UINT8 *)Data;
    868898    InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link);
    869899  }
     900
    870901  return EFI_SUCCESS;
    871902}
     
    892923                                   BufferSize has been updated with the size needed to complete
    893924                                   the request.
     925  @retval EFI_ACCESS_DENIED        The server needs to authenticate the client.
    894926  @retval Others                   Unexpected error happened.
    895927
     
    897929EFI_STATUS
    898930HttpBootGetBootFile (
    899   IN     HTTP_BOOT_PRIVATE_DATA   *Private,
    900   IN     BOOLEAN                  HeaderOnly,
    901   IN OUT UINTN                    *BufferSize,
    902      OUT UINT8                    *Buffer,
    903      OUT HTTP_BOOT_IMAGE_TYPE     *ImageType
     931  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
    904936  )
    905937{
    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;
    923958
    924959  ASSERT (Private != NULL);
    925960  ASSERT (Private->HttpCreated);
    926961
    927   if (BufferSize == NULL || ImageType == NULL) {
     962  if ((BufferSize == NULL) || (ImageType == NULL)) {
    928963    return EFI_INVALID_PARAMETER;
    929964  }
    930965
    931   if (*BufferSize != 0 && Buffer == NULL) {
     966  if ((*BufferSize != 0) && (Buffer == NULL)) {
    932967    return EFI_INVALID_PARAMETER;
    933968  }
     
    937972  //
    938973  UrlSize = AsciiStrSize (Private->BootFileUri);
    939   Url = AllocatePool (UrlSize * sizeof (CHAR16));
     974  Url     = AllocatePool (UrlSize * sizeof (CHAR16));
    940975  if (Url == NULL) {
    941976    return EFI_OUT_OF_RESOURCES;
    942977  }
     978
    943979  AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize);
    944   if (!HeaderOnly && Buffer != NULL) {
     980  if (!HeaderOnly && (Buffer != NULL)) {
    945981    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType);
    946982    if (Status != EFI_NOT_FOUND) {
     
    9641000      goto ERROR_1;
    9651001    }
     1002
    9661003    Cache->ImageType = ImageTypeMax;
    9671004    InitializeListHead (&Cache->EntityDataList);
     
    9771014  //       Accept
    9781015  //       User-Agent
    979   //
    980   HttpIoHeader = HttpIoCreateHeader (3);
     1016  //       [Authorization]
     1017  //
     1018  HttpIoHeader = HttpIoCreateHeader ((Private->AuthData != NULL) ? 4 : 3);
    9811019  if (HttpIoHeader == NULL) {
    9821020    Status = EFI_OUT_OF_RESOURCES;
     
    9881026  //
    9891027  HostName = NULL;
    990   Status = HttpUrlGetHostName (
    991              Private->BootFileUri,
    992              Private->BootFileUriParser,
    993              &HostName
    994              );
     1028  Status   = HttpUrlGetHostName (
     1029               Private->BootFileUri,
     1030               Private->BootFileUriParser,
     1031               &HostName
     1032               );
    9951033  if (EFI_ERROR (Status)) {
    9961034    goto ERROR_3;
    9971035  }
     1036
    9981037  Status = HttpIoSetHeader (
    9991038             HttpIoHeader,
     
    10311070
    10321071  //
     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  //
    10331101  // 2.2 Build the rest of HTTP request info.
    10341102  //
     
    10381106    goto ERROR_3;
    10391107  }
     1108
    10401109  RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet;
    1041   RequestData->Url = Url;
     1110  RequestData->Url    = Url;
    10421111
    10431112  //
     
    10591128             0,
    10601129             NULL
    1061             );
     1130             );
    10621131  if (EFI_ERROR (Status)) {
    10631132    goto ERROR_4;
     
    10711140  // 3.1 First step, use zero BodyLength to only receive the response headers.
    10721141  //
    1073   ResponseData = AllocateZeroPool (sizeof(HTTP_IO_RESPONSE_DATA));
     1142  ResponseData = AllocateZeroPool (sizeof (HTTP_IO_RESPONSE_DATA));
    10741143  if (ResponseData == NULL) {
    10751144    Status = EFI_OUT_OF_RESOURCES;
    10761145    goto ERROR_4;
    10771146  }
     1147
     1148  Data   = NULL;
    10781149  Status = HttpIoRecvResponse (
    10791150             &Private->HttpIo,
     
    10861157      HttpBootPrintErrorMessage (StatusCode);
    10871158      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
    10891223    goto ERROR_5;
    10901224  }
     
    11091243  if (Cache != NULL) {
    11101244    Cache->ResponseData = ResponseData;
    1111     Cache->ImageType = *ImageType;
     1245    Cache->ImageType    = *ImageType;
    11121246  }
    11131247
     
    11151249  // 3.3 Init a message-body parser from the header information.
    11161250  //
    1117   Parser = NULL;
     1251  Parser             = NULL;
    11181252  Context.NewBlock   = FALSE;
    11191253  Context.Block      = NULL;
     
    11231257  Context.Cache      = Cache;
    11241258  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              &Parser
    1133              );
     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                         );
    11341268  if (EFI_ERROR (Status)) {
    11351269    goto ERROR_6;
     
    11451279    //
    11461280    ContentLength = 0;
    1147     Status = HttpGetEntityLength (Parser, &ContentLength);
     1281    Status        = HttpGetEntityLength (Parser, &ContentLength);
    11481282    if (!EFI_ERROR (Status)) {
    11491283      IdentityMode = TRUE;
     
    11641298      ReceivedSize = 0;
    11651299      while (ReceivedSize < ContentLength) {
    1166         ResponseBody.Body       = (CHAR8*) Buffer + ReceivedSize;
     1300        ResponseBody.Body       = (CHAR8 *)Buffer + ReceivedSize;
    11671301        ResponseBody.BodyLength = *BufferSize - ReceivedSize;
    1168         Status = HttpIoRecvResponse (
    1169                    &Private->HttpIo,
    1170                    FALSE,
    1171                    &ResponseBody
    1172                    );
     1302        Status                  = HttpIoRecvResponse (
     1303                                    &Private->HttpIo,
     1304                                    FALSE,
     1305                                    &ResponseBody
     1306                                    );
    11731307        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {
    11741308          if (EFI_ERROR (ResponseBody.Status)) {
    11751309            Status = ResponseBody.Status;
    11761310          }
     1311
    11771312          goto ERROR_6;
    11781313        }
     1314
    11791315        ReceivedSize += ResponseBody.BodyLength;
    11801316        if (Private->HttpBootCallback != NULL) {
    11811317          Status = Private->HttpBootCallback->Callback (
    1182                      Private->HttpBootCallback,
    1183                      HttpBootHttpEntityBody,
    1184                      TRUE,
    1185                      (UINT32)ResponseBody.BodyLength,
    1186                      ResponseBody.Body
    1187                      );
     1318                                                Private->HttpBootCallback,
     1319                                                HttpBootHttpEntityBody,
     1320                                                TRUE,
     1321                                                (UINT32)ResponseBody.BodyLength,
     1322                                                ResponseBody.Body
     1323                                                );
    11881324          if (EFI_ERROR (Status)) {
    11891325            goto ERROR_6;
     
    12041340        // every HttpIoRecvResponse().
    12051341        //
    1206         if (Block == NULL || Context.BufferSize == 0) {
     1342        if ((Block == NULL) || (Context.BufferSize == 0)) {
    12071343          Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE);
    12081344          if (Block == NULL) {
     
    12101346            goto ERROR_6;
    12111347          }
     1348
    12121349          Context.NewBlock = TRUE;
    1213           Context.Block = Block;
     1350          Context.Block    = Block;
    12141351        } else {
    12151352          Context.NewBlock = FALSE;
    12161353        }
    12171354
    1218         ResponseBody.Body       = (CHAR8*) Block;
     1355        ResponseBody.Body       = (CHAR8 *)Block;
    12191356        ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE;
    1220         Status = HttpIoRecvResponse (
    1221                    &Private->HttpIo,
    1222                    FALSE,
    1223                    &ResponseBody
    1224                    );
     1357        Status                  = HttpIoRecvResponse (
     1358                                    &Private->HttpIo,
     1359                                    FALSE,
     1360                                    &ResponseBody
     1361                                    );
    12251362        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {
    12261363          if (EFI_ERROR (ResponseBody.Status)) {
    12271364            Status = ResponseBody.Status;
    12281365          }
     1366
    12291367          goto ERROR_6;
    12301368        }
     
    12581396    Status = EFI_SUCCESS;
    12591397  }
     1398
    12601399  *BufferSize = ContentLength;
    12611400
     
    12781417    HttpFreeMsgParser (Parser);
    12791418  }
     1419
    12801420  if (Context.Block != NULL) {
    12811421    FreePool (Context.Block);
    12821422  }
     1423
    12831424  HttpBootFreeCache (Cache);
    12841425
     
    12871428    FreePool (ResponseData);
    12881429  }
     1430
    12891431ERROR_4:
    12901432  if (RequestData != NULL) {
    12911433    FreePool (RequestData);
    12921434  }
     1435
    12931436ERROR_3:
    12941437  HttpIoFreeHeader (HttpIoHeader);
     
    12971440    FreePool (Cache);
    12981441  }
     1442
    12991443ERROR_1:
    13001444  if (Url != NULL) {
     
    13041448  return Status;
    13051449}
    1306 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette