From 9550eb54496c3a0ba58f95a63d92f7c489d39391 Mon Sep 17 00:00:00 2001 From: wangxiaoyun Date: Mon, 25 Sep 2023 18:39:53 -0700 Subject: [PATCH 1/4] fix bug: wifi roams fail when move to a stronger signal Signed-off-by: wangxiaoyun --- .../wifi_manage/wifi_sta/sta_auto_connect_service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp index 910a419a7..05ff0d82c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -260,7 +260,8 @@ bool StaAutoConnectService::ObtainRoamCapFromFirmware() if (WifiStaHalInterface::GetInstance().GetStaCapabilities(capabilities) == WIFI_IDL_OPT_OK) { if ((capabilities & STA_CAP_ROAMING) == 0) { WIFI_LOGE("Firmware roaming is not supported.\n"); - return false; + firmwareRoamFlag = false; + return false; } } -- Gitee From 15a8bf4544254ece973dddc16473d93f0740a595 Mon Sep 17 00:00:00 2001 From: wangxiaoyun Date: Mon, 16 Oct 2023 19:48:04 -0700 Subject: [PATCH 2/4] modify wifi random bug Signed-off-by: wangxiaoyun --- .../wifi_sta/sta_auto_connect_service.cpp | 15 ++++- .../wifi_manage/wifi_sta/sta_define.h | 1 + .../wifi_sta/sta_saved_device_appraisal.cpp | 3 +- .../wifi_sta/sta_state_machine.cpp | 57 +++++++++++++++++-- .../wifi_manage/wifi_sta/sta_state_machine.h | 16 ++++++ 5 files changed, 82 insertions(+), 10 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp index 05ff0d82c..bf78b9ae6 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -217,11 +217,20 @@ void StaAutoConnectService::ConnectElectedDevice(WifiDeviceConfig &electedDevice currentConnectedNetwork.detailedState == DetailedState::PASSWORD_ERROR || currentConnectedNetwork.detailedState == DetailedState::CONNECTION_FULL || currentConnectedNetwork.detailedState == DetailedState::CONNECTION_REJECT) { - pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, + if(electedDevice.userSelectBssid != electedDevice.bssid) { + pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK, + electedDevice.networkId, + NETWORK_SELECTED_BY_AUTO, + electedDevice.bssid); + WIFI_LOGI("connectTo same ssid, networkId: %{public}d, new bssid: %{public}s.\n", + electedDevice.networkId, electedDevice.bssid.c_str()); + } else { + pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, electedDevice.networkId, NETWORK_SELECTED_BY_AUTO); - WIFI_LOGI("connectTo save networkId: %{public}d, preShareKey len: %{public}d.\n", + WIFI_LOGI("connectTo save networkId: %{public}d, preShareKey len: %{public}d.\n", electedDevice.networkId, (int)electedDevice.preSharedKey.length()); + } } else { WIFI_LOGE("The current connection status is %{public}d.\n", currentConnectedNetwork.detailedState); } @@ -261,7 +270,7 @@ bool StaAutoConnectService::ObtainRoamCapFromFirmware() if ((capabilities & STA_CAP_ROAMING) == 0) { WIFI_LOGE("Firmware roaming is not supported.\n"); firmwareRoamFlag = false; - return false; + return false; } } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h index cfa8d8a27..767236b35 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h @@ -34,6 +34,7 @@ namespace Wifi { #define WIFI_SVR_CMD_STA_STARTWPS 0x2009 #define WIFI_SVR_CMD_STA_CANCELWPS 0x200A #define WIFI_SVR_COM_STA_START_ROAM 0x200B +#define WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK 0x200C #define WIFI_SVR_CMD_STA_ERROR 0x3001 #define WIFI_SVR_CMD_STA_SUP_CONNECTION_EVENT 0x3002 diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp index 34e2026b6..c3c405373 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp @@ -69,6 +69,7 @@ ErrCode StaSavedDeviceAppraisal::DeviceAppraisals( if (CheckHigherPriority(score, highestScore, scanInfo.rssi, scanInfoElected.rssi)) { highestScore = score; scanInfoElected.rssi = scanInfo.rssi; + device.bssid = scanInfo.bssid; electedDevice = device; sign = 1; WIFI_LOGD("set highestScore: %{public}d, ssid: %{public}s", highestScore, SsidAnonymize(device.ssid).c_str()); @@ -230,4 +231,4 @@ bool StaSavedDeviceAppraisal::CheckHigherPriority(int score, int lastScore, int return higerPriority; } } // namespace Wifi -} // namespace OHOS \ No newline at end of file +} // namespace OHOS 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 233102d31..8c08bffa7 100644 --- 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 @@ -686,6 +686,7 @@ int StaStateMachine::InitStaSMHandleMap() staSmHandleFuncMap[CMD_SIGNAL_POLL] = &StaStateMachine::DealSignalPollResult; staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_NETWORK] = &StaStateMachine::DealConnectToUserSelectedNetwork; staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK] = &StaStateMachine::DealConnectToUserSelectedNetwork; + staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK] = &StaStateMachine::DealConnectToSameNameNetwork; staSmHandleFuncMap[WIFI_SVR_CMD_STA_NETWORK_DISCONNECTION_EVENT] = &StaStateMachine::DealDisconnectEvent; staSmHandleFuncMap[WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT] = &StaStateMachine::DealConnectionEvent; staSmHandleFuncMap[CMD_NETWORK_CONNECT_TIMEOUT] = &StaStateMachine::DealConnectTimeOutCmd; @@ -855,6 +856,18 @@ void StaStateMachine::OnConnectFailed(int networkId) void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessage *msg) { LOGD("enter DealConnectToUserSelectedNetwork.\n"); + DealConnectToNetwork(msg, false); +} + +void StaStateMachine::DealConnectToSameNameNetwork(InternalMessage *msg) +{ + LOGD("enter DealConnectToSameNameNetwork.\n"); + DealConnectToNetwork(msg, true); +} + +void StaStateMachine::DealConnectToNetwork(InternalMessage *msg, bool changeBssid) +{ + LOGD("enter DealConnectToNetwork.\n"); if (msg == nullptr) { LOGE("msg is null.\n"); return; @@ -865,6 +878,10 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessage *msg) if (connTriggerMode != NETWORK_SELECTED_BY_RETRY) { linkedInfo.retryedConnCount = 0; } + std::string bssid; + if(changeBssid){ + bssid = msg->GetStringFromMessage(); + } WriteWifiConnectionInfoHiSysEvent(networkId); if (networkId == linkedInfo.networkId) { @@ -886,11 +903,18 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessage *msg) /* Callback result to InterfaceService. */ staCallback.OnStaConnChanged(OperateResState::CONNECT_CONNECTING, linkedInfo); - if (StartConnectToNetwork(networkId) != WIFI_OPT_SUCCESS) { - OnConnectFailed(networkId); - return; + if(changeBssid) { + if (StartConnnectToSameNameSsid(networkId,bssid) != WIFI_OPT_SUCCESS) { + OnConnectFailed(networkId); + return; + } + } + else{ + if (StartConnectToNetwork(networkId) != WIFI_OPT_SUCCESS) { + OnConnectFailed(networkId); + return; + } } - /* Sets network status. */ WifiSettings::GetInstance().EnableNetwork(networkId, connTriggerMode == NETWORK_SELECTED_BY_USER); WifiSettings::GetInstance().SetDeviceAfterConnect(networkId); @@ -1351,12 +1375,33 @@ ErrCode StaStateMachine::StartConnectToNetwork(int networkId) WifiStaHalInterface::GetInstance().SetBssid(networkId, deviceConfig.userSelectBssid.c_str()); - if (WifiStaHalInterface::GetInstance().EnableNetwork(targetNetworkId) != WIFI_IDL_OPT_OK) { + return ConnnectToNetwork(networkId); +} + +ErrCode StaStateMachine::StartConnnectToSameNameSsid(int networkId, std::string bssid) +{ + targetNetworkId = networkId; + SetRandomMac(targetNetworkId); + + WifiDeviceConfig deviceConfig; + if (WifiSettings::GetInstance().GetDeviceConfig(networkId, deviceConfig) != 0) { + LOGE("StartConnnectToSameNameSsid get GetDeviceConfig failed!"); + return WIFI_OPT_FAILED; + } + + WifiStaHalInterface::GetInstance().SetBssid(networkId, bssid.c_str()); + + return ConnnectToNetwork(networkId); +} + +ErrCode StaStateMachine::ConnnectToNetwork(int networkId) +{ + if (WifiStaHalInterface::GetInstance().EnableNetwork(networkId) != WIFI_IDL_OPT_OK) { LOGE("EnableNetwork() failed!"); return WIFI_OPT_FAILED; } - if (WifiStaHalInterface::GetInstance().Connect(targetNetworkId) != WIFI_IDL_OPT_OK) { + if (WifiStaHalInterface::GetInstance().Connect(networkId) != WIFI_IDL_OPT_OK) { LOGE("Connect failed!"); staCallback.OnStaConnChanged(OperateResState::CONNECT_SELECT_NETWORK_FAILED, linkedInfo); return WIFI_OPT_FAILED; 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 1fe7672d8..8822629eb 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 @@ -529,6 +529,16 @@ private: * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED */ ErrCode StartConnectToNetwork(int networkId); + /** + * @Description roam to same name ssid When current link is disconectted + */ + ErrCode StartConnnectToSameNameSsid(int networkId, std::string bssid); + + ErrCode ConnnectToNetwork(int networkId); + /** + * @Description DealConnectToNetwork + */ + void DealConnectToNetwork(InternalMessage *msg, bool changeBssid); /** * @Description Disable network * @@ -625,6 +635,12 @@ private: * @param msg - Message body received by the state machine[in] */ void DealConnectToUserSelectedNetwork(InternalMessage *msg); + /** + * @Description : Connect to the network with same ssid when current link is disconnectted. + * + * @param msg - Message body received by the state machine[in] + */ + void DealConnectToSameNameNetwork(InternalMessage *msg); /** * @Description Operations after the disconnection Event is reported. * -- Gitee From 21f46b91610dc5e7b71db8366a04a80dd4f6c153 Mon Sep 17 00:00:00 2001 From: wangxiaoyun Date: Mon, 13 Nov 2023 01:17:04 -0800 Subject: [PATCH 3/4] fix roam question when have same ssid diff passwd Signed-off-by: wangxiaoyun --- .../wifi_manage/wifi_manager.cpp | 8 +++++++- .../wifi_manage/wifi_sta/ista_service.h | 9 ++++++++- .../wifi_sta/sta_auto_connect_service.cpp | 15 +++++++++------ .../wifi_sta/sta_auto_connect_service.h | 3 ++- .../wifi_manage/wifi_sta/sta_define.h | 2 +- .../wifi_manage/wifi_sta/sta_interface.cpp | 12 ++++++++++++ .../wifi_manage/wifi_sta/sta_interface.h | 10 +++++++++- .../wifi_manage/wifi_sta/sta_service.cpp | 8 ++++++++ .../wifi_manage/wifi_sta/sta_service.h | 10 +++++++++- .../wifi_manage/wifi_sta/sta_state_machine.cpp | 18 +++++++++++++----- .../wifi_manage/wifi_sta/sta_state_machine.h | 5 +++-- 11 files changed, 81 insertions(+), 19 deletions(-) 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 58bf5c6d8..683d4aa53 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 @@ -1042,6 +1042,12 @@ void WifiManager::DealStaConnChanged(OperateResState state, const WifiLinkedInfo WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg); } + if(info.detailedState == DetailedState::PASSWORD_ERROR){ + IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(); + if (pService != nullptr) { + pService->EnableOrDisableBssid(info.bssid,false,static_cast(info.detailedState)); + } + } if (state == OperateResState::CONNECT_CONNECTING || state == OperateResState::CONNECT_AP_CONNECTED || state == OperateResState::DISCONNECT_DISCONNECTING || state == OperateResState::DISCONNECT_DISCONNECTED || state == OperateResState::CONNECT_OBTAINING_IP || state == OperateResState::CONNECT_ASSOCIATING || @@ -2134,4 +2140,4 @@ void WifiTimer::UnRegister(uint32_t timerId) } #endif } // namespace Wifi -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h index e412f5c4e..dd99e68a4 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h @@ -224,7 +224,14 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode OnScreenStateChanged(int screenState) = 0; + /** + * @Description EnableOrDisableBssid + * + * @param enable: true to delete bssid from blocklist, false to add bssid to blocklist. + * @return WifiErrorNo + */ + virtual ErrCode EnableOrDisableBssid(std::string bssid, bool enable, int reason) = 0; }; } // namespace Wifi } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp index bf78b9ae6..879208263 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -78,7 +78,7 @@ void StaAutoConnectService::OnScanInfosReadyHandler(const std::vector blockedBssids; GetBlockedBssids(blockedBssids); @@ -99,11 +99,15 @@ void StaAutoConnectService::OnScanInfosReadyHandler(const std::vectorSendMessage(WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK, + pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_DIFF_BSSID_NETWORK, electedDevice.networkId, NETWORK_SELECTED_BY_AUTO, electedDevice.bssid); @@ -228,10 +232,9 @@ void StaAutoConnectService::ConnectElectedDevice(WifiDeviceConfig &electedDevice pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, electedDevice.networkId, NETWORK_SELECTED_BY_AUTO); - WIFI_LOGI("connectTo save networkId: %{public}d, preShareKey len: %{public}d.\n", + WIFI_LOGI("connectTo save networkId: %{public}d, preShareKey len: %{public}d.\n", electedDevice.networkId, (int)electedDevice.preSharedKey.length()); - } - } else { + } } else { WIFI_LOGE("The current connection status is %{public}d.\n", currentConnectedNetwork.detailedState); } return; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h index 4f7d70041..2171f66f2 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h @@ -32,6 +32,7 @@ namespace OHOS { namespace Wifi { static const int MAX_BSSID_BLOCKLIST_COUNT = 3; static const int AP_CANNOT_HANDLE_NEW_STA = 17; +static const int PASSWORD_ERROR = 15; static const int MAX_BSSID_BLOCKLIST_TIME = 60; // 60s static const int BLOCKLIST_INVALID_SIZE = -1; static const int STA_CAP_ROAMING = 0x800000; @@ -231,4 +232,4 @@ private: }; } // namespace Wifi } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h index 767236b35..3ba010eac 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h @@ -34,7 +34,7 @@ namespace Wifi { #define WIFI_SVR_CMD_STA_STARTWPS 0x2009 #define WIFI_SVR_CMD_STA_CANCELWPS 0x200A #define WIFI_SVR_COM_STA_START_ROAM 0x200B -#define WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK 0x200C +#define WIFI_SVR_CMD_STA_CONNECT_DIFF_BSSID_NETWORK 0x200C #define WIFI_SVR_CMD_STA_ERROR 0x3001 #define WIFI_SVR_CMD_STA_SUP_CONNECTION_EVENT 0x3002 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 1f7ff728e..5ac4ccff1 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 @@ -334,5 +334,17 @@ ErrCode StaInterface::OnScreenStateChanged(int screenState) pStaService->HandleScreenStatusChanged(screenState); return WIFI_OPT_SUCCESS; } + +ErrCode StaInterface::EnableOrDisableBssid(std::string bssid, bool enable, int reason) +{ + LOGD("Enter StaInterface::EnableOrDisableBssid.\n"); + std::lock_guard lock(mutex); + CHECK_NULL_AND_RETURN(pStaService, WIFI_OPT_FAILED); + if (pStaService->EnableOrDisableBssid(bssid,enable,reason) != WIFI_OPT_SUCCESS) { + LOGD("EnableOrDisableBssid success.\n"); + return WIFI_OPT_SUCCESS; + } + return WIFI_OPT_FAILED; +} } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h index a66a9e0e9..cd8f6d5cd 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h @@ -224,6 +224,14 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode OnScreenStateChanged(int screenState) override; + + /** + * @Description EnableOrDisableBssid + * + * @param enable: true to delete bssid from blocklist, false to add bssid to blocklist. + * @return WifiErrorNo + */ + virtual ErrCode EnableOrDisableBssid(std::string bssid, bool enable, int reason) override; private: StaServiceCallback staCallback; StaService *pStaService; @@ -231,4 +239,4 @@ private: }; } // namespace Wifi } // namespace OHOS -#endif \ No newline at end of file +#endif 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 560e1693c..25d8e1107 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 @@ -525,5 +525,13 @@ void StaService::HandleScreenStatusChanged(int screenState) #endif return; } + +bool StaService::EnableOrDisableBssid(std::string bssid, bool enable, int reason) +{ + WIFI_LOGI("Enter StaService::EnableOrDisableBssid."); + if(pStaAutoConnectService == nullptr) + return false; + return pStaAutoConnectService->EnableOrDisableBssid(bssid,enable,reason); +} } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h index 9cfcf6854..d57e3ef4f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h @@ -229,6 +229,14 @@ public: * */ virtual void HandleScreenStatusChanged(int screenState); + + /** + * @Description To add or delete bssid from blocklist depends param enable + * + * @Return true or false + */ + virtual bool EnableOrDisableBssid(std::string bssid, bool enable, int reason); + private: void NotifyDeviceConfigChange(ConfigChange value) const; @@ -239,4 +247,4 @@ private: }; } // namespace Wifi } // namespace OHOS -#endif \ No newline at end of file +#endif 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 8c08bffa7..510e52091 100644 --- 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 @@ -68,6 +68,7 @@ StaStateMachine::StaStateMachine() pDhcpService(nullptr), pDhcpResultNotify(nullptr), pNetcheck(nullptr), + bssidBeforePwdError(""), pRootState(nullptr), pInitState(nullptr), pWpaStartingState(nullptr), @@ -686,7 +687,7 @@ int StaStateMachine::InitStaSMHandleMap() staSmHandleFuncMap[CMD_SIGNAL_POLL] = &StaStateMachine::DealSignalPollResult; staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_NETWORK] = &StaStateMachine::DealConnectToUserSelectedNetwork; staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK] = &StaStateMachine::DealConnectToUserSelectedNetwork; - staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_SAME_NAME_NETWORK] = &StaStateMachine::DealConnectToSameNameNetwork; + staSmHandleFuncMap[WIFI_SVR_CMD_STA_CONNECT_DIFF_BSSID_NETWORK] = &StaStateMachine::DealConnectToDiffBssidNetwork; staSmHandleFuncMap[WIFI_SVR_CMD_STA_NETWORK_DISCONNECTION_EVENT] = &StaStateMachine::DealDisconnectEvent; staSmHandleFuncMap[WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT] = &StaStateMachine::DealConnectionEvent; staSmHandleFuncMap[CMD_NETWORK_CONNECT_TIMEOUT] = &StaStateMachine::DealConnectTimeOutCmd; @@ -859,9 +860,9 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessage *msg) DealConnectToNetwork(msg, false); } -void StaStateMachine::DealConnectToSameNameNetwork(InternalMessage *msg) +void StaStateMachine::DealConnectToDiffBssidNetwork(InternalMessage *msg) { - LOGD("enter DealConnectToSameNameNetwork.\n"); + LOGD("enter DealConnectToDiffBssidNetwork.\n"); DealConnectToNetwork(msg, true); } @@ -1023,6 +1024,9 @@ void StaStateMachine::DealDisconnectEvent(InternalMessage *msg) IfConfig::GetInstance().FlushIpAddr(IF_NAME, IPTYPE_IPV4); #endif /* Initialize connection information. */ + if (!linkedInfo.bssid.empty()) { + bssidBeforePwdError = linkedInfo.bssid; + } InitWifiLinkedInfo(); if (lastLinkedInfo.detailedState == DetailedState::CONNECTING) { linkedInfo.networkId = lastLinkedInfo.networkId; @@ -1055,11 +1059,12 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessage *msg) } StopTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT)); - InitWifiLinkedInfo(); - WifiSettings::GetInstance().SaveLinkedInfo(linkedInfo); if (msg->GetMessageName() == WIFI_SVR_CMD_STA_WPA_PASSWD_WRONG_EVENT) { SaveDiscReason(DisconnectedReason::DISC_REASON_WRONG_PWD); SaveLinkstate(ConnState::DISCONNECTED, DetailedState::PASSWORD_ERROR); + if (!bssidBeforePwdError.empty()) { + linkedInfo.bssid = bssidBeforePwdError; + } staCallback.OnStaConnChanged(OperateResState::CONNECT_PASSWORD_WRONG, linkedInfo); } else if (msg->GetMessageName() == WIFI_SVR_CMD_STA_WPA_FULL_CONNECT_EVENT) { DisableNetwork(targetNetworkId); @@ -1076,6 +1081,9 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessage *msg) staCallback.OnStaConnChanged(OperateResState::DISCONNECT_DISCONNECTED, linkedInfo); WriteWifiConnectionHiSysEvent(WifiConnectionType::DISCONNECT, ""); } + bssidBeforePwdError.clear(); + InitWifiLinkedInfo(); + WifiSettings::GetInstance().SaveLinkedInfo(linkedInfo); } bool StaStateMachine::DealReconnectSavedNetwork() 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 8822629eb..5780246a0 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 @@ -636,11 +636,11 @@ private: */ void DealConnectToUserSelectedNetwork(InternalMessage *msg); /** - * @Description : Connect to the network with same ssid when current link is disconnectted. + * @Description : Connect to the network with same ssid diffrent bssid when current link is disconnectted. * * @param msg - Message body received by the state machine[in] */ - void DealConnectToSameNameNetwork(InternalMessage *msg); + void DealConnectToDiffBssidNetwork(InternalMessage *msg); /** * @Description Operations after the disconnection Event is reported. * @@ -805,6 +805,7 @@ private: std::unique_ptr pDhcpService; DhcpResultNotify *pDhcpResultNotify; StaNetworkCheck *pNetcheck; + std::string bssidBeforePwdError; RootState *pRootState; InitState *pInitState; -- Gitee From 149cb586d7cb97efdba0aaf3546f21d0a5e846b4 Mon Sep 17 00:00:00 2001 From: wangxiaoyun Date: Mon, 13 Nov 2023 02:00:06 -0800 Subject: [PATCH 4/4] fix compile question Signed-off-by: wangxiaoyun --- .../wifi_framework/wifi_manage/wifi_manager.cpp | 2 +- .../wifi_manage/wifi_sta/ista_service.h | 2 ++ .../wifi_sta/sta_auto_connect_service.cpp | 13 +++++-------- .../wifi_manage/wifi_sta/sta_service.cpp | 5 ++++- .../wifi_manage/wifi_sta/sta_state_machine.cpp | 11 +++-------- 5 files changed, 15 insertions(+), 18 deletions(-) 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 83b55aef8..07321a757 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 @@ -1239,7 +1239,7 @@ void WifiManager::DealStaConnChanged(OperateResState state, const WifiLinkedInfo if(info.detailedState == DetailedState::PASSWORD_ERROR){ IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(); if (pService != nullptr) { - pService->EnableOrDisableBssid(info.bssid,false,static_cast(info.detailedState)); + pService->EnableOrDisableBssid(info.bssid, false, static_cast(info.detailedState)); } } if (state == OperateResState::CONNECT_CONNECTING || state == OperateResState::CONNECT_AP_CONNECTED || diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h index d295ab2d7..bfba73b38 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/ista_service.h @@ -228,12 +228,14 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode OnScreenStateChanged(int screenState) = 0; + /** * @Description EnableOrDisableBssid * * @param enable: true to delete bssid from blocklist, false to add bssid to blocklist. * @return WifiErrorNo */ + virtual ErrCode EnableOrDisableBssid(std::string bssid, bool enable, int reason) = 0; /** * @Description start portal certification. diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp index 4fe9695b9..6efc82ce8 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -79,7 +79,7 @@ void StaAutoConnectService::OnScanInfosReadyHandler(const std::vector blockedBssids; GetBlockedBssids(blockedBssids); @@ -100,15 +100,11 @@ void StaAutoConnectService::OnScanInfosReadyHandler(const std::vectorSendMessage(WIFI_SVR_CMD_STA_CONNECT_DIFF_BSSID_NETWORK, electedDevice.networkId, NETWORK_SELECTED_BY_AUTO, @@ -235,7 +231,8 @@ void StaAutoConnectService::ConnectElectedDevice(WifiDeviceConfig &electedDevice NETWORK_SELECTED_BY_AUTO); WIFI_LOGI("connectTo save networkId: %{public}d, preShareKey len: %{public}d.\n", electedDevice.networkId, (int)electedDevice.preSharedKey.length()); - } } else { + } + } else { WIFI_LOGE("The current connection status is %{public}d.\n", currentConnectedNetwork.detailedState); } 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 e731e32b0..ac470cf6e 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 @@ -565,9 +565,12 @@ void StaService::HandleScreenStatusChanged(int screenState) bool StaService::EnableOrDisableBssid(std::string bssid, bool enable, int reason) { WIFI_LOGI("Enter StaService::EnableOrDisableBssid."); - if(pStaAutoConnectService == nullptr) + if (pStaAutoConnectService == nullptr) { return false; + } return pStaAutoConnectService->EnableOrDisableBssid(bssid,enable,reason); +} + ErrCode StaService::StartPortalCertification() { if (pStaStateMachine == nullptr) { 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 617c6eac6..d3a52214d 100644 --- 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 @@ -1001,7 +1001,7 @@ void StaStateMachine::DealConnectToNetwork(InternalMessage *msg, bool changeBssi linkedInfo.retryedConnCount = 0; } std::string bssid; - if(changeBssid){ + if (changeBssid) { bssid = msg->GetStringFromMessage(); } WriteWifiConnectionInfoHiSysEvent(networkId); @@ -1025,13 +1025,12 @@ void StaStateMachine::DealConnectToNetwork(InternalMessage *msg, bool changeBssi /* Callback result to InterfaceService. */ InvokeOnStaConnChanged(OperateResState::CONNECT_CONNECTING, linkedInfo); - if(changeBssid) { + if (changeBssid) { if (StartConnnectToSameNameSsid(networkId,bssid) != WIFI_OPT_SUCCESS) { OnConnectFailed(networkId); return; } - } - else{ + } else { if (StartConnectToNetwork(networkId) != WIFI_OPT_SUCCESS) { OnConnectFailed(networkId); return; @@ -1188,10 +1187,6 @@ void StaStateMachine::DealWpaLinkFailEvent(InternalMessage *msg) if (!bssidBeforePwdError.empty()) { linkedInfo.bssid = bssidBeforePwdError; } - staCallback.OnStaConnChanged(OperateResState::CONNECT_PASSWORD_WRONG, linkedInfo); - if (msg->GetMessageName() == WIFI_SVR_CMD_STA_WPA_PASSWD_WRONG_EVENT) { - SaveDiscReason(DisconnectedReason::DISC_REASON_WRONG_PWD); - SaveLinkstate(ConnState::DISCONNECTED, DetailedState::PASSWORD_ERROR); InvokeOnStaConnChanged(OperateResState::CONNECT_PASSWORD_WRONG, linkedInfo); } else if (msg->GetMessageName() == WIFI_SVR_CMD_STA_WPA_FULL_CONNECT_EVENT) { DisableNetwork(targetNetworkId); -- Gitee