12ee81decSopenharmony_ci/*
22ee81decSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
32ee81decSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
42ee81decSopenharmony_ci * you may not use this file except in compliance with the License.
52ee81decSopenharmony_ci * You may obtain a copy of the License at
62ee81decSopenharmony_ci *
72ee81decSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
82ee81decSopenharmony_ci *
92ee81decSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
102ee81decSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
112ee81decSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122ee81decSopenharmony_ci * See the License for the specific language governing permissions and
132ee81decSopenharmony_ci * limitations under the License.
142ee81decSopenharmony_ci */
152ee81decSopenharmony_ci
162ee81decSopenharmony_ci#include "dslm_service.h"
172ee81decSopenharmony_ci#include "ohos_init.h"
182ee81decSopenharmony_ci#include "ohos_types.h"
192ee81decSopenharmony_ci#include "utils_log.h"
202ee81decSopenharmony_ci
212ee81decSopenharmony_ci#include "device_security_defines.h"
222ee81decSopenharmony_ci#include "dslm_rpc_process.h"
232ee81decSopenharmony_ci
242ee81decSopenharmony_cistatic const char *GetName(Service *service);
252ee81decSopenharmony_cistatic BOOL Initialize(Service *service, Identity identity);
262ee81decSopenharmony_cistatic BOOL MessageHandle(Service *service, Request *msg);
272ee81decSopenharmony_cistatic TaskConfig GetTaskConfig(Service *service);
282ee81decSopenharmony_ci
292ee81decSopenharmony_cistatic DslmService g_dslmService = {
302ee81decSopenharmony_ci    .GetName = GetName,
312ee81decSopenharmony_ci    .Initialize = Initialize,
322ee81decSopenharmony_ci    .MessageHandle = MessageHandle,
332ee81decSopenharmony_ci    .GetTaskConfig = GetTaskConfig,
342ee81decSopenharmony_ci    .identity = {-1, -1, NULL},
352ee81decSopenharmony_ci};
362ee81decSopenharmony_ci
372ee81decSopenharmony_cistatic const char *GetName(Service *service)
382ee81decSopenharmony_ci{
392ee81decSopenharmony_ci    return DSLM_SAMGR_SERVICE;
402ee81decSopenharmony_ci}
412ee81decSopenharmony_ci
422ee81decSopenharmony_cistatic BOOL Initialize(Service *service, Identity identity)
432ee81decSopenharmony_ci{
442ee81decSopenharmony_ci    if (service == NULL) {
452ee81decSopenharmony_ci        return FALSE;
462ee81decSopenharmony_ci    }
472ee81decSopenharmony_ci
482ee81decSopenharmony_ci    DslmService *dslmService = (DslmService *)service;
492ee81decSopenharmony_ci    dslmService->identity = identity;
502ee81decSopenharmony_ci    if (InitService() != SUCCESS) {
512ee81decSopenharmony_ci        SECURITY_LOG_ERROR("init service failed");
522ee81decSopenharmony_ci        return FALSE;
532ee81decSopenharmony_ci    }
542ee81decSopenharmony_ci    SECURITY_LOG_INFO("[Initialize S:%s]: init service success", DSLM_SAMGR_SERVICE);
552ee81decSopenharmony_ci    return TRUE;
562ee81decSopenharmony_ci}
572ee81decSopenharmony_ci
582ee81decSopenharmony_cistatic BOOL MessageHandle(Service *service, Request *msg)
592ee81decSopenharmony_ci{
602ee81decSopenharmony_ci    (void)service;
612ee81decSopenharmony_ci    return TRUE;
622ee81decSopenharmony_ci}
632ee81decSopenharmony_cistatic TaskConfig GetTaskConfig(Service *service)
642ee81decSopenharmony_ci{
652ee81decSopenharmony_ci#ifdef L0_MINI
662ee81decSopenharmony_ci    TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0xffff, 20, SINGLE_TASK};
672ee81decSopenharmony_ci#else
682ee81decSopenharmony_ci    TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
692ee81decSopenharmony_ci#endif
702ee81decSopenharmony_ci    return config;
712ee81decSopenharmony_ci}
722ee81decSopenharmony_ci
732ee81decSopenharmony_cistatic void Init(void)
742ee81decSopenharmony_ci{
752ee81decSopenharmony_ci    BOOL isRegistered = SAMGR_GetInstance()->RegisterService((Service *)&g_dslmService);
762ee81decSopenharmony_ci    if (!isRegistered) {
772ee81decSopenharmony_ci        SECURITY_LOG_ERROR("[RegisterService S:%s] init service failed!", DSLM_SAMGR_SERVICE);
782ee81decSopenharmony_ci        return;
792ee81decSopenharmony_ci    }
802ee81decSopenharmony_ci
812ee81decSopenharmony_ci    SECURITY_LOG_INFO("[RegisterService S:%s] init service success!", DSLM_SAMGR_SERVICE);
822ee81decSopenharmony_ci}
832ee81decSopenharmony_ciSYS_SERVICE_INIT(Init);