• 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_ADD_TYPE "addType"
26 #define FIELD_ADD_ID "addId"
27 #define FIELD_ADD_KEY "addKey"
28 #define FIELD_AUTH_DATA "authData"
29 #define FIELD_AUTH_RETURN "authReturn"
30 #define FIELD_AUTH_ID "authId"
31 #define FIELD_AUTH_PK "authPk"
32 #define FIELD_ADD_AUTH_INFO "addAuthInfo"
33 #define FIELD_ADD_RETURN "addReturn"
34 #define FIELD_APP_ID "appId"
35 #define FIELD_BIND_SESSION_TYPE "bindSessionType"
36 #define FIELD_CHALLENGE "challenge"
37 #define FIELD_CHANNEL_ID "channelId"
38 #define FIELD_CONN_DEVICE_ID "connDeviceId"
39 #define FIELD_CONNECT_PARAMS "connectParams"
40 #define FIELD_CROSS_USER_ID_LIST "crossUserIdList"
41 #define FIELD_CURRENT_VERSION "currentVersion"
42 #define FIELD_DELETE_ID "deleteId"
43 #define FIELD_DELETED_RESULT "deletedResult"
44 #define FIELD_DEVICE_CLOUD_CREDENTIAL "devCloudCred"
45 #define FIELD_DEV_ID "devId"
46 #define FIELD_DEVICES_CREDENTIAL "devicesCredential"
47 #define FIELD_ENC_AUTH_TOKEN "encAuthToken"
48 #define FIELD_ENC_RESULT "encResult"
49 #define FIELD_ENC_DATA "encData"
50 #define FIELD_EPK "epk"
51 #define FIELD_EPK_LEN "epkLen"
52 #define FIELD_EX_AUTH_INFO "exAuthInfo"
53 #define FIELD_EXPIRE_TIME "expireTime"
54 #define FIELD_ERROR_CODE "errorCode"
55 #define FIELD_GROUP_INFO "groupInfo"
56 #define FIELD_GROUP_MANAGERS "groupManagers"
57 #define FIELD_GROUP_NAME "groupName"
58 #define FIELD_GROUP_OP "groupOp"
59 #define FIELD_GROUP_TYPE "groupType"
60 #define FIELD_GROUP_VISIBILITY "groupVisibility"
61 #define FIELD_IS_ADMIN "isAdmin"
62 #define FIELD_IS_ACCOUNT_BIND "isAccountBind"
63 #define FIELD_IS_FORCE_DELETE "isForceDelete"
64 #define FIELD_IS_CREDENTIAL_EXISTS "isCredentialExists"
65 #define FIELD_KCF_DATA "kcfData"
66 #define FIELD_KEY_TYPE "keyType"
67 #define FIELD_MESSAGE "message"
68 #define FIELD_GROUP_ERROR_MSG "groupErrorMsg"
69 #define FIELD_MIN_VERSION "minVersion"
70 #define FIELD_GROUP_AND_MODULE_VERSION "groupAndModuleVersion"
71 #define FIELD_NONCE "nonce"
72 #define FIELD_OPERATION_CODE "operationCode"
73 #define FIELD_OPERATION_PARAMS "operationParams"
74 #define FIELD_OS_ACCOUNT_ID "osAccountId"
75 #define FIELD_OWNER_ID "ownerId"
76 #define FIELD_OWNER_NAME "ownerName"
77 #define FIELD_PERMISSION "Permission"
78 #define FIELD_PAYLOAD "payload"
79 #define FIELD_PEER_DEVICE_ID "peerDeviceId"
80 #define FIELD_PIN_CODE "pinCode"
81 #define FIELD_PUBLIC_KEY "publicKey"
82 #define FIELD_PKG_NAME "pkgName"
83 #define FIELD_SELF_AUTH_ID "selfAuthId"
84 #define FIELD_SELF_DEVICE_ID "selfDeviceId"
85 #define FIELD_REQUEST_ID "requestId"
86 #define FIELD_RECEIVED_DATA "receivedData"
87 #define FIELD_RETURN_CODE "returnCode"
88 #define FIELD_RETURN_DATA "returnData"
89 #define FIELD_RETURN_CODE_MAC "returnCodeMac"
90 #define FIELD_RMV_TYPE "rmvType"
91 #define FIELD_RMV_ID "rmvId"
92 #define FIELD_RMV_AUTH_INFO "rmvAuthInfo"
93 #define FIELD_RMV_RETURN "rmvReturn"
94 #define FIELD_SALT "salt"
95 #define FIELD_ISO_SALT "isoSalt"
96 #define FIELD_SEED "seed"
97 #define FIELD_SELF_TYPE "selfType"
98 #define FIELD_SEND_TO_PEER "sendToPeer"
99 #define FIELD_SEND_TO_SELF "sendToSelf"
100 #define FIELD_SHARED_USER_ID_LIST "sharedUserIdList"
101 #define FIELD_SUPPORT_256_MOD "support256mod"
102 #define FIELD_TOKEN "token"
103 #define FIELD_IS_UUID "uuIdAsDeviceId"
104 #define FIELD_VERSION "version"
105 #define FIELD_MK_AGREE_MSG "mkaMsg"
106 #define FIELD_PEER_ID_FROM_REQUEST "peerIdFromRequest"
107 
108 #define INVALID_MODULE_TYPE (-1)
109 #define GROUP_ERR_MSG 0x8080
110 
111 #define CLIENT 1
112 #define SERVER 0
113 
114 #define CREATE_KEY_PAIR 1
115 #define DELETE_KEY_PAIR 2
116 
117 /* DefaultValue */
118 #define DEFAULT_MEMORY_SIZE 64
119 #define DEFAULT_USER_ID_HASH ""
120 #define DEFAULT_REQUEST_ID 0
121 #define DEFAULT_CHANNEL_ID (-1)
122 #define DEFAULT_EXPIRE_TIME 90
123 #define GROUP_MANAGER_PACKAGE_NAME "com.huawei.devicegroupmanage"
124 #define DEFAULT_RETURN_KEY_LENGTH 32
125 #define ERR_AUTH_FORM 0
126 #define MAX_BUFFER_LEN 1024
127 #define MAX_DATA_BUFFER_SIZE 4096
128 #define MAX_AUTH_ID_LEN 256
129 
130 typedef enum {
131     NO_CHANNEL = 1,
132     SERVICE_CHANNEL = 2,
133     SOFT_BUS = 3,
134 } ChannelType;
135 
136 typedef enum {
137     CREDENTIAL_TYPE_INVALID = 0,
138     CREDENTIAL_TYPE_AUTH_CODE = 0X0001,
139     CREDENTIAL_TYPE_ACCOUNT = 0X0002,
140     CREDENTIAL_TYPE_DEFAULT_CONTROLLER = 0X0003,
141     CREDENTIAL_TYPE_DEVICE_CLOUD = 0X0004,
142     CREDENTIAL_TYPE_TEMP = 0X0008,
143 } CredentialType;
144 
145 #define MAX_IN_PARAM_LEN 4096
146 
147 #define CHECK_PTR_RETURN_NULL(ptr, paramTag) \
148     do { \
149         if ((ptr) == NULL) { \
150             LOGE("%s is null ptr", (paramTag)); \
151             return NULL; \
152         } \
153     } while (0)
154 
155 #define CHECK_PTR_RETURN_ERROR_CODE(ptr, paramTag) \
156     do { \
157         if ((ptr) == NULL) { \
158             LOGE("%s is null ptr", (paramTag)); \
159             return HC_ERR_NULL_PTR; \
160         } \
161     } while (0)
162 
163 #define CHECK_PTR_RETURN_NONE(ptr, paramTag) \
164         do { \
165             if ((ptr) == NULL) { \
166                 LOGE("%s is null ptr", (paramTag)); \
167                 return; \
168             } \
169         } while (0)
170 
171 #define GOTO_IF_ERR(x) do { \
172         int32_t res = x; \
173         if ((res) != HC_SUCCESS) { \
174             goto ERR; \
175         } \
176     } while (0)
177 
178 #define GOTO_ERR_AND_SET_RET(x, res) do { \
179         res = x; \
180         if ((res) != HC_SUCCESS) { \
181             goto ERR; \
182         } \
183     } while (0)
184 
185 #define RETURN_IF_ERR(x) do { \
186         int32_t res = x; \
187         if ((res) != HC_SUCCESS) { \
188             return res; \
189         } \
190     } while (0)
191 
192 typedef enum {
193     DAS_MODULE = 0x0001,
194     ACCOUNT_MODULE = 0x0010,
195 } EnumModuleType;
196 
197 typedef enum {
198     CONTINUE = 0,
199     IGNORE_MSG = 1,
200     FINISH,
201 } TaskStatus;
202 
203 typedef enum {
204     CODE_NULL = 0,
205     OP_BIND = 1,
206     AUTHENTICATE = 2,
207     ADD_AUTH_INFO = 3,
208     REMOVE_AUTH_INFO = 4,
209     OP_UNBIND = 5,
210     AUTH_KEY_AGREEMENT = 6,
211     REGISTER = 7,
212     SECURE_CLONE = 8,
213 } OperationCode;
214 
215 #endif
216