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 "huks_core_hal.h"
17 #include "huks_core_hal_mock.h"
18 
19 #include "hks_log.h"
20 
21 #include "securec.h"
22 
23 static bool g_isEnableCreateOrDestroy = true;
24 static bool g_isEnableHdi = true;
25 
26 static struct HuksHdi g_mockHid = { 0 };
27 
HksCreateHuksHdiDevice(struct HuksHdi ** halDevice)28 int32_t HksCreateHuksHdiDevice(struct HuksHdi **halDevice)
29 {
30     if (g_isEnableCreateOrDestroy) {
31         if (g_isEnableHdi) {
32             (void)memset_s(&g_mockHid, sizeof(struct HuksHdi), 1, sizeof(struct HuksHdi));
33         } else {
34             (void)memset_s(&g_mockHid, sizeof(struct HuksHdi), 0, sizeof(struct HuksHdi));
35         }
36         *halDevice = &g_mockHid;
37         return HKS_SUCCESS;
38     }
39     return HKS_FAILURE;
40 }
41 
HksDestroyHuksHdiDevice(struct HuksHdi ** halDevice)42 int32_t HksDestroyHuksHdiDevice(struct HuksHdi **halDevice)
43 {
44     if (g_isEnableCreateOrDestroy) {
45         return HKS_SUCCESS;
46     }
47     return HKS_FAILURE;
48 }
49 
HksEnableCreateOrDestroy(bool isEnable)50 void HksEnableCreateOrDestroy(bool isEnable)
51 {
52     g_isEnableCreateOrDestroy = isEnable;
53 }
54 
HksEnableSetHid(bool isEnable)55 void HksEnableSetHid(bool isEnable)
56 {
57     g_isEnableHdi = isEnable;
58 }
59