1 /*
2 * Copyright (C) 2021-2023 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 "wifi_service_scheduler.h"
17 #include "wifi_controller_define.h"
18 #include "wifi_manager.h"
19 #include "wifi_config_center.h"
20 #include "wifi_internal_msg.h"
21 #include "wifi_sta_hal_interface.h"
22 #include "wifi_common_event_helper.h"
23 #ifdef FEATURE_AP_SUPPORT
24 #include "i_ap_service.h"
25 #endif
26 #ifndef OHOS_ARCH_LITE
27 #include "wifi_country_code_manager.h"
28 #include "wifi_common_util.h"
29 #include "app_network_speed_limit_service.h"
30 #include "wifi_internal_event_dispatcher.h"
31 #else
32 #include "wifi_internal_event_dispatcher_lite.h"
33 #endif
34 #ifdef SUPPORT_ClOUD_WIFI_ASSET
35 #include "wifi_asset_manager.h"
36 #endif
37 #ifdef HDI_CHIP_INTERFACE_SUPPORT
38 #include "hal_device_manage.h"
39 #endif
40
41 namespace OHOS {
42 namespace Wifi {
43 DEFINE_WIFILOG_LABEL("WifiServiceScheduler");
GetInstance()44 WifiServiceScheduler &WifiServiceScheduler::GetInstance()
45 {
46 static WifiServiceScheduler gWifiServiceScheduler;
47 return gWifiServiceScheduler;
48 }
49
WifiServiceScheduler()50 WifiServiceScheduler::WifiServiceScheduler()
51 {
52 WIFI_LOGI("WifiServiceScheduler");
53 }
54
~WifiServiceScheduler()55 WifiServiceScheduler::~WifiServiceScheduler()
56 {
57 WIFI_LOGI("~WifiServiceScheduler");
58 }
59
ClearStaIfaceNameMap(int instId)60 void WifiServiceScheduler::ClearStaIfaceNameMap(int instId)
61 {
62 WIFI_LOGI("ClearStaIfaceNameMap");
63 std::lock_guard<std::mutex> lock(mutex);
64 auto iter = staIfaceNameMap.begin();
65 while (iter != staIfaceNameMap.end()) {
66 if (iter->first == instId) {
67 staIfaceNameMap.erase(iter);
68 break;
69 }
70 iter++;
71 }
72 }
73
ClearSoftApIfaceNameMap(int instId)74 void WifiServiceScheduler::ClearSoftApIfaceNameMap(int instId)
75 {
76 WIFI_LOGI("ClearSoftApIfaceNameMap");
77 std::lock_guard<std::mutex> lock(mutex);
78 auto iter = softApIfaceNameMap.begin();
79 while (iter != softApIfaceNameMap.end()) {
80 if (iter->first == instId) {
81 softApIfaceNameMap.erase(iter);
82 break;
83 }
84 iter++;
85 }
86 }
87
AutoStartStaService(int instId,std::string & staIfName)88 ErrCode WifiServiceScheduler::AutoStartStaService(int instId, std::string &staIfName)
89 {
90 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
91 WIFI_LOGI("AutoStartStaService, current sta state:%{public}d", staState);
92 std::lock_guard<std::mutex> lock(mutex);
93 if (staState == WifiOprMidState::RUNNING) {
94 WIFI_LOGI("AutoStartStaService, cur sta state is running.");
95 }
96 if (PreStartWifi(instId, staIfName) != WIFI_OPT_SUCCESS) {
97 return WIFI_OPT_FAILED;
98 }
99 DispatchWifiOpenRes(OperateResState::OPEN_WIFI_OPENING, instId);
100 WIFI_LOGI("AutoStartStaService startwifi iface:%{public}s instId:%{public}d",
101 WifiConfigCenter::GetInstance().GetStaIfaceName(instId).c_str(), instId);
102 int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId),
103 instId);
104 if (ret != WIFI_OPT_SUCCESS) {
105 WIFI_LOGE("AutoStartStaService start wifi fail.");
106 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
107 WriteWifiOpenAndCloseFailedHiSysEvent(static_cast<int>(OperateResState::OPEN_WIFI_FAILED),
108 "HAL_FAIL", static_cast<int>(staState));
109 WifiManager::GetInstance().GetWifiTogglerManager()->StopWifiToggledTimer();
110 return WIFI_OPT_FAILED;
111 } else {
112 WIFI_LOGE("AutoStartStaService start wifi instId:%{public}d success.", instId);
113 }
114 if (PostStartWifi(instId) != WIFI_OPT_SUCCESS) {
115 WIFI_LOGE("AutoStartStaService PostStartWifi instId:%{public}d", instId);
116 return WIFI_OPT_FAILED;
117 }
118 WifiManager::GetInstance().PushServiceCloseMsg(WifiCloseServiceCode::STA_MSG_OPENED, instId);
119 DispatchWifiOpenRes(OperateResState::OPEN_WIFI_SUCCEED, instId);
120 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
121 ins->HandleStaStart(instId);
122 return WIFI_OPT_SUCCESS;
123 }
124
AutoStartWifi2Service(int instId,std::string & staIfName)125 ErrCode WifiServiceScheduler::AutoStartWifi2Service(int instId, std::string &staIfName)
126 {
127 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
128 WIFI_LOGI("AutoStartWifi2Service, current sta state:%{public}d", staState);
129 std::lock_guard<std::mutex> lock(mutex);
130 if (staState == WifiOprMidState::RUNNING) {
131 WIFI_LOGI("AutoStartWifi2Service, cur sta2 state is running.");
132 }
133 if (PreStartWifi(instId, staIfName) != WIFI_OPT_SUCCESS) {
134 return WIFI_OPT_FAILED;
135 }
136 DispatchWifi2OpenRes(OperateResState::OPEN_WIFI_OPENING, instId);
137 int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId),
138 instId);
139 if (ret != WIFI_OPT_SUCCESS) {
140 WIFI_LOGE("AutoStartWifi2Service start wifi fail.");
141 return WIFI_OPT_FAILED;
142 }
143 if (PostStartWifi2(instId) != WIFI_OPT_SUCCESS) {
144 WIFI_LOGE("AutoStartWifi2Service PostStartWifi instId %{public}d", instId);
145 return WIFI_OPT_FAILED;
146 }
147 DispatchWifi2OpenRes(OperateResState::OPEN_WIFI_SUCCEED, instId);
148 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
149 ins->HandleWifi2Start(instId);
150 return WIFI_OPT_SUCCESS;
151 }
152
AutoStopStaService(int instId)153 ErrCode WifiServiceScheduler::AutoStopStaService(int instId)
154 {
155 WifiOprMidState staStateBefore = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
156 WIFI_LOGI("AutoStopStaService, current sta state:%{public}d", staStateBefore);
157 std::lock_guard<std::mutex> lock(mutex);
158 if (staStateBefore == WifiOprMidState::CLOSED) {
159 WIFI_LOGI("AutoStopStaService, cur sta state is closed.");
160 }
161 ErrCode ret = WIFI_OPT_FAILED;
162 #ifdef FEATURE_P2P_SUPPORT
163 ret = WifiManager::GetInstance().GetWifiP2pManager()->AutoStopP2pService();
164 if (ret != WIFI_OPT_SUCCESS && ret != WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED) {
165 WIFI_LOGE("AutoStopStaService,AutoStopP2pService failed!");
166 }
167 #endif
168
169 if (!WifiConfigCenter::GetInstance().SetWifiMidState(staStateBefore, WifiOprMidState::CLOSING, instId)) {
170 WIFI_LOGE("AutoStopStaService,set wifi mid state closing failed!");
171 return WIFI_OPT_FAILED;
172 }
173
174 IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
175 if (pService == nullptr) {
176 WIFI_LOGE("AutoStopStaService, Instance get sta service is null!");
177 HandleGetStaFailed(instId);
178 return WIFI_OPT_SUCCESS;
179 }
180 DispatchWifiCloseRes(OperateResState::CLOSE_WIFI_CLOSING, instId);
181 ret = pService->DisableStaService();
182 if (ret != WIFI_OPT_SUCCESS) {
183 WIFI_LOGE("service disable sta failed, ret %{public}d!", static_cast<int>(ret));
184 }
185 if (WifiStaHalInterface::GetInstance().StopWifi(instId) != WIFI_HAL_OPT_OK) {
186 WIFI_LOGE("stop wifi failed.");
187 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
188 if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, staStateBefore, instId)) {
189 WIFI_LOGE("AutoStopStaService, set wifi mid state:%{public}d failed!", staStateBefore);
190 return WIFI_OPT_FAILED;
191 }
192 WriteWifiOpenAndCloseFailedHiSysEvent(static_cast<int>(OperateResState::CLOSE_WIFI_FAILED), "TIME_OUT",
193 static_cast<int>(staState));
194 WifiManager::GetInstance().GetWifiTogglerManager()->ForceStopWifi();
195 return WIFI_OPT_FAILED;
196 }
197 WifiManager::GetInstance().PushServiceCloseMsg(WifiCloseServiceCode::STA_MSG_STOPED, instId);
198 DispatchWifiCloseRes(OperateResState::CLOSE_WIFI_SUCCEED, instId);
199 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
200 ins->HandleStaClose(instId);
201 return WIFI_OPT_SUCCESS;
202 }
203
AutoStopWifi2Service(int instId)204 ErrCode WifiServiceScheduler::AutoStopWifi2Service(int instId)
205 {
206 WifiOprMidState staStateBefore = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
207 WIFI_LOGI("AutoStopWifi2Service, current sta state:%{public}d, instId:%{public}d",
208 staStateBefore, instId);
209 std::lock_guard<std::mutex> lock(mutex);
210 if (staStateBefore == WifiOprMidState::CLOSED) {
211 WIFI_LOGI("AutoStopWifi2Service, cur sta2 state is closed.");
212 }
213 ErrCode ret = WIFI_OPT_FAILED;
214
215 if (!WifiConfigCenter::GetInstance().SetWifiMidState(staStateBefore, WifiOprMidState::CLOSING, instId)) {
216 WIFI_LOGE("AutoStopWifi2Service,set wifi mid state closing failed!");
217 return WIFI_OPT_FAILED;
218 }
219
220 IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
221 if (pService == nullptr) {
222 WIFI_LOGE("AutoStopWifi2Service, Instance get sta service is null!");
223 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
224 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, instId);
225 return WIFI_OPT_SUCCESS;
226 }
227 DispatchWifi2CloseRes(OperateResState::CLOSE_WIFI_CLOSING, instId);
228 ret = pService->DisableStaService();
229 if (ret != WIFI_OPT_SUCCESS) {
230 WIFI_LOGE("AutoStopWifi2Service service disable sta failed, ret %{public}d!", static_cast<int>(ret));
231 }
232 if (WifiStaHalInterface::GetInstance().StopWifi(instId) != WIFI_HAL_OPT_OK) {
233 WIFI_LOGE("AutoStopWifi2Service stop wifi failed.");
234 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
235 if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, staStateBefore, instId)) {
236 WIFI_LOGE("AutoStopWifi2Service, set wifi mid state:%{public}d failed!", staStateBefore);
237 return WIFI_OPT_FAILED;
238 }
239 }
240 DispatchWifi2CloseRes(OperateResState::CLOSE_WIFI_SUCCEED, instId);
241 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
242 ins->HandleWifi2Close(instId);
243 WIFI_LOGE("AutoStopWifi2Service %{public}d success!", instId);
244 return WIFI_OPT_SUCCESS;
245 }
246
HandleGetStaFailed(int instId)247 void WifiServiceScheduler::HandleGetStaFailed(int instId)
248 {
249 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
250 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, instId);
251 #ifdef FEATURE_WIFI_PRO_SUPPORT
252 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_WIFIPRO, instId);
253 #endif
254 #ifdef FEATURE_SELF_CURE_SUPPORT
255 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_SELFCURE, instId);
256 #endif
257 }
258
AutoStartScanOnly(int instId,std::string & staIfName)259 ErrCode WifiServiceScheduler::AutoStartScanOnly(int instId, std::string &staIfName)
260 {
261 WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiScanOnlyMidState(instId);
262 WIFI_LOGI("AutoStartScanOnly, Wifi scan only state is %{public}d, instId = %{public}d",
263 static_cast<int>(curState), instId);
264 std::lock_guard<std::mutex> lock(mutex);
265 if (curState != WifiOprMidState::CLOSED && instId == 0) {
266 WIFI_LOGE("ScanOnly State is not closed.");
267 }
268
269 if (WifiOprMidState::RUNNING == WifiConfigCenter::GetInstance().GetWifiMidState(instId) ||
270 WifiOprMidState::OPENING == WifiConfigCenter::GetInstance().GetWifiMidState(instId)) {
271 WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::RUNNING, instId);
272 return WIFI_OPT_SUCCESS;
273 }
274 #ifdef HDI_CHIP_INTERFACE_SUPPORT
275 std::string ifaceName = "";
276 if (staIfaceNameMap.count(instId) > 0) {
277 ifaceName = staIfaceNameMap[instId];
278 }
279 if (ifaceName.empty() && !DelayedSingleton<HalDeviceManager>::GetInstance()->CreateStaIface(
280 std::bind(&WifiServiceScheduler::StaIfaceDestoryCallback, this, std::placeholders::_1, std::placeholders::_2),
281 std::bind(&WifiServiceScheduler::OnRssiReportCallback, this, std::placeholders::_1, std::placeholders::_2),
282 ifaceName, instId)) {
283 WIFI_LOGE("AutoStartScanOnly, create iface failed!");
284 return WIFI_OPT_FAILED;
285 }
286 WIFI_LOGI("AutoStartScanOnly SetStaIfaceName:%{public}s, instId:%{public}d", ifaceName.c_str(), instId);
287 WifiConfigCenter::GetInstance().SetStaIfaceName(ifaceName);
288 staIfName = ifaceName;
289 staIfaceNameMap.insert(std::make_pair(instId, ifaceName));
290 #endif
291 WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::OPENING, instId);
292 if (instId == INSTID_WLAN0) {
293 WifiManager::GetInstance().AutoStartEnhanceService();
294 }
295 WifiManager::GetInstance().GetWifiScanManager()->CheckAndStartScanService(instId);
296 WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::RUNNING, instId);
297 return WIFI_OPT_SUCCESS;
298 }
299
AutoStopScanOnly(int instId,bool setIfaceDown)300 ErrCode WifiServiceScheduler::AutoStopScanOnly(int instId, bool setIfaceDown)
301 {
302 WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiScanOnlyMidState(instId);
303 WIFI_LOGI("AutoStopScanOnly, current wifi scan only state is %{public}d", static_cast<int>(curState));
304 std::lock_guard<std::mutex> lock(mutex);
305 if (curState != WifiOprMidState::RUNNING) {
306 WIFI_LOGI("AutoStopScanOnly, cur scan only state is not running.");
307 }
308
309 if (WifiOprMidState::RUNNING == WifiConfigCenter::GetInstance().GetWifiMidState(instId) ||
310 WifiOprMidState::OPENING == WifiConfigCenter::GetInstance().GetWifiMidState(instId)) {
311 WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::CLOSED, instId);
312 return WIFI_OPT_SUCCESS;
313 }
314
315 if (!WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(curState, WifiOprMidState::CLOSING, instId)) {
316 WIFI_LOGE("set wifi scan only mid state opening failed!");
317 return WIFI_OPT_FAILED;
318 }
319
320 if (setIfaceDown) {
321 #ifdef HDI_CHIP_INTERFACE_SUPPORT
322 DelayedSingleton<HalDeviceManager>::GetInstance()->SetNetworkUpDown(
323 WifiConfigCenter::GetInstance().GetStaIfaceName(instId), false);
324 #endif
325 }
326 WifiManager::GetInstance().GetWifiScanManager()->CheckAndStopScanService(instId);
327 WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::CLOSED, instId);
328 return WIFI_OPT_SUCCESS;
329 }
330
AutoStartSemiStaService(int instId,std::string & staIfName)331 ErrCode WifiServiceScheduler::AutoStartSemiStaService(int instId, std::string &staIfName)
332 {
333 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
334 WIFI_LOGI("AutoStartSemiStaService, current sta state:%{public}d", staState);
335 std::lock_guard<std::mutex> lock(mutex);
336 if (staState == WifiOprMidState::SEMI_ACTIVE) {
337 WIFI_LOGI("AutoStartSemiStaService, cur sta state is semi active.");
338 }
339 if (PreStartWifi(instId, staIfName) != WIFI_OPT_SUCCESS) {
340 WriteWifiOpenAndCloseFailedHiSysEvent(static_cast<int>(OperateResState::ENABLE_SEMI_WIFI_FAILED),
341 "HAL_CREATE_FAILED", static_cast<int>(WifiConfigCenter::GetInstance().GetWifiMidState(instId)));
342 WifiManager::GetInstance().GetWifiTogglerManager()->StopSemiWifiToggledTimer();
343 return WIFI_OPT_FAILED;
344 }
345 DispatchWifiSemiActiveRes(OperateResState::ENABLE_SEMI_WIFI_OPENING, instId);
346 int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId),
347 instId);
348 if (ret != WIFI_OPT_SUCCESS) {
349 WIFI_LOGE("AutoStartSemiStaService start wifi fail.");
350 WriteWifiOpenAndCloseFailedHiSysEvent(static_cast<int>(OperateResState::ENABLE_SEMI_WIFI_FAILED),
351 "HAL_START_FAILED", static_cast<int>(WifiConfigCenter::GetInstance().GetWifiMidState(instId)));
352 WifiManager::GetInstance().GetWifiTogglerManager()->StopSemiWifiToggledTimer();
353 return WIFI_OPT_FAILED;
354 }
355 WifiManager::GetInstance().PushServiceCloseMsg(WifiCloseServiceCode::STA_MSG_OPENED, instId);
356 DispatchWifiSemiActiveRes(OperateResState::ENABLE_SEMI_WIFI_SUCCEED, instId);
357 if (PostStartWifi(instId) != WIFI_OPT_SUCCESS) {
358 WriteWifiOpenAndCloseFailedHiSysEvent(static_cast<int>(OperateResState::ENABLE_SEMI_WIFI_FAILED),
359 "POST_START_FAILED", static_cast<int>(WifiConfigCenter::GetInstance().GetWifiMidState(instId)));
360 WifiManager::GetInstance().GetWifiTogglerManager()->StopSemiWifiToggledTimer();
361 return WIFI_OPT_FAILED;
362 }
363 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
364 ins->HandleStaSemiActive(instId);
365 return WIFI_OPT_SUCCESS;
366 }
367
PreStartWifi(int instId,std::string & staIfName)368 ErrCode WifiServiceScheduler::PreStartWifi(int instId, std::string &staIfName)
369 {
370 #ifdef HDI_CHIP_INTERFACE_SUPPORT
371 std::string ifaceName = "";
372 if (staIfaceNameMap.count(instId) > 0) {
373 ifaceName = staIfaceNameMap[instId];
374 staIfName = ifaceName;
375 }
376 if (ifaceName.empty() && !DelayedSingleton<HalDeviceManager>::GetInstance()->CreateStaIface(
377 std::bind(&WifiServiceScheduler::StaIfaceDestoryCallback, this, std::placeholders::_1, std::placeholders::_2),
378 std::bind(&WifiServiceScheduler::OnRssiReportCallback, this, std::placeholders::_1, std::placeholders::_2),
379 ifaceName, instId)) {
380 WIFI_LOGE("PreStartWifi, create iface failed!");
381 return WIFI_OPT_FAILED;
382 }
383 WIFI_LOGI("PreStartWifi SetStaIfaceName:%{public}s, instId:%{public}d", ifaceName.c_str(), instId);
384 WifiConfigCenter::GetInstance().SetStaIfaceName(ifaceName, instId);
385 staIfaceNameMap.insert(std::make_pair(instId, ifaceName));
386 staIfName = WifiConfigCenter::GetInstance().GetStaIfaceName(instId);
387 #endif
388 WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId);
389 if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, WifiOprMidState::OPENING, instId)) {
390 WIFI_LOGE("PreStartWifi, set wifi mid state opening failed!");
391 return WIFI_OPT_FAILED;
392 }
393 return WIFI_OPT_SUCCESS;
394 }
395
PostStartWifi(int instId)396 ErrCode WifiServiceScheduler::PostStartWifi(int instId)
397 {
398 if (StartWifiStaService(instId) == WIFI_OPT_FAILED) {
399 WIFI_LOGE("StartWifiStaService failed!");
400 }
401 #ifdef FEATURE_SELF_CURE_SUPPORT
402 if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) {
403 WIFI_LOGE("StartSelfCureService failed!");
404 }
405 #endif
406 WifiManager::GetInstance().GetWifiStaManager()->StopUnloadStaSaTimer();
407 #ifdef FEATURE_P2P_SUPPORT
408 ErrCode errCode = WifiManager::GetInstance().GetWifiP2pManager()->AutoStartP2pService();
409 if (errCode != WIFI_OPT_SUCCESS && errCode != WIFI_OPT_OPEN_SUCC_WHEN_OPENED) {
410 WIFI_LOGE("AutoStartStaService, AutoStartP2pService failed!");
411 }
412 #endif
413 return WIFI_OPT_SUCCESS;
414 }
415
PostStartWifi2(int instId)416 ErrCode WifiServiceScheduler::PostStartWifi2(int instId)
417 {
418 StartWifiStaService(instId);
419 return WIFI_OPT_SUCCESS;
420 }
421
StartWifiStaService(int instId)422 ErrCode WifiServiceScheduler::StartWifiStaService(int instId)
423 {
424 if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_STA, instId) < 0) {
425 WIFI_LOGE("StartWifiStaService Load %{public}s service failed!", WIFI_SERVICE_STA);
426 return WIFI_OPT_FAILED;
427 }
428 WIFI_LOGD("StartWifiStaService GetStaServiceInst instId:%{public}d", instId);
429 IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
430 if (pService == nullptr) {
431 WIFI_LOGE("StartWifiStaService Create %{public}s service failed!", WIFI_SERVICE_STA);
432 return WIFI_OPT_FAILED;
433 }
434
435 if (StartDependentService(instId) != WIFI_OPT_SUCCESS) {
436 return WIFI_OPT_FAILED;
437 }
438
439 WIFI_LOGD("StartWifiStaService InitStaService instId:%{public}d", instId);
440 if (InitStaService(pService, instId) != WIFI_OPT_SUCCESS) {
441 WIFI_LOGE("StartWifiStaService InitStaService failed!");
442 return WIFI_OPT_FAILED;
443 }
444 WIFI_LOGD("StartWifiStaService EnableStaService instId:%{public}d", instId);
445 ErrCode errCode = pService->EnableStaService();
446 if (errCode != WIFI_OPT_SUCCESS) {
447 WIFI_LOGE("StartWifiStaService Service enable sta failed ,ret %{public}d!", static_cast<int>(errCode));
448 return WIFI_OPT_FAILED;
449 }
450 WIFI_LOGI("StartWifiStaService instId%{public}d successful", instId);
451 return WIFI_OPT_SUCCESS;
452 }
453
StartDependentService(int instId)454 ErrCode WifiServiceScheduler::StartDependentService(int instId)
455 {
456 if (instId != INSTID_WLAN0) {
457 return WIFI_OPT_SUCCESS;
458 }
459
460 #ifdef FEATURE_WIFI_PRO_SUPPORT
461 if (StartWifiProService(instId) != WIFI_OPT_SUCCESS) {
462 WIFI_LOGE("StartWifiProService failed!");
463 return WIFI_OPT_FAILED;
464 }
465 #endif
466 #ifdef FEATURE_SELF_CURE_SUPPORT
467 if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) {
468 WIFI_LOGE("StartSelfCureService failed!");
469 return WIFI_OPT_FAILED;
470 }
471 #endif
472
473 return WIFI_OPT_SUCCESS;
474 }
475
InitStaService(IStaService * pService,int instId)476 ErrCode WifiServiceScheduler::InitStaService(IStaService *pService, int instId)
477 {
478 if (pService == nullptr) {
479 WIFI_LOGE("pService is nullptr");
480 return WIFI_OPT_FAILED;
481 }
482 ErrCode errCode = pService->RegisterStaServiceCallback(
483 WifiManager::GetInstance().GetWifiStaManager()->GetStaCallback());
484 if (errCode != WIFI_OPT_SUCCESS) {
485 WIFI_LOGE("Register sta service callback failed!");
486 return WIFI_OPT_FAILED;
487 }
488 if (instId == INSTID_WLAN0) {
489 errCode = pService->RegisterStaServiceCallback(
490 WifiManager::GetInstance().GetWifiScanManager()->GetStaCallback());
491 if (errCode != WIFI_OPT_SUCCESS) {
492 WIFI_LOGE("WifiScanManager register sta service callback failed!");
493 return WIFI_OPT_FAILED;
494 }
495 #ifndef OHOS_ARCH_LITE
496 errCode = pService->RegisterStaServiceCallback(WifiCountryCodeManager::GetInstance().GetStaCallback());
497 if (errCode != WIFI_OPT_SUCCESS) {
498 WIFI_LOGE("wifiCountryCodeManager register sta service callback failed, ret=%{public}d!",
499 static_cast<int>(errCode));
500 return WIFI_OPT_FAILED;
501 }
502
503 errCode = pService->RegisterStaServiceCallback(AppNetworkSpeedLimitService::GetInstance().GetStaCallback());
504 if (errCode != WIFI_OPT_SUCCESS) {
505 WIFI_LOGE("AppNetworkSpeedLimitService register sta service callback failed, ret=%{public}d!",
506 static_cast<int>(errCode));
507 return WIFI_OPT_FAILED;
508 }
509 #endif
510 #ifdef SUPPORT_ClOUD_WIFI_ASSET
511 errCode = pService->RegisterStaServiceCallback(WifiAssetManager::GetInstance().GetStaCallback());
512 WIFI_LOGI("WifiAssetManager register");
513 if (errCode != WIFI_OPT_SUCCESS) {
514 WIFI_LOGE("WifiAssetManager register sta service callback failed, ret=%{public}d!",
515 static_cast<int>(errCode));
516 return WIFI_OPT_FAILED;
517 }
518 #endif
519 }
520 return WIFI_OPT_SUCCESS;
521 }
522
523 #ifdef FEATURE_WIFI_PRO_SUPPORT
StartWifiProService(int instId)524 ErrCode WifiServiceScheduler::StartWifiProService(int instId)
525 {
526 if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_WIFIPRO) < 0) {
527 WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_WIFIPRO);
528 return WIFI_OPT_FAILED;
529 }
530
531 IWifiProService *pWifiProService = WifiServiceManager::GetInstance().GetWifiProServiceInst(instId);
532 if (pWifiProService == nullptr) {
533 WIFI_LOGE("Create %{public}s service failed!", WIFI_SERVICE_WIFIPRO);
534 return WIFI_OPT_FAILED;
535 }
536 ErrCode errCode = pWifiProService->InitWifiProService();
537 if (errCode != WIFI_OPT_SUCCESS) {
538 WIFI_LOGE("Service enable wifi pro failed, ret %{public}d!", static_cast<int>(errCode));
539 return WIFI_OPT_FAILED;
540 }
541
542 IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
543 if (pService == nullptr) {
544 WIFI_LOGE("Get %{public}s service failed!", WIFI_SERVICE_STA);
545 return WIFI_OPT_FAILED;
546 }
547
548 errCode = pService->RegisterStaServiceCallback(pWifiProService->GetStaCallback());
549 if (errCode != WIFI_OPT_SUCCESS) {
550 WIFI_LOGE("WifiPro register sta service callback failed!");
551 return WIFI_OPT_FAILED;
552 }
553
554 return WIFI_OPT_SUCCESS;
555 }
556 #endif
557
558 #ifdef FEATURE_SELF_CURE_SUPPORT
StartSelfCureService(int instId)559 ErrCode WifiServiceScheduler::StartSelfCureService(int instId)
560 {
561 if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_SELFCURE) < 0) {
562 WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_SELFCURE);
563 return WIFI_OPT_FAILED;
564 }
565 ISelfCureService *pSelfCureService = WifiServiceManager::GetInstance().GetSelfCureServiceInst(instId);
566 if (pSelfCureService == nullptr) {
567 WIFI_LOGE("Create %{public}s service failed!", WIFI_SERVICE_SELFCURE);
568 return WIFI_OPT_FAILED;
569 }
570 ErrCode errCode = pSelfCureService->InitSelfCureService();
571 if (errCode != WIFI_OPT_SUCCESS) {
572 WIFI_LOGE("Service enable self cure failed, ret %{public}d!", static_cast<int>(errCode));
573 return WIFI_OPT_FAILED;
574 }
575 IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
576 if (pService == nullptr) {
577 WIFI_LOGE("Get %{public}s service failed!", WIFI_SERVICE_STA);
578 return WIFI_OPT_FAILED;
579 }
580 errCode = pService->RegisterStaServiceCallback(pSelfCureService->GetStaCallback());
581 if (errCode != WIFI_OPT_SUCCESS) {
582 WIFI_LOGE("SelfCure register sta service callback failed!");
583 return WIFI_OPT_FAILED;
584 }
585 return WIFI_OPT_SUCCESS;
586 }
587 #endif
588
589 #ifdef HDI_CHIP_INTERFACE_SUPPORT
StaIfaceDestoryCallback(std::string & destoryIfaceName,int createIfaceType)590 void WifiServiceScheduler::StaIfaceDestoryCallback(std::string &destoryIfaceName, int createIfaceType)
591 {
592 WIFI_LOGI("IfaceDestoryCallback, ifaceName:%{public}s, ifaceType:%{public}d",
593 destoryIfaceName.c_str(), createIfaceType);
594 auto iter = staIfaceNameMap.begin();
595 while (iter != staIfaceNameMap.end()) {
596 if (destoryIfaceName == iter->second) {
597 WifiConfigCenter::GetInstance().SetStaIfaceName("");
598 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
599 ins->SendMessage(CMD_STA_REMOVED, createIfaceType, iter->first);
600 staIfaceNameMap.erase(iter);
601 return;
602 }
603 iter++;
604 }
605 }
606
OnRssiReportCallback(int index,int antRssi)607 void WifiServiceScheduler::OnRssiReportCallback(int index, int antRssi)
608 {
609 WIFI_LOGI("HwWiTas OnRssiReportCallback, index:%{public}d, antRssi:%{public}d", index, antRssi);
610
611 std::string data = std::to_string(antRssi);
612 WifiCommonEventHelper::PublishWiTasRssiValueChangedEvent(index, data);
613 }
614 #endif
615
DispatchWifiOpenRes(OperateResState state,int instId)616 void WifiServiceScheduler::DispatchWifiOpenRes(OperateResState state, int instId)
617 {
618 WIFI_LOGI("DispatchWifiOpenRes, state:%{public}d", static_cast<int>(state));
619 WifiEventCallbackMsg cbMsg;
620 cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE;
621 cbMsg.id = instId;
622 if (state == OperateResState::OPEN_WIFI_OPENING) {
623 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::ENABLING), instId);
624 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATING, instId);
625 cbMsg.msgData = static_cast<int>(WifiState::ENABLING);
626 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
627 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_OPEN),
628 static_cast<int>(WifiOperateState::STA_OPENING));
629 return;
630 }
631 if (state == OperateResState::OPEN_WIFI_SUCCEED) {
632 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::ENABLED), instId);
633 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATED, instId);
634 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::OPENING, WifiOprMidState::RUNNING, instId);
635 cbMsg.msgData = static_cast<int>(WifiState::ENABLED);
636 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
637 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_OPEN),
638 static_cast<int>(WifiOperateState::STA_OPENED));
639 WriteWifiStateHiSysEvent(HISYS_SERVICE_TYPE_STA, WifiOperType::ENABLE);
640 return;
641 }
642 }
643
DispatchWifi2OpenRes(OperateResState state,int instId)644 void WifiServiceScheduler::DispatchWifi2OpenRes(OperateResState state, int instId)
645 {
646 WIFI_LOGI("DispatchWifi2OpenRes, state:%{public}d", static_cast<int>(state));
647 WifiEventCallbackMsg cbMsg;
648 cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE;
649 cbMsg.id = instId;
650 if (state == OperateResState::OPEN_WIFI_OPENING) {
651 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::ENABLING), instId);
652 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATING, instId);
653 cbMsg.msgData = static_cast<int>(WifiState::ENABLING);
654 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
655 }
656 if (state == OperateResState::OPEN_WIFI_SUCCEED) {
657 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::ENABLED), instId);
658 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATED, instId);
659 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::OPENING, WifiOprMidState::RUNNING, instId);
660 cbMsg.msgData = static_cast<int>(WifiState::ENABLED);
661 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
662 }
663 return;
664 }
665
DispatchWifiSemiActiveRes(OperateResState state,int instId)666 void WifiServiceScheduler::DispatchWifiSemiActiveRes(OperateResState state, int instId)
667 {
668 WIFI_LOGI("DispatchWifiSemiActiveRes, state:%{public}d", static_cast<int>(state));
669 WifiEventCallbackMsg cbMsg;
670 cbMsg.msgCode = WIFI_CBK_MSG_SEMI_STATE_CHANGE;
671 cbMsg.id = instId;
672 if (state == OperateResState::ENABLE_SEMI_WIFI_OPENING) {
673 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLING), instId);
674 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_SEMI_ACTIVATING, instId);
675 cbMsg.msgData = static_cast<int>(WifiDetailState::STATE_SEMI_ACTIVATING);
676 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
677 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_SEMI_OPEN),
678 static_cast<int>(WifiOperateState::STA_SEMI_OPENING));
679 return;
680 }
681 if (state == OperateResState::ENABLE_SEMI_WIFI_SUCCEED) {
682 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLED), instId);
683 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_SEMI_ACTIVE, instId);
684 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::SEMI_ACTIVE, instId);
685 cbMsg.msgData = static_cast<int>(WifiDetailState::STATE_SEMI_ACTIVE);
686 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
687 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_SEMI_OPEN),
688 static_cast<int>(WifiOperateState::STA_SEMI_OPENED));
689 WriteWifiStateHiSysEvent(HISYS_SERVICE_TYPE_STA, WifiOperType::SEMI_ENABLE);
690 return;
691 }
692 }
693
DispatchWifiCloseRes(OperateResState state,int instId)694 void WifiServiceScheduler::DispatchWifiCloseRes(OperateResState state, int instId)
695 {
696 WIFI_LOGI("DispatchWifiCloseRes, state:%{public}d", static_cast<int>(state));
697 WifiEventCallbackMsg cbMsg;
698 cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE;
699 cbMsg.id = instId;
700 if (state == OperateResState::CLOSE_WIFI_CLOSING) {
701 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLING), instId);
702 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_DEACTIVATING, instId);
703 cbMsg.msgData = static_cast<int>(WifiState::DISABLING);
704 if (!WifiConfigCenter::GetInstance().GetWifiSelfcureReset()) {
705 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
706 }
707 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_CLOSE),
708 static_cast<int>(WifiOperateState::STA_CLOSING));
709 return;
710 }
711 if (state == OperateResState::CLOSE_WIFI_SUCCEED) {
712 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLED), instId);
713 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_INACTIVE, instId);
714 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
715 cbMsg.msgData = static_cast<int>(WifiState::DISABLED);
716 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
717 WriteWifiOperateStateHiSysEvent(static_cast<int>(WifiOperateType::STA_CLOSE),
718 static_cast<int>(WifiOperateState::STA_CLOSED));
719 WriteWifiStateHiSysEvent(HISYS_SERVICE_TYPE_STA, WifiOperType::DISABLE);
720 return;
721 }
722 }
723
DispatchWifi2CloseRes(OperateResState state,int instId)724 void WifiServiceScheduler::DispatchWifi2CloseRes(OperateResState state, int instId)
725 {
726 WIFI_LOGI("DispatchWifi2CloseRes, state:%{public}d", static_cast<int>(state));
727 WifiEventCallbackMsg cbMsg;
728 cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE;
729 cbMsg.id = instId;
730 if (state == OperateResState::CLOSE_WIFI_CLOSING) {
731 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLING), instId);
732 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_DEACTIVATING, instId);
733 cbMsg.msgData = static_cast<int>(WifiState::DISABLING);
734 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
735 return;
736 }
737 if (state == OperateResState::CLOSE_WIFI_SUCCEED) {
738 WifiConfigCenter::GetInstance().SetWifiState(static_cast<int>(WifiState::DISABLED), instId);
739 WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_INACTIVE, instId);
740 WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
741 cbMsg.msgData = static_cast<int>(WifiState::DISABLED);
742 WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
743 return;
744 }
745 }
746
747 /*--------------------------------------------------softAp------------------------------------------------------------*/
748
749 #ifdef FEATURE_AP_SUPPORT
AutoStartApService(int instId,std::string & softApIfName)750 ErrCode WifiServiceScheduler::AutoStartApService(int instId, std::string &softApIfName)
751 {
752 WifiOprMidState apState = WifiConfigCenter::GetInstance().GetApMidState(instId);
753 WIFI_LOGE("AutoStartApService, current ap state:%{public}d", apState);
754 std::lock_guard<std::mutex> lock(mutex);
755 if (apState != WifiOprMidState::CLOSED) {
756 if (apState == WifiOprMidState::CLOSING) {
757 return WIFI_OPT_FAILED;
758 } else {
759 return WIFI_OPT_SUCCESS;
760 }
761 }
762 #ifdef HDI_CHIP_INTERFACE_SUPPORT
763 std::string ifaceName = "";
764 if (softApIfaceNameMap.count(instId) > 0) {
765 ifaceName = softApIfaceNameMap[instId];
766 }
767 if (ifaceName.empty() && !DelayedSingleton<HalDeviceManager>::GetInstance()->CreateApIface(
768 std::bind(&WifiServiceScheduler::SoftApIfaceDestoryCallback,
769 this, std::placeholders::_1, std::placeholders::_2),
770 ifaceName)) {
771 WIFI_LOGE("AutoStartApService, create iface failed!");
772 return WIFI_OPT_FAILED;
773 }
774 WifiConfigCenter::GetInstance().SetApIfaceName(ifaceName);
775 softApIfName = ifaceName;
776 softApIfaceNameMap.insert(std::make_pair(instId, ifaceName));
777 #endif
778 if (!WifiConfigCenter::GetInstance().SetApMidState(apState, WifiOprMidState::OPENING, 0)) {
779 WIFI_LOGE("AutoStartApService, set ap mid state opening failed!");
780 return WIFI_OPT_FAILED;
781 }
782 ErrCode errCode = TryToStartApService(instId);
783 if (errCode != WIFI_OPT_SUCCESS) {
784 WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::OPENING, WifiOprMidState::CLOSED, instId);
785 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_AP, instId);
786 return errCode;
787 }
788 WifiManager::GetInstance().GetWifiHotspotManager()->StopUnloadApSaTimer();
789 return WIFI_OPT_SUCCESS;
790 }
791
AutoStopApService(int instId)792 ErrCode WifiServiceScheduler::AutoStopApService(int instId)
793 {
794 WifiOprMidState apState = WifiConfigCenter::GetInstance().GetApMidState(instId);
795 WIFI_LOGE("AutoStopApService, current ap state:%{public}d", apState);
796 std::lock_guard<std::mutex> lock(mutex);
797 if (apState != WifiOprMidState::RUNNING) {
798 if (apState == WifiOprMidState::OPENING) {
799 return WIFI_OPT_CLOSE_FAIL_WHEN_OPENING;
800 } else {
801 return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
802 }
803 }
804
805 if (!WifiConfigCenter::GetInstance().SetApMidState(apState, WifiOprMidState::CLOSING, instId)) {
806 WIFI_LOGE("AutoStopApService,set ap mid state closing failed!");
807 return WIFI_OPT_SUCCESS;
808 }
809
810 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(instId);
811 if (pService == nullptr) {
812 WIFI_LOGE("AutoStopApService, Instance get hotspot service is null!");
813 WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::CLOSED, instId);
814 WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_AP, instId);
815 return WIFI_OPT_SUCCESS;
816 }
817
818 ErrCode ret = pService->DisableHotspot();
819 if (ret != WIFI_OPT_SUCCESS) {
820 WIFI_LOGE("service disable ap failed, ret %{public}d!", static_cast<int>(ret));
821 WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::CLOSING, WifiOprMidState::RUNNING, instId);
822 return ret;
823 }
824 return WIFI_OPT_SUCCESS;
825 }
826
TryToStartApService(int instId)827 ErrCode WifiServiceScheduler::TryToStartApService(int instId)
828 {
829 ErrCode errCode = WIFI_OPT_FAILED;
830 do {
831 if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_AP) < 0) {
832 WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_AP);
833 break;
834 }
835 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(instId);
836 if (pService == nullptr) {
837 WIFI_LOGE("Instance get hotspot service is null!");
838 break;
839 }
840 errCode = pService->RegisterApServiceCallbacks(
841 WifiManager::GetInstance().GetWifiHotspotManager()->GetApCallback());
842 if (errCode != WIFI_OPT_SUCCESS) {
843 WIFI_LOGE("Register ap service callback failed!");
844 break;
845 }
846 errCode = pService->RegisterApServiceCallbacks(WifiCountryCodeManager::GetInstance().GetApCallback());
847 if (errCode != WIFI_OPT_SUCCESS) {
848 WIFI_LOGE("WifiCountryCodeManager Register ap service callback failed! ret %{public}d!",
849 static_cast<int>(errCode));
850 break;
851 }
852 errCode = pService->EnableHotspot();
853 if (errCode != WIFI_OPT_SUCCESS) {
854 WIFI_LOGE("service enable ap failed, ret %{public}d!", static_cast<int>(errCode));
855 break;
856 }
857 } while (false);
858 return errCode;
859 }
860
861 #ifdef HDI_CHIP_INTERFACE_SUPPORT
SoftApIfaceDestoryCallback(std::string & destoryIfaceName,int createIfaceType)862 void WifiServiceScheduler::SoftApIfaceDestoryCallback(std::string &destoryIfaceName, int createIfaceType)
863 {
864 WIFI_LOGI("IfaceDestoryCallback, ifaceName:%{public}s, ifaceType:%{public}d",
865 destoryIfaceName.c_str(), createIfaceType);
866 auto iter = softApIfaceNameMap.begin();
867 while (iter != softApIfaceNameMap.end()) {
868 if (destoryIfaceName == iter->second) {
869 auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
870 ins->SendMessage(CMD_AP_REMOVED, createIfaceType, iter->first);
871 softApIfaceNameMap.erase(iter);
872 return;
873 }
874 iter++;
875 }
876 }
877 #endif
878 #endif
879 }
880 }