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_service.h"
17 #include "ohos_init.h"
18 #include "ohos_types.h"
19 #include "utils_log.h"
20
21 #include "device_security_defines.h"
22 #include "dslm_rpc_process.h"
23
24 static const char *GetName(Service *service);
25 static BOOL Initialize(Service *service, Identity identity);
26 static BOOL MessageHandle(Service *service, Request *msg);
27 static TaskConfig GetTaskConfig(Service *service);
28
29 static DslmService g_dslmService = {
30 .GetName = GetName,
31 .Initialize = Initialize,
32 .MessageHandle = MessageHandle,
33 .GetTaskConfig = GetTaskConfig,
34 .identity = {-1, -1, NULL},
35 };
36
GetName(Service * service)37 static const char *GetName(Service *service)
38 {
39 return DSLM_SAMGR_SERVICE;
40 }
41
Initialize(Service * service,Identity identity)42 static BOOL Initialize(Service *service, Identity identity)
43 {
44 if (service == NULL) {
45 return FALSE;
46 }
47
48 DslmService *dslmService = (DslmService *)service;
49 dslmService->identity = identity;
50 if (InitService() != SUCCESS) {
51 SECURITY_LOG_ERROR("init service failed");
52 return FALSE;
53 }
54 SECURITY_LOG_INFO("[Initialize S:%s]: init service success", DSLM_SAMGR_SERVICE);
55 return TRUE;
56 }
57
MessageHandle(Service * service,Request * msg)58 static BOOL MessageHandle(Service *service, Request *msg)
59 {
60 (void)service;
61 return TRUE;
62 }
GetTaskConfig(Service * service)63 static TaskConfig GetTaskConfig(Service *service)
64 {
65 #ifdef L0_MINI
66 TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0xffff, 20, SINGLE_TASK};
67 #else
68 TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
69 #endif
70 return config;
71 }
72
Init(void)73 static void Init(void)
74 {
75 BOOL isRegistered = SAMGR_GetInstance()->RegisterService((Service *)&g_dslmService);
76 if (!isRegistered) {
77 SECURITY_LOG_ERROR("[RegisterService S:%s] init service failed!", DSLM_SAMGR_SERVICE);
78 return;
79 }
80
81 SECURITY_LOG_INFO("[RegisterService S:%s] init service success!", DSLM_SAMGR_SERVICE);
82 }
83 SYS_SERVICE_INIT(Init);