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 "hc_log.h"
17 #include "hc_types.h"
18 #include "dev_session_v2.h"
19 #include "iso_task_main.h"
20 #include "iso_base_cur_task.h"
21 #include "iso_client_task.h"
22 #include "iso_server_task.h"
23 #include "pake_v1_task_main.h"
24 #include "pake_base_cur_task.h"
25 #include "pake_v1_client_task.h"
26 #include "pake_v1_server_task.h"
27 #include "protocol_task_main_mock.h"
28 
29 static bool g_isIsoSupported = true;
30 static bool g_isPakeV1Supported = true;
31 
32 #ifdef DEFAULT_V2_NOT_SUPPORT
33 static bool g_isSessionV2Supported = false;
34 #else
35 static bool g_isSessionV2Supported = true;
36 #endif
37 
SetPakeV1Supported(bool isSupported)38 void SetPakeV1Supported(bool isSupported)
39 {
40     g_isPakeV1Supported = isSupported;
41 }
42 
IsSupportPakeV1(void)43 bool IsSupportPakeV1(void)
44 {
45     if (g_isPakeV1Supported) {
46         LOGI("pake v1 support.");
47     } else {
48         LOGI("pake v1 not support.");
49     }
50     return g_isPakeV1Supported;
51 }
52 
CreatePakeV1SubTask(const CJson * in)53 SubTaskBase *CreatePakeV1SubTask(const CJson *in)
54 {
55     bool isClient = true;
56     if (GetBoolFromJson(in, FIELD_IS_CLIENT, &isClient) != HC_SUCCESS) {
57         LOGE("Get isClient failed.");
58         return NULL;
59     }
60     if (isClient) {
61         return CreatePakeV1ClientTask(in);
62     } else {
63         return CreatePakeV1ServerTask(in);
64     }
65 }
66 
SetIsoSupported(bool isSupported)67 void SetIsoSupported(bool isSupported)
68 {
69     g_isIsoSupported = isSupported;
70 }
71 
IsIsoSupported(void)72 bool IsIsoSupported(void)
73 {
74     if (g_isIsoSupported) {
75         LOGI("iso support.");
76     } else {
77         LOGI("iso not support.");
78     }
79     return g_isIsoSupported;
80 }
81 
CreateIsoSubTask(const CJson * in)82 SubTaskBase *CreateIsoSubTask(const CJson *in)
83 {
84     bool isClient = true;
85     if (GetBoolFromJson(in, FIELD_IS_CLIENT, &isClient) != HC_SUCCESS) {
86         LOGE("Get isClient failed.");
87         return NULL;
88     }
89     if (isClient) {
90         return CreateIsoClientTask(in);
91     } else {
92         return CreateIsoServerTask(in);
93     }
94 }
95 
SetSessionV2Supported(bool isSupported)96 void SetSessionV2Supported(bool isSupported)
97 {
98     g_isSessionV2Supported = isSupported;
99 }
100 
IsSupportSessionV2(void)101 bool IsSupportSessionV2(void)
102 {
103     return g_isSessionV2Supported;
104 }
105