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_tui_gp_api.h 29 * 30 * @brief Provides APIs for operating big integers. 31 * 32 * @library NA 33 * @kit TEEKit 34 * @syscap SystemCapability.Tee.TeeClient 35 * @since 20 36 */ 37 38 #ifndef TASK_TUI_GP_API_H 39 #define TASK_TUI_GP_API_H 40 41 #include <stdbool.h> 42 #include <stdint.h> 43 #include <stdlib.h> 44 #include <tee_defines.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Defines the number of button types in TUI. 52 * 53 * @since 20 54 */ 55 #define TEE_TUI_NUMBER_BUTTON_TYPES 0x00000006 56 57 /** 58 * @brief Defines the private storage type. 59 * 60 * @since 20 61 */ 62 #define TEE_STORAGE_PRIVATE 0x00000001 63 64 /** 65 * @brief Defines the default maximum number of entry fields. 66 * 67 * @since 20 68 */ 69 #define DEFAULT_MAX_ENTRY_FIELDS 3 70 71 /** 72 * @brief Defines the identifier for the exit operation. 73 * 74 * @since 20 75 */ 76 #define TUI_EXIT 8 77 78 /** 79 * @brief Enumerates the modes supported when displaying characters within an input entry field. 80 * 81 * @since 20 82 */ 83 typedef enum { 84 /** Never visible, displayed as '*'. */ 85 TEE_TUI_HIDDEN_MODE = 0, 86 /** Always visible. */ 87 TEE_TUI_CLEAR_MODE, 88 /** Visible then hidden. */ 89 TEE_TUI_TEMPORARY_CLEAR_MODE 90 } TEE_TUIEntryFieldMode; 91 92 /** 93 * @brief Enumerates the input types supported of the TUI entry field. 94 * 95 * @since 20 96 */ 97 typedef enum { 98 /** When the field accepts only digits as inputs. */ 99 TEE_TUI_NUMERICAL = 0, 100 /** When the field accepts characters and digits as inputs. */ 101 TEE_TUI_ALPHANUMERICAL, 102 } TEE_TUIEntryFieldType; 103 104 /** 105 * @brief Enumerates the TUI screen orientation. 106 * @attention Currently {@code TEE_TUI_LANDSCAPE} is not supported. 107 * 108 * @since 20 109 */ 110 typedef enum { 111 /** Displayed as a portrait, i.e. vertically. */ 112 TEE_TUI_PORTRAIT = 0, 113 /** Displayed as a landscape, i.e. horizontally. */ 114 TEE_TUI_LANDSCAPE, 115 } TEE_TUIScreenOrientation; 116 117 /** 118 * @brief Enumerates the types of the button. 119 * 120 * @since 20 121 */ 122 typedef enum { 123 /** Used to delete the previous input digit. */ 124 TEE_TUI_CORRECTION = 0, 125 /** Exits the interface. */ 126 TEE_TUI_OK, 127 /** Cancels the operation and exits the interface. */ 128 TEE_TUI_CANCEL, 129 /** Used to trigger PIN verifcation and exit the interface.*/ 130 TEE_TUI_VALIDATE, 131 /** Exit the current interface and ask the TA to display the previous interface. */ 132 TEE_TUI_PREVIOUS, 133 /** Exit the current interface and ask the TA to display the next interface. */ 134 TEE_TUI_NEXT, 135 } TEE_TUIButtonType; 136 137 /** 138 * @brief Enumerates source of the uesd image. 139 * 140 * @since 20 141 */ 142 typedef enum { 143 /** No picture provided in the input. */ 144 TEE_TUI_NO_SOURCE = 0, 145 /** The picture provided as a memory pointer. */ 146 TEE_TUI_REF_SOURCE, 147 /** The picture provided by an object in the secure storage. */ 148 TEE_TUI_OBJECT_SOURCE, 149 /** The picture provided as a file. */ 150 TEE_TUI_FILE_SOURCE = 0x8001 151 } TEE_TUIImageSource; 152 153 /** 154 * @brief Represents the image in PNG format. 155 * 156 * @since 20 157 */ 158 typedef struct { 159 /** Represents the source of the image. */ 160 TEE_TUIImageSource source; 161 /** 162 * @brief Contains the image data and its length. 163 * 164 * @since 20 165 */ 166 struct { 167 /** Pointer to the image data. */ 168 void *image; 169 /** The length of the image data. */ 170 size_t imageLength; 171 } ref; 172 /** 173 * @brief Represents the object storage information. 174 * 175 * @since 20 176 */ 177 struct { 178 /** The storage ID where the image is stored. */ 179 uint32_t storageID; 180 /** Pointer to the object ID where the image is stored. */ 181 void *objectID; 182 /** The length of the object ID. */ 183 size_t objectIDLen; 184 } object; 185 /** Represents the number of pixels in the width of the image. */ 186 uint32_t width; 187 /** Represents the number of pixels in the height of the image. */ 188 uint32_t height; 189 } TEE_TUIImage; 190 191 /** 192 * @brief Enumerates the GP color index. 193 * 194 * @since 20 195 */ 196 enum gp_color_idx { 197 /** Red color index. */ 198 RED_IDX = 0, 199 /** Green color index. */ 200 GREEN_IDX = 1, 201 /** Blue color index. */ 202 BLUE_IDX = 2, 203 /** RGB color index. */ 204 RGB_COLOR_IDX = 3, 205 }; 206 207 /** 208 * @brief Represents the label for TA branding/message, generally on the top of screen. 209 * 210 * @since 20 211 */ 212 typedef struct { 213 /** It's the string to put in the label area, which can be NULL. */ 214 char *text; 215 /** X-coordinate of the upper left corner of the text information. */ 216 uint32_t textXOffset; 217 /** Y-coordinate of the upper left corner of the text information. */ 218 uint32_t textYOffset; 219 /** RGB color used for displaying the text information. */ 220 uint8_t textColor[RGB_COLOR_IDX]; 221 /** The image is placed in the label area. */ 222 TEE_TUIImage image; 223 /** X-coordinate of the upper left corner of the image to be displayed. */ 224 uint32_t imageXOffset; 225 /** Y-coordinate of the upper left corner of the image to be displayed. */ 226 uint32_t imageYOffset; 227 } TEE_TUIScreenLabel; 228 229 /** 230 * @brief Represents the content displayed on a button. 231 * 232 * @since 20 233 */ 234 typedef struct { 235 /** It's the string to associate with the button, which can be NULL. */ 236 char *text; 237 /** The image to associate with the button. */ 238 TEE_TUIImage image; 239 } TEE_TUIButton; 240 241 /** 242 * @brief Represents the configuration about the TUI screen. 243 * 244 * @since 20 245 */ 246 typedef struct { 247 /** The requested screen orientation. */ 248 TEE_TUIScreenOrientation screenOrientation; 249 /** The specifies label of the screen.*/ 250 TEE_TUIScreenLabel label; 251 /** Customizes the buttons compared to the default. */ 252 TEE_TUIButton *buttons[TEE_TUI_NUMBER_BUTTON_TYPES]; 253 /** Specifes which buttons to be displayed. */ 254 bool requestedButtons[TEE_TUI_NUMBER_BUTTON_TYPES]; 255 } TEE_TUIScreenConfiguration; 256 257 /** 258 * @brief Represents the information about a TUI screen button. 259 * @attention The {@code buttonTextCustom} and {@code buttonImageCustom} cannot be set to true at the same time. 260 * 261 * @since 20 262 */ 263 typedef struct { 264 /** Defaut label value of the button text. If the value is NULL means the parameter is unavailable. */ 265 const char *buttonText; 266 /** The pixel width of the button. 267 * If the text or image on the button cannot be customized, the value is <b>0</b>. 268 */ 269 uint32_t buttonWidth; 270 /** The pixel height of the button. 271 * If the text or image on the button cannot be customized, the value is <b>0</b>. 272 */ 273 uint32_t buttonHeight; 274 /** If the text on the button cannot be customized, the value is true. */ 275 bool buttonTextCustom; 276 /** If the image on the button cannot be customized, the value is true. */ 277 bool buttonImageCustom; 278 } TEE_TUIScreenButtonInfo; 279 280 /** 281 * @brief Represents the information displayed on the TUI. 282 * 283 * @since 20 284 */ 285 typedef struct { 286 /** Available grayscale. */ 287 uint32_t grayscaleBitsDepth; 288 /** Available red depth level. */ 289 uint32_t redBitsDepth; 290 /** Available green depth level. */ 291 uint32_t greenBitsDepth; 292 /** Available blue depth level. */ 293 uint32_t blueBitsDepth; 294 /** Indicates the number of pixels per inch in the width direction. */ 295 uint32_t widthInch; 296 /** Indicates the number of pixels per inch in the height direction. */ 297 uint32_t heightInch; 298 /** Indicates the maximum number of entries that can be displayed on the TUI. */ 299 uint32_t maxEntryFields; 300 /** Indicates the pixel width of the input region label. */ 301 uint32_t entryFieldLabelWidth; 302 /** Indicates the pixel height of the input region label. */ 303 uint32_t entryFieldLabelHeight; 304 /** Indicates the maximum number of characters that can be entered in the entry field. */ 305 uint32_t maxEntryFieldLength; 306 /** RGB value of the default label canvas. */ 307 uint8_t labelColor[RGB_COLOR_IDX]; 308 /** Indicates the pixel width of the label canvas. */ 309 uint32_t labelWidth; 310 /** Indicates the pixel height of the label canvas. */ 311 uint32_t labelHeight; 312 /** Indicates the information of the buttons on the interface. */ 313 TEE_TUIScreenButtonInfo buttonInfo[TEE_TUI_NUMBER_BUTTON_TYPES]; 314 } TEE_TUIScreenInfo; 315 316 /** 317 * @brief Represents the information in an entry field that requires user input. 318 * 319 * @since 20 320 */ 321 typedef struct { 322 /** Indicates the label of the entry field. */ 323 char *label; 324 /** Indicates the mode used to display characters. */ 325 TEE_TUIEntryFieldMode mode; 326 /** Indicates the type of the characters can be entered in the entry field. */ 327 TEE_TUIEntryFieldType type; 328 /** The minimum number of characters to be entered. */ 329 uint32_t minExpectedLength; 330 /** The maximum number of characters to be entered. */ 331 uint32_t maxExpectedLength; 332 /** Contains the content entered by user. */ 333 char *buffer; 334 /** Indicates the length of the buffer. */ 335 size_t bufferLength; 336 } TEE_TUIEntryField; 337 338 /** 339 * @brief Initializing the TUI resources. 340 * 341 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 342 * Returns {@code TEE_ERROR_BAD_PARAMETERS} if input parameter is incorrect. 343 * Returns {@code TEE_ERROR_NOT_SUPPORTED} if the device is not support TUI. 344 * Returns {@code TEE_ERROR_BUSY} if the TUI resources cannot be reserved. 345 * Returns {@code TEE_ERROR_OUT_OF_MEMORY} if the system ran out of the resources. 346 * 347 * @since 20 348 */ 349 TEE_Result TEE_TUIInitSession(void); 350 351 352 /** 353 * @brief Releases TUI resources previously acquired. 354 * 355 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 356 * Returns {@code TEE_ERROR_BAD_STATE} if the current TA is not within a TUI session initially 357 * started by a successful call to {@code TEE_TUIInitSession}. 358 * Returns {@code TEE_ERROR_BUSY} if the TUI resources currently are in use. 359 * 360 * @since 20 361 */ 362 TEE_Result TEE_TUICloseSession(void); 363 364 /** 365 * @brief Allows a TA to check whether a given text can be rendered by the current implementation and 366 * retrieves information about the size and width that is needed to render it. 367 * 368 * @param text Indicates the string to be checked. 369 * @param width Indicates the width in pixels needed to render the text. 370 * @param height Indicates the height in pixels needed to render the text. 371 * @param last_index Indicates the last character that has been checked 372 * 373 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 374 * Returns {@code TEE_ERROR_NOT_SUPPORTED} if at least one of the characters present 375 * in the text string cannot be rendered. 376 * 377 * @since 20 378 */ 379 TEE_Result TEE_TUICheckTextFormat(const char *text, uint32_t *width, uint32_t *height, uint32_t *last_index); 380 381 /** 382 * @brief Retrieves information about the screen depending on its orientation and 383 * the number of required entry fields. 384 * 385 * @param screenOrientation Defines for which orientation screen information is requested. 386 * @param nbEntryFields Indicates the number of the requested entry fields. 387 * @param screenInfo Indicates the information on the requested screen for a given orientation. 388 * 389 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 390 * Returns {@code TEE_ERROR_NOT_SUPPORTED} if the number of entry fields is not supported. 391 * 392 * @since 20 393 */ 394 TEE_Result TEE_TUIGetScreenInfo(TEE_TUIScreenOrientation screenOrientation, 395 uint32_t nbEntryFields, 396 TEE_TUIScreenInfo *screenInfo); 397 /** 398 * @brief Display a TUI screen. 399 * 400 * @param screenConfiguration Indicates the configuration of the labels and optional buttons on the display interface. 401 * @param closeTUISession If the value is true, the TUI session will automatically closed when exiting the function. 402 * @param entryFields Indicates the information of entry field. 403 * @param entryFieldCount Indicates the count of the entry fields. 404 * @param selectedButton Indicates which button has been selected by the user to exit the TUI screen. 405 * 406 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 407 * Returns {@code TEE_ERROR_OUT_OF_MEMORY} if the system ran out of the resources. 408 * Returns {@code TEE_ERROR_ITEM_NOT_FOUND} if at least one image provided by the TA refers to a storage 409 * denoted by a storageID which dose not exist or if the corresponding object identifier cannot be found in the storage. 410 * Returns {@code TEE_ERROR_ACCESS_CONFLICT} if at least one image provided by the TA refers to a data 411 * object in the trusted storage and an access right conflict was detected while opening the object. 412 * Returns {@code TEE_ERROR_BAD_FORMAT} if at least one input image is not compliant with PNG format. 413 * Returns {@code TEE_ERROR_BAD_STATE} if the current TA is not within a TUI session 414 * initially started by a successful call to {@code TEE_TUIInitSession}. 415 * Returns {@code TEE_ERROR_BUSY} if the TUI resources are currently in use, i.e. a TUI screen is displayed. 416 * Returns {@code TEE_ERROR_CANCEL} if the operation has been cancelled while a TUI screen is currently 417 * displayed. 418 * Returns {@code TEE_ERROR_EXTERNAL_CANCEL} if the operation has been cancelled by an external event which 419 * occurred in the REE while a TUI screen is currently displayed. 420 * 421 * @since 20 422 */ 423 TEE_Result TEE_TUIDisplayScreen(TEE_TUIScreenConfiguration *screenConfiguration, 424 bool closeTUISession, 425 TEE_TUIEntryField *entryFields, 426 uint32_t entryFieldCount, 427 TEE_TUIButtonType *selectedButton); 428 429 /** 430 * @brief Fringerprint identification port. 431 * 432 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 433 * Returns {@code TEE_ERROR_NOT_SUPPORTED} if the device is not support TUI. 434 * 435 * @since 20 436 */ 437 TEE_Result TEE_TUINotify_fp(void); 438 439 /** 440 * @brief Set the Chinese character encoding. The system supports UTF-8 by default. 441 * 442 * @param type Indicates the encoding type. The value 1 indicates GBK. Other values are not supported. 443 * 444 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 445 * Returns {@code TEE_ERROR_NOT_SUPPORTED} if the device is not support this function. 446 * Returns {@code TEE_ERROR_BAD_PARAMETERS} if input parameter is incorrect. 447 * 448 * @since 20 449 */ 450 TEE_Result TEE_TUISetInfo(int32_t type); 451 452 /** 453 * @brief Send message to TUI. 454 * 455 * @param type Indicates the messages send to the TUI. Only support {@code TUI_EXIT}. 456 * 457 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 458 * Returns {@code TEE_ERROR_BAD_PARAMETERS} if input parameter is incorrect. 459 * 460 * @since 20 461 */ 462 TEE_Result TEE_TUISendEvent(int32_t type); 463 464 /** 465 * @brief Setting the TUI background image. 466 * 467 * @param label Configure the background image information in the label variable. 468 * The image must be a PNG image in array format. 469 * @param len Indicates the label size. 470 * 471 * @return Returns {@code TEE_SUCCESS} if the operation is successful. 472 * Returns {@code TEE_ERROR_GENERIC} if input parameter is incorrect. 473 * Returns {@code TEE_ERROR_ACCESS_DENIED} if the permission verification failed. 474 * 475 * @since 20 476 */ 477 TEE_Result TEE_TUISetLabel(TEE_TUIScreenLabel *label, uint32_t len); 478 479 #ifdef __cplusplus 480 } 481 #endif 482 483 #endif 484 /** @} */