17#define IS_INVALID_PACKET_CURSOR(PacketCursor, Packet) \
18 (((*PacketCursor) < (Packet)->Dhcp6.Option) || \
19 ((*PacketCursor) >= (Packet)->Dhcp6.Option + ((Packet)->Size - sizeof(EFI_DHCP6_HEADER))) \
47 GetVariable2 (L
"ClientId", &gEfiDhcp6ServiceBindingProtocolGuid, (VOID **)&Duid,
NULL);
95 Duid->
Length = (UINT16)(18);
126 ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) *
142 Duid->
Length = (UINT16)(Mode->HwAddressSize + 8);
151 CopyMem (Duid->
Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);
154 Status =
gRT->SetVariable (
156 &gEfiDhcp6ServiceBindingProtocolGuid,
161 if (EFI_ERROR (Status)) {
186 UINTN OptionListSize;
194 if (SorCfg->SolicitRetransmission !=
NULL) {
197 if (DstCfg->SolicitRetransmission ==
NULL) {
201 return EFI_OUT_OF_RESOURCES;
205 DstCfg->SolicitRetransmission,
206 SorCfg->SolicitRetransmission,
211 if ((SorCfg->OptionList !=
NULL) && (SorCfg->OptionCount != 0)) {
215 if (DstCfg->OptionList ==
NULL) {
219 return EFI_OUT_OF_RESOURCES;
222 for (Index = 0; Index < SorCfg->OptionCount; Index++) {
223 OptionSize = NTOHS (SorCfg->OptionList[Index]->OpLen) + 4;
226 if (DstCfg->OptionList[Index] ==
NULL) {
230 return EFI_OUT_OF_RESOURCES;
234 DstCfg->OptionList[Index],
235 SorCfg->OptionList[Index],
257 ASSERT (CfgData !=
NULL);
262 if (CfgData->OptionList !=
NULL) {
263 for (Index = 0; Index < CfgData->OptionCount; Index++) {
264 if (CfgData->OptionList[Index] !=
NULL) {
265 FreePool (CfgData->OptionList[Index]);
272 if (CfgData->SolicitRetransmission !=
NULL) {
273 FreePool (CfgData->SolicitRetransmission);
290 ASSERT (ModeData !=
NULL);
295 if (ModeData->ClientId !=
NULL) {
299 if (ModeData->Ia !=
NULL) {
300 if (ModeData->Ia->ReplyPacket !=
NULL) {
301 FreePool (ModeData->Ia->ReplyPacket);
323 IN BOOLEAN IsFirstRt,
324 IN BOOLEAN NeedSigned
337 Seed = ((Time.Nanosecond >> 10) & DHCP6_10_BIT_MASK);
338 Signed = (BOOLEAN)((((Time.Nanosecond >> 9) & 0x01) != 0) ?
TRUE :
FALSE);
339 Signed = (BOOLEAN)(NeedSigned ? Signed :
FALSE);
350 if (IsFirstRt && Signed) {
351 Expire = Base - (UINT32)(Base * Seed / DHCP6_10_BIT_MASK / 10);
352 }
else if (IsFirstRt && !Signed) {
353 Expire = Base + (UINT32)(Base * Seed / DHCP6_10_BIT_MASK / 10);
354 }
else if (!IsFirstRt && Signed) {
355 Expire = 2 * Base - (UINT32)(Base * Seed / DHCP6_10_BIT_MASK / 10);
357 Expire = 2 * Base + (UINT32)(Base * Seed / DHCP6_10_BIT_MASK / 10);
360 Expire = (Expire != 0) ? Expire : 1;
380 ASSERT (IaCb->Ia->IaAddressCount > 0);
382 MinLt = (UINT32)(-1);
389 for (Index = 0; Index < IaCb->Ia->IaAddressCount; Index++) {
390 MinLt =
MIN (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);
391 MaxLt =
MAX (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);
398 IaCb->T1 = (IaCb->T1 != 0) ? IaCb->T1 : (UINT32)(MinLt * 5 / 10);
399 IaCb->T2 = (IaCb->T2 != 0) ? IaCb->T2 : (UINT32)(MinLt * 8 / 10);
400 IaCb->AllExpireTime = MaxLt;
418 IN UINT32 AddressCount,
430 for (Index1 = 0; Index1 < AddressCount; Index1++) {
433 for (Index2 = 0; Index2 < Ia->IaAddressCount; Index2++) {
436 &Ia->IaAddress[Index2],
446 return EFI_NOT_FOUND;
467 IN UINT32 AddressCount,
477 if (AddressCount == 0) {
484 ASSERT (AddressCount != 0);
489 if (IaCopy ==
NULL) {
493 if (AddressCount == Ia->IaAddressCount) {
501 CopyMem (IaCopy, Ia, IaCopySize);
502 Ia->IaAddressCount = 0;
511 for (Index1 = 0; Index1 < AddressCount; Index1++) {
514 for (Index2 = 0; Index2 < Ia->IaAddressCount; Index2++) {
517 &Ia->IaAddress[Index2],
526 &Ia->IaAddress[Index2],
532 if (Index2 + 1 < Ia->IaAddressCount) {
534 &Ia->IaAddress[Index2],
535 &Ia->IaAddress[Index2 + 1],
545 ASSERT (Found ==
TRUE);
548 Ia->IaAddressCount -= AddressCount;
608 IN OUT UINT8 **PacketCursor,
632 if (Packet ==
NULL) {
633 return EFI_INVALID_PARAMETER;
636 if ((PacketCursor ==
NULL) || (*PacketCursor ==
NULL)) {
637 return EFI_INVALID_PARAMETER;
641 return EFI_INVALID_PARAMETER;
645 return EFI_INVALID_PARAMETER;
651 if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {
652 return EFI_INVALID_PARAMETER;
658 BytesNeeded = DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + NTOHS (OptLen);
663 Length = Packet->Size - Packet->Length;
664 if (Length < BytesNeeded) {
665 return EFI_BUFFER_TOO_SMALL;
669 *PacketCursor += DHCP6_SIZE_OF_OPT_CODE;
671 *PacketCursor += DHCP6_SIZE_OF_OPT_LEN;
672 CopyMem (*PacketCursor, Data, NTOHS (OptLen));
673 *PacketCursor += NTOHS (OptLen);
676 Packet->Length += BytesNeeded;
699 IN OUT UINT8 **PacketCursor,
701 IN UINT32 MessageType
731 if (Packet ==
NULL) {
732 return EFI_INVALID_PARAMETER;
735 if ((PacketCursor ==
NULL) || (*PacketCursor ==
NULL)) {
736 return EFI_INVALID_PARAMETER;
739 if (IaAddr ==
NULL) {
740 return EFI_INVALID_PARAMETER;
746 if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {
747 return EFI_INVALID_PARAMETER;
750 BytesNeeded = DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN;
755 BytesNeeded +=
sizeof (IaAddr->PreferredLifetime);
759 BytesNeeded +=
sizeof (IaAddr->ValidLifetime);
764 Length = Packet->Size - Packet->Length;
765 if (Length < BytesNeeded) {
766 return EFI_BUFFER_TOO_SMALL;
773 *PacketCursor += DHCP6_SIZE_OF_OPT_CODE;
776 *PacketCursor += DHCP6_SIZE_OF_OPT_LEN;
786 if (MessageType != Dhcp6MsgConfirm) {
787 WriteUnaligned32 ((UINT32 *)*PacketCursor, HTONL (IaAddr->PreferredLifetime));
790 *PacketCursor +=
sizeof (IaAddr->PreferredLifetime);
792 if (MessageType != Dhcp6MsgConfirm) {
796 *PacketCursor +=
sizeof (IaAddr->ValidLifetime);
801 Packet->Length += BytesNeeded;
826 IN OUT UINT8 **PacketCursor,
830 IN UINT32 MessageType
862 if (Packet ==
NULL) {
863 return EFI_INVALID_PARAMETER;
866 if ((PacketCursor ==
NULL) || (*PacketCursor ==
NULL)) {
867 return EFI_INVALID_PARAMETER;
871 return EFI_INVALID_PARAMETER;
877 if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {
878 return EFI_INVALID_PARAMETER;
881 BytesNeeded = DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN;
882 BytesNeeded +=
sizeof (Ia->Descriptor.IaId);
887 if (Ia->Descriptor.Type == Dhcp6OptIana) {
888 BytesNeeded +=
sizeof (T1) +
sizeof (T2);
894 Length = (UINT16)(Packet->Size - Packet->Length);
895 if (Length < BytesNeeded) {
896 return EFI_BUFFER_TOO_SMALL;
903 *PacketCursor += DHCP6_SIZE_OF_OPT_CODE;
908 Len = (UINT16 *)*PacketCursor;
909 *PacketCursor += DHCP6_SIZE_OF_OPT_LEN;
915 *PacketCursor +=
sizeof (Ia->Descriptor.IaId);
920 if (Ia->Descriptor.Type == Dhcp6OptIana) {
921 WriteUnaligned32 ((UINT32 *)*PacketCursor, HTONL ((T1 != 0) ? T1 : 0xffffffff));
922 *PacketCursor +=
sizeof (T1);
923 WriteUnaligned32 ((UINT32 *)*PacketCursor, HTONL ((T2 != 0) ? T2 : 0xffffffff));
924 *PacketCursor +=
sizeof (T2);
930 Packet->Length += BytesNeeded;
935 for (Index = 0; Index < Ia->IaAddressCount; Index++) {
938 if (EFI_ERROR (Status)) {
946 *Len = HTONS ((UINT16)(*PacketCursor - (UINT8 *)Len - 2));
970 IN OUT UINT8 **PacketCursor,
992 if (Packet ==
NULL) {
993 return EFI_INVALID_PARAMETER;
996 if ((PacketCursor ==
NULL) || (*PacketCursor ==
NULL)) {
997 return EFI_INVALID_PARAMETER;
1000 if (Instance ==
NULL) {
1001 return EFI_INVALID_PARAMETER;
1004 if (Elapsed ==
NULL) {
1005 return EFI_INVALID_PARAMETER;
1011 if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {
1012 return EFI_INVALID_PARAMETER;
1015 BytesNeeded = DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN;
1019 BytesNeeded +=
sizeof (UINT16);
1023 Length = Packet->Size - Packet->Length;
1024 if (Length < BytesNeeded) {
1025 return EFI_BUFFER_TOO_SMALL;
1032 *PacketCursor += DHCP6_SIZE_OF_OPT_CODE;
1038 *PacketCursor += DHCP6_SIZE_OF_OPT_LEN;
1045 *Elapsed = (UINT16 *)*PacketCursor;
1046 *PacketCursor +=
sizeof (UINT16);
1048 Packet->Length += BytesNeeded;
1068 UINT64 CurrentStamp;
1069 UINT64 ElapsedTimeValue;
1076 ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second,
1089 if (Instance->StartTime == 0) {
1090 ElapsedTimeValue = 0;
1091 Instance->StartTime = CurrentStamp;
1093 ElapsedTimeValue = CurrentStamp - Instance->StartTime;
1098 if (ElapsedTimeValue > 0xffff) {
1099 ElapsedTimeValue = 0xffff;
1135 while (Cursor < Buf + SeekLen) {
1137 if (OpCode == HTONS (OptType)) {
1143 Cursor += (DataLen + 4);
1179 while (Cursor < Buf + SeekLen) {
1182 if ((OpCode == HTONS (IaDesc->Type)) && (IaId == HTONL (IaDesc->IaId))) {
1188 Cursor += (DataLen + 4);
1213 ASSERT (IaAddr !=
NULL && CurrentIa !=
NULL);
1215 for (Index = 0; Index < CurrentIa->IaAddressCount; Index++) {
1216 if (EFI_IP6_EQUAL (&IaAddr->IpAddress, &CurrentIa->IaAddress[Index].IpAddress)) {
1237 IN UINT8 *IaInnerOpt,
1238 IN UINT16 IaInnerLen,
1239 OUT UINT32 *AddrNum,
1280 Cursor = IaInnerOpt;
1283 while (Cursor < IaInnerOpt + IaInnerLen) {
1292 if ((OpCode == HTONS (Dhcp6OptIaAddr)) && (ValidLt >= PreferredLt) &&
1295 if (AddrBuf !=
NULL) {
1297 AddrBuf->PreferredLifetime = PreferredLt;
1298 AddrBuf->ValidLifetime = ValidLt;
1306 Cursor += (DataLen + 4);
1328 IN UINT8 *IaInnerOpt,
1329 IN UINT16 IaInnerLen,
1338 if (Instance->IaCb.Ia ==
NULL) {
1339 return EFI_DEVICE_ERROR;
1349 return EFI_NOT_FOUND;
1359 return EFI_OUT_OF_RESOURCES;
1365 Ia->
State = Instance->IaCb.Ia->State;
1373 if (Instance->IaCb.Ia->ReplyPacket !=
NULL) {
1374 FreePool (Instance->IaCb.Ia->ReplyPacket);
1384 Instance->IaCb.Ia = Ia;
1390 Instance->IaCb.T1 = T1;
1391 Instance->IaCb.T2 = T2;
1414 Ia = Instance->IaCb.Ia;
1416 if ((Instance->CacheIa ==
NULL) && (Ia !=
NULL)) {
1423 if (Instance->CacheIa ==
NULL) {
1424 return EFI_OUT_OF_RESOURCES;
1427 CopyMem (Instance->CacheIa, Ia, IaSize);
1452 Ia = Instance->IaCb.Ia;
1453 CacheIa = Instance->CacheIa;
1461 if (NewIa ==
NULL) {
1484 Instance->CacheIa =
NULL;
1485 Instance->IaCb.Ia = NewIa;
1508 if ((Ip6Cfg ==
NULL) || (TimeOut ==
NULL)) {
1509 return EFI_INVALID_PARAMETER;
1513 Status = Ip6Cfg->GetData (
1519 if (EFI_ERROR (Status)) {
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS Dhcp6CopyConfigData(IN EFI_DHCP6_CONFIG_DATA *DstCfg, IN EFI_DHCP6_CONFIG_DATA *SorCfg)
EFI_STATUS Dhcp6AppendIaOption(IN OUT EFI_DHCP6_PACKET *Packet, IN OUT UINT8 **PacketCursor, IN EFI_DHCP6_IA *Ia, IN UINT32 T1, IN UINT32 T2, IN UINT32 MessageType)
BOOLEAN Dhcp6AddrIsInCurrentIa(IN EFI_DHCP6_IA_ADDRESS *IaAddr, IN EFI_DHCP6_IA *CurrentIa)
EFI_STATUS Dhcp6CacheIa(IN DHCP6_INSTANCE *Instance)
EFI_STATUS Dhcp6GenerateIaCb(IN DHCP6_INSTANCE *Instance, IN UINT8 *IaInnerOpt, IN UINT16 IaInnerLen, IN UINT32 T1, IN UINT32 T2)
VOID Dhcp6ParseAddrOption(IN EFI_DHCP6_IA *CurrentIa, IN UINT8 *IaInnerOpt, IN UINT16 IaInnerLen, OUT UINT32 *AddrNum, IN OUT EFI_DHCP6_IA_ADDRESS *AddrBuf)
EFI_DHCP6_IA * Dhcp6DepriveAddress(IN EFI_DHCP6_IA *Ia, IN UINT32 AddressCount, IN EFI_IPv6_ADDRESS *Addresses)
VOID Dhcp6AppendCacheIa(IN DHCP6_INSTANCE *Instance)
VOID EFIAPI Dhcp6OnTransmitted(IN NET_BUF *Wrap, IN UDP_END_POINT *EndPoint, IN EFI_STATUS IoStatus, IN VOID *Context)
EFI_DHCP6_DUID * Dhcp6GenerateClientId(IN EFI_SIMPLE_NETWORK_MODE *Mode)
EFI_STATUS Dhcp6AppendOption(IN OUT EFI_DHCP6_PACKET *Packet, IN OUT UINT8 **PacketCursor, IN UINT16 OptType, IN UINT16 OptLen, IN UINT8 *Data)
VOID Dhcp6CalculateLeaseTime(IN DHCP6_IA_CB *IaCb)
EFI_STATUS Dhcp6AppendIaAddrOption(IN OUT EFI_DHCP6_PACKET *Packet, IN OUT UINT8 **PacketCursor, IN EFI_DHCP6_IA_ADDRESS *IaAddr, IN UINT32 MessageType)
EFI_STATUS Dhcp6AppendETOption(IN OUT EFI_DHCP6_PACKET *Packet, IN OUT UINT8 **PacketCursor, IN DHCP6_INSTANCE *Instance, OUT UINT16 **Elapsed)
UINT8 * Dhcp6SeekOption(IN UINT8 *Buf, IN UINT32 SeekLen, IN UINT16 OptType)
VOID EFIAPI Dhcp6DummyExtFree(IN VOID *Arg)
VOID Dhcp6CleanupModeData(IN OUT EFI_DHCP6_MODE_DATA *ModeData)
EFI_STATUS Dhcp6CheckAddress(IN EFI_DHCP6_IA *Ia, IN UINT32 AddressCount, IN EFI_IPv6_ADDRESS *Addresses)
VOID SetElapsedTime(IN UINT16 *Elapsed, IN DHCP6_INSTANCE *Instance)
UINT32 Dhcp6CalculateExpireTime(IN UINT32 Base, IN BOOLEAN IsFirstRt, IN BOOLEAN NeedSigned)
UINT8 * Dhcp6SeekIaOption(IN UINT8 *Buf, IN UINT32 SeekLen, IN EFI_DHCP6_IA_DESCRIPTOR *IaDesc)
EFI_STATUS Dhcp6GetMappingTimeOut(IN EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg, OUT UINTN *TimeOut)
VOID Dhcp6CleanupConfigData(IN OUT EFI_DHCP6_CONFIG_DATA *CfgData)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
@ Ip6ConfigDataTypeDupAddrDetectTransmits
EFI_RUNTIME_SERVICES * gRT
#define OFFSET_OF(TYPE, Field)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
EFI_STATUS EFIAPI NetLibGetSystemGuid(OUT EFI_GUID *SystemGuid)
#define PcdGet8(TokenName)
IPv6_ADDRESS EFI_IPv6_ADDRESS
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
#define EFI_VARIABLE_NON_VOLATILE
EFI_DHCP6_IA_DESCRIPTOR Descriptor
EFI_DHCP6_IA_ADDRESS IaAddress[1]
UINT32 DupAddrDetectTransmits
The number of consecutive Neighbor Solicitation messages sent.