From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (NAM02-BL2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.6321.1609930593240877652 for ; Wed, 06 Jan 2021 02:56:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=mYpTKI/2; spf=fail (domain: os.amperecomputing.com, ip: , mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bqw59YdFnezgSbybZnfaFwwE1jmGHpUrbpssg5Ip9HSulwK2Oh9gJ3cyTnBcbk4kEg93wn78cqSS46T13vjr+mWinSw6QJfsu/88s6jbae4INwOtiLDzdxkMsjt0Bk4R5nogsMjjtQN2II5waxR945onCc0sJJdOIx0f1idzwtmLDvEJtMLjTXdl2hwBHpXfihBzLL1eaQNln884SUnsfq/iawiSyPLc+s6Fd25GlEnPC9e5huJbKlctYb+O9c/XpfqSc9mZpotLIaTsZqsNFRgF9YHsqy7keLFT5sYk1UzzsISUifvhYoYWWd2wkk37uTv+kGvhuA0JhtqSGRrdbQ== 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=pn0c2H/7K5xtrc3vx1LKN8Cltrw0xDP+LVSMYKxUgDo=; b=TqaxT+XS7ytxmkOOZipv7kAopq3NIjO5UAWrBM6dwhnx6LNy1Ay5blwN3uguBA9Ijj7EYSilUkLPqgjBAGAf45TU0SsZZZk5C1Nlk7V1AuVDts0phyMKI7zCGxJpCSw2nwWO4JRwWQ7mSrYUl62ohJYuWz4w4UJA7h4kvMk9ihcLqXvphKurspB866iOXzf2YQNXe48dk+wDdGq65YyZ57FGhdlkgbQREeD3cfAvU19AUOiYxIYfh3e9jWih7qvgilXKFpIaBh0c++Zh6er5mxnzGzThipwoqz23xZ13x1K9P0uVA2W2QyL3A1sv+0lOuHJT3S4JoWv3sgcSaVDOYw== 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=pn0c2H/7K5xtrc3vx1LKN8Cltrw0xDP+LVSMYKxUgDo=; b=mYpTKI/2jREWCM3tRrqoeOayXp++XiJ+a+d9KSD84Hjaeb2M817/I+6fY2gEVFeN+72aDWl7qFHKbEUrfnra3QzVU1fL73dOQcmiHNFaIXTsoYJgXKckdAT2VdBGJuCk2oFTSG8gpaKZ1XDuJoJO39s6K46vPMWkSEgn9mgfBjo= 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 DM6PR01MB5051.prod.exchangelabs.com (2603:10b6:5:63::32) 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 10:56:32 +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 10:56:32 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham , Leif Lindholm , Ard Biesheuvel Subject: [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Date: Wed, 6 Jan 2021 17:55:57 +0700 Message-Id: <20210106105558.9582-2-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106105558.9582-1-nhi@os.amperecomputing.com> References: <20210106105558.9582-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK2PR06CA0008.apcprd06.prod.outlook.com (2603:1096:202:2e::20) 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 HK2PR06CA0008.apcprd06.prod.outlook.com (2603:1096:202:2e::20) 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 10:56:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47aae53b-099e-4139-6087-08d8b231ba34 X-MS-TrafficTypeDiagnostic: DM6PR01MB5051: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2D9/3fG2Pf4joDOiJMOlykuVWXn/PFfI5T1EH3gsee8qlafm1K1c1kN4BDX/Fq3Miee0m2pD2uxIrRCPZGkwbtD4jz+miLIEuwWWzPehp3B05q8zNit71P7qI2OoCO2oHpY5k4l/M3VbdyiuqEtQBoY8NrA+TVE2FJap+UwVULtSK1QJRaflvTOAJkQs8XOLNHDLmmyhAr9BV4vu4/N07yFi32VgzApvQRd/rIUWy1BSSntRXjccZlsxBUN4oa3rm+5tCaCgvYJF3biO7csPW3yveOpuwQCWNHvQcfB3Z7M8jqj5gwRf2oivlbsHPSQm8uXEwZ9pSVqlA/pk2DS6FpckB13AJrphjczrkLkkUDdLpzf3NYSCdf2PrFXFSjvLFUrnFt6e2Nh+VQ6SHclTtiuTS5rw9MRny4c8k9AUHBy048EMASDMRp7yZ8ZAZRNdCgzMOeD80NdYM9ZGNtjgmw== 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)(346002)(376002)(39850400004)(396003)(136003)(66556008)(956004)(2616005)(4326008)(54906003)(316002)(5660300002)(6506007)(26005)(52116002)(66946007)(69590400011)(66476007)(186003)(2906002)(16526019)(8936002)(86362001)(8676002)(6666004)(6486002)(6916009)(83380400001)(1076003)(478600001)(6512007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ViRXSG8J1ZCQ1Uf2NijMmgzS/nXMto7JtY53s1oG3iI5scyCnKjpn1rvU+UH?= =?us-ascii?Q?BMDpUe/HLC0uyFFeFp/yE7YJGKfb2NOP6Y1JgzloRJOM4YkFn/o2YNNP64uh?= =?us-ascii?Q?fD60iXmDZbZgP7maZD1FjVBb+0zaE/tETryX7OALtfUFoWD/WPgXXs43wRVP?= =?us-ascii?Q?NBuLuydw30n2PNoY6A6ptXgry+D8yj53cheqLSII2CVUvybKFcY7u7XZ3oLj?= =?us-ascii?Q?RNWzqqiS/r/zuhNvhra0/tTqbuEF4YxTlec3qc60rdTnxuM2aa4sz+Sy299T?= =?us-ascii?Q?SDDtZw6MgaP0Pd8Q+axP1/xfvEKiJH2Bgcn+EwT+Guh5b1dIcGrkx0B9KapO?= =?us-ascii?Q?08RvalCTi0f5DMCb9PSEElDfc6Ho5y5WzNorgqogWPuwr5hc5PP+iAkKY3q+?= =?us-ascii?Q?geekdnBybkik3VaHX5cWWL0qzdZ21mYTCITC7xJ4r1TqkQhy/1d84HFtKbAf?= =?us-ascii?Q?n4DkrbdBCH+JR4PRu2jJks/0cWhNC2XPMKmK0ao/0vJ021pqesemsflarWmE?= =?us-ascii?Q?YxZX+9ds14E6RjCFb7k5yO5B9ugOckP7Ss4hGAQgnuyIVHnmEAtzeLvoTsd4?= =?us-ascii?Q?GcgTgrF5YGScObojwKz6rs+KpbN0rYTrNhDR+1OwGLQ+CYbcDo4ZHkBFNE0g?= =?us-ascii?Q?Dhcgry5Je7eqCz0lkpM5l6iPf0FIo8MpmZsFo88C3cz8vmPx3GBeWA6+VNsV?= =?us-ascii?Q?PrnboFzoU+J6yEH3BCGOQ+4bTYuMAjKJL6a/yaEB+GbWEMdF+74Ew7KkBF7t?= =?us-ascii?Q?axfe4dt3gOVLW0ehuBG2HU01TLCK5L4NCbBO3yVe9XBGFMg3XRT2APXElKlG?= =?us-ascii?Q?3RVEdH6U2FETbSlGWXaRhyU9wqNgUGSslsXs/LtpUF0SWwGpo3wmKJmGm3Dw?= =?us-ascii?Q?LgXt512b4LaXIg2npBzokxqPaRgd+FFa1SPxiisvK7LsDOJLukgMN54EUD9J?= =?us-ascii?Q?L0XaZDtj1cTKFYoISyGJtb1+aeecdZrdc4gWb5NRKgY4hyMug8C7V4e8+02E?= =?us-ascii?Q?DEQc?= 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 10:56:31.8502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: 47aae53b-099e-4139-6087-08d8b231ba34 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /A7r6WClK40HuOk5tuDUutZSCFR1kV25rvcq4oURJweGjm3j9xAhSeGYh/vXCun9TqegDFboIllTmR6R68+Kw6dVJ5MWAXioCGJ707vXmyw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5051 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 | 13 ++++++ EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 47 ++++++++++++++------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h index 90853c3f4b93..8bebf5886db8 100644 --- a/EmbeddedPkg/Include/Library/TimeBaseLib.h +++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h @@ -2,6 +2,7 @@ * * Copyright (c) 2016, Hisilicon Limited. All rights reserved. * Copyright (c) 2016-2019, Linaro Limited. All rights reserved. +* Copyright (c) 2020, Ampere Computing LLC. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -64,6 +65,18 @@ IsDayValid ( IN EFI_TIME *Time ); +BOOLEAN +EFIAPI +IsValidTimeZone ( + IN INT16 TimeZone + ); + +BOOLEAN +EFIAPI +IsValidDaylight ( + IN INT8 Daylight + ); + BOOLEAN EFIAPI IsTimeValid ( diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c index 78fc7b6cd2e5..02d9901338b9 100644 --- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c +++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c @@ -2,6 +2,7 @@ * * Copyright (c) 2016, Hisilicon Limited. All rights reserved. * Copyright (c) 2016-2019, Linaro Limited. All rights reserved. +* Copyright (c) 2020, Ampere Computing LLC. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -173,23 +174,43 @@ IsDayValid ( BOOLEAN EFIAPI -IsTimeValid( +IsValidTimeZone ( + IN INT16 TimeZone + ) +{ + return TimeZone == EFI_UNSPECIFIED_TIMEZONE || + (TimeZone >= -1440 && TimeZone <= 1440); +} + +BOOLEAN +EFIAPI +IsValidDaylight ( + IN INT8 Daylight + ) +{ + return Daylight == 0 || + Daylight == EFI_TIME_ADJUST_DAYLIGHT || + Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT); +} + +BOOLEAN +EFIAPI +IsTimeValid ( IN EFI_TIME *Time ) { // Check the input parameters are within the range specified by UEFI - if ((Time->Year < 2000) || - (Time->Year > 2099) || - (Time->Month < 1 ) || - (Time->Month > 12 ) || - (!IsDayValid (Time) ) || - (Time->Hour > 23 ) || - (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))) - ) { + if ((Time->Year < 2000) || + (Time->Year > 2099) || + (Time->Month < 1 ) || + (Time->Month > 12 ) || + (!IsDayValid (Time) ) || + (Time->Hour > 23 ) || + (Time->Minute > 59 ) || + (Time->Second > 59 ) || + (Time->Nanosecond > 999999999) || + (!IsValidTimeZone(Time->TimeZone)) || + (!IsValidDaylight(Time->Daylight))) { return FALSE; } -- 2.17.1