The stamp used to be generated is assumed 30day/month. Now adding a new function which calculates time stamp with the correct days.
Cc: Maciej Rabeda <maciej.rab...@linux.intel.com> Cc: Jiaxin Wu <jiaxin...@intel.com> Cc: Siyuan Fu <siyuan...@intel.com> Signed-off-by: Wenyi Xie <xiewen...@huawei.com> --- NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c | 71 +++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c index e6368b5b1c6c..bff8b809090f 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c @@ -10,6 +10,62 @@ #include "Dhcp6Impl.h" +CONST UINT32 MonthDays[] = { + 0, + 31, + 31 + 28, + 31 + 28 + 31, + 31 + 28 + 31 + 30, + 31 + 28 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 +}; + +/** + Generate time stamp with current system time. + + @param[in] Time The pointer to the system time. + + @retval NULL . + @retval others . + +**/ +UINT32 +Dhcp6GenerateTimeStamp ( + IN EFI_TIME Time + ) +{ + UINT32 Stamp; + UINT32 Days; + + if (Time.Year < 2000) { + DEBUG ((DEBUG_ERROR, "[%a][%dL] Time before 2000!\n", __FUNCTION__, __LINE__)); + return (UINT32) ~(0); + } + + Days = 0; + Days += ((Time.Year - 2000) * 365) + ((Time.Year - 2000) / 4); + Days += MonthDays[(Time.Month - 1)]; + if (((Time.Year - 2000) % 4 == 0) && (Time.Month >= 3)) { + Days++; + } + + Stamp = (UINT32)Days + Time.Day; + Stamp = Stamp * 24 + Time.Hour; + Stamp = Stamp * 60 + Time.Minute; + if (Time.TimeZone != 0x7ff) { + Stamp -= Time.TimeZone; + } + + Stamp = Stamp * 60 + Time.Second; + + return Stamp; +} + /** Generate client Duid in the format of Duid-llt. @@ -108,15 +164,14 @@ Dhcp6GenerateClientId ( // // - // Generate a time stamp of the seconds from 2000/1/1, assume 30day/month. + // Generate a time stamp of the seconds from 2000/1/1. // - gRT->GetTime (&Time, NULL); - Stamp = (UINT32) - ( - ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * - 60 + - Time.Second - ); + Status = gRT->GetTime (&Time, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[%a][%dL] Get time failed. \n", __FUNCTION__, __LINE__)); + } + + Stamp = Dhcp6GenerateTimeStamp (Time); // // sizeof (option-len + Duid-type + hardware-type + time) = 10 bytes -- 2.20.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#94456): https://edk2.groups.io/g/devel/message/94456 Mute This Topic: https://groups.io/mt/93967207/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-