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