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