From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.102]) by mx.groups.io with SMTP id smtpd.web08.10245.1609949375406160676 for ; Wed, 06 Jan 2021 08:09:35 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=l+BN+ZB4; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.102, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CiVHktyYenWH5yu2yeUcUOgFj8IrK9JWr4I2NNrLFlcvGOUXO0/ALSn9Uq0AEylneSwJ5SHTOLyDWU4dVuakwYmk43VJeer2n2DQUd8PUqERXhvzshX75+xZlNIpX8CJB01vDeQIwVX4xFW/RXAxV3zQCs+PTdKOeJvqSNjQ5x+wI7T3gKVghYim8ooKq4ZOl/MC2je8cNvFCLYrCiIosgqWm59evJqGPHNUStDVcGFkEbP9LqDieL9SkSygVhQsf/+kjx0sUWeMkRgkcao0iGisz0ts/PWMq7Cr8eQq9sJL5bKwzdyeDr0JMOv1GexCD+R2mEzGpQzt5R8WZLoP+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0y3kP55xt2Cs+xZG4IAgcXCkbDu2emI5ru1An71Vsqs=; b=T4UjS88zNfnmmCD54jsTTpDCqdVHE4ClpiJx3AKakp3g1Ky0JnMKBm3DPI5uhhs2KeSQLVntD0MGfYf4SvqWt2bZlPnHkJ+CDAPLwwvc5bQa2Ii8do2IEa0aDy/83s5bwPovzm9w1VbexLMsmmfrRHz5/MZLuTlC2ML5UkTcVN+vIotyfF6x6xT3UGJsFjZlCjQq7FEncQYjk01ezHIejijZIkMwc+jvAlQN6thBN2Pmq9S8VlyRjp5VIWiyHK9R+UGlPukOLgQq4Kq1CElJFR1PlLwxYjskBd5x0+qdePdbR66JiD9eFgIf/w/J+WuQXDE1JfUuy21vHXOZwObXeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0y3kP55xt2Cs+xZG4IAgcXCkbDu2emI5ru1An71Vsqs=; b=l+BN+ZB4vC1CofeRD7m96SArtucOA6C1717bGPg+Mgvi17hjOO3pBctEvtzuo4teVCFWXxu75FQZEfgQQRn2r+jKQZFtiI7zLj4PceJNiVOTMNPsEz3UUcDkqTygcYLepp0LpC7Q+s8Ew34GjZLJzpHRO+mYTtzxDnr8kzPcZUs= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR01MB2538.prod.exchangelabs.com (2603:10b6:3:3e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 16:09:34 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 16:09:32 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham , Leif Lindholm , Ard Biesheuvel Subject: [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Date: Wed, 6 Jan 2021 23:09:02 +0700 Message-Id: <20210106160903.27679-4-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106160903.27679-1-nhi@os.amperecomputing.com> References: <20210106160903.27679-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK2PR02CA0220.apcprd02.prod.outlook.com (2603:1096:201:20::32) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HK2PR02CA0220.apcprd02.prod.outlook.com (2603:1096:201:20::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 16:09:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8a84ab6-8f0f-43f1-6801-08d8b25d740b X-MS-TrafficTypeDiagnostic: DM5PR01MB2538: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3QWjxDTgDJVzXIcQq+pFR0/z3SmP0v27YrJnxJ5bt2rAx+lGQib6bjM6t6f8cslYe6lVoqWVq4DqMEeqi5pMrN5WKAj3QdxDguG2vKMpUEcdUuZnmqhx/tNZS3XBiMOC3TstD5k80HR1l7Y5u73TsiiHiakNXBemYHbxKcpgkVExyAxLCJsPn0rLc87+JPmopECTy4bv1DtxT/jRmL3R5F8/IlhnGaimUiuXIeaRE9s0jLghWfMFAPfDtUHD6AN8mnTmrQhGKFDJFXd+ybps38M8IdtxrvnPBmQFKbSgQCGwXQbRMl2t556qkOI2bZVDG+5sWhskLbnwFfX6WUhG0CVOuiE5t06bI5ATOTWXj66BTFtUQG9VkR+CejqPpsTsD2nBsk3GjcqV2SfCw1SFP/hfV5q0RR8mwprIfu7YFOKTA8o5SAvNa6WcDB2j5dw1cjfuKjLUj3Xd/DvXdSUDDA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(376002)(346002)(396003)(39850400004)(2616005)(6506007)(956004)(316002)(1076003)(6666004)(69590400011)(2906002)(8676002)(478600001)(6486002)(8936002)(54906003)(186003)(26005)(83380400001)(16526019)(6916009)(66556008)(6512007)(86362001)(4326008)(66476007)(52116002)(5660300002)(66946007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?+By5BjAS3rL4/Tj1mhta97VjpHt2jTxc1+JMH8XolQknEFBtxobDP7ai5dpK?= =?us-ascii?Q?+XOranagzyjKFeVtzOi7i8XUihUSbz2aonBsA0OrTQERAw7szOgIrmhcX766?= =?us-ascii?Q?rXJ2PxqEw5DAKeOl1o+c1LKCoKDh4WOZr5sPRHtJwK5zcZxCHN8Az6qyez/s?= =?us-ascii?Q?r5Rff3+zw19VqWirctlaUhkBmb6eTLGGQNqO0piRlOwWTXal7FtEm9PVnM4V?= =?us-ascii?Q?CrYt6mn/itgv4d9p8/ByxYEQBWTyf0apUK05K/fDTnFaPFUw73Mj1X1mwvl+?= =?us-ascii?Q?+irgMxhT8YBARTg1m+TkKbM5X4lgJVAponY029Mm2R6SkYeEptuCH0T5Dck0?= =?us-ascii?Q?MgT8IW9OqEJiZ7Y9g8+O5mBZrdANfluIytC0n/s5IdjHcPMl4gtDd5tZwcbW?= =?us-ascii?Q?p03L8WxZaFM2wrojb2R1W2TraBeJ8eArFkaWFsREm/8ZJVlSlI0FjObUwPto?= =?us-ascii?Q?jCUuP4gC9W3qmDLoPO6Ipcy/Osty03Vvcetcqbx/LuTt0Tr9IgrJGbb8XUBF?= =?us-ascii?Q?65TTR6QzoQyfjALeVzGRJSdIKIWpnPiBtjqKs/1HGaycXaMFPIQRwpuD45mh?= =?us-ascii?Q?jItbziLkuxGWNh8vA2T1Ycg6xMTDfgq8/4apfQoWq6EFz39O2AzpMq9R4Aw3?= =?us-ascii?Q?kxmypiaHzNftOv2YKiO1RWfYWfN0lXfFaSNd5WA2p4so3s5CHDtwOcs9YnCR?= =?us-ascii?Q?1cAEExIcS8MFH5k5/gKcY3U5TNKYtJhAUN/SrfeACMCuQUYOxPFPEOfMpoxg?= =?us-ascii?Q?7RqfazicyVFG4ctZp9ObR8yBtrZVuKJpHEsg0adfO7GSeE/zjB0iDnulbTog?= =?us-ascii?Q?vZaiD7Fq+VHlLkg8zyddg9dpeCfM68eP+PgN2RyqwJdF5cr9VrQAknfsHcx0?= =?us-ascii?Q?yRvpHZZwGrg9lq7AZafjOl592SW49+53jiXYQB6BMkN6RAWDS/vOXNbWgPNm?= =?us-ascii?Q?jkPj76Rjxwen6n2UcMMmctYcdqBw0LKBtHU05qsnrMJCT1/75t00akiAuKsg?= =?us-ascii?Q?C4Ry?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 16:09:32.0762 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: b8a84ab6-8f0f-43f1-6801-08d8b25d740b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZoLVYUlX3UQw4rE8RvZOGOTusNHch6Xqow8Lt9zSWcpg9zKykX988NqIjuB2JJH+1Q036Z+Vmw1f+hyLDd20DYoQrXCy9oF6NMdL169e9Dg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR01MB2538 Content-Type: text/plain This adds two functions IsValidTimeZone() and IsValidDaylight() to check the time zone and daylight value from EFI time. These functions are retrieved from the RealTimeClockRuntimeDxe module as they reduce duplicated code in RTC modules. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Nhi Pham --- EmbeddedPkg/Include/Library/TimeBaseLib.h | 36 ++++++++++++++ EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 49 +++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h index a9f3c6588b75..10700d1a649a 100644 --- a/EmbeddedPkg/Include/Library/TimeBaseLib.h +++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h @@ -83,6 +83,42 @@ IsDayValid ( IN EFI_TIME *Time ); +/** + Check if the time zone is valid. + Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE). + + @param TimeZone The time zone to be checked. + + @retval TRUE Valid. + @retval FALSE Invalid. + +**/ +BOOLEAN +EFIAPI +IsValidTimeZone ( + IN INT16 TimeZone + ); + +/** + Check if the daylight is valid. + Valid values are: + 0 : Time is not affected. + 1 : Time is affected, and has not been adjusted for daylight savings. + 3 : Time is affected, and has been adjusted for daylight savings. + All other values are invalid. + + @param Daylight The daylight to be checked. + + @retval TRUE Valid. + @retval FALSE Invalid. + +**/ +BOOLEAN +EFIAPI +IsValidDaylight ( + IN INT8 Daylight + ); + /** Check if the UEFI time is valid. diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c index 17466c1e6c67..210d0b2bf17d 100644 --- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c +++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c @@ -210,6 +210,51 @@ IsDayValid ( return TRUE; } +/** + Check if the time zone is valid. + Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE). + + @param TimeZone The time zone to be checked. + + @retval TRUE Valid. + @retval FALSE Invalid. + +**/ +BOOLEAN +EFIAPI +IsValidTimeZone ( + IN INT16 TimeZone + ) +{ + return TimeZone == EFI_UNSPECIFIED_TIMEZONE || + (TimeZone >= -1440 && TimeZone <= 1440); +} + +/** + Check if the daylight is valid. + Valid values are: + 0 : Time is not affected. + 1 : Time is affected, and has not been adjusted for daylight savings. + 3 : Time is affected, and has been adjusted for daylight savings. + All other values are invalid. + + @param Daylight The daylight to be checked. + + @retval TRUE Valid. + @retval FALSE Invalid. + +**/ +BOOLEAN +EFIAPI +IsValidDaylight ( + IN INT8 Daylight + ) +{ + return Daylight == 0 || + Daylight == EFI_TIME_ADJUST_DAYLIGHT || + Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT); +} + /** Check if the UEFI time is valid. @@ -235,8 +280,8 @@ IsTimeValid ( (Time->Minute > 59 ) || (Time->Second > 59 ) || (Time->Nanosecond > 999999999) || - (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) || - (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))) { + (!IsValidTimeZone(Time->TimeZone)) || + (!IsValidDaylight(Time->Daylight))) { return FALSE; } -- 2.17.1