1 /*
2  * Copyright (c) 2022-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 COMMON_DEFINES_H
17 #define COMMON_DEFINES_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif // __cplusplus
22 
23 #define IF_TRUE_LOGE_AND_RETURN_VAL(cond, retVal) \
24     do { \
25         if (cond) { \
26             LOG_ERROR("(" #cond ") check fail, return"); \
27             return (retVal); \
28         } \
29     } while (0)
30 
31 #define IF_TRUE_LOGE_AND_RETURN(cond) \
32     do { \
33         if (cond) { \
34             LOG_ERROR("(" #cond ") check fail, return"); \
35             return; \
36         } \
37     } while (0)
38 
39 typedef enum ResultCode {
40     RESULT_SUCCESS = 0x0,
41     RESULT_GENERAL_ERROR = 0x1,
42     RESULT_BAD_PARAM = 0x2,
43     RESULT_BAD_COPY = 0x3,
44     RESULT_NO_MEMORY = 0x4,
45     RESULT_NEED_INIT = 0x5,
46     RESULT_NOT_FOUND = 0x6,
47     RESULT_REACH_LIMIT = 0x7,
48     RESULT_DUPLICATE_CHECK_FAILED = 0x8,
49     RESULT_BAD_READ = 0x9,
50     RESULT_BAD_WRITE = 0xA,
51     RESULT_BAD_DEL = 0xB,
52     RESULT_UNKNOWN = 0xC,
53     RESULT_BAD_MATCH = 0xD,
54     RESULT_BAD_SIGN = 0xE,
55     RESULT_BUSY = 0xF,
56     RESULT_PIN_FREEZE = 0x11,
57     RESULT_PIN_FAIL = 0X12,
58     RESULT_COMPARE_FAIL = 0x13
59 } ResultCode;
60 
61 typedef enum ResultCodeForCoAuth {
62     /**
63      * Indicates that authentication is success or ability is supported.
64      */
65     SUCCESS = 0,
66 
67     /**
68      * Indicates the authenticator fails to identify user.
69      */
70     FAIL = 1,
71 
72     /**
73      * Indicates other errors.
74      */
75     GENERAL_ERROR = 2,
76 
77     /**
78      * Indicates that authentication has been canceled.
79      */
80     CANCELED = 3,
81 
82     /**
83      * Indicates that authentication has timed out.
84      */
85     TIMEOUT = 4,
86 
87     /**
88      * Indicates that this authentication type is not supported.
89      */
90     TYPE_NOT_SUPPORT = 5,
91 
92     /**
93      * Indicates that the authentication trust level is not supported.
94      */
95     TRUST_LEVEL_NOT_SUPPORT = 6,
96 
97     /**
98      * Indicates that the authentication task is busy. Wait for a few seconds and try again.
99      */
100     BUSY = 7,
101 
102     /**
103      * Indicates incorrect parameters.
104      */
105     INVALID_PARAMETERS = 8,
106 
107     /**
108      * Indicates that the authenticator is locked.
109      */
110     LOCKED = 9,
111 
112     /**
113      * Indicates that the user has not enrolled the authenticator.
114      */
115     NOT_ENROLLED = 10,
116 } ResultCodeForCoAuth;
117 
118 typedef enum AuthType {
119     DEFAULT_AUTH_TYPE = 0,
120     PIN_AUTH = 1,
121     FACE_AUTH = 2,
122 } AuthType;
123 
124 typedef enum AuthSubType {
125     DEFAULT_TYPE = 0,
126 } AuthSubType;
127 
128 #define MAX_DULPLICATE_CHECK 100
129 
130 #define MAX_EXECUTOR_MSG_LEN 2048
131 
132 #ifdef __cplusplus
133 }
134 #endif // __cplusplus
135 #endif // COMMON_DEFINES_H
136