1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"), 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup TeeTrusted 18 * @{ 19 * 20 * @brief TEE(Trusted Excution Environment) API. 21 * Provides security capability APIs such as trusted storage, encryption and decryption, 22 * and trusted time for trusted application development. 23 * 24 * @since 20 25 */ 26 27 /** 28 * @file tee_apm_api.h 29 * 30 * @brief Provides the API about TA APM. 31 * 32 * @library NA 33 * @kit TEEKit 34 * @syscap SystemCapability.Tee.TeeClient 35 * @since 20 36 */ 37 38 #ifndef TEE_APM_API_H 39 #define TEE_APM_API_H 40 41 #include "tee_defines.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Enumerates the TEE measurement result values. 49 * 50 * @since 20 51 */ 52 enum tee_measure_result_value { 53 /** Measurement success. */ 54 TEE_MEASURE_SUCCESS = 0x00000000, 55 /** Generic error. */ 56 TEE_MEASURE_ERROR_GENERIC = 0x00000001, 57 /** TA hash check failed. */ 58 TEE_MEASURE_ERROR_TA_HASH_CHECK_FAILED = 0x00000002, 59 /** TA baseline does not exist. */ 60 TEE_MEASURE_ERROR_TA_BASELINE_NOT_EXIST = 0x00000003, 61 /** TA memory hash does not exist. */ 62 TEE_MEASURE_ERROR_TA_MEMHASH_NOT_EXIST = 0x00000004, 63 /** Permission denied. */ 64 TEE_MEASURE_ERROR_PERMISSION_DENY = 0x00000005, 65 /** TA history measurement does not exist. */ 66 TEE_MEASURE_ERROR_TA_HISTORY_MEASURE_NOT_EXIST = 0x00000006, 67 /** MSPC report query failed. */ 68 TEE_MEASURE_ERROR_MSPC_REPORT_QUERY_FAILED = 0x00000007, 69 /** MSPC service is unavailable. */ 70 TEE_MEASURE_ERROR_MSPC_NOT_SUPPORT = 0x00000008, 71 /** APM measurement report not supported. */ 72 TEE_MEASURE_ERROR_REPORT_NOT_SUPPORT = 0x00000009, 73 /** APM service is unavailable. */ 74 TEE_MEASURE_ERROR_APM_NOT_SUPPORT = 0x0000000a, 75 }; 76 77 /** 78 * @brief Record the recent measure errors. 79 * 80 * @since 20 81 */ 82 #define MAX_HISTORY_MEASURE_RECORDS_NUM 10 83 84 /** 85 * @brief Defines the history of measurement errors. 86 * 87 * @since 20 88 */ 89 struct history_measure_result_t { 90 /** recent measure errors number. */ 91 uint8_t error_num; 92 /** measure error type */ 93 uint32_t error_type[MAX_HISTORY_MEASURE_RECORDS_NUM]; 94 /** measure error time */ 95 uint64_t error_time[MAX_HISTORY_MEASURE_RECORDS_NUM]; 96 }; 97 98 /** 99 * @brief Defines the size of the TA memory hash. 100 * 101 * @since 20 102 */ 103 #define TA_HASH_SIZE 32 104 105 /** 106 * @brief Defines the structure of the TA measure report. 107 * 108 * @since 20 109 */ 110 struct ta_measure_report_t { 111 /** TA UUID */ 112 TEE_UUID uuid; 113 /** TA's measurement result */ 114 uint32_t measure_result; 115 /** TA's runtime measurement hash */ 116 uint8_t ta_measured[TA_HASH_SIZE]; 117 /** TA's baseline measurement hash */ 118 uint8_t ta_baseline[TA_HASH_SIZE]; 119 /** History measurement results */ 120 struct history_measure_result_t history_result; 121 }; 122 123 /** 124 * @brief Queries the TA measure report. 125 * 126 * @param uuid A pointer to the TA's UUID. 127 * @param report A pointer to the structure that stores the measure report result. 128 * 129 * @return Returns the query result, TEE_SUCCESS if successful, or the corresponding error code if failed. 130 * 131 * @since 20 132 */ 133 TEE_Result tee_query_ta_measure_report(const TEE_UUID *uuid, struct ta_measure_report_t *report); 134 135 /** 136 * @brief Defines the structure of the MSPC measure report element. 137 * 138 * @since 20 139 */ 140 struct mspc_metric_report_element_t { 141 /** Baseline status */ 142 uint32_t baseline_status; 143 /** Most recent error */ 144 uint32_t recent_error; 145 /** Error type */ 146 uint32_t error_class; 147 /** Time when the error occurred */ 148 uint32_t error_time; 149 }; 150 151 /** 152 * @brief Defines the structure of the MSPC measure result report substructure. 153 * 154 * @since 20 155 */ 156 struct mspc_metric_result_report_sub { 157 /** Global metric result */ 158 struct mspc_metric_report_element_t global_result; 159 /** BL2 metric result */ 160 struct mspc_metric_report_element_t bl2_result; 161 /** BL31 metric result */ 162 struct mspc_metric_report_element_t bl31_result; 163 /** TEE metric result */ 164 struct mspc_metric_report_element_t tee_result; 165 }; 166 167 /** 168 * @brief Defines the structure of the passive part of the MSPC measure result report. 169 * 170 * @since 20 171 */ 172 struct mspc_metric_result_report_passive { 173 /** BL2 verification result */ 174 struct mspc_metric_report_element_t bl2_verify_result; 175 /** TEE active metric result */ 176 struct mspc_metric_report_element_t tee_active_protect; 177 }; 178 179 /** 180 * @brief Defines the structure of the command processing part of the MSPC measure result report. 181 * 182 * @since 20 183 */ 184 struct mspc_metric_result_report_of_cmd_process { 185 /** Baseline command metirc result */ 186 struct mspc_metric_report_element_t cmd_baseline; 187 /** Active command metric result */ 188 struct mspc_metric_report_element_t cmd_active_metric; 189 /** Passive command metric result */ 190 struct mspc_metric_report_element_t cmd_passive_metric; 191 /** Query command metric result */ 192 struct mspc_metric_report_element_t cmd_query_result; 193 }; 194 195 /** 196 * @brief Defines the structure of the MSPC measure result report. 197 * 198 * @since 20 199 */ 200 struct mspc_metric_result_report_t { 201 /** Final metric result */ 202 uint32_t final_result; 203 /** Baseline metric report */ 204 struct mspc_metric_result_report_sub baseline_report; 205 /** Idle metric report */ 206 struct mspc_metric_result_report_sub idle_metric_report; 207 /** Active metric report */ 208 struct mspc_metric_result_report_sub active_metric_report; 209 /** Passive metric report */ 210 struct mspc_metric_result_report_passive passive_metric_report; 211 /** Command metric report */ 212 struct mspc_metric_result_report_of_cmd_process cmd_process_report; 213 }; 214 215 /** 216 * @brief Queries the MSPC measurement report. 217 * 218 * @param report A pointer to the structure that stores mspc measurement report. 219 * 220 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 221 * Returns other information otherwise. 222 * 223 * @since 20 224 */ 225 TEE_Result tee_query_mspc_measure_report(struct mspc_metric_result_report_t *report); 226 227 #ifdef __cplusplus 228 } 229 #endif 230 231 #endif 232 /** @} */