public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH EDK2 v1 0/1] NetworkPkg/Dhcp6Dxe:Generate real time stamp
@ 2022-09-28  6:12 wenyi,xie
  2022-09-28  6:12 ` [PATCH EDK2 v1 1/1] " wenyi,xie
  0 siblings, 1 reply; 2+ messages in thread
From: wenyi,xie @ 2022-09-28  6:12 UTC (permalink / raw)
  To: devel, maciej.rabeda, jiaxin.wu, siyuan.fu; +Cc: songdongkuang, xiewenyi2

Main Changes :
1.Adding a new function to calculate time stamp.

Wenyi Xie (1):
  NetworkPkg/Dhcp6Dxe:Generate real time stamp

 NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c | 71 +++++++++++++++++---
 1 file changed, 63 insertions(+), 8 deletions(-)

-- 
2.20.1.windows.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH EDK2 v1 1/1] NetworkPkg/Dhcp6Dxe:Generate real time stamp
  2022-09-28  6:12 [PATCH EDK2 v1 0/1] NetworkPkg/Dhcp6Dxe:Generate real time stamp wenyi,xie
@ 2022-09-28  6:12 ` wenyi,xie
  0 siblings, 0 replies; 2+ messages in thread
From: wenyi,xie @ 2022-09-28  6:12 UTC (permalink / raw)
  To: devel, maciej.rabeda, jiaxin.wu, siyuan.fu; +Cc: songdongkuang, xiewenyi2

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.rabeda@linux.intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Wenyi Xie <xiewenyi2@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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-28  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  6:12 [PATCH EDK2 v1 0/1] NetworkPkg/Dhcp6Dxe:Generate real time stamp wenyi,xie
2022-09-28  6:12 ` [PATCH EDK2 v1 1/1] " wenyi,xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox