1 /*
2 * Copyright (C) 2021-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 "wifi_hotspot_service_impl.h"
17 #include <csignal>
18 #include <limits>
19 #include "wifi_permission_utils.h"
20 #include "wifi_global_func.h"
21 #include "wifi_auth_center.h"
22 #include "wifi_channel_helper.h"
23 #include "wifi_manager.h"
24 #include "wifi_service_manager.h"
25 #include "wifi_internal_event_dispatcher.h"
26 #include "wifi_logger.h"
27 #include "define.h"
28 #include "wifi_logger.h"
29 #include "wifi_common_util.h"
30 #include "wifi_country_code_manager.h"
31 #include "mac_address.h"
32 #include "wifi_randommac_helper.h"
33
34 DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspotServiceImpl");
35
36 namespace OHOS {
37 namespace Wifi {
WifiHotspotServiceImpl()38 WifiHotspotServiceImpl::WifiHotspotServiceImpl()
39 {}
40
WifiHotspotServiceImpl(int id)41 WifiHotspotServiceImpl::WifiHotspotServiceImpl(int id) : WifiHotspotStub(id)
42 {}
43
~WifiHotspotServiceImpl()44 WifiHotspotServiceImpl::~WifiHotspotServiceImpl()
45 {}
46
IsHotspotActive(bool & bActive)47 ErrCode WifiHotspotServiceImpl::IsHotspotActive(bool &bActive)
48 {
49 WIFI_LOGI("Instance %{public}d %{public}s!", m_id, __func__);
50 if (!WifiAuthCenter::IsSystemAccess()) {
51 WIFI_LOGE("IsHotspotActive:NOT System APP, PERMISSION_DENIED!");
52 return WIFI_OPT_NON_SYSTEMAPP;
53 }
54 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
55 WIFI_LOGE("IsHotspotActive:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
56 return WIFI_OPT_PERMISSION_DENIED;
57 }
58
59 bActive = IsApServiceRunning();
60 return WIFI_OPT_SUCCESS;
61 }
62
IsHotspotDualBandSupported(bool & isSupported)63 ErrCode WifiHotspotServiceImpl::IsHotspotDualBandSupported(bool &isSupported)
64 {
65 WIFI_LOGI("IsHotspotDualBandSupported");
66 if (!WifiAuthCenter::IsSystemAccess()) {
67 WIFI_LOGE("IsHotspotDualBandSupported:NOT System APP, PERMISSION_DENIED!");
68 return WIFI_OPT_NON_SYSTEMAPP;
69 }
70 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
71 WIFI_LOGE("IsHotspotDualBandSupported:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
72 return WIFI_OPT_PERMISSION_DENIED;
73 }
74
75 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
76 WIFI_LOGE("IsHotspotDualBandSupported:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
77 return WIFI_OPT_PERMISSION_DENIED;
78 }
79
80 std::vector<BandType> bands;
81 if (WifiChannelHelper::GetInstance().GetValidBands(bands) < 0) {
82 WIFI_LOGE("IsHotspotDualBandSupported:GetValidBands return failed!");
83 return WIFI_OPT_FAILED;
84 }
85
86 bool is2GSupported = false;
87 bool is5GSupported = false;
88 isSupported = false;
89 for (size_t i = 0; i < bands.size(); i++) {
90 if (bands[i] == BandType::BAND_2GHZ) {
91 is2GSupported = true;
92 } else if (bands[i] == BandType::BAND_5GHZ) {
93 is5GSupported = true;
94 }
95 if (is2GSupported && is5GSupported) {
96 isSupported = true;
97 break;
98 }
99 }
100
101 WIFI_LOGI("2.4G band supported: %{public}d, 5G band supported: %{public}d", is2GSupported, is5GSupported);
102 return WIFI_OPT_SUCCESS;
103 }
104
GetHotspotState(int & state)105 ErrCode WifiHotspotServiceImpl::GetHotspotState(int &state)
106 {
107 WIFI_LOGI("Instance %{public}d %{public}s!", m_id, __func__);
108 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
109 WIFI_LOGE("GetHotspotState:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
110 return WIFI_OPT_PERMISSION_DENIED;
111 }
112
113 if (WifiPermissionUtils::VerifySetWifiConfigPermission() == PERMISSION_DENIED) {
114 WIFI_LOGE("GetHotspotState:VerifySetWifiConfigPermission PERMISSION_DENIED!");
115 return WIFI_OPT_PERMISSION_DENIED;
116 }
117
118 state = WifiConfigCenter::GetInstance().GetHotspotState(m_id);
119 return WIFI_OPT_SUCCESS;
120 }
121
GetHotspotConfig(HotspotConfig & result)122 ErrCode WifiHotspotServiceImpl::GetHotspotConfig(HotspotConfig &result)
123 {
124 WIFI_LOGI("Instance %{public}d %{public}s!", m_id, __func__);
125 if (!WifiAuthCenter::IsSystemAccess()) {
126 WIFI_LOGE("GetHotspotConfig:NOT System APP, PERMISSION_DENIED!");
127 return WIFI_OPT_NON_SYSTEMAPP;
128 }
129 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
130 WIFI_LOGE("GetHotspotConfig:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
131 return WIFI_OPT_PERMISSION_DENIED;
132 }
133
134 if (WifiPermissionUtils::VerifyGetWifiConfigPermission() == PERMISSION_DENIED) {
135 WIFI_LOGE("GetHotspotConfig:VerifyGetWifiConfigPermission PERMISSION_DENIED!");
136 return WIFI_OPT_PERMISSION_DENIED;
137 }
138
139 WifiSettings::GetInstance().GetHotspotConfig(result, m_id);
140 return WIFI_OPT_SUCCESS;
141 }
142
SetHotspotConfig(const HotspotConfig & config)143 ErrCode WifiHotspotServiceImpl::SetHotspotConfig(const HotspotConfig &config)
144 {
145 WIFI_LOGI("Instance %{public}d %{public}s band:%{public}d, channel:%{public}d", m_id, __func__,
146 static_cast<int>(config.GetBand()), config.GetChannel());
147 if (!WifiAuthCenter::IsSystemAccess()) {
148 WIFI_LOGE("SetHotspotConfig:NOT System APP, PERMISSION_DENIED!");
149 return WIFI_OPT_NON_SYSTEMAPP;
150 }
151 if (WifiPermissionUtils::VerifySetWifiInfoPermission() == PERMISSION_DENIED) {
152 WIFI_LOGE("SetHotspotConfig:VerifySetWifiInfoPermission PERMISSION_DENIED!");
153 return WIFI_OPT_PERMISSION_DENIED;
154 }
155
156 if (WifiPermissionUtils::VerifyGetWifiConfigPermission() == PERMISSION_DENIED) {
157 WIFI_LOGE("SetHotspotConfig:VerifyGetWifiConfigPermission PERMISSION_DENIED!");
158 return WIFI_OPT_PERMISSION_DENIED;
159 }
160
161 if (!mGetChannels) {
162 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
163 if (IsApServiceRunning() && pService != nullptr) {
164 std::vector<int32_t> valid2GChannel;
165 std::vector<int32_t> valid5GChannel;
166 (void)pService->GetValidChannels(BandType::BAND_2GHZ, valid2GChannel);
167 (void)pService->GetValidChannels(BandType::BAND_5GHZ, valid5GChannel);
168 if (valid2GChannel.size() + valid5GChannel.size() == 0) {
169 WIFI_LOGE("Failed to get supported band and channel!");
170 } else {
171 mGetChannels = true;
172 }
173 } else {
174 WIFI_LOGE("Instance %{public}d, ap service is not started!", m_id);
175 }
176 }
177 std::vector<BandType> bandsFromCenter;
178 WifiChannelHelper::GetInstance().GetValidBands(bandsFromCenter);
179 ChannelsTable channInfoFromCenter;
180 WifiChannelHelper::GetInstance().GetValidChannels(channInfoFromCenter);
181 HotspotConfig configFromCenter;
182 WifiSettings::GetInstance().GetHotspotConfig(configFromCenter, m_id);
183 ErrCode validRetval = IsValidHotspotConfig(config, configFromCenter, bandsFromCenter, channInfoFromCenter);
184 if (validRetval != ErrCode::WIFI_OPT_SUCCESS) {
185 WIFI_LOGE("Instance %{public}d Hotspot config is invalid!", m_id);
186 return validRetval;
187 }
188
189 WifiLinkedInfo linkInfo;
190 for (int i = 0; i < STA_INSTANCE_MAX_NUM; ++i) {
191 WifiConfigCenter::GetInstance().GetLinkedInfo(linkInfo, i);
192 if (!linkInfo.ssid.empty() && linkInfo.ssid == config.GetSsid()) {
193 WIFI_LOGE("set ssid equal current linked ap ssid, no permission!");
194 return WIFI_OPT_INVALID_PARAM;
195 }
196 }
197
198 if (!IsApServiceRunning() ||
199 WifiServiceManager::GetInstance().ApServiceSetHotspotConfig(config, m_id) == false) {
200 WifiSettings::GetInstance().SetHotspotConfig(config, m_id);
201 WifiSettings::GetInstance().SyncHotspotConfig();
202 }
203 return WIFI_OPT_SUCCESS;
204 }
205
SetHotspotIdleTimeout(int time)206 ErrCode WifiHotspotServiceImpl::SetHotspotIdleTimeout(int time)
207 {
208 WIFI_LOGI("SetHotspotIdleTimeout");
209 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
210 WIFI_LOGE("SetHotspotIdleTimeout:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
211 return WIFI_OPT_PERMISSION_DENIED;
212 }
213 /* Set the hotspot idle timeout unit to 1 minute */
214 constexpr int hotspotIdleTimeoutUnit = 60000;
215 int maxValue = std::numeric_limits<int>::max() / hotspotIdleTimeoutUnit;
216 if (maxValue <= time || time < 0) {
217 WIFI_LOGE("SetHotspotIdleTimeout invalid time:%{public}d maxValue is %{public}d", time, maxValue);
218 return WIFI_OPT_INVALID_PARAM;
219 }
220 int delayTime = time * hotspotIdleTimeoutUnit;
221 if (!IsApServiceRunning()) {
222 WifiConfigCenter::GetInstance().SetHotspotIdleTimeout(delayTime);
223 } else {
224 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst();
225 if (pService == nullptr) {
226 return WIFI_OPT_AP_NOT_OPENED;
227 }
228 return pService->SetHotspotIdleTimeout(delayTime);
229 }
230 return WIFI_OPT_SUCCESS;
231 }
232
GetStationList(std::vector<StationInfo> & result)233 ErrCode WifiHotspotServiceImpl::GetStationList(std::vector<StationInfo> &result)
234 {
235 WIFI_LOGI("Instance %{public}d %{public}s!", m_id, __func__);
236 int apiVersion = WifiPermissionUtils::GetApiVersion();
237 if (apiVersion < API_VERSION_9 && apiVersion != API_VERSION_INVALID) {
238 WIFI_LOGE("%{public}s The version %{public}d is too early to be supported", __func__, apiVersion);
239 return WIFI_OPT_PERMISSION_DENIED;
240 }
241 if (!WifiAuthCenter::IsSystemAccess()) {
242 WIFI_LOGE("GetStationList:NOT System APP, PERMISSION_DENIED!");
243 return WIFI_OPT_NON_SYSTEMAPP;
244 }
245 if (apiVersion == API_VERSION_9) {
246 #ifndef SUPPORT_RANDOM_MAC_ADDR
247 if (WifiPermissionUtils::VerifyGetScanInfosPermission() == PERMISSION_DENIED) {
248 WIFI_LOGE("GetStationList:VerifyGetScanInfosPermission PERMISSION_DENIED!");
249 return WIFI_OPT_PERMISSION_DENIED;
250 }
251 #endif
252 }
253 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
254 WIFI_LOGE("GetStationList:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
255 return WIFI_OPT_PERMISSION_DENIED;
256 }
257 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
258 WIFI_LOGE("GetStationList:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
259 return WIFI_OPT_PERMISSION_DENIED;
260 }
261
262 if (!IsApServiceRunning()) {
263 WIFI_LOGE("Instance %{public}d hotspot service is not running!", m_id);
264 return WIFI_OPT_AP_NOT_OPENED;
265 }
266
267 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
268 if (pService == nullptr) {
269 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
270 return WIFI_OPT_AP_NOT_OPENED;
271 }
272 ErrCode errCode = pService->GetStationList(result);
273 #ifdef SUPPORT_RANDOM_MAC_ADDR
274 if (WifiPermissionUtils::VerifyGetWifiPeersMacPermission() == PERMISSION_DENIED) {
275 WIFI_LOGI("%{public}s: GET_WIFI_PEERS_MAC PERMISSION_DENIED", __func__);
276 for (auto iter = result.begin(); iter != result.end(); ++iter) {
277 WifiMacAddrInfo macAddrInfo;
278 macAddrInfo.bssid = iter->bssid;
279 macAddrInfo.bssidType = iter->bssidType;
280 std::string randomMacAddr =
281 WifiConfigCenter::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, macAddrInfo);
282 if (!randomMacAddr.empty() &&
283 (macAddrInfo.bssidType == REAL_DEVICE_ADDRESS)) {
284 iter->bssid = randomMacAddr;
285 iter->bssidType = RANDOM_DEVICE_ADDRESS;
286 WIFI_LOGI("%{public}s: the record is updated, bssid:%{private}s, bssidType:%{public}d",
287 __func__, iter->bssid.c_str(), iter->bssidType);
288 }
289 }
290 }
291 #endif
292 return errCode;
293 }
294
TransRandomToRealMac(StationInfo & updateInfo,const StationInfo & info)295 ErrCode WifiHotspotServiceImpl::TransRandomToRealMac(StationInfo &updateInfo, const StationInfo &info)
296 {
297 if (MacAddress::IsValidMac(info.bssid)) {
298 if (info.bssidType > REAL_DEVICE_ADDRESS) {
299 WIFI_LOGE("%{public}s: invalid bssidType:%{public}d",
300 __func__, info.bssidType);
301 return WIFI_OPT_INVALID_PARAM;
302 }
303 WifiMacAddrInfo macAddrInfo;
304 macAddrInfo.bssid = info.bssid;
305 macAddrInfo.bssidType = info.bssidType;
306 std::string macAddr =
307 WifiConfigCenter::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, macAddrInfo);
308 if (macAddr.empty()) {
309 WIFI_LOGW("no record found, bssid:%{private}s, bssidType:%{public}d",
310 macAddrInfo.bssid.c_str(), macAddrInfo.bssidType);
311 } else {
312 WIFI_LOGI("%{public}s: find the record, bssid:%{private}s, bssidType:%{public}d, randomMac:%{private}s",
313 __func__, info.bssid.c_str(), info.bssidType, macAddr.c_str());
314 /* random MAC address are translated into real MAC address */
315 if (info.bssidType == RANDOM_DEVICE_ADDRESS) {
316 updateInfo.bssid = macAddr;
317 updateInfo.bssidType = REAL_DEVICE_ADDRESS;
318 WIFI_LOGI("%{public}s: the record is updated, bssid:%{private}s, bssidType:%{public}d",
319 __func__, updateInfo.bssid.c_str(), updateInfo.bssidType);
320 }
321 }
322 } else {
323 WIFI_LOGW("invalid mac address");
324 }
325 return WIFI_OPT_SUCCESS;
326 }
327
DisassociateSta(const StationInfo & info)328 ErrCode WifiHotspotServiceImpl::DisassociateSta(const StationInfo &info)
329 {
330 WIFI_LOGI("Instance %{public}d %{public}s device name [%{private}s]", m_id, __func__,
331 info.deviceName.c_str());
332 if (WifiPermissionUtils::VerifySetWifiInfoPermission() == PERMISSION_DENIED) {
333 WIFI_LOGE("DisassociateSta:VerifySetWifiInfoPermission PERMISSION_DENIED!");
334 return WIFI_OPT_PERMISSION_DENIED;
335 }
336 if (!WifiAuthCenter::IsSystemAccess()) {
337 WIFI_LOGE("DisassociateSta:IsSystemAppByToken NOT System APP, PERMISSION_DENIED!");
338 return WIFI_OPT_NON_SYSTEMAPP;
339 }
340 if (CheckMacIsValid(info.bssid)) {
341 return WIFI_OPT_INVALID_PARAM;
342 }
343 if (!IsApServiceRunning()) {
344 return WIFI_OPT_AP_NOT_OPENED;
345 }
346 StationInfo updateInfo = info;
347 #ifdef SUPPORT_RANDOM_MAC_ADDR
348 TransRandomToRealMac(updateInfo, info);
349 #endif
350 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
351 if (pService == nullptr) {
352 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
353 return WIFI_OPT_AP_NOT_OPENED;
354 }
355 return pService->DisconnetStation(updateInfo);
356 }
357
CheckOperHotspotSwitchPermission(const ServiceType type)358 int WifiHotspotServiceImpl::CheckOperHotspotSwitchPermission(const ServiceType type)
359 {
360 #ifdef FEATURE_AP_EXTENSION
361 return (type == ServiceType::WIFI_EXT) ? WifiPermissionUtils::VerifySetWifiInfoPermission() :
362 WifiPermissionUtils::VerifyManageWifiHotspotPermission();
363 #else
364 return (type == ServiceType::WIFI_EXT) ? PERMISSION_DENIED :
365 WifiPermissionUtils::VerifyManageWifiHotspotPermission();
366 #endif
367 }
368
CheckCanEnableHotspot(const ServiceType type)369 ErrCode WifiHotspotServiceImpl::CheckCanEnableHotspot(const ServiceType type)
370 {
371 if (!WifiAuthCenter::IsSystemAccess()) {
372 WIFI_LOGE("EnableHotspot:NOT System APP, PERMISSION_DENIED!");
373 return WIFI_OPT_NON_SYSTEMAPP;
374 }
375 if (CheckOperHotspotSwitchPermission(type) == PERMISSION_DENIED) {
376 WIFI_LOGE("EnableHotspot:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
377 return WIFI_OPT_PERMISSION_DENIED;
378 }
379
380 WifiManager::GetInstance().GetWifiEventSubscriberManager()->GetAirplaneModeByDatashare();
381 if (WifiConfigCenter::GetInstance().GetAirplaneModeState() == MODE_STATE_OPEN) {
382 WIFI_LOGI("current airplane mode and can not use ap, open failed!");
383 return WIFI_OPT_FORBID_AIRPLANE;
384 }
385 if (WifiConfigCenter::GetInstance().GetPowerSavingModeState() == 1) {
386 WIFI_LOGI("current power saving mode and can not use ap, open failed!");
387 return WIFI_OPT_FORBID_POWSAVING;
388 }
389
390 if (WifiManager::GetInstance().GetWifiMultiVapManager() == nullptr) {
391 WIFI_LOGE("GetWifiMultiVapManager Fail");
392 return WIFI_OPT_FAILED;
393 }
394
395 if (!WifiManager::GetInstance().GetWifiMultiVapManager()->CheckCanUseSoftAp()) {
396 WIFI_LOGE("SoftAp is not allowed to use");
397 return WIFI_OPT_FAILED;
398 }
399
400 return WIFI_OPT_SUCCESS;
401 }
402
EnableHotspot(const ServiceType type)403 ErrCode WifiHotspotServiceImpl::EnableHotspot(const ServiceType type)
404 {
405 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
406 ErrCode errCode = CheckCanEnableHotspot(type);
407 if (errCode != WIFI_OPT_SUCCESS) {
408 return errCode;
409 }
410
411 std::string bundleName = "";
412 if (!GetBundleNameByUid(GetCallingUid(), bundleName)) {
413 WIFI_LOGE("GetBundleNameByUid failed");
414 }
415 WIFI_LOGI("%{public}s calling inst %{public}d EnableHotspot", bundleName.c_str(), m_id);
416 HotspotMacConfig config;
417 WifiConfigCenter::GetInstance().GetHotspotMacConfig(config, m_id);
418 config.SetCallingBundleName(bundleName);
419 WifiConfigCenter::GetInstance().SetHotspotMacConfig(config, m_id);
420
421 return WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(1, m_id);
422 }
423
DisableHotspot(const ServiceType type)424 ErrCode WifiHotspotServiceImpl::DisableHotspot(const ServiceType type)
425 {
426 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
427 if (!WifiAuthCenter::IsSystemAccess()) {
428 WIFI_LOGE("DisableHotspot:NOT System APP, PERMISSION_DENIED!");
429 return WIFI_OPT_NON_SYSTEMAPP;
430 }
431 if (CheckOperHotspotSwitchPermission(type) == PERMISSION_DENIED) {
432 WIFI_LOGE("EnableHotspot:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
433 return WIFI_OPT_PERMISSION_DENIED;
434 }
435
436 return WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(0, m_id);
437 }
438
AddBlockList(const StationInfo & info)439 ErrCode WifiHotspotServiceImpl::AddBlockList(const StationInfo &info)
440 {
441 WIFI_LOGI("current ap service is %{public}d %{public}s"
442 " device name [%{private}s]", m_id, __func__, info.deviceName.c_str());
443 if (!WifiAuthCenter::IsSystemAccess()) {
444 WIFI_LOGE("AddBlockList:NOT System APP, PERMISSION_DENIED!");
445 return WIFI_OPT_NON_SYSTEMAPP;
446 }
447 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
448 WIFI_LOGE("AddBlockList:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
449 return WIFI_OPT_PERMISSION_DENIED;
450 }
451 if (WifiPermissionUtils::VerifySetWifiInfoPermission() == PERMISSION_DENIED) {
452 WIFI_LOGE("AddBlockList:VerifySetWifiInfoPermission PERMISSION_DENIED!");
453 return WIFI_OPT_PERMISSION_DENIED;
454 }
455 if (CheckMacIsValid(info.bssid)) {
456 return WIFI_OPT_INVALID_PARAM;
457 }
458 if (!IsApServiceRunning()) {
459 WIFI_LOGE("ApService is not running!");
460 return WIFI_OPT_AP_NOT_OPENED;
461 }
462 StationInfo updateInfo = info;
463 #ifdef SUPPORT_RANDOM_MAC_ADDR
464 TransRandomToRealMac(updateInfo, info);
465 #endif
466 if (WifiSettings::GetInstance().ManageBlockList(info, MODE_ADD, m_id) < 0) {
467 WIFI_LOGE("Add block list failed!");
468 return WIFI_OPT_FAILED;
469 }
470 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
471 if (pService == nullptr) {
472 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
473 return WIFI_OPT_AP_NOT_OPENED;
474 }
475 if (pService->AddBlockList(updateInfo) != WIFI_OPT_SUCCESS) {
476 WIFI_LOGE("AddBlockList: request add hotspot blocklist failed!");
477 return WIFI_OPT_FAILED;
478 }
479 if (pService->DisconnetStation(updateInfo) != WIFI_OPT_SUCCESS) {
480 WIFI_LOGE("AddBlockList: request disconnet station failed!");
481 return WIFI_OPT_FAILED;
482 }
483 return WIFI_OPT_SUCCESS;
484 }
485
DelBlockList(const StationInfo & info)486 ErrCode WifiHotspotServiceImpl::DelBlockList(const StationInfo &info)
487 {
488 WIFI_LOGI("current ap service is %{public}d %{public}s device name [%{private}s]",
489 m_id, __func__, info.deviceName.c_str());
490 if (!WifiAuthCenter::IsSystemAccess()) {
491 WIFI_LOGE("DelBlockList:NOT System APP, PERMISSION_DENIED!");
492 return WIFI_OPT_NON_SYSTEMAPP;
493 }
494 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
495 WIFI_LOGE("DelBlockList:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
496 return WIFI_OPT_PERMISSION_DENIED;
497 }
498
499 if (WifiPermissionUtils::VerifySetWifiInfoPermission() == PERMISSION_DENIED) {
500 WIFI_LOGE("DelBlockList:VerifySetWifiInfoPermission PERMISSION_DENIED!");
501 return WIFI_OPT_PERMISSION_DENIED;
502 }
503
504 if (CheckMacIsValid(info.bssid)) {
505 return WIFI_OPT_INVALID_PARAM;
506 }
507 StationInfo updateInfo = info;
508 #ifdef SUPPORT_RANDOM_MAC_ADDR
509 TransRandomToRealMac(updateInfo, info);
510 #endif
511 if (IsApServiceRunning()) {
512 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
513 if (pService == nullptr) {
514 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
515 return WIFI_OPT_AP_NOT_OPENED;
516 }
517 if (pService->DelBlockList(updateInfo) != WIFI_OPT_SUCCESS) {
518 WIFI_LOGE("request del hotspot blocklist failed!");
519 return WIFI_OPT_FAILED;
520 }
521 }
522
523 if (WifiSettings::GetInstance().ManageBlockList(info, MODE_DEL, m_id) < 0) {
524 WIFI_LOGE("Delete block list failed!");
525 return WIFI_OPT_FAILED;
526 }
527 return WIFI_OPT_SUCCESS;
528 }
529
GetValidBands(std::vector<BandType> & bands)530 ErrCode WifiHotspotServiceImpl::GetValidBands(std::vector<BandType> &bands)
531 {
532 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
533 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
534 WIFI_LOGE("GetValidBands:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
535 return WIFI_OPT_PERMISSION_DENIED;
536 }
537
538 if (WifiChannelHelper::GetInstance().GetValidBands(bands) < 0) {
539 return WIFI_OPT_FAILED;
540 }
541 return WIFI_OPT_SUCCESS;
542 }
543
GetValidChannels(BandType band,std::vector<int32_t> & validchannels)544 ErrCode WifiHotspotServiceImpl::GetValidChannels(BandType band, std::vector<int32_t> &validchannels)
545 {
546 WIFI_LOGI("current ap service is %{public}d %{public}s band %{public}d",
547 m_id, __func__, static_cast<int>(band));
548 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
549 WIFI_LOGE("GetValidChannels:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
550 return WIFI_OPT_PERMISSION_DENIED;
551 }
552
553 if (band == BandType::BAND_NONE) {
554 return WIFI_OPT_INVALID_PARAM;
555 }
556 ChannelsTable channInfoFromCenter;
557 WifiChannelHelper::GetInstance().GetValidChannels(channInfoFromCenter);
558 auto iter = channInfoFromCenter.find(band);
559 if (iter != channInfoFromCenter.end()) {
560 validchannels = iter->second;
561 }
562 return WIFI_OPT_SUCCESS;
563 }
564
GetBlockLists(std::vector<StationInfo> & infos)565 ErrCode WifiHotspotServiceImpl::GetBlockLists(std::vector<StationInfo> &infos)
566 {
567 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
568 if (!WifiAuthCenter::IsSystemAccess()) {
569 WIFI_LOGE("GetBlockLists:NOT System APP, PERMISSION_DENIED!");
570 return WIFI_OPT_NON_SYSTEMAPP;
571 }
572 if (WifiPermissionUtils::VerifyManageWifiHotspotPermission() == PERMISSION_DENIED) {
573 WIFI_LOGE("GetBlockLists:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
574 return WIFI_OPT_PERMISSION_DENIED;
575 }
576
577 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
578 WIFI_LOGE("GetBlockLists:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
579 return WIFI_OPT_PERMISSION_DENIED;
580 }
581 #ifdef SUPPORT_RANDOM_MAC_ADDR
582 if (WifiPermissionUtils::VerifyGetWifiPeersMacPermission() == PERMISSION_DENIED) {
583 WIFI_LOGI("%{public}s: GET_WIFI_PEERS_MAC PERMISSION_DENIED", __func__);
584 for (auto iter = infos.begin(); iter != infos.end(); ++iter) {
585 WifiMacAddrInfo macAddrInfo;
586 macAddrInfo.bssid = iter->bssid;
587 macAddrInfo.bssidType = iter->bssidType;
588 std::string randomMacAddr =
589 WifiConfigCenter::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, macAddrInfo);
590 if (randomMacAddr.empty()) {
591 WIFI_LOGI("%{public}s: GenerateRandomMacAddress", __func__);
592 WifiRandomMacHelper::GenerateRandomMacAddress(randomMacAddr);
593 }
594 if (!randomMacAddr.empty() &&
595 (macAddrInfo.bssidType == REAL_DEVICE_ADDRESS)) {
596 iter->bssid = randomMacAddr;
597 iter->bssidType = RANDOM_DEVICE_ADDRESS;
598 WIFI_LOGI("%{public}s: the record is updated, bssid:%{private}s, bssidType:%{public}d",
599 __func__, iter->bssid.c_str(), iter->bssidType);
600 }
601 }
602 }
603 #endif
604 if (WifiSettings::GetInstance().GetBlockList(infos, m_id) < 0) {
605 WIFI_LOGE("Get block list failed!");
606 return WIFI_OPT_FAILED;
607 }
608 return WIFI_OPT_SUCCESS;
609 }
610
IsApServiceRunning()611 bool WifiHotspotServiceImpl::IsApServiceRunning()
612 {
613 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
614 WifiOprMidState curState = WifiConfigCenter::GetInstance().GetApMidState(m_id);
615 if (curState != WifiOprMidState::RUNNING) {
616 WIFI_LOGI("current ap state is %{public}d", static_cast<int>(curState));
617 return false;
618 }
619 return true;
620 }
621
RegisterCallBack(const sptr<IWifiHotspotCallback> & callback,const std::vector<std::string> & event)622 ErrCode WifiHotspotServiceImpl::RegisterCallBack(const sptr<IWifiHotspotCallback> &callback,
623 const std::vector<std::string> &event)
624 {
625 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
626 if (WifiPermissionUtils::VerifyWifiConnectionPermission() == PERMISSION_DENIED) {
627 WIFI_LOGE("RegisterCallBack:VerifyWifiConnectionPermission() PERMISSION_DENIED!");
628 return WIFI_OPT_PERMISSION_DENIED;
629 }
630 WifiInternalEventDispatcher::GetInstance().SetSingleHotspotCallback(callback, m_id);
631 return WIFI_OPT_SUCCESS;
632 }
633
GetSupportedFeatures(long & features)634 ErrCode WifiHotspotServiceImpl::GetSupportedFeatures(long &features)
635 {
636 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
637 if (!WifiAuthCenter::IsSystemAccess()) {
638 WIFI_LOGE("GetSupportedFeatures:NOT System APP, PERMISSION_DENIED!");
639 return WIFI_OPT_NON_SYSTEMAPP;
640 }
641 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
642 WIFI_LOGE("GetSupportedFeatures:VerifyGetWifiInfoPermission() PERMISSION_DENIED!");
643 return WIFI_OPT_PERMISSION_DENIED;
644 }
645 int ret = WifiManager::GetInstance().GetSupportedFeatures(features);
646 if (ret < 0) {
647 WIFI_LOGE("Failed to get supported features!");
648 return WIFI_OPT_FAILED;
649 }
650 return WIFI_OPT_SUCCESS;
651 }
652
GetSupportedPowerModel(std::set<PowerModel> & setPowerModelList)653 ErrCode WifiHotspotServiceImpl::GetSupportedPowerModel(std::set<PowerModel>& setPowerModelList)
654 {
655 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
656 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
657 WIFI_LOGE("GetSupportedPowerModel:VerifyGetWifiInfoPermission() PERMISSION_DENIED!");
658 return WIFI_OPT_PERMISSION_DENIED;
659 }
660
661 if (!IsApServiceRunning()) {
662 return WIFI_OPT_AP_NOT_OPENED;
663 }
664 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
665 if (pService == nullptr) {
666 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
667 return WIFI_OPT_AP_NOT_OPENED;
668 }
669 pService->GetSupportedPowerModel(setPowerModelList);
670 return WIFI_OPT_SUCCESS;
671 }
672
GetPowerModel(PowerModel & model)673 ErrCode WifiHotspotServiceImpl::GetPowerModel(PowerModel& model)
674 {
675 WIFI_LOGI("current ap service is %{public}d %{public}s", m_id, __func__);
676 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
677 WIFI_LOGE("GetPowerModel:VerifyGetWifiInfoPermission() PERMISSION_DENIED!");
678 return WIFI_OPT_PERMISSION_DENIED;
679 }
680
681 if (!IsApServiceRunning()) {
682 return WIFI_OPT_AP_NOT_OPENED;
683 }
684 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
685 if (pService == nullptr) {
686 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
687 return WIFI_OPT_AP_NOT_OPENED;
688 }
689 pService->GetPowerModel(model);
690 return WIFI_OPT_SUCCESS;
691 }
692
SetPowerModel(const PowerModel & model)693 ErrCode WifiHotspotServiceImpl::SetPowerModel(const PowerModel& model)
694 {
695 WIFI_LOGI("SetPowerModel, m_id is %{public}d %{public}s", m_id, __func__);
696 if (WifiPermissionUtils::VerifySetWifiInfoPermission() == PERMISSION_DENIED) {
697 WIFI_LOGE("SetPowerModel:VerifySetWifiInfoPermission() PERMISSION_DENIED!");
698 return WIFI_OPT_PERMISSION_DENIED;
699 }
700
701 if (!IsApServiceRunning()) {
702 return WIFI_OPT_AP_NOT_OPENED;
703 }
704 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
705 if (pService == nullptr) {
706 WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
707 return WIFI_OPT_AP_NOT_OPENED;
708 }
709 pService->SetPowerModel(model);
710 return WIFI_OPT_SUCCESS;
711 }
712
ConfigInfoDump(std::string & result)713 void WifiHotspotServiceImpl::ConfigInfoDump(std::string& result)
714 {
715 HotspotConfig config;
716 WifiSettings::GetInstance().GetHotspotConfig(config);
717 std::stringstream ss;
718 ss << "Hotspot config: " << "\n";
719 ss << " Config.ssid: " << config.GetSsid() << "\n";
720
721 std::map<KeyMgmt, std::string> mapKeyMgmtToStr = {
722 {KeyMgmt::NONE, "Open"}, {KeyMgmt::WPA_PSK, "WPA_PSK"}, {KeyMgmt::WPA_EAP, "WPA_EAP"},
723 {KeyMgmt::IEEE8021X, "IEEE8021X"}, {KeyMgmt::WPA2_PSK, "WPA2_PSK"}, {KeyMgmt::OSEN, "OSEN"},
724 {KeyMgmt::FT_PSK, "FT_PSK"}, {KeyMgmt::FT_EAP, "FT_EAP"}
725 };
726
727 auto funcStrKeyMgmt = [&mapKeyMgmtToStr](KeyMgmt secType) {
728 std::map<KeyMgmt, std::string>::iterator iter = mapKeyMgmtToStr.find(secType);
729 return (iter != mapKeyMgmtToStr.end()) ? iter->second : "Unknown";
730 };
731 ss << " Config.security_type: " << funcStrKeyMgmt(config.GetSecurityType()) << "\n";
732
733 auto funcStrBand = [](BandType band) {
734 std::string retStr;
735 switch (band) {
736 case BandType::BAND_2GHZ:
737 retStr = "2.4GHz";
738 break;
739 case BandType::BAND_5GHZ:
740 retStr = "5GHz";
741 break;
742 case BandType::BAND_ANY:
743 retStr = "dual-mode frequency band";
744 break;
745 case BandType::BAND_6GHZ:
746 retStr = "6GHz";
747 break;
748 default:
749 retStr = "unknown band";
750 }
751 return retStr;
752 };
753 ss << " Config.band: " << funcStrBand(config.GetBand()) << "\n";
754 ss << " Config.channel: " << config.GetChannel() << "\n";
755 ss << " Config.max_conn: " << config.GetMaxConn() << "\n";
756 result += "\n";
757 result += ss.str();
758 result += "\n";
759 }
760
StationsInfoDump(std::string & result)761 void WifiHotspotServiceImpl::StationsInfoDump(std::string& result)
762 {
763 IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst();
764 if (pService != nullptr) {
765 std::stringstream ss;
766 std::vector<StationInfo> vecStations;
767 pService->GetStationList(vecStations);
768 ss << "Station list size: " << vecStations.size() << "\n";
769 int idx = 0;
770 for (auto& each : vecStations) {
771 ++idx;
772 ss << " Station[" << idx << "].deviceName: " << each.deviceName << "\n";
773 ss << " Station[" << idx << "].bssid: " << MacAnonymize(each.bssid) << "\n";
774 ss << " Station[" << idx << "].bssidType: " << each.bssidType << "\n";
775 ss << " Station[" << idx << "].ipAddr: " << IpAnonymize(each.ipAddr) << "\n";
776 ss << "\n";
777 }
778 result += ss.str();
779 result += "\n";
780 }
781
782 std::vector<StationInfo> vecBlockStations;
783 WifiSettings::GetInstance().GetBlockList(vecBlockStations);
784 if (!vecBlockStations.empty()) {
785 std::stringstream ss;
786 ss << "Block station list size: " << vecBlockStations.size() << "\n";
787 int idx = 0;
788 for (auto& each : vecBlockStations) {
789 ++idx;
790 ss << " BlockStation[" << idx << "].deviceName: " << each.deviceName << "\n";
791 ss << " BlockStation[" << idx << "].bssid: " << MacAnonymize(each.bssid) << "\n";
792 ss << " BlockStation[" << idx << "].bssidType: " << each.bssidType << "\n";
793 ss << " BlockStation[" << idx << "].ipAddr: " << IpAnonymize(each.ipAddr) << "\n";
794 ss << "\n";
795 }
796 result += ss.str();
797 result += "\n";
798 }
799 }
800
SaBasicDump(std::string & result)801 void WifiHotspotServiceImpl::SaBasicDump(std::string& result)
802 {
803 WifiHotspotServiceImpl impl;
804 bool isActive = impl.IsApServiceRunning();
805 result.append("WiFi hotspot active state: ");
806 std::string strActive = isActive ? "activated" : "inactive";
807 result += strActive + "\n";
808
809 if (isActive) {
810 ConfigInfoDump(result);
811 StationsInfoDump(result);
812 }
813 }
814
IsRemoteDied(void)815 bool WifiHotspotServiceImpl::IsRemoteDied(void)
816 {
817 return false;
818 }
819
CfgCheckSsid(const HotspotConfig & cfg)820 ErrCode WifiHotspotServiceImpl::CfgCheckSsid(const HotspotConfig &cfg)
821 {
822 if (cfg.GetSsid().length() < MIN_SSID_LEN || cfg.GetSsid().length() > MAX_SSID_LEN) {
823 LOGE("Config ssid length is invalid!");
824 return ErrCode::WIFI_OPT_INVALID_PARAM;
825 }
826 return ErrCode::WIFI_OPT_SUCCESS;
827 }
828
CfgCheckPsk(const HotspotConfig & cfg)829 ErrCode WifiHotspotServiceImpl::CfgCheckPsk(const HotspotConfig &cfg)
830 {
831 size_t len = cfg.GetPreSharedKey().length();
832 if (len < MIN_PSK_LEN || len > MAX_PSK_LEN) {
833 LOGE("PreSharedKey length error! invalid len: %{public}zu", len);
834 return ErrCode::WIFI_OPT_INVALID_PARAM;
835 }
836 return ErrCode::WIFI_OPT_SUCCESS;
837 }
838
CfgCheckBand(const HotspotConfig & cfg,std::vector<BandType> & bandsFromCenter)839 ErrCode WifiHotspotServiceImpl::CfgCheckBand(const HotspotConfig &cfg, std::vector<BandType> &bandsFromCenter)
840 {
841 for (auto it = bandsFromCenter.begin(); it != bandsFromCenter.end(); ++it) {
842 if (cfg.GetBand() == *it) {
843 return ErrCode::WIFI_OPT_SUCCESS;
844 }
845 }
846 LOGE("Hotspot config band is invalid!");
847 return ErrCode::WIFI_OPT_INVALID_PARAM;
848 }
849
CfgCheckChannel(const HotspotConfig & cfg,ChannelsTable & channInfoFromCenter)850 ErrCode WifiHotspotServiceImpl::CfgCheckChannel(const HotspotConfig &cfg, ChannelsTable &channInfoFromCenter)
851 {
852 std::vector<int32_t> channels = channInfoFromCenter[static_cast<BandType>(cfg.GetBand())];
853 auto it = find(channels.begin(), channels.end(), cfg.GetChannel());
854 return ((it == channels.end()) ? ErrCode::WIFI_OPT_INVALID_PARAM : ErrCode::WIFI_OPT_SUCCESS);
855 }
856
isNumber(std::string & str)857 static bool isNumber(std::string &str)
858 {
859 return !str.empty() && (str.find_first_not_of("0123456789") == std::string::npos);
860 }
861
CfgCheckIpAddress(const std::string & ipAddress)862 ErrCode WifiHotspotServiceImpl::CfgCheckIpAddress(const std::string &ipAddress)
863 {
864 if (ipAddress.empty()) {
865 WIFI_LOGI("CfgCheckIpAddress ipAddress is empty.");
866 return ErrCode::WIFI_OPT_SUCCESS;
867 }
868 std::vector<std::string> list{};
869 SplitString(ipAddress, ".", list);
870
871 if (list.size() != MAX_IPV4_SPLIT_LEN) {
872 WIFI_LOGE("CfgCheckIpAddress split size invalid.");
873 return ErrCode::WIFI_OPT_INVALID_PARAM;
874 }
875
876 for (auto str : list) {
877 if (!isNumber(str) || stoi(str) > MAX_IPV4_VALUE || stoi(str) < 0) {
878 WIFI_LOGE("CfgCheckIpAddress stoi failed.");
879 return ErrCode::WIFI_OPT_INVALID_PARAM;
880 }
881 }
882
883 std::vector ips = {"0.0.0.0", "255.255.255.255", "127.0.0.0"};
884 if (std::find(ips.begin(), ips.end(), ipAddress) != ips.end()) {
885 WIFI_LOGE("CfgCheckIpAddress unused ip range.");
886 return ErrCode::WIFI_OPT_INVALID_PARAM;
887 }
888
889 return ErrCode::WIFI_OPT_SUCCESS;
890 }
891
IsValidHotspotConfig(const HotspotConfig & cfg,const HotspotConfig & cfgFromCenter,std::vector<BandType> & bandsFromCenter,ChannelsTable & channInfoFromCenter)892 ErrCode WifiHotspotServiceImpl::IsValidHotspotConfig(const HotspotConfig &cfg, const HotspotConfig &cfgFromCenter,
893 std::vector<BandType> &bandsFromCenter, ChannelsTable &channInfoFromCenter)
894 {
895 if (CfgCheckIpAddress(cfg.GetIpAddress()) == ErrCode::WIFI_OPT_INVALID_PARAM) {
896 return ErrCode::WIFI_OPT_INVALID_PARAM;
897 }
898 if (cfg.GetMaxConn() <= 0 || cfg.GetMaxConn() > MAX_AP_CONN) {
899 LOGE("Open hotspot maxConn is illegal %{public}d !", cfg.GetMaxConn());
900 return ErrCode::WIFI_OPT_INVALID_PARAM;
901 }
902 if (CfgCheckSsid(cfg) == ErrCode::WIFI_OPT_INVALID_PARAM) {
903 return ErrCode::WIFI_OPT_INVALID_PARAM;
904 }
905
906 if (cfg.GetSecurityType() == KeyMgmt::NONE) {
907 if (cfg.GetPreSharedKey().length() > 0) {
908 LOGE("Open hotspot PreSharedKey length is non-zero error!");
909 return ErrCode::WIFI_OPT_INVALID_PARAM;
910 }
911 } else if (cfg.GetSecurityType() == KeyMgmt::WPA_PSK || cfg.GetSecurityType() == KeyMgmt::WPA2_PSK) {
912 if (CfgCheckPsk(cfg) == ErrCode::WIFI_OPT_INVALID_PARAM) {
913 return ErrCode::WIFI_OPT_INVALID_PARAM;
914 }
915 } else {
916 LOGE("Hotspot securityType is not supported!");
917 return ErrCode::WIFI_OPT_INVALID_PARAM;
918 }
919
920 if (cfg.GetBand() != cfgFromCenter.GetBand() && bandsFromCenter.size() != 0) {
921 if (CfgCheckBand(cfg, bandsFromCenter) == ErrCode::WIFI_OPT_INVALID_PARAM) {
922 return ErrCode::WIFI_OPT_INVALID_PARAM;
923 }
924 }
925
926 return ErrCode::WIFI_OPT_SUCCESS;
927 }
928
GetApIfaceName(std::string & ifaceName)929 ErrCode WifiHotspotServiceImpl::GetApIfaceName(std::string& ifaceName)
930 {
931 if (!WifiAuthCenter::IsSystemAccess()) {
932 WIFI_LOGE("GetBlockLists:NOT System APP, PERMISSION_DENIED!");
933 return WIFI_OPT_NON_SYSTEMAPP;
934 }
935 if (WifiPermissionUtils::VerifyGetWifiInfoPermission() == PERMISSION_DENIED) {
936 WIFI_LOGE("GetBlockLists:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
937 return WIFI_OPT_PERMISSION_DENIED;
938 }
939 ifaceName = WifiConfigCenter::GetInstance().GetApIfaceName();
940 return ErrCode::WIFI_OPT_SUCCESS;
941 }
942 } // namespace Wifi
943 } // namespace OHOS
944