• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_DEFS_H
17 #define COMMON_DEFS_H
18 
19 #include "device_auth.h"
20 #include "device_auth_defines.h"
21 #include "hc_string.h"
22 #include "hc_vector.h"
23 #include "json_utils.h"
24 
25 #define FIELD_DEVICE_PK "devicePk"
26 #define FIELD_UDID "udid"
27 #define FIELD_PK_INFO_SIGNATURE "pkInfoSignature"
28 #define FIELD_CREDENTIAL "credential"
29 #define FIELD_SERVER_PK "serverPk"
30 
31 #define FIELD_ADD_TYPE "addType"
32 #define FIELD_ADD_ID "addId"
33 #define FIELD_ADD_KEY "addKey"
34 #define FIELD_AUTH_DATA "authData"
35 #define FIELD_AUTH_RETURN "authReturn"
36 #define FIELD_AUTH_ID "authId"
37 #define FIELD_AUTH_PK "authPk"
38 #define FIELD_ADD_AUTH_INFO "addAuthInfo"
39 #define FIELD_ADD_RETURN "addReturn"
40 #define FIELD_APP_ID "appId"
41 #define FIELD_BIND_SESSION_TYPE "bindSessionType"
42 #define FIELD_CHALLENGE "challenge"
43 #define FIELD_CHANNEL_ID "channelId"
44 #define FIELD_CONN_DEVICE_ID "connDeviceId"
45 #define FIELD_CONNECT_PARAMS "connectParams"
46 #define FIELD_CROSS_USER_ID_LIST "crossUserIdList"
47 #define FIELD_CURRENT_VERSION "currentVersion"
48 #define FIELD_DELETE_ID "deleteId"
49 #define FIELD_DELETED_RESULT "deletedResult"
50 #define FIELD_DEVICE_CLOUD_CREDENTIAL "devCloudCred"
51 #define FIELD_DEV_ID "devId"
52 #define FIELD_DEVICES_CREDENTIAL "devicesCredential"
53 #define FIELD_ENC_AUTH_TOKEN "encAuthToken"
54 #define FIELD_ENC_RESULT "encResult"
55 #define FIELD_ENC_DATA "encData"
56 #define FIELD_EPK "epk"
57 #define FIELD_EPK_LEN "epkLen"
58 #define FIELD_EX_AUTH_INFO "exAuthInfo"
59 #define FIELD_EXPIRE_TIME "expireTime"
60 #define FIELD_ERROR_CODE "errorCode"
61 #define FIELD_GROUP_INFO "groupInfo"
62 #define FIELD_GROUP_MANAGERS "groupManagers"
63 #define FIELD_GROUP_NAME "groupName"
64 #define FIELD_GROUP_OP "groupOp"
65 #define FIELD_GROUP_TYPE "groupType"
66 #define FIELD_GROUP_VISIBILITY "groupVisibility"
67 #define FIELD_IS_ADMIN "isAdmin"
68 #define FIELD_IS_ACCOUNT_BIND "isAccountBind"
69 #define FIELD_IS_FORCE_DELETE "isForceDelete"
70 #define FIELD_IS_CREDENTIAL_EXISTS "isCredentialExists"
71 #define FIELD_KCF_DATA "kcfData"
72 #define FIELD_KEY_TYPE "keyType"
73 #define FIELD_MESSAGE "message"
74 #define FIELD_GROUP_ERROR_MSG "groupErrorMsg"
75 #define FIELD_MIN_VERSION "minVersion"
76 #define FIELD_GROUP_AND_MODULE_VERSION "groupAndModuleVersion"
77 #define FIELD_NONCE "nonce"
78 #define FIELD_OPERATION_CODE "operationCode"
79 #define FIELD_OPERATION_PARAMS "operationParams"
80 #define FIELD_OWNER_ID "ownerId"
81 #define FIELD_OWNER_NAME "ownerName"
82 #define FIELD_PERMISSION "Permission"
83 #define FIELD_PAYLOAD "payload"
84 #define FIELD_PIN_CODE "pinCode"
85 #define FIELD_PUBLIC_KEY "publicKey"
86 #define FIELD_PK_INFO "pkInfo"
87 #define FIELD_PKG_NAME "pkgName"
88 #define FIELD_SELF_AUTH_ID "selfAuthId"
89 #define FIELD_SELF_DEVICE_ID "selfDeviceId"
90 #define FIELD_SELF_DEV_ID "selfDevId"
91 #define FIELD_SELF_USER_ID "selfUserId"
92 #define FIELD_REQUEST_ID "requestId"
93 #define FIELD_RECEIVED_DATA "receivedData"
94 #define FIELD_RETURN_CODE "returnCode"
95 #define FIELD_RETURN_DATA "returnData"
96 #define FIELD_RETURN_CODE_MAC "returnCodeMac"
97 #define FIELD_RMV_TYPE "rmvType"
98 #define FIELD_RMV_ID "rmvId"
99 #define FIELD_RMV_AUTH_INFO "rmvAuthInfo"
100 #define FIELD_RMV_RETURN "rmvReturn"
101 #define FIELD_SALT "salt"
102 #define FIELD_ISO_SALT "isoSalt"
103 #define FIELD_SEED "seed"
104 #define FIELD_SELF_TYPE "selfType"
105 #define FIELD_SEND_TO_PEER "sendToPeer"
106 #define FIELD_SEND_TO_SELF "sendToSelf"
107 #define FIELD_SHARED_USER_ID_LIST "sharedUserIdList"
108 #define FIELD_SUPPORT_256_MOD "support256mod"
109 #define FIELD_TOKEN "token"
110 #define FIELD_IS_UUID "uuIdAsDeviceId"
111 #define FIELD_VERSION "version"
112 #define FIELD_MK_AGREE_MSG "mkaMsg"
113 #define FIELD_PEER_ID_FROM_REQUEST "peerIdFromRequest"
114 #define FIELD_STEP "step"
115 #define FIELD_DATA "data"
116 #define FIELD_EPK "epk"
117 #define FIELD_AUTH_KEY_ALG_ENCODE "authKeyAlgEncode"
118 #define FIELD_AUTH_PK_INFO "authPkInfo"
119 #define FIELD_AUTH_PK_INFO_SIGN "authPkInfoSign"
120 #define FIELD_AUTH_RESULT_MAC "authResultMac"
121 #define FIELD_LOCAL_DEVICE_TYPE "localDeviceType"
122 
123 #define INVALID_MODULE_TYPE (-1)
124 #define GROUP_ERR_MSG 0x8080
125 
126 #define CLIENT 1
127 #define SERVER 0
128 
129 #define CREATE_KEY_PAIR 1
130 #define DELETE_KEY_PAIR 2
131 
132 /* DefaultValue */
133 #define DEFAULT_MEMORY_SIZE 64
134 #define DEFAULT_USER_ID_HASH ""
135 #define DEFAULT_REQUEST_ID 0
136 #define DEFAULT_CHANNEL_ID (-1)
137 #define DEFAULT_EXPIRE_TIME 90
138 #define GROUP_MANAGER_PACKAGE_NAME "com.huawei.devicegroupmanage"
139 #define DEFAULT_RETURN_KEY_LENGTH 32
140 #define MAX_BUFFER_LEN 1024
141 #define MAX_DATA_BUFFER_SIZE 4096
142 #define MAX_AUTH_ID_LEN 256
143 
144 typedef enum {
145     NO_CHANNEL = 1,
146     SERVICE_CHANNEL = 2,
147     SOFT_BUS = 3,
148 } ChannelType;
149 
150 typedef enum {
151     SELF_CREATED = 0,
152     IMPORTED_FROM_CLOUD = 1,
153 } RelationShipSource;
154 
155 #define MAX_IN_PARAM_LEN 4096
156 
157 #define CHECK_PTR_RETURN_NULL(ptr, paramTag) \
158     do { \
159         if ((ptr) == NULL) { \
160             LOGE("%s is null ptr", (paramTag)); \
161             return NULL; \
162         } \
163     } while (0)
164 
165 #define CHECK_PTR_RETURN_ERROR_CODE(ptr, paramTag) \
166     do { \
167         if ((ptr) == NULL) { \
168             LOGE("%s is null ptr", (paramTag)); \
169             return HC_ERR_NULL_PTR; \
170         } \
171     } while (0)
172 
173 #define CHECK_PTR_RETURN_NONE(ptr, paramTag) \
174         do { \
175             if ((ptr) == NULL) { \
176                 LOGE("%s is null ptr", (paramTag)); \
177                 return; \
178             } \
179         } while (0)
180 
181 #define GOTO_IF_ERR(x) do { \
182         int32_t res = x; \
183         if ((res) != HC_SUCCESS) { \
184             goto ERR; \
185         } \
186     } while (0)
187 
188 #define GOTO_IF_CHECK_NULL(ptr, paramTag) \
189     do { \
190         if ((ptr) == NULL) { \
191             LOGE("%s is null ptr", (paramTag)); \
192             goto ERR; \
193         } \
194     } while (0)
195 
196 #define GOTO_ERR_AND_SET_RET(x, res) do { \
197         res = x; \
198         if ((res) != HC_SUCCESS) { \
199             goto ERR; \
200         } \
201     } while (0)
202 
203 #define RETURN_IF_ERR(x) do { \
204         int32_t res = x; \
205         if ((res) != HC_SUCCESS) { \
206             return res; \
207         } \
208     } while (0)
209 
210 typedef enum {
211     DAS_MODULE = 0x0001,
212     ACCOUNT_MODULE = 0x0010,
213 } EnumModuleType;
214 
215 typedef enum {
216     CONTINUE = 0,
217     IGNORE_MSG = 1,
218     FINISH,
219 } TaskStatus;
220 
221 typedef enum {
222     CODE_NULL = 0,
223     OP_BIND = 1,
224     AUTHENTICATE = 2,
225     ADD_AUTH_INFO = 3,
226     REMOVE_AUTH_INFO = 4,
227     OP_UNBIND = 5,
228     AUTH_KEY_AGREEMENT = 6,
229     REGISTER = 7,
230     SECURE_CLONE = 8,
231 } OperationCode;
232 
233 typedef enum {
234     IMPORT_SELF_CREDENTIAL = 0,
235     DELETE_SELF_CREDENTIAL = 1,
236     QUERY_SELF_CREDENTIAL_INFO = 2,
237     IMPORT_TRUSTED_CREDENTIALS = 3,
238     DELETE_TRUSTED_CREDENTIALS = 4,
239     QUERY_TRUSTED_CREDENTIALS = 5,
240     REQUEST_SIGNATURE = 6,
241 } CredentialCode;
242 
243 #endif
244