diff --git a/wifi/frameworks/native/interfaces/define.h b/wifi/frameworks/native/interfaces/define.h index fa5252216..5699495de 100644 --- a/wifi/frameworks/native/interfaces/define.h +++ b/wifi/frameworks/native/interfaces/define.h @@ -116,4 +116,12 @@ #define INTERFACEDESCRIPTORL1 u"ohos.wifi.IWifiDeviceService" #define DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH (sizeof(INTERFACEDESCRIPTORL1)/sizeof(uint16_t)) #define DECLARE_INTERFACE_DESCRIPTOR_L1 ((uint16_t*)&INTERFACEDESCRIPTORL1[0]) + +/* Multilink */ +#define INSTID_WLAN0 (0) +#define INSTID_WLAN1 (1) +#ifndef STA_INSTANCE_MAX_NUM +#define STA_INSTANCE_MAX_NUM (2) #endif + +#endif \ No newline at end of file diff --git a/wifi/frameworks/native/src/wifi_device.cpp b/wifi/frameworks/native/src/wifi_device.cpp index 5d045e706..98bf19cf1 100644 --- a/wifi/frameworks/native/src/wifi_device.cpp +++ b/wifi/frameworks/native/src/wifi_device.cpp @@ -32,6 +32,7 @@ NO_SANITIZE("cfi") std::shared_ptr WifiDevice::GetInstance(int syste std::shared_ptr device = std::make_shared(); if (device && device->Init(systemAbilityId, instId)) { + WIFI_LOGI("Init instId%{public}d. %{public}d", instId, systemAbilityId); return device; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn index 573bcb2c5..2e41a6952 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/BUILD.gn @@ -468,6 +468,8 @@ if (defined(ohos_lite)) { sources = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_clientmode_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.cpp index a4ecc17ad..c6b7cacb1 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.cpp @@ -20,6 +20,7 @@ #include "wifi_common_util.h" #include "wifi_auth_center.h" #include "wifi_permission_utils.h" +#include "define.h" #ifdef SUPPORT_RANDOM_MAC_ADDR #include "wifi_p2p_msg.h" #include "wifi_common_msg.h" @@ -555,13 +556,13 @@ void WifiInternalEventDispatcher::DealStaCallbackMsg( switch (msg.msgCode) { case WIFI_CBK_MSG_STATE_CHANGE: - WifiInternalEventDispatcher::PublishWifiStateChangedEvent(msg.msgData); + WifiInternalEventDispatcher::PublishWifiStateChangedEvent(msg.msgData, msg.id); break; case WIFI_CBK_MSG_CONNECTION_CHANGE: - WifiInternalEventDispatcher::PublishConnStateChangedEvent(msg.msgData, msg.linkInfo); + WifiInternalEventDispatcher::PublishConnStateChangedEvent(msg.msgData, msg.id, msg.linkInfo); break; case WIFI_CBK_MSG_RSSI_CHANGE: - WifiInternalEventDispatcher::PublishRssiValueChangedEvent(msg.msgData); + WifiInternalEventDispatcher::PublishRssiValueChangedEvent(msg.msgData, msg.id); break; case WIFI_CBK_MSG_STREAM_DIRECTION: break; @@ -936,7 +937,7 @@ void WifiInternalEventDispatcher::DealP2pCallbackMsg( return; } -void WifiInternalEventDispatcher::PublishConnStateChangedEvent(int state, const WifiLinkedInfo &info) +void WifiInternalEventDispatcher::PublishConnStateChangedEvent(int state, int instId, const WifiLinkedInfo &info) { std::string eventData = "Other"; switch (state) { @@ -957,15 +958,20 @@ void WifiInternalEventDispatcher::PublishConnStateChangedEvent(int state, const break; } } - if (!WifiCommonEventHelper::PublishConnStateChangedEvent(state, eventData)) { - WIFI_LOGE("failed to publish connection state changed event,%{public}s!", eventData.c_str()); + if ((instId == INSTID_WLAN0 && WifiCommonEventHelper::PublishConnStateChangedEvent(state, eventData)) || + (instId == INSTID_WLAN1 && WifiCommonEventHelper::PublishWifi2ConnStateChangedEvent(state, eventData))) { + WIFI_LOGI("publish connection state changed event,%{public}s, instId %{public}d.", eventData.c_str(), instId); return; } - WIFI_LOGI("publish connection state changed event,%{public}s.", eventData.c_str()); + WIFI_LOGE("publish connection state changed event,%{public}s, instId %{public}d fail.", eventData.c_str(), instId); } -void WifiInternalEventDispatcher::PublishRssiValueChangedEvent(int state) +void WifiInternalEventDispatcher::PublishRssiValueChangedEvent(int state, int instId) { + if (instId == INSTID_WLAN1) { + WIFI_LOGW("PublishRssiValueChangedEvent instId wlan1!"); + return ; + } WifiLinkedInfo likedInfo; WifiConfigCenter::GetInstance().GetLinkedInfo(likedInfo); int signalLevel = WifiSettings::GetInstance().GetSignalLevel(state, likedInfo.band); @@ -977,13 +983,24 @@ void WifiInternalEventDispatcher::PublishRssiValueChangedEvent(int state) WIFI_LOGD("publish rssi value changed event."); } -void WifiInternalEventDispatcher::PublishWifiStateChangedEvent(int state) +void WifiInternalEventDispatcher::PublishWifiStateChangedEvent(int state, int instId) { - if (!WifiCommonEventHelper::PublishPowerStateChangeEvent(state, "OnWifiPowerStateChanged")) { - WIFI_LOGE("failed to publish wifi state changed event!"); - return; + if (instId == INSTID_WLAN0) { + if (!WifiCommonEventHelper::PublishPowerStateChangeEvent(state, "OnWifiPowerStateChanged")) { + WIFI_LOGE("failed to publish wifi state changed event!"); + return; + } + } else if (instId == INSTID_WLAN1) { + if (!WifiCommonEventHelper::PublishWifi2PowerStateChangeEvent(state, "OnWifiPowerStateChanged")) { + WIFI_LOGE("failed to publish wifi state changed event!"); + return; + } + } else { + WIFI_LOGE("invalid InstId!"); + return; } - WIFI_LOGD("publish wifi state changed event."); + + WIFI_LOGI("publish wifi state changed event, state %{public}d, instId %{public}d", state, instId); } bool WifiInternalEventDispatcher::VerifyRegisterCallbackPermission(int callbackEventId) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.h index 6a7d06a36..6c3f4cb08 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.h @@ -132,9 +132,9 @@ private: #ifdef SUPPORT_RANDOM_MAC_ADDR static void updateP2pDeviceMacAddress(std::vector &device); #endif - static void PublishConnStateChangedEvent(int state, const WifiLinkedInfo &info); - static void PublishWifiStateChangedEvent(int state); - static void PublishRssiValueChangedEvent(int state); + static void PublishConnStateChangedEvent(int state, int instId, const WifiLinkedInfo &info); + static void PublishWifiStateChangedEvent(int state, int instId); + static void PublishRssiValueChangedEvent(int state, int instId); static void SendConfigChangeEvent(sptr &callback, CfgInfo* cfgInfo); private: std::unique_ptr mBroadcastThread = nullptr; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_agent.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_agent.cpp index 19ca71cbd..4c8aff229 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_agent.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_agent.cpp @@ -232,7 +232,7 @@ void WifiNetAgent::OnStaMachineNetManagerRestart(const sptr &netLinkInfo, IpInfo &wifiIpInfo, IpV6Info &wifiIpV6Info, WifiProxyConfig &wifiProxyConfig, int instId) { - netLinkInfo->ifaceName_ = WifiConfigCenter::GetInstance().GetStaIfaceName(); + netLinkInfo->ifaceName_ = WifiConfigCenter::GetInstance().GetStaIfaceName(instId); SetNetLinkIPInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info); SetNetLinkRouteInfo(netLinkInfo, wifiIpInfo, wifiIpV6Info); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp index 18a97487e..166752248 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp @@ -59,10 +59,12 @@ ConcreteMangerMachine::~ConcreteMangerMachine() WifiConfigCenter::GetInstance().SetWifiStopState(false); #ifdef HDI_CHIP_INTERFACE_SUPPORT if (!ifaceName.empty()) { + WIFI_LOGW("destroy ConcreteMangerMachine RemoveStaIface ifaceName:%{public}s, instId:%{public}d", + ifaceName.c_str(), mid); DelayedSingleton::GetInstance()->RemoveStaIface(ifaceName); ifaceName.clear(); WifiServiceScheduler::GetInstance().ClearStaIfaceNameMap(mid); - WifiConfigCenter::GetInstance().SetStaIfaceName(""); + WifiConfigCenter::GetInstance().SetStaIfaceName("", mid); } #endif } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp new file mode 100644 index 000000000..8a276342b --- /dev/null +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software`` + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "multi_sta_manager.h" +#include "wifi_logger.h" + +DEFINE_WIFILOG_LABEL("MultiStaManager"); + +namespace OHOS { +namespace Wifi { +MultiStaManager::MultiStaManager(MultiStaManager::Role role, int id) : mid(id), curRole(role), + pMultiStaStateMachine(nullptr) +{} + +MultiStaManager::~MultiStaManager() +{ + WIFI_LOGE("Exit."); + if (pMultiStaStateMachine != nullptr) { + delete pMultiStaStateMachine; + } +} + +ErrCode MultiStaManager::InitMultiStaManager() +{ + pMultiStaStateMachine = new (std::nothrow) MultiStaStateMachine(); + if (pMultiStaStateMachine == nullptr) { + WIFI_LOGE("Alloc pMultiStaStateMachine failed.\n"); + return WIFI_OPT_FAILED; + } + if (pMultiStaStateMachine->InitMultiStaStateMachine() != WIFI_OPT_SUCCESS) { + WIFI_LOGE("InitMultiStaStateMachine failed.\n"); + return WIFI_OPT_FAILED; + } + pMultiStaStateMachine->RegisterCallback(mcb); + pMultiStaStateMachine->SendMessage(MULTI_STA_CMD_START, static_cast(curRole), mid); + return WIFI_OPT_SUCCESS; +} + +ErrCode MultiStaManager::RegisterCallback(const MultiStaModeCallback &callbacks) +{ + mcb = callbacks; + return WIFI_OPT_SUCCESS; +} + +MultiStaStateMachine *MultiStaManager::GetMultiStaMachine() +{ + return pMultiStaStateMachine; +} + +void MultiStaManager::SetRole(Role role) +{ + curRole = role; +} + +MultiStaManager::Role MultiStaManager::GetRole() +{ + return curRole; +} + +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.h new file mode 100644 index 000000000..6bbb91381 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_MULTI_STA_MANAGER_H +#define OHOS_MULTI_STA_MANAGER_H + +#include +#include +#include "wifi_errcode.h" +#include "multi_sta_state_machine.h" + +namespace OHOS { +namespace Wifi { +class MultiStaManager { +public: + enum class Role { + ROLE_UNKNOW = -1, + ROLE_STA_WIFI_2 = 0, + ROLE_STA_2_REMOVED = 1, + }; + + explicit MultiStaManager(MultiStaManager::Role role, int id); + ErrCode RegisterCallback(const MultiStaModeCallback &callbacks); + ~MultiStaManager(); + ErrCode InitMultiStaManager(); + void SetRole(Role role); + Role GetRole(); + MultiStaStateMachine *GetMultiStaMachine(); + int mid; + +private: + MultiStaManager::Role curRole; + MultiStaModeCallback mcb; + MultiStaStateMachine *pMultiStaStateMachine; +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp new file mode 100644 index 000000000..9b092ed08 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "multi_sta_state_machine.h" +#include "wifi_manager.h" +#include "wifi_service_manager.h" +#include "wifi_config_center.h" +#include "wifi_chip_hal_interface.h" +#include "wifi_internal_event_dispatcher.h" +#include "wifi_settings.h" +#include "wifi_common_event_helper.h" +#include "wifi_service_scheduler.h" +#include "i_ap_service.h" +#ifdef HDI_CHIP_INTERFACE_SUPPORT +#include "hal_device_manage.h" +#endif + +namespace OHOS { +namespace Wifi { +DEFINE_WIFILOG_LABEL("MultiStaStateMachine"); +int MultiStaStateMachine::mid{0}; + +MultiStaStateMachine::MultiStaStateMachine() + : StateMachine("MultiStaStateMachine"), pDefaultState(nullptr), pIdleState(nullptr), pStartedState(nullptr) +{} + +MultiStaStateMachine::~MultiStaStateMachine() +{ + WIFI_LOGE("MultiStaStateMachine::~MultiStaStateMachine"); + StopHandlerThread(); + ParsePointer(pDefaultState); + ParsePointer(pIdleState); + ParsePointer(pStartedState); +#ifdef HDI_CHIP_INTERFACE_SUPPORT + if (!ifaceName.empty()) { + WIFI_LOGW("~MultiStaStateMachine ifaceName: %{public}s,instId:%{public}d", + ifaceName.c_str(), mid); + DelayedSingleton::GetInstance()->RemoveStaIface(ifaceName); + ifaceName.clear(); + WifiServiceScheduler::GetInstance().ClearStaIfaceNameMap(mid); + WifiConfigCenter::GetInstance().SetStaIfaceName("", mid); + } +#endif +} + +/* --------------------------Initialization functions--------------------------*/ +ErrCode MultiStaStateMachine::InitMultiStaStateMachine() +{ + WIFI_LOGI("Enter MultiStaStateMachine::InitMultiStaStateMachine.\n"); + if (!InitialStateMachine("MultiStaStateMachine")) { + WIFI_LOGE("Initial StateMachine failed.\n"); + return WIFI_OPT_FAILED; + } + + if (InitMultiStaStates() == WIFI_OPT_FAILED) { + return WIFI_OPT_FAILED; + } + BuildStateTree(); + SetFirstState(pIdleState); + StartStateMachine(); + return WIFI_OPT_SUCCESS; +} + +void MultiStaStateMachine::BuildStateTree() +{ + StatePlus(pDefaultState, nullptr); + StatePlus(pIdleState, pDefaultState); + StatePlus(pStartedState, pDefaultState); +} + +ErrCode MultiStaStateMachine::InitMultiStaStates() +{ + int tmpErrNumber; + + WIFI_LOGE("Enter MultiStaStateMachine\n"); + pDefaultState = new (std::nothrow) DefaultState(this); + tmpErrNumber = JudgmentEmpty(pDefaultState); + pIdleState = new (std::nothrow) IdleState(this); + tmpErrNumber += JudgmentEmpty(pIdleState); + pStartedState = new (std::nothrow) StartedState(this); + tmpErrNumber += JudgmentEmpty(pStartedState); + if (tmpErrNumber != 0) { + WIFI_LOGE("InitMultiStaStates some one state is null\n"); + return WIFI_OPT_FAILED; + } + return WIFI_OPT_SUCCESS; +} + +ErrCode MultiStaStateMachine::RegisterCallback(const MultiStaModeCallback &callbacks) +{ + mcb = callbacks; + return WIFI_OPT_SUCCESS; +} + +MultiStaStateMachine::DefaultState::DefaultState(MultiStaStateMachine *multiStaStateMachine) + : State("DefaultState"), pMultiStaStateMachine(multiStaStateMachine) +{} + +MultiStaStateMachine::DefaultState::~DefaultState() +{} + +void MultiStaStateMachine::DefaultState::GoInState() +{ + WIFI_LOGE("DefaultState GoInState function.\n"); +} + +void MultiStaStateMachine::DefaultState::GoOutState() +{ + WIFI_LOGE("DefaultState GoOutState function.\n"); +} + +bool MultiStaStateMachine::DefaultState::ExecuteStateMsg(InternalMessagePtr msg) +{ + if (msg == nullptr || pMultiStaStateMachine == nullptr) { + return false; + } + WIFI_LOGE("DefaultState-msgCode=%{public}d is received.\n", msg->GetMessageName()); + return true; +} + +MultiStaStateMachine::IdleState::IdleState(MultiStaStateMachine *multiStaStateMachine) + : State("IdleState"), pMultiStaStateMachine(multiStaStateMachine) +{} + +MultiStaStateMachine::IdleState::~IdleState() +{} + +void MultiStaStateMachine::IdleState::GoInState() +{ + WIFI_LOGE("IdleState GoInState function.\n"); +} + +void MultiStaStateMachine::IdleState::GoOutState() +{ + WIFI_LOGE("IdleState GoOutState function.\n"); +} + +bool MultiStaStateMachine::IdleState::ExecuteStateMsg(InternalMessagePtr msg) +{ + if (msg == nullptr) { + return false; + } + WIFI_LOGI("IdleState-msgCode=%{public}d is received.\n", msg->GetMessageName()); + switch (msg->GetMessageName()) { + case MULTI_STA_CMD_START: + HandleStartInIdleState(msg); + break; + case MULTI_STA_CMD_STOP: + break; + case MULTI_STA_CMD_STARTED: + pMultiStaStateMachine->SwitchState(pMultiStaStateMachine->pStartedState); + break; + default: + break; + } + return true; +} + +void MultiStaStateMachine::IdleState::HandleStartInIdleState(InternalMessagePtr msg) +{ + mid = msg->GetParam2(); + ErrCode ret = WifiServiceScheduler::GetInstance().AutoStartWifi2Service(mid, pMultiStaStateMachine->ifaceName); + if (ret != WIFI_OPT_SUCCESS) { + WIFI_LOGE("IdelState start wifi2 fail.\n"); + pMultiStaStateMachine->mcb.onStartFailure(mid); + return; + } +} + +MultiStaStateMachine::StartedState::StartedState(MultiStaStateMachine *multiStaStateMachine) + : State("StartedState"), pMultiStaStateMachine(multiStaStateMachine) +{} + +MultiStaStateMachine::StartedState::~StartedState() +{} + +void MultiStaStateMachine::StartedState::GoInState() +{ + WIFI_LOGE("StartedState GoInState function.\n"); +} + +void MultiStaStateMachine::StartedState::GoOutState() +{ + WIFI_LOGE("StartedState GoOutState function.\n"); +} + +bool MultiStaStateMachine::StartedState::ExecuteStateMsg(InternalMessagePtr msg) +{ + if (msg == nullptr) { + return false; + } + WIFI_LOGE("StartedState-msgCode=%{public}d is received.\n", msg->GetMessageName()); + ErrCode ret = WIFI_OPT_FAILED; + switch (msg->GetMessageName()) { + case MULTI_STA_CMD_STOP: + ret = WifiServiceScheduler::GetInstance().AutoStopWifi2Service(mid); + if (ret != WIFI_OPT_SUCCESS) { + WIFI_LOGE("AutoStopWifi2Service fail.\n"); + } + pMultiStaStateMachine->mcb.onStopped(mid); + break; + default: + break; + } + return true; +} + +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.h new file mode 100644 index 000000000..a04967bce --- /dev/null +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.h @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MULTI_STA_STATE_MACHINE_H +#define MULTI_STA_STATE_MACHINE_H + +#include "state.h" +#include "state_machine.h" +#include "wifi_logger.h" +#include "wifi_errcode.h" +#include +#include "wifi_ap_msg.h" +#include "wifi_internal_msg.h" +#include "wifi_controller_define.h" + +namespace OHOS { +namespace Wifi { +class MultiStaStateMachine : public StateMachine { +public: + MultiStaStateMachine(); + ~MultiStaStateMachine(); + + class IdleState : public State { + public: + explicit IdleState(MultiStaStateMachine *multiStaStateMachine); + ~IdleState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessagePtr msg) override; + + private: + MultiStaStateMachine *pMultiStaStateMachine; + void HandleStartInIdleState(InternalMessagePtr msg); + }; + + class DefaultState : public State { + public: + explicit DefaultState(MultiStaStateMachine *multiStaStateMachine); + ~DefaultState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessagePtr msg) override; + + private: + MultiStaStateMachine *pMultiStaStateMachine; + }; + + class StartedState : public State { + public: + explicit StartedState(MultiStaStateMachine *multiStaStateMachine); + ~StartedState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessagePtr msg) override; + + private: + MultiStaStateMachine *pMultiStaStateMachine; + }; + +public: + ErrCode InitMultiStaStateMachine(); + ErrCode RegisterCallback(const MultiStaModeCallback &callbacks); + +private: + template + inline void ParsePointer(T *&pointer) + { + if (pointer != nullptr) { + delete pointer; + pointer = nullptr; + } + } + + template + inline ErrCode JudgmentEmpty(T *&pointer) + { + if (pointer == nullptr) { + return WIFI_OPT_FAILED; + } + return WIFI_OPT_SUCCESS; + } + + void BuildStateTree(); + ErrCode InitMultiStaStates(); + DefaultState *pDefaultState; + IdleState *pIdleState; + StartedState *pStartedState; + MultiStaModeCallback mcb; + static int mid; + std::string ifaceName{""}; +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_define.h index 65b737c8f..2e03b01b0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_define.h @@ -53,6 +53,12 @@ namespace Wifi { #define SOFTAP_CMD_START 0x201 #define SOFTAP_CMD_STOP 0x202 +#define MULTI_STA_CMD_START 0x301 +#define MULTI_STA_CMD_STOP 0x302 +#define MULTI_STA_CMD_STARTED 0x303 +#define MULTI_STA_CMD_STOPPED 0x304 +#define CMD_MULTI_STA_STOPPED 0x305 + #define STOP_WIFI_WAIT_TIME 100 struct ConcreteModeCallback { @@ -66,6 +72,11 @@ struct SoftApModeCallback { std::function onStartFailure; }; +struct MultiStaModeCallback { + std::function onStopped; + std::function onStartFailure; +}; + enum class ConcreteManagerRole { ROLE_UNKNOW = -1, ROLE_CLIENT_SCAN_ONLY = 0, diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp index bf5f8b7bf..f3fd6da84 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp @@ -131,14 +131,23 @@ bool WifiControllerMachine::DisableState::ExecuteStateMsg(InternalMessagePtr msg #endif case CMD_WIFI_TOGGLED: case CMD_SCAN_ALWAYS_MODE_CHANGED: - if (pWifiControllerMachine->ShouldEnableWifi()) { - ConcreteManagerRole role = pWifiControllerMachine->GetWifiRole(); - if (role == ConcreteManagerRole::ROLE_UNKNOW) { + if (!pWifiControllerMachine->ShouldEnableWifi(msg->GetParam2())) { + WIFI_LOGW("keep disable, shouldn't enabled wifi."); + break; + } + if (msg->GetParam2() == INSTID_WLAN1) { + pWifiControllerMachine->MakeMultiStaManager(MultiStaManager::Role::ROLE_STA_WIFI_2, msg->GetParam2()); + pWifiControllerMachine->SwitchState(pWifiControllerMachine->pEnableState); + } else if (msg->GetParam2() == INSTID_WLAN0) { + ConcreteManagerRole roleStaWifi1 = pWifiControllerMachine->GetWifiRole(); + if (roleStaWifi1 == ConcreteManagerRole::ROLE_UNKNOW) { WIFI_LOGE("Get unknow wifi role, break"); break; } - pWifiControllerMachine->MakeConcreteManager(role, msg->GetParam2()); + pWifiControllerMachine->MakeConcreteManager(roleStaWifi1, msg->GetParam2()); pWifiControllerMachine->SwitchState(pWifiControllerMachine->pEnableState); + } else { + WIFI_LOGE("DisableState, invalid instance id"); } break; case CMD_AIRPLANE_TOGGLED: @@ -206,10 +215,14 @@ bool WifiControllerMachine::EnableState::ExecuteStateMsg(InternalMessagePtr msg) break; #endif case CMD_STA_START_FAILURE: - HandleStaStartFailure(msg->GetParam1()); + msg->GetParam1() == INSTID_WLAN0 ? + HandleStaStartFailure(INSTID_WLAN0) : pWifiControllerMachine->RemoveMultiStaManager(INSTID_WLAN1); break; case CMD_CONCRETE_STOPPED: - pWifiControllerMachine->HandleConcreteStop(msg->GetParam1()); + pWifiControllerMachine->HandleConcreteStop(INSTID_WLAN0); + break; + case CMD_MULTI_STA_STOPPED: + pWifiControllerMachine->RemoveMultiStaManager(INSTID_WLAN1); break; case CMD_AIRPLANE_TOGGLED: if (msg->GetParam1()) { @@ -222,7 +235,7 @@ bool WifiControllerMachine::EnableState::ExecuteStateMsg(InternalMessagePtr msg) pWifiControllerMachine->SendMessage(CMD_WIFI_TOGGLED, 1, 0); break; case CMD_STA_REMOVED: - HandleStaRemoved(msg); + INSTID_WLAN0 == msg->GetParam2() ? HandleStaRemoved(msg) : HandleWifi2Removed(msg); break; case CMD_CONCRETECLIENT_REMOVED: HandleConcreteClientRemoved(msg); @@ -283,7 +296,7 @@ void WifiControllerMachine::HandleAirplaneClose() #ifndef OHOS_ARCH_LITE WifiManager::GetInstance().GetWifiEventSubscriberManager()->GetWifiAllowSemiActiveByDatashare(); #endif - if (!ShouldEnableWifi() || WifiConfigCenter::GetInstance().GetWifiStopState()) { + if (!ShouldEnableWifi(INSTID_WLAN0) || WifiConfigCenter::GetInstance().GetWifiStopState()) { return; } #ifdef FEATURE_AP_SUPPORT @@ -348,6 +361,22 @@ bool WifiControllerMachine::ConcreteIdExist(int id) std::unique_lock lock(concreteManagerMutex); for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) { if ((*iter)->mid == id) { + WIFI_LOGI("concreteManagers is match"); + return true; + } + } + return false; +} + +bool WifiControllerMachine::IsWifi2IdExist(int id) +{ + if (!HasAnyMultiStaManager()) { + return false; + } + std::unique_lock lock(multiStaManagerMutex); + for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) { + if ((*iter)->mid == id) { + WIFI_LOGI("multiStaManagers is match"); return true; } } @@ -358,6 +387,17 @@ bool WifiControllerMachine::HasAnyConcreteManager() { std::unique_lock lock(concreteManagerMutex); if (concreteManagers.empty()) { + WIFI_LOGE("Enter HasAnyConcreteManager is empty"); + return false; + } + return true; +} + +bool WifiControllerMachine::HasAnyMultiStaManager() +{ + std::unique_lock lock(multiStaManagerMutex); + if (multiStaManagers.empty()) { + WIFI_LOGE("Enter HasAnyMultiStaManager is empty"); return false; } return true; @@ -398,6 +438,20 @@ void WifiControllerMachine::MakeConcreteManager(ConcreteManagerRole role, int id concreteManagers.push_back(clientmode); } +void WifiControllerMachine::MakeMultiStaManager(MultiStaManager::Role role, int instId) +{ + WIFI_LOGI("Enter MakeMultiStaManager"); + MultiStaManager *multiStaMode = new (std::nothrow) MultiStaManager(role, instId); + if (multiStaMode == nullptr) { + WIFI_LOGE("new multiStaMode failed"); + return; + } + multiStaMode->RegisterCallback(WifiManager::GetInstance().GetWifiTogglerManager()->GetMultiStaCallback()); + multiStaMode->InitMultiStaManager(); + std::unique_lock lock(multiStaManagerMutex); + multiStaManagers.push_back(multiStaMode); +} + #ifdef FEATURE_AP_SUPPORT void WifiControllerMachine::MakeSoftapManager(SoftApManager::Role role, int id) { @@ -426,18 +480,21 @@ bool WifiControllerMachine::ShouldDisableWifi(InternalMessagePtr msg) WIFI_LOGI("Should disable wifi"); return true; } - return !ShouldEnableWifi(); + return !ShouldEnableWifi(msg->GetParam2()); } -bool WifiControllerMachine::ShouldEnableWifi() +bool WifiControllerMachine::ShouldEnableWifi(int id) { WIFI_LOGI("Enter ShouldEnableWifi"); + if (id == INSTID_WLAN1) { + return WifiConfigCenter::GetInstance().GetWifiToggledEnable(INSTID_WLAN0) == WIFI_STATE_ENABLED; + } #ifndef OHOS_ARCH_LITE if (WifiManager::GetInstance().GetWifiEventSubscriberManager()->IsMdmForbidden()) { return false; } #endif - if (WifiConfigCenter::GetInstance().GetWifiToggledEnable() != WIFI_STATE_DISABLED || IsScanOnlyEnable()) { + if (WifiConfigCenter::GetInstance().GetWifiToggledEnable(id) != WIFI_STATE_DISABLED || IsScanOnlyEnable()) { WIFI_LOGI("Should start wifi or scanonly."); return true; } @@ -461,9 +518,9 @@ ConcreteManagerRole WifiControllerMachine::GetWifiRole() } } -bool WifiControllerMachine::IsWifiEnable() +bool WifiControllerMachine::IsWifiEnable(int id) { - return WifiConfigCenter::GetInstance().GetWifiToggledEnable() == WIFI_STATE_ENABLED; + return WifiConfigCenter::GetInstance().GetWifiToggledEnable(id) == WIFI_STATE_ENABLED; } bool WifiControllerMachine::IsSemiWifiEnable() @@ -498,6 +555,7 @@ void WifiControllerMachine::StopAllConcreteManagers() } std::unique_lock lock(concreteManagerMutex); for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) { + WIFI_LOGD("Enter StopAllConcreteManagers. mid = %{public}d", (*iter)->mid); (*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STOP); } } @@ -533,6 +591,21 @@ void WifiControllerMachine::StopSoftapManager(int id) } } +void WifiControllerMachine::StopMultiStaManager(int id) +{ + WIFI_LOGI("Enter StopMultiStaManager, id = %{public}d", id); + if (!HasAnyMultiStaManager()) { + return; + } + std::unique_lock lock(multiStaManagerMutex); + for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) { + if ((*iter)->mid == id) { + (*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STOP); + return; + } + } +} + void WifiControllerMachine::StopAllSoftapManagers() { if (!HasAnySoftApManager()) { @@ -568,6 +641,29 @@ void WifiControllerMachine::RemoveConcreteManager(int id) } } +void WifiControllerMachine::RemoveMultiStaManager(int id) +{ + MultiStaManager *multiStaMgr = nullptr; + + if (!HasAnyMultiStaManager()) { + return; + } + { + std::unique_lock lock(multiStaManagerMutex); + for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) { + if ((*iter)->mid == id) { + multiStaMgr = *iter; + multiStaManagers.erase(iter); + break; + } + } + } + if (multiStaMgr != nullptr) { + delete multiStaMgr; + multiStaMgr = nullptr; + } +} + #ifdef FEATURE_AP_SUPPORT void WifiControllerMachine::RmoveSoftapManager(int id) { @@ -604,6 +700,20 @@ void WifiControllerMachine::HandleStaClose(int id) } } +void WifiControllerMachine::HandleWifi2Close(int id) +{ + std::unique_lock lock(multiStaManagerMutex); + if (multiStaManagers.empty()) { + return; + } + for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) { + if ((*iter)->mid == id) { + (*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STOPPED); + break; + } + } +} + void WifiControllerMachine::SwitchRole(ConcreteManagerRole role) { std::unique_lock lock(concreteManagerMutex); @@ -614,8 +724,20 @@ void WifiControllerMachine::SwitchRole(ConcreteManagerRole role) void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(InternalMessagePtr msg) { + if (msg->GetParam2() == INSTID_WLAN1 && msg->GetParam1() == 0) { + WIFI_LOGI("Toggle disable wlan1."); + pWifiControllerMachine->StopMultiStaManager(INSTID_WLAN1); + return; + } + if (msg->GetParam2() == INSTID_WLAN1 && WifiConfigCenter::GetInstance().GetPersistWifiState(INSTID_WLAN0) + == WIFI_STATE_ENABLED && msg->GetParam1() == 1) { + pWifiControllerMachine->MakeMultiStaManager(MultiStaManager::Role::ROLE_STA_WIFI_2, msg->GetParam2()); + return; + } + ConcreteManagerRole presentRole; if (pWifiControllerMachine->ShouldDisableWifi(msg)) { + pWifiControllerMachine->StopMultiStaManager(INSTID_WLAN1); pWifiControllerMachine->StopAllConcreteManagers(); return; } @@ -628,6 +750,9 @@ void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(In WIFI_LOGE("Get unknow wifi role in enablestate."); return; } + if (presentRole != ConcreteManagerRole::ROLE_CLIENT_STA) { + pWifiControllerMachine->StopMultiStaManager(INSTID_WLAN1); + } pWifiControllerMachine->SwitchRole(presentRole); return; } @@ -671,7 +796,8 @@ void WifiControllerMachine::EnableState::HandleSoftapToggleChangeInEnabledState( } #ifndef HDI_CHIP_INTERFACE_SUPPORT if (!WifiConfigCenter::GetInstance().GetCoexSupport() && - pWifiControllerMachine->ShouldEnableWifi() && !WifiConfigCenter::GetInstance().GetWifiStopState() && + pWifiControllerMachine->ShouldEnableWifi(INSTID_WLAN0) && + !WifiConfigCenter::GetInstance().GetWifiStopState() && pWifiControllerMachine->HasAnyConcreteManager()) { ConcreteManagerRole role = pWifiControllerMachine->GetWifiRole(); if (role != ConcreteManagerRole::ROLE_UNKNOW) { @@ -697,7 +823,7 @@ void WifiControllerMachine::EnableState::HandleStaStartFailure(int id) WIFI_LOGE("HandleStaStartFailure"); pWifiControllerMachine->RemoveConcreteManager(id); mWifiStartFailCount++; - if (pWifiControllerMachine->ShouldEnableWifi() && mWifiStartFailCount < WIFI_OPEN_RETRY_MAX_COUNT) { + if (pWifiControllerMachine->ShouldEnableWifi(id) && mWifiStartFailCount < WIFI_OPEN_RETRY_MAX_COUNT) { pWifiControllerMachine->StartTimer(CMD_OPEN_WIFI_RETRY, WIFI_OPEN_RETRY_TIMEOUT); } } @@ -716,6 +842,11 @@ void WifiControllerMachine::EnableState::HandleStaRemoved(InternalMessagePtr msg pWifiControllerMachine->StopConcreteManager(msg->GetParam2()); } +void WifiControllerMachine::EnableState::HandleWifi2Removed(InternalMessagePtr msg) +{ + pWifiControllerMachine->StopMultiStaManager(msg->GetParam2()); +} + void WifiControllerMachine::EnableState::HandleConcreteClientRemoved(InternalMessagePtr msg) { int id = msg->GetParam1(); @@ -747,6 +878,14 @@ void WifiControllerMachine::HandleStaStart(int id) } } +void WifiControllerMachine::HandleWifi2Start(int id) +{ + std::unique_lock lock(multiStaManagerMutex); + for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) { + (*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STARTED); + } +} + void WifiControllerMachine::HandleStaSemiActive(int id) { mWifiStartFailCount = 0; @@ -786,6 +925,7 @@ void WifiControllerMachine::EnableState::HandleApStop(InternalMessagePtr msg) void WifiControllerMachine::HandleConcreteStop(int id) { + WIFI_LOGD("WifiControllerMachine HandleConcreteStop id = %{public}d", id); RemoveConcreteManager(id); #ifndef HDI_CHIP_INTERFACE_SUPPORT if (!WifiConfigCenter::GetInstance().GetCoexSupport()) { @@ -798,7 +938,7 @@ void WifiControllerMachine::HandleConcreteStop(int id) } #endif if (!WifiManager::GetInstance().GetWifiTogglerManager()->HasAnyApRuning()) { - if (ShouldEnableWifi()) { + if (ShouldEnableWifi(id)) { ConcreteManagerRole presentRole = GetWifiRole(); MakeConcreteManager(presentRole, 0); return; @@ -806,7 +946,7 @@ void WifiControllerMachine::HandleConcreteStop(int id) } } else { #endif - if (ShouldEnableWifi()) { + if (ShouldEnableWifi(id)) { ConcreteManagerRole presentRole = GetWifiRole(); MakeConcreteManager(presentRole, 0); return; @@ -840,7 +980,7 @@ void WifiControllerMachine::HandleSoftapStop(int id) if (HasAnyManager()) { return; } - if (ShouldEnableWifi() && !WifiConfigCenter::GetInstance().GetWifiStopState()) { + if (ShouldEnableWifi(INSTID_WLAN0) && !WifiConfigCenter::GetInstance().GetWifiStopState()) { role = GetWifiRole(); if (role == ConcreteManagerRole::ROLE_UNKNOW) { WIFI_LOGE("Get unknow wifi role in HandleSoftapStop."); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.h index 5dce0dd29..f01057601 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.h @@ -23,6 +23,7 @@ #include "wifi_logger.h" #include "wifi_errcode.h" #include "concrete_clientmode_manager.h" +#include "multi_sta_manager.h" #ifdef FEATURE_AP_SUPPORT #include "softap_manager.h" #endif @@ -55,6 +56,7 @@ public: bool ExecuteStateMsg(InternalMessagePtr msg) override; void HandleStaStartFailure(int id); void HandleStaRemoved(InternalMessagePtr msg); + void HandleWifi2Removed(InternalMessagePtr msg); void HandleAPServiceStartFail(int id); void HandleConcreteClientRemoved(InternalMessagePtr msg); @@ -85,8 +87,11 @@ public: ErrCode InitWifiControllerMachine(); void RemoveConcreteManager(int id); + void RemoveMultiStaManager(int id); void HandleStaClose(int id); + void HandleWifi2Close(int id); void HandleStaStart(int id); + void HandleWifi2Start(int id); void HandleStaSemiActive(int id); void HandleConcreteStop(int id); void ClearWifiStartFailCount(); @@ -120,9 +125,12 @@ private: void BuildStateTree(); ErrCode InitWifiStates(); bool HasAnyConcreteManager(); + bool HasAnyMultiStaManager(); bool HasAnyManager(); bool ConcreteIdExist(int id); + bool IsWifi2IdExist(int id); void MakeConcreteManager(ConcreteManagerRole role, int id); + void MakeMultiStaManager(MultiStaManager::Role role, int instId); #ifdef FEATURE_AP_SUPPORT bool HasAnySoftApManager(); bool SoftApIdExist(int id); @@ -133,14 +141,15 @@ private: SoftApManager *GetSoftApManager(int id); #endif bool ShouldDisableWifi(InternalMessagePtr msg); - bool ShouldEnableWifi(); + bool ShouldEnableWifi(int id = 0); ConcreteManagerRole GetWifiRole(); void StopAllConcreteManagers(); void StopConcreteManager(int id); + void StopMultiStaManager(int id); void SwitchRole(ConcreteManagerRole role); void HandleAirplaneOpen(); void HandleAirplaneClose(); - static bool IsWifiEnable(); + static bool IsWifiEnable(int id = 0); static bool IsSemiWifiEnable(); static bool IsScanOnlyEnable(); @@ -158,6 +167,8 @@ private: mutable std::mutex softapManagerMutex; uint64_t stopSoftapTimerId_ {0}; #endif + mutable std::mutex multiStaManagerMutex; + std::vector multiStaManagers; }; } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.cpp index 499853267..5db45d781 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.cpp @@ -97,15 +97,21 @@ ErrCode WifiServiceScheduler::AutoStartStaService(int instId, std::string &staIf return WIFI_OPT_FAILED; } DispatchWifiOpenRes(OperateResState::OPEN_WIFI_OPENING, instId); - int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName()); + WIFI_LOGI("AutoStartStaService startwifi iface:%{public}s instId:%{public}d", + WifiConfigCenter::GetInstance().GetStaIfaceName(instId).c_str(), instId); + int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId), + instId); if (ret != WIFI_OPT_SUCCESS) { WIFI_LOGE("AutoStartStaService start wifi fail."); WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); WriteWifiOpenAndCloseFailedHiSysEvent(static_cast(OperateResState::OPEN_WIFI_FAILED), "TIME_OUT", static_cast(staState)); return WIFI_OPT_FAILED; + } else { + WIFI_LOGE("AutoStartStaService start wifi instId:%{public}d success.", instId); } if (PostStartWifi(instId) != WIFI_OPT_SUCCESS) { + WIFI_LOGE("AutoStartStaService PostStartWifi instId:%{public}d", instId); return WIFI_OPT_FAILED; } WifiManager::GetInstance().PushServiceCloseMsg(WifiCloseServiceCode::STA_MSG_OPENED, instId); @@ -115,6 +121,34 @@ ErrCode WifiServiceScheduler::AutoStartStaService(int instId, std::string &staIf return WIFI_OPT_SUCCESS; } +ErrCode WifiServiceScheduler::AutoStartWifi2Service(int instId, std::string &staIfName) +{ + WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); + WIFI_LOGI("AutoStartWifi2Service, current sta state:%{public}d", staState); + std::lock_guard lock(mutex); + if (staState == WifiOprMidState::RUNNING) { + return WIFI_OPT_SUCCESS; + } + if (PreStartWifi(instId, staIfName) != WIFI_OPT_SUCCESS) { + return WIFI_OPT_FAILED; + } + DispatchWifi2OpenRes(OperateResState::OPEN_WIFI_OPENING, instId); + int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId), + instId); + if (ret != WIFI_OPT_SUCCESS) { + WIFI_LOGE("AutoStartWifi2Service start wifi fail."); + return WIFI_OPT_FAILED; + } + if (PostStartWifi2(instId) != WIFI_OPT_SUCCESS) { + WIFI_LOGE("AutoStartWifi2Service PostStartWifi instId %{public}d", instId); + return WIFI_OPT_FAILED; + } + DispatchWifi2OpenRes(OperateResState::OPEN_WIFI_SUCCEED, instId); + auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine(); + ins->HandleWifi2Start(instId); + return WIFI_OPT_SUCCESS; +} + ErrCode WifiServiceScheduler::AutoStopStaService(int instId) { WifiOprMidState staStateBefore = WifiConfigCenter::GetInstance().GetWifiMidState(instId); @@ -151,7 +185,7 @@ ErrCode WifiServiceScheduler::AutoStopStaService(int instId) if (ret != WIFI_OPT_SUCCESS) { WIFI_LOGE("service disable sta failed, ret %{public}d!", static_cast(ret)); } - if (WifiStaHalInterface::GetInstance().StopWifi() != WIFI_HAL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().StopWifi(instId) != WIFI_HAL_OPT_OK) { WIFI_LOGE("stop wifi failed."); WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, staStateBefore, instId)) { @@ -169,12 +203,57 @@ ErrCode WifiServiceScheduler::AutoStopStaService(int instId) return WIFI_OPT_SUCCESS; } +ErrCode WifiServiceScheduler::AutoStopWifi2Service(int instId) +{ + WifiOprMidState staStateBefore = WifiConfigCenter::GetInstance().GetWifiMidState(instId); + WIFI_LOGI("AutoStopWifi2Service, current sta state:%{public}d, instId:%{public}d", + staStateBefore, instId); + std::lock_guard lock(mutex); + if (staStateBefore == WifiOprMidState::CLOSED) { + return WIFI_OPT_SUCCESS; + } + ErrCode ret = WIFI_OPT_FAILED; + + if (!WifiConfigCenter::GetInstance().SetWifiMidState(staStateBefore, WifiOprMidState::CLOSING, instId)) { + WIFI_LOGE("AutoStopWifi2Service,set wifi mid state closing failed!"); + return WIFI_OPT_FAILED; + } + + IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId); + if (pService == nullptr) { + WIFI_LOGE("AutoStopWifi2Service, Instance get sta service is null!"); + WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId); + WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, instId); + return WIFI_OPT_SUCCESS; + } + DispatchWifi2CloseRes(OperateResState::CLOSE_WIFI_CLOSING, instId); + ret = pService->DisableStaService(); + if (ret != WIFI_OPT_SUCCESS) { + WIFI_LOGE("AutoStopWifi2Service service disable sta failed, ret %{public}d!", static_cast(ret)); + } + if (WifiStaHalInterface::GetInstance().StopWifi(instId) != WIFI_HAL_OPT_OK) { + WIFI_LOGE("AutoStopWifi2Service stop wifi failed."); + WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); + if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, staStateBefore, instId)) { + WIFI_LOGE("AutoStopWifi2Service, set wifi mid state:%{public}d failed!", staStateBefore); + return WIFI_OPT_FAILED; + } + } + WifiManager::GetInstance().PushServiceCloseMsg(WifiCloseServiceCode::STA_MSG_STOPED, instId); + DispatchWifi2CloseRes(OperateResState::CLOSE_WIFI_SUCCEED, instId); + auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine(); + ins->HandleWifi2Close(instId); + WIFI_LOGE("AutoStopWifi2Service %{public}d success!", instId); + return WIFI_OPT_SUCCESS; +} + ErrCode WifiServiceScheduler::AutoStartScanOnly(int instId, std::string &staIfName) { WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiScanOnlyMidState(instId); - WIFI_LOGI("AutoStartScanOnly, Wifi scan only state is %{public}d", static_cast(curState)); + WIFI_LOGI("AutoStartScanOnly, Wifi scan only state is %{public}d, instId = %{public}d", + static_cast(curState), instId); std::lock_guard lock(mutex); - if (curState != WifiOprMidState::CLOSED) { + if (curState != WifiOprMidState::CLOSED && instId == 0) { WIFI_LOGE("ScanOnly State is not closed, return\n"); return WIFI_OPT_SUCCESS; } @@ -192,16 +271,19 @@ ErrCode WifiServiceScheduler::AutoStartScanOnly(int instId, std::string &staIfNa if (ifaceName.empty() && !DelayedSingleton::GetInstance()->CreateStaIface( std::bind(&WifiServiceScheduler::StaIfaceDestoryCallback, this, std::placeholders::_1, std::placeholders::_2), std::bind(&WifiServiceScheduler::OnRssiReportCallback, this, std::placeholders::_1, std::placeholders::_2), - ifaceName)) { + ifaceName, instId)) { WIFI_LOGE("AutoStartScanOnly, create iface failed!"); return WIFI_OPT_FAILED; } + WIFI_LOGI("AutoStartScanOnly SetStaIfaceName:%{public}s, instId:%{public}d", ifaceName.c_str(), instId); WifiConfigCenter::GetInstance().SetStaIfaceName(ifaceName); staIfName = ifaceName; g_staIfaceNameMap.insert(std::make_pair(instId, ifaceName)); #endif WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::OPENING, instId); - WifiManager::GetInstance().AutoStartEnhanceService(); + if (instId == INSTID_WLAN0) { + WifiManager::GetInstance().AutoStartEnhanceService(); + } WifiManager::GetInstance().GetWifiScanManager()->CheckAndStartScanService(instId); WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(WifiOprMidState::RUNNING, instId); return WIFI_OPT_SUCCESS; @@ -230,7 +312,7 @@ ErrCode WifiServiceScheduler::AutoStopScanOnly(int instId, bool setIfaceDown) if (setIfaceDown) { #ifdef HDI_CHIP_INTERFACE_SUPPORT DelayedSingleton::GetInstance()->SetNetworkUpDown( - WifiConfigCenter::GetInstance().GetStaIfaceName(), false); + WifiConfigCenter::GetInstance().GetStaIfaceName(instId), false); #endif } WifiManager::GetInstance().GetWifiScanManager()->CheckAndStopScanService(instId); @@ -250,7 +332,8 @@ ErrCode WifiServiceScheduler::AutoStartSemiStaService(int instId, std::string &s return WIFI_OPT_FAILED; } DispatchWifiSemiActiveRes(OperateResState::ENABLE_SEMI_WIFI_OPENING, instId); - int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName()); + int ret = WifiStaHalInterface::GetInstance().StartWifi(WifiConfigCenter::GetInstance().GetStaIfaceName(instId), + instId); if (ret != WIFI_OPT_SUCCESS) { WIFI_LOGE("AutoStartSemiStaService start wifi fail."); WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); @@ -279,12 +362,14 @@ ErrCode WifiServiceScheduler::PreStartWifi(int instId, std::string &staIfName) if (ifaceName.empty() && !DelayedSingleton::GetInstance()->CreateStaIface( std::bind(&WifiServiceScheduler::StaIfaceDestoryCallback, this, std::placeholders::_1, std::placeholders::_2), std::bind(&WifiServiceScheduler::OnRssiReportCallback, this, std::placeholders::_1, std::placeholders::_2), - ifaceName)) { + ifaceName, instId)) { WIFI_LOGE("PreStartWifi, create iface failed!"); return WIFI_OPT_FAILED; } - WifiConfigCenter::GetInstance().SetStaIfaceName(ifaceName); + WIFI_LOGI("PreStartWifi SetStaIfaceName:%{public}s, instId:%{public}d", ifaceName.c_str(), instId); + WifiConfigCenter::GetInstance().SetStaIfaceName(ifaceName, instId); g_staIfaceNameMap.insert(std::make_pair(instId, ifaceName)); + staIfName = WifiConfigCenter::GetInstance().GetStaIfaceName(instId); #endif WifiOprMidState staState = WifiConfigCenter::GetInstance().GetWifiMidState(instId); if (!WifiConfigCenter::GetInstance().SetWifiMidState(staState, WifiOprMidState::OPENING, instId)) { @@ -296,48 +381,17 @@ ErrCode WifiServiceScheduler::PreStartWifi(int instId, std::string &staIfName) ErrCode WifiServiceScheduler::PostStartWifi(int instId) { - ErrCode errCode = WIFI_OPT_FAILED; - do { - if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_STA) < 0) { - WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_STA); - break; - } - IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId); - if (pService == nullptr) { - WIFI_LOGE("Create %{public}s service failed!", WIFI_SERVICE_STA); - break; - } - if (InitStaService(pService) != WIFI_OPT_SUCCESS) { - WIFI_LOGE("InitStaService failed!"); - break; - } + if (StartWifiStaService(instId) == WIFI_OPT_FAILED) { + WIFI_LOGE("StartWifiStaService failed!"); + } #ifdef FEATURE_SELF_CURE_SUPPORT - if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) { - WIFI_LOGE("StartSelfCureService failed!"); - break; - } + if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) { + WIFI_LOGE("StartSelfCureService failed!"); + } #endif - errCode = pService->EnableStaService(); - if (errCode != WIFI_OPT_SUCCESS) { - WIFI_LOGE("Service enable sta failed ,ret %{public}d!", static_cast(errCode)); - break; - } - #ifndef OHOS_ARCH_LITE - IEnhanceService *pEnhanceService = WifiServiceManager::GetInstance().GetEnhanceServiceInst(); - if (pEnhanceService == nullptr) { - WIFI_LOGE("get pEnhance service failed!"); - break; - } - errCode = pService->SetEnhanceService(pEnhanceService); - if (errCode != WIFI_OPT_SUCCESS) { - WIFI_LOGE("SetEnhanceService failed, ret %{public}d!", static_cast(errCode)); - break; - } - #endif - } while (0); WifiManager::GetInstance().GetWifiStaManager()->StopUnloadStaSaTimer(); #ifdef FEATURE_P2P_SUPPORT - errCode = WifiManager::GetInstance().GetWifiP2pManager()->AutoStartP2pService(); + ErrCode errCode = WifiManager::GetInstance().GetWifiP2pManager()->AutoStartP2pService(); if (errCode != WIFI_OPT_SUCCESS && errCode != WIFI_OPT_OPEN_SUCC_WHEN_OPENED) { WIFI_LOGE("AutoStartStaService, AutoStartP2pService failed!"); } @@ -345,7 +399,40 @@ ErrCode WifiServiceScheduler::PostStartWifi(int instId) return WIFI_OPT_SUCCESS; } -ErrCode WifiServiceScheduler::InitStaService(IStaService *pService) +ErrCode WifiServiceScheduler::PostStartWifi2(int instId) +{ + StartWifiStaService(instId); + return WIFI_OPT_SUCCESS; +} + +ErrCode WifiServiceScheduler::StartWifiStaService(int instId) +{ + if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_STA, instId) < 0) { + WIFI_LOGE("StartWifiStaService Load %{public}s service failed!", WIFI_SERVICE_STA); + return WIFI_OPT_FAILED; + } + WIFI_LOGD("StartWifiStaService GetStaServiceInst instId:%{public}d", instId); + IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId); + if (pService == nullptr) { + WIFI_LOGE("StartWifiStaService Create %{public}s service failed!", WIFI_SERVICE_STA); + return WIFI_OPT_FAILED; + } + WIFI_LOGD("StartWifiStaService InitStaService instId:%{public}d", instId); + if (InitStaService(pService, instId) != WIFI_OPT_SUCCESS) { + WIFI_LOGE("StartWifiStaService InitStaService failed!"); + return WIFI_OPT_FAILED; + } + WIFI_LOGD("StartWifiStaService EnableStaService instId:%{public}d", instId); + ErrCode errCode = pService->EnableStaService(); + if (errCode != WIFI_OPT_SUCCESS) { + WIFI_LOGE("StartWifiStaService Service enable sta failed ,ret %{public}d!", static_cast(errCode)); + return WIFI_OPT_FAILED; + } + WIFI_LOGI("StartWifiStaService instId%{public}d successful", instId); + return WIFI_OPT_SUCCESS; +} + +ErrCode WifiServiceScheduler::InitStaService(IStaService *pService, int instId) { if (pService == nullptr) { WIFI_LOGE("pService is nullptr"); @@ -357,11 +444,13 @@ ErrCode WifiServiceScheduler::InitStaService(IStaService *pService) WIFI_LOGE("Register sta service callback failed!"); return WIFI_OPT_FAILED; } - errCode = pService->RegisterStaServiceCallback(WifiManager::GetInstance().GetWifiScanManager()->GetStaCallback()); - if (errCode != WIFI_OPT_SUCCESS) { - WIFI_LOGE("WifiScanManager register sta service callback failed!"); - return WIFI_OPT_FAILED; - } + if (instId == INSTID_WLAN0) { + errCode = pService->RegisterStaServiceCallback( + WifiManager::GetInstance().GetWifiScanManager()->GetStaCallback()); + if (errCode != WIFI_OPT_SUCCESS) { + WIFI_LOGE("WifiScanManager register sta service callback failed!"); + return WIFI_OPT_FAILED; + } #ifndef OHOS_ARCH_LITE errCode = pService->RegisterStaServiceCallback(WifiCountryCodeManager::GetInstance().GetStaCallback()); if (errCode != WIFI_OPT_SUCCESS) { @@ -377,6 +466,7 @@ ErrCode WifiServiceScheduler::InitStaService(IStaService *pService) return WIFI_OPT_FAILED; } #endif + } return WIFI_OPT_SUCCESS; } @@ -429,7 +519,7 @@ void WifiServiceScheduler::StaIfaceDestoryCallback(std::string &destoryIfaceName auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine(); ins->SendMessage(CMD_STA_REMOVED, createIfaceType, iter->first); if (createIfaceType >= 0) { - WifiConfigCenter::GetInstance().SetStaIfaceName(""); + WifiConfigCenter::GetInstance().SetStaIfaceName("", iter->first); g_staIfaceNameMap.erase(iter); } return; @@ -480,6 +570,29 @@ void WifiServiceScheduler::DispatchWifiOpenRes(OperateResState state, int instId } } +void WifiServiceScheduler::DispatchWifi2OpenRes(OperateResState state, int instId) +{ + WIFI_LOGI("DispatchWifi2OpenRes, state:%{public}d", static_cast(state)); + WifiEventCallbackMsg cbMsg; + cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE; + cbMsg.id = instId; + if (state == OperateResState::OPEN_WIFI_OPENING) { + WifiConfigCenter::GetInstance().SetWifiState(static_cast(WifiState::ENABLING), instId); + WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATING, instId); + cbMsg.msgData = static_cast(WifiState::ENABLING); + WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg); + } + if (state == OperateResState::OPEN_WIFI_SUCCEED) { + WifiConfigCenter::GetInstance().SetWifiState(static_cast(WifiState::ENABLED), instId); + WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATED, instId); + WifiSettings::GetInstance().SetStaLastRunState(WIFI_STATE_ENABLED, instId); + WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::OPENING, WifiOprMidState::RUNNING, instId); + cbMsg.msgData = static_cast(WifiState::ENABLED); + WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg); + } + return; +} + void WifiServiceScheduler::DispatchWifiSemiActiveRes(OperateResState state, int instId) { WIFI_LOGI("DispatchWifiSemiActiveRes, state:%{public}d", static_cast(state)); @@ -538,7 +651,7 @@ void WifiServiceScheduler::DispatchWifiCloseRes(OperateResState state, int instI WIFI_LOGI("reset selfcure wifi off->open!"); int state = WifiSettings::GetInstance().GetStaLastRunState(); state = (state == WIFI_STATE_SEMI_ENABLED) ? WIFI_STATE_SEMI_ENABLED : WIFI_STATE_ENABLED; - WifiConfigCenter::GetInstance().SetWifiToggledState(state); + WifiConfigCenter::GetInstance().SetWifiToggledState(state, instId); WifiSettings::GetInstance().SetStaLastRunState(WIFI_STATE_DISABLED, instId); WifiManager::GetInstance().GetWifiTogglerManager()->WifiToggled(1, 0); } @@ -549,6 +662,30 @@ void WifiServiceScheduler::DispatchWifiCloseRes(OperateResState state, int instI } } +void WifiServiceScheduler::DispatchWifi2CloseRes(OperateResState state, int instId) +{ + WIFI_LOGI("DispatchWifi2CloseRes, state:%{public}d", static_cast(state)); + WifiEventCallbackMsg cbMsg; + cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE; + cbMsg.id = instId; + if (state == OperateResState::CLOSE_WIFI_CLOSING) { + WifiConfigCenter::GetInstance().SetWifiState(static_cast(WifiState::DISABLING), instId); + WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_DEACTIVATING, instId); + cbMsg.msgData = static_cast(WifiState::DISABLING); + WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg); + return; + } + if (state == OperateResState::CLOSE_WIFI_SUCCEED) { + WifiConfigCenter::GetInstance().SetWifiState(static_cast(WifiState::DISABLED), instId); + WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_INACTIVE, instId); + WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId); + cbMsg.msgData = static_cast(WifiState::DISABLED); + WifiSettings::GetInstance().SetStaLastRunState(WIFI_STATE_DISABLED, instId); + WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg); + return; + } +} + /*--------------------------------------------------softAp------------------------------------------------------------*/ #ifdef FEATURE_AP_SUPPORT diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.h index eb8ea5b23..7d8c20830 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.h @@ -40,22 +40,28 @@ public: explicit WifiServiceScheduler(); ~WifiServiceScheduler(); ErrCode AutoStartStaService(int instId, std::string &staIfName); + ErrCode AutoStartWifi2Service(int instId, std::string &staIfName); ErrCode AutoStopStaService(int instId); + ErrCode AutoStopWifi2Service(int instId); ErrCode AutoStartScanOnly(int instId, std::string &staIfName); ErrCode AutoStopScanOnly(int instId, bool setIfaceDown); ErrCode AutoStartSemiStaService(int instId, std::string &staIfName); ErrCode AutoStartApService(int instId, std::string &softApIfName); ErrCode AutoStopApService(int instId); void DispatchWifiOpenRes(OperateResState state, int instId); + void DispatchWifi2OpenRes(OperateResState state, int instId); void DispatchWifiSemiActiveRes(OperateResState state, int instId); void DispatchWifiCloseRes(OperateResState state, int instId); + void DispatchWifi2CloseRes(OperateResState state, int instId); void ClearStaIfaceNameMap(int instId); void ClearP2pIfaceNameMap(int instId); void ClearSoftApIfaceNameMap(int instId); private: ErrCode PreStartWifi(int instId, std::string &staIfName); ErrCode PostStartWifi(int instId); - ErrCode InitStaService(IStaService *pService); + ErrCode PostStartWifi2(int instId); + ErrCode InitStaService(IStaService *pService, int instId); + ErrCode StartWifiStaService(int instId); #ifdef FEATURE_SELF_CURE_SUPPORT ErrCode StartSelfCureService(int instId); #endif diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index 1592aac78..9de08d277 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -112,7 +112,7 @@ int WifiManager::Init() int lastState = WifiSettings::GetInstance().GetStaLastRunState(); if (lastState != WIFI_STATE_DISABLED && !IsFactoryMode()) { /* Automatic startup upon startup */ WIFI_LOGI("AutoStartServiceThread lastState:%{public}d", lastState); - WifiConfigCenter::GetInstance().SetWifiToggledState(lastState); + WifiConfigCenter::GetInstance().SetWifiToggledState(lastState, INSTID_WLAN0); mStartServiceThread = std::make_unique("StartServiceThread"); mStartServiceThread->PostAsyncTask([this]() { AutoStartServiceThread(); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.c b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.c index c2d532f66..e9c6ec036 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.c +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.c @@ -68,7 +68,7 @@ static pthread_mutex_t g_wpaObjMutex = PTHREAD_MUTEX_INITIALIZER; static struct IWpaInterface *g_wpaObj = NULL; static struct HDIDeviceManager *g_devMgr = NULL; static pthread_mutex_t g_ifaceNameMutex = PTHREAD_MUTEX_INITIALIZER; -static char g_staIfaceName[IFACENAME_LEN] = {0}; +static char g_staIfaceName[STA_INSTANCE_MAX_NUM][IFACENAME_LEN] = {{0}, {0}}; static char g_p2pIfaceName[IFACENAME_LEN] = {0}; const char *HDI_AP_SERVICE_NAME = "hostapd_interface_service"; @@ -425,38 +425,56 @@ pthread_mutex_t* GetWpaObjMutex(void) return &g_wpaObjMutex; } -WifiErrorNo SetHdiStaIfaceName(const char *ifaceName) +WifiErrorNo SetHdiStaIfaceName(const char *ifaceName, int instId) { pthread_mutex_lock(&g_ifaceNameMutex); - if (ifaceName == NULL) { + LOGI("SetHdiStaIfaceName enter instId = %{public}d", instId); + if (ifaceName == NULL || instId >= STA_INSTANCE_MAX_NUM) { pthread_mutex_unlock(&g_ifaceNameMutex); return WIFI_HAL_OPT_INVALID_PARAM; } - if (memset_s(g_staIfaceName, IFACENAME_LEN, 0, IFACENAME_LEN) != EOK) { + if (memset_s(g_staIfaceName[instId], IFACENAME_LEN, 0, IFACENAME_LEN) != EOK) { pthread_mutex_unlock(&g_ifaceNameMutex); return WIFI_HAL_OPT_FAILED; } - if (strcpy_s(g_staIfaceName, IFACENAME_LEN, ifaceName) != EOK) { + if (strcpy_s(g_staIfaceName[instId], IFACENAME_LEN, ifaceName) != EOK) { pthread_mutex_unlock(&g_ifaceNameMutex); return WIFI_HAL_OPT_FAILED; } - LOGI("SetHdiStaIfaceName, g_staIfaceName:%{public}s", g_staIfaceName); + LOGI("SetHdiStaIfaceName, g_staIfaceName:%{public}s, instId = %{public}d", g_staIfaceName[instId], instId); pthread_mutex_unlock(&g_ifaceNameMutex); return WIFI_HAL_OPT_OK; } -const char *GetHdiStaIfaceName() +const char *GetHdiStaIfaceName(int instId) { + LOGI("GetHdiStaIfaceName enter instId = %{public}d", instId); const char *ifaceName = NULL; + if (instId >= STA_INSTANCE_MAX_NUM) { + LOGE("invalid param instId = %{public}d", instId); + return ifaceName; + } + pthread_mutex_lock(&g_ifaceNameMutex); - ifaceName = g_staIfaceName; + ifaceName = g_staIfaceName[instId]; pthread_mutex_unlock(&g_ifaceNameMutex); + LOGI("GetHdiStaIfaceName enter ifaceName = %{public}s", ifaceName); return ifaceName; } +void ClearHdiStaIfaceName(int instId) +{ + pthread_mutex_lock(&g_ifaceNameMutex); + if (memset_s(g_staIfaceName[instId], IFACENAME_LEN, 0, IFACENAME_LEN) != EOK) { + pthread_mutex_unlock(&g_ifaceNameMutex); + return; + } + pthread_mutex_unlock(&g_ifaceNameMutex); +} + WifiErrorNo SetHdiP2pIfaceName(const char *ifaceName) { pthread_mutex_lock(&g_ifaceNameMutex); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.h index 13582ad19..b52ee2d13 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_proxy.h @@ -101,8 +101,9 @@ WifiErrorNo HdiAddWpaIface(const char *ifName, const char *confName); */ WifiErrorNo HdiRemoveWpaIface(const char *ifName); -WifiErrorNo SetHdiStaIfaceName(const char *ifaceName); -const char *GetHdiStaIfaceName(); +WifiErrorNo SetHdiStaIfaceName(const char *ifaceName, int instId); +const char *GetHdiStaIfaceName(int instId); +void ClearHdiStaIfaceName(int instId); WifiErrorNo SetHdiP2pIfaceName(const char *ifaceName); const char *GetHdiP2pIfaceName(); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.c b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.c index 636dc60ab..ae7e901f0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.c +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.c @@ -32,10 +32,17 @@ #define REPLY_BUF_LENGTH (4096 * 10) #define ETH_ADDR_LEN 6 +#ifndef INSTID_WLAN0 +#define INSTID_WLAN0 (0) +#endif +#ifndef INSTID_WLAN1 +#define INSTID_WLAN1 (1) +#endif + const int QUOTATION_MARKS_FLAG_YES = 0; const int QUOTATION_MARKS_FLAG_NO = 1; -static struct IWpaCallback *g_hdiWpaStaCallbackObj = NULL; +static struct IWpaCallback *g_hdiWpaStaCallbackObj[STA_INSTANCE_MAX_NUM]; static WpaSsidField g_wpaSsidFields[] = { {DEVICE_CONFIG_SSID, "ssid", QUOTATION_MARKS_FLAG_YES}, {DEVICE_CONFIG_PSK, "psk", QUOTATION_MARKS_FLAG_YES}, @@ -69,11 +76,33 @@ static WpaSsidField g_wpaSsidFields[] = { {DEVICE_CONFIG_WAPI_CA_CERT, "wapi_ca_cert", QUOTATION_MARKS_FLAG_YES}, }; -static WifiErrorNo RegisterEventCallback() +static int GetInstId(const char *ifaceName) { - LOGI("RegisterEventCallback enter"); + int inst = INSTID_WLAN0; + if (ifaceName == NULL) { + LOGE("GetInstId ifaceName is null"); + return inst; + } + for (int instId = 0; instId < STA_INSTANCE_MAX_NUM; instId++) { + const char *hdiStaIfname = GetHdiStaIfaceName(instId); + if (hdiStaIfname == NULL) { + continue; + } + if (strcmp(ifaceName, hdiStaIfname) == 0) { + inst = instId; + break; + } + } + LOGI("GetInstId ifaceName = %{public}sm instId = %{public}d", ifaceName, inst); + return inst; +} + +static WifiErrorNo RegisterEventCallback(const char *ifaceName) +{ + LOGI("RegisterEventCallback enter! ifaceName = %{puiblic}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); - if (g_hdiWpaStaCallbackObj == NULL) { + int instId = GetInstId(ifaceName); + if (g_hdiWpaStaCallbackObj[instId] == NULL) { pthread_mutex_unlock(GetWpaObjMutex()); LOGE("RegisterEventCallback: g_hdiWpaStaCallbackObj is NULL"); return WIFI_HAL_OPT_FAILED; @@ -86,7 +115,7 @@ static WifiErrorNo RegisterEventCallback() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->RegisterWpaEventCallback(wpaObj, g_hdiWpaStaCallbackObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->RegisterWpaEventCallback(wpaObj, g_hdiWpaStaCallbackObj[instId], ifaceName); if (result != HDF_SUCCESS) { pthread_mutex_unlock(GetWpaObjMutex()); LOGE("RegisterEventCallback: RegisterEventCallback failed result:%{public}d", result); @@ -98,11 +127,17 @@ static WifiErrorNo RegisterEventCallback() return WIFI_HAL_OPT_OK; } -static WifiErrorNo UnRegisterEventCallback() +static WifiErrorNo UnRegisterEventCallback(const char *ifaceName) { - LOGI("UnRegisterEventCallback enter"); + LOGI("UnRegisterEventCallback enter! ifaceName = %{public}s", ifaceName); + if (ifaceName == NULL) { + LOGE("UnRegisterEventCallback ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } pthread_mutex_lock(GetWpaObjMutex()); - if (g_hdiWpaStaCallbackObj != NULL) { + int instId = GetInstId(ifaceName); + LOGI("UnRegisterEventCallback enter! instId = %{puiblic}d", instId); + if (g_hdiWpaStaCallbackObj[instId] != NULL) { struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { pthread_mutex_unlock(GetWpaObjMutex()); @@ -110,15 +145,15 @@ static WifiErrorNo UnRegisterEventCallback() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->UnregisterWpaEventCallback(wpaObj, g_hdiWpaStaCallbackObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->UnregisterWpaEventCallback(wpaObj, g_hdiWpaStaCallbackObj[instId], ifaceName); if (result != HDF_SUCCESS) { pthread_mutex_unlock(GetWpaObjMutex()); LOGE("UnRegisterEventCallback: UnregisterEventCallback failed result:%{public}d", result); return WIFI_HAL_OPT_FAILED; } - StubCollectorRemoveObject(IWPACALLBACK_INTERFACE_DESC, g_hdiWpaStaCallbackObj); - free(g_hdiWpaStaCallbackObj); - g_hdiWpaStaCallbackObj = NULL; + StubCollectorRemoveObject(IWPACALLBACK_INTERFACE_DESC, g_hdiWpaStaCallbackObj[instId]); + free(g_hdiWpaStaCallbackObj[instId]); + g_hdiWpaStaCallbackObj[instId] = NULL; } pthread_mutex_unlock(GetWpaObjMutex()); @@ -150,8 +185,12 @@ static int CalcQuotationMarksFlag(int pos, const char value[WIFI_NETWORK_CONFIG_ return flag; } -static WifiErrorNo SetNetwork(int networkId, SetNetworkConfig conf) +static WifiErrorNo SetNetwork(int networkId, SetNetworkConfig conf, const char *ifaceName) { + if (ifaceName == NULL) { + LOGE("GetInstId ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } int pos = -1; for (unsigned i = 0; i < sizeof(g_wpaSsidFields) / sizeof(g_wpaSsidFields[0]); ++i) { if (g_wpaSsidFields[i].field == conf.cfgParam) { @@ -183,22 +222,25 @@ static WifiErrorNo SetNetwork(int networkId, SetNetworkConfig conf) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SetNetwork(wpaObj, GetHdiStaIfaceName(), networkId, g_wpaSsidFields[pos].fieldName, - conf.cfgValue); + int32_t result = wpaObj->SetNetwork(wpaObj, ifaceName, networkId, g_wpaSsidFields[pos].fieldName, conf.cfgValue); if (result != HDF_SUCCESS) { LOGE("SetNetwork: SetNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); return WIFI_HAL_OPT_FAILED; } pthread_mutex_unlock(GetWpaObjMutex()); - LOGI("SetNetwork success."); + LOGI("SetNetwork success. ifaceName = %{public}s", ifaceName); return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaStart(const char *ifaceName) +WifiErrorNo HdiWpaStaStart(const char *ifaceName, int instId) { - LOGI("HdiWpaStaStart enter"); - if (SetHdiStaIfaceName(ifaceName) != WIFI_HAL_OPT_OK) { + if (ifaceName == NULL) { + LOGE("HdiWpaStaStart ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaStart enter! ifaceName = %{public}s, instId = %{public}d", ifaceName, instId); + if (SetHdiStaIfaceName(ifaceName, instId) != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStart: set sta iface name failed!"); return WIFI_HAL_OPT_FAILED; } @@ -213,12 +255,12 @@ WifiErrorNo HdiWpaStaStart(const char *ifaceName) return WIFI_HAL_OPT_FAILED; } - if (RegisterEventCallback() != WIFI_HAL_OPT_OK) { + if (RegisterEventCallback(ifaceName) != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStart: RegisterEventCallback failed!"); return WIFI_HAL_OPT_FAILED; } - if (HdiAddWpaIface(GetHdiStaIfaceName(), CONFIG_ROOR_DIR"/wpa_supplicant/wpa_supplicant.conf") != WIFI_HAL_OPT_OK) { + if (HdiAddWpaIface(ifaceName, CONFIG_ROOR_DIR "/wpa_supplicant/wpa_supplicant.conf") != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStart: HdiAddWpaIface failed!"); return WIFI_HAL_OPT_FAILED; } @@ -227,30 +269,60 @@ WifiErrorNo HdiWpaStaStart(const char *ifaceName) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaStop() +static WifiErrorNo HdiWpaStaStopWifi(int instId) { - LOGI("HdiWpaStaStop enter"); + for (int inst = instId; inst < STA_INSTANCE_MAX_NUM; inst++) { + const char *ifaceName = GetHdiStaIfaceName(instId); + if (ifaceName == NULL) { + LOGE("HdiWpaStopWifi ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + if (HdiRemoveWpaIface(ifaceName) != WIFI_HAL_OPT_OK) { + LOGE("HdiWpaStop: HdiRemoveWpaIface failed"); + return WIFI_HAL_OPT_FAILED; + } + if (UnRegisterEventCallback(ifaceName) != WIFI_HAL_OPT_OK) { + LOGE("HdiWpaStop: UnRegisterEventCallback failed"); + return WIFI_HAL_OPT_FAILED; + } + ClearHdiStaIfaceName(instId); + LOGI("HdiWpaStaStopWifi success, instId = %{public}d, ifaceName = %{public}s", instId, ifaceName); + } + return WIFI_HAL_OPT_OK; +} + +WifiErrorNo HdiWpaStaStop(int instId) +{ + LOGI("HdiWpaStaStop enter, instId = %{public}d", instId); if (IsHdiWpaStopped() == WIFI_HAL_OPT_OK) { LOGI("HdiWpa already stopped, HdiWpaStaStop success!"); return WIFI_HAL_OPT_OK; } - do { - if (HdiRemoveWpaIface(GetHdiP2pIfaceName()) != WIFI_HAL_OPT_OK) { - LOGE("HdiWpaStaStop: HdiRemoveWpaP2pIface failed!"); - break; + if (instId == INSTID_WLAN1) { + const char *ifaceName = GetHdiStaIfaceName(instId); + if (ifaceName == NULL) { + LOGE("HdiWpaStaStopWifi ifaceName is null"); + return WIFI_HAL_OPT_FAILED; } - - if (HdiRemoveWpaIface(GetHdiStaIfaceName()) != WIFI_HAL_OPT_OK) { + if (HdiRemoveWpaIface(ifaceName) != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStop: HdiRemoveWpaStaIface failed!"); - break; + return WIFI_HAL_OPT_FAILED; } - - if (UnRegisterEventCallback() != WIFI_HAL_OPT_OK) { + if (UnRegisterEventCallback(ifaceName) != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStop: UnRegisterEventCallback failed!"); - break; + return WIFI_HAL_OPT_FAILED; } - } while (0); + ClearHdiStaIfaceName(instId); + LOGI("HdiWpaStaStopWifi success, instId = %{public}d, ifaceName = %{public}s", instId, ifaceName); + return WIFI_HAL_OPT_OK; + } + + if (HdiRemoveWpaIface(GetHdiP2pIfaceName()) != WIFI_HAL_OPT_OK) { + LOGE("HdiWpaStaStop: HdiRemoveWpaP2pIface failed!"); + } + + HdiWpaStaStopWifi(INSTID_WLAN0); if (HdiWpaStop() != WIFI_HAL_OPT_OK) { LOGE("HdiWpaStaStop: HdiWpaStaStop failed!"); @@ -261,9 +333,13 @@ WifiErrorNo HdiWpaStaStop() return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaConnect(int networkId) +WifiErrorNo HdiWpaStaConnect(int networkId, const char *ifaceName) { - LOGI("HdiWpaStaConnect enter, networkId:%{public}d", networkId); + if (ifaceName == NULL) { + LOGE("HdiWpaStaConnect ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaConnect enter, networkId:%{public}d, ifaceName = %{public}s", networkId, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -272,7 +348,7 @@ WifiErrorNo HdiWpaStaConnect(int networkId) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SelectNetwork(wpaObj, GetHdiStaIfaceName(), networkId); + int32_t result = wpaObj->SelectNetwork(wpaObj, ifaceName, networkId); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaConnect: SelectNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -283,9 +359,13 @@ WifiErrorNo HdiWpaStaConnect(int networkId) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaReconnect() +WifiErrorNo HdiWpaStaReconnect(const char *ifaceName) { - LOGI("HdiWpaStaReconnect enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaReconnect ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaReconnect enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -294,7 +374,7 @@ WifiErrorNo HdiWpaStaReconnect() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->Reconnect(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->Reconnect(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaReconnect: Reconnect failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -305,8 +385,12 @@ WifiErrorNo HdiWpaStaReconnect() return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaReassociate() +WifiErrorNo HdiWpaStaReassociate(const char *ifaceName) { + if (ifaceName == NULL) { + LOGE("HdiWpaStaReassociate ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -315,7 +399,7 @@ WifiErrorNo HdiWpaStaReassociate() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->Reassociate(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->Reassociate(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaReassociate: Reassociate failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -325,9 +409,13 @@ WifiErrorNo HdiWpaStaReassociate() return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaDisconnect() +WifiErrorNo HdiWpaStaDisconnect(const char *ifaceName) { - LOGI("HdiWpaStaDisconnect enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaDisconnect ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaDisconnect enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -336,7 +424,7 @@ WifiErrorNo HdiWpaStaDisconnect() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->Disconnect(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->Disconnect(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaDisconnect: Disconnect failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -385,9 +473,9 @@ static void HdiWpaFree(struct HdiWpaCmdStatus *status) } } -WifiErrorNo HdiWpaStaGetDeviceMacAddress(char *macAddr, int macAddrLen) +WifiErrorNo HdiWpaStaGetDeviceMacAddress(char *macAddr, int macAddrLen, const char *ifaceName) { - LOGI("HdiWpaStaGetDeviceMacAddress enter"); + LOGI("HdiWpaStaGetDeviceMacAddress enter! ifaceName = %{public}s", ifaceName); if (macAddr == NULL) { LOGE("HdiWpaStaGetDeviceMacAddress: invalid parameter!"); return WIFI_HAL_OPT_INVALID_PARAM; @@ -403,7 +491,7 @@ WifiErrorNo HdiWpaStaGetDeviceMacAddress(char *macAddr, int macAddrLen) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->WifiStatus(wpaObj, GetHdiStaIfaceName(), &status); + int32_t result = wpaObj->WifiStatus(wpaObj, ifaceName, &status); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaGetDeviceMacAddress: WifiStatus failed result:%{public}d", result); HdiWpaFree(&status); @@ -441,7 +529,7 @@ WifiErrorNo HdiWpaStaScan() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->Scan(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->Scan(wpaObj, GetHdiStaIfaceName(INSTID_WLAN0)); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaScan: Scan failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -452,11 +540,11 @@ WifiErrorNo HdiWpaStaScan() return WIFI_HAL_OPT_OK; } -ScanInfo *HdiWpaStaGetScanInfos(int *size) +ScanInfo *HdiWpaStaGetScanInfos(int *size, const char *ifaceName) { LOGI("HdiWpaStaGetScanInfos enter"); - if (size == NULL) { - LOGE("HdiWpaStaGetScanInfos: invalid parameter!"); + if (ifaceName == NULL || size == NULL) { + LOGE("HdiWpaStaGetScanInfos ifaceName is null"); return NULL; } @@ -486,7 +574,7 @@ ScanInfo *HdiWpaStaGetScanInfos(int *size) return NULL; } - int32_t result = wpaObj->ScanResult(wpaObj, GetHdiStaIfaceName(), resultBuff, &resultBuffLen); + int32_t result = wpaObj->ScanResult(wpaObj, ifaceName, resultBuff, &resultBuffLen); if (result != HDF_SUCCESS) { free(results); free(resultBuff); @@ -533,9 +621,13 @@ ScanInfo *HdiWpaStaGetScanInfos(int *size) return results; } -WifiErrorNo HdiWpaStaRemoveNetwork(int networkId) +WifiErrorNo HdiWpaStaRemoveNetwork(int networkId, const char *ifaceName) { - LOGI("HdiWpaStaRemoveNetwork enter, networkId:%{public}d", networkId); + if (ifaceName == NULL) { + LOGE("HdiWpaStaRemoveNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaRemoveNetwork enter, networkId:%{public}d, ifaceName = %{public}s", networkId, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -544,7 +636,7 @@ WifiErrorNo HdiWpaStaRemoveNetwork(int networkId) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->RemoveNetwork(wpaObj, GetHdiStaIfaceName(), networkId); + int32_t result = wpaObj->RemoveNetwork(wpaObj, ifaceName, networkId); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaRemoveNetwork: RemoveNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -555,9 +647,13 @@ WifiErrorNo HdiWpaStaRemoveNetwork(int networkId) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaAddNetwork(int *networkId) +WifiErrorNo HdiWpaStaAddNetwork(int *networkId, const char *ifaceName) { - LOGI("HdiWpaStaAddNetwork enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaAddNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaAddNetwork enter! ifaceName = %{public}s", ifaceName); if (networkId == NULL) { LOGE("HdiWpaStaAddNetwork: invalid parameter!"); return WIFI_HAL_OPT_INVALID_PARAM; @@ -570,7 +666,7 @@ WifiErrorNo HdiWpaStaAddNetwork(int *networkId) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->AddNetwork(wpaObj, GetHdiStaIfaceName(), networkId); + int32_t result = wpaObj->AddNetwork(wpaObj, ifaceName, networkId); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaAddNetwork: AddNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -581,9 +677,13 @@ WifiErrorNo HdiWpaStaAddNetwork(int *networkId) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaEnableNetwork(int networkId) +WifiErrorNo HdiWpaStaEnableNetwork(int networkId, const char *ifaceName) { - LOGI("HdiWpaStaEnableNetwork enter, networkId:%{public}d", networkId); + if (ifaceName == NULL) { + LOGE("HdiWpaStaEnableNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaEnableNetwork enter, networkId:%{public}d, ifaceName = %{public}s", networkId, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -592,7 +692,7 @@ WifiErrorNo HdiWpaStaEnableNetwork(int networkId) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->EnableNetwork(wpaObj, GetHdiStaIfaceName(), networkId); + int32_t result = wpaObj->EnableNetwork(wpaObj, ifaceName, networkId); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaEnableNetwork: EnableNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -603,9 +703,13 @@ WifiErrorNo HdiWpaStaEnableNetwork(int networkId) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaDisableNetwork(int networkId) +WifiErrorNo HdiWpaStaDisableNetwork(int networkId, const char *ifaceName) { - LOGI("HdiWpaStaDisableNetwork enter, networkId:%{public}d", networkId); + if (ifaceName == NULL) { + LOGE("HdiWpaStaDisableNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaDisableNetwork enter, networkId:%{public}d, ifaceName = %{public}s", networkId, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -614,7 +718,7 @@ WifiErrorNo HdiWpaStaDisableNetwork(int networkId) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->DisableNetwork(wpaObj, GetHdiStaIfaceName(), networkId); + int32_t result = wpaObj->DisableNetwork(wpaObj, ifaceName, networkId); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaDisableNetwork: DisableNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -625,24 +729,32 @@ WifiErrorNo HdiWpaStaDisableNetwork(int networkId) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaSetNetwork(int networkId, SetNetworkConfig *confs, int size) +WifiErrorNo HdiWpaStaSetNetwork(int networkId, SetNetworkConfig *confs, int size, const char *ifaceName) { - LOGI("HdiWpaStaSetNetwork enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaSetNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaSetNetwork enter! ifaceName = %{public}s", ifaceName); if (confs == NULL) { LOGE("HdiWpaStaSetNetwork: invalid parameter!"); return WIFI_HAL_OPT_INVALID_PARAM; } for (int i = 0; i < size; ++i) { - SetNetwork(networkId, confs[i]); + SetNetwork(networkId, confs[i], ifaceName); } return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaSaveConfig() +WifiErrorNo HdiWpaStaSaveConfig(const char *ifaceName) { - LOGI("HdiWpaStaSaveConfig enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaSaveConfig ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaSaveConfig enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -651,7 +763,7 @@ WifiErrorNo HdiWpaStaSaveConfig() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SaveConfig(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->SaveConfig(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaSaveConfig: SaveConfig failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -662,9 +774,13 @@ WifiErrorNo HdiWpaStaSaveConfig() return WIFI_HAL_OPT_OK; } -WifiErrorNo RegisterHdiWpaStaEventCallback(struct IWpaCallback *callback) +WifiErrorNo RegisterHdiWpaStaEventCallback(struct IWpaCallback *callback, const char *ifaceName, int instId) { - LOGI("RegisterHdiWpaStaEventCallback enter"); + if (ifaceName == NULL) { + LOGE("RegisterHdiWpaStaEventCallback ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("RegisterHdiWpaStaEventCallback enter, ifaceName = %{public}s, instId = %{public}d", ifaceName, instId); pthread_mutex_lock(GetWpaObjMutex()); if (callback == NULL || callback->OnEventConnected == NULL) { pthread_mutex_unlock(GetWpaObjMutex()); @@ -672,44 +788,47 @@ WifiErrorNo RegisterHdiWpaStaEventCallback(struct IWpaCallback *callback) return WIFI_HAL_OPT_INVALID_PARAM; } - if (g_hdiWpaStaCallbackObj != NULL) { + if (g_hdiWpaStaCallbackObj[instId] != NULL) { pthread_mutex_unlock(GetWpaObjMutex()); LOGI("RegisterHdiWpaStaEventCallback: already register!"); return WIFI_HAL_OPT_OK; } - g_hdiWpaStaCallbackObj = (struct IWpaCallback *)malloc(sizeof(struct IWpaCallback)); - if (g_hdiWpaStaCallbackObj == NULL) { + g_hdiWpaStaCallbackObj[instId] = (struct IWpaCallback *)malloc(sizeof(struct IWpaCallback)); + if (g_hdiWpaStaCallbackObj[instId] == NULL) { pthread_mutex_unlock(GetWpaObjMutex()); LOGE("RegisterHdiWpaStaEventCallback: IWpaCallback malloc failed!"); return WIFI_HAL_OPT_FAILED; } - if (memset_s(g_hdiWpaStaCallbackObj, sizeof(struct IWpaCallback), - 0, sizeof(struct IWpaCallback)) != EOK) { + if (memset_s(g_hdiWpaStaCallbackObj[instId], sizeof(struct IWpaCallback), 0, sizeof(struct IWpaCallback)) != EOK) { pthread_mutex_unlock(GetWpaObjMutex()); return WIFI_HAL_OPT_FAILED; } - g_hdiWpaStaCallbackObj->OnEventDisconnected = callback->OnEventDisconnected; - g_hdiWpaStaCallbackObj->OnEventConnected = callback->OnEventConnected; - g_hdiWpaStaCallbackObj->OnEventBssidChanged = callback->OnEventBssidChanged; - g_hdiWpaStaCallbackObj->OnEventStateChanged = callback->OnEventStateChanged; - g_hdiWpaStaCallbackObj->OnEventTempDisabled = callback->OnEventTempDisabled; - g_hdiWpaStaCallbackObj->OnEventAssociateReject = callback->OnEventAssociateReject; - g_hdiWpaStaCallbackObj->OnEventWpsOverlap = callback->OnEventWpsOverlap; - g_hdiWpaStaCallbackObj->OnEventWpsTimeout = callback->OnEventWpsTimeout; - g_hdiWpaStaCallbackObj->OnEventAuthTimeout = callback->OnEventAuthTimeout; + g_hdiWpaStaCallbackObj[instId]->OnEventDisconnected = callback->OnEventDisconnected; + g_hdiWpaStaCallbackObj[instId]->OnEventConnected = callback->OnEventConnected; + g_hdiWpaStaCallbackObj[instId]->OnEventBssidChanged = callback->OnEventBssidChanged; + g_hdiWpaStaCallbackObj[instId]->OnEventStateChanged = callback->OnEventStateChanged; + g_hdiWpaStaCallbackObj[instId]->OnEventTempDisabled = callback->OnEventTempDisabled; + g_hdiWpaStaCallbackObj[instId]->OnEventAssociateReject = callback->OnEventAssociateReject; + g_hdiWpaStaCallbackObj[instId]->OnEventWpsOverlap = callback->OnEventWpsOverlap; + g_hdiWpaStaCallbackObj[instId]->OnEventWpsTimeout = callback->OnEventWpsTimeout; + g_hdiWpaStaCallbackObj[instId]->OnEventAuthTimeout = callback->OnEventAuthTimeout; #ifndef HDI_CHIP_INTERFACE_SUPPORT - g_hdiWpaStaCallbackObj->OnEventScanResult = callback->OnEventScanResult; + g_hdiWpaStaCallbackObj[instId]->OnEventScanResult = callback->OnEventScanResult; #endif - g_hdiWpaStaCallbackObj->OnEventStaNotify = callback->OnEventStaNotify; + g_hdiWpaStaCallbackObj[instId]->OnEventStaNotify = callback->OnEventStaNotify; pthread_mutex_unlock(GetWpaObjMutex()); LOGI("RegisterHdiWpaStaEventCallback3 success."); return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config) +WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config, const char *ifaceName) { - LOGI("HdiWpaStaStartWpsPbcMode enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaStartWpsPbcMode ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaStartWpsPbcMode enter! ifaceName = %{public}s", ifaceName); if (config == NULL) { LOGE("HdiWpaStaStartWpsPbcMode: invalid parameter!"); return WIFI_HAL_OPT_INVALID_PARAM; @@ -728,7 +847,7 @@ WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->WpsPbcMode(wpaObj, GetHdiStaIfaceName(), &wpsParam); + int32_t result = wpaObj->WpsPbcMode(wpaObj, ifaceName, &wpsParam); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaStartWpsPbcMode: WpsPbcMode failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -739,9 +858,13 @@ WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode) +WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode, const char *ifaceName) { - LOGI("HdiWpaStaStartWpsPinMode enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaStartWpsPinMode ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaStartWpsPinMode enter! ifaceName = %{public}s", ifaceName); if (config == NULL || pinCode == NULL) { LOGE("HdiWpaStaStartWpsPinMode: invalid parameter!"); return WIFI_HAL_OPT_INVALID_PARAM; @@ -762,7 +885,7 @@ WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->WpsPinMode(wpaObj, GetHdiStaIfaceName(), &wpsParam, pinCode); + int32_t result = wpaObj->WpsPinMode(wpaObj, ifaceName, &wpsParam, pinCode); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaStartWpsPinMode: WpsPbcMode failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -773,9 +896,13 @@ WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiStopWpsSta() +WifiErrorNo HdiStopWpsSta(const char *ifaceName) { - LOGI("HdiStopWpsSta enter"); + if (ifaceName == NULL) { + LOGE("HdiStopWpsSta ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiStopWpsSta enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -784,7 +911,7 @@ WifiErrorNo HdiStopWpsSta() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->WpsCancel(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->WpsCancel(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiStopWpsSta: WpsCancel failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -795,9 +922,13 @@ WifiErrorNo HdiStopWpsSta() return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaAutoConnect(int enable) +WifiErrorNo HdiWpaStaAutoConnect(int enable, const char *ifaceName) { - LOGI("HdiWpaStaAutoConnect enter, enable:%{public}d", enable); + if (ifaceName == NULL) { + LOGE("HdiWpaStaAutoConnect ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaAutoConnect enter, enable:%{public}d, ifaceName = %{public}s", enable, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -806,7 +937,7 @@ WifiErrorNo HdiWpaStaAutoConnect(int enable) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->AutoConnect(wpaObj, GetHdiStaIfaceName(), enable); + int32_t result = wpaObj->AutoConnect(wpaObj, ifaceName, enable); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaAutoConnect: AutoConnect failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -817,9 +948,13 @@ WifiErrorNo HdiWpaStaAutoConnect(int enable) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaBlocklistClear() +WifiErrorNo HdiWpaStaBlocklistClear(const char *ifaceName) { - LOGI("HdiWpaStaBlocklistClear enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaStaBlocklistClear ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaBlocklistClear enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -828,7 +963,7 @@ WifiErrorNo HdiWpaStaBlocklistClear() return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->BlocklistClear(wpaObj, GetHdiStaIfaceName()); + int32_t result = wpaObj->BlocklistClear(wpaObj, ifaceName); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaBlocklistClear: BlocklistClear failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -839,9 +974,13 @@ WifiErrorNo HdiWpaStaBlocklistClear() return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaSetPowerSave(int enable) +WifiErrorNo HdiWpaStaSetPowerSave(int enable, const char *ifaceName) { - LOGI("HdiWpaStaSetPowerSave enter, enable:%{public}d", enable); + if (ifaceName == NULL) { + LOGE("HdiWpaStaSetPowerSave ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaSetPowerSave enter, enable:%{public}d, ifaceName = %{public}s", enable, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -850,7 +989,7 @@ WifiErrorNo HdiWpaStaSetPowerSave(int enable) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SetPowerSave(wpaObj, GetHdiStaIfaceName(), enable); + int32_t result = wpaObj->SetPowerSave(wpaObj, ifaceName, enable); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaSetPowerSave: SetPowerSave failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -861,9 +1000,13 @@ WifiErrorNo HdiWpaStaSetPowerSave(int enable) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode) +WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode, const char *ifaceName) { - LOGI("HdiWpaStaSetCountryCode enter, enable:%{public}s", countryCode); + if (ifaceName == NULL) { + LOGE("HdiWpaStaSetCountryCode ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaSetCountryCode enter, enable:%{public}s, ifaceName = %{public}s", countryCode, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -872,7 +1015,7 @@ WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SetCountryCode(wpaObj, GetHdiStaIfaceName(), countryCode); + int32_t result = wpaObj->SetCountryCode(wpaObj, ifaceName, countryCode); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaSetCountryCode: SetCountryCode failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -883,9 +1026,13 @@ WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size) +WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size, const char *ifaceName) { - LOGI("HdiWpaStaGetCountryCode enter, enable:%{public}s", countryCode); + if (ifaceName == NULL) { + LOGE("HdiWpaStaGetCountryCode ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaGetCountryCode enter, enable:%{public}s, ifaceName = %{public}s", countryCode, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -894,7 +1041,7 @@ WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->GetCountryCode(wpaObj, GetHdiStaIfaceName(), countryCode, size); + int32_t result = wpaObj->GetCountryCode(wpaObj, ifaceName, countryCode, size); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaGetCountryCode: SetCountryCode failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -905,9 +1052,13 @@ WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaStaSetSuspendMode(int mode) +WifiErrorNo HdiWpaStaSetSuspendMode(int mode, const char *ifaceName) { - LOGI("HdiWpaStaSetSuspendMode enter, mode:%{public}d", mode); + if (ifaceName == NULL) { + LOGE("HdiWpaStaSetSuspendMode ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaStaSetSuspendMode enter, mode:%{public}d, ifaceName = %{public}s", mode, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -916,7 +1067,7 @@ WifiErrorNo HdiWpaStaSetSuspendMode(int mode) return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->SetSuspendMode(wpaObj, GetHdiStaIfaceName(), mode); + int32_t result = wpaObj->SetSuspendMode(wpaObj, ifaceName, mode); if (result != HDF_SUCCESS) { LOGE("HdiWpaStaSetSuspendMode: SetSuspendMode failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -927,9 +1078,13 @@ WifiErrorNo HdiWpaStaSetSuspendMode(int mode) return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32_t *size) +WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32_t *size, const char *ifaceName) { - LOGI("HdiWpaListNetworks enter"); + if (ifaceName == NULL) { + LOGE("HdiWpaListNetworks ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaListNetworks enter! ifaceName = %{public}s", ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -938,7 +1093,7 @@ WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32 return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->ListNetworks(wpaObj, GetHdiStaIfaceName(), networkList, size); + int32_t result = wpaObj->ListNetworks(wpaObj, ifaceName, networkList, size); if (result != HDF_SUCCESS) { LOGE("HdiWpaListNetworks: ListNetworks failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); @@ -949,9 +1104,14 @@ WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32 return WIFI_HAL_OPT_OK; } -WifiErrorNo HdiWpaGetNetwork(int32_t networkId, const char* param, char* value, uint32_t valueLen) +WifiErrorNo HdiWpaGetNetwork( + int32_t networkId, const char* param, char* value, uint32_t valueLen, const char *ifaceName) { - LOGI("HdiWpaGetNetwork enter,networkId:%{public}d", networkId); + if (ifaceName == NULL) { + LOGE("HdiWpaGetNetwork ifaceName is null"); + return WIFI_HAL_OPT_FAILED; + } + LOGI("HdiWpaGetNetwork enter,networkId:%{public}d, ifaceName = %{public}s", networkId, ifaceName); pthread_mutex_lock(GetWpaObjMutex()); struct IWpaInterface *wpaObj = GetWpaInterface(); if (wpaObj == NULL) { @@ -960,7 +1120,7 @@ WifiErrorNo HdiWpaGetNetwork(int32_t networkId, const char* param, char* value, return WIFI_HAL_OPT_FAILED; } - int32_t result = wpaObj->GetNetwork(wpaObj, GetHdiStaIfaceName(), networkId, param, value, valueLen); + int32_t result = wpaObj->GetNetwork(wpaObj, ifaceName, networkId, param, value, valueLen); if (result != HDF_SUCCESS) { LOGE("HdiWpaGetNetwork: GetNetwork failed result:%{public}d", result); pthread_mutex_unlock(GetWpaObjMutex()); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.h index dad50ac83..483c18642 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl.h @@ -24,59 +24,60 @@ extern "C" { #endif -WifiErrorNo HdiWpaStaStart(const char *ifaceName); +WifiErrorNo HdiWpaStaStart(const char *ifaceName, int instId); -WifiErrorNo HdiWpaStaStop(); +WifiErrorNo HdiWpaStaStop(int instId); -WifiErrorNo HdiWpaStaConnect(int networkId); +WifiErrorNo HdiWpaStaConnect(int networkId, const char *ifaceName); -WifiErrorNo HdiWpaStaReconnect(); +WifiErrorNo HdiWpaStaReconnect(const char *ifaceName); -WifiErrorNo HdiWpaStaReassociate(); +WifiErrorNo HdiWpaStaReassociate(const char *ifaceName); -WifiErrorNo HdiWpaStaDisconnect(); +WifiErrorNo HdiWpaStaDisconnect(const char *ifaceName); -WifiErrorNo HdiWpaStaGetDeviceMacAddress(char *macAddr, int macAddrLen); +WifiErrorNo HdiWpaStaGetDeviceMacAddress(char *macAddr, int macAddrLen, const char *ifaceName); WifiErrorNo HdiWpaStaScan(); -ScanInfo *HdiWpaStaGetScanInfos(int *size); +ScanInfo *HdiWpaStaGetScanInfos(int *size, const char *ifaceName); -WifiErrorNo HdiWpaStaRemoveNetwork(int networkId); +WifiErrorNo HdiWpaStaRemoveNetwork(int networkId, const char *ifaceName); -WifiErrorNo HdiWpaStaAddNetwork(int *networkId); +WifiErrorNo HdiWpaStaAddNetwork(int *networkId, const char *ifaceName); -WifiErrorNo HdiWpaStaEnableNetwork(int networkId); +WifiErrorNo HdiWpaStaEnableNetwork(int networkId, const char *ifaceName); -WifiErrorNo HdiWpaStaDisableNetwork(int networkId); +WifiErrorNo HdiWpaStaDisableNetwork(int networkId, const char *ifaceName); -WifiErrorNo HdiWpaStaSetNetwork(int networkId, SetNetworkConfig *confs, int size); +WifiErrorNo HdiWpaStaSetNetwork(int networkId, SetNetworkConfig *confs, int size, const char *ifaceName); -WifiErrorNo HdiWpaStaSaveConfig(); +WifiErrorNo HdiWpaStaSaveConfig(const char *ifaceName); -WifiErrorNo RegisterHdiWpaStaEventCallback(struct IWpaCallback *callback); +WifiErrorNo RegisterHdiWpaStaEventCallback(struct IWpaCallback *callback, const char *ifaceName, int instId); -WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config); +WifiErrorNo HdiWpaStaStartWpsPbcMode(WifiWpsParam *config, const char *ifaceName); -WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode); +WifiErrorNo HdiWpaStaStartWpsPinMode(WifiWpsParam *config, int *pinCode, const char *ifaceName); -WifiErrorNo HdiStopWpsSta(); +WifiErrorNo HdiStopWpsSta(const char *ifaceName); -WifiErrorNo HdiWpaStaAutoConnect(int enable); +WifiErrorNo HdiWpaStaAutoConnect(int enable, const char *ifaceName); -WifiErrorNo HdiWpaStaBlocklistClear(); +WifiErrorNo HdiWpaStaBlocklistClear(const char *ifaceName); -WifiErrorNo HdiWpaStaSetPowerSave(int enable); +WifiErrorNo HdiWpaStaSetPowerSave(int enable, const char *ifaceName); -WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode); +WifiErrorNo HdiWpaStaSetCountryCode(const char *countryCode, const char *ifaceName); -WifiErrorNo HdiWpaStaSetSuspendMode(int mode); +WifiErrorNo HdiWpaStaSetSuspendMode(int mode, const char *ifaceName); -WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size); +WifiErrorNo HdiWpaStaGetCountryCode(char *countryCode, uint32_t size, const char *ifaceName); -WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32_t *size); +WifiErrorNo HdiWpaListNetworks(struct HdiWifiWpaNetworkInfo *networkList, uint32_t *size, const char *ifaceName); -WifiErrorNo HdiWpaGetNetwork(int32_t networkId, const char* param, char* value, uint32_t valueLen); +WifiErrorNo HdiWpaGetNetwork( + int32_t networkId, const char* param, char* value, uint32_t valueLen, const char *ifaceName); WifiErrorNo HdiWpaStaSetShellCmd(const char *ifName, const char *cmd); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_callback.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_callback.cpp index a1d451f32..4a5f24b2c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_callback.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_callback.cpp @@ -45,7 +45,11 @@ int g_currentWpaStatus = static_cast(OHOS::Wifi::SupplicantState::UNKNOWN); int32_t OnEventDisconnected(struct IWpaCallback *self, const struct HdiWpaDisconnectParam *disconectParam, const char* ifName) { - LOGI("OnEventDisconnected: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventDisconnected: invalid ifName!"); + return 1; + } + LOGI("OnEventDisconnected: callback enter! ifName = %{public}s", ifName); if (disconectParam == NULL || disconectParam->bssidLen <= 0) { LOGE("OnEventDisconnected: invalid parameter!"); return 1; @@ -57,7 +61,7 @@ int32_t OnEventDisconnected(struct IWpaCallback *self, return 1; } int reasonCode = disconectParam->reasonCode; - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onReportDisConnectReason) { cbk.onReportDisConnectReason(reasonCode, std::string(szBssid)); } @@ -82,14 +86,21 @@ int32_t OnEventDisconnected(struct IWpaCallback *self, if (cbk.onConnectChanged) { cbk.onConnectChanged(HAL_WPA_CB_DISCONNECTED, reasonCode, std::string(szBssid)); } - LOGI("%{public}s callback out, bssid:%{public}s", __func__, OHOS::Wifi::MacAnonymize(szBssid).c_str()); + LOGI("%{public}s callback out, bssid:%{public}s ifName = %{public}s", + __func__, + OHOS::Wifi::MacAnonymize(szBssid).c_str(), + ifName); return 0; } int32_t OnEventConnected(struct IWpaCallback *self, const struct HdiWpaConnectParam *connectParam, const char* ifName) { - LOGI("OnEventConnected: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventConnected: invalid ifName!"); + return 1; + } + LOGI("OnEventConnected: callback enter! ifName = %{public}s", ifName); if (connectParam == NULL || connectParam->bssidLen <= 0) { LOGE("OnEventConnected: invalid parameter!"); return 1; @@ -100,7 +111,7 @@ int32_t OnEventConnected(struct IWpaCallback *self, LOGE("%{public}s: failed to convert mac!", __func__); return 1; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onConnectChanged) { cbk.onConnectChanged(HAL_WPA_CB_CONNECTED, connectParam->networkId, szBssid); } @@ -111,7 +122,11 @@ int32_t OnEventConnected(struct IWpaCallback *self, int32_t OnEventBssidChanged(struct IWpaCallback *self, const struct HdiWpaBssidChangedParam *bssidChangedParam, const char* ifName) { - LOGI("OnEventBssidChanged: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventBssidChanged: invalid ifName!"); + return 1; + } + LOGI("OnEventBssidChanged: callback enter! ifName = %{public}s", ifName); if (bssidChangedParam == nullptr || bssidChangedParam->reason == nullptr) { LOGE("OnEventBssidChanged: invalid parameter!"); return 1; @@ -129,7 +144,7 @@ int32_t OnEventBssidChanged(struct IWpaCallback *self, return 1; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onBssidChanged) { cbk.onBssidChanged(reason, szBssid); } @@ -141,25 +156,33 @@ int32_t OnEventBssidChanged(struct IWpaCallback *self, int32_t OnEventStateChanged(struct IWpaCallback *self, const struct HdiWpaStateChangedParam *statechangedParam, const char* ifName) { - LOGI("OnEventStateChanged: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventStateChanged: invalid ifName!"); + return 1; + } + LOGI("OnEventStateChanged: callback enter! ifName = %{public}s", ifName); if (statechangedParam == NULL) { LOGE("OnEventStateChanged: invalid parameter!"); return 1; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); g_currentWpaStatus = statechangedParam->status; if (cbk.onWpaStateChanged) { cbk.onWpaStateChanged(g_currentWpaStatus); } - LOGI("OnEventStateChanged:callback out status = %{public}d", g_currentWpaStatus); + LOGI("OnEventStateChanged:callback out status = %{public}d, ifName = %{public}s", g_currentWpaStatus, ifName); return 0; } int32_t OnEventTempDisabled(struct IWpaCallback *self, const struct HdiWpaTempDisabledParam *tempDisabledParam, const char *ifName) { - LOGI("OnEventTempDisabled: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventTempDisabled: invalid ifName!"); + return 1; + } + LOGI("OnEventTempDisabled: callback enter! ifName = %{public}s", ifName); if (tempDisabledParam == NULL) { LOGE("OnEventTempDisabled tempDisabledParam is NULL"); @@ -173,9 +196,11 @@ int32_t OnEventTempDisabled(struct IWpaCallback *self, if (tempDisabledParam->reason != NULL && tempDisabledParam->reasonLen > 0) { reason = std::string(tempDisabledParam->reason, tempDisabledParam->reason + tempDisabledParam->reasonLen); } - LOGI("OnEventTempDisabled ssid:%{public}s reason:%{public}s", - OHOS::Wifi::SsidAnonymize(ssid).c_str(), reason.c_str()); - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + LOGI("OnEventTempDisabled ssid:%{public}s reason:%{public}s, ifName = %{public}s", + OHOS::Wifi::SsidAnonymize(ssid).c_str(), + reason.c_str(), + ifName); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onWpaSsidWrongKey && reason == "AUTH_FAILED") { cbk.onWpaSsidWrongKey(); } @@ -185,7 +210,11 @@ int32_t OnEventTempDisabled(struct IWpaCallback *self, int32_t OnEventAssociateReject(struct IWpaCallback *self, const struct HdiWpaAssociateRejectParam *associateRejectParam, const char *ifName) { - LOGI("OnEventAssociateReject: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventAssociateReject: invalid ifName!"); + return 1; + } + LOGI("OnEventAssociateReject: callback enter! ifName = %{public}s", ifName); if (associateRejectParam == NULL) { LOGE("OnEventAssociateReject: invalid parameter!"); return 1; @@ -215,7 +244,7 @@ int32_t OnEventAssociateReject(struct IWpaCallback *self, } } } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (isWrongPwd && cbk.onWpaSsidWrongKey) { LOGI("onWpaConnectionRejectCallBack, wrong password"); cbk.onWpaSsidWrongKey(); @@ -238,14 +267,19 @@ int32_t OnEventAssociateReject(struct IWpaCallback *self, int32_t OnEventStaNotify(struct IWpaCallback *self, const char* notifyParam, const char *ifName) { - LOGI("OnEventStaNotify: callback enter!"); + if (ifName == nullptr) { + LOGE("OnEventStaNotify: invalid ifName!"); + return 1; + } + LOGI("OnEventStaNotify: callback enter! ifName = %{public}s", ifName); if (notifyParam == NULL) { LOGE("OnEventStaNotify: invalid parameter!"); return 1; } - if (strcmp(ifName, "wlan0") == 0) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + if (strcmp(ifName, "wlan0") == 0 || strcmp(ifName, "wlan1") == 0) { + const OHOS::Wifi::WifiEventCallback &cbk = + OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onEventStaNotify) { cbk.onEventStaNotify(notifyParam); } @@ -260,8 +294,12 @@ int32_t OnEventStaNotify(struct IWpaCallback *self, const char* notifyParam, con int32_t OnEventWpsOverlap(struct IWpaCallback *self, const char *ifName) { - LOGI("OnEventWpsOverlap: callback enter!"); - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + if (ifName == nullptr) { + LOGE("OnEventWpsOverlap: invalid ifName!"); + return 1; + } + LOGI("OnEventWpsOverlap: callback enter! ifName = %{public}s", ifName); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onWpsOverlap) { cbk.onWpsOverlap(1); } @@ -270,8 +308,12 @@ int32_t OnEventWpsOverlap(struct IWpaCallback *self, const char *ifName) int32_t OnEventWpsTimeout(struct IWpaCallback *self, const char *ifName) { - LOGI("OnEventWpsTimeout: callback enter!"); - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + if (ifName == nullptr) { + LOGE("OnEventWpsOverlap: invalid ifName!"); + return 1; + } + LOGI("OnEventWpsTimeout: callback enter! ifName = %{public}s", ifName); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (cbk.onWpsTimeOut) { cbk.onWpsTimeOut(1); } @@ -280,8 +322,12 @@ int32_t OnEventWpsTimeout(struct IWpaCallback *self, const char *ifName) int32_t OnEventAuthTimeout(struct IWpaCallback *self, const char *ifName) { - LOGI("OnEventAuthTimeout: callback enter!"); - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + if (ifName == nullptr) { + LOGE("OnEventWpsOverlap: invalid ifName!"); + return 1; + } + LOGI("OnEventAuthTimeout: callback enter! ifName = %{public}s", ifName); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName); if (g_currentWpaStatus == static_cast(OHOS::Wifi::SupplicantState::FOUR_WAY_HANDSHAKE) && cbk.onWpaSsidWrongKey) { LOGI("OnEventAuthTimeout, wrong password"); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.cpp index 7753d4f0d..b547e9007 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.cpp @@ -31,6 +31,8 @@ #include "wifi_common_util.h" #include "wifi_common_def.h" #include "hdi_struct_toolkit.h" +#include "wifi_hdi_wpa_proxy.h" +#include "define.h" #ifndef UT_TEST #include "wifi_log.h" @@ -62,37 +64,38 @@ constexpr int P2P_SUPPLICANT_CONNECTED = 1; constexpr int SSID_ASSIC_WIDTH = 2; constexpr int BAND_WIDTH_OFFSET = 16; -WifiErrorNo WifiHdiWpaClient::StartWifi(const std::string &ifaceName) +WifiErrorNo WifiHdiWpaClient::StartWifi(const std::string &ifaceName, int instId) { WifiEventCallback callback; callback.onConnectChanged = [](int param1, int param2, const std::string ¶m3) {}; - ReqRegisterStaEventCallback(callback); - return HdiWpaStaStart(ifaceName.c_str()); + ReqRegisterStaEventCallback(callback, ifaceName.c_str(), instId); + LOGI("WifiHdiWpaClient StartWifi ifaceName:%{public}s instId:%{public}d", ifaceName.c_str(), instId); + return HdiWpaStaStart(ifaceName.c_str(), instId); } -WifiErrorNo WifiHdiWpaClient::StopWifi(void) +WifiErrorNo WifiHdiWpaClient::StopWifi(int instId) { - return HdiWpaStaStop(); + return HdiWpaStaStop(instId); } -WifiErrorNo WifiHdiWpaClient::ReqConnect(int networkId) +WifiErrorNo WifiHdiWpaClient::ReqConnect(int networkId, const char *ifaceName) { - return HdiWpaStaConnect(networkId); + return HdiWpaStaConnect(networkId, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqReconnect(void) +WifiErrorNo WifiHdiWpaClient::ReqReconnect(const char *ifaceName) { - return HdiWpaStaReconnect(); + return HdiWpaStaReconnect(ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqReassociate(void) +WifiErrorNo WifiHdiWpaClient::ReqReassociate(const char *ifaceName) { - return HdiWpaStaReassociate(); + return HdiWpaStaReassociate(ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqDisconnect(void) +WifiErrorNo WifiHdiWpaClient::ReqDisconnect(const char *ifaceName) { - return HdiWpaStaDisconnect(); + return HdiWpaStaDisconnect(ifaceName); } WifiErrorNo WifiHdiWpaClient::GetStaCapabilities(unsigned int &capabilities) @@ -101,11 +104,11 @@ WifiErrorNo WifiHdiWpaClient::GetStaCapabilities(unsigned int &capabilities) return WIFI_HAL_OPT_OK; } -WifiErrorNo WifiHdiWpaClient::GetStaDeviceMacAddress(std::string &mac) +WifiErrorNo WifiHdiWpaClient::GetStaDeviceMacAddress(std::string &mac, const char *ifaceName) { char macAddr[HAL_BSSID_LENGTH + 1] = {0}; int macAddrLen = HAL_BSSID_LENGTH + 1; - WifiErrorNo err = HdiWpaStaGetDeviceMacAddress(macAddr, macAddrLen); + WifiErrorNo err = HdiWpaStaGetDeviceMacAddress(macAddr, macAddrLen, ifaceName); if (err == WIFI_HAL_OPT_OK) { mac = std::string(macAddr); } @@ -131,7 +134,7 @@ WifiErrorNo WifiHdiWpaClient::QueryScanInfos(std::vector &scanInf { LOGI("WifiHdiWpaClient::%{public}s enter", __func__); int size = HAL_GET_MAX_SCAN_INFO; - ScanInfo* results = HdiWpaStaGetScanInfos(&size); + ScanInfo *results = HdiWpaStaGetScanInfos(&size, GetHdiStaIfaceName(INSTID_WLAN0)); if (results == NULL) { return size == 0 ? WIFI_HAL_OPT_OK : WIFI_HAL_OPT_FAILED; } @@ -186,33 +189,33 @@ WifiErrorNo WifiHdiWpaClient::ReqStopPnoScan(void) return WIFI_HAL_OPT_NOT_SUPPORT; } -WifiErrorNo WifiHdiWpaClient::RemoveDevice(int networkId) +WifiErrorNo WifiHdiWpaClient::RemoveDevice(int networkId, const char *ifaceName) { if (networkId < 0) { return WIFI_HAL_OPT_INVALID_PARAM; } - return HdiWpaStaRemoveNetwork(networkId); + return HdiWpaStaRemoveNetwork(networkId, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ClearDeviceConfig(void) const +WifiErrorNo WifiHdiWpaClient::ClearDeviceConfig(const char *ifaceName) const { - return HdiWpaStaRemoveNetwork(-1); + return HdiWpaStaRemoveNetwork(-1, ifaceName); } -WifiErrorNo WifiHdiWpaClient::GetNextNetworkId(int &networkId) +WifiErrorNo WifiHdiWpaClient::GetNextNetworkId(int &networkId, const char *ifaceName) { - return HdiWpaStaAddNetwork(&networkId); + return HdiWpaStaAddNetwork(&networkId, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqEnableNetwork(int networkId) +WifiErrorNo WifiHdiWpaClient::ReqEnableNetwork(int networkId, const char *ifaceName) { - return HdiWpaStaEnableNetwork(networkId); + return HdiWpaStaEnableNetwork(networkId, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqDisableNetwork(int networkId) +WifiErrorNo WifiHdiWpaClient::ReqDisableNetwork(int networkId, const char *ifaceName) { - return HdiWpaStaDisableNetwork(networkId); + return HdiWpaStaDisableNetwork(networkId, ifaceName); } void WifiHdiWpaClient::SetWapiConfig(const WifiHalDeviceConfig &config, SetNetworkConfig *conf, int &num) @@ -229,7 +232,7 @@ void WifiHdiWpaClient::SetWapiConfig(const WifiHalDeviceConfig &config, SetNetwo } } -WifiErrorNo WifiHdiWpaClient::SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config) +WifiErrorNo WifiHdiWpaClient::SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config, const char *ifaceName) { if (CheckValidDeviceConfig(config) != WIFI_HAL_OPT_OK) { LOGE("SetDeviceConfig, CheckValidDeviceConfig return error!"); @@ -353,10 +356,10 @@ WifiErrorNo WifiHdiWpaClient::SetDeviceConfig(int networkId, const WifiHalDevice if (num == 0) { return WIFI_HAL_OPT_OK; } - return HdiWpaStaSetNetwork(networkId, conf, num); + return HdiWpaStaSetNetwork(networkId, conf, num, ifaceName); } -WifiErrorNo WifiHdiWpaClient::SetBssid(int networkId, const std::string &bssid) +WifiErrorNo WifiHdiWpaClient::SetBssid(int networkId, const std::string &bssid, const char *ifaceName) { SetNetworkConfig conf; int num = PushDeviceConfigString(&conf, DEVICE_CONFIG_BSSID, bssid, false); @@ -365,15 +368,16 @@ WifiErrorNo WifiHdiWpaClient::SetBssid(int networkId, const std::string &bssid) return WIFI_HAL_OPT_OK; } - return HdiWpaStaSetNetwork(networkId, &conf, num); + return HdiWpaStaSetNetwork(networkId, &conf, num, ifaceName); } -WifiErrorNo WifiHdiWpaClient::SaveDeviceConfig(void) +WifiErrorNo WifiHdiWpaClient::SaveDeviceConfig(const char *ifaceName) { - return HdiWpaStaSaveConfig(); + return HdiWpaStaSaveConfig(ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqRegisterStaEventCallback(const WifiEventCallback &callback) +WifiErrorNo WifiHdiWpaClient::ReqRegisterStaEventCallback( + const WifiEventCallback &callback, const char *ifaceName, int instId) { struct IWpaCallback cWifiHdiWpaCallback; if (memset_s(&cWifiHdiWpaCallback, sizeof(cWifiHdiWpaCallback), 0, sizeof(cWifiHdiWpaCallback)) != EOK) { @@ -394,10 +398,10 @@ WifiErrorNo WifiHdiWpaClient::ReqRegisterStaEventCallback(const WifiEventCallbac cWifiHdiWpaCallback.OnEventStaNotify = OnEventStaNotify; } - return RegisterHdiWpaStaEventCallback(&cWifiHdiWpaCallback); + return RegisterHdiWpaStaEventCallback(&cWifiHdiWpaCallback, ifaceName, instId); } -WifiErrorNo WifiHdiWpaClient::ReqStartWpsPbcMode(const WifiHalWpsConfig &config) +WifiErrorNo WifiHdiWpaClient::ReqStartWpsPbcMode(const WifiHalWpsConfig &config, const char *ifaceName) { WifiWpsParam param; if (memset_s(¶m, sizeof(param), 0, sizeof(param)) != EOK) { @@ -408,10 +412,10 @@ WifiErrorNo WifiHdiWpaClient::ReqStartWpsPbcMode(const WifiHalWpsConfig &config) if (strncpy_s(param.bssid, sizeof(param.bssid), config.bssid.c_str(), config.bssid.length()) != EOK) { return WIFI_HAL_OPT_FAILED; } - return HdiWpaStaStartWpsPbcMode(¶m); + return HdiWpaStaStartWpsPbcMode(¶m, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqStartWpsPinMode(const WifiHalWpsConfig &config, int &pinCode) +WifiErrorNo WifiHdiWpaClient::ReqStartWpsPinMode(const WifiHalWpsConfig &config, int &pinCode, const char *ifaceName) { WifiWpsParam param; if (memset_s(¶m, sizeof(param), 0, sizeof(param)) != EOK) { @@ -427,12 +431,12 @@ WifiErrorNo WifiHdiWpaClient::ReqStartWpsPinMode(const WifiHalWpsConfig &config, return WIFI_HAL_OPT_FAILED; } } - return HdiWpaStaStartWpsPinMode(¶m, &pinCode); + return HdiWpaStaStartWpsPinMode(¶m, &pinCode, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqStopWps(void) +WifiErrorNo WifiHdiWpaClient::ReqStopWps(const char *ifaceName) { - return HdiStopWpsSta(); + return HdiStopWpsSta(ifaceName); } WifiErrorNo WifiHdiWpaClient::ReqGetRoamingCapabilities(WifiHalRoamCapability &capability) @@ -450,39 +454,39 @@ WifiErrorNo WifiHdiWpaClient::ReqGetConnectSignalInfo(const std::string &endBssi return WIFI_HAL_OPT_NOT_SUPPORT; } -WifiErrorNo WifiHdiWpaClient::ReqWpaAutoConnect(int enable) +WifiErrorNo WifiHdiWpaClient::ReqWpaAutoConnect(int enable, const char *ifaceName) { - return HdiWpaStaAutoConnect(enable); + return HdiWpaStaAutoConnect(enable, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqWpaBlocklistClear(void) +WifiErrorNo WifiHdiWpaClient::ReqWpaBlocklistClear(const char *ifaceName) { - return HdiWpaStaBlocklistClear(); + return HdiWpaStaBlocklistClear(ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqSetPowerSave(bool enable) +WifiErrorNo WifiHdiWpaClient::ReqSetPowerSave(bool enable, const char *ifaceName) { - return HdiWpaStaSetPowerSave(enable); + return HdiWpaStaSetPowerSave(enable, ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqWpaSetCountryCode(const std::string &countryCode) +WifiErrorNo WifiHdiWpaClient::ReqWpaSetCountryCode(const std::string &countryCode, const char *ifaceName) { - return HdiWpaStaSetCountryCode(countryCode.c_str()); + return HdiWpaStaSetCountryCode(countryCode.c_str(), ifaceName); } -WifiErrorNo WifiHdiWpaClient::ReqWpaGetCountryCode(std::string &countryCode) +WifiErrorNo WifiHdiWpaClient::ReqWpaGetCountryCode(std::string &countryCode, const char *ifaceName) { char szCountryCode[HAL_COUNTRY_CODE_LENGTH + 1] = ""; - if (WIFI_HAL_OPT_OK != HdiWpaStaGetCountryCode(szCountryCode, HAL_COUNTRY_CODE_LENGTH)) { + if (WIFI_HAL_OPT_OK != HdiWpaStaGetCountryCode(szCountryCode, HAL_COUNTRY_CODE_LENGTH, ifaceName)) { return WIFI_HAL_OPT_FAILED; } countryCode = szCountryCode; return WIFI_HAL_OPT_OK; } -WifiErrorNo WifiHdiWpaClient::ReqWpaSetSuspendMode(bool mode) const +WifiErrorNo WifiHdiWpaClient::ReqWpaSetSuspendMode(bool mode, const char *ifaceName) const { - return HdiWpaStaSetSuspendMode(mode); + return HdiWpaStaSetSuspendMode(mode, ifaceName); } WifiErrorNo WifiHdiWpaClient::ReqWpaShellCmd(const std::string &ifName, const std::string &cmd) @@ -592,7 +596,7 @@ WifiErrorNo WifiHdiWpaClient::CheckValidDeviceConfig(const WifiHalDeviceConfig & return WIFI_HAL_OPT_OK; } -WifiErrorNo WifiHdiWpaClient::GetNetworkList(std::vector &networkList) +WifiErrorNo WifiHdiWpaClient::GetNetworkList(std::vector &networkList, const char *ifaceName) { HdiWifiWpaNetworkInfo *listNetwork = new HdiWifiWpaNetworkInfo[WIFI_MAX_SCAN_COUNT]; if (listNetwork == nullptr) { @@ -600,7 +604,7 @@ WifiErrorNo WifiHdiWpaClient::GetNetworkList(std::vector return WIFI_HAL_OPT_FAILED; } uint32_t size = WIFI_MAX_SCAN_COUNT; - if (WIFI_HAL_OPT_OK != HdiWpaListNetworks(listNetwork, &size)) { + if (WIFI_HAL_OPT_OK != HdiWpaListNetworks(listNetwork, &size, ifaceName)) { if (listNetwork != nullptr) { delete[] listNetwork; listNetwork = nullptr; @@ -634,7 +638,7 @@ WifiErrorNo WifiHdiWpaClient::GetNetworkList(std::vector return WIFI_HAL_OPT_OK; } -WifiErrorNo WifiHdiWpaClient::GetDeviceConfig(WifiHalGetDeviceConfig &config) +WifiErrorNo WifiHdiWpaClient::GetDeviceConfig(WifiHalGetDeviceConfig &config, const char *ifaceName) { int32_t networkId = config.networkId; char param[WIFI_HDI_MAX_STR_LENGTH +1] = {0}; @@ -644,7 +648,7 @@ WifiErrorNo WifiHdiWpaClient::GetDeviceConfig(WifiHalGetDeviceConfig &config) } char value[WIFI_HDI_MAX_STR_LENGTH +1] = {0}; uint32_t valueLen = WIFI_HDI_MAX_STR_LENGTH; - if (WIFI_HAL_OPT_OK != HdiWpaGetNetwork(networkId, param, value, valueLen)) { + if (WIFI_HAL_OPT_OK != HdiWpaGetNetwork(networkId, param, value, valueLen, ifaceName)) { LOGE("WifiHdiWpaClient::%{public}s failed", __func__); return WIFI_HAL_OPT_FAILED; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.h index 8654cd503..acf792c57 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client.h @@ -27,6 +27,7 @@ #include "wifi_event_callback.h" #include "wifi_ap_event_callback.h" #include "wifi_p2p_event_callback.h" +#include "define.h" namespace OHOS { namespace Wifi { @@ -41,14 +42,14 @@ public: * * @return WifiErrorNo */ - WifiErrorNo StartWifi(const std::string &ifaceName); + WifiErrorNo StartWifi(const std::string &ifaceName, int instId = 0); /** * @Description Close Wifi. * * @return WifiErrorNo */ - WifiErrorNo StopWifi(void); + WifiErrorNo StopWifi(int instId = 0); /** * @Description Connect Wifi. @@ -56,28 +57,28 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo ReqConnect(int networkId); + WifiErrorNo ReqConnect(int networkId, const char *ifaceName); /** * @Description Reconnect Wifi. * * @return WifiErrorNo */ - WifiErrorNo ReqReconnect(void); + WifiErrorNo ReqReconnect(const char *ifaceName); /** * @Description Reassociate Wifi. * * @return WifiErrorNo */ - WifiErrorNo ReqReassociate(void); + WifiErrorNo ReqReassociate(const char *ifaceName); /** * @Description Disconnect Wifi. * * @return WifiErrorNo */ - WifiErrorNo ReqDisconnect(void); + WifiErrorNo ReqDisconnect(const char *ifaceName); /** * @Description Obtaining the STA Support Capability. @@ -93,7 +94,7 @@ public: * @param mac * @return WifiErrorNo */ - WifiErrorNo GetStaDeviceMacAddress(std::string &mac); + WifiErrorNo GetStaDeviceMacAddress(std::string &mac, const char *ifaceName); /** * @Description Obtains the frequencies supported by a specified @@ -150,14 +151,14 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo RemoveDevice(int networkId); + WifiErrorNo RemoveDevice(int networkId, const char *ifaceName); /** * @Description Clears the network configuration information saved by wpa_supplicant. * * @return WifiErrorNo */ - WifiErrorNo ClearDeviceConfig(void) const; + WifiErrorNo ClearDeviceConfig(const char *ifaceName) const; /** * @Description Request to obtain the next network ID. @@ -165,7 +166,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo GetNextNetworkId(int &networkId); + WifiErrorNo GetNextNetworkId(int &networkId, const char *ifaceName); /** * @Description Enable a network. @@ -173,7 +174,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo ReqEnableNetwork(int networkId); + WifiErrorNo ReqEnableNetwork(int networkId, const char *ifaceName); /** * @Description Disable a network. @@ -181,7 +182,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo ReqDisableNetwork(int networkId); + WifiErrorNo ReqDisableNetwork(int networkId, const char *ifaceName); /** * @Description Setting the network. @@ -190,7 +191,7 @@ public: * @param config - Setting Network Parameters. * @return WifiErrorNo */ - WifiErrorNo SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config); + WifiErrorNo SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config, const char *ifaceName); /** * @Description Set bssid to supplicant. @@ -199,14 +200,14 @@ public: * @param bssid * @return WifiErrorNo */ - WifiErrorNo SetBssid(int networkId, const std::string &bssid); + WifiErrorNo SetBssid(int networkId, const std::string &bssid, const char *ifaceName); /** * @Description Save the network. * * @return WifiErrorNo */ - WifiErrorNo SaveDeviceConfig(void); + WifiErrorNo SaveDeviceConfig(const char *ifaceName); /** * @Description Registering the Sta Event Callback. @@ -214,7 +215,7 @@ public: * @param callback - Registering an Event Callback Function. * @return WifiErrorNo */ - WifiErrorNo ReqRegisterStaEventCallback(const WifiEventCallback &callback); + WifiErrorNo ReqRegisterStaEventCallback(const WifiEventCallback &callback, const char *ifaceName, int instId); /** * @Description Enabling WPS in PBC Mode. @@ -222,7 +223,7 @@ public: * @param config * @return WifiErrorNo */ - WifiErrorNo ReqStartWpsPbcMode(const WifiHalWpsConfig &config); + WifiErrorNo ReqStartWpsPbcMode(const WifiHalWpsConfig &config, const char *ifaceName); /** * @Description Enable PIN mode WPS. @@ -231,14 +232,14 @@ public: * @param pinCode * @return WifiErrorNo */ - WifiErrorNo ReqStartWpsPinMode(const WifiHalWpsConfig &config, int &pinCode); + WifiErrorNo ReqStartWpsPinMode(const WifiHalWpsConfig &config, int &pinCode, const char *ifaceName); /** * @Description Close wps. * * @return WifiErrorNo */ - WifiErrorNo ReqStopWps(void); + WifiErrorNo ReqStopWps(const char *ifaceName); /** * @Description Obtains the roaming support capability. @@ -271,14 +272,14 @@ public: * @param enable * @return WifiErrorNo */ - WifiErrorNo ReqWpaAutoConnect(int enable); + WifiErrorNo ReqWpaAutoConnect(int enable, const char *ifaceName); /** * @Description Clearing the wpa Blocklist. * * @return WifiErrorNo */ - WifiErrorNo ReqWpaBlocklistClear(void); + WifiErrorNo ReqWpaBlocklistClear(const char *ifaceName); /** * @Description Turn on/off power save mode for the interface. @@ -286,7 +287,7 @@ public: * @param enable * @return WifiErrorNo */ - WifiErrorNo ReqSetPowerSave(bool enable); + WifiErrorNo ReqSetPowerSave(bool enable, const char *ifaceName); /** * @Description Setting the country code. @@ -294,17 +295,17 @@ public: * @param countCode * @return WifiErrorNo */ - WifiErrorNo ReqWpaSetCountryCode(const std::string &countryCode); - WifiErrorNo ReqWpaGetCountryCode(std::string &countryCode); + WifiErrorNo ReqWpaSetCountryCode(const std::string &countryCode, const char *ifaceName); + WifiErrorNo ReqWpaGetCountryCode(std::string &countryCode, const char *ifaceName); /** * @Description Send suspend mode to wpa * * @param mode: true for suspend, false for resume * @return WifiErrorNo */ - WifiErrorNo ReqWpaSetSuspendMode(bool mode) const; - WifiErrorNo GetNetworkList(std::vector &networkList); - WifiErrorNo GetDeviceConfig(WifiHalGetDeviceConfig &config); + WifiErrorNo ReqWpaSetSuspendMode(bool mode, const char *ifaceName) const; + WifiErrorNo GetNetworkList(std::vector &networkList, const char *ifaceName); + WifiErrorNo GetDeviceConfig(WifiHalGetDeviceConfig &config, const char *ifaceName); /** * @Description Send SIM/AKA/AKA' authentication to wpa diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/wifi_idl_inner_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/wifi_idl_inner_interface.cpp index 6a8e6ff66..d3fbbee07 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/wifi_idl_inner_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/wifi_idl_inner_interface.cpp @@ -19,6 +19,7 @@ #include "wifi_supplicant_hal_interface.h" #include "wifi_p2p_hal_interface.h" #include "wifi_global_func.h" +#include "wifi_config_center.h" RpcClient *GetChipRpcClient(void) { @@ -64,7 +65,8 @@ void OnConnectChanged(int status, int networkId, const char *mac) if (mac == nullptr) { return; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onConnectChanged) { cbk.onConnectChanged(status, networkId, mac); } @@ -75,7 +77,8 @@ void OnDisConnectReasonCallback(int reason, const char *bssid) if (bssid == nullptr) { return; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onReportDisConnectReason) { cbk.onReportDisConnectReason(reason, bssid); } @@ -86,7 +89,8 @@ void OnBssidChanged(const char *reason, const char *bssid) if (reason == nullptr || bssid == nullptr) { return; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onBssidChanged) { cbk.onBssidChanged(reason, bssid); } @@ -94,7 +98,8 @@ void OnBssidChanged(const char *reason, const char *bssid) void OnWpaStateChanged(int status) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpaStateChanged) { cbk.onWpaStateChanged(status); } @@ -102,7 +107,8 @@ void OnWpaStateChanged(int status) void OnWpaSsidWrongKey() { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpaSsidWrongKey) { cbk.onWpaSsidWrongKey(); } @@ -110,7 +116,8 @@ void OnWpaSsidWrongKey() void OnWpaConnectionFull(int status) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpaConnectionFull) { cbk.onWpaConnectionFull(status); } @@ -118,7 +125,8 @@ void OnWpaConnectionFull(int status) void OnWpaConnectionReject(int status) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpaConnectionReject) { cbk.onWpaConnectionReject(status); } @@ -129,7 +137,8 @@ void OnWpaStaNotifyCallBack(const char *notifyParam) if (notifyParam == nullptr) { return; } - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onEventStaNotify) { cbk.onEventStaNotify(notifyParam); } @@ -137,7 +146,8 @@ void OnWpaStaNotifyCallBack(const char *notifyParam) void OnWpsOverlap(int status) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpsOverlap) { cbk.onWpsOverlap(status); } @@ -145,7 +155,8 @@ void OnWpsOverlap(int status) void OnWpsTimeOut(int status) { - const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst( + OHOS::Wifi::WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0)); if (cbk.onWpsTimeOut) { cbk.onWpsTimeOut(status); } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.cpp index ac776a6f9..88afc504f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.cpp @@ -110,9 +110,11 @@ void HalDeviceManager::StopChipHdi() } bool HalDeviceManager::CreateStaIface(const IfaceDestoryCallback &ifaceDestoryCallback, - const RssiReportCallback &rssiReportCallback, std::string &ifaceName) + const RssiReportCallback &rssiReportCallback, std::string &ifaceName, int instId) { + LOGI("CreateStaIface, ifaceName: %{public}s, instId = %{public}d", ifaceName.c_str(), instId); if (!CheckReloadChipHdiService()) { + LOGE("CreateStaIface CheckReloadChipHdiService failed"); return false; } @@ -125,14 +127,17 @@ bool HalDeviceManager::CreateStaIface(const IfaceDestoryCallback &ifaceDestoryCa CHECK_NULL_AND_RETURN(iface, false); CHECK_NULL_AND_RETURN(g_chipIfaceCallback, false); - int32_t ret = iface->RegisterChipIfaceCallBack(g_chipIfaceCallback); - if (ret != HDF_SUCCESS) { - LOGE("CreateStaIface, call RegisterChipIfaceCallBack failed! ret:%{public}d", ret); - return false; + if (instId == INSTID_WLAN0) { + int32_t ret = iface->RegisterChipIfaceCallBack(g_chipIfaceCallback); + if (ret != HDF_SUCCESS) { + LOGE("CreateStaIface, call RegisterChipIfaceCallBack failed! ret:%{public}d", ret); + return false; + } + g_rssiReportCallback = rssiReportCallback; + } else { + LOGE("CreateStaIface wlan1 skip scan callback instId = %{public}d", instId); } - - g_rssiReportCallback = rssiReportCallback; - + mIWifiStaIfaces[ifaceName] = iface; LOGI("CreateStaIface success! ifaceName:%{public}s", ifaceName.c_str()); return true; @@ -1443,11 +1448,14 @@ bool HalDeviceManager::RemoveIface(sptr &iface, bool isCallback, Ifa CHECK_NULL_AND_RETURN(chip, false); int32_t ret = HDF_FAILURE; switch (ifaceType) { - case IfaceType::STA : - if (iface && g_chipIfaceCallback) { - iface->UnRegisterChipIfaceCallBack(g_chipIfaceCallback); + case IfaceType::STA: + if (ifaceName == "wlan0") { + LOGE("RemoveIface, IfaceType::STA wlan0"); + if (iface && g_chipIfaceCallback) { + iface->UnRegisterChipIfaceCallBack(g_chipIfaceCallback); + } + g_rssiReportCallback = nullptr; } - g_rssiReportCallback = nullptr; ret = chip->RemoveStaService(ifaceName); break; case IfaceType::AP : diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.h index 90f1814d7..3ef1f1807 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage/hal_device_manage.h @@ -192,8 +192,8 @@ public: * @param ifaceName: [out] iface name * @return bool */ - bool CreateStaIface(const IfaceDestoryCallback &ifaceDestoryCallback, - const RssiReportCallback &rssiReportCallback, std::string &ifaceName); + bool CreateStaIface(const IfaceDestoryCallback &ifaceDestoryCallback, const RssiReportCallback &rssiReportCallback, + std::string &ifaceName, int instId); /** * @Description create ap iface diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.cpp index c2c6a223d..9a1a36e24 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.cpp @@ -19,12 +19,26 @@ #include "wifi_log.h" #include "wifi_hdi_util.h" #include "wifi_code_convert.h" +#include "wifi_config_center.h" +#include "define.h" #undef LOG_TAG #define LOG_TAG "WifiStaHalInterface" namespace OHOS { namespace Wifi { +static int GetInstId(const std::string &ifaceName) +{ + int inst = INSTID_WLAN0; + for (int instId = INSTID_WLAN0; instId < STA_INSTANCE_MAX_NUM; instId++) { + if (ifaceName.compare(WifiConfigCenter::GetInstance().GetStaIfaceName(instId)) == 0) { + inst = instId; + break; + } + } + return inst; +} + WifiStaHalInterface &WifiStaHalInterface::GetInstance(void) { static WifiStaHalInterface inst; @@ -47,11 +61,12 @@ WifiStaHalInterface &WifiStaHalInterface::GetInstance(void) return inst; } -WifiErrorNo WifiStaHalInterface::StartWifi(const std::string &ifaceName) +WifiErrorNo WifiStaHalInterface::StartWifi(const std::string &ifaceName, int instId) { + LOGD("WifiStaHalInterface ifaceName:%{public}s, instId:%{public}d", ifaceName.c_str(), instId); #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->StartWifi(ifaceName); + return mHdiWpaClient->StartWifi(ifaceName, instId); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->StartWifi(); @@ -59,22 +74,22 @@ WifiErrorNo WifiStaHalInterface::StartWifi(const std::string &ifaceName) } -WifiErrorNo WifiStaHalInterface::StopWifi(void) +WifiErrorNo WifiStaHalInterface::StopWifi(int instId) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->StopWifi(); + return mHdiWpaClient->StopWifi(instId); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->StopWifi(); #endif } -WifiErrorNo WifiStaHalInterface::Connect(int networkId) +WifiErrorNo WifiStaHalInterface::Connect(int networkId, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqConnect(networkId); + return mHdiWpaClient->ReqConnect(networkId, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqConnect(networkId); @@ -85,7 +100,7 @@ WifiErrorNo WifiStaHalInterface::Reconnect(void) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqReconnect(); + return mHdiWpaClient->ReqReconnect(WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqReconnect(); @@ -96,18 +111,19 @@ WifiErrorNo WifiStaHalInterface::Reassociate(void) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqReassociate(); + return mHdiWpaClient->ReqReassociate(WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqReassociate(); #endif } -WifiErrorNo WifiStaHalInterface::Disconnect(void) +WifiErrorNo WifiStaHalInterface::Disconnect(const std::string &ifaceName) { + LOGD("WifiStaHalInterface Disconnect ifaceName:%{public}s", ifaceName.c_str()); #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqDisconnect(); + return mHdiWpaClient->ReqDisconnect(ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqDisconnect(); @@ -125,11 +141,11 @@ WifiErrorNo WifiStaHalInterface::GetStaCapabilities(unsigned int &capabilities) #endif } -WifiErrorNo WifiStaHalInterface::GetStaDeviceMacAddress(std::string &mac) +WifiErrorNo WifiStaHalInterface::GetStaDeviceMacAddress(std::string &mac, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->GetStaDeviceMacAddress(mac); + return mHdiWpaClient->GetStaDeviceMacAddress(mac, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->GetStaDeviceMacAddress(mac); @@ -351,7 +367,8 @@ WifiErrorNo WifiStaHalInterface::GetNetworkList(std::vectorGetNetworkList(networkList); + return mHdiWpaClient->GetNetworkList( + networkList, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqGetNetworkList(networkList); @@ -395,74 +412,76 @@ WifiErrorNo WifiStaHalInterface::RemoveDevice(int networkId) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->RemoveDevice(networkId); + return mHdiWpaClient->RemoveDevice( + networkId, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->RemoveDevice(networkId); #endif } -WifiErrorNo WifiStaHalInterface::ClearDeviceConfig(void) const +WifiErrorNo WifiStaHalInterface::ClearDeviceConfig(const std::string &ifaceName) const { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ClearDeviceConfig(); + return mHdiWpaClient->ClearDeviceConfig(ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ClearDeviceConfig(); #endif } -WifiErrorNo WifiStaHalInterface::GetNextNetworkId(int &networkId) +WifiErrorNo WifiStaHalInterface::GetNextNetworkId(int &networkId, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->GetNextNetworkId(networkId); + return mHdiWpaClient->GetNextNetworkId(networkId, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->GetNextNetworkId(networkId); #endif } -WifiErrorNo WifiStaHalInterface::EnableNetwork(int networkId) +WifiErrorNo WifiStaHalInterface::EnableNetwork(int networkId, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqEnableNetwork(networkId); + return mHdiWpaClient->ReqEnableNetwork(networkId, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqEnableNetwork(networkId); #endif } -WifiErrorNo WifiStaHalInterface::DisableNetwork(int networkId) +WifiErrorNo WifiStaHalInterface::DisableNetwork(int networkId, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqDisableNetwork(networkId); + return mHdiWpaClient->ReqDisableNetwork(networkId, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqDisableNetwork(networkId); #endif } -WifiErrorNo WifiStaHalInterface::SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config) +WifiErrorNo WifiStaHalInterface::SetDeviceConfig( + int networkId, const WifiHalDeviceConfig &config, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->SetDeviceConfig(networkId, config); + return mHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->SetDeviceConfig(networkId, config); #endif } -WifiErrorNo WifiStaHalInterface::GetDeviceConfig(WifiHalGetDeviceConfig &config) +WifiErrorNo WifiStaHalInterface::GetDeviceConfig(WifiHalGetDeviceConfig &config, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT LOGI("call WifiStaHalInterface::%{public}s!", __func__); CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->GetDeviceConfig(config); + return mHdiWpaClient->GetDeviceConfig(config, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->GetDeviceConfig(config); @@ -473,24 +492,26 @@ WifiErrorNo WifiStaHalInterface::SaveDeviceConfig(void) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->SaveDeviceConfig(); + return mHdiWpaClient->SaveDeviceConfig(WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->SaveDeviceConfig(); #endif } -WifiErrorNo WifiStaHalInterface::RegisterStaEventCallback(const WifiEventCallback &callback) +WifiErrorNo WifiStaHalInterface::RegisterStaEventCallback( + const WifiEventCallback &callback, const std::string &ifaceName) { + int instId = GetInstId(ifaceName); #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - WifiErrorNo err = mHdiWpaClient->ReqRegisterStaEventCallback(callback); + WifiErrorNo err = mHdiWpaClient->ReqRegisterStaEventCallback(callback, ifaceName.c_str(), instId); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); WifiErrorNo err = mIdlClient->ReqRegisterStaEventCallback(callback); #endif if (err == WIFI_HAL_OPT_OK || callback.onConnectChanged == nullptr) { - mStaCallback = callback; + mStaCallback[instId] = callback; } return err; } @@ -499,7 +520,8 @@ WifiErrorNo WifiStaHalInterface::StartWpsPbcMode(const WifiHalWpsConfig &config) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqStartWpsPbcMode(config); + return mHdiWpaClient->ReqStartWpsPbcMode( + config, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqStartWpsPbcMode(config); @@ -513,7 +535,8 @@ WifiErrorNo WifiStaHalInterface::StartWpsPinMode(const WifiHalWpsConfig &config, } #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqStartWpsPinMode(config, pinCode); + return mHdiWpaClient->ReqStartWpsPinMode( + config, pinCode, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqStartWpsPinMode(config, pinCode); @@ -524,7 +547,7 @@ WifiErrorNo WifiStaHalInterface::StopWps(void) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqStopWps(); + return mHdiWpaClient->ReqStopWps(WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqStopWps(); @@ -542,11 +565,11 @@ WifiErrorNo WifiStaHalInterface::GetRoamingCapabilities(WifiHalRoamCapability &c #endif } -WifiErrorNo WifiStaHalInterface::SetBssid(int networkId, const std::string &bssid) +WifiErrorNo WifiStaHalInterface::SetBssid(int networkId, const std::string &bssid, const std::string &ifaceName) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->SetBssid(networkId, bssid); + return mHdiWpaClient->SetBssid(networkId, bssid, ifaceName.c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->SetBssid(networkId, bssid); @@ -568,7 +591,8 @@ WifiErrorNo WifiStaHalInterface::WpaAutoConnect(int enable) { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqWpaAutoConnect(enable); + return mHdiWpaClient->ReqWpaAutoConnect( + enable, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaAutoConnect(enable); @@ -579,7 +603,7 @@ WifiErrorNo WifiStaHalInterface::WpaBlocklistClear() { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqWpaBlocklistClear(); + return mHdiWpaClient->ReqWpaBlocklistClear(WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaBlocklistClear(); @@ -710,9 +734,10 @@ WifiErrorNo WifiStaHalInterface::SetNetworkInterfaceUpDown(const std::string &if #endif } -const WifiEventCallback &WifiStaHalInterface::GetCallbackInst(void) const +const WifiEventCallback &WifiStaHalInterface::GetCallbackInst(const std::string &ifaceName) const { - return mStaCallback; + int instId = GetInstId(ifaceName); + return mStaCallback[instId]; } const std::function &WifiStaHalInterface::GetDeathCallbackInst(void) const diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.h index 26dae7c20..0d61b84b2 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_sta_hal_interface.h @@ -18,6 +18,7 @@ #include #include +#include "define.h" #include "wifi_base_hal_interface.h" #include "wifi_event_callback.h" #include "wifi_native_struct.h" @@ -38,14 +39,14 @@ public: * * @return WifiErrorNo */ - WifiErrorNo StartWifi(const std::string &ifaceName = "wlan0"); + WifiErrorNo StartWifi(const std::string &ifaceName = "wlan0", int instId = 0); /** * @Description Close Wifi. * * @return WifiErrorNo */ - WifiErrorNo StopWifi(void); + WifiErrorNo StopWifi(int instId = 0); /** * @Description Connect Wifi. @@ -53,7 +54,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo Connect(int networkId); + WifiErrorNo Connect(int networkId, const std::string &ifaceName); /** * @Description Reconnect Wifi. @@ -74,7 +75,7 @@ public: * * @return WifiErrorNo */ - WifiErrorNo Disconnect(void); + WifiErrorNo Disconnect(const std::string &ifaceName); /** * @Description Obtaining the STA Support Capability. @@ -90,7 +91,7 @@ public: * @param mac * @return WifiErrorNo */ - WifiErrorNo GetStaDeviceMacAddress(std::string &mac); + WifiErrorNo GetStaDeviceMacAddress(std::string &mac, const std::string &ifaceName); /** * @Description Sets the Wi-Fi country code. @@ -194,7 +195,7 @@ public: * * @return WifiErrorNo */ - WifiErrorNo ClearDeviceConfig(void) const; + WifiErrorNo ClearDeviceConfig(const std::string &ifaceName) const; /** * @Description Request to obtain the next network ID. @@ -202,7 +203,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo GetNextNetworkId(int &networkId); + WifiErrorNo GetNextNetworkId(int &networkId, const std::string &ifaceName); /** * @Description Enable a network. @@ -210,7 +211,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo EnableNetwork(int networkId); + WifiErrorNo EnableNetwork(int networkId, const std::string &ifaceName); /** * @Description Disable a network. @@ -218,7 +219,7 @@ public: * @param networkId * @return WifiErrorNo */ - WifiErrorNo DisableNetwork(int networkId); + WifiErrorNo DisableNetwork(int networkId, const std::string &ifaceName); /** * @Description Setting the network. @@ -227,7 +228,7 @@ public: * @param config * @return WifiErrorNo */ - WifiErrorNo SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config); + WifiErrorNo SetDeviceConfig(int networkId, const WifiHalDeviceConfig &config, const std::string &ifaceName); /** * @Description Obtaining Network Configurations. @@ -235,7 +236,7 @@ public: * @param config * @return WifiErrorNo */ - WifiErrorNo GetDeviceConfig(WifiHalGetDeviceConfig &config); + WifiErrorNo GetDeviceConfig(WifiHalGetDeviceConfig &config, const std::string &ifaceName); /** * @Description Save network config. @@ -250,7 +251,7 @@ public: * @param callback * @return WifiErrorNo */ - WifiErrorNo RegisterStaEventCallback(const WifiEventCallback &callback); + WifiErrorNo RegisterStaEventCallback(const WifiEventCallback &callback, const std::string &ifaceName); /** * @Description Enabling WPS in PBC Mode. @@ -291,7 +292,7 @@ public: * @param bssid * @return WifiErrorNo */ - WifiErrorNo SetBssid(int networkId, const std::string &bssid); + WifiErrorNo SetBssid(int networkId, const std::string &bssid, const std::string &ifaceName); /** * @Description Setting Roaming Configurations. @@ -395,7 +396,7 @@ public: * * @return const WifiEventCallback& - register sta callback objects */ - const WifiEventCallback &GetCallbackInst(void) const; + const WifiEventCallback &GetCallbackInst(const std::string &ifaceName) const; /** * @Description Get register callback objects for death receiver @@ -413,7 +414,7 @@ public: WifiErrorNo RegisterNativeProcessCallback(const std::function &callback); private: - WifiEventCallback mStaCallback; + WifiEventCallback mStaCallback[2]; std::function mDeathCallback; }; } // namespace Wifi diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.cpp index cebf97d6d..4e91a6f67 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.cpp @@ -15,6 +15,7 @@ #include "wifi_supplicant_hal_interface.h" #include #include "wifi_log.h" +#include "wifi_config_center.h" #undef LOG_TAG #define LOG_TAG "WifiSupplicantHalInterface" @@ -133,7 +134,8 @@ WifiErrorNo WifiSupplicantHalInterface::SetPowerSave(bool enable) const { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqSetPowerSave(enable); + return mHdiWpaClient->ReqSetPowerSave( + enable, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqSetPowerSave(enable); @@ -144,7 +146,8 @@ WifiErrorNo WifiSupplicantHalInterface::WpaSetCountryCode(const std::string &cou { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqWpaSetCountryCode(countryCode); + return mHdiWpaClient->ReqWpaSetCountryCode( + countryCode, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaSetCountryCode(countryCode); @@ -155,7 +158,8 @@ WifiErrorNo WifiSupplicantHalInterface::WpaGetCountryCode(std::string &countryCo { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqWpaGetCountryCode(countryCode); + return mHdiWpaClient->ReqWpaGetCountryCode( + countryCode, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaGetCountryCode(countryCode); @@ -171,7 +175,8 @@ WifiErrorNo WifiSupplicantHalInterface::WpaSetSuspendMode(bool mode) const { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqWpaSetSuspendMode(mode); + return mHdiWpaClient->ReqWpaSetSuspendMode( + mode, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaSetSuspendMode(mode); @@ -182,7 +187,7 @@ WifiErrorNo WifiSupplicantHalInterface::WpaSetPowerMode(bool mode) const { #ifdef HDI_WPA_INTERFACE_SUPPORT CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED); - return mHdiWpaClient->ReqSetPowerSave(mode); + return mHdiWpaClient->ReqSetPowerSave(mode, WifiConfigCenter::GetInstance().GetStaIfaceName(INSTID_WLAN0).c_str()); #else CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED); return mIdlClient->ReqWpaSetPowerMode(!mode); // idl impl need revese power mode diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.h index a387937b9..7c7fa989b 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface/wifi_supplicant_hal_interface.h @@ -21,6 +21,7 @@ #include "wifi_base_hal_interface.h" #include "wifi_error_no.h" #include "i_wifi_struct.h" +#include "define.h" namespace OHOS { namespace Wifi { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp index 3f48b9375..c61465d6d 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp @@ -104,7 +104,7 @@ int WifiServiceManager::CheckPreLoadService(void) for (auto iter = mServiceDllMap.begin(); iter != mServiceDllMap.end(); ++iter) { bool bLoad = WifiSettings::GetInstance().IsModulePreLoad(iter->first); if (bLoad) { - int ret = CheckAndEnforceService(iter->first, false); + int ret = CheckAndEnforceService(iter->first, 0, false); if (ret < 0) { return -1; } @@ -113,15 +113,17 @@ int WifiServiceManager::CheckPreLoadService(void) return 0; } -int WifiServiceManager::LoadStaService(const std::string &dlname, bool bCreate) +int WifiServiceManager::LoadStaService(const std::string &dlname, int instId, bool bCreate) { - WIFI_LOGI("LoadStaService"); + WIFI_LOGI("LoadStaService, insId %{public}d", instId); std::unique_lock lock(mStaMutex); - if (mStaServiceHandle.pService[0]) { + if (mStaServiceHandle.pService[instId]) { + WIFI_LOGE("WifiServiceManager::LoadStaService pService is not NULL"); return 0; } - IStaService *service = new StaInterface(); - mStaServiceHandle.pService[0] = service; + IStaService *service = new StaInterface(instId); + mStaServiceHandle.pService[instId] = service; + WIFI_LOGI("WifiServiceManager::LoadStaService new pService %{public}d", instId); WifiManager::GetInstance().GetWifiStaManager()->StopUnloadStaSaTimer(); return 0; } @@ -209,7 +211,7 @@ int WifiServiceManager::LoadEnhanceService(const std::string &dlname, bool bCrea return 0; } -int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCreate) +int WifiServiceManager::CheckAndEnforceService(const std::string &name, int instId, bool bCreate) { WIFI_LOGD("WifiServiceManager::CheckAndEnforceService name: %{public}s", name.c_str()); std::string dlname; @@ -219,7 +221,7 @@ int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCr } WIFI_LOGD("WifiServiceManager::CheckAndEnforceService get dllname: %{public}s", dlname.c_str()); if (name == WIFI_SERVICE_STA) { - return LoadStaService(dlname, bCreate); + return LoadStaService(dlname, instId, bCreate); } #ifdef FEATURE_SELF_CURE_SUPPORT if (name == WIFI_SERVICE_SELFCURE) { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.h index fd2de2fc3..ede21efe6 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.h @@ -143,7 +143,7 @@ public: * @param bCreate - whether create the service instance * @return int - 0 success; -1 feature service name not correct or load service failed */ - int CheckAndEnforceService(const std::string &name, bool bCreate = true); + int CheckAndEnforceService(const std::string &name, int instId = 0, bool bCreate = true); /** * @Description Get the Sta Service Inst object @@ -214,7 +214,7 @@ public: private: int GetServiceDll(const std::string &name, std::string &dlname); - int LoadStaService(const std::string &dlname, bool bCreate); + int LoadStaService(const std::string &dlname, int insId, bool bCreate); int UnloadStaService(bool bPreLoad, int instId = 0); #ifdef FEATURE_SELF_CURE_SUPPORT int LoadSelfCureService(const std::string &dlname, bool bCreate); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp index f5cf290ea..b29bd5010 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp @@ -22,7 +22,9 @@ DEFINE_WIFILOG_LABEL("StaInterface"); namespace OHOS { namespace Wifi { StaInterface::StaInterface(int instId) : pStaService(nullptr), m_instId(instId) -{} +{ + WIFI_LOGI("StaInterface constuctor instId %{public}d", instId); +} StaInterface::~StaInterface() { @@ -47,7 +49,7 @@ extern "C" void Destroy(IStaService *pservice) ErrCode StaInterface::EnableStaService() { - WIFI_LOGI("Enter EnableStaService.\n"); + WIFI_LOGI("Enter EnableStaService m_instId:%{public}d\n", m_instId); std::lock_guard lock(mutex); if (!InitStaServiceLocked()) { return WIFI_OPT_FAILED; @@ -55,7 +57,7 @@ ErrCode StaInterface::EnableStaService() CHECK_NULL_AND_RETURN(pStaService, WIFI_OPT_FAILED); if (pStaService->EnableStaService() != WIFI_OPT_SUCCESS) { - LOGE("EnableStaService failed.\n"); + LOGE("EnableStaService failed m_instId:%{public}d\n", m_instId); pStaService->DisableStaService(); return WIFI_OPT_FAILED; } @@ -64,7 +66,7 @@ ErrCode StaInterface::EnableStaService() ErrCode StaInterface::DisableStaService() { - LOGI("Enter DisableStaService.\n"); + WIFI_LOGI("Enter DisableStaService m_instId:%{public}d\n", m_instId); std::lock_guard lock(mutex); CHECK_NULL_AND_RETURN(pStaService, WIFI_OPT_FAILED); if (pStaService->DisableStaService() != WIFI_OPT_SUCCESS) { @@ -496,14 +498,15 @@ ErrCode StaInterface::DeliverStaIfaceData(const std::string ¤tMac) bool StaInterface::InitStaServiceLocked() { + WIFI_LOGI("InitStaServiceLocked m_instId:%{public}d\n", m_instId); if (pStaService == nullptr) { pStaService = new (std::nothrow) StaService(m_instId); if (pStaService == nullptr) { - WIFI_LOGE("New StaService failed.\n"); + WIFI_LOGE("New StaService m_instId:%{public}d\n", m_instId); return false; } if (pStaService->InitStaService(m_staCallback) != WIFI_OPT_SUCCESS) { - WIFI_LOGE("InitStaService failed.\n"); + WIFI_LOGE("InitStaService m_instId:%{public}d\n", m_instId); delete pStaService; pStaService = nullptr; return false; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp index a20ce47de..7eb2f4877 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp @@ -29,7 +29,9 @@ DEFINE_WIFILOG_LABEL("StaMonitor"); namespace OHOS { namespace Wifi { StaMonitor::StaMonitor(int instId) : pStaStateMachine(nullptr), m_instId(instId) -{} +{ + WIFI_LOGI("StaMonitor constuctor insId %{public}d", instId); +} StaMonitor::~StaMonitor() { @@ -56,7 +58,8 @@ ErrCode StaMonitor::InitStaMonitor() [this](int reason, const std::string &bssid) { this->OnReportDisConnectReasonCallBack(reason, bssid); }, }; - if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack) != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack, ifaceName) != WIFI_HAL_OPT_OK) { WIFI_LOGE("InitStaMonitor RegisterStaEventCallback failed!"); return WIFI_OPT_FAILED; } @@ -67,7 +70,8 @@ NO_SANITIZE("cfi") ErrCode StaMonitor::UnInitStaMonitor() const { WIFI_LOGI("Enter UnInitStaMonitor.\n"); WifiEventCallback callBack; - if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack) != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack, ifaceName) != WIFI_HAL_OPT_OK) { WIFI_LOGE("~StaMonitor RegisterStaEventCallback failed!"); return WIFI_OPT_FAILED; } @@ -106,10 +110,8 @@ void StaMonitor::OnReportDisConnectReasonCallBack(int reason, const std::string void StaMonitor::OnConnectChangedCallBack(int status, int networkId, const std::string &bssid) { - WIFI_LOGI("OnConnectChangedCallBack() status:%{public}d,networkId=%{public}d,bssid=%{public}s", - status, - networkId, - MacAnonymize(bssid).c_str()); + WIFI_LOGI("OnConnectChangedCallBack status:%{public}d, networkId=%{public}d, bssid=%{public}s, instId=%{public}d", + status, networkId, MacAnonymize(bssid).c_str(), m_instId); if (pStaStateMachine == nullptr) { WIFI_LOGE("The statemachine pointer is null."); return; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp index dbfca28f6..806b57094 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp @@ -97,7 +97,7 @@ StaService::~StaService() ErrCode StaService::InitStaService(const std::vector &callbacks) { - WIFI_LOGI("Enter InitStaService.\n"); + WIFI_LOGI("Enter InitStaService m_instId:%{public}d\n", m_instId); pStaStateMachine = new (std::nothrow) StaStateMachine(m_instId); if (pStaStateMachine == nullptr) { WIFI_LOGE("Alloc pStaStateMachine failed.\n"); @@ -124,30 +124,32 @@ ErrCode StaService::InitStaService(const std::vector &callba pStaMonitor->SetStateMachine(pStaStateMachine); - pStaAutoConnectService = new (std::nothrow) StaAutoConnectService(pStaStateMachine, m_instId); - if (pStaAutoConnectService == nullptr) { - WIFI_LOGE("Alloc pStaAutoConnectService failed.\n"); - return WIFI_OPT_FAILED; - } - if (pStaAutoConnectService->InitAutoConnectService() != WIFI_OPT_SUCCESS) { - WIFI_LOGE("InitAutoConnectService failed.\n"); - return WIFI_OPT_FAILED; - } - pStaAutoConnectService->SetAutoConnectStateCallback(callbacks); + if (m_instId == INSTID_WLAN0) { + pStaAutoConnectService = new (std::nothrow) StaAutoConnectService(pStaStateMachine, m_instId); + if (pStaAutoConnectService == nullptr) { + WIFI_LOGE("Alloc pStaAutoConnectService failed.\n"); + return WIFI_OPT_FAILED; + } + if (pStaAutoConnectService->InitAutoConnectService() != WIFI_OPT_SUCCESS) { + WIFI_LOGE("InitAutoConnectService failed.\n"); + return WIFI_OPT_FAILED; + } + pStaAutoConnectService->SetAutoConnectStateCallback(callbacks); #ifndef OHOS_ARCH_LITE - pStaAppAcceleration = new (std::nothrow) StaAppAcceleration(m_instId); - if (pStaAppAcceleration == nullptr) { - WIFI_LOGE("Alloc pStaAppAcceleration failed.\n"); - } + pStaAppAcceleration = new (std::nothrow) StaAppAcceleration(m_instId); + if (pStaAppAcceleration == nullptr) { + WIFI_LOGE("Alloc pStaAppAcceleration failed.\n"); + } - if (pStaAppAcceleration->InitAppAcceleration() != WIFI_OPT_SUCCESS) { - WIFI_LOGE("InitAppAcceleration failed.\n"); - } - std::vector appAccelerationStaCallBacks; - appAccelerationStaCallBacks.push_back(pStaAppAcceleration->GetStaCallback()); - RegisterStaServiceCallback(appAccelerationStaCallBacks); - GetStaControlInfo(); + if (pStaAppAcceleration->InitAppAcceleration() != WIFI_OPT_SUCCESS) { + WIFI_LOGE("InitAppAcceleration failed.\n"); + } + std::vector appAccelerationStaCallBacks; + appAccelerationStaCallBacks.push_back(pStaAppAcceleration->GetStaCallback()); + RegisterStaServiceCallback(appAccelerationStaCallBacks); + GetStaControlInfo(); #endif + } WIFI_LOGI("Init staservice successfully.\n"); return WIFI_OPT_SUCCESS; } @@ -179,7 +181,7 @@ bool StaService::IsAppInCandidateFilterList(int uid) const ErrCode StaService::EnableStaService() { - WIFI_LOGI("Enter EnableStaService.\n"); + WIFI_LOGI("Enter EnableStaService m_instId:%{public}d\n", m_instId); CHECK_NULL_AND_RETURN(pStaStateMachine, WIFI_OPT_FAILED); #ifndef OHOS_ARCH_LITE // notification of registration country code change @@ -189,7 +191,9 @@ ErrCode StaService::EnableStaService() WIFI_LOGI("m_staObserver is null\n"); return WIFI_OPT_FAILED; } - WifiCountryCodeManager::GetInstance().RegisterWifiCountryCodeChangeListener(m_staObserver); + if (m_instId == INSTID_WLAN0) { + WifiCountryCodeManager::GetInstance().RegisterWifiCountryCodeChangeListener(m_staObserver); + } #endif WifiSettings::GetInstance().ReloadDeviceConfig(); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_ENABLE_STA, STA_CONNECT_MODE); @@ -298,7 +302,7 @@ ErrCode StaService::ConnectToCandidateConfig(const int uid, const int networkId) std::string StaService::ConvertString(const std::u16string &wideText) const { - return std::wstring_convert, char16_t> {}.to_bytes(wideText); + return std::wstring_convert, char16_t>{}.to_bytes(wideText); } #ifndef OHOS_ARCH_LITE @@ -407,6 +411,7 @@ int StaService::AddDeviceConfig(const WifiDeviceConfig &config) const std::string userSelectbssid = config.bssid; int status = config.status; WifiDeviceConfig tempDeviceConfig; + tempDeviceConfig.instanceId = config.instanceId; if (FindDeviceConfig(config, tempDeviceConfig) == 0) { netWorkId = tempDeviceConfig.networkId; status = tempDeviceConfig.status; @@ -471,15 +476,16 @@ int StaService::UpdateDeviceConfig(const WifiDeviceConfig &config) const ErrCode StaService::RemoveDevice(int networkId) const { - LOGI("Enter RemoveDevice, networkId = %{public}d.\n", networkId); + LOGI("Enter RemoveDevice, networkId = %{public}d m_instId:%{public}d\n", networkId, m_instId); WifiLinkedInfo linkedInfo; WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo, m_instId); if (linkedInfo.networkId == networkId) { - WifiStaHalInterface::GetInstance().ClearDeviceConfig(); + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + WifiStaHalInterface::GetInstance().ClearDeviceConfig(ifaceName); } WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) == 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) == 0) { CHECK_NULL_AND_RETURN(pStaAutoConnectService, WIFI_OPT_FAILED); pStaAutoConnectService->EnableOrDisableBssid(config.bssid, true, 0); } else { @@ -507,7 +513,8 @@ ErrCode StaService::RemoveDevice(int networkId) const ErrCode StaService::RemoveAllDevice() const { LOGI("Enter RemoveAllDevice.\n"); - if (WifiStaHalInterface::GetInstance().ClearDeviceConfig() == WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().ClearDeviceConfig(ifaceName) == WIFI_HAL_OPT_OK) { LOGD("Remove all device config successfully!"); } else { LOGE("WifiStaHalInterface:RemoveAllDevice failed!"); @@ -538,10 +545,11 @@ ErrCode StaService::RemoveAllDevice() const ErrCode StaService::ConnectToDevice(const WifiDeviceConfig &config) const { - LOGI("Enter ConnectToDevice, ssid = %{public}s.\n", SsidAnonymize(config.ssid).c_str()); + LOGI( + "Enter ConnectToDevice, ssid = %{public}s instId:%{public}d. \n", SsidAnonymize(config.ssid).c_str(), m_instId); CHECK_NULL_AND_RETURN(pStaStateMachine, WIFI_OPT_FAILED); int netWorkId = AddDeviceConfig(config); - if(netWorkId == INVALID_NETWORK_ID) { + if (netWorkId == INVALID_NETWORK_ID) { LOGD("ConnectToDevice, AddDeviceConfig failed!"); return WIFI_OPT_FAILED; } @@ -554,7 +562,7 @@ ErrCode StaService::ConnectToNetwork(int networkId) const { LOGI("Enter ConnectToNetwork, networkId is %{public}d.", networkId); WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) != 0) { LOGE("WifiDeviceConfig is null!"); return WIFI_OPT_FAILED; } @@ -571,7 +579,7 @@ ErrCode StaService::StartRoamToNetwork(const int networkId, const std::string bs { LOGI("Enter StartRoamToNetwork, networkId: %{public}d, bssid: %{public}s", networkId, MacAnonymize(bssid).c_str()); WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) != 0) { LOGE("%{public}s WifiDeviceConfig is null!", __FUNCTION__); return WIFI_OPT_FAILED; } @@ -603,7 +611,7 @@ ErrCode StaService::StartConnectToUserSelectNetwork(int networkId, std::string b LOGI("Enter StartConnectToUserSelectNetwork, networkId: %{public}d, bssid: %{public}s", networkId, MacAnonymize(bssid).c_str()); WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) != 0) { LOGE("%{public}s WifiDeviceConfig is null!", __FUNCTION__); return WIFI_OPT_FAILED; } @@ -777,7 +785,7 @@ int StaService::FindDeviceConfig(const WifiDeviceConfig &config, WifiDeviceConfi if (config.uid > WIFI_INVALID_UID) { ret = WifiSettings::GetInstance().GetCandidateConfig(config.uid, config.ssid, config.keyMgmt, outConfig); } else { - ret = WifiSettings::GetInstance().GetDeviceConfig(config.ssid, config.keyMgmt, outConfig); + ret = WifiSettings::GetInstance().GetDeviceConfig(config.ssid, config.keyMgmt, outConfig, m_instId); } LOGI("FindDeviceConfig uid:%{public}d, ssid:%{public}s, ret:%{public}d.", config.uid, SsidAnonymize(outConfig.ssid).c_str(), ret); @@ -860,7 +868,7 @@ ErrCode StaService::EnableAutoJoin(const std::string &conditionName) } ErrCode StaService::RegisterAutoJoinCondition(const std::string &conditionName, - const std::function &autoJoinCondition) + const std::function &autoJoinCondition) { CHECK_NULL_AND_RETURN(pStaAutoConnectService, WIFI_OPT_FAILED); pStaAutoConnectService->RegisterAutoJoinCondition(conditionName, autoJoinCondition); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp index 3eb4b6a64..6cb0ff522 100755 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp @@ -32,6 +32,7 @@ #include "wifi_hisysevent.h" #include "block_connect_service.h" #include "wifi_randommac_helper.h" +#include "define.h" #ifndef OHOS_ARCH_LITE #include #include "securec.h" @@ -59,7 +60,7 @@ DEFINE_WIFILOG_LABEL("StaStateMachine"); #define PORTAL_ENTITY "entity.browser.hbct" #define PORTAL_CHECK_TIME (10 * 60) #define PORTAL_AUTH_EXPIRED_CHECK_TIME (2) -#define PORTAL_MILLSECOND 1000 +#define PORTAL_MILLSECOND 1000 #define WPA3_BLACKMAP_MAX_NUM 20 #define WPA3_BLACKMAP_RSSI_THRESHOLD (-70) #define WPA3_CONNECT_FAIL_COUNT_THRESHOLD 2 @@ -107,45 +108,19 @@ DEFINE_WIFILOG_LABEL("StaStateMachine"); #define MAX_AUTN_STR_LEN (2 * UMTS_AUTH_CHALLENGE_AUTN_LEN) StaStateMachine::StaStateMachine(int instId) - : StateMachine("StaStateMachine"), - lastNetworkId(INVALID_NETWORK_ID), - operationalMode(STA_CONNECT_MODE), - targetNetworkId(INVALID_NETWORK_ID), - pinCode(0), - wpsState(SetupMethod::INVALID), - lastSignalLevel_(INVALID_SIGNAL_LEVEL), - targetRoamBssid(WPA_BSSID_ANY), - currentTpType(IPTYPE_IPV4), - isWpsConnect(IsWpsConnected::WPS_INVALID), - getIpSucNum(0), - getIpFailNum(0), - enableSignalPoll(true), - isRoam(false), - lastTimestamp(0), - portalFlag(true), - portalState(PortalState::UNCHECKED), - detectNum(0), - portalExpiredDetectCount(0), - mIsWifiInternetCHRFlag(false), - networkStatusHistoryInserted(false), - pDhcpResultNotify(nullptr), - pRootState(nullptr), - pInitState(nullptr), - pWpaStartingState(nullptr), - pWpaStartedState(nullptr), - pWpaStoppingState(nullptr), - pLinkState(nullptr), - pSeparatingState(nullptr), - pSeparatedState(nullptr), - pApLinkedState(nullptr), - pWpsState(nullptr), - pGetIpState(nullptr), - pLinkedState(nullptr), - pApRoamingState(nullptr), - m_instId(instId), - mLastConnectNetId(INVALID_NETWORK_ID), + : StateMachine("StaStateMachine"), lastNetworkId(INVALID_NETWORK_ID), operationalMode(STA_CONNECT_MODE), + targetNetworkId(INVALID_NETWORK_ID), pinCode(0), wpsState(SetupMethod::INVALID), + lastSignalLevel_(INVALID_SIGNAL_LEVEL), targetRoamBssid(WPA_BSSID_ANY), currentTpType(IPTYPE_IPV4), + isWpsConnect(IsWpsConnected::WPS_INVALID), getIpSucNum(0), getIpFailNum(0), enableSignalPoll(true), isRoam(false), + lastTimestamp(0), portalFlag(true), portalState(PortalState::UNCHECKED), detectNum(0), + portalExpiredDetectCount(0), mIsWifiInternetCHRFlag(false), networkStatusHistoryInserted(false), + pDhcpResultNotify(nullptr), pRootState(nullptr), pInitState(nullptr), pWpaStartingState(nullptr), + pWpaStartedState(nullptr), pWpaStoppingState(nullptr), pLinkState(nullptr), pSeparatingState(nullptr), + pSeparatedState(nullptr), pApLinkedState(nullptr), pWpsState(nullptr), pGetIpState(nullptr), + pLinkedState(nullptr), pApRoamingState(nullptr), mLastConnectNetId(INVALID_NETWORK_ID), mConnectFailedCnt(0) { + m_instId = instId; } StaStateMachine::~StaStateMachine() @@ -176,9 +151,9 @@ StaStateMachine::~StaStateMachine() /* ---------------------------Initialization functions------------------------------ */ ErrCode StaStateMachine::InitStaStateMachine() { - WIFI_LOGI("Enter InitStaStateMachine.\n"); + WIFI_LOGI("Enter InitStateMachine m_instId = %{public}d", m_instId); if (!InitialStateMachine("StaStateMachine")) { - WIFI_LOGE("Initial StateMachine failed.\n"); + WIFI_LOGE("Initial StateMachine failed m_instId = %{public}d", m_instId); return WIFI_OPT_FAILED; } @@ -189,12 +164,14 @@ ErrCode StaStateMachine::InitStaStateMachine() SetFirstState(pInitState); StartStateMachine(); InitStaSMHandleMap(); + if (m_instId == 0) { #ifndef OHOS_ARCH_LITE - NetSupplierInfo = std::make_unique().release(); - m_NetWorkState = sptr(new NetStateObserver()); - m_NetWorkState->SetNetStateCallback( - [this](SystemNetWorkState netState, std::string url) { this->NetStateObserverCallback(netState, url); }); + NetSupplierInfo = std::make_unique().release(); + m_NetWorkState = sptr(new NetStateObserver()); + m_NetWorkState->SetNetStateCallback( + [this](SystemNetWorkState netState, std::string url) { this->NetStateObserverCallback(netState, url); }); #endif + } return WIFI_OPT_SUCCESS; } @@ -202,33 +179,33 @@ ErrCode StaStateMachine::InitStaStates() { WIFI_LOGE("Enter InitStaStates\n"); int tmpErrNumber; - pRootState = new (std::nothrow)RootState(); + pRootState = new (std::nothrow) RootState(); tmpErrNumber = JudgmentEmpty(pRootState); - pInitState = new (std::nothrow)InitState(this); + pInitState = new (std::nothrow) InitState(this); tmpErrNumber += JudgmentEmpty(pInitState); - pWpaStartingState = new (std::nothrow)WpaStartingState(this); + pWpaStartingState = new (std::nothrow) WpaStartingState(this); tmpErrNumber += JudgmentEmpty(pWpaStartingState); - pWpaStartedState = new (std::nothrow)WpaStartedState(this); + pWpaStartedState = new (std::nothrow) WpaStartedState(this); tmpErrNumber += JudgmentEmpty(pWpaStartedState); - pWpaStoppingState = new (std::nothrow)WpaStoppingState(this); + pWpaStoppingState = new (std::nothrow) WpaStoppingState(this); tmpErrNumber += JudgmentEmpty(pWpaStoppingState); - pLinkState = new (std::nothrow)LinkState(this); + pLinkState = new (std::nothrow) LinkState(this); tmpErrNumber += JudgmentEmpty(pLinkState); - pSeparatingState = new (std::nothrow)SeparatingState(); + pSeparatingState = new (std::nothrow) SeparatingState(); tmpErrNumber += JudgmentEmpty(pSeparatingState); - pSeparatedState = new (std::nothrow)SeparatedState(this); + pSeparatedState = new (std::nothrow) SeparatedState(this); tmpErrNumber += JudgmentEmpty(pSeparatedState); - pApLinkedState = new (std::nothrow)ApLinkedState(this); + pApLinkedState = new (std::nothrow) ApLinkedState(this); tmpErrNumber += JudgmentEmpty(pApLinkedState); - pWpsState = new (std::nothrow)StaWpsState(this); + pWpsState = new (std::nothrow) StaWpsState(this); tmpErrNumber += JudgmentEmpty(pWpsState); - pGetIpState = new (std::nothrow)GetIpState(this); + pGetIpState = new (std::nothrow) GetIpState(this); tmpErrNumber += JudgmentEmpty(pGetIpState); - pLinkedState = new (std::nothrow)LinkedState(this); + pLinkedState = new (std::nothrow) LinkedState(this); tmpErrNumber += JudgmentEmpty(pLinkedState); - pApRoamingState = new (std::nothrow)ApRoamingState(this); + pApRoamingState = new (std::nothrow) ApRoamingState(this); tmpErrNumber += JudgmentEmpty(pApRoamingState); - pDhcpResultNotify = new (std::nothrow)DhcpResultNotify(); + pDhcpResultNotify = new (std::nothrow) DhcpResultNotify(); tmpErrNumber += JudgmentEmpty(pDhcpResultNotify); if (tmpErrNumber != 0) { WIFI_LOGE("InitStaStates some one state is null\n"); @@ -338,15 +315,19 @@ void StaStateMachine::InvokeOnStaConnChanged(OperateResState state, const WifiLi switch (state) { case OperateResState::CONNECT_AP_CONNECTED: WriteWifiConnectionHiSysEvent(WifiConnectionType::CONNECT, ""); + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - WifiNetStatsManager::GetInstance().StartNetStats(); + WifiNetStatsManager::GetInstance().StartNetStats(); #endif + } break; case OperateResState::DISCONNECT_DISCONNECTED: WriteWifiConnectionHiSysEvent(WifiConnectionType::DISCONNECT, ""); + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - WifiNetStatsManager::GetInstance().StopNetStats(); + WifiNetStatsManager::GetInstance().StopNetStats(); #endif + } break; default: break; @@ -471,7 +452,8 @@ bool StaStateMachine::InitState::ExecuteStateMsg(InternalMessagePtr msg) return false; } - WIFI_LOGI("InitState-msgCode=%{public}d is received.\n", msg->GetMessageName()); + WIFI_LOGI("InitState-msgCode=%{public}d is received. m_instId = %{public}d\n", msg->GetMessageName(), + pStaStateMachine->GetInstanceId()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_ENABLE_STA: { @@ -649,11 +631,13 @@ ErrCode StaStateMachine::ConvertDeviceCfg(const WifiDeviceConfig &config) const for (int i = 0; i < HAL_MAX_WEPKEYS_SIZE; i++) { halDeviceConfig.wepKeys[i] = config.wepKeys[i]; } - LOGI("ConvertDeviceCfg SetDeviceConfig selected network ssid=%{public}s, bssid=%{public}s", - SsidAnonymize(halDeviceConfig.ssid).c_str(), MacAnonymize(halDeviceConfig.bssid).c_str()); + LOGI("ConvertDeviceCfg SetDeviceConfig selected network ssid=%{public}s, bssid=%{public}s, instId=%{public}d", + SsidAnonymize(halDeviceConfig.ssid).c_str(), MacAnonymize(halDeviceConfig.bssid).c_str(), m_instId); ConvertSsidToOriginalSsid(config, halDeviceConfig); - - if (WifiStaHalInterface::GetInstance().SetDeviceConfig(WPA_DEFAULT_NETWORKID, halDeviceConfig) != WIFI_HAL_OPT_OK) { + + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().SetDeviceConfig(WPA_DEFAULT_NETWORKID, halDeviceConfig, ifaceName) != + WIFI_HAL_OPT_OK) { LOGE("ConvertDeviceCfg SetDeviceConfig failed!"); return WIFI_OPT_FAILED; } @@ -672,13 +656,16 @@ void StaStateMachine::StartWifiProcess() } int screenState = WifiConfigCenter::GetInstance().GetScreenState(); WIFI_LOGI("set suspend mode to chip when wifi started, screenState: %{public}d", screenState); - if (WifiSupplicantHalInterface::GetInstance().WpaSetSuspendMode(screenState == MODE_STATE_CLOSE) - != WIFI_HAL_OPT_OK) { - WIFI_LOGE("%{public}s WpaSetSuspendMode failed!", __FUNCTION__); + if (m_instId == INSTID_WLAN0) { + if (WifiSupplicantHalInterface::GetInstance().WpaSetSuspendMode(screenState == MODE_STATE_CLOSE) + != WIFI_HAL_OPT_OK) { + WIFI_LOGE("%{public}s WpaSetSuspendMode failed!", __FUNCTION__); + } } /* Sets the MAC address of WifiSettings. */ std::string mac; - if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(mac)) == WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(mac, ifaceName)) == WIFI_HAL_OPT_OK) { WifiConfigCenter::GetInstance().SetMacAddress(mac, m_instId); std::string realMacAddress; WifiSettings::GetInstance().GetRealMacAddress(realMacAddress, m_instId); @@ -688,10 +675,13 @@ void StaStateMachine::StartWifiProcess() } else { WIFI_LOGI("GetStaDeviceMacAddress failed!"); } + + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - WIFI_LOGI("Register netsupplier"); - WifiNetAgent::GetInstance().OnStaMachineWifiStart(); + WIFI_LOGI("Register netsupplier"); + WifiNetAgent::GetInstance().OnStaMachineWifiStart(); #endif + } /* Initialize Connection Information. */ InitWifiLinkedInfo(); InitLastWifiLinkedInfo(); @@ -778,7 +768,8 @@ bool StaStateMachine::WpaStartedState::ExecuteStateMsg(InternalMessagePtr msg) return false; } - WIFI_LOGI("WpaStartedState ExecuteStateMsg-msgCode:%{public}d.\n", msg->GetMessageName()); + WIFI_LOGI("WpaStartedState ExecuteStateMsg-msgCode:%{public}d m_instId = %{public}d\n", + msg->GetMessageName(), pStaStateMachine->GetInstanceId()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_DISABLE_STA: { @@ -794,41 +785,45 @@ bool StaStateMachine::WpaStartedState::ExecuteStateMsg(InternalMessagePtr msg) void StaStateMachine::StopWifiProcess() { - WIFI_LOGI("Enter StaStateMachine::StopWifiProcess.\n"); + WIFI_LOGI("Enter StaStateMachine::StopWifiProcess m_instId = %{public}d\n", m_instId); + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - WifiNetAgent::GetInstance().UnregisterNetSupplier(); - if (m_NetWorkState != nullptr) { - m_NetWorkState->StopNetStateObserver(m_NetWorkState); - } + WifiNetAgent::GetInstance().UnregisterNetSupplier(); + if (m_NetWorkState != nullptr) { + m_NetWorkState->StopNetStateObserver(m_NetWorkState); + } +#endif + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + + if (currentTpType == IPTYPE_IPV4) { + StopDhcpClient(ifaceName.c_str(), false); + } else { + StopDhcpClient(ifaceName.c_str(), true); + } + + IpInfo ipInfo; + WifiConfigCenter::GetInstance().SaveIpInfo(ipInfo, m_instId); + IpV6Info ipV6Info; + WifiConfigCenter::GetInstance().SaveIpV6Info(ipV6Info, m_instId); +#ifdef OHOS_ARCH_LITE + IfConfig::GetInstance().FlushIpAddr(WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId), IPTYPE_IPV4); #endif - WIFI_LOGI("Stop wifi is in process...\n"); - StopTimer(static_cast(CMD_SIGNAL_POLL)); - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); - if (currentTpType == IPTYPE_IPV4) { - StopDhcpClient(ifname.c_str(), false); - } else { - StopDhcpClient(ifname.c_str(), true); } + + WIFI_LOGI("Stop wifi is in process... m_instId = %{public}d", m_instId); + StopTimer(static_cast(CMD_SIGNAL_POLL)); isRoam = false; WifiConfigCenter::GetInstance().SetMacAddress("", m_instId); - IpInfo ipInfo; - WifiConfigCenter::GetInstance().SaveIpInfo(ipInfo, m_instId); - IpV6Info ipV6Info; - WifiConfigCenter::GetInstance().SaveIpV6Info(ipV6Info, m_instId); -#ifdef OHOS_ARCH_LITE - IfConfig::GetInstance().FlushIpAddr(WifiConfigCenter::GetInstance().GetStaIfaceName(), IPTYPE_IPV4); -#endif - ConnState curConnState = linkedInfo.connState; - WIFI_LOGI("current connect state is %{public}d\n", curConnState); + WIFI_LOGI("current connect state is %{public}d m_instId = %{public}d\n", curConnState, m_instId); std::string ssid = linkedInfo.ssid; /* clear connection information. */ InitWifiLinkedInfo(); WifiConfigCenter::GetInstance().SaveLinkedInfo(linkedInfo, m_instId); - if (curConnState == ConnState::CONNECTING || curConnState == ConnState::AUTHENTICATING - || curConnState == ConnState::OBTAINING_IPADDR ||curConnState == ConnState::CONNECTED) { - WifiStaHalInterface::GetInstance().Disconnect(); + if (curConnState == ConnState::CONNECTING || curConnState == ConnState::AUTHENTICATING || + curConnState == ConnState::OBTAINING_IPADDR || curConnState == ConnState::CONNECTED) { + WifiStaHalInterface::GetInstance().Disconnect(WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId)); /* Callback result to InterfaceService. */ linkedInfo.ssid = ssid; InvokeOnStaConnChanged(OperateResState::DISCONNECT_DISCONNECTED, linkedInfo); @@ -895,7 +890,8 @@ bool StaStateMachine::LinkState::ExecuteStateMsg(InternalMessagePtr msg) if (msg == nullptr) { return false; } - LOGD("LinkState ExecuteStateMsg function:msgName=[%{public}d].\n", msg->GetMessageName()); + LOGD("LinkState ExecuteStateMsg function:msgName=[%{public}d]. m_instId=%{public}d\n", + msg->GetMessageName(), pStaStateMachine->GetInstanceId()); auto iter = pStaStateMachine->staSmHandleFuncMap.find(msg->GetMessageName()); if (iter != pStaStateMachine->staSmHandleFuncMap.end()) { (iter->second)(msg); @@ -1020,7 +1016,7 @@ void StaStateMachine::DealSignalPollResult() LOGD("enter SignalPoll."); WifiHalWpaSignalInfo signalInfo; WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetConnectSignalInfo( - WifiConfigCenter::GetInstance().GetStaIfaceName(), linkedInfo.bssid, signalInfo); + WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId), linkedInfo.bssid, signalInfo); if (ret != WIFI_HAL_OPT_OK) { LOGE("GetConnectSignalInfo return fail: %{public}d.", ret); return; @@ -1113,7 +1109,7 @@ void StaStateMachine::DealSignalPacketChanged(int txPackets, int rxPackets) void StaStateMachine::ConvertFreqToChannel() { WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config, m_instId) != 0) { LOGE("GetDeviceConfig failed!"); return; } @@ -1143,14 +1139,36 @@ void StaStateMachine::OnConnectFailed(int networkId) InvokeOnStaConnChanged(OperateResState::DISCONNECT_DISCONNECTED, linkedInfo); } +void StaStateMachine::CreateWifi2Config(int &networkId) +{ + WifiDeviceConfig config1; + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config1, m_instId) != 0) { + LOGE("GetDeviceConfig failed m_instId = %{public}d", m_instId); + return; + } + if (config1.instanceId != m_instId) { + int netWorkId2 = INVALID_NETWORK_ID; + netWorkId2 = WifiSettings::GetInstance().GetNextNetworkId(); + LOGI("DealConnectToUserSelectedNetwork netWorkId2 = %{public}d, m_instId = %{public}d", netWorkId2, m_instId); + config1.networkId = netWorkId2; + config1.instanceId = m_instId; + WifiSettings::GetInstance().AddDeviceConfig(config1); + WifiSettings::GetInstance().SyncDeviceConfig(); + networkId = netWorkId2; + } + LOGI("DealConnectToUserSelectedNetwork the same networkId = %{public}d, m_instId = %{public}d", + networkId, m_instId); +} + void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessagePtr msg) { - LOGD("enter DealConnectToUserSelectedNetwork.\n"); + LOGI("enter DealConnectToUserSelectedNetwork m_instId = %{public}d\n", m_instId); if (msg == nullptr) { LOGE("msg is null.\n"); return; } int networkId = msg->GetParam1(); + CreateWifi2Config(networkId); int connTriggerMode = msg->GetParam2(); auto bssid = msg->GetStringFromMessage(); if (connTriggerMode == NETWORK_SELECTED_BY_USER) { @@ -1158,42 +1176,38 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessagePtr msg) } WriteWifiConnectionInfoHiSysEvent(networkId); WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) != 0) { LOGE("GetDeviceConfig failed!"); return; } if (networkId == linkedInfo.networkId) { if (linkedInfo.connState == ConnState::CONNECTED && config.isReassocSelfCureWithFactoryMacAddress == 0) { InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, linkedInfo); - WIFI_LOGI("This network is in use and does not need to be reconnected.\n"); + WIFI_LOGI("This network is in use and does not need to be reconnected m_istId = %{public}d", m_instId); return; } if (linkedInfo.connState == ConnState::CONNECTING && linkedInfo.detailedState == DetailedState::OBTAINING_IPADDR) { - WIFI_LOGI("This network is connecting and does not need to be reconnected.\n"); + WIFI_LOGI("This network is connecting and does not need to be reconnected m_instId = %{public}d", + m_instId); return; } } - std::string connectType = config.lastConnectTime <= 0 ? "FIRST_CONNECT" : connTriggerMode == NETWORK_SELECTED_BY_AUTO ? "AUTO_CONNECT" : connTriggerMode == NETWORK_SELECTED_BY_USER ? "SELECT_CONNECT" : ""; if (!connectType.empty()) { WirteConnectTypeHiSysEvent(connectType); } - /* Save connection information. */ SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT); SaveLinkstate(ConnState::CONNECTING, DetailedState::CONNECTING); networkStatusHistoryInserted = false; - /* Callback result to InterfaceService. */ InvokeOnStaConnChanged(OperateResState::CONNECT_CONNECTING, linkedInfo); - if (StartConnectToNetwork(networkId, bssid) != WIFI_OPT_SUCCESS) { OnConnectFailed(networkId); return; } SetConnectMethod(connTriggerMode); - /* Sets network status. */ WifiConfigCenter::GetInstance().EnableNetwork(networkId, connTriggerMode == NETWORK_SELECTED_BY_USER, m_instId); WifiSettings::GetInstance().SetDeviceState(networkId, (int)WifiDeviceConfigStatus::ENABLED, false); } @@ -1212,7 +1226,8 @@ void StaStateMachine::DealConnectTimeOutCmd(InternalMessagePtr msg) if (targetNetworkId == mLastConnectNetId) { mConnectFailedCnt++; } - WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID); + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID, ifaceName); DealSetStaConnectFailedCount(1, false); std::string ssid = linkedInfo.ssid; WifiConfigCenter::GetInstance().SetConnectTimeoutBssid(linkedInfo.bssid, m_instId); @@ -1245,7 +1260,8 @@ bool StaStateMachine::CheckRoamingBssidIsSame(std::string bssid) bool StaStateMachine::CurrentIsRandomizedMac() { std::string curMacAddress = ""; - if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(curMacAddress)) != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(curMacAddress, ifaceName)) != WIFI_HAL_OPT_OK) { LOGE("CurrentIsRandomizedMac GetStaDeviceMacAddress failed!"); return false; } @@ -1261,7 +1277,7 @@ void StaStateMachine::HilinkSaveConfig(void) WIFI_LOGI("enter HilinkSaveConfig"); WifiDeviceConfig outConfig; if (WifiSettings::GetInstance().GetDeviceConfig(m_hilinkDeviceConfig.ssid, m_hilinkDeviceConfig.keyMgmt, - outConfig) == 0) { + outConfig, m_instId) == 0) { m_hilinkDeviceConfig.networkId = outConfig.networkId; } else { m_hilinkDeviceConfig.networkId = WifiSettings::GetInstance().GetNextNetworkId(); @@ -1295,7 +1311,7 @@ void StaStateMachine::DealConnectionEvent(InternalMessagePtr msg) if (m_hilinkFlag) { HilinkSaveConfig(); } - WIFI_LOGI("enter DealConnectionEvent"); + WIFI_LOGI("enter DealConnectionEvent m_instId = %{public}d", m_instId); if (CurrentIsRandomizedMac()) { WifiSettings::GetInstance().SetDeviceRandomizedMacSuccessEver(targetNetworkId); } @@ -1309,26 +1325,32 @@ void StaStateMachine::DealConnectionEvent(InternalMessagePtr msg) if (wpsState != SetupMethod::INVALID) { wpsState = SetupMethod::INVALID; } + WIFI_LOGI("enter state machine change to ip state m_instId = %{public}d", m_instId); + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - if (NetSupplierInfo != nullptr) { - NetSupplierInfo->isAvailable_ = true; - NetSupplierInfo->isRoaming_ = isRoam; - NetSupplierInfo->ident_ = std::to_string(linkedInfo.networkId); - WIFI_LOGI("On connect update net supplier info\n"); - WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); - } + if (NetSupplierInfo != nullptr) { + NetSupplierInfo->isAvailable_ = true; + NetSupplierInfo->isRoaming_ = isRoam; + NetSupplierInfo->ident_ = std::to_string(linkedInfo.networkId); + WIFI_LOGI("On connect update net supplier info\n"); + WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); + } #endif - /* Callback result to InterfaceService. */ - InvokeOnStaConnChanged(OperateResState::CONNECT_OBTAINING_IP, linkedInfo); - mConnectFailedCnt = 0; - /* The current state of StaStateMachine transfers to GetIpState. */ - SwitchState(pGetIpState); + /* Callback result to InterfaceService. */ + InvokeOnStaConnChanged(OperateResState::CONNECT_OBTAINING_IP, linkedInfo); + mConnectFailedCnt = 0; + /* The current state of StaStateMachine transfers to GetIpState. */ + SwitchState(pGetIpState); + } else { + mConnectFailedCnt = 0; + SwitchState(pLinkedState); + } WifiConfigCenter::GetInstance().SetUserLastSelectedNetworkId(INVALID_NETWORK_ID, m_instId); } void StaStateMachine::DealDisconnectEvent(InternalMessagePtr msg) { - LOGI("Enter DealDisconnectEvent.\n"); + LOGI("Enter DealDisconnectEvent m_instId = %{public}d", m_instId); if (msg == nullptr || wpsState != SetupMethod::INVALID) { WIFI_LOGE("msg is null or wpsState is INVALID, wpsState:%{public}d", static_cast(wpsState)); return; @@ -1339,34 +1361,40 @@ void StaStateMachine::DealDisconnectEvent(InternalMessagePtr msg) WIFI_LOGE("DealDisconnectEvent inconsistent bssid in connecter"); return; } -#ifndef OHOS_ARCH_LITE - if (NetSupplierInfo != nullptr) { - NetSupplierInfo->isAvailable_ = false; - NetSupplierInfo->ident_ = ""; - WIFI_LOGI("On disconnect update net supplier info\n"); - WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); - } -#endif + StopTimer(static_cast(CMD_SIGNAL_POLL)); - StopTimer(static_cast(CMD_START_NETCHECK)); - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); - if (currentTpType == IPTYPE_IPV4) { - StopDhcpClient(ifname.c_str(), false); - } else { - StopDhcpClient(ifname.c_str(), true); + + if (m_instId == INSTID_WLAN0) { +#ifndef OHOS_ARCH_LITE + if (NetSupplierInfo != nullptr) { + NetSupplierInfo->isAvailable_ = false; + NetSupplierInfo->ident_ = ""; + WIFI_LOGI("On disconnect update net supplier info\n"); + WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); + } +#endif + StopTimer(static_cast(CMD_START_NETCHECK)); + std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (currentTpType == IPTYPE_IPV4) { + StopDhcpClient(ifname.c_str(), false); + } else { + StopDhcpClient(ifname.c_str(), true); + } + HandlePostDhcpSetup(); + getIpSucNum = 0; + getIpFailNum = 0; + + IpInfo ipInfo; + WifiConfigCenter::GetInstance().SaveIpInfo(ipInfo, m_instId); + IpV6Info ipV6Info; + WifiConfigCenter::GetInstance().SaveIpV6Info(ipV6Info, m_instId); +#ifdef OHOS_ARCH_LITE + IfConfig::GetInstance().FlushIpAddr(WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId), IPTYPE_IPV4); +#endif } - HandlePostDhcpSetup(); - getIpSucNum = 0; - getIpFailNum = 0; + isRoam = false; - IpInfo ipInfo; - WifiConfigCenter::GetInstance().SaveIpInfo(ipInfo, m_instId); - IpV6Info ipV6Info; - WifiConfigCenter::GetInstance().SaveIpV6Info(ipV6Info, m_instId); -#ifdef OHOS_ARCH_LITE - IfConfig::GetInstance().FlushIpAddr(WifiConfigCenter::GetInstance().GetStaIfaceName(), IPTYPE_IPV4); -#endif /* Initialize connection information. */ std::string ssid = linkedInfo.ssid; InitWifiLinkedInfo(); @@ -1423,6 +1451,7 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessagePtr msg) if (shouldStopTimer) { StopTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT)); } + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); switch (eventName) { case WIFI_SVR_CMD_STA_WPA_PASSWD_WRONG_EVENT: SaveDiscReason(DisconnectedReason::DISC_REASON_WRONG_PWD); @@ -1438,7 +1467,7 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessagePtr msg) } break; case WIFI_SVR_CMD_STA_WPA_FULL_CONNECT_EVENT: - WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID); + WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID, ifaceName); SaveDiscReason(DisconnectedReason::DISC_REASON_CONNECTION_FULL); SaveLinkstate(ConnState::DISCONNECTED, DetailedState::CONNECTION_FULL); InvokeOnStaConnChanged(OperateResState::CONNECT_CONNECTION_FULL, linkedInfo); @@ -1448,7 +1477,7 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessagePtr msg) AddRandomMacCure(); break; case WIFI_SVR_CMD_STA_WPA_ASSOC_REJECT_EVENT: - WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID); + WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID, ifaceName); SaveDiscReason(DisconnectedReason::DISC_REASON_CONNECTION_REJECTED); SaveLinkstate(ConnState::DISCONNECTED, DetailedState::CONNECTION_REJECT); InvokeOnStaConnChanged(OperateResState::CONNECT_CONNECTION_REJECT, linkedInfo); @@ -1467,7 +1496,7 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessagePtr msg) void StaStateMachine::DealSetStaConnectFailedCount(int count, bool set) { WifiDeviceConfig config; - int ret = WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, config); + int ret = WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, config, m_instId); if (ret != 0) { WIFI_LOGW("DealConnectTimeOutCmd get device[%{public}d] config failed.\n", targetNetworkId); return; @@ -1531,7 +1560,8 @@ void StaStateMachine::DealStartWpsCmd(InternalMessagePtr msg) return; } - if (WifiStaHalInterface::GetInstance().ClearDeviceConfig() != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().ClearDeviceConfig(ifaceName) != WIFI_HAL_OPT_OK) { LOGE("ClearDeviceConfig() failed!"); return; } @@ -1662,8 +1692,9 @@ void StaStateMachine::DealCancelWpsCmd(InternalMessagePtr msg) } if (wpsState != SetupMethod::INVALID) { wpsState = SetupMethod::INVALID; - - if (WifiStaHalInterface::GetInstance().EnableNetwork(WPA_DEFAULT_NETWORKID) == WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().EnableNetwork(WPA_DEFAULT_NETWORKID, ifaceName) + == WIFI_HAL_OPT_OK) { WIFI_LOGI("EnableNetwork success!"); } else { WIFI_LOGE("EnableNetwork failed"); @@ -1690,8 +1721,9 @@ void StaStateMachine::DealStartRoamCmd(InternalMessagePtr msg) } std::string bssid = msg->GetStringFromMessage(); targetRoamBssid = bssid; - WIFI_LOGI("%{public}s target bssid:{public}s", MacAnonymize(linkedInfo.bssid).c_str()); - if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, targetRoamBssid) + WIFI_LOGI("%{public}s target bssid:%{public}s,", __FUNCTION__, MacAnonymize(linkedInfo.bssid).c_str()); + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, targetRoamBssid, ifaceName) != WIFI_HAL_OPT_OK) { WIFI_LOGE("%{public}s set roam target bssid fail", __FUNCTION__); return; @@ -1707,20 +1739,26 @@ void StaStateMachine::DealStartRoamCmd(InternalMessagePtr msg) ErrCode StaStateMachine::StartConnectToNetwork(int networkId, const std::string & bssid) { - if (ConfigRandMacSelfCure(networkId) != WIFI_OPT_SUCCESS) { - LOGE("ConfigRandMacSelfCure failed!"); - return WIFI_OPT_FAILED; + if (m_instId == INSTID_WLAN0) { + if (ConfigRandMacSelfCure(networkId) != WIFI_OPT_SUCCESS) { + LOGE("ConfigRandMacSelfCure failed!"); + return WIFI_OPT_FAILED; + } } + targetNetworkId = networkId; SetRandomMac(targetNetworkId, bssid); + LOGE("StartConnectToNetwork SetRandomMac targetNetworkId:%{public}d, bssid:%{public}s", targetNetworkId, + MacAnonymize(bssid).c_str()); WifiDeviceConfig deviceConfig; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, deviceConfig) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, deviceConfig, m_instId) != 0) { LOGE("StartConnectToNetwork get GetDeviceConfig failed!"); return WIFI_OPT_FAILED; } - WifiStaHalInterface::GetInstance().ClearDeviceConfig(); + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + WifiStaHalInterface::GetInstance().ClearDeviceConfig(ifaceName); int wpaNetworkId = INVALID_NETWORK_ID; - if (WifiStaHalInterface::GetInstance().GetNextNetworkId(wpaNetworkId) != WIFI_HAL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().GetNextNetworkId(wpaNetworkId, ifaceName) != WIFI_HAL_OPT_OK) { LOGE("StartConnectToNetwork GetNextNetworkId failed!"); return WIFI_OPT_FAILED; } @@ -1728,21 +1766,21 @@ ErrCode StaStateMachine::StartConnectToNetwork(int networkId, const std::string if (bssid.empty()) { // user select connect LOGI("SetBssid userSelectBssid=%{public}s", MacAnonymize(deviceConfig.userSelectBssid).c_str()); - WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, deviceConfig.userSelectBssid); + WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, deviceConfig.userSelectBssid, ifaceName); deviceConfig.userSelectBssid = ""; WifiSettings::GetInstance().AddDeviceConfig(deviceConfig); WifiSettings::GetInstance().SyncDeviceConfig(); } else { // auto connect LOGI("SetBssid bssid=%{public}s", MacAnonymize(bssid).c_str()); - WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid); + WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid, ifaceName); } - if (WifiStaHalInterface::GetInstance().EnableNetwork(WPA_DEFAULT_NETWORKID) != WIFI_HAL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().EnableNetwork(WPA_DEFAULT_NETWORKID, ifaceName) != WIFI_HAL_OPT_OK) { LOGE("EnableNetwork() failed!"); return WIFI_OPT_FAILED; } - if (WifiStaHalInterface::GetInstance().Connect(WPA_DEFAULT_NETWORKID) != WIFI_HAL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().Connect(WPA_DEFAULT_NETWORKID, ifaceName) != WIFI_HAL_OPT_OK) { LOGE("Connect failed!"); InvokeOnStaConnChanged(OperateResState::CONNECT_SELECT_NETWORK_FAILED, linkedInfo); return WIFI_OPT_FAILED; @@ -1857,7 +1895,7 @@ void StaStateMachine::OnWifiWpa3SelfCure(int failreason, int networkId) return; } failCountReason = iter->second; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) == -1) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) == -1) { WIFI_LOGE("OnWifiWpa3SelfCure, get deviceconfig failed"); return; } @@ -1962,12 +2000,44 @@ void StaStateMachine::SetRandomMacConfig(WifiStoreRandomMac &randomMacInfo, cons #endif } +bool StaStateMachine::SetMacToHal(const std::string ¤tMac, const std::string &realMac, int instId) +{ + std::string lastMac; + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(instId); + if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(lastMac, ifaceName)) != WIFI_HAL_OPT_OK) { + LOGE("%{public}s randommac, GetStaDeviceMacAddress failed!", __func__); + return false; + } + bool isRealMac = currentMac == realMac; + std::string actualConfiguredMac = currentMac; + if (!isRealMac && instId == 1) { + if (!WifiRandomMacHelper::GetWifi2RandomMac(actualConfiguredMac)) { + actualConfiguredMac = realMac; + } + LOGI("%{public}s wifi2 actualConfiguredMac: %{public}s", __func__, MacAnonymize(actualConfiguredMac).c_str()); + } + if (MacAddress::IsValidMac(actualConfiguredMac.c_str())) { + if (lastMac != actualConfiguredMac) { + if (WifiStaHalInterface::GetInstance().SetConnectMacAddr( + WifiConfigCenter::GetInstance().GetStaIfaceName(instId), actualConfiguredMac) != WIFI_HAL_OPT_OK) { + LOGE("set Mac [%{public}s] failed", MacAnonymize(actualConfiguredMac).c_str()); + return false; + } + } + WifiConfigCenter::GetInstance().SetMacAddress(actualConfiguredMac, instId); + return true; + } else { + LOGE("%{public}s randommac, Check MacAddress error", __func__); + return false; + } +} + bool StaStateMachine::SetRandomMac(int networkId, const std::string &bssid) { LOGD("enter SetRandomMac."); #ifdef SUPPORT_LOCAL_RANDOM_MAC WifiDeviceConfig deviceConfig; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, deviceConfig) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, deviceConfig, m_instId) != 0) { LOGE("SetRandomMac : GetDeviceConfig failed!"); return false; } @@ -2003,27 +2073,11 @@ bool StaStateMachine::SetRandomMac(int networkId, const std::string &bssid) currentMac = deviceConfig.macAddress; } } - std::string lastMac; - if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(lastMac)) != WIFI_HAL_OPT_OK) { - LOGE("%{public}s randommac, GetStaDeviceMacAddress failed!", __func__); - return false; - } - LOGI("%{public}s, randommac, use %{public}s mac to connect, currentMac:%{public}s, lastMac:%{public}s", __func__, - realMac == currentMac ? "factory" : "random", MacAnonymize(currentMac).c_str(), MacAnonymize(lastMac).c_str()); - if (MacAddress::IsValidMac(currentMac.c_str())) { - if (lastMac != currentMac) { - if (WifiStaHalInterface::GetInstance().SetConnectMacAddr( - WifiConfigCenter::GetInstance().GetStaIfaceName(), currentMac) != WIFI_HAL_OPT_OK) { - LOGE("set Mac [%{public}s] failed.", MacAnonymize(currentMac).c_str()); - return false; - } - } - WifiConfigCenter::GetInstance().SetMacAddress(currentMac, m_instId); + if (SetMacToHal(currentMac, realMac, m_instId)) { deviceConfig.macAddress = currentMac; WifiSettings::GetInstance().AddDeviceConfig(deviceConfig); WifiSettings::GetInstance().SyncDeviceConfig(); } else { - LOGE("%{public}s randommac, Check MacAddress error.", __func__); return false; } #endif @@ -2142,7 +2196,7 @@ int32_t StaStateMachine::GetDataSlotId(int32_t slotId) int32_t StaStateMachine::GetCardType(CardType &cardType) { WifiDeviceConfig deviceConfig; - WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig); + WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig, m_instId); return CoreServiceClient::GetInstance().GetCardType(GetDataSlotId(deviceConfig.wifiEapConfig.eapSubId), cardType); } @@ -2193,7 +2247,7 @@ std::string StaStateMachine::SimAkaAuth(const std::string &nonce, AuthType authT { LOGD("StaStateMachine::SimAkaAuth in, authType:%{public}d, nonce:%{private}s", authType, nonce.c_str()); WifiDeviceConfig deviceConfig; - WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig); + WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig, m_instId); auto slotId = GetDataSlotId(deviceConfig.wifiEapConfig.eapSubId); SimAuthenticationResponse response; int32_t result = CoreServiceClient::GetInstance().SimAuthentication(slotId, authType, nonce, response); @@ -2288,9 +2342,9 @@ std::string StaStateMachine::GetGsmAuthResponseWithLength(EapSimGsmAuthParam par // strcat request message if (i == 0) { - authRsp += std::string(kcBuf) + ":" + std::string(sresBuf); + authRsp += std::string(kcBuf) + ":" + std::string(sresBuf); } else { - authRsp += ":" + std::string(kcBuf) + ":" + std::string(sresBuf); + authRsp += ":" + std::string(kcBuf) + ":" + std::string(sresBuf); } i++; } @@ -2371,9 +2425,9 @@ std::string StaStateMachine::GetGsmAuthResponseWithoutLength(EapSimGsmAuthParam // strcat request message if (i == 0) { - authRsp += std::string(kcBuf) + ":" + std::string(sresBuf); + authRsp += std::string(kcBuf) + ":" + std::string(sresBuf); } else { - authRsp += ":" + std::string(kcBuf) + ":" + std::string(sresBuf); + authRsp += ":" + std::string(kcBuf) + ":" + std::string(sresBuf); } i++; } @@ -2664,7 +2718,8 @@ bool StaStateMachine::SeparatedState::ExecuteStateMsg(InternalMessagePtr msg) return false; } - WIFI_LOGI("SeparatedState-msgCode=%{public}d received.\n", msg->GetMessageName()); + WIFI_LOGI("SeparatedState-msgCode=%{public}d received. m_instId=%{public}d\n", msg->GetMessageName(), + pStaStateMachine->GetInstanceId()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_NETWORK_DISCONNECTION_EVENT: { @@ -2716,7 +2771,8 @@ bool StaStateMachine::ApLinkedState::ExecuteStateMsg(InternalMessagePtr msg) return false; } - WIFI_LOGD("ApLinkedState-msgCode=%{public}d received.\n", msg->GetMessageName()); + WIFI_LOGD("ApLinkedState-msgCode=%{public}d received. m_instId = %{public}d\n", msg->GetMessageName(), + pStaStateMachine->GetInstanceId()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { /* The current state of StaStateMachine transfers to SeparatingState when @@ -2774,31 +2830,37 @@ void StaStateMachine::ApLinkedState::HandleStaBssidChangedEvent(InternalMessageP return; } pStaStateMachine->linkedInfo.bssid = bssid; - WifiConfigCenter::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo, pStaStateMachine->m_instId); + WifiConfigCenter::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo, pStaStateMachine->GetInstanceId()); /* BSSID change is not received during roaming, only set BSSID */ - if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid) != WIFI_HAL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid, + WifiConfigCenter::GetInstance().GetStaIfaceName(pStaStateMachine->GetInstanceId())) != WIFI_HAL_OPT_OK) { WIFI_LOGE("SetBssid return fail."); } } void StaStateMachine::DisConnectProcess() { - WIFI_LOGI("Enter DisConnectProcess!"); + WIFI_LOGI("Enter DisConnectProcess m_instId:%{public}d!", m_instId); InvokeOnStaConnChanged(OperateResState::DISCONNECT_DISCONNECTING, linkedInfo); - if (WifiStaHalInterface::GetInstance().Disconnect() == WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + WIFI_LOGI("Enter DisConnectProcess ifaceName:%{public}s!", ifaceName.c_str()); + if (WifiStaHalInterface::GetInstance().Disconnect(ifaceName) == WIFI_HAL_OPT_OK) { WIFI_LOGI("Disconnect() succeed!"); + if (m_instId == INSTID_WLAN0) { #ifndef OHOS_ARCH_LITE - if (NetSupplierInfo != nullptr) { - NetSupplierInfo->isAvailable_ = false; - NetSupplierInfo->ident_ = ""; - WIFI_LOGI("Disconnect process update netsupplierinfo"); - WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); - } + if (NetSupplierInfo != nullptr) { + NetSupplierInfo->isAvailable_ = false; + NetSupplierInfo->ident_ = ""; + WIFI_LOGI("Disconnect process update netsupplierinfo"); + WifiNetAgent::GetInstance().OnStaMachineUpdateNetSupplierInfo(NetSupplierInfo); + } #endif + } WIFI_LOGI("Disconnect update wifi status"); /* Save connection information to WifiSettings. */ SaveLinkstate(ConnState::DISCONNECTED, DetailedState::DISCONNECTED); - WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID); + WIFI_LOGI("Enter DisConnectProcess DisableNetwork ifaceName:%{public}s!", ifaceName.c_str()); + WifiStaHalInterface::GetInstance().DisableNetwork(WPA_DEFAULT_NETWORKID, ifaceName); getIpSucNum = 0; /* The current state of StaStateMachine transfers to SeparatedState. */ @@ -2806,7 +2868,7 @@ void StaStateMachine::DisConnectProcess() } else { SaveLinkstate(ConnState::DISCONNECTING, DetailedState::FAILED); InvokeOnStaConnChanged(OperateResState::DISCONNECT_DISCONNECT_FAILED, linkedInfo); - WIFI_LOGE("Disconnect() failed!"); + WIFI_LOGE("Disconnect() failed m_instId:%{public}d!", m_instId); } } @@ -2898,7 +2960,7 @@ int StaStateMachine::RegisterCallBack() { clientCallBack.OnIpSuccessChanged = DhcpResultNotify::OnSuccess; clientCallBack.OnIpFailChanged = DhcpResultNotify::OnFailed; - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); + std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); DhcpErrorCode dhcpRet = RegisterDhcpClientCallBack(ifname.c_str(), &clientCallBack); if (dhcpRet != DHCP_SUCCESS) { WIFI_LOGE("RegisterDhcpClientCallBack failed. dhcpRet=%{public}d", dhcpRet); @@ -2919,7 +2981,7 @@ StaStateMachine::GetIpState::~GetIpState() void StaStateMachine::GetIpState::GoInState() { - WIFI_LOGI("GetIpState GoInState function."); + WIFI_LOGI("GetIpState GoInState function. m_instId=%{public}d", pStaStateMachine->GetInstanceId()); #ifdef WIFI_DHCP_DISABLED SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT); SaveLinkstate(ConnState::CONNECTED, DetailedState::WORKING); @@ -2930,7 +2992,8 @@ void StaStateMachine::GetIpState::GoInState() pStaStateMachine->getIpSucNum = 0; WifiDeviceConfig config; AssignIpMethod assignMethod = AssignIpMethod::DHCP; - int ret = WifiSettings::GetInstance().GetDeviceConfig(pStaStateMachine->linkedInfo.networkId, config); + int ret = WifiSettings::GetInstance().GetDeviceConfig(pStaStateMachine->linkedInfo.networkId, config, + pStaStateMachine->GetInstanceId()); if (ret == 0) { assignMethod = config.wifiIpConfig.assignMethod; } @@ -2954,7 +3017,7 @@ void StaStateMachine::GetIpState::GoInState() break; } int dhcpRet; - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); + std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(pStaStateMachine->GetInstanceId()); pStaStateMachine->currentTpType = static_cast(WifiSettings::GetInstance().GetDhcpIpType()); RouterConfig config; @@ -2969,8 +3032,8 @@ void StaStateMachine::GetIpState::GoInState() } else { dhcpRet = StartDhcpClient(ifname.c_str(), true); } - LOGI("StartDhcpClient type:%{public}d dhcpRet:%{public}d isRoam:%{public}d", pStaStateMachine->currentTpType, - dhcpRet, pStaStateMachine->isRoam); + LOGI("StartDhcpClient type:%{public}d dhcpRet:%{public}d isRoam:%{public}d m_instId=%{public}d", + pStaStateMachine->currentTpType, dhcpRet, pStaStateMachine->isRoam, pStaStateMachine->GetInstanceId()); if (dhcpRet == 0) { LOGI("StartTimer CMD_START_GET_DHCP_IP_TIMEOUT 30s"); pStaStateMachine->StartTimer(static_cast(CMD_START_GET_DHCP_IP_TIMEOUT), @@ -3002,13 +3065,15 @@ bool StaStateMachine::GetIpState::ExecuteStateMsg(InternalMessagePtr msg) } bool ret = NOT_EXECUTED; - WIFI_LOGI("GetIpState-msgCode=%{public}d received.\n", msg->GetMessageName()); + WIFI_LOGI("GetIpState-msgCode=%{public}d received. m_instId = %{public}d\n", msg->GetMessageName(), + pStaStateMachine->GetInstanceId()); switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_DHCP_RESULT_NOTIFY_EVENT: { ret = EXECUTED; int result = msg->GetParam1(); int ipType = msg->GetParam2(); - WIFI_LOGI("GetIpState, get ip result:%{public}d, ipType = %{public}d\n", result, ipType); + WIFI_LOGI("GetIpState, get ip result:%{public}d, ipType = %{public}d, m_instId = %{public}d\n", + result, ipType, pStaStateMachine->GetInstanceId()); switch (result) { case DhcpReturnCode::DHCP_RESULT: { pStaStateMachine->pDhcpResultNotify->DealDhcpResult(ipType); @@ -3085,7 +3150,8 @@ bool StaStateMachine::GetIpState::IsProhibitUseCacheIp() } WifiDeviceConfig config; - WifiSettings::GetInstance().GetDeviceConfig(pStaStateMachine->linkedInfo.networkId, config); + WifiSettings::GetInstance().GetDeviceConfig(pStaStateMachine->linkedInfo.networkId, config, + pStaStateMachine->GetInstanceId()); if (config.keyMgmt == KEY_MGMT_WEP) { WIFI_LOGE("current keyMgmt is WEP, not use cache ip if dhcp timeout"); return true; @@ -3099,7 +3165,7 @@ bool StaStateMachine::GetIpState::IsProhibitUseCacheIp() } #endif int currentSignalLevel = WifiSettings::GetInstance().GetSignalLevel( - pStaStateMachine->linkedInfo.rssi, pStaStateMachine->linkedInfo.band, pStaStateMachine->m_instId); + pStaStateMachine->linkedInfo.rssi, pStaStateMachine->linkedInfo.band, pStaStateMachine->GetInstanceId()); if (currentSignalLevel < RSSI_LEVEL_3) { WIFI_LOGE("current rssi level is less than 3"); return true; @@ -3156,7 +3222,7 @@ void StaStateMachine::ReplaceEmptyDns(DhcpResult *result) bool StaStateMachine::ConfigStaticIpAddress(StaticIpAddress &staticIpAddress) { WIFI_LOGI("Enter StaStateMachine::SetDhcpResultFromStatic."); - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); + std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); DhcpResult result; switch (currentTpType) { case IPTYPE_IPV4: { @@ -3484,20 +3550,26 @@ StaStateMachine::LinkedState::~LinkedState() void StaStateMachine::LinkedState::GoInState() { - WIFI_LOGI("LinkedState GoInState function."); + WIFI_LOGI("LinkedState GoInState function. m_instId = %{public}d", pStaStateMachine->GetInstanceId()); WriteWifiOperateStateHiSysEvent(static_cast(WifiOperateType::STA_CONNECT), static_cast(WifiOperateState::STA_CONNECTED)); - WifiSettings::GetInstance().SetDeviceAfterConnect(pStaStateMachine->linkedInfo.networkId); - WifiSettings::GetInstance().SetDeviceState(pStaStateMachine->linkedInfo.networkId, - static_cast(WifiDeviceConfigStatus::ENABLED), false); - WifiSettings::GetInstance().SyncDeviceConfig(); + if (pStaStateMachine->GetInstanceId() == INSTID_WLAN0) { + WifiSettings::GetInstance().SetDeviceAfterConnect(pStaStateMachine->linkedInfo.networkId); + WifiSettings::GetInstance().SetDeviceState(pStaStateMachine->linkedInfo.networkId, + static_cast(WifiDeviceConfigStatus::ENABLED), false); + WifiSettings::GetInstance().SyncDeviceConfig(); #ifndef OHOS_ARCH_LITE - if (pStaStateMachine != nullptr && pStaStateMachine->m_NetWorkState != nullptr) { - pStaStateMachine->m_NetWorkState->StartNetStateObserver(pStaStateMachine->m_NetWorkState); - pStaStateMachine->lastTimestamp = 0; - pStaStateMachine->StartDetectTimer(DETECT_TYPE_DEFAULT); - } + if (pStaStateMachine != nullptr && pStaStateMachine->m_NetWorkState != nullptr) { + pStaStateMachine->m_NetWorkState->StartNetStateObserver(pStaStateMachine->m_NetWorkState); + pStaStateMachine->lastTimestamp = 0; + pStaStateMachine->StartDetectTimer(DETECT_TYPE_DEFAULT); + } #endif + } else { + pStaStateMachine->SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT); + pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); + pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, pStaStateMachine->linkedInfo); + } #ifdef SUPPORT_ClOUD_WIFI_ASSET WifiAssetManager::GetInstance().WifiAssetTriggerSync(); #endif @@ -3563,7 +3635,9 @@ bool StaStateMachine::LinkedState::ExecuteStateMsg(InternalMessagePtr msg) WIFI_LOGE("Bssid change not for ASSOC_COMPLETE, do nothing."); return false; } - if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid) != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(pStaStateMachine->GetInstanceId()); + if (WifiStaHalInterface::GetInstance().SetBssid(WPA_DEFAULT_NETWORKID, bssid, ifaceName) + != WIFI_HAL_OPT_OK) { WIFI_LOGE("SetBssid return fail."); return false; } @@ -3572,7 +3646,8 @@ bool StaStateMachine::LinkedState::ExecuteStateMsg(InternalMessagePtr msg) #endif pStaStateMachine->isRoam = true; pStaStateMachine->linkedInfo.bssid = bssid; - WifiConfigCenter::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo, pStaStateMachine->m_instId); + WifiConfigCenter::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo, + pStaStateMachine->GetInstanceId()); /* The current state of StaStateMachine transfers to pApRoamingState. */ pStaStateMachine->SwitchState(pStaStateMachine->pApRoamingState); break; @@ -3665,7 +3740,8 @@ void StaStateMachine::DealHiLinkDataToWpa(InternalMessagePtr msg) } case WIFI_SVR_COM_STA_HILINK_TRIGGER_WPS: { LOGI("DealHiLinkTriggerWps start ClearDeviceConfig"); - WifiStaHalInterface::GetInstance().ClearDeviceConfig(); + WifiStaHalInterface::GetInstance().ClearDeviceConfig( + WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId)); LOGI("DealHiLinkTriggerWps SPECIAL_CONNECTED"); InvokeOnStaConnChanged(OperateResState::SPECIAL_CONNECTED, linkedInfo); @@ -3723,7 +3799,8 @@ bool StaStateMachine::ApRoamingState::ExecuteStateMsg(InternalMessagePtr msg) return false; } - WIFI_LOGI("ApRoamingState, reveived msgCode=%{public}d msg.", msg->GetMessageName()); + WIFI_LOGI("ApRoamingState, reveived msgCode=%{public}d msg. m_instId = %{public}d", + msg->GetMessageName(), pStaStateMachine->GetInstanceId()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT: { @@ -3755,7 +3832,8 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa bool ret = EXECUTED; std::string bssid = msg->GetStringFromMessage(); if (pStaStateMachine->CheckRoamingBssidIsSame(bssid)) { - WIFI_LOGE("ApRoamingState inconsistent bssid in connecter"); + WIFI_LOGE("ApRoamingState inconsistent bssid in connecter m_instId = %{public}d", + pStaStateMachine->GetInstanceId()); ret = NOT_EXECUTED; } pStaStateMachine->isRoam = true; @@ -3765,18 +3843,22 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa /* Notify result to InterfaceService. */ pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_ASSOCIATED, pStaStateMachine->linkedInfo); - if (!pStaStateMachine->CanArpReachable()) { - WIFI_LOGI("Arp is not reachable"); - WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); - pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_OBTAINING_IP, - pStaStateMachine->linkedInfo); - /* The current state of StaStateMachine transfers to GetIpState. */ - pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); + if (pStaStateMachine->GetInstanceId() == INSTID_WLAN0) { + if (!pStaStateMachine->CanArpReachable()) { + WIFI_LOGI("Arp is not reachable"); + WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); + pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_OBTAINING_IP, + pStaStateMachine->linkedInfo); + /* The current state of StaStateMachine transfers to GetIpState. */ + pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); + } else { + WIFI_LOGI("Arp is reachable"); + pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); + pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, + pStaStateMachine->linkedInfo); + pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); + } } else { - WIFI_LOGI("Arp is reachable"); - pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); - pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, - pStaStateMachine->linkedInfo); pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); } return ret; @@ -3790,7 +3872,7 @@ bool StaStateMachine::CanArpReachable() IpInfo ipInfo; WifiConfigCenter::GetInstance().GetIpInfo(ipInfo, m_instId); std::string ipAddress = IpTools::ConvertIpv4Address(ipInfo.ipAddress); - std::string ifName = WifiConfigCenter::GetInstance().GetStaIfaceName(); + std::string ifName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); if (ipInfo.gateway == 0) { WIFI_LOGI("gateway is empty"); return false; @@ -3811,7 +3893,7 @@ bool StaStateMachine::CanArpReachable() ErrCode StaStateMachine::ConfigRandMacSelfCure(const int networkId) { WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) != 0) { LOGE("GetDeviceConfig failed!"); return WIFI_OPT_FAILED; } @@ -3825,12 +3907,13 @@ ErrCode StaStateMachine::ConfigRandMacSelfCure(const int networkId) return WIFI_OPT_SUCCESS; } -void StaStateMachine::GetDeviceCfgInfo(const std::string& bssid, WifiDeviceConfig &deviceConfig) +void StaStateMachine::GetDeviceCfgInfo(const std::string &bssid, WifiDeviceConfig &deviceConfig) { WifiHalGetDeviceConfig config; config.networkId = WPA_DEFAULT_NETWORKID; config.param = "ssid"; - if (WifiStaHalInterface::GetInstance().GetDeviceConfig(config) != WIFI_HAL_OPT_OK) { + std::string ifaceName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); + if (WifiStaHalInterface::GetInstance().GetDeviceConfig(config, ifaceName) != WIFI_HAL_OPT_OK) { WIFI_LOGI("GetDeviceConfig failed!"); } deviceConfig.networkId = WPA_DEFAULT_NETWORKID; @@ -3845,21 +3928,24 @@ void StaStateMachine::GetDeviceCfgInfo(const std::string& bssid, WifiDeviceConf void StaStateMachine::ConnectToNetworkProcess(std::string bssid) { - WIFI_LOGI("ConnectToNetworkProcess, Receive bssid=%{public}s", MacAnonymize(bssid).c_str()); + WIFI_LOGI("ConnectToNetworkProcess, Receive bssid=%{public}s m_instId = %{public}d", + MacAnonymize(bssid).c_str(), m_instId); if ((wpsState == SetupMethod::DISPLAY) || (wpsState == SetupMethod::PBC) || (wpsState == SetupMethod::KEYPAD)) { targetNetworkId = WPA_DEFAULT_NETWORKID; } WifiDeviceConfig deviceConfig; - if (WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig) != 0) { + if (WifiSettings::GetInstance().GetDeviceConfig(targetNetworkId, deviceConfig, m_instId) != 0) { WIFI_LOGE("%{public}s cnanot find config for networkId = %{public}d", __FUNCTION__, targetNetworkId); } UpdateDeviceConfigAfterWifiConnected(deviceConfig, bssid); - + std::string macAddr; std::string realMacAddr; WifiConfigCenter::GetInstance().GetMacAddress(macAddr, m_instId); WifiSettings::GetInstance().GetRealMacAddress(realMacAddr, m_instId); + WIFI_LOGI("ConnectToNetworkProcess instId:%{public}d, macAddr:%{public}s, realMacAddr:%{public}s", + m_instId, macAddr.c_str(), realMacAddr.c_str()); linkedInfo.networkId = targetNetworkId; linkedInfo.bssid = bssid; linkedInfo.ssid = deviceConfig.ssid; @@ -3927,7 +4013,7 @@ void StaStateMachine::SetWifiLinkedInfo(int networkId) } else if (networkId != INVALID_NETWORK_ID) { linkedInfo.networkId = networkId; WifiDeviceConfig config; - int ret = WifiSettings::GetInstance().GetDeviceConfig(networkId, config); + int ret = WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId); if (ret == 0) { /* Update connection information according to configuration. */ linkedInfo.networkId = config.networkId; @@ -4166,8 +4252,8 @@ void StaStateMachine::DhcpResultNotify::DealDhcpResult(int ipType) if (ret == 0) { assignMethod = config.wifiIpConfig.assignMethod; } - LOGI("DhcpResultNotify OnSuccess, uLeaseTime=%{public}d %{public}d %{public}d", result->uOptLeasetime, assignMethod, - pStaStateMachine->currentTpType); + LOGI("DhcpResultNotify OnSuccess, uLeaseTime=%{public}d %{public}d %{public}d m_instId = %{public}d", + result->uOptLeasetime, assignMethod, pStaStateMachine->currentTpType, pStaStateMachine->GetInstanceId()); return; } @@ -4248,7 +4334,7 @@ void StaStateMachine::DhcpResultNotify::TryToSaveIpV6Result(IpInfo &ipInfo, IpV6 LOGE("TryToSaveIpV6Result resultis nullptr."); return; } - + if ((ipv6Info.globalIpV6Address != result->strOptClientId) || (ipv6Info.randGlobalIpV6Address != result->strOptRandIpv6Addr) || (ipv6Info.uniqueLocalAddress1 != result->strOptLocalAddr1) || @@ -4291,7 +4377,7 @@ void StaStateMachine::DhcpResultNotify::TryToSaveIpV6Result(IpInfo &ipInfo, IpV6 void StaStateMachine::DhcpResultNotify::TryToCloseDhcpClient(int iptype) { - std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(); + std::string ifname = WifiConfigCenter::GetInstance().GetStaIfaceName(pStaStateMachine->m_instId); if (iptype == 1) { LOGI("TryToCloseDhcpClient iptype ipv6 return"); return; @@ -4402,7 +4488,9 @@ void StaStateMachine::SetOperationalMode(int mode) void StaStateMachine::OnNetManagerRestart(void) { LOGI("OnNetManagerRestart()"); - WifiNetAgent::GetInstance().OnStaMachineNetManagerRestart(NetSupplierInfo, m_instId); + if (m_instId == INSTID_WLAN0) { + WifiNetAgent::GetInstance().OnStaMachineNetManagerRestart(NetSupplierInfo, m_instId); + } } void StaStateMachine::ReUpdateNetLinkInfo(const WifiDeviceConfig &config) @@ -4418,8 +4506,10 @@ void StaStateMachine::ReUpdateNetLinkInfo(const WifiDeviceConfig &config) IpV6Info wifiIpV6Info; WifiConfigCenter::GetInstance().GetIpv6Info(wifiIpV6Info, m_instId); WifiDeviceConfig config; - WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config); - WifiNetAgent::GetInstance().UpdateNetLinkInfo(wifiIpInfo, wifiIpV6Info, config.wifiProxyconfig, m_instId); + WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config, m_instId); + if (m_instId == INSTID_WLAN0) { + WifiNetAgent::GetInstance().UpdateNetLinkInfo(wifiIpInfo, wifiIpV6Info, config.wifiProxyconfig, m_instId); + } } } @@ -4427,7 +4517,7 @@ void StaStateMachine::SaveWifiConfigForUpdate(int networkId) { WIFI_LOGI("Enter SaveWifiConfigForUpdate."); WifiDeviceConfig config; - if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config) == -1) { + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, config, m_instId) == -1) { WIFI_LOGE("SaveWifiConfigForUpdate, get current config failed."); return; } @@ -4449,8 +4539,9 @@ void StaStateMachine::HandlePostDhcpSetup() WifiDeviceConfig StaStateMachine::getCurrentWifiDeviceConfig() { + WIFI_LOGI("getCurrentWifiDeviceConfig, networkId %{public}d.", linkedInfo.networkId); WifiDeviceConfig wifiDeviceConfig; - WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, wifiDeviceConfig); + WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, wifiDeviceConfig, m_instId); return wifiDeviceConfig; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h index 4565a071d..5da02af11 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h @@ -553,6 +553,8 @@ public: #ifndef OHOS_ARCH_LITE void SetEnhanceService(IEnhanceService* enhanceService); #endif + + bool SetMacToHal(const std::string ¤tMac, const std::string &realMac, int instId); private: /** * @Description Destruct state. @@ -1269,6 +1271,7 @@ private: bool IsGoodSignalQuality(); void AppendFastTransitionKeyMgmt(const WifiScanInfo &scanInfo, WifiHalDeviceConfig &halDeviceConfig) const; void ConvertSsidToOriginalSsid(const WifiDeviceConfig &config, WifiHalDeviceConfig &halDeviceConfig) const; + void CreateWifi2Config(int &networkId); }; } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/wifi_device_service_impl.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/wifi_device_service_impl.cpp index 46265f274..090ce576a 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/wifi_device_service_impl.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/wifi_device_service_impl.cpp @@ -147,8 +147,8 @@ ErrCode WifiDeviceServiceImpl::DisableWifi() return WIFI_OPT_PERMISSION_DENIED; } - if (m_instId == 0) { - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_DISABLED); + if (m_instId == INSTID_WLAN0 || m_instId == INSTID_WLAN1) { + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_DISABLED, m_instId); WifiConfigCenter::GetInstance().SetWifiAllowSemiActive(false); } @@ -184,7 +184,7 @@ ErrCode WifiDeviceServiceImpl::EnableSemiWifi() return WIFI_OPT_FORBID_AIRPLANE; } #endif - if (m_instId == 0) { + if (m_instId == INSTID_WLAN0 || m_instId == INSTID_WLAN1) { WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED); } @@ -1760,8 +1760,8 @@ ErrCode WifiDeviceServiceImpl::FactoryReset() } WIFI_LOGI("WifiDeviceServiceImpl FactoryReset sta,p2p,hotspot! m_instId:%{public}d", m_instId); - if (m_instId == 0) { - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED); + if (m_instId >= 0 || m_instId < STA_INSTANCE_MAX_NUM) { + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED, m_instId); } WifiManager::GetInstance().GetWifiTogglerManager()->WifiToggled(0, m_instId); WifiOprMidState curState = WifiConfigCenter::GetInstance().GetApMidState(m_instId); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp index ae3cafc75..05b2fc89f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp @@ -445,14 +445,14 @@ void WifiEventSubscriberManager::CheckAndStartStaByDatashare() int lastStaState = GetLastStaStateByDatashare(); if (lastStaState == openWifi) { - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED); + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED, INSTID_WLAN0); WifiManager::GetInstance().GetWifiTogglerManager()->WifiToggled(1, 0); } else if (lastStaState == openWifiInAirplanemode) { WifiSettings::GetInstance().SetWifiFlagOnAirplaneMode(true); - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED); + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED, INSTID_WLAN0); WifiManager::GetInstance().GetWifiTogglerManager()->WifiToggled(1, 0); } else if (lastStaState == closeWifiByAirplanemodeOpen) { - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED); + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_ENABLED, INSTID_WLAN0); } } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.cpp index 57e3798e4..b44d14322 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.cpp @@ -49,6 +49,7 @@ WifiTogglerManager::WifiTogglerManager() #endif InitConcreteCallback(); InitSoftapCallback(); + InitMultiStacallback(); pWifiControllerMachine = std::make_unique(); if (pWifiControllerMachine) { pWifiControllerMachine->InitWifiControllerMachine(); @@ -65,9 +66,15 @@ SoftApModeCallback& WifiTogglerManager::GetSoftApCallback() return mSoftApModeCb; } +MultiStaModeCallback& WifiTogglerManager::GetMultiStaCallback() +{ + return mMultiStaModeCb; +} + ErrCode WifiTogglerManager::WifiToggled(int isOpen, int id) { pWifiControllerMachine->ClearWifiStartFailCount(); + WIFI_LOGI("WifiTogglerManager::WifiToggled, isOpen %{public}d instId: %{public}d", isOpen, id); pWifiControllerMachine->SendMessage(CMD_WIFI_TOGGLED, isOpen, id); return WIFI_OPT_SUCCESS; } @@ -133,6 +140,13 @@ void WifiTogglerManager::InitSoftapCallback() mSoftApModeCb.onStopped = std::bind(&WifiTogglerManager::DealSoftapStop, this, _1); } +void WifiTogglerManager::InitMultiStacallback() +{ + using namespace std::placeholders; + mMultiStaModeCb.onStartFailure = std::bind(&WifiTogglerManager::DealMultiStaStartFailure, this, _1); + mMultiStaModeCb.onStopped = std::bind(&WifiTogglerManager::DealMultiStaStop, this, _1); +} + void WifiTogglerManager::DealConcreateStop(int id) { if (pWifiControllerMachine) { @@ -168,6 +182,20 @@ void WifiTogglerManager::DealClientRemoved(int id) } } +void WifiTogglerManager::DealMultiStaStartFailure(int id) +{ + if (pWifiControllerMachine) { + pWifiControllerMachine->SendMessage(CMD_STA_START_FAILURE, id); + } +} + +void WifiTogglerManager::DealMultiStaStop(int id) +{ + if (pWifiControllerMachine) { + pWifiControllerMachine->SendMessage(CMD_MULTI_STA_STOPPED, id); + } +} + void WifiTogglerManager::ForceStopWifi() { if (pWifiControllerMachine) { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.h index b372cc99f..639994431 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.h @@ -31,6 +31,7 @@ public: ~WifiTogglerManager() = default; ConcreteModeCallback& GetConcreteCallback(void); + MultiStaModeCallback &GetMultiStaCallback(); SoftApModeCallback& GetSoftApCallback(void); ErrCode WifiToggled(int isOpen, int id = 0); ErrCode SoftapToggled(int isOpen, int id = 0); @@ -48,17 +49,21 @@ public: private: void InitConcreteCallback(void); void InitSoftapCallback(void); + void InitMultiStacallback(); void DealConcreateStop(int id = 0); void DealConcreateStartFailure(int id = 0); void DealSoftapStop(int id = 0); void DealSoftapStartFailure(int id = 0); void DealClientRemoved(int id = 0); + void DealMultiStaStartFailure(int id); + void DealMultiStaStop(int id); void CheckSatelliteState(); bool IsInterfaceUp(std::string &iface); private: ConcreteModeCallback mConcreteModeCb; SoftApModeCallback mSoftApModeCb; + MultiStaModeCallback mMultiStaModeCb; std::unique_ptr pWifiControllerMachine = nullptr; }; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.cpp index 1c44c4a51..2cd96a296 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.cpp @@ -74,7 +74,7 @@ int WifiConfigCenter::Init() InitScanControlForbidList(); InitScanControlIntervalList(); ClearLocalHid2dInfo(); - mPersistWifiState = WifiSettings::GetInstance().GetOperatorWifiType(); + mPersistWifiState[INSTID_WLAN0] = WifiSettings::GetInstance().GetOperatorWifiType(INSTID_WLAN0); mAirplaneModeState = WifiSettings::GetInstance().GetLastAirplaneMode(); return 0; } @@ -143,16 +143,18 @@ bool WifiConfigCenter::GetWifiStopState() const return mWifiStoping.load(); } -void WifiConfigCenter::SetStaIfaceName(const std::string &ifaceName) +void WifiConfigCenter::SetStaIfaceName(const std::string &ifaceName, int instId) { std::unique_lock lock(mStaMutex); - mStaIfaceName = ifaceName; + mStaIfaceName[instId] = ifaceName; } -std::string WifiConfigCenter::GetStaIfaceName() +std::string WifiConfigCenter::GetStaIfaceName(int instId) { std::unique_lock lock(mStaMutex); - return mStaIfaceName; + WIFI_LOGD("GetStaIfaceName instId:%{public}d mStaIfaceName[instId]:%{public}s ", + instId, mStaIfaceName[instId].c_str()); + return mStaIfaceName[instId]; } int WifiConfigCenter::GetWifiState(int instId) @@ -337,6 +339,8 @@ int WifiConfigCenter::SaveLinkedInfo(const WifiLinkedInfo &info, int instId) if (bssid == info.bssid) { iter->second.channelWidth = channelWidth; } + } else { + mWifiLinkedInfo.emplace(instId, info); } return 0; @@ -357,6 +361,7 @@ int WifiConfigCenter::SetMacAddress(const std::string &macAddress, int instId) { std::unique_lock lock(mStaMutex); mMacAddress[instId] = macAddress; + WIFI_LOGI("SetMacAddress instId:%{public}d, macAddress:%{public}s", instId, macAddress.c_str()); return 0; } @@ -1054,23 +1059,23 @@ bool WifiConfigCenter::SetWifiStateOnAirplaneChanged(const int &state) mAirplaneModeState = state; WifiSettings::GetInstance().SetLastAirplaneMode(state); if (WifiSettings::GetInstance().GetWifiFlagOnAirplaneMode()) { - if (GetPersistWifiState() == WIFI_STATE_DISABLED) { + if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_DISABLED) { return true; } - if (GetPersistWifiState() == WIFI_STATE_SEMI_ENABLED && state == MODE_STATE_OPEN) { - SetPersistWifiState(WIFI_STATE_DISABLED); + if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_SEMI_ENABLED && state == MODE_STATE_OPEN) { + SetPersistWifiState(WIFI_STATE_DISABLED, INSTID_WLAN0); return true; } return false; } if (state == MODE_STATE_OPEN) { - if (GetPersistWifiState() == WIFI_STATE_ENABLED) { + if (GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_ENABLED) { WifiSettings::GetInstance().SetWifiDisabledByAirplane(true); } - SetPersistWifiState(WIFI_STATE_DISABLED); + SetPersistWifiState(WIFI_STATE_DISABLED, INSTID_WLAN0); } else { if (WifiSettings::GetInstance().GetWifiDisabledByAirplane()) { - SetPersistWifiState(WIFI_STATE_ENABLED); + SetPersistWifiState(WIFI_STATE_ENABLED, INSTID_WLAN0); WifiSettings::GetInstance().SetWifiDisabledByAirplane(false); } } @@ -1082,21 +1087,21 @@ int WifiConfigCenter::GetAirplaneModeState() const return mAirplaneModeState.load(); } -int WifiConfigCenter::GetWifiToggledEnable() +int WifiConfigCenter::GetWifiToggledEnable(int id) { if (GetAirplaneModeState() == MODE_STATE_OPEN) { - if (GetPersistWifiState() == WIFI_STATE_ENABLED) { + if (GetPersistWifiState(id) == WIFI_STATE_ENABLED) { return WIFI_STATE_ENABLED; } return WIFI_STATE_DISABLED; } - if (GetPersistWifiState() != WIFI_STATE_ENABLED && GetWifiAllowSemiActive()) { + if (GetPersistWifiState(id) != WIFI_STATE_ENABLED && GetWifiAllowSemiActive()) { return WIFI_STATE_SEMI_ENABLED; } - return GetPersistWifiState(); + return GetPersistWifiState(id); } -void WifiConfigCenter::SetWifiToggledState(int state) +void WifiConfigCenter::SetWifiToggledState(int state, int id) { if (GetAirplaneModeState() == MODE_STATE_OPEN) { WifiSettings::GetInstance().SetWifiDisabledByAirplane(false); @@ -1107,7 +1112,7 @@ void WifiConfigCenter::SetWifiToggledState(int state) state = WIFI_STATE_DISABLED; } } - SetPersistWifiState(state); + SetPersistWifiState(state, id); } void WifiConfigCenter::SetPowerSavingModeState(const int &state) @@ -1459,16 +1464,24 @@ void WifiConfigCenter::InitScanControlIntervalList() return; } -void WifiConfigCenter::SetPersistWifiState(int state) +void WifiConfigCenter::SetPersistWifiState(int state, int instId) { - mPersistWifiState = state; - WifiSettings::GetInstance().SetOperatorWifiType(state); + if (instId < 0 || instId >= STA_INSTANCE_MAX_NUM) { + LOGE("SetPersistWifiState invalid instId %{public}d", instId); + return; + } + mPersistWifiState.at(instId) = state; + WifiSettings::GetInstance().SetOperatorWifiType(state, instId); LOGI("persist wifi state is %{public}d", state); } -int WifiConfigCenter::GetPersistWifiState() +int WifiConfigCenter::GetPersistWifiState(int instId) { - return mPersistWifiState.load(); + if (instId < 0 || instId >= STA_INSTANCE_MAX_NUM) { + LOGE("GetPersistWifiState invalid instId %{public}d", instId); + return -1; + } + return mPersistWifiState.at(instId); } std::string WifiConfigCenter::GetPairMacAddress(std::map& macAddrInfoMap, diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.h b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.h index 9eb9b5a9a..a3d175b2c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_center.h @@ -24,7 +24,9 @@ #include #include "wifi_internal_msg.h" #include "wifi_settings.h" - +#ifndef STA_INSTANCE_MAX_NUM +#define STA_INSTANCE_MAX_NUM 2 +#endif #define SOFT_BUS_SERVICE_UID 1024 #define CAST_ENGINE_SERVICE_UID 5526 #define MIRACAST_SERVICE_UID 5529 @@ -66,9 +68,9 @@ public: bool GetWifiStopState() const; - void SetStaIfaceName(const std::string &ifaceName); + void SetStaIfaceName(const std::string &ifaceName, int instId = 0); - std::string GetStaIfaceName(); + std::string GetStaIfaceName(int instId = 0); int GetWifiState(int instId = 0); @@ -282,9 +284,9 @@ public: int GetAirplaneModeState() const; - int GetWifiToggledEnable(); + int GetWifiToggledEnable(int id = 0); - void SetWifiToggledState(int state); + void SetWifiToggledState(int state, int id = 0); void SetPowerSavingModeState(const int &state); @@ -315,14 +317,16 @@ public: void ClearMacAddrPairs(WifiMacAddrInfoType type); + void SetPersistWifiState(int state, int instId); + + int GetPersistWifiState(int instId); + private: WifiConfigCenter(); bool HasWifiActive(); void UpdateLinkedInfo(int instId = 0); void InitScanControlForbidList(); void InitScanControlIntervalList(); - void SetPersistWifiState(int state); - int GetPersistWifiState(); std::string GetPairMacAddress(std::map& macAddrInfoMap, const WifiMacAddrInfo &macAddrInfo); WifiMacAddrErrCode InsertMacAddrPairs(std::map& macAddrInfoMap, @@ -341,7 +345,7 @@ private: std::atomic mSelectedCandidateNetworkId {INVALID_NETWORK_ID}; std::atomic mWifiAllowSemiActive {false}; std::atomic mWifiStoping {false}; - std::string mStaIfaceName {"wlan0"}; + std::vector mStaIfaceName = {"wlan0", "wlan1"}; std::map> mWifiState; std::map mWifiDetailState; std::map> mStaMidState; @@ -403,7 +407,7 @@ private: std::atomic mGnssFixState {MODE_STATE_CLOSE}; std::atomic mScanGenieState {MODE_STATE_OPEN}; std::atomic mAirplaneModeState {MODE_STATE_CLOSE}; - std::atomic mPersistWifiState {WIFI_STATE_DISABLED}; + std::vector mPersistWifiState {std::vector(2, WIFI_STATE_DISABLED)}; std::atomic mPowerSavingModeState {MODE_STATE_CLOSE}; std::atomic mFreezeModeState {MODE_STATE_CLOSE}; std::atomic mNoChargerPlugModeState {MODE_STATE_CLOSE}; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp index b092cf7fc..8d6d0220d 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp @@ -187,7 +187,7 @@ void WifiSettings::ClearDeviceConfig(void) return; } -int WifiSettings::GetDeviceConfig(std::vector &results) +int WifiSettings::GetDeviceConfig(std::vector &results, int instId) { if (!deviceConfigLoadFlag.test_and_set()) { LOGD("Reload wifi config"); @@ -196,14 +196,14 @@ int WifiSettings::GetDeviceConfig(std::vector &results) std::unique_lock lock(mStaMutex); for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { // -1: Connect by system, use default uid. - if (iter->second.uid == -1 || iter->second.isShared) { + if ((iter->second.uid == -1 || iter->second.isShared) && iter->second.instanceId == instId) { results.push_back(iter->second); } } return 0; } -int WifiSettings::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config) +int WifiSettings::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config, int instId) { if (!deviceConfigLoadFlag.test_and_set()) { LOGD("Reload wifi config"); @@ -211,7 +211,7 @@ int WifiSettings::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config } std::unique_lock lock(mStaMutex); for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { - if (iter->second.networkId == networkId) { + if (iter->second.networkId == networkId && iter->second.instanceId == instId) { config = iter->second; SyncAfterDecryped(config); return 0; @@ -220,7 +220,8 @@ int WifiSettings::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config return -1; } -int WifiSettings::GetDeviceConfig(const std::string &index, const int &indexType, WifiDeviceConfig &config) +int WifiSettings::GetDeviceConfig(const std::string &index, const int &indexType, + WifiDeviceConfig &config, int instId) { if (!deviceConfigLoadFlag.test_and_set()) { LOGD("Reload wifi config"); @@ -229,7 +230,7 @@ int WifiSettings::GetDeviceConfig(const std::string &index, const int &indexType std::unique_lock lock(mStaMutex); if (indexType == DEVICE_CONFIG_INDEX_SSID) { for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { - if (iter->second.ssid == index) { + if (iter->second.ssid == index && iter->second.instanceId == instId) { config = iter->second; SyncAfterDecryped(config); return 0; @@ -237,7 +238,7 @@ int WifiSettings::GetDeviceConfig(const std::string &index, const int &indexType } } else { for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { - if (iter->second.bssid == index) { + if (iter->second.bssid == index && iter->second.instanceId == instId) { config = iter->second; SyncAfterDecryped(config); return 0; @@ -247,7 +248,8 @@ int WifiSettings::GetDeviceConfig(const std::string &index, const int &indexType return -1; } -int WifiSettings::GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config) +int WifiSettings::GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, + WifiDeviceConfig &config, int instId) { if (!deviceConfigLoadFlag.test_and_set()) { LOGD("Reload wifi config"); @@ -258,7 +260,7 @@ int WifiSettings::GetDeviceConfig(const std::string &ssid, const std::string &ke if (keymgmt.compare("WPA-PSK+SAE") == 0) { for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { if ((iter->second.ssid == ssid) && (keymgmt.find(iter->second.keyMgmt) != std::string::npos) - && (iter->second.uid == -1 || iter->second.isShared)) { + && (iter->second.uid == -1 || iter->second.isShared) && iter->second.instanceId == instId) { config = iter->second; SyncAfterDecryped(config); return 0; @@ -267,7 +269,7 @@ int WifiSettings::GetDeviceConfig(const std::string &ssid, const std::string &ke } else { for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) { if ((iter->second.ssid == ssid) && (iter->second.keyMgmt == keymgmt) - && (iter->second.uid == -1 || iter->second.isShared)) { + && (iter->second.uid == -1 || iter->second.isShared) && iter->second.instanceId == instId) { config = iter->second; SyncAfterDecryped(config); return 0; @@ -441,7 +443,7 @@ int WifiSettings::SyncDeviceConfig() std::unique_lock lock(mStaMutex); std::vector tmp; for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); ++iter) { - if (!iter->second.isEphemeral) { + if (!iter->second.isEphemeral && iter->second.instanceId == 0) { tmp.push_back(iter->second); } } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.h b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.h index 529f78777..80bcba65f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.h @@ -115,13 +115,13 @@ public: void ClearDeviceConfig(void); - int GetDeviceConfig(std::vector &results); + int GetDeviceConfig(std::vector &results, int instId = 0); - int GetDeviceConfig(const int &networkId, WifiDeviceConfig &config); + int GetDeviceConfig(const int &networkId, WifiDeviceConfig &config, int instId = 0); - int GetDeviceConfig(const std::string &index, const int &indexType, WifiDeviceConfig &config); + int GetDeviceConfig(const std::string &index, const int &indexType, WifiDeviceConfig &config, int instId = 0); - int GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config); + int GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config, int instId = 0); int SetDeviceState(int networkId, int state, bool bSetOther = false); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.cpp index 5c30e93e6..7d05bcda9 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.cpp @@ -96,6 +96,11 @@ bool WifiCommonEventHelper::PublishEvent(const std::string &eventAction, const s return true; } +bool WifiCommonEventHelper::PublishWifi2PowerStateChangeEvent(const int &code, const std::string &data) +{ + return WifiCommonEventHelper::PublishEvent(COMMON_EVENT_WIFI2_POWER_STATE, code, data); +} + bool WifiCommonEventHelper::PublishPowerStateChangeEvent(const int &code, const std::string &data) { return WifiCommonEventHelper::PublishEvent(COMMON_EVENT_WIFI_POWER_STATE, code, data); @@ -122,6 +127,11 @@ bool WifiCommonEventHelper::PublishWiTasRssiValueChangedEvent(const int &code, c return WifiCommonEventHelper::PublishEvent(COMMON_EVENT_WITAS_RSSI_VALUE, code, data); } +bool WifiCommonEventHelper::PublishWifi2ConnStateChangedEvent(const int &code, const std::string &data) +{ + return WifiCommonEventHelper::PublishEvent(COMMON_EVENT_WIFI2_CONN_STATE, code, data); +} + bool WifiCommonEventHelper::PublishConnStateChangedEvent(const int &code, const std::string &data) { return WifiCommonEventHelper::PublishEvent(COMMON_EVENT_WIFI_CONN_STATE, code, data); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.h b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.h index e6b75bd2b..618a965d0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.h @@ -21,18 +21,21 @@ namespace OHOS { namespace Wifi { inline const std::string COMMON_EVENT_WIFI_POWER_STATE = "usual.event.wifi.POWER_STATE"; +inline const std::string COMMON_EVENT_WIFI2_POWER_STATE = "usual.event.wifi.WIFI2_POWER_STATE"; inline const std::string COMMON_EVENT_WIFI_SCAN_FINISHED = "usual.event.wifi.SCAN_FINISHED"; inline const std::string COMMON_EVENT_WIFI_SCAN_STATE = "usual.event.wifi.SCAN_STATE"; inline const std::string COMMON_EVENT_WIFI_RSSI_VALUE = "usual.event.wifi.RSSI_VALUE"; inline const std::string COMMON_EVENT_WITAS_RSSI_VALUE = "usual.event.wifi.WITAS_RSSI_VALUE"; inline const std::string COMMON_EVENT_WIFI_CONN_STATE = "usual.event.wifi.CONN_STATE"; +inline const std::string COMMON_EVENT_WIFI2_CONN_STATE = "usual.event.wifi.WIFI2_CONN_STATE"; inline const std::string COMMON_EVENT_WIFI_HOTSPOT_STATE = "usual.event.wifi.HOTSPOT_STATE"; inline const std::string COMMON_EVENT_WIFI_AP_STA_JOIN = "usual.event.wifi.WIFI_HS_STA_JOIN"; inline const std::string COMMON_EVENT_WIFI_AP_STA_LEAVE = "usual.event.wifi.WIFI_HS_STA_LEAVE"; inline const std::string COMMON_EVENT_WIFI_MPLINK_STATE = "usual.event.wifi.mplink.STATE_CHANGE"; inline const std::string COMMON_EVENT_WIFI_P2P_CONN_STATE = "usual.event.wifi.p2p.CONN_STATE_CHANGE"; inline const std::string COMMON_EVENT_WIFI_P2P_STATE_CHANGED = "usual.event.wifi.p2p.STATE_CHANGE"; -inline const std::string COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED = "usual.event.wifi.p2p.DEVICES_CHANGE"; +inline const std::string COMMON_EVENT_WIFI_P2P_PEERS_STATE_CHANGED = + "usual.event.wifi.p2p.DEVICES_CHANGE"; inline const std::string COMMON_EVENT_WIFI_P2P_PEERS_DISCOVERY_STATE_CHANGED = "usual.event.wifi.p2p.PEER_DISCOVERY_STATE_CHANGE"; inline const std::string COMMON_EVENT_WIFI_P2P_CURRENT_DEVICE_STATE_CHANGED = @@ -52,12 +55,14 @@ public: static bool PublishEvent(const std::string &eventAction, const std::string ¶mKey, T paramValue, const int &code, const std::string &data); static bool PublishPowerStateChangeEvent(const int &code, const std::string &data); + static bool PublishWifi2PowerStateChangeEvent(const int &code, const std::string &data); static bool PublishScanFinishedEvent(const int &code, const std::string &data); static bool PublishScanStateChangedEvent(const int &code, const std::string &data); static bool PublishRssiValueChangedEvent(const std::string &pramKey, int paramValue, const int &code, const std::string &data); static bool PublishWiTasRssiValueChangedEvent(const int &code, const std::string &data); static bool PublishConnStateChangedEvent(const int &code, const std::string &data); + static bool PublishWifi2ConnStateChangedEvent(const int &code, const std::string &data); static bool PublishHotspotStateChangedEvent(const int &code, const std::string &data); static bool PublishApStaJoinEvent(const int &code, const std::string &data); static bool PublishApStaLeaveEvent(const int &code, const std::string &data); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_randommac_helper.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_randommac_helper.cpp index e7adfb715..535a948c1 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_randommac_helper.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_randommac_helper.cpp @@ -33,6 +33,9 @@ const unsigned long long MAC_ADDRESS_MULTICAST_MASK = 1ULL << 40; constexpr int MAX_MAC_SIZE = 18; constexpr int LONG_TO_BYTE_SIZE = 8; constexpr int MAC_ADDRESS_ETHER_ADDR_LEN = 6; +constexpr unsigned int WIFI2_RANDOM_MAC_CHANGE_POS = 9; +constexpr unsigned int WIFI2_RANDOM_MAC_CHANGE_LEN = 2; +constexpr unsigned int WIFI2_RANDOM_MAC_MASK = 0x80; constexpr int OFFSET_VALUE_56 = 56; constexpr int OFFSET_VALUE_48 = 48; @@ -268,5 +271,24 @@ int WifiRandomMacHelper::GenerateRandomMacAddressByLong(unsigned long long rando lngAddr, MacAnonymize(randomMacAddr).c_str()); return ret; } + +bool WifiRandomMacHelper::GetWifi2RandomMac(std::string &wifi2RandomMac) +{ + std::string inputStrMac = wifi2RandomMac.substr(WIFI2_RANDOM_MAC_CHANGE_POS, WIFI2_RANDOM_MAC_CHANGE_LEN); + std::stringstream inputSsMac; + inputSsMac << std::hex <> inputHexMac) { + WIFI_LOGD("%{public}s conver pos 3 mac to hex success", __func__); + } else { + WIFI_LOGE("%{public}s conver pos 3 mac to hex fail", __func__); + } + unsigned int outputHexMac = inputHexMac ^ WIFI2_RANDOM_MAC_MASK; + std::stringstream outSsMac; + outSsMac << std::hex < &bytes); + + /** + * @Description change random mac for wifi2 + *for example, input mac is 00:1a:2b:3c:4d:5e, this func will change pos 3 byte mac from "3c" to "bc" by + *performing an XOR operation with 0x80 + * @param wifi2RandomMac - wifi2RandomMac + */ + static bool GetWifi2RandomMac(std::string &wifi2RandomMac); }; } } diff --git a/wifi/test/wifi_standard/precompiled_macro/BUILD.gn b/wifi/test/wifi_standard/precompiled_macro/BUILD.gn index 7c140fc68..a08966c17 100644 --- a/wifi/test/wifi_standard/precompiled_macro/BUILD.gn +++ b/wifi/test/wifi_standard/precompiled_macro/BUILD.gn @@ -112,7 +112,11 @@ ohos_unittest("precompiled_macro_unittest") { deps = [ "$WIFI_ROOT_DIR/base:wifi_base", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_device_ability", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_hotspot_ability", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_ability", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit", "$WIFI_ROOT_DIR/utils:wifi_utils", "//third_party/googletest:gmock_main", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/hal_device_manage_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/hal_device_manage_test.cpp index 9ed605c82..6084b94f1 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/hal_device_manage_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/hal_device_manage_test.cpp @@ -32,11 +32,13 @@ void WifiHalDeviceManagerTest::OnRssiReportCallback(int index, int antRssi) HWTEST_F(WifiHalDeviceManagerTest, ScanTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); ScanParams scanParams; DelayedSingleton::GetInstance()->Scan(ifaceName, scanParams); } @@ -44,11 +46,13 @@ HWTEST_F(WifiHalDeviceManagerTest, ScanTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, StartPnoScanTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); PnoScanParams pnoScanParams; DelayedSingleton::GetInstance()->StartPnoScan(ifaceName, pnoScanParams); } @@ -56,22 +60,26 @@ HWTEST_F(WifiHalDeviceManagerTest, StartPnoScanTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, StopPnoScanTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); DelayedSingleton::GetInstance()->StopPnoScan(ifaceName); } HWTEST_F(WifiHalDeviceManagerTest, GetScanInfosTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); std::vector scanResultsInfo; DelayedSingleton::GetInstance()->GetScanInfos(ifaceName, scanResultsInfo); } @@ -79,11 +87,13 @@ HWTEST_F(WifiHalDeviceManagerTest, GetScanInfosTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, GetConnectSignalInfoTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); SignalPollResult signalPollResult; DelayedSingleton::GetInstance()->GetConnectSignalInfo(ifaceName, signalPollResult); } @@ -91,11 +101,13 @@ HWTEST_F(WifiHalDeviceManagerTest, GetConnectSignalInfoTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, SetPmModeTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); int mode = 0; DelayedSingleton::GetInstance()->SetPmMode(ifaceName, mode); } @@ -103,11 +115,13 @@ HWTEST_F(WifiHalDeviceManagerTest, SetPmModeTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, SetDpiMarkRuleTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); int uid = 0; int protocol = 0; int enable = 0; @@ -117,11 +131,13 @@ HWTEST_F(WifiHalDeviceManagerTest, SetDpiMarkRuleTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, SetStaMacAddressTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); std::string mac{"12:34:56:78:90:AB"}; DelayedSingleton::GetInstance()->SetStaMacAddress(ifaceName, mac); } @@ -145,11 +161,13 @@ HWTEST_F(WifiHalDeviceManagerTest, GetChipsetCategoryTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, GetChipsetWifiFeatrureCapabilityTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); int chipsetFeatrureCapability = 0; DelayedSingleton::GetInstance()->GetChipsetWifiFeatrureCapability( ifaceName, chipsetFeatrureCapability); @@ -158,9 +176,12 @@ HWTEST_F(WifiHalDeviceManagerTest, GetChipsetWifiFeatrureCapabilityTest, TestSiz HWTEST_F(WifiHalDeviceManagerTest, GetFrequenciesByBandTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateApIface( - std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), ifaceName); + std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), + ifaceName, + instId); int32_t band = 0; std::vector frequencies; DelayedSingleton::GetInstance()->GetFrequenciesByBand(ifaceName, band, frequencies); @@ -168,7 +189,8 @@ HWTEST_F(WifiHalDeviceManagerTest, GetFrequenciesByBandTest, TestSize.Level1) DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); DelayedSingleton::GetInstance()->GetFrequenciesByBand(ifaceName, band, frequencies); } @@ -195,6 +217,7 @@ HWTEST_F(WifiHalDeviceManagerTest, GetPowerModelTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, SetWifiCountryCodeTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateApIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), ifaceName); @@ -204,7 +227,8 @@ HWTEST_F(WifiHalDeviceManagerTest, SetWifiCountryCodeTest, TestSize.Level1) DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); code = "CN"; DelayedSingleton::GetInstance()->SetWifiCountryCode(ifaceName, code); } @@ -222,11 +246,13 @@ HWTEST_F(WifiHalDeviceManagerTest, SetApMacAddressTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, SelectInterfacesToDeleteTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); WifiChipInfo wifiChipInfo; DelayedSingleton::GetInstance()->GetChipInfo(0, wifiChipInfo); IfaceType ifaceType = IfaceType::STA; @@ -238,11 +264,13 @@ HWTEST_F(WifiHalDeviceManagerTest, SelectInterfacesToDeleteTest, TestSize.Level1 HWTEST_F(WifiHalDeviceManagerTest, CreateTheNeedChangeChipModeIfaceDataTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); UsableMode chipMode; IfaceCreationData ifaceCreationData; WifiChipInfo wifiChipInfo; @@ -260,11 +288,13 @@ HWTEST_F(WifiHalDeviceManagerTest, CreateTheNeedChangeChipModeIfaceDataTest, Tes HWTEST_F(WifiHalDeviceManagerTest, CompareIfaceCreationDataTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); WifiIfaceInfo ifaceInfo; IfaceCreationData data1; DelayedSingleton::GetInstance()->GetChipInfo(0, data1.chipInfo); @@ -290,11 +320,13 @@ HWTEST_F(WifiHalDeviceManagerTest, DispatchIfaceDestoryCallbackTest, TestSize.Le { IfaceType ifaceType = IfaceType::STA; std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); DelayedSingleton::GetInstance()->DispatchIfaceDestoryCallback( ifaceName, ifaceType, true, ifaceType); HalDeviceManager::g_chipHdiServiceDied = true; @@ -314,11 +346,13 @@ HWTEST_F(WifiHalDeviceManagerTest, DispatchIfaceDestoryCallbackTest, TestSize.Le HWTEST_F(WifiHalDeviceManagerTest, RemoveStaIfaceTest, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); DelayedSingleton::GetInstance()->RemoveStaIface(ifaceName); } @@ -343,11 +377,13 @@ HWTEST_F(WifiHalDeviceManagerTest, RemoveP2pIfaceTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, CreateStaIfaceTest, TestSize.Level1) { std::string ifaceName = "Wlan0"; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = false; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); bool result = DelayedSingleton::GetInstance()->RemoveStaIface(ifaceName); EXPECT_EQ(result, false); } @@ -375,11 +411,13 @@ HWTEST_F(WifiHalDeviceManagerTest, CreateApIfaceTest, TestSize.Level1) HWTEST_F(WifiHalDeviceManagerTest, ScanTest_01, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = true; DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); ScanParams scanParams; HalDeviceManager::g_chipHdiServiceDied = false; DelayedSingleton::GetInstance()->Scan(ifaceName, scanParams); @@ -427,12 +465,14 @@ HWTEST_F(WifiHalDeviceManagerTest, GetChipsetWifiFeatrureCapabilityTest_01, Test HWTEST_F(WifiHalDeviceManagerTest, GetScanInfosTest_01, TestSize.Level1) { std::string ifaceName; + int instId = 0; HalDeviceManager::g_chipHdiServiceDied = false; DelayedSingleton::GetInstance()->ResetHalDeviceManagerInfo(false); DelayedSingleton::GetInstance()->CreateStaIface( std::bind(WifiHalDeviceManagerTest::DestoryCallback, std::placeholders::_1, std::placeholders::_2), std::bind(WifiHalDeviceManagerTest::OnRssiReportCallback, std::placeholders::_1, std::placeholders::_2), - ifaceName); + ifaceName, + instId); std::vector scanResultsInfo; DelayedSingleton::GetInstance()->GetScanInfos(ifaceName, scanResultsInfo); } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_idl_inner_interface_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_idl_inner_interface_test.cpp index db0daf990..9e8c94d26 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_idl_inner_interface_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_idl_inner_interface_test.cpp @@ -344,12 +344,13 @@ HWTEST_F(WifiIdlInnerInterfaceTest, OnConnectChangedTest, TestSize.Level1) char *mac = nullptr; OnConnectChanged(status, networkId, mac); char mac1[] = "00:00:AA:BB:CC:DD"; + std::string ifaceName = "wlan0"; WifiEventCallback callback; RegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnConnectChanged(status, networkId, mac1); UnRegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnConnectChanged(status, networkId, mac1); } @@ -366,12 +367,13 @@ HWTEST_F(WifiIdlInnerInterfaceTest, OnDisConnectReasonCallbackTest, TestSize.Lev char *mac = nullptr; OnDisConnectReasonCallback(reason, mac); char mac1[] = "00:00:AA:BB:CC:DD"; + std::string ifaceName = "wlan0"; WifiEventCallback callback; RegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnDisConnectReasonCallback(reason, mac1); UnRegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnDisConnectReasonCallback(reason, mac1); } @@ -391,11 +393,12 @@ HWTEST_F(WifiIdlInnerInterfaceTest, OnBssidChangedTest, TestSize.Level1) OnBssidChanged(reason, bss); char bssid[] = "00:00:AA:BB:CC:DD"; WifiEventCallback callback; + std::string ifaceName = "wlan0"; RegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnBssidChanged(reason, bssid); UnRegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnBssidChanged(reason, bssid); } /** @@ -410,7 +413,8 @@ HWTEST_F(WifiIdlInnerInterfaceTest, OnWpaStateChangedTest, TestSize.Level1) int status = 1; WifiEventCallback callback; RegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + std::string ifaceName = "wlan0"; + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnWpaStateChanged(status); OnWpaSsidWrongKey(); OnWpaConnectionFull(status); @@ -418,7 +422,7 @@ HWTEST_F(WifiIdlInnerInterfaceTest, OnWpaStateChangedTest, TestSize.Level1) OnWpsOverlap(status); OnWpsTimeOut(status); UnRegisterStaCallbackMock(&callback); - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); OnWpaStateChanged(status); OnWpaSsidWrongKey(); OnWpaConnectionFull(status); diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_sta_hal_interface_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_sta_hal_interface_test.cpp index 90dfae118..f78e18dd3 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_sta_hal_interface_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest/wifi_sta_hal_interface_test.cpp @@ -61,7 +61,7 @@ void WifiStaHalInterfaceTest::SetUpTestCase() callback.onWpaSsidWrongKey = OnWpaSsidWrongKey; callback.onWpsOverlap = OnWpsOverlap; callback.onWpsTimeOut = OnWpsTimeOut; - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); SupplicantEventCallback cbk; cbk.onScanNotify = OnScanNotify; @@ -71,7 +71,8 @@ void WifiStaHalInterfaceTest::SetUpTestCase() void WifiStaHalInterfaceTest::TearDownTestCase() { WifiEventCallback callback; - WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback); + std::string ifaceName = "wlan0"; + WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callback, ifaceName); WifiSupplicantHalInterface::GetInstance().UnRegisterSupplicantEventCallback(); } @@ -83,7 +84,8 @@ HWTEST_F(WifiStaHalInterfaceTest, StartWifiTest, TestSize.Level1) HWTEST_F(WifiStaHalInterfaceTest, ConnectTest, TestSize.Level1) { - WifiErrorNo ret = WifiStaHalInterface::GetInstance().Connect(1); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().Connect(1, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); } @@ -101,7 +103,8 @@ HWTEST_F(WifiStaHalInterfaceTest, ReassociateTest, TestSize.Level1) HWTEST_F(WifiStaHalInterfaceTest, DisconnectTest, TestSize.Level1) { - WifiErrorNo ret = WifiStaHalInterface::GetInstance().Disconnect(); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().Disconnect(ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_OK); } @@ -115,7 +118,8 @@ HWTEST_F(WifiStaHalInterfaceTest, GetStaCapabilitiesTest, TestSize.Level1) HWTEST_F(WifiStaHalInterfaceTest, GetStaDeviceMacAddressTest, TestSize.Level1) { std::string mac; - WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(mac); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(mac, ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_OK); } @@ -224,26 +228,30 @@ HWTEST_F(WifiStaHalInterfaceTest, RemoveDeviceConfigTest, TestSize.Level1) HWTEST_F(WifiStaHalInterfaceTest, ClearDeviceConfigTest, TestSize.Level1) { - WifiErrorNo ret = WifiStaHalInterface::GetInstance().ClearDeviceConfig(); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().ClearDeviceConfig(ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_OK); } HWTEST_F(WifiStaHalInterfaceTest, GetNextNetworkIdTest, TestSize.Level1) { int id = 0; - WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetNextNetworkId(id); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetNextNetworkId(id, ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_OK); } HWTEST_F(WifiStaHalInterfaceTest, EnableNetworkTest, TestSize.Level1) { - WifiErrorNo ret = WifiStaHalInterface::GetInstance().EnableNetwork(1); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().EnableNetwork(1, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); } HWTEST_F(WifiStaHalInterfaceTest, DisableNetworkTest, TestSize.Level1) { - WifiErrorNo ret = WifiStaHalInterface::GetInstance().DisableNetwork(1); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().DisableNetwork(1, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); } @@ -251,35 +259,37 @@ HWTEST_F(WifiStaHalInterfaceTest, SetDeviceConfigTest, TestSize.Level1) { WifiHalDeviceConfig cfg; cfg.psk = "1234567"; + std::string ifaceName = "wlan0"; WifiErrorNo ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); EXPECT_TRUE(ret == WIFI_HAL_OPT_FAILED); cfg.psk = "01234567890123456789012345678901234567890123456789012345678901234"; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_FAILED); cfg.psk = "12345678"; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); cfg.authAlgorithms = 8; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_TRUE(ret == WIFI_HAL_OPT_FAILED); cfg.authAlgorithms = 7; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); cfg.ssid = "Honor"; cfg.priority = 5; cfg.scanSsid = 1; cfg.wepKeyIdx = 2; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); cfg.allowedGroupMgmtCiphers = 4; - ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg); + ret = WifiStaHalInterface::GetInstance().SetDeviceConfig(1, cfg, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); } HWTEST_F(WifiStaHalInterfaceTest, GetDeviceConfigTest, TestSize.Level1) { WifiHalGetDeviceConfig cfg; - WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetDeviceConfig(cfg); + std::string ifaceName = "wlan0"; + WifiErrorNo ret = WifiStaHalInterface::GetInstance().GetDeviceConfig(cfg, ifaceName); EXPECT_FALSE(ret == WIFI_HAL_OPT_OK); } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn index 4e8e679b7..6def8415a 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/BUILD.gn @@ -57,6 +57,8 @@ ohos_unittest("manager_unittest") { "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_system_timer.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_clientmode_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/BUILD.gn index d91bc2cb2..82c454b39 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/BUILD.gn @@ -28,6 +28,8 @@ ohos_unittest("wifi_controller_unittest") { "$WIFI_ROOT_DIR/frameworks/native/src/network_selection.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_clientmode_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine_test.cpp index 23d2c17d6..a77390004 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine_test.cpp @@ -84,8 +84,9 @@ public: void WifiToggledTest1() { + int instId = 0; InternalMessagePtr msg = std::make_shared(); - WifiConfigCenter::GetInstance().SetWifiToggledState(false); + WifiConfigCenter::GetInstance().SetWifiToggledState(false, instId); WifiSettings::GetInstance().SetScanOnlySwitchState(0, 0); WifiConfigCenter::GetInstance().SetWifiStopState(true); msg->SetMessageName(CMD_WIFI_TOGGLED); @@ -101,8 +102,9 @@ public: void WifiToggledTest2() { + int instId = 0; InternalMessagePtr msg = std::make_shared(); - WifiConfigCenter::GetInstance().SetWifiToggledState(false); + WifiConfigCenter::GetInstance().SetWifiToggledState(false, instId); WifiSettings::GetInstance().SetScanOnlySwitchState(0, 0); WifiConfigCenter::GetInstance().SetWifiStopState(true); msg->SetMessageName(CMD_WIFI_TOGGLED); @@ -120,8 +122,9 @@ public: void HandleStaStartFail() { + int instId = 0; InternalMessagePtr msg = std::make_shared(); - WifiConfigCenter::GetInstance().SetWifiToggledState(false); + WifiConfigCenter::GetInstance().SetWifiToggledState(false, instId); WifiSettings::GetInstance().SetScanOnlySwitchState(0, 0); WifiConfigCenter::GetInstance().SetWifiStopState(true); msg->SetMessageName(CMD_STA_START_FAILURE); @@ -295,6 +298,7 @@ public: void ConcreteIdExistTest() { + int instId = 0; ConcreteClientModeManager *clientmode = new (std::nothrow) ConcreteClientModeManager(ConcreteManagerRole::ROLE_CLIENT_STA, 0); clientmode->pConcreteMangerMachine = new MockConcreteMangerMachine(); @@ -310,13 +314,13 @@ public: pWifiControllerMachine->HandleStaSemiActive(0); pWifiControllerMachine->HandleStaClose(0); pWifiControllerMachine->SwitchRole(ConcreteManagerRole::ROLE_CLIENT_SCAN_ONLY); - WifiConfigCenter::GetInstance().SetWifiToggledState(1); - EXPECT_TRUE(pWifiControllerMachine->ShouldEnableWifi()); + WifiConfigCenter::GetInstance().SetWifiToggledState(1, instId); + EXPECT_TRUE(pWifiControllerMachine->ShouldEnableWifi(instId)); InternalMessagePtr msg = std::make_shared(); msg->SetMessageName(CMD_WIFI_TOGGLED); msg->SetParam2(0); EXPECT_FALSE(pWifiControllerMachine->ShouldDisableWifi(msg)); - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED); + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED, instId); WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATED, 0); EXPECT_TRUE(pWifiControllerMachine->ShouldDisableWifi(msg)); pWifiControllerMachine->RemoveConcreteManager(1); @@ -326,6 +330,7 @@ public: void GetWifiRoleTest() { + int instId = 0; pWifiControllerMachine->GetWifiRole(); } }; @@ -467,11 +472,12 @@ HWTEST_F(WifiControllerMachineTest, GetWifiRoleTest, TestSize.Level1) HWTEST_F(WifiControllerMachineTest, HandleApStopTest, TestSize.Level1) { + int instId = 0; InternalMessagePtr msg = std::make_shared(); msg->SetMessageName(CMD_AP_STOPPED); msg->SetParam1(0); WifiConfigCenter::GetInstance().SetSoftapToggledState(false); - WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_DISABLED); + WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_DISABLED, instId); pWifiControllerMachine->pEnableState->HandleApStop(msg); } } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl_test.cpp index 9c92863aa..f5c6718e4 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/hdi_interface/wifi_hdi_wpa_sta_impl_test.cpp @@ -33,46 +33,53 @@ public: HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaStartTest_01, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaStart(nullptr); + WifiErrorNo result = HdiWpaStaStart(nullptr, 0); + int instId = 0; + std::string ifaceName = "wlan0"; EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); - result = HdiWpaStaStart("wlan0"); + result = HdiWpaStaStart(ifaceName.c_str(), instId); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaStopTest_01, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaStop(); + int instId = 0; + WifiErrorNo result = HdiWpaStaStop(instId); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaConnectTest, TestSize.Level1) { int networkId = 1; - WifiErrorNo result = HdiWpaStaConnect(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaConnect(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaAddNetworkTest, TestSize.Level1) { int *networkId = nullptr; - WifiErrorNo result = HdiWpaStaAddNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaAddNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); int workld = 1; - result = HdiWpaStaAddNetwork(&workld); + result = HdiWpaStaAddNetwork(&workld, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaDisableNetworkTest, TestSize.Level1) { int networkId = 1; - WifiErrorNo result = HdiWpaStaDisableNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaDisableNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaSaveConfigTest, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaSaveConfig(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaSaveConfig(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -80,29 +87,32 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaStartWpsPinModeTest, TestSize.Level1) { WifiWpsParam config; int pinCode; - WifiErrorNo result = HdiWpaStaStartWpsPinMode(nullptr, &pinCode); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaStartWpsPinMode(nullptr, &pinCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); - result = HdiWpaStaStartWpsPinMode(&config, nullptr); + result = HdiWpaStaStartWpsPinMode(&config, nullptr, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); - result = HdiWpaStaStartWpsPinMode(nullptr, nullptr); + result = HdiWpaStaStartWpsPinMode(nullptr, nullptr, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); - result = HdiWpaStaStartWpsPinMode(&config, &pinCode); + result = HdiWpaStaStartWpsPinMode(&config, &pinCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaStartWpsPbcModeTest, TestSize.Level1) { WifiWpsParam config; - WifiErrorNo result = HdiWpaStaStartWpsPbcMode(nullptr); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaStartWpsPbcMode(nullptr, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); - result = HdiWpaStaStartWpsPbcMode(&config); + result = HdiWpaStaStartWpsPbcMode(&config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaSetCountryCodeTest, TestSize.Level1) { char countryCode[10] = "CN"; - WifiErrorNo result = HdiWpaStaSetCountryCode(countryCode); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaSetCountryCode(countryCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -110,14 +120,16 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaGetCountryCodeTest, TestSize.Level1) { char countryCode[2]; uint32_t size = 2; - WifiErrorNo result = HdiWpaStaGetCountryCode(countryCode, size); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaGetCountryCode(countryCode, size, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaSetSuspendModeTest, TestSize.Level1) { int mode = 1; - WifiErrorNo result = HdiWpaStaSetSuspendMode(mode); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaSetSuspendMode(mode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -125,7 +137,8 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaListNetworksTest, TestSize.Level1) { struct HdiWifiWpaNetworkInfo networkList[10]; uint32_t size = 10; - WifiErrorNo result = HdiWpaListNetworks(networkList, &size); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaListNetworks(networkList, &size, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -135,7 +148,8 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaGetNetworkTest, TestSize.Level1) const char *param = "param"; char value[10]; uint32_t valueLen = 10; - WifiErrorNo result = HdiWpaGetNetwork(networkId, param, value, valueLen); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaGetNetwork(networkId, param, value, valueLen, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -159,26 +173,30 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaGetPskPassphraseTest, TestSize.Level1) HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaSetPowerSaveTest, TestSize.Level1) { int enable = true; - WifiErrorNo result = HdiWpaStaSetPowerSave(enable); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaSetPowerSave(enable, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaBlocklistClearTest, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaBlocklistClear(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaBlocklistClear(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaAutoConnectTest, TestSize.Level1) { int enable = true; - WifiErrorNo result = HdiWpaStaAutoConnect(enable); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaAutoConnect(enable, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiStopWpsStaTest, TestSize.Level1) { - WifiErrorNo result = HdiStopWpsSta(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiStopWpsSta(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -186,21 +204,24 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaSetNetworkTest, TestSize.Level1) { int networkId = 1; int size = 1; - WifiErrorNo result = HdiWpaStaSetNetwork(networkId, nullptr, size); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaSetNetwork(networkId, nullptr, size, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaEnableNetworkTest, TestSize.Level1) { int networkId = 2; - WifiErrorNo result = HdiWpaStaEnableNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaEnableNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaRemoveNetworkTest, TestSize.Level1) { int networkId = 3; - WifiErrorNo result = HdiWpaStaRemoveNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaRemoveNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -214,10 +235,11 @@ HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaGetDeviceMacAddressTest, TestSize.Level { char macAddr[18] = {0}; int macAddrLen = 0; - WifiErrorNo result = HdiWpaStaGetDeviceMacAddress(nullptr, macAddrLen); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaGetDeviceMacAddress(nullptr, macAddrLen, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); - result = HdiWpaStaGetDeviceMacAddress(macAddr, macAddrLen); + result = HdiWpaStaGetDeviceMacAddress(macAddr, macAddrLen, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -313,33 +335,38 @@ HWTEST_F(WifiHdiWpaStaImplTest, ConvertMacToStrSuccess, TestSize.Level1) HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaDisconnectTest, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaDisconnect(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaDisconnect(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaReassociateTest, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaReassociate(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaReassociate(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaReconnectTest, TestSize.Level1) { - WifiErrorNo result = HdiWpaStaReconnect(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = HdiWpaStaReconnect(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaGetScanInfosTest, TestSize.Level1) { int *size = nullptr; - ScanInfo *result = HdiWpaStaGetScanInfos(size); + std::string ifaceName = "wlan0"; + ScanInfo *result = HdiWpaStaGetScanInfos(size, ifaceName.c_str()); EXPECT_EQ(result, NULL); } HWTEST_F(WifiHdiWpaStaImplTest, HdiWpaStaGetScanInfosTest1, TestSize.Level1) { int size = 1; - ScanInfo *result = HdiWpaStaGetScanInfos(&size); + std::string ifaceName = "wlan0"; + ScanInfo *result = HdiWpaStaGetScanInfos(&size, ifaceName.c_str()); EXPECT_EQ(result, NULL); } } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client_test.cpp index b604bc0d6..637179a4a 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/hdi_client/wifi_hdi_wpa_client_test.cpp @@ -40,38 +40,45 @@ public: HWTEST_F(WifiHdiWpaClientTest, StartWifi, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->StartWifi("wlan"); + std::string ifaceName = "wlan0"; + int instId = 0; + WifiErrorNo result = wifiHdiWpaClient->StartWifi(ifaceName.c_str(), instId); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaClientTest, ReqConnect, TestSize.Level1) { int networkId = 111; - WifiErrorNo result = wifiHdiWpaClient->ReqConnect(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqConnect(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, StopWifi, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->StopWifi(); + int instId = 0; + WifiErrorNo result = wifiHdiWpaClient->StopWifi(instId); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaClientTest, ReqReconnect, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ReqReconnect(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqReconnect(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqReassociate, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ReqReassociate(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqReassociate(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqDisconnect, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ReqDisconnect(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqDisconnect(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -87,10 +94,11 @@ HWTEST_F(WifiHdiWpaClientTest, GetStaDeviceMacAddress, TestSize.Level1) { std::string macAddress = "00:11:22:33:44:55"; std::string result; - WifiErrorNo error = wifiHdiWpaClient->GetStaDeviceMacAddress(result); + std::string ifaceName = "wlan0"; + WifiErrorNo error = wifiHdiWpaClient->GetStaDeviceMacAddress(result, ifaceName.c_str()); EXPECT_EQ(error, WIFI_HAL_OPT_FAILED); - error = wifiHdiWpaClient->GetStaDeviceMacAddress(macAddress); + error = wifiHdiWpaClient->GetStaDeviceMacAddress(macAddress, ifaceName.c_str()); EXPECT_EQ(error, WIFI_HAL_OPT_FAILED); } @@ -137,37 +145,42 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStopPnoScan, TestSize.Level1) HWTEST_F(WifiHdiWpaClientTest, RemoveDevice, TestSize.Level1) { int networkId = 222; - WifiErrorNo result = wifiHdiWpaClient->RemoveDevice(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->RemoveDevice(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); - result = wifiHdiWpaClient->RemoveDevice(-1); + result = wifiHdiWpaClient->RemoveDevice(-1, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); } HWTEST_F(WifiHdiWpaClientTest, GetNextNetworkId, TestSize.Level1) { int networkId; - WifiErrorNo result = wifiHdiWpaClient->GetNextNetworkId(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->GetNextNetworkId(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); EXPECT_EQ(networkId, 0); } HWTEST_F(WifiHdiWpaClientTest, ClearDeviceConfig, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ClearDeviceConfig(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ClearDeviceConfig(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqEnableNetwork, TestSize.Level1) { int networkId = 333; - WifiErrorNo result = wifiHdiWpaClient->ReqEnableNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqEnableNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqDisableNetwork, TestSize.Level1) { int networkId = 444; - WifiErrorNo result = wifiHdiWpaClient->ReqDisableNetwork(networkId); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqDisableNetwork(networkId, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -176,17 +189,18 @@ HWTEST_F(WifiHdiWpaClientTest, SetDeviceConfigTest, TestSize.Level1) int networkId = 555; WifiHalDeviceConfig config; config.psk = ""; - WifiErrorNo result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.psk = "12345"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.psk = "1234567891011121314151617181920abcdefdhigklmnopqrst123456789101112131415"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.psk = "12345678910"; config.authAlgorithms = 10; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.ssid = "TestSSID"; @@ -195,26 +209,26 @@ HWTEST_F(WifiHdiWpaClientTest, SetDeviceConfigTest, TestSize.Level1) config.priority = 1; SetNetworkConfig expectedConfig[DEVICE_CONFIG_END_POS]; memcpy_s(expectedConfig, sizeof(expectedConfig), 0, sizeof(expectedConfig)); - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.keyMgmt = "SAE"; config.eapConfig.eap = "NONE"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.keyMgmt = "NONE"; config.eapConfig.eap = "TLS"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.keyMgmt = "WEP"; config.eapConfig.eap = "TTLS"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); config.keyMgmt = "WAPI"; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -223,46 +237,47 @@ HWTEST_F(WifiHdiWpaClientTest, SetDeviceConfigTest1, TestSize.Level1) int networkId = 555; WifiHalDeviceConfig config; config.priority = -1; - WifiErrorNo result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.priority = 1; config.scanSsid = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.scanSsid = 2; config.wepKeyIdx = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.wepKeyIdx = -1; config.authAlgorithms = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.authAlgorithms = 0; config.isRequirePmf = true; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.allowedProtocols = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.allowedProtocols = -1; config.allowedPairwiseCiphers = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.allowedPairwiseCiphers = 0; config.allowedGroupCiphers = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); config.allowedGroupCiphers = 0; config.allowedGroupMgmtCiphers = 1; - result = wifiHdiWpaClient->SetDeviceConfig(networkId, config); + result = wifiHdiWpaClient->SetDeviceConfig(networkId, config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -270,28 +285,32 @@ HWTEST_F(WifiHdiWpaClientTest, SetBssid, TestSize.Level1) { int networkId = 666; std::string bssid = "00:11:22:33:44:55"; - + std::string ifaceName = "wlan0"; SetNetworkConfig expectedConfig; memset_s(&expectedConfig, sizeof(expectedConfig), 0, sizeof(expectedConfig)); - WifiErrorNo result = wifiHdiWpaClient->SetBssid(networkId, bssid); + WifiErrorNo result = wifiHdiWpaClient->SetBssid(networkId, bssid, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); bssid = ""; - result = wifiHdiWpaClient->SetBssid(networkId, bssid); + result = wifiHdiWpaClient->SetBssid(networkId, bssid, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, SaveDeviceConfig, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->SaveDeviceConfig(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->SaveDeviceConfig(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqRegisterStaEventCallbackTEST, TestSize.Level1) { + int instId = 0; + std::string ifaceName = "wlan0"; WifiEventCallback *wifiEventCallbackMock = new WifiEventCallback(); - WifiErrorNo result = wifiHdiWpaClient->ReqRegisterStaEventCallback(*wifiEventCallbackMock); + WifiErrorNo result = + wifiHdiWpaClient->ReqRegisterStaEventCallback(*wifiEventCallbackMock, ifaceName.c_str(), instId); EXPECT_EQ(result, WIFI_HAL_OPT_INVALID_PARAM); delete wifiEventCallbackMock; } @@ -302,12 +321,13 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStartWpsPbcModeTEST, TestSize.Level1) config.anyFlag = true; config.multiAp = false; config.bssid = "00:11:22:33:44:55"; + std::string ifaceName = "wlan0"; WifiWpsParam expectedParam; memset_s(&expectedParam, sizeof(expectedParam), 0, sizeof(expectedParam)); expectedParam.anyFlag = true; expectedParam.multiAp = false; strncpy_s(expectedParam.bssid, sizeof(expectedParam.bssid), config.bssid.c_str(), sizeof(expectedParam.bssid) - 1); - WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPbcMode(config); + WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPbcMode(config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -317,7 +337,8 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStartWpsPbcModeTest, TestSize.Level1) config.anyFlag = true; config.multiAp = false; config.bssid = ""; - WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPbcMode(config); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPbcMode(config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -328,6 +349,7 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStartWpsPinModeTEST, TestSize.Level1) config.multiAp = false; config.bssid = "00:11:22:33:44:55"; config.pinCode = "12345678"; + std::string ifaceName = "wlan0"; WifiWpsParam expectedParam; memset_s(&expectedParam, sizeof(expectedParam), 0, sizeof(expectedParam)); expectedParam.anyFlag = config.anyFlag; @@ -336,7 +358,7 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStartWpsPinModeTEST, TestSize.Level1) strncpy_s(expectedParam.pinCode, sizeof(expectedParam.pinCode), config.pinCode.c_str(), sizeof(expectedParam.pinCode) - 1); int pinCode; - WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPinMode(config, pinCode); + WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPinMode(config, pinCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -346,14 +368,16 @@ HWTEST_F(WifiHdiWpaClientTest, ReqStartWpsPinModeTest, TestSize.Level1) config.anyFlag = true; config.multiAp = false; config.bssid = ""; + std::string ifaceName = "wlan0"; int pinCode; - WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPinMode(config, pinCode); + WifiErrorNo result = wifiHdiWpaClient->ReqStartWpsPinMode(config, pinCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaClientTest, ReqStopWpsTEST, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ReqStopWps(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqStopWps(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -382,42 +406,48 @@ HWTEST_F(WifiHdiWpaClientTest, ReqGetConnectSignalInfoTEST, TestSize.Level1) HWTEST_F(WifiHdiWpaClientTest, ReqWpaAutoConnectTEST, TestSize.Level1) { int enable = 1; - WifiErrorNo result = wifiHdiWpaClient->ReqWpaAutoConnect(enable); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqWpaAutoConnect(enable, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqWpaBlocklistClearTEST, TestSize.Level1) { - WifiErrorNo result = wifiHdiWpaClient->ReqWpaBlocklistClear(); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqWpaBlocklistClear(ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqSetPowerSave, TestSize.Level1) { bool enable = true; - WifiErrorNo result = wifiHdiWpaClient->ReqSetPowerSave(enable); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqSetPowerSave(enable, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqWpaSetCountryCodeTEST, TestSize.Level1) { std::string countryCode = "US"; - WifiErrorNo result = wifiHdiWpaClient->ReqWpaSetCountryCode(countryCode); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqWpaSetCountryCode(countryCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } HWTEST_F(WifiHdiWpaClientTest, ReqWpaGetCountryCodeTEST, TestSize.Level1) { std::string expectedCountryCode = "US"; + std::string ifaceName = "wlan0"; std::string countryCode; - WifiErrorNo result = wifiHdiWpaClient->ReqWpaGetCountryCode(countryCode); + WifiErrorNo result = wifiHdiWpaClient->ReqWpaGetCountryCode(countryCode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } HWTEST_F(WifiHdiWpaClientTest, ReqWpaSetSuspendModeTEST, TestSize.Level1) { bool mode = true; - WifiErrorNo result = wifiHdiWpaClient->ReqWpaSetSuspendMode(mode); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->ReqWpaSetSuspendMode(mode, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } @@ -447,8 +477,9 @@ HWTEST_F(WifiHdiWpaClientTest, ReqWpaShellCmdTest2, TestSize.Level1) HWTEST_F(WifiHdiWpaClientTest, GetNetworkListTEST, TestSize.Level1) { + std::string ifaceName = "wlan0"; std::vector networkList; - WifiErrorNo result = wifiHdiWpaClient->GetNetworkList(networkList); + WifiErrorNo result = wifiHdiWpaClient->GetNetworkList(networkList, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_FAILED); } @@ -457,7 +488,8 @@ HWTEST_F(WifiHdiWpaClientTest, GetDeviceConfigTEST, TestSize.Level1) WifiHalGetDeviceConfig config; config.networkId = 777; config.param = "param"; - WifiErrorNo result = wifiHdiWpaClient->GetDeviceConfig(config); + std::string ifaceName = "wlan0"; + WifiErrorNo result = wifiHdiWpaClient->GetDeviceConfig(config, ifaceName.c_str()); EXPECT_EQ(result, WIFI_HAL_OPT_OK); } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn index 34f7ca398..ceb4852b3 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/BUILD.gn @@ -225,6 +225,8 @@ ohos_unittest("wifi_selfcure_unittest") { "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_system_ability_listerner.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_clientmode_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_new/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_new/BUILD.gn index 02e924094..4f1c0061c 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_new/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_new/BUILD.gn @@ -112,6 +112,14 @@ ohos_unittest("wifi_sta_new_unittest") { "//third_party/googletest:gtest_main", ] + deps += [ + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_device_ability", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_hotspot_ability", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_ability", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_service", + ] + ldflags = [ "-fPIC", "--coverage", diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp index 973e23331..ddbc1460e 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp @@ -61,7 +61,7 @@ int WifiServiceManager::CheckPreLoadService(void) return 0; } -int WifiServiceManager::LoadStaService(const std::string &dlname, bool bCreate) +int WifiServiceManager::LoadStaService(const std::string &dlname, int instId, bool bCreate) { WIFI_LOGI("LoadStaService"); return 0; @@ -103,7 +103,7 @@ int WifiServiceManager::LoadEnhanceService(const std::string &dlname, bool bCrea return 0; } -int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCreate) +int WifiServiceManager::CheckAndEnforceService(const std::string &name, int instId, bool bCreate) { WIFI_LOGD("WifiServiceManager::CheckAndEnforceService name: %{public}s", name.c_str()); return 0; diff --git a/wifi/wifi.gni b/wifi/wifi.gni index 9d93aac0c..09eea8ca9 100644 --- a/wifi/wifi.gni +++ b/wifi/wifi.gni @@ -22,7 +22,7 @@ declare_args() { wifi_feature_with_p2p = true wifi_feature_with_ap_intf = "wlan" wifi_feature_with_ap_num = 1 - wifi_feature_with_sta_num = 1 + wifi_feature_with_sta_num = 2 wifi_feature_with_auth_disable = false wifi_feature_with_dhcp_disable = false wifi_feature_with_encryption = true