1 /*
2 * Copyright (C) 2021-2023 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 #include "ipc_service.h"
17
18 #include "common_defs.h"
19 #include "device_auth_defines.h"
20 #include "device_auth.h"
21 #include "hc_condition.h"
22 #include "hc_log.h"
23 #include "hc_thread.h"
24 #include "ipc_adapt.h"
25 #include "ipc_sdk.h"
26 #include "securec.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 static const int32_t IPC_RESULT_NUM_1 = 1;
33 static const int32_t IPC_RESULT_NUM_2 = 2;
34 static const char *SERVICE_APP_ID = "deviceauth_service";
35 static DeviceGroupManager g_devGroupMgrMethod = {NULL};
36 static GroupAuthManager g_groupAuthMgrMethod = {NULL};
37 static DeviceAuthCallback g_bindCbAdt = {NULL};
38 static DeviceAuthCallback g_authCbAdt = {NULL};
39 static DataChangeListener g_listenCbAdt = {NULL};
40
BindRequestIdWithAppId(const char * data)41 static int32_t BindRequestIdWithAppId(const char *data)
42 {
43 const char *appId = NULL;
44 int32_t ret;
45 int64_t requestId = -1;
46 CJson *dataJson = CreateJsonFromString(data);
47 if (dataJson == NULL) {
48 LOGE("failed to create json from string!");
49 return HC_ERR_JSON_CREATE;
50 }
51
52 appId = GetStringFromJson(dataJson, FIELD_APP_ID);
53 if (appId == NULL) {
54 LOGE("failed to get appId from json object!");
55 FreeJson(dataJson);
56 return HC_ERROR;
57 }
58 (void)GetInt64FromJson(dataJson, FIELD_REQUEST_ID, &requestId);
59 ret = AddReqIdByAppId(appId, requestId);
60 FreeJson(dataJson);
61 return ret;
62 }
63
IpcServiceGmRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)64 static int32_t IpcServiceGmRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
65 {
66 int32_t callRet;
67 int32_t ret;
68 const char *appId = NULL;
69 const DeviceAuthCallback *callback = NULL;
70 int32_t cbObjIdx = -1;
71 int32_t inOutLen;
72
73 LOGI("starting ...");
74 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
75 if (ret != HC_SUCCESS) {
76 LOGE("get param error, type %d", PARAM_TYPE_APPID);
77 return HC_ERR_IPC_BAD_PARAM;
78 }
79
80 inOutLen = sizeof(DeviceAuthCallback);
81 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
82 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DeviceAuthCallback))) {
83 LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
84 return HC_ERR_IPC_BAD_PARAM;
85 }
86 ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_DEV_AUTH);
87 if (ret != HC_SUCCESS) {
88 LOGE("add ipc callback failed");
89 return HC_ERROR;
90 }
91
92 inOutLen = sizeof(int32_t);
93 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
94 if (ret != HC_SUCCESS) {
95 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
96 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
97 return HC_ERR_IPC_BAD_PARAM;
98 }
99 AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_DEV_AUTH);
100 InitDeviceAuthCbCtx(&g_bindCbAdt, CB_TYPE_DEV_AUTH);
101 callRet = g_devGroupMgrMethod.regCallback(appId, &g_bindCbAdt);
102 if (callRet != HC_SUCCESS) {
103 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
104 }
105 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
106 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
107 return ret;
108 }
109
IpcServiceGmUnRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)110 static int32_t IpcServiceGmUnRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
111 {
112 int32_t callRet = HC_SUCCESS;
113 int32_t ret;
114 const char *appId = NULL;
115
116 LOGI("starting ...");
117 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
118 if (ret != HC_SUCCESS) {
119 LOGE("get param error, type %d", PARAM_TYPE_APPID);
120 return HC_ERR_IPC_BAD_PARAM;
121 }
122
123 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
124 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
125 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
126 return ret;
127 }
128
IpcServiceGmRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)129 static int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
130 {
131 int32_t callRet;
132 int32_t ret;
133 const char *appId = NULL;
134 const DataChangeListener *callback = NULL;
135 static int32_t registered = 0;
136 int32_t cbObjIdx = -1;
137 int32_t inOutLen;
138
139 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
140 if (ret != HC_SUCCESS) {
141 LOGE("get param error, type %d", PARAM_TYPE_APPID);
142 return HC_ERR_IPC_BAD_PARAM;
143 }
144
145 inOutLen = sizeof(DataChangeListener);
146 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTERNER, (uint8_t *)&callback, &inOutLen);
147 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DataChangeListener))) {
148 LOGE("get param error, type %d", PARAM_TYPE_LISTERNER);
149 return HC_ERR_IPC_BAD_PARAM;
150 }
151
152 ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DataChangeListener), CB_TYPE_LISTENER);
153 if (ret != HC_SUCCESS) {
154 LOGE("add ipc callback failed");
155 return HC_ERROR;
156 }
157
158 inOutLen = sizeof(int32_t);
159 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
160 if (ret != HC_SUCCESS) {
161 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
162 DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
163 return HC_ERR_IPC_BAD_PARAM;
164 }
165 AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_LISTENER);
166
167 callRet = HC_SUCCESS;
168 if (registered == 0) {
169 InitDevAuthListenerCbCtx(&g_listenCbAdt);
170 callRet = g_devGroupMgrMethod.regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt);
171 if (callRet == HC_SUCCESS) {
172 registered = 1;
173 } else {
174 DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
175 }
176 }
177 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
178 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
179 return ret;
180 }
181
IpcServiceGmUnRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)182 static int32_t IpcServiceGmUnRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
183 {
184 int32_t callRet = HC_SUCCESS;
185 int32_t ret;
186 const char *appId = NULL;
187
188 LOGI("starting ...");
189 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
190 if (ret != HC_SUCCESS) {
191 LOGE("get param error, type %d", PARAM_TYPE_APPID);
192 return HC_ERR_IPC_BAD_PARAM;
193 }
194 DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
195 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
196 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
197 return ret;
198 }
199
IpcServiceGmCreateGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)200 static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
201 {
202 int32_t callRet;
203 int32_t ret;
204 int32_t osAccountId;
205 int64_t requestId = 0;
206 int32_t inOutLen;
207 const char *createParams = NULL;
208 const char *appId = NULL;
209
210 LOGI("starting ...");
211 inOutLen = sizeof(int32_t);
212 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
213 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
214 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
215 return HC_ERR_IPC_BAD_PARAM;
216 }
217 inOutLen = sizeof(int64_t);
218 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
219 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
220 LOGE("get param error, type %d", PARAM_TYPE_REQID);
221 return HC_ERR_IPC_BAD_PARAM;
222 }
223 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
224 if (ret != HC_SUCCESS) {
225 LOGE("get param error, type %d", PARAM_TYPE_APPID);
226 return HC_ERR_IPC_BAD_PARAM;
227 }
228 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREATE_PARAMS, (uint8_t *)&createParams, NULL);
229 if (ret != HC_SUCCESS) {
230 LOGE("get param error, type %d", PARAM_TYPE_CREATE_PARAMS);
231 return HC_ERR_IPC_BAD_PARAM;
232 }
233 ret = AddReqIdByAppId(appId, requestId);
234 if (ret != 0) {
235 LOGE("bind request id by app id failed");
236 return ret;
237 }
238 callRet = g_devGroupMgrMethod.createGroup(osAccountId, requestId, appId, createParams);
239 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
240 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
241 return ret;
242 }
243
IpcServiceGmDelGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)244 static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
245 {
246 int32_t callRet;
247 int32_t ret;
248 int32_t osAccountId;
249 int64_t requestId = 0;
250 int32_t inOutLen;
251 const char *appId = NULL;
252 const char *delParams = NULL;
253
254 LOGI("starting ...");
255 inOutLen = sizeof(int32_t);
256 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
257 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
258 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
259 return HC_ERR_IPC_BAD_PARAM;
260 }
261 inOutLen = sizeof(int64_t);
262 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
263 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
264 LOGE("get param error, type %d", PARAM_TYPE_REQID);
265 return HC_ERR_IPC_BAD_PARAM;
266 }
267 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
268 if (ret != HC_SUCCESS) {
269 LOGE("get param error, type %d", PARAM_TYPE_APPID);
270 return HC_ERR_IPC_BAD_PARAM;
271 }
272 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
273 if (ret != HC_SUCCESS) {
274 LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
275 return HC_ERR_IPC_BAD_PARAM;
276 }
277 ret = AddReqIdByAppId(appId, requestId);
278 if (ret != 0) {
279 LOGE("bind request id by app id failed");
280 return ret;
281 }
282 callRet = g_devGroupMgrMethod.deleteGroup(osAccountId, requestId, appId, delParams);
283 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
284 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
285 return ret;
286 }
287
IpcServiceGmAddMemberToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)288 static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
289 {
290 int32_t callRet;
291 int32_t ret;
292 int32_t inOutLen;
293 int32_t osAccountId;
294 int64_t requestId = 0;
295 const char *addParams = NULL;
296 const char *appId = NULL;
297
298 LOGI("starting ...");
299 inOutLen = sizeof(int32_t);
300 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
301 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
302 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
303 return HC_ERR_IPC_BAD_PARAM;
304 }
305 inOutLen = sizeof(int64_t);
306 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
307 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
308 LOGE("get param error, type %d", PARAM_TYPE_REQID);
309 return HC_ERR_IPC_BAD_PARAM;
310 }
311 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
312 if (ret != HC_SUCCESS) {
313 LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS);
314 return HC_ERR_IPC_BAD_PARAM;
315 }
316 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
317 if (ret != HC_SUCCESS) {
318 LOGE("get param error, type %d", PARAM_TYPE_APPID);
319 return HC_ERR_IPC_BAD_PARAM;
320 }
321 ret = AddReqIdByAppId(appId, requestId);
322 if (ret != HC_SUCCESS) {
323 return ret;
324 }
325 callRet = g_devGroupMgrMethod.addMemberToGroup(osAccountId, requestId, appId, addParams);
326 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
327 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
328 return ret;
329 }
330
IpcServiceGmDelMemberFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)331 static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
332 {
333 int32_t callRet;
334 int32_t ret;
335 int32_t inOutLen;
336 int32_t osAccountId;
337 int64_t requestId = 0;
338 const char *delParams = NULL;
339 const char *appId = NULL;
340
341 LOGI("starting ...");
342 inOutLen = sizeof(int32_t);
343 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
344 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
345 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
346 return HC_ERR_IPC_BAD_PARAM;
347 }
348 inOutLen = sizeof(int64_t);
349 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
350 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
351 LOGE("get param error, type %d", PARAM_TYPE_REQID);
352 return HC_ERR_IPC_BAD_PARAM;
353 }
354 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
355 if (ret != HC_SUCCESS) {
356 LOGE("get param error, type %d", PARAM_TYPE_APPID);
357 return HC_ERR_IPC_BAD_PARAM;
358 }
359 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
360 if (ret != HC_SUCCESS) {
361 LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
362 return HC_ERR_IPC_BAD_PARAM;
363 }
364 ret = AddReqIdByAppId(appId, requestId);
365 if (ret != 0) {
366 LOGE("bind request id by app id failed");
367 return ret;
368 }
369 callRet = g_devGroupMgrMethod.deleteMemberFromGroup(osAccountId, requestId, appId, delParams);
370 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
371 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
372 return ret;
373 }
374
IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)375 static int32_t IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
376 {
377 int32_t callRet;
378 int32_t ret;
379 int32_t inOutLen;
380 int32_t osAccountId;
381 const char *addParams = NULL;
382 const char *appId = NULL;
383
384 LOGI("starting ...");
385 inOutLen = sizeof(int32_t);
386 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
387 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
388 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
389 return HC_ERR_IPC_BAD_PARAM;
390 }
391 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
392 if (ret != HC_SUCCESS) {
393 LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS);
394 return HC_ERR_IPC_BAD_PARAM;
395 }
396 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
397 if (ret != HC_SUCCESS) {
398 LOGE("get param error, type %d", PARAM_TYPE_APPID);
399 return HC_ERR_IPC_BAD_PARAM;
400 }
401 callRet = g_devGroupMgrMethod.addMultiMembersToGroup(osAccountId, appId, addParams);
402 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
403 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
404 return ret;
405 }
406
IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)407 static int32_t IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
408 {
409 int32_t callRet;
410 int32_t ret;
411 int32_t inOutLen;
412 int32_t osAccountId;
413 const char *delParams = NULL;
414 const char *appId = NULL;
415
416 LOGI("starting ...");
417 inOutLen = sizeof(int32_t);
418 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
419 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
420 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
421 return HC_ERR_IPC_BAD_PARAM;
422 }
423 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
424 if (ret != HC_SUCCESS) {
425 LOGE("get param error, type %d", PARAM_TYPE_APPID);
426 return ret;
427 }
428 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
429 if (ret != HC_SUCCESS) {
430 LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
431 return HC_ERR_IPC_BAD_PARAM;
432 }
433 callRet = g_devGroupMgrMethod.delMultiMembersFromGroup(osAccountId, appId, delParams);
434 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
435 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
436 return ret;
437 }
438
IpcServiceGmProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)439 static int32_t IpcServiceGmProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
440 {
441 int32_t callRet;
442 int32_t ret;
443 int32_t dataLen;
444 int32_t inOutLen;
445 int64_t requestId = 0;
446 const uint8_t *data = NULL;
447
448 LOGI("starting ...");
449 inOutLen = sizeof(int64_t);
450 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
451 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
452 LOGE("get param error, type %d", PARAM_TYPE_REQID);
453 return HC_ERR_IPC_BAD_PARAM;
454 }
455
456 dataLen = 0;
457 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen);
458 if ((dataLen <= 0) || (ret != HC_SUCCESS)) {
459 LOGE("get param error, type %d, data length %d", PARAM_TYPE_COMM_DATA, dataLen);
460 return HC_ERR_IPC_BAD_PARAM;
461 }
462 ret = BindRequestIdWithAppId((const char *)data);
463 if (ret != HC_SUCCESS) {
464 return ret;
465 }
466 callRet = g_devGroupMgrMethod.processData(requestId, data, dataLen);
467 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
468 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
469 return ret;
470 }
471
IpcServiceGmApplyRegisterInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)472 static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
473 {
474 int32_t callRet;
475 int32_t ret;
476 const char *reqJsonStr = NULL;
477 char *registerInfo = NULL;
478
479 LOGI("starting ...");
480 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, NULL);
481 if ((reqJsonStr == NULL) || (ret != HC_SUCCESS)) {
482 LOGE("get param error, type %d", PARAM_TYPE_REQ_JSON);
483 return HC_ERR_IPC_BAD_PARAM;
484 }
485 callRet = g_devGroupMgrMethod.getRegisterInfo(reqJsonStr, ®isterInfo);
486 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
487 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
488 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
489 if (registerInfo != NULL) {
490 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO,
491 (const uint8_t *)registerInfo, HcStrlen(registerInfo) + 1);
492 g_devGroupMgrMethod.destroyInfo(®isterInfo);
493 } else {
494 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO, NULL, 0);
495 }
496 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
497 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
498 }
499
IpcServiceGmCheckAccessToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)500 static int32_t IpcServiceGmCheckAccessToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
501 {
502 int32_t callRet;
503 int32_t ret;
504 int32_t inOutLen;
505 int32_t osAccountId;
506 const char *appId = NULL;
507 const char *groupId = NULL;
508
509 LOGI("starting ...");
510 inOutLen = sizeof(int32_t);
511 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
512 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
513 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
514 return HC_ERR_IPC_BAD_PARAM;
515 }
516 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
517 if ((appId == NULL) || (ret != HC_SUCCESS)) {
518 LOGE("get param error, type %d", PARAM_TYPE_APPID);
519 return HC_ERR_IPC_BAD_PARAM;
520 }
521 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
522 if ((groupId == NULL) || (ret != HC_SUCCESS)) {
523 LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
524 return HC_ERR_IPC_BAD_PARAM;
525 }
526
527 callRet = g_devGroupMgrMethod.checkAccessToGroup(osAccountId, appId, groupId);
528 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
529 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
530 return ret;
531 }
532
IpcServiceGmGetPkInfoList(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)533 static int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
534 {
535 int32_t callRet;
536 int32_t ret;
537 int32_t inOutLen;
538 int32_t osAccountId;
539 const char *appId = NULL;
540 const char *queryParams = NULL;
541 char *returnInfoList = NULL;
542 uint32_t returnInfoNum = 0;
543
544 inOutLen = sizeof(int32_t);
545 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
546 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
547 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
548 return HC_ERR_IPC_BAD_PARAM;
549 }
550 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
551 if ((appId == NULL) || (ret != HC_SUCCESS)) {
552 LOGE("get param error, type %d", PARAM_TYPE_APPID);
553 return HC_ERR_IPC_BAD_PARAM;
554 }
555 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
556 if ((queryParams == NULL) || (ret != HC_SUCCESS)) {
557 LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
558 return HC_ERR_IPC_BAD_PARAM;
559 }
560
561 callRet = g_devGroupMgrMethod.getPkInfoList(osAccountId, appId, queryParams, &returnInfoList, &returnInfoNum);
562 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
563 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
564 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
565 if (returnInfoList != NULL) {
566 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList,
567 HcStrlen(returnInfoList) + 1);
568 } else {
569 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
570 }
571 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&returnInfoNum, sizeof(int32_t));
572 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
573 g_devGroupMgrMethod.destroyInfo(&returnInfoList);
574 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
575 }
576
IpcServiceGmGetGroupInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)577 static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
578 {
579 int32_t callRet;
580 int32_t ret;
581 int32_t inOutLen;
582 int32_t osAccountId;
583 const char *appId = NULL;
584 const char *groupId = NULL;
585 char *groupInfo = NULL;
586
587 LOGI("starting ...");
588 inOutLen = sizeof(int32_t);
589 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
590 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
591 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
592 return HC_ERR_IPC_BAD_PARAM;
593 }
594 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
595 if ((appId == NULL) || (ret != HC_SUCCESS)) {
596 LOGE("get param error, type %d", PARAM_TYPE_APPID);
597 return HC_ERR_IPC_BAD_PARAM;
598 }
599 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
600 if ((groupId == NULL) || (ret != HC_SUCCESS)) {
601 LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
602 return HC_ERR_IPC_BAD_PARAM;
603 }
604
605 callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo);
606 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
607 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
608 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
609 if (groupInfo != NULL) {
610 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, HcStrlen(groupInfo) + 1);
611 g_devGroupMgrMethod.destroyInfo(&groupInfo);
612 } else {
613 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
614 }
615 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
616 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
617 }
618
IpcServiceGmGetGroupInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)619 static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
620 {
621 int32_t callRet;
622 int32_t ret;
623 int32_t inOutLen;
624 int32_t osAccountId;
625 const char *appId = NULL;
626 const char *queryParams = NULL;
627 char *outGroups = NULL;
628 uint32_t groupNum = 0;
629
630 LOGI("starting ...");
631 inOutLen = sizeof(int32_t);
632 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
633 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
634 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
635 return HC_ERR_IPC_BAD_PARAM;
636 }
637 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
638 if ((appId == NULL) || (ret != HC_SUCCESS)) {
639 LOGE("get param error, type %d", PARAM_TYPE_APPID);
640 return HC_ERR_IPC_BAD_PARAM;
641 }
642 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
643 if ((queryParams == NULL) || (ret != HC_SUCCESS)) {
644 LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
645 return HC_ERR_IPC_BAD_PARAM;
646 }
647
648 callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum);
649 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
650 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
651 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
652 if (outGroups != NULL) {
653 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
654 } else {
655 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
656 }
657 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
658 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
659 g_devGroupMgrMethod.destroyInfo(&outGroups);
660 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
661 }
662
IpcServiceGmGetJoinedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)663 static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
664 {
665 int32_t callRet;
666 int32_t ret;
667 int32_t groupType = 0;
668 int32_t inOutLen;
669 int32_t osAccountId;
670 const char *appId = NULL;
671 char *outGroups = NULL;
672 uint32_t groupNum = 0;
673
674 LOGI("starting ...");
675 inOutLen = sizeof(int32_t);
676 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
677 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
678 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
679 return HC_ERR_IPC_BAD_PARAM;
680 }
681 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
682 if ((appId == NULL) || (ret != HC_SUCCESS)) {
683 LOGE("get param error, type %d", PARAM_TYPE_APPID);
684 return HC_ERR_IPC_BAD_PARAM;
685 }
686 inOutLen = sizeof(groupType);
687 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)&groupType, &inOutLen);
688 if ((inOutLen != sizeof(groupType)) || (ret != HC_SUCCESS)) {
689 LOGE("get param error, type %d", PARAM_TYPE_GROUP_TYPE);
690 return HC_ERR_IPC_BAD_PARAM;
691 }
692
693 callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum);
694 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
695 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
696 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
697 if (outGroups != NULL) {
698 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
699 g_devGroupMgrMethod.destroyInfo(&outGroups);
700 } else {
701 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
702 }
703 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
704 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
705 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
706 }
707
IpcServiceGmGetRelatedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)708 static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
709 {
710 int32_t callRet;
711 int32_t ret;
712 int32_t inOutLen;
713 int32_t osAccountId;
714 const char *appId = NULL;
715 const char *peerUdid = NULL;
716 char *outGroups = NULL;
717 uint32_t groupNum = 0;
718
719 inOutLen = sizeof(int32_t);
720 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
721 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
722 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
723 return HC_ERR_IPC_BAD_PARAM;
724 }
725 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
726 if ((appId == NULL) || (ret != HC_SUCCESS)) {
727 LOGE("get param error, type %d", PARAM_TYPE_APPID);
728 return HC_ERR_IPC_BAD_PARAM;
729 }
730 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
731 if ((peerUdid == NULL) || (ret != HC_SUCCESS)) {
732 LOGE("get param error, type %d", PARAM_TYPE_UDID);
733 return HC_ERR_IPC_BAD_PARAM;
734 }
735
736 callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum);
737 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
738 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
739 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
740 if (outGroups != NULL) {
741 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1);
742 } else {
743 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
744 }
745 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
746 g_devGroupMgrMethod.destroyInfo(&outGroups);
747 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
748 }
749
IpcServiceGmGetDeviceInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)750 static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
751 {
752 int32_t callRet;
753 int32_t ret;
754 int32_t inOutLen;
755 int32_t osAccountId;
756 const char *appId = NULL;
757 const char *peerUdid = NULL;
758 const char *groupId = NULL;
759 char *outDevInfo = NULL;
760
761 LOGI("starting ...");
762 inOutLen = sizeof(int32_t);
763 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
764 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
765 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
766 return HC_ERR_IPC_BAD_PARAM;
767 }
768 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
769 if ((appId == NULL) || (ret != HC_SUCCESS)) {
770 LOGE("get param error, type %d", PARAM_TYPE_APPID);
771 return HC_ERR_IPC_BAD_PARAM;
772 }
773 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
774 if ((peerUdid == NULL) || (ret != HC_SUCCESS)) {
775 LOGE("get param error, type %d", PARAM_TYPE_UDID);
776 return HC_ERR_IPC_BAD_PARAM;
777 }
778 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
779 if ((groupId == NULL) || (ret != HC_SUCCESS)) {
780 LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
781 return HC_ERR_IPC_BAD_PARAM;
782 }
783
784 callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo);
785 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
786 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
787 (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
788 if (outDevInfo != NULL) {
789 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO,
790 (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1);
791 g_devGroupMgrMethod.destroyInfo(&outDevInfo);
792 } else {
793 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
794 }
795 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
796 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
797 }
798
IpcServiceGmGetTrustedDevices(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)799 static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
800 {
801 int32_t callRet;
802 int32_t ret;
803 int32_t inOutLen;
804 int32_t osAccountId;
805 const char *appId = NULL;
806 const char *groupId = NULL;
807 char *outDevInfo = NULL;
808 uint32_t outDevNum = 0;
809
810 inOutLen = sizeof(int32_t);
811 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
812 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
813 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
814 return HC_ERR_IPC_BAD_PARAM;
815 }
816 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
817 if ((appId == NULL) || (ret != HC_SUCCESS)) {
818 LOGE("get param error, type %d", PARAM_TYPE_APPID);
819 return HC_ERR_IPC_BAD_PARAM;
820 }
821 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
822 if ((groupId == NULL) || (ret != HC_SUCCESS)) {
823 LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
824 return HC_ERR_IPC_BAD_PARAM;
825 }
826
827 callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum);
828 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
829 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM,
830 (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
831 if (outDevInfo != NULL) {
832 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO,
833 (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1);
834 } else {
835 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
836 }
837 ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&outDevNum, sizeof(int32_t));
838 g_devGroupMgrMethod.destroyInfo(&outDevInfo);
839 return (ret == HC_SUCCESS) ? ret : HC_ERROR;
840 }
841
IpcServiceGmIsDeviceInGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)842 static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
843 {
844 int32_t callRet;
845 int32_t ret;
846 int32_t inOutLen;
847 int32_t osAccountId;
848 bool bRet = false;
849 const char *appId = NULL;
850 const char *udid = NULL;
851 const char *groupId = NULL;
852
853 LOGI("starting ...");
854 inOutLen = sizeof(int32_t);
855 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
856 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
857 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
858 return HC_ERR_IPC_BAD_PARAM;
859 }
860 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
861 if ((appId == NULL) || (ret != HC_SUCCESS)) {
862 LOGE("get param error, type %d", PARAM_TYPE_APPID);
863 return HC_ERR_IPC_BAD_PARAM;
864 }
865 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&udid, NULL);
866 if ((udid == NULL) || (ret != HC_SUCCESS)) {
867 LOGE("get param error, type %d", PARAM_TYPE_UDID);
868 return HC_ERR_IPC_BAD_PARAM;
869 }
870 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
871 if ((groupId == NULL) || (ret != HC_SUCCESS)) {
872 LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
873 return HC_ERR_IPC_BAD_PARAM;
874 }
875
876 bRet = g_devGroupMgrMethod.isDeviceInGroup(osAccountId, appId, groupId, udid);
877 callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
878 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
879 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
880 return ret;
881 }
882
IpcServiceGmCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)883 static int32_t IpcServiceGmCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
884 {
885 int32_t ret;
886 int64_t requestId = 0;
887 const char *appId = NULL;
888
889 LOGI("starting ...");
890 int32_t inOutLen = sizeof(int64_t);
891 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
892 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
893 LOGE("get param error, type %d", PARAM_TYPE_REQID);
894 return HC_ERR_IPC_BAD_PARAM;
895 }
896 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
897 if ((appId == NULL) || (ret != HC_SUCCESS)) {
898 LOGE("get param error, type %d", PARAM_TYPE_APPID);
899 return HC_ERR_IPC_BAD_PARAM;
900 }
901
902 g_devGroupMgrMethod.cancelRequest(requestId, appId);
903 LOGI("process done, ipc ret %d", ret);
904 return ret;
905 }
906
IpcServiceGaProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)907 static int32_t IpcServiceGaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
908 {
909 int32_t callRet;
910 int32_t ret;
911 const DeviceAuthCallback *gaCallback = NULL;
912 int64_t reqId = 0;
913 uint8_t *data = NULL;
914 uint32_t dataLen = 0;
915 int32_t inOutLen;
916 int32_t cbObjIdx = -1;
917
918 LOGI("starting ...");
919 inOutLen = sizeof(int64_t);
920 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
921 if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
922 LOGE("get param error, type %d", PARAM_TYPE_REQID);
923 return HC_ERR_IPC_BAD_PARAM;
924 }
925 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen);
926 if ((data == NULL) || (dataLen == 0) || (ret != HC_SUCCESS)) {
927 LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
928 return HC_ERR_IPC_BAD_PARAM;
929 }
930 inOutLen = sizeof(DeviceAuthCallback);
931 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen);
932 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DeviceAuthCallback))) {
933 LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
934 return HC_ERR_IPC_BAD_PARAM;
935 }
936 /* add call back */
937 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
938 if (ret != HC_SUCCESS) {
939 LOGE("add ipc callback failed");
940 return ret;
941 }
942 inOutLen = sizeof(int32_t);
943 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
944 if (ret != HC_SUCCESS) {
945 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
946 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
947 return HC_ERR_IPC_BAD_PARAM;
948 }
949 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
950 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
951 callRet = g_groupAuthMgrMethod.processData(reqId, data, dataLen, &g_authCbAdt);
952 if (callRet != HC_SUCCESS) {
953 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
954 }
955 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
956 }
957
IpcServiceGaAuthDevice(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)958 static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
959 {
960 int32_t ret;
961 DeviceAuthCallback *gaCallback = NULL;
962 int32_t osAccountId;
963 int64_t reqId = 0;
964 const char *authParams = NULL;
965 int32_t inOutLen;
966 int32_t cbObjIdx = -1;
967
968 inOutLen = sizeof(int32_t);
969 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
970 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
971 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
972 return HC_ERR_IPC_BAD_PARAM;
973 }
974 inOutLen = sizeof(int64_t);
975 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen);
976 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
977 LOGE("get param error, type %d", PARAM_TYPE_REQID);
978 return HC_ERR_IPC_BAD_PARAM;
979 }
980 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
981 if ((ret != HC_SUCCESS) || (authParams == NULL)) {
982 LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
983 return HC_ERR_IPC_BAD_PARAM;
984 }
985 inOutLen = sizeof(DeviceAuthCallback);
986 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen);
987 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DeviceAuthCallback))) {
988 LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
989 return HC_ERR_IPC_BAD_PARAM;
990 }
991
992 /* add call back */
993 ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
994 if (ret != HC_SUCCESS) {
995 return ret;
996 }
997 inOutLen = sizeof(int32_t);
998 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
999 if (ret != HC_SUCCESS) {
1000 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
1001 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1002 return ret;
1003 }
1004 AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1005 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1006 ret = g_groupAuthMgrMethod.authDevice(osAccountId, reqId, authParams, &g_authCbAdt);
1007 if (ret != HC_SUCCESS) {
1008 DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true);
1009 }
1010 return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1011 }
1012
IpcServiceGaCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1013 static int32_t IpcServiceGaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1014 {
1015 int32_t ret;
1016 int64_t requestId = 0;
1017 const char *appId = NULL;
1018
1019 LOGI("starting ...");
1020 int32_t inOutLen = sizeof(int64_t);
1021 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1022 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1023 LOGE("get param error, type %d", PARAM_TYPE_REQID);
1024 return HC_ERR_IPC_BAD_PARAM;
1025 }
1026 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1027 if ((appId == NULL) || (ret != HC_SUCCESS)) {
1028 LOGE("get param error, type %d", PARAM_TYPE_APPID);
1029 return HC_ERR_IPC_BAD_PARAM;
1030 }
1031
1032 g_groupAuthMgrMethod.cancelRequest(requestId, appId);
1033 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1034 LOGI("process done, ipc ret %d", ret);
1035 return ret;
1036 }
1037
IpcServiceGaGetRealInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1038 static int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1039 {
1040 int32_t ret;
1041 int32_t osAccountId;
1042 const char *pseudonymId = NULL;
1043
1044 LOGI("starting ...");
1045 int32_t inOutLen = sizeof(int64_t);
1046 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1047 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
1048 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
1049 return HC_ERR_IPC_BAD_PARAM;
1050 }
1051 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_PSEUDONYM_ID, (uint8_t *)&pseudonymId, NULL);
1052 if ((pseudonymId == NULL) || (ret != HC_SUCCESS)) {
1053 LOGE("get param error, type %d", PARAM_TYPE_PSEUDONYM_ID);
1054 return HC_ERR_IPC_BAD_PARAM;
1055 }
1056
1057 char *realInfo = NULL;
1058 ret = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo);
1059 if ((realInfo != NULL) && (ret == HC_SUCCESS)) {
1060 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo,
1061 HcStrlen(realInfo) + 1);
1062 HcFree(realInfo);
1063 } else {
1064 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1065 }
1066 LOGI("process done, ipc ret %d", ret);
1067 return ret;
1068 }
1069
IpcServiceGaGetPseudonymId(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1070 static int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1071 {
1072 int32_t ret;
1073 int32_t osAccountId;
1074 const char *indexKey = NULL;
1075
1076 LOGI("starting ...");
1077 int32_t inOutLen = sizeof(int64_t);
1078 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1079 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
1080 LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
1081 return HC_ERR_IPC_BAD_PARAM;
1082 }
1083 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_INDEX_KEY, (uint8_t *)&indexKey, NULL);
1084 if ((indexKey == NULL) || (ret != HC_SUCCESS)) {
1085 LOGE("get param error, type %d", PARAM_TYPE_INDEX_KEY);
1086 return HC_ERR_IPC_BAD_PARAM;
1087 }
1088
1089 char *pseudonymId = NULL;
1090 ret = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId);
1091 if ((pseudonymId != NULL) && (ret == HC_SUCCESS)) {
1092 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId,
1093 HcStrlen(pseudonymId) + 1);
1094 HcFree(pseudonymId);
1095 } else {
1096 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1097 }
1098 LOGI("process done, ipc ret %d", ret);
1099 return ret;
1100 }
1101
IpcServiceDaProcessCredential(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1102 static int32_t IpcServiceDaProcessCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1103 {
1104 int32_t ret;
1105 int32_t operationCode = 0;
1106 const char *reqJsonStr = NULL;
1107 char *returnData = NULL;
1108
1109 LOGI("starting ...");
1110 int32_t inOutLen = sizeof(int32_t);
1111 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OPCODE, (uint8_t *)&operationCode, &inOutLen);
1112 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
1113 LOGE("get param error, type %d", PARAM_TYPE_OPCODE);
1114 return HC_ERR_IPC_BAD_PARAM;
1115 }
1116 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, NULL);
1117 if ((reqJsonStr == NULL) || (ret != HC_SUCCESS)) {
1118 LOGE("get param error, type %d", PARAM_TYPE_REQ_JSON);
1119 return HC_ERR_IPC_BAD_PARAM;
1120 }
1121 ret = ProcessCredential(operationCode, reqJsonStr, &returnData);
1122 if (ret != HC_SUCCESS) {
1123 LOGI("call ProcessCredential failed %d", ret);
1124 }
1125 if (returnData != NULL) {
1126 ret = IpcEncodeCallReply(
1127 outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnData, HcStrlen(returnData) + 1);
1128 HcFree(returnData);
1129 } else {
1130 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1131 }
1132 LOGI("process done, ipc ret %d", ret);
1133 return ret;
1134 }
1135
IpcServiceDaProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1136 static int32_t IpcServiceDaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1137 {
1138 int32_t callRet;
1139 int32_t ret;
1140 const DeviceAuthCallback *callback = NULL;
1141 int64_t authReqId = 0;
1142 const char *authParams = NULL;
1143 int32_t inOutLen;
1144 int32_t cbObjIdx = -1;
1145
1146 LOGI("starting ...");
1147 inOutLen = sizeof(int64_t);
1148 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
1149 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) {
1150 LOGE("get param error, type %d", PARAM_TYPE_REQID);
1151 return HC_ERR_IPC_BAD_PARAM;
1152 }
1153 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1154 if ((ret != HC_SUCCESS) || (authParams == NULL)) {
1155 LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
1156 return HC_ERR_IPC_BAD_PARAM;
1157 }
1158 inOutLen = sizeof(DeviceAuthCallback);
1159 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
1160 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DeviceAuthCallback))) {
1161 LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
1162 return HC_ERR_IPC_BAD_PARAM;
1163 }
1164 ret = AddIpcCallBackByReqId(
1165 authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1166 if (ret != HC_SUCCESS) {
1167 return ret;
1168 }
1169 inOutLen = sizeof(int32_t);
1170 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1171 if (ret != HC_SUCCESS) {
1172 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
1173 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1174 return HC_ERR_IPC_BAD_PARAM;
1175 }
1176 AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1177 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1178 callRet = ProcessAuthDevice(authReqId, authParams, &g_authCbAdt);
1179 if (callRet != HC_SUCCESS) {
1180 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1181 }
1182 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1183 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
1184 return ret;
1185 }
1186
IpcServiceDaAuthDevice(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1187 static int32_t IpcServiceDaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1188 {
1189 int32_t callRet;
1190 int32_t ret;
1191 DeviceAuthCallback *callback = NULL;
1192 int64_t authReqId = 0;
1193 const char *authParams = NULL;
1194 int32_t inOutLen;
1195 int32_t cbObjIdx = -1;
1196
1197 LOGI("starting ...");
1198 inOutLen = sizeof(int64_t);
1199 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
1200 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(int64_t))) {
1201 LOGE("get param error, type %d", PARAM_TYPE_REQID);
1202 return HC_ERR_IPC_BAD_PARAM;
1203 }
1204 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1205 if ((ret != HC_SUCCESS) || (authParams == NULL)) {
1206 LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
1207 return HC_ERR_IPC_BAD_PARAM;
1208 }
1209 inOutLen = sizeof(DeviceAuthCallback);
1210 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen);
1211 if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DeviceAuthCallback))) {
1212 LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
1213 return HC_ERR_IPC_BAD_PARAM;
1214 }
1215 ret = AddIpcCallBackByReqId(
1216 authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1217 if (ret != HC_SUCCESS) {
1218 LOGE("add ipc callback failed");
1219 return ret;
1220 }
1221 inOutLen = sizeof(int32_t);
1222 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1223 if (ret != HC_SUCCESS) {
1224 LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
1225 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1226 return HC_ERR_IPC_BAD_PARAM;
1227 }
1228 AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1229 InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1230 callRet = StartAuthDevice(authReqId, authParams, &g_authCbAdt);
1231 if (callRet != HC_SUCCESS) {
1232 DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1233 }
1234 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1235 LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
1236 return ret;
1237 }
1238
IpcServiceDaCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1239 static int32_t IpcServiceDaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1240 {
1241 int32_t ret;
1242 int64_t requestId = 0;
1243 const char *authParams = NULL;
1244
1245 LOGI("starting ...");
1246 int32_t inOutLen = sizeof(int64_t);
1247 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1248 if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1249 LOGE("get param error, type %d", PARAM_TYPE_REQID);
1250 return HC_ERR_IPC_BAD_PARAM;
1251 }
1252 ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
1253 if ((authParams == NULL) || (ret != HC_SUCCESS)) {
1254 LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
1255 return HC_ERR_IPC_BAD_PARAM;
1256 }
1257 ret = CancelAuthRequest(requestId, authParams);
1258 DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true);
1259 ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&ret, sizeof(int32_t));
1260 LOGI("process done, ipc ret %d", ret);
1261 return ret;
1262 }
1263
1264 #ifndef DEV_AUTH_FUZZ_TEST
DeMainRescInit(void)1265 static void DeMainRescInit(void)
1266 {
1267 if (g_devGroupMgrMethod.unRegDataChangeListener != NULL) {
1268 (void)g_devGroupMgrMethod.unRegDataChangeListener(SERVICE_APP_ID);
1269 }
1270 DeInitIpcCallBackList();
1271 }
1272 #endif
1273
AddMethodMap(uintptr_t ipcInstance)1274 int32_t AddMethodMap(uintptr_t ipcInstance)
1275 {
1276 uint32_t ret;
1277
1278 // Group Manager Interfaces
1279 ret = SetIpcCallMap(ipcInstance, IpcServiceGmRegCallback, IPC_CALL_ID_REG_CB);
1280 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegCallback, IPC_CALL_ID_UNREG_CB);
1281 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmRegDataChangeListener, IPC_CALL_ID_REG_LISTENER);
1282 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegDataChangeListener, IPC_CALL_ID_UNREG_LISTENER);
1283 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCreateGroup, IPC_CALL_ID_CREATE_GROUP);
1284 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroup, IPC_CALL_ID_DEL_GROUP);
1285 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddMemberToGroup, IPC_CALL_ID_ADD_GROUP_MEMBER);
1286 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelMemberFromGroup, IPC_CALL_ID_DEL_GROUP_MEMBER);
1287 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddMultiMembersToGroup, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS);
1288 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelMultiMembersFromGroup, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS);
1289 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmProcessData, IPC_CALL_ID_GM_PROC_DATA);
1290 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO);
1291 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCheckAccessToGroup, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP);
1292 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetPkInfoList, IPC_CALL_ID_GET_PK_INFO_LIST);
1293 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfoById, IPC_CALL_ID_GET_GROUP_INFO);
1294 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfo, IPC_CALL_ID_SEARCH_GROUPS);
1295 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetJoinedGroups, IPC_CALL_ID_GET_JOINED_GROUPS);
1296 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetRelatedGroups, IPC_CALL_ID_GET_RELATED_GROUPS);
1297 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID);
1298 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES);
1299 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP);
1300 ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCancelRequest, IPC_CALL_GM_CANCEL_REQUEST);
1301
1302 // Group Auth Interfaces
1303 ret &= SetIpcCallMap(ipcInstance, IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA);
1304 ret &= SetIpcCallMap(ipcInstance, IpcServiceGaAuthDevice, IPC_CALL_ID_AUTH_DEVICE);
1305 ret &= SetIpcCallMap(ipcInstance, IpcServiceGaCancelRequest, IPC_CALL_GA_CANCEL_REQUEST);
1306 ret &= SetIpcCallMap(ipcInstance, IpcServiceGaGetRealInfo, IPC_CALL_ID_GET_REAL_INFO);
1307 ret &= SetIpcCallMap(ipcInstance, IpcServiceGaGetPseudonymId, IPC_CALL_ID_GET_PSEUDONYM_ID);
1308
1309 // Direct Auth Interfaces
1310 ret &= SetIpcCallMap(ipcInstance, IpcServiceDaProcessCredential, IPC_CALL_ID_PROCESS_CREDENTIAL);
1311 ret &= SetIpcCallMap(ipcInstance, IpcServiceDaAuthDevice, IPC_CALL_ID_DA_AUTH_DEVICE);
1312 ret &= SetIpcCallMap(ipcInstance, IpcServiceDaProcessData, IPC_CALL_ID_DA_PROC_DATA);
1313 ret &= SetIpcCallMap(ipcInstance, IpcServiceDaCancelRequest, IPC_CALL_ID_DA_CANCEL_REQUEST);
1314 LOGI("process done, ret %u", ret);
1315 return ret;
1316 }
1317
MainRescInit(void)1318 int32_t MainRescInit(void)
1319 {
1320 int32_t ret;
1321 const DeviceGroupManager *gmInst = NULL;
1322 const GroupAuthManager *gaInst = NULL;
1323
1324 LOGI("starting ...");
1325 ret = InitIpcCallBackList();
1326 if (ret != HC_SUCCESS) {
1327 return ret;
1328 }
1329 gmInst = GetGmInstance();
1330 gaInst = GetGaInstance();
1331 if ((gmInst == NULL) || (gaInst == NULL)) {
1332 DeInitIpcCallBackList();
1333 LOGE("MainInit, GetGmInstance failed");
1334 return HC_ERROR;
1335 }
1336 g_devGroupMgrMethod = (DeviceGroupManager)(*gmInst);
1337 g_groupAuthMgrMethod = (GroupAuthManager)(*gaInst);
1338 InitDevAuthListenerCbCtx(&g_listenCbAdt);
1339 ret = gmInst->regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt);
1340 if (ret != HC_SUCCESS) {
1341 DeInitIpcCallBackList();
1342 LOGE("MainInit, register ipc listener failed, ret %d", ret);
1343 return HC_ERROR;
1344 }
1345
1346 LOGI("process done");
1347 return HC_SUCCESS;
1348 }
1349
1350 #ifndef DEV_AUTH_FUZZ_TEST
main(int32_t argc,char const * argv[])1351 int32_t main(int32_t argc, char const *argv[])
1352 {
1353 int32_t ret;
1354 HcCondition cond;
1355
1356 (void)argc;
1357 (void)argv;
1358 LOGI("device authentication service starting ...");
1359 ret = InitDeviceAuthService();
1360 if (ret != HC_SUCCESS) {
1361 LOGE("device auth service main, InitDeviceAuthService failed, ret %d", ret);
1362 return 1;
1363 }
1364
1365 ret = MainRescInit();
1366 if (ret != HC_SUCCESS) {
1367 DestroyDeviceAuthService();
1368 LOGE("device auth service main, init work failed");
1369 return 1;
1370 }
1371
1372 uintptr_t serviceInstance = 0x0;
1373 ret = CreateServiceInstance(&serviceInstance);
1374 if (ret != HC_SUCCESS) {
1375 LOGE("Failed to create device auth service instance!");
1376 DeMainRescInit();
1377 DestroyDeviceAuthService();
1378 return 1;
1379 }
1380 (void)AddMethodMap(serviceInstance);
1381 ret = AddDevAuthServiceToManager(serviceInstance);
1382 if (ret != HC_SUCCESS) {
1383 DestroyServiceInstance(serviceInstance);
1384 DeMainRescInit();
1385 DestroyDeviceAuthService();
1386 LOGE("device auth service main, AddDevAuthServiceToManager failed, ret %d", ret);
1387 return 1;
1388 }
1389 LOGI("device authentication service register to IPC manager done, service running...");
1390 (void)memset_s(&cond, sizeof(cond), 0, sizeof(cond));
1391 InitHcCond(&cond, NULL);
1392 cond.wait(&cond);
1393 DestroyHcCond(&cond);
1394 return 0;
1395 }
1396 #endif
1397
1398 #ifdef __cplusplus
1399 }
1400 #endif
1401