1 /*
2 * Copyright (c) 2022 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 "dslm_ipc_process.h"
17 #include "dslm_service.h"
18
19 #include "ohos_init.h"
20 #include "ohos_types.h"
21 #include "utils_log.h"
22
23 static const char *FEATURE_GetName(Feature *feature);
24 static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
25 static void FEATURE_OnStop(Feature *feature, Identity identity);
26 static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
27 static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
28
29 static DslmFeature g_dslmFeature = {
30 .GetName = FEATURE_GetName,
31 .OnInitialize = FEATURE_OnInitialize,
32 .OnStop = FEATURE_OnStop,
33 .OnMessage = FEATURE_OnMessage,
34 SERVER_IPROXY_IMPL_BEGIN,
35 .Invoke = Invoke,
36 .DslmGetDeviceSecurityLevel = DslmProcessGetDeviceSecurityLevel,
37 IPROXY_END,
38 .identity = {-1, -1, NULL},
39 };
40
FEATURE_GetName(Feature * feature)41 static const char *FEATURE_GetName(Feature *feature)
42 {
43 return DSLM_SAMGR_FEATURE;
44 }
45
FEATURE_OnInitialize(Feature * feature,Service * parent,Identity identity)46 static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
47 {
48 DslmFeature *dslmFeature = (DslmFeature *)feature;
49 dslmFeature->identity = identity;
50 dslmFeature->parent = parent;
51 }
52
FEATURE_OnStop(Feature * feature,Identity identity)53 static void FEATURE_OnStop(Feature *feature, Identity identity)
54 {
55 g_dslmFeature.identity.queueId = NULL;
56 g_dslmFeature.identity.featureId = -1;
57 g_dslmFeature.identity.serviceId = -1;
58 }
59
FEATURE_OnMessage(Feature * feature,Request * request)60 static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
61 {
62 (void)feature;
63 Response response = {.data = "Default response", .len = 0};
64 SAMGR_SendResponse(request, &response);
65 return TRUE;
66 }
67
Invoke(IServerProxy * iProxy,int funcId,void * origin,IpcIo * req,IpcIo * reply)68 static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply)
69 {
70 DslmFeatureApi *api = (DslmFeatureApi *)iProxy;
71 switch (funcId) {
72 case CMD_SET_DEVICE_SECURITY_LEVEL:
73 return api->DslmGetDeviceSecurityLevel((IUnknown *)iProxy, req, reply);
74 default:
75 WriteInt32(reply, ERR_REQUEST_CODE_ERR);
76 break;
77 }
78 return ERR_REQUEST_CODE_ERR;
79 }
80
Init(void)81 static void Init(void)
82 {
83 BOOL isRegistered = SAMGR_GetInstance()->RegisterFeature(DSLM_SAMGR_SERVICE, (Feature *)&g_dslmFeature);
84 if (!isRegistered) {
85 SECURITY_LOG_ERROR("[RegisterFeature S:%s F:%s] init feature failed!",
86 DSLM_SAMGR_SERVICE, DSLM_SAMGR_FEATURE);
87 return;
88 }
89
90 isRegistered = SAMGR_GetInstance()->RegisterFeatureApi(DSLM_SAMGR_SERVICE,
91 DSLM_SAMGR_FEATURE, GET_IUNKNOWN(g_dslmFeature));
92 if (!isRegistered) {
93 SECURITY_LOG_ERROR("[RegisterFeatureApi S:%s F:%s] init feature failed!",
94 DSLM_SAMGR_SERVICE, DSLM_SAMGR_FEATURE);
95 return;
96 }
97
98 SECURITY_LOG_INFO("[RegisterFeature S:%s F:%s] init feature success!",
99 DSLM_SAMGR_SERVICE, DSLM_SAMGR_FEATURE);
100 }
101 SYS_FEATURE_INIT(Init);