VirtualBox

Ignore:
Timestamp:
Oct 28, 2015 8:17:18 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103761
Message:

EFI/Firmware: 'svn merge /vendor/edk2/UDK2010.SR1 /vendor/edk2/current .', reverting and removing files+dirs listed in ReadMe.vbox, resolving conflicts with help from ../UDK2014.SP1/. This is a raw untested merge.

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
11 edited

Legend:

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

  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/ComponentName.c

    r48674 r58459  
    22  UEFI Component Name(2) protocol implementation for Dhcp6 driver.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    173173};
    174174
     175GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE   *gDhcp6ControllerNameTable = NULL;
     176
     177CHAR16 *mDhcp6ControllerName[] = {
     178  L"DHCPv6 (State=0, Init)",
     179  L"DHCPv6 (State=1, Selecting)",
     180  L"DHCPv6 (State=2, Requesting)",
     181  L"DHCPv6 (State=3, Declining)",
     182  L"DHCPv6 (State=4, Confirming)",
     183  L"DHCPv6 (State=5, Releasing)",
     184  L"DHCPv6 (State=6, Bound)",
     185  L"DHCPv6 (State=7, Renewing)",
     186  L"DHCPv6 (State=8, Rebinding)"
     187};
    175188
    176189/**
     
    230243}
    231244
     245/**
     246  Update the component name for the Dhcp6 child handle.
     247
     248  @param  Dhcp6[in]                   A pointer to the EFI_DHCP6_PROTOCOL.
     249
     250 
     251  @retval EFI_SUCCESS                 Update the ControllerNameTable of this instance successfully.
     252  @retval EFI_INVALID_PARAMETER       The input parameter is invalid.
     253 
     254**/
     255EFI_STATUS
     256UpdateName (
     257  IN   EFI_DHCP6_PROTOCOL             *Dhcp6
     258  )
     259{
     260  EFI_STATUS                       Status;
     261  EFI_DHCP6_MODE_DATA              Dhcp6ModeData;
     262  CHAR16                           *HandleName;
     263
     264  if (Dhcp6 == NULL) {
     265    return EFI_INVALID_PARAMETER;
     266  }
     267
     268  //
     269  // Format the child name into the string buffer.
     270  //
     271  Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);
     272  if (EFI_ERROR (Status)) {
     273    return Status;
     274  }
     275 
     276  if (gDhcp6ControllerNameTable != NULL) {
     277    FreeUnicodeStringTable (gDhcp6ControllerNameTable);
     278    gDhcp6ControllerNameTable = NULL;
     279  }
     280 
     281  if (Dhcp6ModeData.Ia == NULL) {
     282    HandleName = L"DHCPv6 (No configured IA)";
     283  } else {
     284    if (Dhcp6ModeData.Ia->State > Dhcp6Rebinding) {
     285      return EFI_DEVICE_ERROR;
     286    }
     287    HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];
     288  }
     289 
     290  Status = AddUnicodeString2 (
     291             "eng",
     292             gDhcp6ComponentName.SupportedLanguages,
     293             &gDhcp6ControllerNameTable,
     294             HandleName,
     295             TRUE
     296             );
     297  if (EFI_ERROR (Status)) {
     298    return Status;
     299  }
     300 
     301  return AddUnicodeString2 (
     302           "en",
     303           gDhcp6ComponentName2.SupportedLanguages,
     304           &gDhcp6ControllerNameTable,
     305           HandleName,
     306           FALSE
     307           );
     308}
    232309
    233310/**
     
    309386  )
    310387{
    311   return EFI_UNSUPPORTED;
     388  EFI_STATUS                    Status;
     389  EFI_DHCP6_PROTOCOL            *Dhcp6;
     390
     391  //
     392  // Only provide names for child handles.
     393  //
     394  if (ChildHandle == NULL) {
     395    return EFI_UNSUPPORTED;
     396  }
     397 
     398  //
     399  // Make sure this driver produced ChildHandle
     400  //
     401  Status = EfiTestChildHandle (
     402             ControllerHandle,
     403             ChildHandle,
     404             &gEfiUdp6ProtocolGuid
     405             );
     406  if (EFI_ERROR (Status)) {
     407    return Status;
     408  }
     409
     410  //
     411  // Retrieve an instance of a produced protocol from ChildHandle
     412  //
     413  Status = gBS->OpenProtocol (
     414                  ChildHandle,
     415                  &gEfiDhcp6ProtocolGuid,
     416                  (VOID **)&Dhcp6,
     417                  NULL,
     418                  NULL,
     419                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
     420                  );
     421  if (EFI_ERROR (Status)) {
     422    return Status;
     423  }
     424
     425  //
     426  // Update the component name for this child handle.
     427  //
     428  Status = UpdateName (Dhcp6);
     429  if (EFI_ERROR (Status)) {
     430    return Status;
     431  }
     432
     433  return LookupUnicodeString2 (
     434           Language,
     435           This->SupportedLanguages,
     436           gDhcp6ControllerNameTable,
     437           ControllerName,
     438           (BOOLEAN)(This == &gDhcp6ComponentName)
     439           );
    312440}
     441
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Driver.c

    r48674 r58459  
    33  implementationfor for Dhcp6 Driver.
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    66
    77  This program and the accompanying materials
     
    3232};
    3333
    34 
    3534/**
    3635  Configure the default Udp6Io to receive all the DHCP6 traffic
     
    8382
    8483/**
    85   Destory the Dhcp6 service. The Dhcp6 service may be partly initialized,
     84  Destroy the Dhcp6 service. The Dhcp6 service may be partly initialized,
    8685  or partly destroyed. If a resource is destroyed, it is marked as such in
    8786  case the destroy failed and being called again later.
     
    9695{
    9796  //
    98   // All children instances should have been already destoryed here.
     97  // All children instances should have been already destroyed here.
    9998  //
    10099  ASSERT (Service->NumOfChild == 0);
     
    133132{
    134133  DHCP6_SERVICE             *Dhcp6Srv;
     134  EFI_STATUS                Status;
    135135
    136136  *Service = NULL;
     
    155155  //
    156156  Dhcp6Srv->Signature       = DHCP6_SERVICE_SIGNATURE;
    157   Dhcp6Srv->InDestory       = FALSE;
    158157  Dhcp6Srv->Controller      = Controller;
    159158  Dhcp6Srv->Image           = ImageHandle;
     
    165164    sizeof (EFI_SERVICE_BINDING_PROTOCOL)
    166165    );
     166
     167  //
     168  // Locate Ip6->Ip6Config and store it for get IP6 Duplicate Address Detection transmits.
     169  //
     170  Status = gBS->HandleProtocol (
     171                  Controller,
     172                  &gEfiIp6ConfigProtocolGuid,
     173                  (VOID **) &Dhcp6Srv->Ip6Cfg
     174                  );
     175  if (EFI_ERROR (Status)) {
     176    FreePool (Dhcp6Srv);
     177    return Status;
     178  }
    167179
    168180  //
     
    281293  Dhcp6Ins->UdpSts          = EFI_ALREADY_STARTED;
    282294  Dhcp6Ins->Service         = Service;
    283   Dhcp6Ins->InDestory       = FALSE;
     295  Dhcp6Ins->InDestroy       = FALSE;
    284296  Dhcp6Ins->MediaPresent    = TRUE;
    285297
     
    313325
    314326  return EFI_SUCCESS;
     327}
     328
     329/**
     330  Callback function which provided by user to remove one node in NetDestroyLinkList process.
     331 
     332  @param[in]    Entry           The entry to be removed.
     333  @param[in]    Context         Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
     334
     335  @retval EFI_SUCCESS           The entry has been removed successfully.
     336  @retval Others                Fail to remove the entry.
     337
     338**/
     339EFI_STATUS
     340EFIAPI
     341Dhcp6DestroyChildEntry (
     342  IN LIST_ENTRY         *Entry,
     343  IN VOID               *Context
     344  )
     345{
     346  DHCP6_INSTANCE                   *Instance;
     347  EFI_SERVICE_BINDING_PROTOCOL     *ServiceBinding;
     348
     349  if (Entry == NULL || Context == NULL) {
     350    return EFI_INVALID_PARAMETER;
     351  }
     352
     353  Instance = NET_LIST_USER_STRUCT_S (Entry, DHCP6_INSTANCE, Link, DHCP6_INSTANCE_SIGNATURE);
     354  ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context;
     355 
     356  return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
    315357}
    316358
     
    485527{
    486528  EFI_STATUS                       Status;
    487   EFI_TPL                          OldTpl;
    488529  EFI_HANDLE                       NicHandle;
    489530  EFI_SERVICE_BINDING_PROTOCOL     *ServiceBinding;
    490531  DHCP6_SERVICE                    *Service;
    491   DHCP6_INSTANCE                   *Instance;
     532  LIST_ENTRY                       *List;
     533  UINTN                            ListLength;
    492534
    493535  //
     
    497539
    498540  if (NicHandle == NULL) {
    499     return EFI_DEVICE_ERROR;
     541    return EFI_SUCCESS;
    500542  }
    501543
     
    514556
    515557  Service = DHCP6_SERVICE_FROM_THIS (ServiceBinding);
    516 
    517   if (Service->InDestory) {
    518     return EFI_SUCCESS;
    519   }
    520 
    521   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
    522 
    523   if (NumberOfChildren == 0) {
     558  if (!IsListEmpty (&Service->Child)) {
    524559    //
    525     // Destory the service itself if no child instance left.
     560    // Destroy all the children instances before destory the service.
     561    // 
     562    List = &Service->Child;
     563    Status = NetDestroyLinkList (
     564               List,
     565               Dhcp6DestroyChildEntry,
     566               ServiceBinding,
     567               &ListLength
     568               );
     569    if (EFI_ERROR (Status) || ListLength != 0) {
     570      Status = EFI_DEVICE_ERROR;
     571    }
     572  }
     573
     574  if (NumberOfChildren == 0 && !IsListEmpty (&Service->Child)) {
     575    Status = EFI_DEVICE_ERROR;
     576  }
     577
     578  if (NumberOfChildren == 0 && IsListEmpty (&Service->Child)) {
    526579    //
    527     Service->InDestory = TRUE;
    528 
     580    // Destroy the service itself if no child instance left.
     581    //
    529582    Status = gBS->UninstallProtocolInterface (
    530583                    NicHandle,
     
    532585                    ServiceBinding
    533586                    );
    534 
    535587    if (EFI_ERROR (Status)) {
    536       Service->InDestory = FALSE;
    537588      goto ON_EXIT;
    538589    }
    539590
    540591    Dhcp6DestroyService (Service);
    541 
    542   } else {
    543     //
    544     // Destory all the children instances before destory the service.
    545     //
    546     while (!IsListEmpty (&Service->Child)) {
    547       Instance = NET_LIST_HEAD (&Service->Child, DHCP6_INSTANCE, Link);
    548       ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
    549     }
    550     //
    551     // Any of child failed to be destroyed.
    552     //
    553     if (Service->NumOfChild != 0) {
    554       Status = EFI_DEVICE_ERROR;
    555     }
    556   }
    557 
     592    Status = EFI_SUCCESS;
     593  }
     594 
    558595ON_EXIT:
    559   gBS->RestoreTPL (OldTpl);
    560596  return Status;
    561597}
     
    734770  }
    735771
    736   if (Instance->InDestory) {
     772  if (Instance->InDestroy) {
    737773    return EFI_SUCCESS;
    738774  }
     
    740776  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
    741777
    742   Instance->InDestory = TRUE;
     778  Instance->InDestroy = TRUE;
    743779
    744780  Status = gBS->CloseProtocol (
     
    750786
    751787  if (EFI_ERROR (Status)) {
    752     Instance->InDestory = FALSE;
     788    Instance->InDestroy = FALSE;
    753789    gBS->RestoreTPL (OldTpl);
    754790    return Status;
     
    758794  // Uninstall the MTFTP6 protocol first to enable a top down destruction.
    759795  //
     796  gBS->RestoreTPL (OldTpl);
    760797  Status = gBS->UninstallProtocolInterface (
    761798                  ChildHandle,
     
    763800                  Dhcp6
    764801                  );
    765 
    766   if (EFI_ERROR (Status)) {
    767     Instance->InDestory = FALSE;
     802  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
     803  if (EFI_ERROR (Status)) {
     804    Instance->InDestroy = FALSE;
    768805    gBS->RestoreTPL (OldTpl);
    769806    return Status;
     
    776813  Service->NumOfChild--;
    777814
     815  gBS->RestoreTPL (OldTpl);
     816
    778817  Dhcp6DestroyInstance (Instance);
    779 
    780   gBS->RestoreTPL (OldTpl);
    781 
    782818  return EFI_SUCCESS;
    783819}
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Driver.h

    r48674 r58459  
    33  declaration for Dhcp6 Driver.
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    66
    77  This program and the accompanying materials
     
    2222extern EFI_COMPONENT_NAME_PROTOCOL  gDhcp6ComponentName;
    2323extern EFI_COMPONENT_NAME2_PROTOCOL gDhcp6ComponentName2;
     24extern EFI_UNICODE_STRING_TABLE     *gDhcp6ControllerNameTable;
    2425
    2526/**
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Dxe.inf

    r48674 r58459  
    11## @file
    2 #  Component description file for Dhcp6 module.
     2#  Client-side DHCPv6 services.
     3
     4#  This driver produces EFI DHCPv6 Protocol which is used to get IPv6 addresses
     5#  and other configuration parameters from DHCPv6 servers.
    36#
    4 #  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     7#  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    58#
    69#  This program and the accompanying materials
     
    2225  ENTRY_POINT                    = Dhcp6DriverEntryPoint
    2326  UNLOAD_IMAGE                   = NetLibDefaultUnload
     27  MODULE_UNI_FILE                = Dhcp6Dxe.uni
     28
    2429#
    2530# The following information is for reference only and not required by the build tools.
     
    6368
    6469[Protocols]
    65   gEfiUdp6ServiceBindingProtocolGuid
    66   gEfiUdp6ProtocolGuid
    67   gEfiDhcp6ServiceBindingProtocolGuid
    68   gEfiDhcp6ProtocolGuid
     70  gEfiUdp6ServiceBindingProtocolGuid                 ## TO_START
     71  gEfiUdp6ProtocolGuid                               ## TO_START
     72  gEfiDhcp6ServiceBindingProtocolGuid                ## BY_START
     73  gEfiDhcp6ProtocolGuid                              ## BY_START
     74  gEfiIp6ConfigProtocolGuid                          ## TO_START
    6975
     76[UserExtensions.TianoCore."ExtraFiles"]
     77  Dhcp6DxeExtra.uni
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c

    r48674 r58459  
    22  This EFI_DHCP6_PROTOCOL interface implementation.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    105105
    106106  //
    107   // Need to clear initial time to make sure that elapsed-time
    108   // is set to 0 for first Solicit.
    109   //
    110   Instance->StartTime = 0;
    111 
    112   //
    113107  // Send the solicit message to start S.A.R.R process.
    114108  //
     
    201195
    202196  //
    203   // The instance has already been stopped.
     197  // No valid REPLY message received yet, cleanup this instance directly.
    204198  //
    205199  if (Instance->IaCb.Ia->State == Dhcp6Init ||
     
    207201      Instance->IaCb.Ia->State == Dhcp6Requesting
    208202      ) {
    209     return Status;
     203    goto ON_EXIT;
    210204  }
    211205
     
    216210
    217211  Instance->UdpSts = EFI_ALREADY_STARTED;
    218   Dhcp6SendReleaseMsg (Instance, Instance->IaCb.Ia);
    219 
     212  Status = Dhcp6SendReleaseMsg (Instance, Instance->IaCb.Ia);
    220213  gBS->RestoreTPL (OldTpl);
     214  if (EFI_ERROR (Status)) {
     215    goto ON_EXIT;
     216  }
    221217
    222218  //
     
    230226    Status = Instance->UdpSts;
    231227  }
    232 
     228 
     229ON_EXIT:
    233230  //
    234231  // Clean up the session data for the released Ia.
     
    605602{
    606603  EFI_STATUS                   Status;
    607   EFI_TPL                      OldTpl;
    608604  DHCP6_INSTANCE               *Instance;
    609605  DHCP6_SERVICE                *Service;
    610   DHCP6_INF_CB                 *InfCb;
    611606  UINTN                        Index;
     607  EFI_EVENT                    Timer;
     608  EFI_STATUS                   TimerStatus;
     609  UINTN                        GetMappingTimeOut;
    612610
    613611  if (This == NULL || OptionRequest == NULL || Retransmission == NULL || ReplyCallback == NULL) {
     
    634632  Service  = Instance->Service;
    635633
    636   OldTpl           = gBS->RaiseTPL (TPL_CALLBACK);
    637   Instance->UdpSts = EFI_ALREADY_STARTED;
    638 
    639   //
    640   // Create and initialize the control block for the info-request.
    641   //
    642   InfCb = AllocateZeroPool (sizeof(DHCP6_INF_CB));
    643 
    644   if (InfCb == NULL) {
    645     gBS->RestoreTPL (OldTpl);
    646     return EFI_OUT_OF_RESOURCES;
    647   }
    648 
    649   InfCb->ReplyCallback   = ReplyCallback;
    650   InfCb->CallbackContext = CallbackContext;
    651   InfCb->TimeoutEvent    = TimeoutEvent;
    652 
    653   InsertTailList (&Instance->InfList, &InfCb->Link);
    654 
    655   //
    656   // Send the info-request message to start exchange process.
    657   //
    658   Status = Dhcp6SendInfoRequestMsg (
     634  Status = Dhcp6StartInfoRequest (
    659635             Instance,
    660              InfCb,
    661636             SendClientId,
    662637             OptionRequest,
    663638             OptionCount,
    664639             OptionList,
    665              Retransmission
     640             Retransmission,
     641             TimeoutEvent,
     642             ReplyCallback,
     643             CallbackContext
    666644             );
    667 
     645  if (Status == EFI_NO_MAPPING) {
     646    //
     647    // The link local address is not ready, wait for some time and restart
     648    // the DHCP6 information request process.
     649    //
     650    Status = Dhcp6GetMappingTimeOut(Service->Ip6Cfg, &GetMappingTimeOut);
     651    if (EFI_ERROR(Status)) {
     652      return Status;
     653    }
     654
     655    Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);
     656    if (EFI_ERROR (Status)) {
     657      return Status;
     658    }
     659
     660    //
     661    // Start the timer, wait for link local address DAD to finish.
     662    //
     663    Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut);
     664    if (EFI_ERROR (Status)) {
     665      gBS->CloseEvent (Timer);
     666      return Status;
     667    }
     668
     669    do { 
     670      TimerStatus = gBS->CheckEvent (Timer);
     671      if (!EFI_ERROR (TimerStatus)) {
     672        Status = Dhcp6StartInfoRequest (
     673                   Instance,
     674                   SendClientId,
     675                   OptionRequest,
     676                   OptionCount,
     677                   OptionList,
     678                   Retransmission,
     679                   TimeoutEvent,
     680                   ReplyCallback,
     681                   CallbackContext
     682                   );
     683      }
     684    } while (TimerStatus == EFI_NOT_READY);
     685   
     686    gBS->CloseEvent (Timer);
     687  }
    668688  if (EFI_ERROR (Status)) {
    669     goto ON_ERROR;
    670   }
    671 
    672   //
    673   // Register receive callback for the stateless exchange process.
    674   //
    675   Status = UdpIoRecvDatagram(
    676              Service->UdpIo,
    677              Dhcp6ReceivePacket,
    678              Service,
    679              0
    680              );
    681 
    682   if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
    683     goto ON_ERROR;
    684   }
    685 
    686   gBS->RestoreTPL (OldTpl);
     689    return Status;
     690  }
    687691
    688692  //
     
    698702
    699703  return EFI_SUCCESS;
    700 
    701 ON_ERROR:
    702 
    703   RemoveEntryList (&InfCb->Link);
    704   FreePool (InfCb);
    705   gBS->RestoreTPL (OldTpl);
    706 
    707   return Status;
    708704}
    709705
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h

    r48674 r58459  
    22  Dhcp6 internal data structure and definition declaration.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    2222#include <Protocol/Dhcp6.h>
    2323#include <Protocol/Udp6.h>
     24#include <Protocol/Ip6Config.h>
    2425#include <Protocol/ServiceBinding.h>
    2526#include <Protocol/DriverBinding.h>
     
    3435#include <Library/BaseLib.h>
    3536#include <Library/NetLib.h>
     37#include <Library/PrintLib.h>
    3638
    3739
     
    245247  UINT8                         AdPref;
    246248  EFI_IPv6_ADDRESS              *Unicast;
    247   EFI_STATUS                    UdpSts;
    248   BOOLEAN                       InDestory;
     249  volatile EFI_STATUS           UdpSts;
     250  BOOLEAN                       InDestroy;
    249251  BOOLEAN                       MediaPresent;
     252  //
     253  // StartTime is used to calculate the 'elapsed-time' option. Refer to RFC3315,
     254  // the elapsed-time is amount of time since the client began its current DHCP transaction.
     255  //
    250256  UINT64                        StartTime;
    251257};
     
    260266  EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;
    261267  EFI_SIMPLE_NETWORK_PROTOCOL   *Snp;
     268  EFI_IP6_CONFIG_PROTOCOL       *Ip6Cfg;
    262269  EFI_DHCP6_DUID                *ClientId;
    263270  UDP_IO                        *UdpIo;
     
    265272  LIST_ENTRY                    Child;
    266273  UINTN                         NumOfChild;
    267   BOOLEAN                       InDestory;
    268274};
    269275
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c

    r48674 r58459  
    22  Dhcp6 internal functions implementation.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    5353
    5454  //
    55   // Save tx packet pointer, and it will be destoryed when reply received.
     55  // Save tx packet pointer, and it will be destroyed when reply received.
    5656  //
    5757  TxCb->TxPacket = Packet;
     
    364364}
    365365
     366/**
     367  Check whether the TxCb is still a valid control block in the instance's retry list.
     368
     369  @param[in]  Instance       The pointer to DHCP6_INSTANCE.
     370  @param[in]  TxCb           The control block for a transmitted message.
     371
     372  @retval   TRUE      The control block is in Instance's retry list.
     373  @retval   FALSE     The control block is NOT in Instance's retry list.
     374 
     375**/
     376BOOLEAN
     377Dhcp6IsValidTxCb (
     378  IN  DHCP6_INSTANCE          *Instance,
     379  IN  DHCP6_TX_CB             *TxCb
     380  )
     381{
     382  LIST_ENTRY                *Entry;
     383
     384  NET_LIST_FOR_EACH (Entry, &Instance->TxList) {
     385    if (TxCb == NET_LIST_USER_STRUCT (Entry, DHCP6_TX_CB, Link)) {
     386      return TRUE;
     387    }
     388  }
     389
     390  return FALSE;
     391}
    366392
    367393/**
     
    594620    T1 = NTOHL (ReadUnaligned32 ((UINT32 *) (Option + 8)));
    595621    T2 = NTOHL (ReadUnaligned32 ((UINT32 *) (Option + 12)));
     622    //
     623    // Refer to RFC3155 Chapter 22.4. If a client receives an IA_NA with T1 greater than T2,
     624    // and both T1 and T2 are greater than 0, the client discards the IA_NA option and processes
     625    // the remainder of the message as though the server had not  included the invalid IA_NA option.
     626    //
     627    if (T1 > T2 && T2 > 0) {
     628      return EFI_DEVICE_ERROR;
     629    }
    596630    IaInnerOpt = Option + 16;
    597631    IaInnerLen = (UINT16) (NTOHS (ReadUnaligned16 ((UINT16 *) (Option + 2))) - 12);
     
    698732              );
    699733  if (*Option == NULL) {
    700     return EFI_DEVICE_ERROR;
     734    return EFI_SUCCESS;
    701735  }
    702736
     
    950984             Instance->IaCb.Ia,
    951985             Instance->IaCb.T1,
    952              Instance->IaCb.T2
     986             Instance->IaCb.T2,
     987             Packet->Dhcp6.Header.MessageType
    953988             );
    954989
     
    9881023  //
    9891024  Instance->IaCb.Ia->State = Dhcp6Selecting;
     1025  //
     1026  // Clear initial time for current transaction.
     1027  //
     1028  Instance->StartTime = 0;
    9901029
    9911030  Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
     
    11341173             Instance->IaCb.Ia,
    11351174             Instance->IaCb.T1,
    1136              Instance->IaCb.T2
     1175             Instance->IaCb.T2,
     1176             Packet->Dhcp6.Header.MessageType
    11371177             );
    11381178
     
    11721212  //
    11731213  Instance->IaCb.Ia->State = Dhcp6Requesting;
     1214  //
     1215  // Clear initial time for current transaction.
     1216  //
     1217  Instance->StartTime = 0;
    11741218
    11751219  Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
     
    12831327             );
    12841328
    1285   Cursor = Dhcp6AppendIaOption (Cursor, DecIa, 0, 0);
     1329  Cursor = Dhcp6AppendIaOption (Cursor, DecIa, 0, 0, Packet->Dhcp6.Header.MessageType);
    12861330
    12871331  //
     
    13061350  //
    13071351  Instance->IaCb.Ia->State = Dhcp6Declining;
     1352  //
     1353  // Clear initial time for current transaction.
     1354  //
     1355  Instance->StartTime = 0;
    13081356
    13091357  Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
     
    14161464             );
    14171465
    1418   Cursor = Dhcp6AppendIaOption (Cursor, RelIa, 0, 0);
     1466  Cursor = Dhcp6AppendIaOption (Cursor, RelIa, 0, 0, Packet->Dhcp6.Header.MessageType);
    14191467
    14201468  //
     
    15411589             Instance->IaCb.Ia,
    15421590             Instance->IaCb.T1,
    1543              Instance->IaCb.T2
     1591             Instance->IaCb.T2,
     1592             Packet->Dhcp6.Header.MessageType
    15441593             );
    15451594
     
    16131662  Instance->IaCb.Ia->State = State;
    16141663  Instance->IaCb.LeaseTime = (RebindRequest) ? Instance->IaCb.T2 : Instance->IaCb.T1;
     1664  //
     1665  // Clear initial time for current transaction.
     1666  //
     1667  Instance->StartTime = 0;
    16151668
    16161669  Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
     
    16271680}
    16281681
     1682/**
     1683  Start the information request process.
     1684
     1685  @param[in]  Instance          The pointer to the Dhcp6 instance.
     1686  @param[in]  SendClientId      If TRUE, the client identifier option will be included in
     1687                                information request message. Otherwise, the client identifier
     1688                                option will not be included.
     1689  @param[in]  OptionRequest     The pointer to the option request option.
     1690  @param[in]  OptionCount       The number options in the OptionList.
     1691  @param[in]  OptionList        The array pointers to the appended options.
     1692  @param[in]  Retransmission    The pointer to the retransmission control.
     1693  @param[in]  TimeoutEvent      The event of timeout.
     1694  @param[in]  ReplyCallback     The callback function when the reply was received.
     1695  @param[in]  CallbackContext   The pointer to the parameter passed to the callback.
     1696
     1697  @retval EFI_SUCCESS           Start the info-request process successfully.
     1698  @retval EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
     1699  @retval EFI_NO_MAPPING        No source address is available for use.
     1700  @retval Others                Failed to start the info-request process.
     1701
     1702**/
     1703EFI_STATUS
     1704Dhcp6StartInfoRequest (
     1705  IN DHCP6_INSTANCE            *Instance,
     1706  IN BOOLEAN                   SendClientId,
     1707  IN EFI_DHCP6_PACKET_OPTION   *OptionRequest,
     1708  IN UINT32                    OptionCount,
     1709  IN EFI_DHCP6_PACKET_OPTION   *OptionList[]    OPTIONAL,
     1710  IN EFI_DHCP6_RETRANSMISSION  *Retransmission,
     1711  IN EFI_EVENT                 TimeoutEvent     OPTIONAL,
     1712  IN EFI_DHCP6_INFO_CALLBACK   ReplyCallback,
     1713  IN VOID                      *CallbackContext OPTIONAL
     1714  )
     1715{
     1716  EFI_STATUS                   Status;
     1717  DHCP6_INF_CB                 *InfCb;
     1718  DHCP6_SERVICE                *Service;
     1719  EFI_TPL                      OldTpl;
     1720
     1721  Service  = Instance->Service;
     1722
     1723  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
     1724  Instance->UdpSts = EFI_ALREADY_STARTED;
     1725  //
     1726  // Create and initialize the control block for the info-request.
     1727  //
     1728  InfCb = AllocateZeroPool (sizeof(DHCP6_INF_CB));
     1729
     1730  if (InfCb == NULL) {
     1731    gBS->RestoreTPL (OldTpl);
     1732    return EFI_OUT_OF_RESOURCES;
     1733  }
     1734
     1735  InfCb->ReplyCallback   = ReplyCallback;
     1736  InfCb->CallbackContext = CallbackContext;
     1737  InfCb->TimeoutEvent    = TimeoutEvent;
     1738
     1739  InsertTailList (&Instance->InfList, &InfCb->Link);
     1740
     1741  //
     1742  // Send the info-request message to start exchange process.
     1743  //
     1744  Status = Dhcp6SendInfoRequestMsg (
     1745             Instance,
     1746             InfCb,
     1747             SendClientId,
     1748             OptionRequest,
     1749             OptionCount,
     1750             OptionList,
     1751             Retransmission
     1752             );
     1753
     1754  if (EFI_ERROR (Status)) {
     1755    goto ON_ERROR;
     1756  }
     1757
     1758  //
     1759  // Register receive callback for the stateless exchange process.
     1760  //
     1761  Status = UdpIoRecvDatagram(
     1762             Service->UdpIo,
     1763             Dhcp6ReceivePacket,
     1764             Service,
     1765             0
     1766             );
     1767
     1768  if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
     1769    goto ON_ERROR;
     1770  }
     1771 
     1772  gBS->RestoreTPL (OldTpl);
     1773  return EFI_SUCCESS;
     1774 
     1775ON_ERROR:
     1776  gBS->RestoreTPL (OldTpl);
     1777  RemoveEntryList (&InfCb->Link);
     1778  FreePool (InfCb);
     1779
     1780  return Status;
     1781}
    16291782
    16301783/**
     
    17451898  Packet->Length += (UINT32) (Cursor - Packet->Dhcp6.Option);
    17461899  ASSERT (Packet->Size > Packet->Length + 8);
     1900 
     1901  //
     1902  // Clear initial time for current transaction.
     1903  //
     1904  Instance->StartTime = 0;
    17471905
    17481906  //
     
    18422000             Instance->IaCb.Ia,
    18432001             Instance->IaCb.T1,
    1844              Instance->IaCb.T2
     2002             Instance->IaCb.T2,
     2003             Packet->Dhcp6.Header.MessageType
    18452004             );
    18462005
     
    18792038  //
    18802039  Instance->IaCb.Ia->State = Dhcp6Confirming;
     2040  //
     2041  // Clear initial time for current transaction.
     2042  //
     2043  Instance->StartTime = 0;
    18812044
    18822045  Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
     
    19212084  ASSERT (Packet != NULL);
    19222085
     2086  Status = EFI_SUCCESS;
     2087
    19232088  if (Packet->Dhcp6.Header.MessageType != Dhcp6MsgReply) {
    19242089    return EFI_DEVICE_ERROR;
     
    19572122               );
    19582123    if (Option == NULL) {
    1959       return EFI_DEVICE_ERROR;
     2124      return EFI_SUCCESS;
    19602125    }
    19612126  }
     
    19652130  //
    19662131  Status = Dhcp6CallbackUser (Instance, Dhcp6RcvdReply, &Packet);
    1967 
    1968   if (EFI_ERROR (Status)) {
    1969     return Status;
    1970   }
    1971 
    1972   //
    1973   // Dequeue the sent packet from retransmit list since reply received.
    1974   //
    1975   Status = Dhcp6DequeueRetry (
    1976              Instance,
    1977              Packet->Dhcp6.Header.TransactionId,
    1978              FALSE
    1979              );
    19802132
    19812133  if (EFI_ERROR (Status)) {
     
    20162168    Instance->StartTime       = 0;
    20172169
    2018     return EFI_SUCCESS;
     2170    Status = EFI_SUCCESS;
     2171    goto ON_EXIT;
    20192172  }
    20202173
     
    20332186  if (!EFI_ERROR (Status)) {
    20342187    //
    2035     // Reset start time for next exchange.
    2036     //
    2037     Instance->StartTime       = 0;
    2038 
    2039     //
    20402188    // No status code or no error status code means succeed to reply.
    20412189    //
    20422190    Status = Dhcp6UpdateIaInfo (Instance, Packet);
    2043 
    2044     if (EFI_ERROR (Status)) {
    2045       return Status;
     2191    if (!EFI_ERROR (Status)) {
     2192      //
     2193      // Reset start time for next exchange.
     2194      //
     2195      Instance->StartTime       = 0;
     2196
     2197      //
     2198      // Set bound state and store the reply packet.
     2199      //
     2200      if (Instance->IaCb.Ia->ReplyPacket != NULL) {
     2201        FreePool (Instance->IaCb.Ia->ReplyPacket);
     2202      }
     2203
     2204      Instance->IaCb.Ia->ReplyPacket = AllocateZeroPool (Packet->Size);
     2205
     2206      if (Instance->IaCb.Ia->ReplyPacket == NULL) {
     2207        Status = EFI_OUT_OF_RESOURCES;
     2208        goto ON_EXIT;
     2209      }
     2210
     2211      CopyMem (Instance->IaCb.Ia->ReplyPacket, Packet, Packet->Size);
     2212
     2213      Instance->IaCb.Ia->State = Dhcp6Bound;
     2214
     2215      //
     2216      // For sync, set the success flag out of polling in start/renewrebind.
     2217      //
     2218      Instance->UdpSts         = EFI_SUCCESS;
     2219
     2220      //
     2221      // Maybe this is a new round DHCP process due to some reason, such as NotOnLink
     2222      // ReplyMsg for ConfirmMsg should triger new round to acquire new address. In that
     2223      // case, clear old address.ValidLifetime and append to new address. Therefore, DHCP
     2224      // consumers can be notified to flush old address.
     2225      //
     2226      Dhcp6AppendCacheIa (Instance);
     2227
     2228      //
     2229      // For async, signal the Ia event to inform Ia infomation update.
     2230      //
     2231      if (Instance->Config->IaInfoEvent != NULL) {
     2232        gBS->SignalEvent (Instance->Config->IaInfoEvent);
     2233      }
     2234    } else if (Status == EFI_NOT_FOUND) {
     2235      //
     2236      // Refer to RFC3315 Chapter 18.1.8, for each IA in the original Renew or Rebind message,
     2237      // the client sends a Renew or Rebind if the IA is not in the Reply message.
     2238      // Return EFI_SUCCESS so we can continue to restart the Renew/Rebind process.
     2239      //
     2240      return EFI_SUCCESS;
    20462241    }
    2047 
    2048     //
    2049     // Set bound state and store the reply packet.
    2050     //
    2051     if (Instance->IaCb.Ia->ReplyPacket != NULL) {
    2052       FreePool (Instance->IaCb.Ia->ReplyPacket);
    2053     }
    2054 
    2055     Instance->IaCb.Ia->ReplyPacket = AllocateZeroPool (Packet->Size);
    2056 
    2057     if (Instance->IaCb.Ia->ReplyPacket == NULL) {
    2058       return EFI_OUT_OF_RESOURCES;
    2059     }
    2060 
    2061     CopyMem (Instance->IaCb.Ia->ReplyPacket, Packet, Packet->Size);
    2062 
    2063     Instance->IaCb.Ia->State = Dhcp6Bound;
    2064 
    2065     //
    2066     // For sync, set the success flag out of polling in start/renewrebind.
    2067     //
    2068     Instance->UdpSts         = EFI_SUCCESS;
    2069 
    2070     //
    2071     // Maybe this is a new round DHCP process due to some reason, such as NotOnLink
    2072     // ReplyMsg for ConfirmMsg should triger new round to acquire new address. In that
    2073     // case, clear old address.ValidLifetime and append to new address. Therefore, DHCP
    2074     // consumers can be notified to flush old address.
    2075     //
    2076     Dhcp6AppendCacheIa (Instance);
    2077 
    2078     //
    2079     // For async, signal the Ia event to inform Ia infomation update.
    2080     //
    2081     if (Instance->Config->IaInfoEvent != NULL) {
    2082       gBS->SignalEvent (Instance->Config->IaInfoEvent);
    2083     }
     2242   
     2243    goto ON_EXIT;
     2244   
    20842245  } else if (Option != NULL) {
    20852246    //
     
    21272288      break;
    21282289
     2290    case Dhcp6StsNoBinding:
     2291      if (Instance->IaCb.Ia->State == Dhcp6Renewing || Instance->IaCb.Ia->State == Dhcp6Rebinding) {
     2292        //
     2293        // Refer to RFC3315 Chapter 18.1.8, for each IA in the original Renew or Rebind message, the client
     2294        // sends a Request message if the IA contained a Status Code option with the NoBinding status.
     2295        //
     2296        Status = Dhcp6SendRequestMsg(Instance);
     2297        if (EFI_ERROR (Status)) {
     2298          return Status;
     2299        }
     2300      }
     2301      break;
     2302
    21292303    default:
    21302304      //
     
    21362310
    21372311  return EFI_SUCCESS;
     2312 
     2313ON_EXIT:
     2314
     2315  if (!EFI_ERROR(Status)) {
     2316    Status = Dhcp6DequeueRetry (
     2317               Instance,
     2318               Packet->Dhcp6.Header.TransactionId,
     2319               FALSE
     2320               );
     2321  }
     2322 
     2323  return Status;
    21382324}
    21392325
     
    22792465  // See the details in the section-17.1.3 of rfc-3315.
    22802466  //
    2281   Option = Dhcp6SeekOption(
    2282              Packet->Dhcp6.Option,
    2283              Packet->Length - 4,
    2284              Dhcp6OptStatusCode
    2285              );
    2286 
    2287   if (Option != NULL) {
    2288     StsCode = NTOHS (ReadUnaligned16 ((UINT16 *) (Option + 4)));
    2289     if (StsCode != Dhcp6StsSuccess) {
    2290       return EFI_DEVICE_ERROR;
    2291     }
     2467  Status = Dhcp6SeekStsOption (
     2468             Instance,
     2469             Packet,
     2470             &Option
     2471             );
     2472  if (EFI_ERROR (Status)) {
     2473    return EFI_DEVICE_ERROR;
    22922474  }
    22932475
     
    24112593  Status   = EFI_SUCCESS;
    24122594
    2413   if (Instance->InDestory || Instance->Config == NULL) {
     2595  if (Instance->Config == NULL) {
    24142596    goto ON_CONTINUE;
    24152597  }
     
    25242706  IsMatched = FALSE;
    25252707  InfCb     = NULL;
    2526 
    2527   if (Instance->InDestory) {
    2528     goto ON_EXIT;
    2529   }
    25302708
    25312709  if (Packet->Dhcp6.Header.MessageType != Dhcp6MsgReply) {
     
    28303008          //
    28313009          Status = Dhcp6SelectAdvertiseMsg (Instance, Instance->AdSelect);
    2832           if (EFI_ERROR (Status)) {
     3010          if (Status == EFI_ABORTED) {
     3011            goto ON_CLOSE;
     3012          } else if (EFI_ERROR (Status)) {
    28333013            TxCb->RetryCnt++;
    28343014          }
     
    28463026      //
    28473027      if (TxCb->RetryCtl.Mrc != 0 && TxCb->RetryCtl.Mrc < TxCb->RetryCnt) {
     3028        Status = EFI_NO_RESPONSE;
    28483029        goto ON_CLOSE;
    28493030      }
     
    28533034      //
    28543035      if (TxCb->RetryCtl.Mrd != 0 && TxCb->RetryCtl.Mrd <= TxCb->RetryLos) {
     3036        Status = EFI_NO_RESPONSE;
    28553037        goto ON_CLOSE;
    28563038      }
     
    29423124 ON_CLOSE:
    29433125
    2944   if (TxCb->TxPacket->Dhcp6.Header.MessageType == Dhcp6MsgInfoRequest ||
     3126  if (Dhcp6IsValidTxCb (Instance, TxCb) &&
     3127      TxCb->TxPacket != NULL &&
     3128      (TxCb->TxPacket->Dhcp6.Header.MessageType == Dhcp6MsgInfoRequest ||
    29453129      TxCb->TxPacket->Dhcp6.Header.MessageType == Dhcp6MsgRenew       ||
    2946       TxCb->TxPacket->Dhcp6.Header.MessageType == Dhcp6MsgConfirm
     3130      TxCb->TxPacket->Dhcp6.Header.MessageType == Dhcp6MsgConfirm)
    29473131      ) {
    29483132    //
     
    29693153    // The failure of the others will terminate current state machine if timeout.
    29703154    //
    2971     Dhcp6CleanupSession (Instance, EFI_NO_RESPONSE);
     3155    Dhcp6CleanupSession (Instance, Status);
    29723156  }
    29733157}
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Io.h

    r48674 r58459  
    22  Dhcp6 internal functions declaration.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    128128  IN DHCP6_INSTANCE            *Instance,
    129129  IN EFI_DHCP6_IA              *RelIa
     130  );
     131
     132/**
     133  Start the information request process.
     134
     135  @param[in]  Instance          The pointer to the Dhcp6 instance.
     136  @param[in]  SendClientId      If TRUE, the client identifier option will be included in
     137                                information request message. Otherwise, the client identifier
     138                                option will not be included.
     139  @param[in]  OptionRequest     The pointer to the option request option.
     140  @param[in]  OptionCount       The number options in the OptionList.
     141  @param[in]  OptionList        The array pointers to the appended options.
     142  @param[in]  Retransmission    The pointer to the retransmission control.
     143  @param[in]  TimeoutEvent      The event of timeout.
     144  @param[in]  ReplyCallback     The callback function when the reply was received.
     145  @param[in]  CallbackContext   The pointer to the parameter passed to the callback.
     146
     147  @retval EFI_SUCCESS           Start the info-request process successfully.
     148  @retval EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
     149  @retval EFI_NO_MAPPING        No source address is available for use.
     150  @retval Others                Failed to start the info-request process.
     151
     152**/
     153EFI_STATUS
     154Dhcp6StartInfoRequest (
     155  IN DHCP6_INSTANCE            *Instance,
     156  IN BOOLEAN                   SendClientId,
     157  IN EFI_DHCP6_PACKET_OPTION   *OptionRequest,
     158  IN UINT32                    OptionCount,
     159  IN EFI_DHCP6_PACKET_OPTION   *OptionList[]    OPTIONAL,
     160  IN EFI_DHCP6_RETRANSMISSION  *Retransmission,
     161  IN EFI_EVENT                 TimeoutEvent     OPTIONAL,
     162  IN EFI_DHCP6_INFO_CALLBACK   ReplyCallback,
     163  IN VOID                      *CallbackContext OPTIONAL
    130164  );
    131165
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c

    r48674 r58459  
    22  Dhcp6 support functions implementation.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    4242  // See details in section-9 of rfc-3315.
    4343  //
    44   Duid = GetVariable (L"ClientId", &gEfiDhcp6ServiceBindingProtocolGuid);
     44  GetVariable2 (L"ClientId", &gEfiDhcp6ServiceBindingProtocolGuid, (VOID**)&Duid, NULL);
    4545  if (Duid != NULL) {
    4646    return Duid;
     
    144144    // Set the Duid-type, hardware-type, time and copy the hardware address.
    145145    //
    146     WriteUnaligned16 ((UINT16 *) (Duid->Duid), HTONS (Dhcp6DuidTypeLlt));
    147     WriteUnaligned16 ((UINT16 *) (Duid->Duid + 2), HTONS (NET_IFTYPE_ETHERNET));
    148     WriteUnaligned32 ((UINT32 *) (Duid->Duid + 4), HTONL (Stamp));
    149  
     146    WriteUnaligned16 ((UINT16 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid)), HTONS (Dhcp6DuidTypeLlt));
     147    WriteUnaligned16 ((UINT16 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid) + 2), HTONS (NET_IFTYPE_ETHERNET));
     148    WriteUnaligned32 ((UINT32 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid) + 4), HTONL (Stamp));
     149
    150150    CopyMem (Duid->Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);
    151151  }
     
    158158                  (VOID *) Duid
    159159                  );
    160   ASSERT_EFI_ERROR (Status);
     160  if (EFI_ERROR (Status)) {
     161    FreePool (Duid);
     162    return NULL;
     163  }
    161164
    162165  return Duid;
     
    384387  )
    385388{
    386   EFI_DHCP6_IA_ADDRESS        *IaAddr;
    387389  UINT32                      MinLt;
    388390  UINT32                      MaxLt;
     
    399401  //
    400402  for (Index = 0; Index < IaCb->Ia->IaAddressCount; Index++) {
    401     IaAddr = IaCb->Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);
    402     MinLt  = MIN (MinLt, IaAddr->ValidLifetime);
    403     MaxLt  = MAX (MinLt, IaAddr->ValidLifetime);
     403    MinLt  = MIN (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);
     404    MaxLt  = MAX (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);
    404405  }
    405406
     
    648649}
    649650
     651/**
     652  Append the appointed IA Address option to Buf, and move Buf to the end.
     653
     654  @param[in, out] Buf           The pointer to the position to append.
     655  @param[in]      IaAddr        The pointer to the IA Address.
     656  @param[in]      MessageType   Message type of DHCP6 package.
     657
     658  @return         Buf           The position to append the next option.
     659
     660**/
     661UINT8 *
     662Dhcp6AppendIaAddrOption (
     663  IN OUT UINT8                  *Buf,
     664  IN     EFI_DHCP6_IA_ADDRESS   *IaAddr,
     665  IN     UINT32                 MessageType
     666)
     667{
     668
     669  //  The format of the IA Address option is:
     670  //
     671  //       0                   1                   2                   3
     672  //       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     673  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     674  //      |          OPTION_IAADDR        |          option-len           |
     675  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     676  //      |                                                               |
     677  //      |                         IPv6 address                          |
     678  //      |                                                               |
     679  //      |                                                               |
     680  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     681  //      |                      preferred-lifetime                       |
     682  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     683  //      |                        valid-lifetime                         |
     684  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     685  //      .                                                               .
     686  //      .                        IAaddr-options                         .
     687  //      .                                                               .
     688  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     689 
     690  //
     691  // Fill the value of Ia Address option type
     692  //
     693  WriteUnaligned16 ((UINT16 *) Buf, HTONS (Dhcp6OptIaAddr));
     694  Buf                     += 2;
     695
     696  WriteUnaligned16 ((UINT16 *) Buf, HTONS (sizeof (EFI_DHCP6_IA_ADDRESS)));
     697  Buf                     += 2;
     698
     699  CopyMem (Buf, &IaAddr->IpAddress, sizeof(EFI_IPv6_ADDRESS));
     700  Buf                     += sizeof(EFI_IPv6_ADDRESS);
     701
     702  //
     703  // Fill the value of preferred-lifetime and valid-lifetime.
     704  // According to RFC3315 Chapter 18.1.2, the preferred-lifetime and valid-lifetime fields
     705  // should set to 0 when initiate a Confirm message.
     706  //
     707  if (MessageType != Dhcp6MsgConfirm) {
     708    WriteUnaligned32 ((UINT32 *) Buf, HTONL (IaAddr->PreferredLifetime));
     709  }
     710  Buf                     += 4;
     711
     712  if (MessageType != Dhcp6MsgConfirm) {
     713    WriteUnaligned32 ((UINT32 *) Buf, HTONL (IaAddr->ValidLifetime));
     714  }
     715  Buf                     += 4;
     716
     717  return Buf;
     718}
     719
    650720
    651721/**
     
    656726  @param[in]      T1            The time of T1.
    657727  @param[in]      T2            The time of T2.
     728  @param[in]      MessageType   Message type of DHCP6 package.
    658729
    659730  @return         Buf           The position to append the next Ia option.
     
    665736  IN     EFI_DHCP6_IA           *Ia,
    666737  IN     UINT32                 T1,
    667   IN     UINT32                 T2
     738  IN     UINT32                 T2,
     739  IN     UINT32                 MessageType
    668740  )
    669741{
     
    671743  UINT16                    *Len;
    672744  UINTN                     Index;
    673   UINT16                    Length;
    674745
    675746  //
     
    714785  //
    715786  if (Ia->Descriptor.Type == Dhcp6OptIana) {
    716     WriteUnaligned32 ((UINT32 *) Buf, ((T1 != 0) ? T1 : 0xffffffff));
     787    WriteUnaligned32 ((UINT32 *) Buf, HTONL ((T1 != 0) ? T1 : 0xffffffff));
    717788    Buf                   += 4;
    718     WriteUnaligned32 ((UINT32 *) Buf, ((T2 != 0) ? T2 : 0xffffffff));
     789    WriteUnaligned32 ((UINT32 *) Buf, HTONL ((T2 != 0) ? T2 : 0xffffffff));
    719790    Buf                   += 4;
    720791  }
     
    724795  //
    725796  for (Index = 0; Index < Ia->IaAddressCount; Index++) {
    726 
    727      AddrOpt = (UINT8 *) Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);
    728      Length  = HTONS ((UINT16) sizeof (EFI_DHCP6_IA_ADDRESS));
    729      Buf     = Dhcp6AppendOption (
    730                  Buf,
    731                  HTONS (Dhcp6OptIaAddr),
    732                  Length,
    733                  AddrOpt
    734                  );
     797    AddrOpt = (UINT8 *) Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);
     798    Buf = Dhcp6AppendIaAddrOption (Buf, (EFI_DHCP6_IA_ADDRESS *) AddrOpt, MessageType);
    735799  }
    736800
     
    828892  //
    829893  // Sentinel value of 0 means that this is the first DHCP packet that we are
    830   // sending and that we need to initialize the value.  First DHCP Solicit
     894  // sending and that we need to initialize the value.  First DHCP message
    831895  // gets 0 elapsed-time.  Otherwise, calculate based on StartTime.
    832896  //
     
    935999}
    9361000
     1001/**
     1002  Check whether the incoming IPv6 address in IaAddr is one of the maintained
     1003  addresses in the IA control blcok.
     1004
     1005  @param[in]  IaAddr            The pointer to the IA Address to be checked.
     1006  @param[in]  CurrentIa         The pointer to the IA in IA control block.
     1007
     1008  @retval     TRUE              Yes, this Address is already in IA control block.
     1009  @retval     FALSE             No, this Address is NOT in IA control block.
     1010
     1011**/
     1012BOOLEAN
     1013Dhcp6AddrIsInCurrentIa (
     1014  IN    EFI_DHCP6_IA_ADDRESS      *IaAddr,
     1015  IN    EFI_DHCP6_IA              *CurrentIa
     1016  )
     1017{
     1018  UINT32    Index;
     1019
     1020  ASSERT (IaAddr != NULL && CurrentIa != NULL);
     1021 
     1022  for (Index = 0; Index < CurrentIa->IaAddressCount; Index++) {
     1023    if (EFI_IP6_EQUAL(&IaAddr->IpAddress, &CurrentIa->IaAddress[Index].IpAddress)) {
     1024      return TRUE;
     1025    }
     1026  }
     1027  return FALSE;
     1028}
    9371029
    9381030/**
    9391031  Parse the address option and update the address infomation.
    9401032
     1033  @param[in]      CurrentIa     The pointer to the Ia Address in control blcok.
    9411034  @param[in]      IaInnerOpt    The pointer to the buffer.
    9421035  @param[in]      IaInnerLen    The length to parse.
     
    9471040VOID
    9481041Dhcp6ParseAddrOption (
     1042  IN     EFI_DHCP6_IA            *CurrentIa,
    9491043  IN     UINT8                   *IaInnerOpt,
    9501044  IN     UINT16                  IaInnerLen,
     
    9571051  UINT16                      OpCode;
    9581052  UINT32                      ValidLt;
     1053  UINT32                      PreferredLt;
     1054  EFI_DHCP6_IA_ADDRESS        *IaAddr;
    9591055
    9601056  //
     
    9931089  while (Cursor < IaInnerOpt + IaInnerLen) {
    9941090    //
    995     // Count the Ia address option with non-0 valid time.
     1091    // Refer to RFC3315 Chapter 18.1.8, we need to update lifetimes for any addresses in the IA option
     1092    // that the client already has recorded in the IA, and discard the Ia address option with 0 valid time.
    9961093    //
    9971094    OpCode  = ReadUnaligned16 ((UINT16 *) Cursor);
    998     ValidLt = ReadUnaligned32 ((UINT32 *) (Cursor + 24));
    999     if (OpCode == HTONS (Dhcp6OptIaAddr) && ValidLt != 0) {
    1000 
     1095    PreferredLt = NTOHL (ReadUnaligned32 ((UINT32 *) (Cursor + 20)));
     1096    ValidLt = NTOHL (ReadUnaligned32 ((UINT32 *) (Cursor + 24)));
     1097    IaAddr = (EFI_DHCP6_IA_ADDRESS *) (Cursor + 4);
     1098    if (OpCode == HTONS (Dhcp6OptIaAddr) && ValidLt >= PreferredLt &&
     1099        (Dhcp6AddrIsInCurrentIa(IaAddr, CurrentIa) || ValidLt !=0)) {
    10011100      if (AddrBuf != NULL) {
    1002         CopyMem (AddrBuf, Cursor + 4, sizeof (EFI_DHCP6_IA_ADDRESS));
    1003         AddrBuf->PreferredLifetime = NTOHL (AddrBuf->PreferredLifetime);
    1004         AddrBuf->ValidLifetime     = NTOHL (AddrBuf->ValidLifetime);
     1101        CopyMem (AddrBuf, IaAddr, sizeof (EFI_DHCP6_IA_ADDRESS));
     1102        AddrBuf->PreferredLifetime = PreferredLt;
     1103        AddrBuf->ValidLifetime     = ValidLt;
    10051104        AddrBuf = (EFI_DHCP6_IA_ADDRESS *) ((UINT8 *) AddrBuf + sizeof (EFI_DHCP6_IA_ADDRESS));
    10061105      }
    1007 
    10081106      (*AddrNum)++;
    10091107    }
     
    10261124  @retval     EFI_SUCCESS           Create an IA control block successfully.
    10271125  @retval     EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
     1126  @retval     EFI_DEVICE_ERROR      An unexpected error.
    10281127
    10291128**/
     
    10421141
    10431142  if (Instance->IaCb.Ia == NULL) {
    1044     return EFI_NOT_FOUND;
     1143    return EFI_DEVICE_ERROR;
    10451144  }
    10461145
     
    10491148  // the value 0 of valid lifetime.
    10501149  //
    1051   Dhcp6ParseAddrOption (IaInnerOpt, IaInnerLen, &AddrNum, NULL);
     1150  Dhcp6ParseAddrOption (Instance->IaCb.Ia, IaInnerOpt, IaInnerLen, &AddrNum, NULL);
    10521151
    10531152  if (AddrNum == 0) {
     
    10711170  Ia->IaAddressCount = AddrNum;
    10721171  CopyMem (&Ia->Descriptor, &Instance->Config->IaDescriptor, sizeof (EFI_DHCP6_IA_DESCRIPTOR));
    1073   Dhcp6ParseAddrOption (IaInnerOpt, IaInnerLen, &AddrNum, Ia->IaAddress);
     1172  Dhcp6ParseAddrOption (Instance->IaCb.Ia, IaInnerOpt, IaInnerLen, &AddrNum, Ia->IaAddress);
    10741173
    10751174  //
     
    11901289  }
    11911290}
     1291
     1292/**
     1293  Calculate the Dhcp6 get mapping timeout by adding additinal delay to the IP6 DAD transmits count.
     1294
     1295  @param[in]   Ip6Cfg              The pointer to Ip6 config protocol.
     1296  @param[out]  TimeOut             The time out value in 100ns units.
     1297
     1298  @retval   EFI_INVALID_PARAMETER  Input parameters are invalid.
     1299  @retval   EFI_SUCCESS            Calculate the time out value successfully.
     1300**/
     1301EFI_STATUS
     1302Dhcp6GetMappingTimeOut (
     1303  IN  EFI_IP6_CONFIG_PROTOCOL       *Ip6Cfg,
     1304  OUT UINTN                         *TimeOut
     1305  )
     1306{
     1307  EFI_STATUS            Status;
     1308  UINTN                 DataSize;
     1309  EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS    DadXmits;
     1310
     1311  if (Ip6Cfg == NULL || TimeOut == NULL) {
     1312    return EFI_INVALID_PARAMETER;
     1313  }
     1314
     1315  DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);
     1316  Status = Ip6Cfg->GetData (
     1317                     Ip6Cfg,
     1318                     Ip6ConfigDataTypeDupAddrDetectTransmits,
     1319                     &DataSize,
     1320                     &DadXmits
     1321                     );
     1322  if (EFI_ERROR (Status)) {
     1323    return Status;
     1324  }
     1325 
     1326  *TimeOut = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + DHCP6_DAD_ADDITIONAL_DELAY;
     1327 
     1328  return EFI_SUCCESS;
     1329}
  • trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.h

    r48674 r58459  
    22  Dhcp6 support functions declaration.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    1818
    1919
    20 #define  DHCP6_10_BIT_MASK     0x3ff
     20#define  DHCP6_10_BIT_MASK             0x3ff
     21#define  DHCP6_DAD_ADDITIONAL_DELAY    30000000 // 3 seconds
    2122
    2223/**
     
    192193  @param[in]      T1            The time of T1.
    193194  @param[in]      T2            The time of T2.
     195  @param[in]      MessageType   Message type of DHCP6 package.
    194196
    195197  @return         Buf           The position to append the next Ia option.
     
    201203  IN     EFI_DHCP6_IA           *Ia,
    202204  IN     UINT32                 T1,
    203   IN     UINT32                 T2
     205  IN     UINT32                 T2,
     206  IN     UINT32                 MessageType
    204207  );
    205208
     
    274277  Parse the address option and update the address info.
    275278
     279  @param[in]      CurrentIa     The pointer to the Ia Address in control blcok.
    276280  @param[in]      IaInnerOpt    The pointer to the buffer.
    277281  @param[in]      IaInnerLen    The length to parse.
     
    282286VOID
    283287Dhcp6ParseAddrOption (
     288  IN     EFI_DHCP6_IA            *CurrentIa,
    284289  IN     UINT8                   *IaInnerOpt,
    285290  IN     UINT16                  IaInnerLen,
     
    300305  @retval     EFI_SUCCESS           Create an IA control block successfully.
    301306  @retval     EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
     307  @retval     EFI_DEVICE_ERROR      An unexpected error.
    302308
    303309**/
     
    338344  );
    339345
     346/**
     347  Calculate the Dhcp6 get mapping timeout by adding additinal delay to the IP6 DAD transmits count.
     348
     349  @param[in]   Ip6Cfg              The pointer to Ip6 config protocol.
     350  @param[out]  TimeOut             The time out value in 100ns units.
     351
     352  @retval   EFI_INVALID_PARAMETER  Input parameters are invalid.
     353  @retval   EFI_SUCCESS            Calculate the time out value successfully.
     354**/
     355EFI_STATUS
     356Dhcp6GetMappingTimeOut (
     357  IN  EFI_IP6_CONFIG_PROTOCOL       *Ip6Cfg,
     358  OUT UINTN                         *TimeOut
     359  );
    340360#endif
Note: See TracChangeset for help on using the changeset viewer.

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