14a616216Sopenharmony_ci/* 24a616216Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 34a616216Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44a616216Sopenharmony_ci * you may not use this file except in compliance with the License. 54a616216Sopenharmony_ci * You may obtain a copy of the License at 64a616216Sopenharmony_ci * 74a616216Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84a616216Sopenharmony_ci * 94a616216Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104a616216Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114a616216Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124a616216Sopenharmony_ci * See the License for the specific language governing permissions and 134a616216Sopenharmony_ci * limitations under the License. 144a616216Sopenharmony_ci */ 154a616216Sopenharmony_ci 164a616216Sopenharmony_ci#include "dev_slinfo_list.h" 174a616216Sopenharmony_ci#include "dev_slinfo_adpt.h" 184a616216Sopenharmony_ci#include "dev_slinfo_log.h" 194a616216Sopenharmony_ci 204a616216Sopenharmony_ci#ifdef __cplusplus 214a616216Sopenharmony_ciextern "C" { 224a616216Sopenharmony_ci#endif 234a616216Sopenharmony_ci 244a616216Sopenharmony_ci#define DATASL_API __attribute__ ((visibility ("default"))) 254a616216Sopenharmony_ci 264a616216Sopenharmony_cistatic int32_t GetHighestSecLevelByUdid(DEVSLQueryParams *queryParams, uint32_t *dataLevel) 274a616216Sopenharmony_ci{ 284a616216Sopenharmony_ci int32_t ret; 294a616216Sopenharmony_ci int32_t devLevel = DEFAULT_DEV_SEC_LEVEL; 304a616216Sopenharmony_ci 314a616216Sopenharmony_ci if ((queryParams->udidLen <= 0u) || (queryParams->udidLen > 64u)) { 324a616216Sopenharmony_ci return DEVSL_ERR_BAD_PARAMETERS; 334a616216Sopenharmony_ci } 344a616216Sopenharmony_ci 354a616216Sopenharmony_ci ret = GetDeviceSecLevelByUdid(queryParams->udid, queryParams->udidLen, &devLevel); 364a616216Sopenharmony_ci if (ret != DEVSL_SUCCESS) { 374a616216Sopenharmony_ci *dataLevel = DATA_SEC_LEVEL0; 384a616216Sopenharmony_ci DATA_SEC_LOG_ERROR("GetHighestSecLevelByUdid: get device security level failed, error code: %d", ret); 394a616216Sopenharmony_ci return ret; 404a616216Sopenharmony_ci } 414a616216Sopenharmony_ci 424a616216Sopenharmony_ci *dataLevel = GetDataSecLevelByDevSecLevel(devLevel); 434a616216Sopenharmony_ci return ret; 444a616216Sopenharmony_ci} 454a616216Sopenharmony_ci 464a616216Sopenharmony_ciDATASL_API int32_t DATASL_OnStart(void) 474a616216Sopenharmony_ci{ 484a616216Sopenharmony_ci int32_t ret; 494a616216Sopenharmony_ci 504a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("Enter DATASL_Onstart..."); 514a616216Sopenharmony_ci ret = StartDevslEnv(); 524a616216Sopenharmony_ci if (ret != DEVSL_SUCCESS) { 534a616216Sopenharmony_ci DATA_SEC_LOG_ERROR("DATASL_Onstart: StartDevslEnv - failed, error code is %d", ret); 544a616216Sopenharmony_ci FinishDevslEnv(); 554a616216Sopenharmony_ci return DEVSL_ERROR; 564a616216Sopenharmony_ci } 574a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("DATASL_Onstart done!"); 584a616216Sopenharmony_ci return DEVSL_SUCCESS; 594a616216Sopenharmony_ci} 604a616216Sopenharmony_ci 614a616216Sopenharmony_ciDATASL_API void DATASL_OnStop(void) 624a616216Sopenharmony_ci{ 634a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("Enter DATASL_OnStop..."); 644a616216Sopenharmony_ci FinishDevslEnv(); 654a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("DATASL_OnStop done!"); 664a616216Sopenharmony_ci return; 674a616216Sopenharmony_ci} 684a616216Sopenharmony_ci 694a616216Sopenharmony_ciDATASL_API int32_t DATASL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo) 704a616216Sopenharmony_ci{ 714a616216Sopenharmony_ci int32_t ret; 724a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("Enter DATASL_GetHighestSecLevel..."); 734a616216Sopenharmony_ci if ((queryParams == NULL) || (levelInfo == NULL)) { 744a616216Sopenharmony_ci return DEVSL_ERR_BAD_PARAMETERS; 754a616216Sopenharmony_ci } 764a616216Sopenharmony_ci 774a616216Sopenharmony_ci ret = GetHighestSecLevelByUdid(queryParams, levelInfo); 784a616216Sopenharmony_ci 794a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("DATASL_GetHighestSecLevel done!"); 804a616216Sopenharmony_ci return ret; 814a616216Sopenharmony_ci} 824a616216Sopenharmony_ci 834a616216Sopenharmony_cistatic int32_t GetHighestSecLevelByUdidAsync(DEVSLQueryParams *queryParams) 844a616216Sopenharmony_ci{ 854a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("Enter GetHighestSecLevelByUdidAsync..."); 864a616216Sopenharmony_ci int32_t ret; 874a616216Sopenharmony_ci 884a616216Sopenharmony_ci ret = GetDeviceSecLevelByUdidAsync(queryParams->udid, queryParams->udidLen); 894a616216Sopenharmony_ci if (ret != DEVSL_SUCCESS) { 904a616216Sopenharmony_ci DATA_SEC_LOG_ERROR("GetHighestSecLevelByUdidAsync: get device security level failed, error code: %d", ret); 914a616216Sopenharmony_ci return ret; 924a616216Sopenharmony_ci } 934a616216Sopenharmony_ci 944a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("GetHighestSecLevelByUdidAsync done!"); 954a616216Sopenharmony_ci return ret; 964a616216Sopenharmony_ci} 974a616216Sopenharmony_ci 984a616216Sopenharmony_ciDATASL_API int32_t DATASL_GetHighestSecLevelAsync(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback) 994a616216Sopenharmony_ci{ 1004a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("Enter DATASL_GetHighestSecLevelAsync..."); 1014a616216Sopenharmony_ci int32_t ret; 1024a616216Sopenharmony_ci 1034a616216Sopenharmony_ci if ((queryParams == NULL) || (callback == NULL) || (queryParams->udidLen <= 0u) || (queryParams->udidLen > 64u)) { 1044a616216Sopenharmony_ci return DEVSL_ERR_BAD_PARAMETERS; 1054a616216Sopenharmony_ci } 1064a616216Sopenharmony_ci 1074a616216Sopenharmony_ci ret = UpdateCallbackListParams(queryParams, callback); 1084a616216Sopenharmony_ci if (ret != DEVSL_SUCCESS) { 1094a616216Sopenharmony_ci DATA_SEC_LOG_ERROR("DATASL_GetHighestSecLevelAsync: Update Callback list params failed, error code: %d", ret); 1104a616216Sopenharmony_ci return ret; 1114a616216Sopenharmony_ci } 1124a616216Sopenharmony_ci 1134a616216Sopenharmony_ci ret = GetHighestSecLevelByUdidAsync(queryParams); 1144a616216Sopenharmony_ci DATA_SEC_LOG_DEBUG("DATASL_GetHighestSecLevelAsync done!"); 1154a616216Sopenharmony_ci return ret; 1164a616216Sopenharmony_ci} 1174a616216Sopenharmony_ci 1184a616216Sopenharmony_ci#ifdef __cplusplus 1194a616216Sopenharmony_ci} 1204a616216Sopenharmony_ci#endif