1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (C) 2022-2024 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef COMMON_DEFINES_H
17094332d3Sopenharmony_ci#define COMMON_DEFINES_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <stdint.h>
20094332d3Sopenharmony_ci
21094332d3Sopenharmony_ci#include "adaptor_log.h"
22094332d3Sopenharmony_ci
23094332d3Sopenharmony_ci#ifdef __cplusplus
24094332d3Sopenharmony_ciextern "C" {
25094332d3Sopenharmony_ci#endif
26094332d3Sopenharmony_ci
27094332d3Sopenharmony_cienum InnerKitResultCode {
28094332d3Sopenharmony_ci    INNER_RESULT_SUCCESS = 0,
29094332d3Sopenharmony_ci    INNER_RESULT_FAIL = 1,
30094332d3Sopenharmony_ci    INNER_RESULT_GENERAL_ERROR = 2,
31094332d3Sopenharmony_ci    INNER_RESULT_CANCELED = 3,
32094332d3Sopenharmony_ci    INNER_RESULT_TIMEOUT = 4,
33094332d3Sopenharmony_ci    INNER_RESULT_TYPE_NOT_SUPPORT = 5,
34094332d3Sopenharmony_ci    INNER_RESULT_TRUST_LEVEL_NOT_SUPPORT = 6,
35094332d3Sopenharmony_ci    INNER_RESULT_BUSY = 7,
36094332d3Sopenharmony_ci    INNER_RESULT_INVALID_PARAMETERS = 8,
37094332d3Sopenharmony_ci    INNER_RESULT_LOCKED = 9,
38094332d3Sopenharmony_ci    INNER_RESULT_NOT_ENROLLED = 10,
39094332d3Sopenharmony_ci    INNER_RESULT_HARDWARE_NOT_SUPPORTED = 11,
40094332d3Sopenharmony_ci    INNER_RESULT_PIN_EXPIRED = 13,
41094332d3Sopenharmony_ci    INNER_RESULT_SYSTEM_ERROR_CODE_BEGIN = 1000, // error code for system
42094332d3Sopenharmony_ci    INNER_RESULT_IPC_ERROR = 1001,
43094332d3Sopenharmony_ci    INNER_RESULT_INVALID_CONTEXT_ID = 1002,
44094332d3Sopenharmony_ci    INNER_RESULT_READ_PARCEL_ERROR = 1003,
45094332d3Sopenharmony_ci    INNER_RESULT_WRITE_PARCEL_ERROR = 1004,
46094332d3Sopenharmony_ci    INNER_RESULT_CHECK_PERMISSION_FAILED = 1005,
47094332d3Sopenharmony_ci    INNER_RESULT_INVALID_HDI_INTERFACE = 1006,
48094332d3Sopenharmony_ci    INNER_RESULT_VENDOR_ERROR_CODE_BEGIN = 10000, // error code for vendor
49094332d3Sopenharmony_ci};
50094332d3Sopenharmony_ci
51094332d3Sopenharmony_citypedef enum ResultCode {
52094332d3Sopenharmony_ci    RESULT_SUCCESS = INNER_RESULT_SUCCESS,
53094332d3Sopenharmony_ci    RESULT_GENERAL_ERROR = INNER_RESULT_GENERAL_ERROR,
54094332d3Sopenharmony_ci    RESULT_BAD_PARAM = INNER_RESULT_INVALID_PARAMETERS,
55094332d3Sopenharmony_ci    RESULT_NOT_ENROLLED = INNER_RESULT_NOT_ENROLLED,
56094332d3Sopenharmony_ci    RESULT_TYPE_NOT_SUPPORT = INNER_RESULT_TYPE_NOT_SUPPORT,
57094332d3Sopenharmony_ci    RESULT_TRUST_LEVEL_NOT_SUPPORT = INNER_RESULT_TRUST_LEVEL_NOT_SUPPORT,
58094332d3Sopenharmony_ci    RESULT_TIMEOUT = INNER_RESULT_TIMEOUT,
59094332d3Sopenharmony_ci    RESULT_PIN_EXPIRED = INNER_RESULT_PIN_EXPIRED,
60094332d3Sopenharmony_ci    RESULT_BAD_COPY = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x3,
61094332d3Sopenharmony_ci    RESULT_NO_MEMORY = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x4,
62094332d3Sopenharmony_ci    RESULT_NEED_INIT = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x5,
63094332d3Sopenharmony_ci    RESULT_NOT_FOUND = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x6,
64094332d3Sopenharmony_ci    RESULT_REACH_LIMIT = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x7,
65094332d3Sopenharmony_ci    RESULT_DUPLICATE_CHECK_FAILED = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x8,
66094332d3Sopenharmony_ci    RESULT_BAD_READ = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x9,
67094332d3Sopenharmony_ci    RESULT_BAD_WRITE = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0xA,
68094332d3Sopenharmony_ci    RESULT_BAD_DEL = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0xB,
69094332d3Sopenharmony_ci    RESULT_UNKNOWN = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0xC,
70094332d3Sopenharmony_ci    RESULT_BAD_MATCH = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0xD,
71094332d3Sopenharmony_ci    RESULT_BAD_SIGN = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0xE,
72094332d3Sopenharmony_ci    RESULT_BUSY = INNER_RESULT_BUSY,
73094332d3Sopenharmony_ci    RESULT_TOKEN_TIMEOUT = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x10,
74094332d3Sopenharmony_ci    RESULT_VERIFY_TOKEN_FAIL = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x11,
75094332d3Sopenharmony_ci    RESULT_EXCEED_LIMIT = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x12,
76094332d3Sopenharmony_ci
77094332d3Sopenharmony_ci    RESULT_AUTH_NOT_COMPELETED = INNER_RESULT_VENDOR_ERROR_CODE_BEGIN + 0x10001,
78094332d3Sopenharmony_ci} ResultCode;
79094332d3Sopenharmony_ci
80094332d3Sopenharmony_citypedef enum AuthType {
81094332d3Sopenharmony_ci    DEFAULT_AUTH_TYPE = 0, // default type used to cache pin
82094332d3Sopenharmony_ci    PIN_AUTH = 1,
83094332d3Sopenharmony_ci    FACE_AUTH = 2,
84094332d3Sopenharmony_ci    FINGER_AUTH = 4,
85094332d3Sopenharmony_ci    RECOVERY_KEY = 8,
86094332d3Sopenharmony_ci} AuthType;
87094332d3Sopenharmony_ci
88094332d3Sopenharmony_citypedef enum ScheduleMode {
89094332d3Sopenharmony_ci    SCHEDULE_MODE_ENROLL = 0,
90094332d3Sopenharmony_ci    SCHEDULE_MODE_AUTH = 1,
91094332d3Sopenharmony_ci    SCHEDULE_MODE_IDENTIFY = 2,
92094332d3Sopenharmony_ci    SCHEDULE_MODE_REUSE_UNLOCK_AUTH_RESULT = 3,
93094332d3Sopenharmony_ci} ScheduleMode;
94094332d3Sopenharmony_ci
95094332d3Sopenharmony_citypedef enum AuthSubType {
96094332d3Sopenharmony_ci    DEFAULT_TYPE = 0,
97094332d3Sopenharmony_ci} AuthSubType;
98094332d3Sopenharmony_ci
99094332d3Sopenharmony_citypedef enum UserType {
100094332d3Sopenharmony_ci    MAIN_USER = 0,
101094332d3Sopenharmony_ci    SUB_USER = 1,
102094332d3Sopenharmony_ci    PRIVATE_USER = 2,
103094332d3Sopenharmony_ci} UserType;
104094332d3Sopenharmony_ci
105094332d3Sopenharmony_citypedef enum AuthPropertyMode {
106094332d3Sopenharmony_ci    PROPERTY_INIT_ALGORITHM = 1,
107094332d3Sopenharmony_ci    PROPERTY_MODE_DEL = 2,
108094332d3Sopenharmony_ci    PROPERTY_MODE_GET = 3,
109094332d3Sopenharmony_ci    PROPERTY_MODE_SET = 4,
110094332d3Sopenharmony_ci    PROPERTY_MODE_FREEZE = 5,
111094332d3Sopenharmony_ci    PROPERTY_MODE_UNFREEZE = 6,
112094332d3Sopenharmony_ci    PROPERTY_MODE_SET_CACHED_TEMPLATES = 7,
113094332d3Sopenharmony_ci} AuthPropertyMode;
114094332d3Sopenharmony_ci
115094332d3Sopenharmony_citypedef enum Asl {
116094332d3Sopenharmony_ci    ASL0 = 0,
117094332d3Sopenharmony_ci    ASL1 = 1,
118094332d3Sopenharmony_ci    ASL2 = 2,
119094332d3Sopenharmony_ci    ASL3 = 3,
120094332d3Sopenharmony_ci    MAX_ASL = 4,
121094332d3Sopenharmony_ci} Asl;
122094332d3Sopenharmony_ci
123094332d3Sopenharmony_citypedef enum Acl {
124094332d3Sopenharmony_ci    ACL0 = 0,
125094332d3Sopenharmony_ci    ACL1 = 1,
126094332d3Sopenharmony_ci    ACL2 = 2,
127094332d3Sopenharmony_ci    ACL3 = 3,
128094332d3Sopenharmony_ci} Acl;
129094332d3Sopenharmony_ci
130094332d3Sopenharmony_citypedef enum Atl {
131094332d3Sopenharmony_ci    ATL0 = 0,
132094332d3Sopenharmony_ci    ATL1 = 10000,
133094332d3Sopenharmony_ci    ATL2 = 20000,
134094332d3Sopenharmony_ci    ATL3 = 30000,
135094332d3Sopenharmony_ci    ATL4 = 40000,
136094332d3Sopenharmony_ci} Atl;
137094332d3Sopenharmony_ci
138094332d3Sopenharmony_citypedef enum TokenType {
139094332d3Sopenharmony_ci    TOKEN_TYPE_LOCAL_AUTH = 0,
140094332d3Sopenharmony_ci    TOKEN_TYPE_LOCAL_RESIGN = 1,
141094332d3Sopenharmony_ci    TOKEN_TYPE_COAUTH = 2,
142094332d3Sopenharmony_ci} TokenType;
143094332d3Sopenharmony_ci
144094332d3Sopenharmony_citypedef enum AuthIntent {
145094332d3Sopenharmony_ci    DEFUALT = 0,
146094332d3Sopenharmony_ci    UNLOCK = 1,
147094332d3Sopenharmony_ci    SILENT_AUTH = 2,
148094332d3Sopenharmony_ci} AuthIntent;
149094332d3Sopenharmony_ci
150094332d3Sopenharmony_ci#define IF_TRUE_LOGE_AND_RETURN_VAL(cond, retVal) \
151094332d3Sopenharmony_ci    do { \
152094332d3Sopenharmony_ci        if (cond) { \
153094332d3Sopenharmony_ci            LOG_ERROR("(" #cond ") check fail, return"); \
154094332d3Sopenharmony_ci            return (retVal); \
155094332d3Sopenharmony_ci        } \
156094332d3Sopenharmony_ci    } while (0)
157094332d3Sopenharmony_ci
158094332d3Sopenharmony_ci#define IF_TRUE_LOGE_AND_RETURN(cond) \
159094332d3Sopenharmony_ci    do { \
160094332d3Sopenharmony_ci        if (cond) { \
161094332d3Sopenharmony_ci            LOG_ERROR("(" #cond ") check fail, return"); \
162094332d3Sopenharmony_ci            return; \
163094332d3Sopenharmony_ci        } \
164094332d3Sopenharmony_ci    } while (0)
165094332d3Sopenharmony_ci
166094332d3Sopenharmony_ci#define MAX_DUPLICATE_CHECK 100
167094332d3Sopenharmony_ci#define INVALID_SENSOR_HINT 0
168094332d3Sopenharmony_ci#define MAX_TEMPLATE_OF_SCHEDULE 10
169094332d3Sopenharmony_ci#define CHALLENGE_LEN 32
170094332d3Sopenharmony_ci#define MAX_CREDENTIAL_OUTPUT 10
171094332d3Sopenharmony_ci#define MAX_ENROLL_OUTPUT 5
172094332d3Sopenharmony_ci#define MAX_AUTH_TYPE_LEN 4
173094332d3Sopenharmony_ci#define UDID_LEN 64
174094332d3Sopenharmony_ci#define INVALID_USER_ID (-1)
175094332d3Sopenharmony_ci
176094332d3Sopenharmony_ci#ifdef __cplusplus
177094332d3Sopenharmony_ci}
178094332d3Sopenharmony_ci#endif
179094332d3Sopenharmony_ci
180094332d3Sopenharmony_ci#endif
181