From: "wenyi,xie" <xiewenyi2@huawei.com>
To: <devel@edk2.groups.io>, <maciej.rabeda@linux.intel.com>,
<jiaxin.wu@intel.com>, <siyuan.fu@intel.com>
Cc: <songdongkuang@huawei.com>, <xiewenyi2@huawei.com>
Subject: [PATCH EDK2 v1 1/1] NetworkPkg/Dhcp6Dxe:Generate real time stamp
Date: Wed, 28 Sep 2022 14:12:20 +0800 [thread overview]
Message-ID: <20220928061220.3124990-2-xiewenyi2@huawei.com> (raw)
In-Reply-To: <20220928061220.3124990-1-xiewenyi2@huawei.com>
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
prev parent reply other threads:[~2022-09-28 6:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220928061220.3124990-2-xiewenyi2@huawei.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox