17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci#ifndef __TEE_TIME_API_H 177777dab0Sopenharmony_ci#define __TEE_TIME_API_H 187777dab0Sopenharmony_ci 197777dab0Sopenharmony_ci/** 207777dab0Sopenharmony_ci * @addtogroup TeeTrusted 217777dab0Sopenharmony_ci * @{ 227777dab0Sopenharmony_ci * 237777dab0Sopenharmony_ci * @brief TEE(Trusted Excution Environment) API. 247777dab0Sopenharmony_ci * Provides security capability APIs such as trusted storage, encryption and decryption, 257777dab0Sopenharmony_ci * and trusted time for trusted application development. 267777dab0Sopenharmony_ci * 277777dab0Sopenharmony_ci * @since 12 287777dab0Sopenharmony_ci */ 297777dab0Sopenharmony_ci 307777dab0Sopenharmony_ci/** 317777dab0Sopenharmony_ci * @file tee_time_api.h 327777dab0Sopenharmony_ci * 337777dab0Sopenharmony_ci * @brief Provides APIs for managing the Trusted Execution Environment (TEE) time. 347777dab0Sopenharmony_ci * 357777dab0Sopenharmony_ci * You can use these APIs to implement time-related features in a TEE. 367777dab0Sopenharmony_ci * 377777dab0Sopenharmony_ci * @library NA 387777dab0Sopenharmony_ci * @kit TEEKit 397777dab0Sopenharmony_ci * @syscap SystemCapability.Tee.TeeClient 407777dab0Sopenharmony_ci * @since 12 417777dab0Sopenharmony_ci * @version 1.0 427777dab0Sopenharmony_ci */ 437777dab0Sopenharmony_ci 447777dab0Sopenharmony_ci#include "tee_defines.h" 457777dab0Sopenharmony_ci 467777dab0Sopenharmony_ci#ifdef __cplusplus 477777dab0Sopenharmony_ciextern "C" { 487777dab0Sopenharmony_ci#endif 497777dab0Sopenharmony_ci 507777dab0Sopenharmony_ci/** 517777dab0Sopenharmony_ci * @brief Obtains the current TEE system time. 527777dab0Sopenharmony_ci * 537777dab0Sopenharmony_ci * @param time Indicates the pointer to the current system time obtained. 547777dab0Sopenharmony_ci * 557777dab0Sopenharmony_ci * @since 12 567777dab0Sopenharmony_ci * @version 1.0 577777dab0Sopenharmony_ci */ 587777dab0Sopenharmony_civoid TEE_GetSystemTime(TEE_Time *time); 597777dab0Sopenharmony_ci 607777dab0Sopenharmony_ci/** 617777dab0Sopenharmony_ci * @brief Waits for the specified period of time, in milliseconds. 627777dab0Sopenharmony_ci * 637777dab0Sopenharmony_ci * @param timeout Indicates the period of time to wait, in milliseconds. 647777dab0Sopenharmony_ci * 657777dab0Sopenharmony_ci * @return Returns <b>TEE_SUCCESS</b> if the operation is successful. 667777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_CANCEL</b> if the wait is canceled. 677777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_OUT_OF_MEMORY</b> if the memory is not sufficient to complete the operation. 687777dab0Sopenharmony_ci * 697777dab0Sopenharmony_ci * @since 12 707777dab0Sopenharmony_ci * @version 1.0 717777dab0Sopenharmony_ci */ 727777dab0Sopenharmony_ciTEE_Result TEE_Wait(uint32_t timeout); 737777dab0Sopenharmony_ci 747777dab0Sopenharmony_ci/** 757777dab0Sopenharmony_ci * @brief Obtains the persistent time of this trusted application (TA). 767777dab0Sopenharmony_ci * 777777dab0Sopenharmony_ci * @param time Indicates the pointer to the persistent time of the TA. 787777dab0Sopenharmony_ci * 797777dab0Sopenharmony_ci * @return Returns <b>TEE_SUCCESS</b> if the operation is successful. 807777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_TIME_NOT_SET</b> if the persistent time has not been set. 817777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_TIME_NEEDS_RESET</b> if the persistent time is corrupted and 827777dab0Sopenharmony_ci * the application is not longer trusted. 837777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_OVERFLOW</b> if the number of seconds in the TA persistent time 847777dab0Sopenharmony_ci * exceeds the range of <b>uint32_t</b>. 857777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_OUT_OF_MEMORY</b> if the memory is not sufficient to complete the operation. 867777dab0Sopenharmony_ci * 877777dab0Sopenharmony_ci * @since 12 887777dab0Sopenharmony_ci * @version 1.0 897777dab0Sopenharmony_ci */ 907777dab0Sopenharmony_ciTEE_Result TEE_GetTAPersistentTime(TEE_Time *time); 917777dab0Sopenharmony_ci 927777dab0Sopenharmony_ci/** 937777dab0Sopenharmony_ci * @brief Sets the persistent time for this TA. 947777dab0Sopenharmony_ci * 957777dab0Sopenharmony_ci * @param time Indicates the pointer to the persistent time of the TA. 967777dab0Sopenharmony_ci * 977777dab0Sopenharmony_ci * @return Returns <b>TEE_SUCCESS</b> if the operation is successful. 987777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_OUT_OF_MEMORY</b> if the memory is not sufficient to complete the operation. 997777dab0Sopenharmony_ci * @return Returns <b>TEE_ERROR_STORAGE_NO_SPACE</b> if the storage space is not sufficient to complete the operation. 1007777dab0Sopenharmony_ci * 1017777dab0Sopenharmony_ci * @since 12 1027777dab0Sopenharmony_ci * @version 1.0 1037777dab0Sopenharmony_ci */ 1047777dab0Sopenharmony_ciTEE_Result TEE_SetTAPersistentTime(TEE_Time *time); 1057777dab0Sopenharmony_ci 1067777dab0Sopenharmony_ci/** 1077777dab0Sopenharmony_ci * @brief Obtains the current Rich Execution Environment (REE) system time. 1087777dab0Sopenharmony_ci * 1097777dab0Sopenharmony_ci * @param time Indicates the pointer to the REE system time obtained. 1107777dab0Sopenharmony_ci * 1117777dab0Sopenharmony_ci * @since 12 1127777dab0Sopenharmony_ci * @version 1.0 1137777dab0Sopenharmony_ci */ 1147777dab0Sopenharmony_civoid TEE_GetREETime(TEE_Time *time); 1157777dab0Sopenharmony_ci 1167777dab0Sopenharmony_ci/** 1177777dab0Sopenharmony_ci * @brief Obtains the string format of the current Rich Execution Environment (REE) system time. 1187777dab0Sopenharmony_ci * 1197777dab0Sopenharmony_ci * @param tim_str Indicates the REE system time string. 1207777dab0Sopenharmony_ci * @param time_str_len Indicates the length of the string. 1217777dab0Sopenharmony_ci * 1227777dab0Sopenharmony_ci * @since 12 1237777dab0Sopenharmony_ci * @version 1.0 1247777dab0Sopenharmony_ci */ 1257777dab0Sopenharmony_civoid TEE_GetREETimeStr(char *tim_str, uint32_t time_str_len); 1267777dab0Sopenharmony_ci 1277777dab0Sopenharmony_ci#ifdef __cplusplus 1287777dab0Sopenharmony_ci} 1297777dab0Sopenharmony_ci#endif 1307777dab0Sopenharmony_ci/** @} */ 1317777dab0Sopenharmony_ci#endif 132