1 /*
2 * Copyright (C) 2024-2025 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 #include "ipc_service_common.h"
16 #include "common_defs.h"
17 #include "device_auth_defines.h"
18 #include "device_auth.h"
19 #include "hc_log.h"
20 #include "ipc_adapt.h"
21 #include "ipc_sdk_defines.h"
22 #ifdef __cplusplus
23 extern "C" {
24 # endif
25 static const int32_t IPC_RESULT_NUM_1 = 1;
26 static const int32_t IPC_RESULT_NUM_2 = 2;
27 static const int32_t IPC_RESULT_NUM_4 = 4;
28 static const char *SERVICE_APP_ID = "deviceauth_service";
29 static DeviceGroupManager g_devGroupMgrMethod = {NULL};
30 static GroupAuthManager g_groupAuthMgrMethod = {NULL};
31 static AccountVerifier g_accountVerifierMethod = {NULL};
32 static LightAccountVerifier g_lightaccountVerifierMethod = {NULL};
33 static DeviceAuthCallback g_bindCbAdt = {NULL};
34 static DeviceAuthCallback g_authCbAdt = {NULL};
35 static DataChangeListener g_listenCbAdt = {NULL};
36 static DeviceAuthCallback g_lightCbAdt = {NULL};
37 #ifdef DEV_AUTH_IS_ENABLE
38 static CredManager g_devCredMgrMethod = {NULL};
39 static CredChangeListener g_credListenCbAdt = {NULL};
40 static CredAuthManager g_credAuthMgrMethod = {NULL};
41 #endif
42
GetAndValSize32Param(const IpcDataInfo * ipcParams,int32_t paramNum,int32_t paramType,uint8_t * param,int32_t * paramSize)43 static inline int32_t GetAndValSize32Param(const IpcDataInfo *ipcParams,
44 int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize)
45 {
46 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize);
47 if ((*paramSize) != sizeof(int32_t) || ret != HC_SUCCESS) {
48 LOGE("get param error, type %" LOG_PUB "d", paramType);
49 return HC_ERR_IPC_BAD_PARAM;
50 }
51 return HC_SUCCESS;
52 }
53
GetAndValSize64Param(const IpcDataInfo * ipcParams,int32_t paramNum,int32_t paramType,uint8_t * param,int32_t * paramSize)54 static inline int32_t GetAndValSize64Param(const IpcDataInfo *ipcParams,
55 int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize)
56 {
57 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize);
58 if ((*paramSize) != sizeof(int64_t) || ret != HC_SUCCESS) {
59 LOGE("get param error, type %" LOG_PUB "d", paramType);
60 return HC_ERR_IPC_BAD_PARAM;
61 }
62 return HC_SUCCESS;
63 }
64
GetAndValSizeCbParam(const IpcDataInfo * ipcParams,int32_t paramNum,int32_t paramType,uint8_t * param,int32_t * paramSize)65 static inline int32_t GetAndValSizeCbParam(const IpcDataInfo *ipcParams,
66 int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize)
67 {
68 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize);
69 if ((*paramSize) != sizeof(DeviceAuthCallback) || ret != HC_SUCCESS) {
70 LOGE("get param error, type %" LOG_PUB "d", paramType);
71 return HC_ERR_IPC_BAD_PARAM;
72 }
73 return HC_SUCCESS;
74 }
75
GetAndValNullParam(const IpcDataInfo * ipcParams,int32_t paramNum,int32_t paramType,uint8_t * param,int32_t * paramSize)76 static inline int32_t GetAndValNullParam(const IpcDataInfo *ipcParams,
77 int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize)
78 {
79 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, NULL);
80 if (param == NULL || ret != HC_SUCCESS) {
81 LOGE("get param error, type %" LOG_PUB "d", paramType);
82 return HC_ERR_IPC_BAD_PARAM;
83 }
84 return HC_SUCCESS;
85 }
86
BindRequestIdWithAppId(const char * data)87 static int32_t BindRequestIdWithAppId(const char *data)
88 {
89 const char *appId = NULL;
90 int32_t ret;
91 int64_t requestId = -1;
92 CJson *dataJson = CreateJsonFromString(data);
93 if (dataJson == NULL) {
94 LOGE("failed to create json from string!");
95 return HC_ERR_JSON_CREATE;
96 }
97 appId = GetStringFromJson(dataJson, FIELD_APP_ID);
98 if (appId == NULL) {
99 LOGE("failed to get appId from json object!");
100 FreeJson(dataJson);
101 return HC_ERROR;
102 }
103 (void)GetInt64FromJson(dataJson, FIELD_REQUEST_ID, &requestId);
104 ret = AddReqIdByAppId(appId, requestId);
105 FreeJson(dataJson);
106 return ret;
107 }
108
IpcServiceGmRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)109 int32_t IpcServiceGmRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
110 {
111 int32_t callRet;
112 int32_t ret;
113 const char *appId = NULL;
114 const DeviceAuthCallback *callback = NULL;
115 int32_t cbObjIdx = -1;
116 int32_t inOutLen;
117 LOGI("starting ...");
118 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
119 if (ret != HC_SUCCESS) {
120 LOGE("IpcServiceGmRegCallback failed, get app id error.");
121 return HC_ERR_IPC_BAD_PARAM;
122 }
123 inOutLen = sizeof(DeviceAuthCallback);
124 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
125 if (ret != HC_SUCCESS) {
126 return ret;
127 }
128 ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_DEV_AUTH);
129 if (ret != HC_SUCCESS) {
130 LOGE("add ipc callback failed");
131 return HC_ERROR;
132 }
133 inOutLen = sizeof(int32_t);
134 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
135 if (ret != HC_SUCCESS) {
136 LOGE("IpcServiceGmRegCallback failed, get cb object error.");
137 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
138 return HC_ERR_IPC_BAD_PARAM;
139 }
140 AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_DEV_AUTH);
141 InitDeviceAuthCbCtx(&g_bindCbAdt, CB_TYPE_DEV_AUTH);
142 callRet = g_devGroupMgrMethod.regCallback(appId, &g_bindCbAdt);
143 if (callRet != HC_SUCCESS) {
144 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
145 }
146 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
147 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
148 return ret;
149 }
150
IpcServiceGmUnRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)151 int32_t IpcServiceGmUnRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
152 {
153 int32_t callRet = HC_SUCCESS;
154 int32_t ret;
155 const char *appId = NULL;
156 LOGI("starting ...");
157 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
158 if (ret != HC_SUCCESS) {
159 LOGE("IpcServiceGmUnRegCallback failed, get app id error.");
160 return HC_ERR_IPC_BAD_PARAM;
161 }
162 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
163 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
164 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
165 return ret;
166 }
167
IpcServiceGmRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)168 int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
169 {
170 int32_t callRet;
171 int32_t ret;
172 const char *appId = NULL;
173 const DataChangeListener *callback = NULL;
174 static int32_t registered = 0;
175 int32_t cbObjIdx = -1;
176 int32_t inOutLen;
177 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
178 if (ret != HC_SUCCESS) {
179 LOGE("IpcServiceGmRegDataChangeListener failed, get app id error.");
180 return HC_ERR_IPC_BAD_PARAM;
181 }
182 inOutLen = sizeof(DataChangeListener);
183 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTENER, (uint8_t *)&callback, &inOutLen);
184 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DataChangeListener))) {
185 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_LISTENER);
186 return HC_ERR_IPC_BAD_PARAM;
187 }
188 ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DataChangeListener), CB_TYPE_LISTENER);
189 if (ret != HC_SUCCESS) {
190 LOGE("IpcServiceGmRegDataChangeListener failed, add ipc callback failed.");
191 return HC_ERROR;
192 }
193 inOutLen = sizeof(int32_t);
194 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
195 if (ret != HC_SUCCESS) {
196 LOGE("IpcServiceGmRegDataChangeListener failed, get cb object error.");
197 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
198 return HC_ERR_IPC_BAD_PARAM;
199 }
200 AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_LISTENER);
201 callRet = HC_SUCCESS;
202 if (registered == 0) {
203 InitDevAuthListenerCbCtx(&g_listenCbAdt);
204 callRet = g_devGroupMgrMethod.regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt);
205 if (callRet == HC_SUCCESS) {
206 registered = 1;
207 } else {
208 DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
209 }
210 }
211 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
212 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
213 return ret;
214 }
215
IpcServiceGmUnRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)216 int32_t IpcServiceGmUnRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
217 {
218 int32_t callRet = HC_SUCCESS;
219 int32_t ret;
220 const char *appId = NULL;
221 LOGI("starting ...");
222 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
223 if (ret != HC_SUCCESS) {
224 LOGE("IpcServiceGmUnRegDataChangeListener failed, get app id error.");
225 return HC_ERR_IPC_BAD_PARAM;
226 }
227 DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
228 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
229 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
230 return ret;
231 }
232
IpcServiceGmCreateGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)233 int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
234 {
235 int32_t callRet;
236 int32_t ret;
237 int32_t osAccountId;
238 int64_t requestId = 0;
239 int32_t inOutLen;
240 const char *createParams = NULL;
241 const char *appId = NULL;
242 LOGI("starting ...");
243 inOutLen = sizeof(int32_t);
244 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
245 if (ret != HC_SUCCESS) {
246 LOGE("IpcServiceGmCreateGroup failed, get os account id error.");
247 return ret;
248 }
249 inOutLen = sizeof(int64_t);
250 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
251 if (ret != HC_SUCCESS) {
252 LOGE("IpcServiceGmCreateGroup failed, get req id error.");
253 return ret;
254 }
255 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
256 if (ret != HC_SUCCESS) {
257 LOGE("IpcServiceGmCreateGroup failed, get app id error.");
258 return HC_ERR_IPC_BAD_PARAM;
259 }
260 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREATE_PARAMS, (uint8_t *)&createParams, NULL);
261 if (ret != HC_SUCCESS) {
262 LOGE("IpcServiceGmCreateGroup failed, get create params error.");
263 return HC_ERR_IPC_BAD_PARAM;
264 }
265 ret = AddReqIdByAppId(appId, requestId);
266 if (ret != 0) {
267 LOGE("bind request id by app id failed");
268 return ret;
269 }
270 callRet = g_devGroupMgrMethod.createGroup(osAccountId, requestId, appId, createParams);
271 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
272 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
273 return ret;
274 }
275
IpcServiceGmDelGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)276 int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
277 {
278 int32_t callRet;
279 int32_t ret;
280 int32_t osAccountId;
281 int64_t requestId = 0;
282 int32_t inOutLen;
283 const char *appId = NULL;
284 const char *delParams = NULL;
285 LOGI("starting ...");
286 inOutLen = sizeof(int32_t);
287 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
288 if (ret != HC_SUCCESS) {
289 LOGE("IpcServiceGmDelGroup failed, get os account id error.");
290 return ret;
291 }
292 inOutLen = sizeof(int64_t);
293 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
294 if (ret != HC_SUCCESS) {
295 LOGE("IpcServiceGmDelGroup failed, get req id error.");
296 return ret;
297 }
298 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
299 if (ret != HC_SUCCESS) {
300 LOGE("IpcServiceGmDelGroup failed, get app id error.");
301 return HC_ERR_IPC_BAD_PARAM;
302 }
303 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
304 if (ret != HC_SUCCESS) {
305 LOGE("IpcServiceGmDelGroup failed, get delete params error.");
306 return HC_ERR_IPC_BAD_PARAM;
307 }
308 ret = AddReqIdByAppId(appId, requestId);
309 if (ret != 0) {
310 LOGE("bind request id by app id failed");
311 return ret;
312 }
313 callRet = g_devGroupMgrMethod.deleteGroup(osAccountId, requestId, appId, delParams);
314 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
315 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
316 return ret;
317 }
318
IpcServiceGmAddMemberToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)319 int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
320 {
321 int32_t callRet;
322 int32_t ret;
323 int32_t inOutLen;
324 int32_t osAccountId;
325 int64_t requestId = 0;
326 const char *addParams = NULL;
327 const char *appId = NULL;
328 LOGI("starting ...");
329 inOutLen = sizeof(int32_t);
330 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
331 if (ret != HC_SUCCESS) {
332 LOGE("IpcServiceGmAddMemberToGroup failed, get os account id error.");
333 return ret;
334 }
335 inOutLen = sizeof(int64_t);
336 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
337 if (ret != HC_SUCCESS) {
338 LOGE("IpcServiceGmAddMemberToGroup failed, get req id error.");
339 return ret;
340 }
341 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
342 if (ret != HC_SUCCESS) {
343 LOGE("IpcServiceGmAddMemberToGroup failed, get add params error.");
344 return HC_ERR_IPC_BAD_PARAM;
345 }
346 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
347 if (ret != HC_SUCCESS) {
348 LOGE("IpcServiceGmAddMemberToGroup failed, get app id error.");
349 return HC_ERR_IPC_BAD_PARAM;
350 }
351 ret = AddReqIdByAppId(appId, requestId);
352 if (ret != HC_SUCCESS) {
353 return ret;
354 }
355 callRet = g_devGroupMgrMethod.addMemberToGroup(osAccountId, requestId, appId, addParams);
356 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
357 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
358 return ret;
359 }
360
IpcServiceGmDelMemberFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)361 int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
362 {
363 int32_t callRet;
364 int32_t ret;
365 int32_t inOutLen;
366 int32_t osAccountId;
367 int64_t requestId = 0;
368 const char *delParams = NULL;
369 const char *appId = NULL;
370 LOGI("starting ...");
371 inOutLen = sizeof(int32_t);
372 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
373 if (ret != HC_SUCCESS) {
374 LOGE("IpcServiceGmDelMemberFromGroup failed, get os account id error.");
375 return ret;
376 }
377 inOutLen = sizeof(int64_t);
378 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
379 if (ret != HC_SUCCESS) {
380 LOGE("IpcServiceGmDelMemberFromGroup failed, get req id error.");
381 return ret;
382 }
383 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
384 if (ret != HC_SUCCESS) {
385 LOGE("IpcServiceGmDelMemberFromGroup failed, get app id error.");
386 return HC_ERR_IPC_BAD_PARAM;
387 }
388 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
389 if (ret != HC_SUCCESS) {
390 LOGE("IpcServiceGmDelMemberFromGroup failed, get del params error.");
391 return HC_ERR_IPC_BAD_PARAM;
392 }
393 ret = AddReqIdByAppId(appId, requestId);
394 if (ret != 0) {
395 LOGE("bind request id by app id failed");
396 return ret;
397 }
398 callRet = g_devGroupMgrMethod.deleteMemberFromGroup(osAccountId, requestId, appId, delParams);
399 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
400 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
401 return ret;
402 }
403
IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)404 int32_t IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
405 {
406 int32_t callRet;
407 int32_t ret;
408 int32_t inOutLen;
409 int32_t osAccountId;
410 const char *addParams = NULL;
411 const char *appId = NULL;
412 LOGI("starting ...");
413 inOutLen = sizeof(int32_t);
414 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
415 if (ret != HC_SUCCESS) {
416 LOGE("IpcServiceGmAddMultiMembersToGroup failed, get os account id error.");
417 return ret;
418 }
419 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
420 if (ret != HC_SUCCESS) {
421 LOGE("IpcServiceGmAddMultiMembersToGroup failed, get add params error.");
422 return HC_ERR_IPC_BAD_PARAM;
423 }
424 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
425 if (ret != HC_SUCCESS) {
426 LOGE("IpcServiceGmAddMultiMembersToGroup failed, get app id error.");
427 return HC_ERR_IPC_BAD_PARAM;
428 }
429 callRet = g_devGroupMgrMethod.addMultiMembersToGroup(osAccountId, appId, addParams);
430 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
431 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
432 return ret;
433 }
434
IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)435 int32_t IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
436 {
437 int32_t callRet;
438 int32_t ret;
439 int32_t inOutLen;
440 int32_t osAccountId;
441 const char *delParams = NULL;
442 const char *appId = NULL;
443 LOGI("starting ...");
444 inOutLen = sizeof(int32_t);
445 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
446 if (ret != HC_SUCCESS) {
447 LOGE("IpcServiceGmDelMultiMembersFromGroup failed, get os account id error.");
448 return ret;
449 }
450 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
451 if (ret != HC_SUCCESS) {
452 LOGE("IpcServiceGmDelMultiMembersFromGroup failed, get app id error.");
453 return ret;
454 }
455 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
456 if (ret != HC_SUCCESS) {
457 LOGE("IpcServiceGmDelMultiMembersFromGroup failed, get del params error.");
458 return HC_ERR_IPC_BAD_PARAM;
459 }
460 callRet = g_devGroupMgrMethod.delMultiMembersFromGroup(osAccountId, appId, delParams);
461 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
462 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
463 return ret;
464 }
465
IpcServiceGmProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)466 int32_t IpcServiceGmProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
467 {
468 int32_t callRet;
469 int32_t ret;
470 int32_t dataLen;
471 int32_t inOutLen;
472 int64_t requestId = 0;
473 const uint8_t *data = NULL;
474 LOGI("starting ...");
475 inOutLen = sizeof(int64_t);
476 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
477 if (ret != HC_SUCCESS) {
478 return ret;
479 }
480 dataLen = 0;
481 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen);
482 if ((dataLen <= 0) || (ret != HC_SUCCESS)) {
483 LOGE("get param error, type %" LOG_PUB "d, data length %" LOG_PUB "d", PARAM_TYPE_COMM_DATA, dataLen);
484 return HC_ERR_IPC_BAD_PARAM;
485 }
486 ret = BindRequestIdWithAppId((const char *)data);
487 if (ret != HC_SUCCESS) {
488 return ret;
489 }
490 callRet = g_devGroupMgrMethod.processData(requestId, data, dataLen);
491 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
492 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
493 return ret;
494 }
495
IpcServiceGmApplyRegisterInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)496 int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
497 {
498 int32_t callRet;
499 int32_t ret;
500 const char *reqJsonStr = NULL;
501 char *registerInfo = NULL;
502 LOGI("starting ...");
503 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, NULL);
504 if (ret != HC_SUCCESS) {
505 return ret;
506 }
507 callRet = g_devGroupMgrMethod.getRegisterInfo(reqJsonStr, ®isterInfo);
508 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
509 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
510 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
511 if (registerInfo != NULL) {
512 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO,
513 (const uint8_t *)registerInfo, HcStrlen(registerInfo) + 1);
514 g_devGroupMgrMethod.destroyInfo(®isterInfo);
515 } else {
516 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO, NULL, 0);
517 }
518 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
519 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
520 }
521
IpcServiceGmCheckAccessToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)522 int32_t IpcServiceGmCheckAccessToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
523 {
524 int32_t callRet;
525 int32_t ret;
526 int32_t inOutLen;
527 int32_t osAccountId;
528 const char *appId = NULL;
529 const char *groupId = NULL;
530 LOGI("starting ...");
531 inOutLen = sizeof(int32_t);
532 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
533 if (ret != HC_SUCCESS) {
534 LOGE("IpcServiceGmCheckAccessToGroup failed, get os account id error.");
535 return ret;
536 }
537 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
538 if (ret != HC_SUCCESS) {
539 LOGE("IpcServiceGmCheckAccessToGroup failed, get app id error.");
540 return ret;
541 }
542 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
543 if (ret != HC_SUCCESS) {
544 LOGE("IpcServiceGmCheckAccessToGroup failed, get group id error.");
545 return ret;
546 }
547 callRet = g_devGroupMgrMethod.checkAccessToGroup(osAccountId, appId, groupId);
548 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
549 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
550 return ret;
551 }
552
IpcServiceGmGetPkInfoList(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)553 int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
554 {
555 int32_t callRet;
556 int32_t ret;
557 int32_t inOutLen;
558 int32_t osAccountId;
559 const char *appId = NULL;
560 const char *queryParams = NULL;
561 char *returnInfoList = NULL;
562 uint32_t returnInfoNum = 0;
563 inOutLen = sizeof(int32_t);
564 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
565 if (ret != HC_SUCCESS) {
566 LOGE("IpcServiceGmGetPkInfoList failed, get os account id error.");
567 return ret;
568 }
569 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
570 if (ret != HC_SUCCESS) {
571 LOGE("IpcServiceGmGetPkInfoList failed, get appId error.");
572 return ret;
573 }
574 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
575 if (ret != HC_SUCCESS) {
576 return ret;
577 }
578 callRet = g_devGroupMgrMethod.getPkInfoList(osAccountId, appId, queryParams, &returnInfoList, &returnInfoNum);
579 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
580 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
581 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
582 if (returnInfoList != NULL) {
583 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList,
584 HcStrlen(returnInfoList) + 1);
585 } else {
586 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
587 }
588 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&returnInfoNum, sizeof(int32_t));
589 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
590 g_devGroupMgrMethod.destroyInfo(&returnInfoList);
591 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
592 }
593
IpcServiceGmGetGroupInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)594 int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
595 {
596 int32_t callRet;
597 int32_t ret;
598 int32_t inOutLen;
599 int32_t osAccountId;
600 const char *appId = NULL;
601 const char *groupId = NULL;
602 char *groupInfo = NULL;
603 LOGI("starting ...");
604 inOutLen = sizeof(int32_t);
605 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
606 if (ret != HC_SUCCESS) {
607 LOGE("IpcServiceGmGetGroupInfoById failed, get os account id error.");
608 return ret;
609 }
610 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
611 if (ret != HC_SUCCESS) {
612 LOGE("IpcServiceGmGetGroupInfoById failed, get app id error.");
613 return ret;
614 }
615 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
616 if (ret != HC_SUCCESS) {
617 LOGE("IpcServiceGmGetGroupInfoById failed, get group id error.");
618 return ret;
619 }
620 callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo);
621 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
622 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
623 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
624 if (groupInfo != NULL) {
625 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, HcStrlen(groupInfo) + 1);
626 g_devGroupMgrMethod.destroyInfo(&groupInfo);
627 } else {
628 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
629 }
630 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
631 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
632 }
633
IpcServiceGmGetGroupInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)634 int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
635 {
636 int32_t callRet;
637 int32_t ret;
638 int32_t inOutLen;
639 int32_t osAccountId;
640 const char *appId = NULL;
641 const char *queryParams = NULL;
642 char *outGroups = NULL;
643 uint32_t groupNum = 0;
644 LOGI("starting ...");
645 inOutLen = sizeof(int32_t);
646 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
647 if (ret != HC_SUCCESS) {
648 LOGE("IpcServiceGmGetGroupInfo failed, get os account id error.");
649 return ret;
650 }
651 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
652 if (ret != HC_SUCCESS) {
653 LOGE("IpcServiceGmGetGroupInfo failed, get app id error.");
654 return ret;
655 }
656 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
657 if (ret != HC_SUCCESS) {
658 LOGE("IpcServiceGmGetGroupInfo failed, query params error.");
659 return ret;
660 }
661 callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum);
662 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
663 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
664 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
665 if (outGroups != NULL) {
666 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
667 } else {
668 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
669 }
670 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
671 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
672 g_devGroupMgrMethod.destroyInfo(&outGroups);
673 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
674 }
675
IpcServiceGmGetJoinedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)676 int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
677 {
678 int32_t callRet;
679 int32_t ret;
680 int32_t groupType = 0;
681 int32_t inOutLen;
682 int32_t osAccountId;
683 const char *appId = NULL;
684 char *outGroups = NULL;
685 uint32_t groupNum = 0;
686 LOGI("starting ...");
687 inOutLen = sizeof(int32_t);
688 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
689 if (ret != HC_SUCCESS) {
690 LOGE("IpcServiceGmGetJoinedGroups failed, get os account id error.");
691 return ret;
692 }
693 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
694 if (ret != HC_SUCCESS) {
695 LOGE("IpcServiceGmGetJoinedGroups failed, get app id error.");
696 return ret;
697 }
698 inOutLen = sizeof(groupType);
699 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)&groupType, &inOutLen);
700 if ((inOutLen != sizeof(groupType)) || (ret != HC_SUCCESS)) {
701 LOGE("IpcServiceGmGetJoinedGroups failed, get group type error.");
702 return HC_ERR_IPC_BAD_PARAM;
703 }
704 callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum);
705 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
706 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
707 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
708 if (outGroups != NULL) {
709 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
710 g_devGroupMgrMethod.destroyInfo(&outGroups);
711 } else {
712 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
713 }
714 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
715 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
716 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
717 }
718
IpcServiceGmGetRelatedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)719 int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
720 {
721 int32_t callRet;
722 int32_t ret;
723 int32_t inOutLen;
724 int32_t osAccountId;
725 const char *appId = NULL;
726 const char *peerUdid = NULL;
727 char *outGroups = NULL;
728 uint32_t groupNum = 0;
729 inOutLen = sizeof(int32_t);
730 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
731 if (ret != HC_SUCCESS) {
732 LOGE("IpcServiceGmGetRelatedGroups failed, get os account id error.");
733 return ret;
734 }
735 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
736 if (ret != HC_SUCCESS) {
737 LOGE("IpcServiceGmGetRelatedGroups failed, get os account id error.");
738 return ret;
739 }
740 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
741 if (ret != HC_SUCCESS) {
742 LOGE("IpcServiceGmGetRelatedGroups failed, get udid error.");
743 return ret;
744 }
745 callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum);
746 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
747 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
748 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
749 if (outGroups != NULL) {
750 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
751 } else {
752 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
753 }
754 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
755 g_devGroupMgrMethod.destroyInfo(&outGroups);
756 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
757 }
758
IpcServiceGmGetDeviceInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)759 int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
760 {
761 int32_t callRet;
762 int32_t ret;
763 int32_t inOutLen;
764 int32_t osAccountId;
765 const char *appId = NULL;
766 const char *peerUdid = NULL;
767 const char *groupId = NULL;
768 char *outDevInfo = NULL;
769 LOGI("starting ...");
770 inOutLen = sizeof(int32_t);
771 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
772 if (ret != HC_SUCCESS) {
773 LOGE("IpcServiceGmGetDeviceInfoById failed, get os account id error.");
774 return ret;
775 }
776 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
777 if (ret != HC_SUCCESS) {
778 LOGE("IpcServiceGmGetDeviceInfoById failed, get app id error.");
779 return ret;
780 }
781 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
782 if (ret != HC_SUCCESS) {
783 LOGE("IpcServiceGmGetDeviceInfoById failed, get udid error.");
784 return ret;
785 }
786 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
787 if (ret != HC_SUCCESS) {
788 return ret;
789 }
790 callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo);
791 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
792 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
793 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
794 if (outDevInfo != NULL) {
795 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO,
796 (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1);
797 g_devGroupMgrMethod.destroyInfo(&outDevInfo);
798 } else {
799 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
800 }
801 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
802 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
803 }
804
IpcServiceGmGetTrustedDevices(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)805 int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
806 {
807 int32_t callRet;
808 int32_t ret;
809 int32_t inOutLen;
810 int32_t osAccountId;
811 const char *appId = NULL;
812 const char *groupId = NULL;
813 char *outDevInfo = NULL;
814 uint32_t outDevNum = 0;
815 inOutLen = sizeof(int32_t);
816 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
817 if (ret != HC_SUCCESS) {
818 LOGE("IpcServiceGmGetTrustedDevices failed, get os account id error.");
819 return ret;
820 }
821 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
822 if (ret != HC_SUCCESS) {
823 LOGE("IpcServiceGmGetTrustedDevices failed, get app id error.");
824 return ret;
825 }
826 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
827 if (ret != HC_SUCCESS) {
828 LOGE("IpcServiceGmGetTrustedDevices failed, get os group id error.");
829 return ret;
830 }
831 callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum);
832 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
833 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
834 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
835 if (outDevInfo != NULL) {
836 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO,
837 (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1);
838 } else {
839 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
840 }
841 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&outDevNum, sizeof(int32_t));
842 g_devGroupMgrMethod.destroyInfo(&outDevInfo);
843 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
844 }
845
IpcServiceAvGetClientSharedKey(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)846 int32_t IpcServiceAvGetClientSharedKey(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
847 {
848 const char *peerPkWithSig = NULL;
849 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_PK_WITH_SIG, (uint8_t *)&peerPkWithSig,
850 NULL);
851 if (ret != HC_SUCCESS) {
852 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_PK_WITH_SIG);
853 return HC_ERR_IPC_BAD_PARAM;
854 }
855 const char *serviceId = NULL;
856 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_SERVICE_ID, (uint8_t *)&serviceId, NULL);
857 if (ret != HC_SUCCESS) {
858 LOGE("IpcServiceAvGetClientSharedKey failed, get service id error.");
859 return HC_ERR_IPC_BAD_PARAM;
860 }
861 DataBuff returnSharedKey = { NULL, 0 };
862 DataBuff returnRandom = { NULL, 0 };
863 int32_t callRet = g_accountVerifierMethod.getClientSharedKey(peerPkWithSig, serviceId, &returnSharedKey,
864 &returnRandom);
865 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
866 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_4,
867 sizeof(int32_t));
868 if (returnSharedKey.data != NULL) {
869 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_VAL, (const uint8_t *)returnSharedKey.data,
870 returnSharedKey.length);
871 uint32_t len = returnSharedKey.length;
872 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_LEN, (const uint8_t *)&len, sizeof(uint32_t));
873 g_accountVerifierMethod.destroyDataBuff(&returnSharedKey);
874 } else {
875 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_VAL, NULL, 0);
876 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_LEN, NULL, 0);
877 }
878 if (returnRandom.data != NULL) {
879 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RANDOM_VAL, (const uint8_t *)returnRandom.data,
880 returnRandom.length);
881 uint32_t len = returnRandom.length;
882 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RANDOM_LEN, (const uint8_t *)&len, sizeof(uint32_t));
883 g_accountVerifierMethod.destroyDataBuff(&returnRandom);
884 } else {
885 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RANDOM_VAL, NULL, 0);
886 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RANDOM_LEN, NULL, 0);
887 }
888 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
889 }
890
IpcServiceAvGetServerSharedKey(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)891 int32_t IpcServiceAvGetServerSharedKey(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
892 {
893 const char *peerPkWithSig = NULL;
894 int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_PK_WITH_SIG, (uint8_t *)&peerPkWithSig,
895 NULL);
896 if (ret != HC_SUCCESS) {
897 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_PK_WITH_SIG);
898 return HC_ERR_IPC_BAD_PARAM;
899 }
900 const char *serviceId = NULL;
901 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_SERVICE_ID, (uint8_t *)&serviceId, NULL);
902 if (ret != HC_SUCCESS) {
903 LOGE("IpcServiceAvGetServerSharedKey failed, get service id error.");
904 return HC_ERR_IPC_BAD_PARAM;
905 }
906 int32_t randomLen = 0;
907 const uint8_t *randomVal = NULL;
908 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_RANDOM, (uint8_t *)&randomVal, &randomLen);
909 if (ret != HC_SUCCESS) {
910 LOGE("IpcServiceAvGetServerSharedKey failed, get random error.");
911 return HC_ERR_IPC_BAD_PARAM;
912 }
913 DataBuff randomBuff = { (uint8_t *)randomVal, (uint32_t)randomLen };
914 DataBuff returnSharedKey = { NULL, 0 };
915 int32_t callRet = g_accountVerifierMethod.getServerSharedKey(peerPkWithSig, serviceId, &randomBuff,
916 &returnSharedKey);
917 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
918 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_2,
919 sizeof(int32_t));
920 if (returnSharedKey.data != NULL) {
921 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_VAL, (const uint8_t *)returnSharedKey.data,
922 returnSharedKey.length);
923 uint32_t len = returnSharedKey.length;
924 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_LEN, (const uint8_t *)&len, sizeof(uint32_t));
925 g_accountVerifierMethod.destroyDataBuff(&returnSharedKey);
926 } else {
927 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_VAL, NULL, 0);
928 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_SHARED_KEY_LEN, NULL, 0);
929 }
930 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
931 }
932
IpcServiceLaStartLightAccountAuth(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)933 int32_t IpcServiceLaStartLightAccountAuth(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
934 {
935 int32_t ret;
936 int32_t inOutLen;
937 int32_t cbObjIdx = -1;
938 int32_t osAccountId;
939 int64_t requestId;
940 const char *serviceId = NULL;
941 const DeviceAuthCallback *laCallBack = NULL;
942 inOutLen = sizeof(int32_t);
943 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
944 if (ret != HC_SUCCESS) {
945 return ret;
946 }
947 inOutLen = sizeof(int64_t);
948 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
949 if (ret != HC_SUCCESS) {
950 return ret;
951 }
952 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_SERVICE_ID, (uint8_t *)&serviceId, NULL);
953 if (ret != HC_SUCCESS) {
954 return ret;
955 }
956 inOutLen = sizeof(DeviceAuthCallback);
957 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&laCallBack, &inOutLen);
958 if (ret != HC_SUCCESS) {
959 return ret;
960 }
961 /* add call back */
962 ret = AddIpcCallBackByReqId(requestId, (const uint8_t *)laCallBack,
963 sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
964 if (ret != HC_SUCCESS) {
965 return ret;
966 }
967 inOutLen = sizeof(int32_t);
968 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
969 if (ret != HC_SUCCESS) {
970 LOGE("IpcServiceLaStartLightAccountAuth failed, get cb object error.");
971 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
972 return ret;
973 }
974 AddIpcCbObjByReqId(requestId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
975 InitDeviceAuthCbCtx(&g_lightCbAdt, CB_TYPE_TMP_DEV_AUTH);
976 ret = g_lightaccountVerifierMethod.startLightAccountAuth(osAccountId, requestId, serviceId, &g_lightCbAdt);
977 if (ret != HC_SUCCESS) {
978 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
979 }
980 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
981 }
982
IpcServiceLaProcessLightAccountAuth(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)983 int32_t IpcServiceLaProcessLightAccountAuth(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
984 {
985 int32_t ret;
986 int32_t inOutLen;
987 int32_t cbObjIdx = -1;
988 int32_t osAccountId;
989 int64_t requestId;
990 const DeviceAuthCallback *laCallBack = NULL;
991 inOutLen = sizeof(int32_t);
992 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
993 if (ret != HC_SUCCESS) {
994 return ret;
995 }
996 inOutLen = sizeof(int64_t);
997 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
998 if (ret != HC_SUCCESS) {
999 return ret;
1000 }
1001 int32_t msgLen = 0;
1002 const uint8_t *msgVal = NULL;
1003 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&msgVal, &msgLen);
1004 if (ret != HC_SUCCESS) {
1005 LOGE("IpcServiceLaProcessLightAccountAuth failed, get msg error.");
1006 return HC_ERR_IPC_BAD_PARAM;
1007 }
1008 DataBuff inMsgBuff = { (uint8_t *)msgVal, (uint32_t)msgLen };
1009 inOutLen = sizeof(DeviceAuthCallback);
1010 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&laCallBack, &inOutLen);
1011 if (ret != HC_SUCCESS) {
1012 return ret;
1013 }
1014 /* add call back */
1015 ret = AddIpcCallBackByReqId(requestId, (const uint8_t *)laCallBack,
1016 sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1017 if (ret != HC_SUCCESS) {
1018 return ret;
1019 }
1020 inOutLen = sizeof(int32_t);
1021 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1022 if (ret != HC_SUCCESS) {
1023 LOGE("IpcServiceLaProcessLightAccountAuth failed, get cb object error.");
1024 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1025 return ret;
1026 }
1027 AddIpcCbObjByReqId(requestId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1028 InitDeviceAuthCbCtx(&g_lightCbAdt, CB_TYPE_TMP_DEV_AUTH);
1029 ret = g_lightaccountVerifierMethod.processLightAccountAuth(osAccountId, requestId, &inMsgBuff, &g_lightCbAdt);
1030 if (ret != HC_SUCCESS) {
1031 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1032 }
1033 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1034 }
1035
IpcServiceGmIsDeviceInGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1036 int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1037 {
1038 int32_t callRet;
1039 int32_t ret;
1040 int32_t inOutLen;
1041 int32_t osAccountId;
1042 bool bRet = false;
1043 const char *appId = NULL;
1044 const char *udid = NULL;
1045 const char *groupId = NULL;
1046 LOGI("starting ...");
1047 inOutLen = sizeof(int32_t);
1048 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1049 if (ret != HC_SUCCESS) {
1050 LOGE("IpcServiceGmIsDeviceInGroup failed, get os account id error.");
1051 return ret;
1052 }
1053 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1054 if (ret != HC_SUCCESS) {
1055 LOGE("IpcServiceGmIsDeviceInGroup failed, get app id error.");
1056 return ret;
1057 }
1058 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&udid, NULL);
1059 if (ret != HC_SUCCESS) {
1060 LOGE("IpcServiceGmIsDeviceInGroup failed, get udid error.");
1061 return ret;
1062 }
1063 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
1064 if (ret != HC_SUCCESS) {
1065 LOGE("IpcServiceGmIsDeviceInGroup failed, get group id error.");
1066 return ret;
1067 }
1068
1069 bRet = g_devGroupMgrMethod.isDeviceInGroup(osAccountId, appId, groupId, udid);
1070 callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
1071 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1072 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1073 return ret;
1074 }
1075
IpcServiceGmCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1076 int32_t IpcServiceGmCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1077 {
1078 int32_t ret;
1079 int64_t requestId = 0;
1080 const char *appId = NULL;
1081
1082 LOGI("starting ...");
1083 int32_t inOutLen = sizeof(int64_t);
1084 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1085 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1086 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_REQID);
1087 return HC_ERR_IPC_BAD_PARAM;
1088 }
1089 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1090 if (ret != HC_SUCCESS) {
1091 return ret;
1092 }
1093
1094 g_devGroupMgrMethod.cancelRequest(requestId, appId);
1095 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1096 return ret;
1097 }
1098
IpcServiceGaProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1099 int32_t IpcServiceGaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1100 {
1101 int32_t callRet;
1102 int32_t ret;
1103 const DeviceAuthCallback *gaCallback = NULL;
1104 int64_t reqId = 0;
1105 uint8_t *data = NULL;
1106 uint32_t dataLen = 0;
1107 int32_t inOutLen;
1108 int32_t cbObjIdx = -1;
1109
1110 LOGI("starting ...");
1111 inOutLen = sizeof(int64_t);
1112 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
1113 if (ret != HC_SUCCESS) {
1114 return ret;
1115 }
1116 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen);
1117 if ((data == NULL) || (dataLen == 0) || (ret != HC_SUCCESS)) {
1118 LOGE("IpcServiceGaProcessData failed, get comm data error.");
1119 return HC_ERR_IPC_BAD_PARAM;
1120 }
1121 inOutLen = sizeof(DeviceAuthCallback);
1122 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen);
1123 if (ret != HC_SUCCESS) {
1124 return ret;
1125 }
1126 /* add call back */
1127 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1128 if (ret != HC_SUCCESS) {
1129 LOGE("add ipc callback failed");
1130 return ret;
1131 }
1132 inOutLen = sizeof(int32_t);
1133 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1134 if (ret != HC_SUCCESS) {
1135 LOGE("IpcServiceGaProcessData failed, get cb object error.");
1136 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1137 return HC_ERR_IPC_BAD_PARAM;
1138 }
1139 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1140 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1141 callRet = g_groupAuthMgrMethod.processData(reqId, data, dataLen, &g_authCbAdt);
1142 if (callRet != HC_SUCCESS) {
1143 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1144 }
1145 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1146 }
1147
IpcServiceGaAuthDevice(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1148 int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1149 {
1150 int32_t ret;
1151 DeviceAuthCallback *gaCallback = NULL;
1152 int32_t osAccountId;
1153 int64_t reqId = 0;
1154 const char *authParams = NULL;
1155 int32_t inOutLen;
1156 int32_t cbObjIdx = -1;
1157
1158 inOutLen = sizeof(int32_t);
1159 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1160 if (ret != HC_SUCCESS) {
1161 return ret;
1162 }
1163 inOutLen = sizeof(int64_t);
1164 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
1165 if (ret != HC_SUCCESS) {
1166 return ret;
1167 }
1168 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1169 if (ret != HC_SUCCESS) {
1170 return ret;
1171 }
1172 inOutLen = sizeof(DeviceAuthCallback);
1173 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen);
1174 if (ret != HC_SUCCESS) {
1175 return ret;
1176 }
1177
1178 /* add call back */
1179 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1180 if (ret != HC_SUCCESS) {
1181 return ret;
1182 }
1183 inOutLen = sizeof(int32_t);
1184 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1185 if (ret != HC_SUCCESS) {
1186 LOGE("IpcServiceGaAuthDevice failed, get cb object error.");
1187 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1188 return ret;
1189 }
1190 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1191 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1192 ret = g_groupAuthMgrMethod.authDevice(osAccountId, reqId, authParams, &g_authCbAdt);
1193 if (ret != HC_SUCCESS) {
1194 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1195 }
1196 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1197 }
1198
IpcServiceGaCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1199 int32_t IpcServiceGaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1200 {
1201 int32_t ret;
1202 int64_t requestId = 0;
1203 const char *appId = NULL;
1204
1205 LOGI("starting ...");
1206 int32_t inOutLen = sizeof(int64_t);
1207 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1208 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1209 LOGE("IpcServiceGaCancelRequest failed, get req id error.");
1210 return HC_ERR_IPC_BAD_PARAM;
1211 }
1212 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1213 if (ret != HC_SUCCESS) {
1214 return ret;
1215 }
1216
1217 g_groupAuthMgrMethod.cancelRequest(requestId, appId);
1218 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1219 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1220 return ret;
1221 }
1222
IpcServiceGaGetRealInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1223 int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1224 {
1225 int32_t callRet;
1226 int32_t ret;
1227 int32_t osAccountId;
1228 const char *pseudonymId = NULL;
1229
1230 LOGI("starting ...");
1231 int32_t inOutLen = sizeof(int64_t);
1232 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1233 if (ret != HC_SUCCESS) {
1234 LOGE("IpcServiceGaGetRealInfo failed, get os account id error.");
1235 return ret;
1236 }
1237 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_PSEUDONYM_ID, (uint8_t *)&pseudonymId, NULL);
1238 if (ret != HC_SUCCESS) {
1239 return ret;
1240 }
1241
1242 char *realInfo = NULL;
1243 callRet = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo);
1244 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1245 if ((realInfo != NULL) && (callRet == HC_SUCCESS)) {
1246 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo,
1247 HcStrlen(realInfo) + 1);
1248 HcFree(realInfo);
1249 } else {
1250 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1251 }
1252 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1253 return ret;
1254 }
1255
IpcServiceGaGetPseudonymId(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1256 int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1257 {
1258 int32_t callRet;
1259 int32_t ret;
1260 int32_t osAccountId;
1261 const char *indexKey = NULL;
1262 LOGI("starting ...");
1263 int32_t inOutLen = sizeof(int64_t);
1264 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1265 if (ret != HC_SUCCESS) {
1266 LOGE("IpcServiceGaGetRealInfo failed, get os account id error.");
1267 return ret;
1268 }
1269 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_INDEX_KEY, (uint8_t *)&indexKey, NULL);
1270 if (ret != HC_SUCCESS) {
1271 return ret;
1272 }
1273
1274 char *pseudonymId = NULL;
1275 callRet = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId);
1276 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1277 if ((pseudonymId != NULL) && (callRet == HC_SUCCESS)) {
1278 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId,
1279 HcStrlen(pseudonymId) + 1);
1280 HcFree(pseudonymId);
1281 } else {
1282 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1283 }
1284 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1285 return ret;
1286 }
1287
IpcServiceDaProcessCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1288 int32_t IpcServiceDaProcessCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1289 {
1290 int32_t callRet;
1291 int32_t ret;
1292 int32_t operationCode = 0;
1293 const char *reqJsonStr = NULL;
1294 char *returnData = NULL;
1295 LOGI("starting ...");
1296 int32_t inOutLen = sizeof(int32_t);
1297 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OPCODE, (uint8_t *)&operationCode, &inOutLen);
1298 if (ret != HC_SUCCESS) {
1299 LOGE("IpcServiceDaProcessCredential failed, get op code error.");
1300 return ret;
1301 }
1302 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, NULL);
1303 if (ret != HC_SUCCESS) {
1304 return ret;
1305 }
1306 callRet = ProcessCredential(operationCode, reqJsonStr, &returnData);
1307 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1308 if (returnData != NULL && callRet == HC_SUCCESS) {
1309 ret += IpcEncodeCallReply(
1310 outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnData, HcStrlen(returnData) + 1);
1311 HcFree(returnData);
1312 } else {
1313 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1314 }
1315 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1316 return ret;
1317 }
1318
IpcServiceDaProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1319 int32_t IpcServiceDaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1320 {
1321 int32_t callRet;
1322 int32_t ret;
1323 const DeviceAuthCallback *callback = NULL;
1324 int64_t authReqId = 0;
1325 const char *authParams = NULL;
1326 int32_t inOutLen;
1327 int32_t cbObjIdx = -1;
1328 LOGI("starting ...");
1329 inOutLen = sizeof(int64_t);
1330 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
1331 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) {
1332 LOGE("IpcServiceDaProcessData failed, get req id error.");
1333 return HC_ERR_IPC_BAD_PARAM;
1334 }
1335 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1336 if (ret != HC_SUCCESS) {
1337 return ret;
1338 }
1339 inOutLen = sizeof(DeviceAuthCallback);
1340 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
1341 if (ret != HC_SUCCESS) {
1342 return ret;
1343 }
1344 ret = AddIpcCallBackByReqId(
1345 authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1346 if (ret != HC_SUCCESS) {
1347 return ret;
1348 }
1349 inOutLen = sizeof(int32_t);
1350 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1351 if (ret != HC_SUCCESS) {
1352 LOGE("IpcServiceDaProcessData failed, get cb object error.");
1353 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1354 return HC_ERR_IPC_BAD_PARAM;
1355 }
1356 AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1357 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1358 callRet = ProcessAuthDevice(authReqId, authParams, &g_authCbAdt);
1359 if (callRet != HC_SUCCESS) {
1360 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1361 }
1362 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1363 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1364 return ret;
1365 }
1366
IpcServiceDaAuthDevice(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1367 int32_t IpcServiceDaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1368 {
1369 int32_t callRet;
1370 int32_t ret;
1371 DeviceAuthCallback *callback = NULL;
1372 int64_t authReqId = 0;
1373 const char *authParams = NULL;
1374 int32_t inOutLen;
1375 int32_t cbObjIdx = -1;
1376 LOGI("starting ...");
1377 inOutLen = sizeof(int64_t);
1378 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
1379 if (ret != HC_SUCCESS) {
1380 LOGE("IpcServiceDaAuthDevice failed, get req id error.");
1381 return ret;
1382 }
1383 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1384 if (ret != HC_SUCCESS) {
1385 LOGE("IpcServiceDaAuthDevice failed, get auth params error.");
1386 return ret;
1387 }
1388 inOutLen = sizeof(DeviceAuthCallback);
1389 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
1390 if (ret != HC_SUCCESS) {
1391 return ret;
1392 }
1393 ret = AddIpcCallBackByReqId(
1394 authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1395 if (ret != HC_SUCCESS) {
1396 LOGE("add ipc callback failed");
1397 return ret;
1398 }
1399 inOutLen = sizeof(int32_t);
1400 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1401 if (ret != HC_SUCCESS) {
1402 LOGE("IpcServiceDaAuthDevice failed, get cb object error.");
1403 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1404 return HC_ERR_IPC_BAD_PARAM;
1405 }
1406 AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1407 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1408 callRet = StartAuthDevice(authReqId, authParams, &g_authCbAdt);
1409 if (callRet != HC_SUCCESS) {
1410 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1411 }
1412 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1413 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1414 return ret;
1415 }
1416
IpcServiceDaCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1417 int32_t IpcServiceDaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1418 {
1419 int32_t ret;
1420 int64_t requestId = 0;
1421 const char *authParams = NULL;
1422 LOGI("starting ...");
1423 int32_t inOutLen = sizeof(int64_t);
1424 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1425 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1426 LOGE("IpcServiceDaCancelRequest failed, get req id error.");
1427 return HC_ERR_IPC_BAD_PARAM;
1428 }
1429 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1430 if (ret != HC_SUCCESS) {
1431 return ret;
1432 }
1433 ret = CancelAuthRequest(requestId, authParams);
1434 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1435 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1436 LOGI("process done, ipc ret %" LOG_PUB "d", ret);
1437 return ret;
1438 }
1439
1440 #ifdef DEV_AUTH_IS_ENABLE
IpcServiceCmAddCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1441 int32_t IpcServiceCmAddCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1442 {
1443 int32_t callRet;
1444 int32_t ret;
1445 int32_t osAccountId;
1446 int32_t inOutLen;
1447 const char *requestParams = NULL;
1448 char *credId = NULL;
1449
1450 LOGI("starting ...");
1451 inOutLen = sizeof(int32_t);
1452 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1453 if (ret != HC_SUCCESS) {
1454 LOGE("IpcServiceCmAddCredential failed, get os account id error.");
1455 return ret;
1456 }
1457 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQUEST_PARAMS, (uint8_t *)&requestParams, NULL);
1458 if (ret != HC_SUCCESS) {
1459 LOGE("IpcServiceCmAddCredential failed, get request params error.");
1460 return ret;
1461 }
1462 callRet = g_devCredMgrMethod.addCredential(osAccountId, requestParams, &credId);
1463 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1464 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1465 if (credId != NULL) {
1466 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_ID, (const uint8_t *)credId, HcStrlen(credId) + 1);
1467 } else {
1468 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_ID, NULL, 0);
1469 }
1470 g_devCredMgrMethod.destroyInfo(&credId);
1471 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1472 return ret;
1473 }
1474
IpcServiceCmRegCredChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1475 int32_t IpcServiceCmRegCredChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1476 {
1477 int32_t callRet;
1478 int32_t ret;
1479 const char *appId = NULL;
1480 const CredChangeListener *listener = NULL;
1481 static int32_t registered = 0;
1482 int32_t cbObjIdx = -1;
1483 int32_t inOutLen;
1484 LOGI("starting ...");
1485 inOutLen = sizeof(int32_t);
1486 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1487 if (ret != HC_SUCCESS) {
1488 LOGE("IpcServiceCmRegCredChangeListener failed, get app id error.");
1489 return HC_ERR_IPC_BAD_PARAM;
1490 }
1491 inOutLen = sizeof(CredChangeListener);
1492 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTENER, (uint8_t *)&listener, &inOutLen);
1493 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(CredChangeListener))) {
1494 LOGE("IpcServiceCmRegCredChangeListener failed, get listener error.");
1495 return HC_ERR_IPC_BAD_PARAM;
1496 }
1497 ret = AddIpcCallBackByAppId(appId, (const uint8_t *)listener, sizeof(CredChangeListener), CB_TYPE_CRED_LISTENER);
1498 if (ret != HC_SUCCESS) {
1499 LOGE("add ipc listener failed");
1500 return HC_ERROR;
1501 }
1502 inOutLen = sizeof(int32_t);
1503 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1504 if (ret != HC_SUCCESS) {
1505 LOGE("IpcServiceCmRegCredChangeListener failed, get cb object error.");
1506 DelIpcCallBackByAppId(appId, CB_TYPE_CRED_LISTENER);
1507 return HC_ERR_IPC_BAD_PARAM;
1508 }
1509 AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_CRED_LISTENER);
1510 callRet = HC_SUCCESS;
1511 if (registered == 0) {
1512 InitDevAuthCredListenerCbCtx(&g_credListenCbAdt);
1513 callRet = g_devCredMgrMethod.registerChangeListener(SERVICE_APP_ID, &g_credListenCbAdt);
1514 if (callRet == HC_SUCCESS) {
1515 registered = 1;
1516 } else {
1517 DelIpcCallBackByAppId(appId, CB_TYPE_CRED_LISTENER);
1518 }
1519 }
1520 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1521 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1522 return ret;
1523 }
1524
IpcServiceCmUnRegCredChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1525 int32_t IpcServiceCmUnRegCredChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1526 {
1527 int32_t callRet = HC_SUCCESS;
1528 int32_t ret;
1529 const char *appId = NULL;
1530 LOGI("starting ...");
1531 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1532 if (ret != HC_SUCCESS) {
1533 LOGE("IpcServiceCmUnRegCredChangeListener failed, get app id error.");
1534 return HC_ERR_IPC_BAD_PARAM;
1535 }
1536 DelIpcCallBackByAppId(appId, CB_TYPE_CRED_LISTENER);
1537 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1538 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1539 return ret;
1540 }
1541
1542
IpcServiceCmExportCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1543 int32_t IpcServiceCmExportCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1544 {
1545 int32_t callRet;
1546 int32_t ret;
1547 int32_t osAccountId;
1548 int32_t inOutLen;
1549 const char *credId = NULL;
1550 char *returnCredVal = NULL;
1551 LOGI("starting ...");
1552 inOutLen = sizeof(int32_t);
1553 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1554 if (ret != HC_SUCCESS) {
1555 LOGE("IpcServiceCmExportCredential failed, get os account id error.");
1556 return ret;
1557 }
1558 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_CRED_ID, (uint8_t *)&credId, NULL);
1559 if (ret != HC_SUCCESS) {
1560 LOGE("IpcServiceCmExportCredential failed, get cred id error.");
1561 return ret;
1562 }
1563 callRet = g_devCredMgrMethod.exportCredential(osAccountId, credId, &returnCredVal);
1564 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1565 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1566 if (returnCredVal != NULL) {
1567 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_VAL, (const uint8_t *)returnCredVal,
1568 HcStrlen(returnCredVal) + 1);
1569 } else {
1570 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_VAL, NULL, 0);
1571 }
1572 g_devCredMgrMethod.destroyInfo(&returnCredVal);
1573 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1574 return ret;
1575 }
1576
IpcServiceCmQueryCredentialByParams(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1577 int32_t IpcServiceCmQueryCredentialByParams(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1578 {
1579 int32_t callRet;
1580 int32_t ret;
1581 int32_t osAccountId;
1582 int32_t inOutLen;
1583 const char *requestParams = NULL;
1584 char *returnCredList = NULL;
1585 LOGI("starting ...");
1586 inOutLen = sizeof(int32_t);
1587 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1588 if (ret != HC_SUCCESS) {
1589 LOGE("IpcServiceCmQueryCredentialByParams failed, get os account id error.");
1590 return ret;
1591 }
1592 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&requestParams, NULL);
1593 if (ret != HC_SUCCESS) {
1594 LOGE("IpcServiceCmQueryCredentialByParams failed, get query params error.");
1595 return ret;
1596 }
1597 callRet = g_devCredMgrMethod.queryCredentialByParams(osAccountId, requestParams, &returnCredList);
1598 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1599 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1600 if (returnCredList != NULL) {
1601 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, (const uint8_t *)returnCredList,
1602 HcStrlen(returnCredList) + 1);
1603 } else {
1604 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, NULL, 0);
1605 }
1606 g_devCredMgrMethod.destroyInfo(&returnCredList);
1607 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1608 return ret;
1609 }
1610
IpcServiceCmQueryCredentialByCredId(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1611 int32_t IpcServiceCmQueryCredentialByCredId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1612 {
1613 int32_t callRet;
1614 int32_t ret;
1615 int32_t osAccountId;
1616 int32_t inOutLen;
1617 const char *credId = NULL;
1618 char *returnCredInfo = NULL;
1619 LOGI("starting ...");
1620 inOutLen = sizeof(int32_t);
1621 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1622 if (ret != HC_SUCCESS) {
1623 LOGE("IpcServiceCmQueryCredentialByCredId failed, get os account id error.");
1624 return ret;
1625 }
1626 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_CRED_ID, (uint8_t *)&credId, NULL);
1627 if (ret != HC_SUCCESS) {
1628 LOGE("IpcServiceCmQueryCredentialByCredId failed, get cred id error.");
1629 return ret;
1630 }
1631 callRet = g_devCredMgrMethod.queryCredInfoByCredId(osAccountId, credId, &returnCredInfo);
1632 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1633 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1634 if (returnCredInfo != NULL) {
1635 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO, (const uint8_t *)returnCredInfo,
1636 HcStrlen(returnCredInfo) + 1);
1637 } else {
1638 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO, NULL, 0);
1639 }
1640 g_devCredMgrMethod.destroyInfo(&returnCredInfo);
1641 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1642 return ret;
1643 }
1644
IpcServiceCmDeleteCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1645 int32_t IpcServiceCmDeleteCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1646 {
1647 int32_t callRet;
1648 int32_t ret;
1649 int32_t osAccountId;
1650 int32_t inOutLen;
1651 const char *credId = NULL;
1652 LOGI("starting ...");
1653 inOutLen = sizeof(int32_t);
1654 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1655 if (ret != HC_SUCCESS) {
1656 LOGE("IpcServiceCmDeleteCredential failed, get os account id error.");
1657 return ret;
1658 }
1659 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_CRED_ID, (uint8_t *)&credId, NULL);
1660 if (ret != HC_SUCCESS) {
1661 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_CRED_ID);
1662 return ret;
1663 }
1664 callRet = g_devCredMgrMethod.deleteCredential(osAccountId, credId);
1665 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1666 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1667 return ret;
1668 }
1669
IpcServiceCmUpdateCredInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1670 int32_t IpcServiceCmUpdateCredInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1671 {
1672 int32_t callRet;
1673 int32_t ret;
1674 int32_t osAccountId;
1675 int32_t inOutLen;
1676 const char *credId = NULL;
1677 const char *requestParams = NULL;
1678 LOGI("starting ...");
1679 inOutLen = sizeof(int32_t);
1680 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1681 if (ret != HC_SUCCESS) {
1682 LOGE("IpcServiceCmUpdateCredInfo failed, get os account id error.");
1683 return ret;
1684 }
1685 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_CRED_ID, (uint8_t *)&credId, NULL);
1686 if (ret != HC_SUCCESS) {
1687 LOGE("IpcServiceCmUpdateCredInfo failed, get cred id error.");
1688 return ret;
1689 }
1690 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQUEST_PARAMS, (uint8_t *)&requestParams, NULL);
1691 if (ret != HC_SUCCESS) {
1692 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_REQUEST_PARAMS);
1693 return ret;
1694 }
1695 callRet = g_devCredMgrMethod.updateCredInfo(osAccountId, credId, requestParams);
1696 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1697 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1698 return ret;
1699 }
1700
IpcServiceCmAgreeCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1701 int32_t IpcServiceCmAgreeCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1702 {
1703 int32_t callRet;
1704 int32_t ret;
1705 int32_t osAccountId;
1706 int32_t inOutLen;
1707 const char *selfCredId = NULL;
1708 const char *requestParams = NULL;
1709 char *agreeCredId = NULL;
1710 LOGI("starting ...");
1711 inOutLen = sizeof(int32_t);
1712 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1713 if (ret != HC_SUCCESS) {
1714 LOGE("IpcServiceCmAgreeCredential failed, get os account id error.");
1715 return ret;
1716 }
1717 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_CRED_ID, (uint8_t *)&selfCredId, NULL);
1718 if (ret != HC_SUCCESS) {
1719 LOGE("IpcServiceCmAgreeCredential failed, get os cred id error.");
1720 return ret;
1721 }
1722 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQUEST_PARAMS, (uint8_t *)&requestParams, NULL);
1723 if (ret != HC_SUCCESS) {
1724 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_REQUEST_PARAMS);
1725 return ret;
1726 }
1727 callRet = g_devCredMgrMethod.agreeCredential(osAccountId, selfCredId, requestParams, &agreeCredId);
1728 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1729 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1730 if (agreeCredId != NULL) {
1731 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_ID, (const uint8_t *)agreeCredId,
1732 HcStrlen(agreeCredId) + 1);
1733 } else {
1734 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_ID, NULL, 0);
1735 }
1736 g_devCredMgrMethod.destroyInfo(&agreeCredId);
1737 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1738 return ret;
1739 }
1740
IpcServiceCmDelCredByParams(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1741 int32_t IpcServiceCmDelCredByParams(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1742 {
1743 int32_t callRet;
1744 int32_t ret;
1745 int32_t osAccountId;
1746 int32_t inOutLen;
1747 const char *requestParams = NULL;
1748 char *returnCredList = NULL;
1749 LOGI("starting ...");
1750 inOutLen = sizeof(int32_t);
1751 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1752 if (ret != HC_SUCCESS) {
1753 LOGE("IpcServiceCmDelCredByParams failed, get os account id error.");
1754 return ret;
1755 }
1756 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQUEST_PARAMS, (uint8_t *)&requestParams, NULL);
1757 if (ret != HC_SUCCESS) {
1758 LOGE("IpcServiceCmDelCredByParams failed, get request params error.");
1759 return ret;
1760 }
1761 callRet = g_devCredMgrMethod.deleteCredByParams(osAccountId, requestParams, &returnCredList);
1762 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1763 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1764 if (returnCredList != NULL) {
1765 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, (const uint8_t *)returnCredList,
1766 HcStrlen(returnCredList) + 1);
1767 } else {
1768 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, NULL, 0);
1769 }
1770 g_devCredMgrMethod.destroyInfo(&returnCredList);
1771 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1772 return ret;
1773 }
1774
IpcServiceCmBatchUpdateCredentials(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1775 int32_t IpcServiceCmBatchUpdateCredentials(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1776 {
1777 int32_t callRet;
1778 int32_t ret;
1779 int32_t osAccountId;
1780 int32_t inOutLen;
1781 const char *requestParams = NULL;
1782 char *returnCredList = NULL;
1783 LOGI("starting ...");
1784 inOutLen = sizeof(int32_t);
1785 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1786 if (ret != HC_SUCCESS) {
1787 LOGE("IpcServiceCmBatchUpdateCredentials failed, get os account id error.");
1788 return ret;
1789 }
1790 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQUEST_PARAMS, (uint8_t *)&requestParams, NULL);
1791 if (ret != HC_SUCCESS) {
1792 LOGE("get param error, type %" LOG_PUB "d", PARAM_TYPE_REQUEST_PARAMS);
1793 return ret;
1794 }
1795 callRet = g_devCredMgrMethod.batchUpdateCredentials(osAccountId, requestParams, &returnCredList);
1796 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1797 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
1798 if (returnCredList != NULL) {
1799 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, (const uint8_t *)returnCredList,
1800 HcStrlen(returnCredList) + 1);
1801 } else {
1802 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_CRED_INFO_LIST, NULL, 0);
1803 }
1804 g_devCredMgrMethod.destroyInfo(&returnCredList);
1805 LOGI("process done, call ret %" LOG_PUB "d, ipc ret %" LOG_PUB "d", callRet, ret);
1806 return ret;
1807 }
1808
IpcServiceCaAuthCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1809 int32_t IpcServiceCaAuthCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1810 {
1811 int32_t ret;
1812 DeviceAuthCallback *caCallback = NULL;
1813 int32_t osAccountId;
1814 int64_t reqId = 0;
1815 const char *authParams = NULL;
1816 int32_t inOutLen;
1817 int32_t cbObjIdx = -1;
1818 inOutLen = sizeof(int32_t);
1819 ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1820 if (ret != HC_SUCCESS) {
1821 LOGE("IpcServiceCaAuthCredential failed, get os account id error.");
1822 return ret;
1823 }
1824 inOutLen = sizeof(int64_t);
1825 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
1826 if (ret != HC_SUCCESS) {
1827 LOGE("IpcServiceCaAuthCredential failed, get req id error.");
1828 return ret;
1829 }
1830 ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1831 if (ret != HC_SUCCESS) {
1832 return ret;
1833 }
1834 inOutLen = sizeof(DeviceAuthCallback);
1835 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&caCallback, &inOutLen);
1836 if (ret != HC_SUCCESS) {
1837 return ret;
1838 }
1839 /* add call back */
1840 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)caCallback, sizeof(DeviceAuthCallback), CB_TYPE_CRED_DEV_AUTH);
1841 if (ret != HC_SUCCESS) {
1842 return ret;
1843 }
1844 inOutLen = sizeof(int32_t);
1845 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1846 if (ret != HC_SUCCESS) {
1847 LOGE("IpcServiceCaAuthCredential failed, get cb object error.");
1848 DelIpcCallBackByReqId(reqId, CB_TYPE_CRED_DEV_AUTH, true);
1849 return ret;
1850 }
1851 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_CRED_DEV_AUTH);
1852 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_CRED_DEV_AUTH);
1853 ret = g_credAuthMgrMethod.authCredential(osAccountId, reqId, authParams, &g_authCbAdt);
1854 if (ret != HC_SUCCESS) {
1855 DelIpcCallBackByReqId(reqId, CB_TYPE_CRED_DEV_AUTH, true);
1856 }
1857 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1858 }
1859
1860
IpcServiceCaProcessCredData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1861 int32_t IpcServiceCaProcessCredData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1862 {
1863 int32_t callRet;
1864 int32_t ret;
1865 const DeviceAuthCallback *caCallback = NULL;
1866 int64_t reqId = 0;
1867 uint8_t *data = NULL;
1868 uint32_t dataLen = 0;
1869 int32_t inOutLen;
1870 int32_t cbObjIdx = -1;
1871 LOGI("starting ...");
1872 inOutLen = sizeof(int64_t);
1873 ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
1874 if (ret != HC_SUCCESS) {
1875 return ret;
1876 }
1877 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen);
1878 if ((data == NULL) || (dataLen == 0) || (ret != HC_SUCCESS)) {
1879 LOGE("IpcServiceCaProcessCredData failed, get comm data error.");
1880 return HC_ERR_IPC_BAD_PARAM;
1881 }
1882 inOutLen = sizeof(DeviceAuthCallback);
1883 ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&caCallback, &inOutLen);
1884 if (ret != HC_SUCCESS) {
1885 return ret;
1886 }
1887 /* add call back */
1888 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)caCallback, sizeof(DeviceAuthCallback), CB_TYPE_CRED_DEV_AUTH);
1889 if (ret != HC_SUCCESS) {
1890 LOGE("add ipc callback failed");
1891 return ret;
1892 }
1893 inOutLen = sizeof(int32_t);
1894 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1895 if (ret != HC_SUCCESS) {
1896 LOGE("IpcServiceCaProcessCredData failed, get cb object error.");
1897 DelIpcCallBackByReqId(reqId, CB_TYPE_CRED_DEV_AUTH, true);
1898 return HC_ERR_IPC_BAD_PARAM;
1899 }
1900 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_CRED_DEV_AUTH);
1901 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_CRED_DEV_AUTH);
1902 callRet = g_credAuthMgrMethod.processCredData(reqId, data, dataLen, &g_authCbAdt);
1903 if (callRet != HC_SUCCESS) {
1904 DelIpcCallBackByReqId(reqId, CB_TYPE_CRED_DEV_AUTH, true);
1905 }
1906 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1907 }
1908
ISIpcInit(void)1909 static int32_t ISIpcInit(void)
1910 {
1911 const CredManager *cmInst = NULL;
1912 const CredAuthManager *caInst = NULL;
1913 cmInst = GetCredMgrInstance();
1914 caInst = GetCredAuthInstance();
1915 if (cmInst == NULL || caInst == NULL) {
1916 DeInitIpcCallBackList();
1917 LOGE("MainInit, GetGmInstance failed");
1918 return HC_ERROR;
1919 }
1920 g_devCredMgrMethod = (CredManager)(*cmInst);
1921 g_credAuthMgrMethod = (CredAuthManager)(*caInst);
1922 InitDevAuthCredListenerCbCtx(&g_credListenCbAdt);
1923 int32_t ret = cmInst->registerChangeListener(SERVICE_APP_ID, &g_credListenCbAdt);
1924 if (ret != HC_SUCCESS) {
1925 DeInitIpcCallBackList();
1926 LOGE("MainInit, register ipc cred listener failed, ret %" LOG_PUB "d", ret);
1927 return HC_ERROR;
1928 }
1929 return HC_SUCCESS;
1930 }
1931 #endif
1932
MainRescInit(void)1933 int32_t MainRescInit(void)
1934 {
1935 int32_t ret;
1936 LOGI("starting ...");
1937 const DeviceGroupManager *gmInst = NULL;
1938 const GroupAuthManager *gaInst = NULL;
1939 const AccountVerifier *avInst = NULL;
1940 const LightAccountVerifier *lvInst = NULL;
1941 ret = InitIpcCallBackList();
1942 if (ret != HC_SUCCESS) {
1943 return ret;
1944 }
1945 gmInst = GetGmInstance();
1946 gaInst = GetGaInstance();
1947 avInst = GetAccountVerifierInstance();
1948 lvInst = GetLightAccountVerifierInstance();
1949 if ((gmInst == NULL) || (gaInst == NULL) || (avInst == NULL) || (lvInst == NULL)) {
1950 DeInitIpcCallBackList();
1951 LOGE("MainInit, GetGmInstance failed");
1952 return HC_ERROR;
1953 }
1954 g_devGroupMgrMethod = (DeviceGroupManager)(*gmInst);
1955 g_groupAuthMgrMethod = (GroupAuthManager)(*gaInst);
1956 g_accountVerifierMethod = (AccountVerifier)(*avInst);
1957 g_lightaccountVerifierMethod = (LightAccountVerifier)(*lvInst);
1958 InitDevAuthListenerCbCtx(&g_listenCbAdt);
1959 ret = gmInst->regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt);
1960 if (ret != HC_SUCCESS) {
1961 DeInitIpcCallBackList();
1962 LOGE("MainInit, register ipc listener failed, ret %" LOG_PUB "d", ret);
1963 return HC_ERROR;
1964 }
1965 #ifdef DEV_AUTH_IS_ENABLE
1966 ret = ISIpcInit();
1967 if (ret != HC_SUCCESS) {
1968 DeInitIpcCallBackList();
1969 LOGE("IS ipc init failed.");
1970 return ret;
1971 }
1972 #endif
1973 LOGI("process done");
1974 return HC_SUCCESS;
1975 }
1976
DeMainRescInit(void)1977 void DeMainRescInit(void)
1978 {
1979 if (g_devGroupMgrMethod.unRegDataChangeListener != NULL) {
1980 (void)g_devGroupMgrMethod.unRegDataChangeListener(SERVICE_APP_ID);
1981 }
1982 #ifdef DEV_AUTH_IS_ENABLE
1983 if (g_devCredMgrMethod.unregisterChangeListener != NULL) {
1984 (void)g_devCredMgrMethod.unregisterChangeListener(SERVICE_APP_ID);
1985 }
1986 #endif
1987 DeInitIpcCallBackList();
1988 }
1989
1990 #ifdef __cplusplus
1991 }
1992 #endif