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 "device_security_info.h"
17
18 #include "ohos_types.h"
19 #include "utils_log.h"
20 #include "utils_mem.h"
21
22 #include "device_security_level_defines.h"
23 #ifdef L0_MINI
24 #include "device_security_level_inner.h"
25 #else
26 #include "device_security_level_proxy.h"
27 #endif
28
29 int32_t RequestDeviceSecurityInfoAsyncImpl(const DeviceIdentify *identify, const RequestOption *option,
30 DeviceSecurityInfoCallback callback);
31
RequestDeviceSecurityInfoImpl(const DeviceIdentify * identify,const RequestOption * option,DeviceSecurityInfo ** info)32 static int32_t RequestDeviceSecurityInfoImpl(const DeviceIdentify *identify, const RequestOption *option,
33 DeviceSecurityInfo **info)
34 {
35 return ERR_IPC_ERR;
36 }
37
FreeDeviceSecurityInfoImpl(DeviceSecurityInfo * info)38 static void FreeDeviceSecurityInfoImpl(DeviceSecurityInfo *info)
39 {
40 if (info != NULL && info->magicNum == SECURITY_MAGIC) {
41 info->magicNum = 0;
42 FREE(info);
43 }
44 }
45
GetDeviceSecurityLevelValueImpl(const DeviceSecurityInfo * info,int32_t * level)46 static int32_t GetDeviceSecurityLevelValueImpl(const DeviceSecurityInfo *info, int32_t *level)
47 {
48 if (info == NULL || level == NULL) {
49 return ERR_INVALID_PARA;
50 }
51 if (info->magicNum != SECURITY_MAGIC) {
52 return ERR_INVALID_PARA;
53 }
54
55 *level = (int32_t)(info->level);
56 return (int32_t)(info->result);
57 }
58
RequestDeviceSecurityInfo(const DeviceIdentify * identify,const RequestOption * option,DeviceSecurityInfo ** info)59 int32_t RequestDeviceSecurityInfo(const DeviceIdentify *identify, const RequestOption *option,
60 DeviceSecurityInfo **info)
61 {
62 return RequestDeviceSecurityInfoImpl(identify, option, info);
63 }
64
RequestDeviceSecurityInfoAsync(const DeviceIdentify * identify,const RequestOption * option,DeviceSecurityInfoCallback callback)65 int32_t RequestDeviceSecurityInfoAsync(const DeviceIdentify *identify, const RequestOption *option,
66 DeviceSecurityInfoCallback callback)
67 {
68 return RequestDeviceSecurityInfoAsyncImpl(identify, option, callback);
69 }
70
FreeDeviceSecurityInfo(DeviceSecurityInfo * info)71 void FreeDeviceSecurityInfo(DeviceSecurityInfo *info)
72 {
73 return FreeDeviceSecurityInfoImpl(info);
74 }
75
GetDeviceSecurityLevelValue(const DeviceSecurityInfo * info,int32_t * level)76 int32_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo *info, int32_t *level)
77 {
78 return GetDeviceSecurityLevelValueImpl(info, level);
79 }
80