• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_lite.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 "ipc_adapt.h"
24 #include "ipc_sdk_defines.h"
25 #include "ipc_service_common.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
AddMethodMap(uintptr_t ipcInstance)31 int32_t AddMethodMap(uintptr_t ipcInstance)
32 {
33     uint32_t ret = 0;
34     typedef struct {
35         int32_t (*func)(const IpcDataInfo*, int32_t, uintptr_t);
36         uint32_t id;
37     } IpcCallMap;
38 
39     IpcCallMap ipcCallMaps[] = {
40         {IpcServiceGmRegCallback, IPC_CALL_ID_REG_CB},
41         {IpcServiceGmUnRegCallback, IPC_CALL_ID_UNREG_CB},
42         {IpcServiceGmRegDataChangeListener, IPC_CALL_ID_REG_LISTENER},
43         {IpcServiceGmUnRegDataChangeListener, IPC_CALL_ID_UNREG_LISTENER},
44         {IpcServiceGmCreateGroup, IPC_CALL_ID_CREATE_GROUP},
45         {IpcServiceGmDelGroup, IPC_CALL_ID_DEL_GROUP},
46         {IpcServiceGmAddMemberToGroup, IPC_CALL_ID_ADD_GROUP_MEMBER},
47         {IpcServiceGmDelMemberFromGroup, IPC_CALL_ID_DEL_GROUP_MEMBER},
48         {IpcServiceGmAddMultiMembersToGroup, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS},
49         {IpcServiceGmDelMultiMembersFromGroup, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS},
50         {IpcServiceGmProcessData, IPC_CALL_ID_GM_PROC_DATA},
51         {IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO},
52         {IpcServiceGmCheckAccessToGroup, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP},
53         {IpcServiceGmGetPkInfoList, IPC_CALL_ID_GET_PK_INFO_LIST},
54         {IpcServiceGmGetGroupInfoById, IPC_CALL_ID_GET_GROUP_INFO},
55         {IpcServiceGmGetGroupInfo, IPC_CALL_ID_SEARCH_GROUPS},
56         {IpcServiceGmGetJoinedGroups, IPC_CALL_ID_GET_JOINED_GROUPS},
57         {IpcServiceGmGetRelatedGroups, IPC_CALL_ID_GET_RELATED_GROUPS},
58         {IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID},
59         {IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES},
60         {IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP},
61         {IpcServiceGmCancelRequest, IPC_CALL_GM_CANCEL_REQUEST},
62         {IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA},
63         {IpcServiceGaAuthDevice, IPC_CALL_ID_AUTH_DEVICE},
64         {IpcServiceGaCancelRequest, IPC_CALL_GA_CANCEL_REQUEST},
65         {IpcServiceGaGetRealInfo, IPC_CALL_ID_GET_REAL_INFO},
66         {IpcServiceGaGetPseudonymId, IPC_CALL_ID_GET_PSEUDONYM_ID},
67         {IpcServiceDaProcessCredential, IPC_CALL_ID_PROCESS_CREDENTIAL},
68         {IpcServiceDaAuthDevice, IPC_CALL_ID_DA_AUTH_DEVICE},
69         {IpcServiceDaProcessData, IPC_CALL_ID_DA_PROC_DATA},
70         {IpcServiceDaCancelRequest, IPC_CALL_ID_DA_CANCEL_REQUEST},
71     };
72 
73     for (uint32_t i = 0; i < sizeof(ipcCallMaps)/sizeof(ipcCallMaps[0]); i++) {
74         ret &= SetIpcCallMap(ipcInstance, ipcCallMaps[i].func, ipcCallMaps[i].id);
75     }
76 
77     return ret;
78 }
79 
80 #ifndef DEV_AUTH_FUZZ_TEST
main(int32_t argc,char const * argv[])81 int32_t main(int32_t argc, char const *argv[])
82 {
83     int32_t ret;
84     HcCondition cond;
85 
86     (void)argc;
87     (void)argv;
88     LOGI("device authentication service starting ...");
89     ret = InitDeviceAuthService();
90     if (ret != HC_SUCCESS) {
91         LOGE("device auth service main, InitDeviceAuthService failed, ret %" LOG_PUB "d", ret);
92         return 1;
93     }
94 
95     ret = MainRescInit();
96     if (ret != HC_SUCCESS) {
97         DestroyDeviceAuthService();
98         LOGE("device auth service main, init work failed");
99         return 1;
100     }
101 
102     uintptr_t serviceInstance = 0x0;
103     ret = CreateServiceInstance(&serviceInstance);
104     if (ret != HC_SUCCESS) {
105         LOGE("Failed to create device auth service instance!");
106         DeMainRescInit();
107         DestroyDeviceAuthService();
108         return 1;
109     }
110     (void)AddMethodMap(serviceInstance);
111     ret = AddDevAuthServiceToManager(serviceInstance);
112     if (ret != HC_SUCCESS) {
113         DestroyServiceInstance(serviceInstance);
114         DeMainRescInit();
115         DestroyDeviceAuthService();
116         LOGE("device auth service main, AddDevAuthServiceToManager failed, ret %" LOG_PUB "d", ret);
117         return 1;
118     }
119     LOGI("device authentication service register to IPC manager done, service running...");
120     (void)memset_s(&cond, sizeof(cond), 0, sizeof(cond));
121     InitHcCond(&cond, NULL);
122     cond.wait(&cond);
123     DestroyHcCond(&cond);
124     return 0;
125 }
126 #endif
127 
128 #ifdef __cplusplus
129 }
130 #endif
131