1 /*
2 * Copyright (c) 2024 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 #ifndef OHOS_ARCH_LITE
17 #include "wifi_multi_vap_manager.h"
18 #include "wifi_manager.h"
19 #include "wifi_service_manager.h"
20 #include "wifi_config_center.h"
21 #include "wifi_notification_util.h"
22 #include "wifi_ap_hal_interface.h"
23 #include "wifi_logger.h"
24
25 DEFINE_WIFILOG_LABEL("WifiMultiVapManager");
26
27 namespace OHOS {
28 namespace Wifi {
CheckCanConnectDevice()29 bool WifiMultiVapManager::CheckCanConnectDevice()
30 {
31 // to be implemented
32 return true;
33 }
34
CheckCanUseP2p()35 bool WifiMultiVapManager::CheckCanUseP2p()
36 {
37 // to be implemented
38 return true;
39 }
40
CheckCanUseSoftAp()41 bool WifiMultiVapManager::CheckCanUseSoftAp()
42 {
43 #ifdef FEATURE_VAP_MANAGER_SUPPORT
44 IEnhanceService *pEnhanceService = WifiServiceManager::GetInstance().GetEnhanceServiceInst();
45 if (pEnhanceService) {
46 return pEnhanceService->CheckEnhanceVapAvailable();
47 } else {
48 // to be implemented
49 return true;
50 }
51 #endif
52 return true;
53 }
54
CheckStaConnected()55 bool WifiMultiVapManager::CheckStaConnected()
56 {
57 for (int i = 0; i < STA_INSTANCE_MAX_NUM; ++i) {
58 WifiLinkedInfo linkInfo;
59 WifiConfigCenter::GetInstance().GetLinkedInfo(linkInfo, i);
60 WIFI_LOGI("CheckStaConnected: Instance %{public}d sta connect state is %{public}d", i, linkInfo.connState);
61 if (linkInfo.connState == ConnState::CONNECTING || linkInfo.connState == ConnState::AUTHENTICATING
62 || linkInfo.connState == ConnState::OBTAINING_IPADDR || linkInfo.connState == ConnState::CONNECTED) {
63 return true;
64 }
65 }
66
67 WIFI_LOGI("CheckStaConnected: Sta is not connected!");
68 return false;
69 }
70
CheckP2pConnected()71 bool WifiMultiVapManager::CheckP2pConnected()
72 {
73 WifiP2pLinkedInfo p2pLinkedInfo;
74 WifiConfigCenter::GetInstance().GetP2pInfo(p2pLinkedInfo);
75 if (p2pLinkedInfo.GetConnectState() == P2pConnectedState::P2P_CONNECTED) {
76 WIFI_LOGI("CheckP2pConnected: P2p is connected!");
77 return true;
78 }
79
80 WifiP2pGroupInfo group = WifiConfigCenter::GetInstance().GetCurrentP2pGroupInfo();
81 if (group.GetFrequency() > 0) {
82 WIFI_LOGI("CheckP2pConnected: P2p is created group!");
83 return true;
84 }
85
86 IEnhanceService *pEnhanceService = WifiServiceManager::GetInstance().GetEnhanceServiceInst();
87 if (pEnhanceService && pEnhanceService->CheckChbaConncted()) {
88 WIFI_LOGI("CheckP2pConnected: Chba is connected!");
89 return true;
90 }
91
92 WIFI_LOGI("CheckP2pConnected: P2p is not connected!");
93 return false;
94 }
95
CheckSoftApStarted()96 bool WifiMultiVapManager::CheckSoftApStarted()
97 {
98 for (int i = 0; i < AP_INSTANCE_MAX_NUM; ++i) {
99 int state = WifiConfigCenter::GetInstance().GetHotspotState(i);
100 WIFI_LOGI("CheckSoftApStarted: Instance %{public}d ap start state is %{public}d", i, state);
101 if (state == static_cast<int>(ApState::AP_STATE_STARTING)
102 || state == static_cast<int>(ApState::AP_STATE_STARTED)) {
103 return true;
104 }
105 }
106
107 WIFI_LOGI("CheckSoftApStarted: SoftAp is not Started!");
108 return false;
109 }
110
ForceStopSoftAp()111 void WifiMultiVapManager::ForceStopSoftAp()
112 {
113 for (int i = 0; i < AP_INSTANCE_MAX_NUM; ++i) {
114 WifiApHalInterface::GetInstance().StopAp(i);
115 if (WifiManager::GetInstance().GetWifiTogglerManager()) {
116 WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(0, i);
117 }
118 }
119 }
120
ShowToast()121 void WifiMultiVapManager::ShowToast()
122 {
123 WifiNotificationUtil::GetInstance().ShowDialog(WifiDialogType::THREE_VAP);
124 }
125
126 } // namespace Wifi
127 } // namespace OHOS
128 #endif