From 341e56ad5999bc854a58996c4c07aec741198757 Mon Sep 17 00:00:00 2001 From: xionglei Date: Thu, 26 Jun 2025 12:05:19 +0800 Subject: [PATCH 1/4] renew dhcp selfcure Signed-off-by: xionglei --- wifi/interfaces/inner_api/wifi_msg.h | 1 + .../wifi_self_cure/iself_cure_service.h | 12 ++ .../wifi_self_cure/self_cure_common.h | 2 + .../wifi_self_cure/self_cure_interface.cpp | 24 +++ .../wifi_self_cure/self_cure_interface.h | 12 ++ .../wifi_self_cure/self_cure_msg.h | 11 ++ .../wifi_self_cure/self_cure_service.cpp | 24 +++ .../wifi_self_cure/self_cure_service.h | 2 + .../self_cure_state_machine.cpp | 137 +++++++++++++++++- .../wifi_self_cure/self_cure_state_machine.h | 7 + .../wifi_self_cure/self_cure_utils.cpp | 19 +++ .../wifi_manage/wifi_sta/ista_service.h | 7 + .../wifi_manage/wifi_sta/sta_define.h | 1 + .../wifi_manage/wifi_sta/sta_interface.cpp | 12 ++ .../wifi_manage/wifi_sta/sta_interface.h | 7 + .../wifi_manage/wifi_sta/sta_service.cpp | 8 + .../wifi_manage/wifi_sta/sta_service.h | 8 + .../wifi_sta/sta_state_machine.cpp | 19 +++ .../wifi_manage/wifi_sta/sta_state_machine.h | 1 + .../wifi_sta/Mock/mock_sta_interface.cpp | 6 + .../wifi_sta/Mock/mock_sta_service.h | 1 + .../wifi_sta/self_cure_interface_test.cpp | 12 ++ .../wifi_sta/self_cure_service_test.cpp | 12 ++ .../wifi_sta/self_cure_state_machine_test.cpp | 22 +++ .../wifi_sta/sta_interface_test.cpp | 24 +++ 25 files changed, 387 insertions(+), 4 deletions(-) diff --git a/wifi/interfaces/inner_api/wifi_msg.h b/wifi/interfaces/inner_api/wifi_msg.h index b80be0f22..1e8852fb6 100644 --- a/wifi/interfaces/inner_api/wifi_msg.h +++ b/wifi/interfaces/inner_api/wifi_msg.h @@ -1061,6 +1061,7 @@ enum class WifiSelfcureType { RESET_SELFCURE_SUCC, RAND_MAC_REASSOC_SELFCURE_SUCC, MULTI_GATEWAY_SELFCURE_SUCC, + RENEW_DHCP_SELFCURE_SUCC, }; enum class Wifi3VapConflictType { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/iself_cure_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/iself_cure_service.h index e4d68a933..dceb9a096 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/iself_cure_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/iself_cure_service.h @@ -92,6 +92,18 @@ public: * @return bool - true: have done selfcure or no need to do, false: selfcure not finish */ virtual bool IsWifiSelfcureDone() = 0; + + /** + * @Description Check if Selfcure state, + * + * @param bssid - string - bssid info + */ + virtual void NotifyWifiRoamingCompleted(std::string bssid) = 0; + + /** + * @Description notify selfcure ip config completed + */ + virtual void NotifyIpConfigCompleted() = 0; }; } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_common.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_common.h index bcb341d37..10ba4778a 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_common.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_common.h @@ -70,6 +70,7 @@ namespace Wifi { #define WIFI_CURE_RESET_LEVEL_MULTI_GATEWAY 210 #define WIFI_CURE_RESET_LEVEL_HIGH_RESET_WIFI_ON 211 +#define WIFI_CURE_RESET_LEVEL_RENEW_DHCP 212 #define WIFI_CURE_INTERNET_FAILED_RAND_MAC 300 #define WIFI_CURE_INTERNET_FAILED_TYPE_GATEWAY 302 @@ -90,6 +91,7 @@ namespace Wifi { #define WIFI_CURE_CMD_STOP_SELF_CURE 316 #define WIFI_CURE_CMD_FORCE_STOP_SELF_CURE 317 #define WIFI_CURE_DISCONNECT_TIMEOUT 318 +#define WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING 319 #define SELFCURE_FAIL_LENGTH 12 #define SELFCURE_HISTORY_LENGTH 14 diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.cpp index 23095c4ca..d99b67018 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.cpp @@ -189,5 +189,29 @@ void SelfCureInterface::DealRssiLevelChanged(int rssi, int instId) } pSelfCureService->HandleRssiLevelChanged(rssi); } + +void SelfCureInterface::NotifyWifiRoamingCompleted(std::string bssid) +{ + std::lock_guard lock(mutex); + if (pSelfCureService == nullptr) { + WIFI_LOGI("pSelfCureService is null"); + return; + } + if (bssid.empty()) { + WIFI_LOGI("bssid is null"); + return; + } + pSelfCureService->NotifyWifiRoamingCompleted(bssid); +} + +void SelfCureInterface::NotifyIpConfigCompleted() +{ + std::lock_guard lock(mutex); + if (pSelfCureService == nullptr) { + WIFI_LOGI("pSelfCureService is null"); + return; + } + pSelfCureService->NotifyIpConfigCompleted(); +} } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.h index 2ce8820b2..dc9e9b38c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_interface.h @@ -126,6 +126,18 @@ public: * @return bool - true: have done selfcure or no need to do, false: selfcure not finish */ bool IsWifiSelfcureDone() override; + + /** + * @Description Check if Selfcure state, + * + * @param bssid - string - bssid info + */ + void NotifyWifiRoamingCompleted(std::string bssid) override; + + /** + * @Description notify selfcure ip config completed + */ + void NotifyIpConfigCompleted() override; private: std::mutex mutex; std::vector mSelfCureCallback; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_msg.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_msg.h index c2eacec60..846095d8b 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_msg.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_msg.h @@ -63,8 +63,16 @@ struct WifiSelfCureHistoryInfo { /* record last reset connect failed milliseconds */ int64_t lastResetSelfCureConnectFailedTs; + + /* record renew dhcp connect failed count */ + int renewDhcpSelfCureConnectFailedCnt; + + /* record last renew dhcp connect failed milliseconds */ + int64_t lastRenewDhcpSelfCureConnectFailedTs; WifiSelfCureHistoryInfo() { + renewDhcpSelfCureConnectFailedCnt = 0; + lastRenewDhcpSelfCureConnectFailedTs = 0; staticIpSelfCureFailedCnt = 0; lastStaticIpSelfCureFailedTs = 0; reassocSelfCureFailedCnt = 0; @@ -83,6 +91,8 @@ struct WifiSelfCureHistoryInfo { std::string GetSelfCureHistory() { std::string internetSelfCureHistory; + internetSelfCureHistory.append(std::to_string(renewDhcpSelfCureConnectFailedCnt) + "|"); + internetSelfCureHistory.append(std::to_string(lastRenewDhcpSelfCureConnectFailedTs) + "|"); internetSelfCureHistory.append(std::to_string(staticIpSelfCureFailedCnt) + "|"); internetSelfCureHistory.append(std::to_string(lastStaticIpSelfCureFailedTs) + "|"); internetSelfCureHistory.append(std::to_string(reassocSelfCureFailedCnt) + "|"); @@ -128,6 +138,7 @@ enum class SelfCureType { SCE_TYPE_RANDMAC = 6, SCE_TYPE_RESET = 7, SCE_TYPE_RESET_WIFI_ON = 8, + SCE_TYPE_RENEW_DHCP = 9, }; enum SelfCureState { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.cpp index e512a77fe..69e503e40 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.cpp @@ -223,5 +223,29 @@ void SelfCureService::P2pEnhanceStateChange(const std::string &ifName, int32_t s WifiConfigCenter::GetInstance().SetP2pEnhanceState(p2pEnhanceState); } } + +void SelfCureService::NotifyWifiRoamingCompleted(std::string bssid) +{ + WIFI_LOGI("enter NotifyWifiRoamingCompleted"); + if (pSelfCureStateMachine == nullptr) { + WIFI_LOGE("%{public}s pSelfCureStateMachine is null.", __FUNCTION__); + return; + } + if (bssid.empty()) { + WIFI_LOGE("bssid is null"); + return; + } + pSelfCureStateMachine->SendMessage(WIFI_CURE_CMD_NETWORK_ROAMING_DETECT, bssid); +} + +void SelfCureService::NotifyIpConfigCompleted() +{ + WIFI_LOGI("enter NotifyIpConfigCompleted"); + if (pSelfCureStateMachine == nullptr) { + WIFI_LOGE("%{public}s pSelfCureStateMachine is null.", __FUNCTION__); + return; + } + pSelfCureStateMachine->SendMessage(WIFI_CURE_CMD_IP_CONFIG_COMPLETED); +} } //namespace Wifi } //namespace OHOS \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.h index ad7f8e1de..1e242181e 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_service.h @@ -43,6 +43,8 @@ public: void StopSelfCureWifi(int32_t status); bool CheckSelfCureWifiResult(int event); bool IsWifiSelfcureDone(); + void NotifyWifiRoamingCompleted(std::string bssid); + void NotifyIpConfigCompleted(); private: void RegisterP2pEnhanceCallback(); void P2pEnhanceStateChange(const std::string &ifName, int32_t state, int32_t frequency); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.cpp index a376b5251..0b5b5095c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.cpp @@ -46,7 +46,7 @@ const uint32_t WIFI_SINGLE_ITEM_BYTE_LEN = 8; const uint32_t WIFI_SINGLE_MAC_LEN = 6; const uint32_t WIFI_MAX_BLA_LIST_NUM = 16; const uint32_t DHCP_OFFER_COUNT = 2; -const std::string INIT_SELFCURE_HISTORY = "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0"; +const std::string INIT_SELFCURE_HISTORY = "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0"; const std::string COUNTRY_CODE_CN = "460"; SelfCureStateMachine::SelfCureStateMachine(int instId) @@ -319,12 +319,16 @@ int SelfCureStateMachine::ConnectedMonitorState::InitSelfCureCmsHandleMap() selfCureCmsHandleFuncMap_[WIFI_CURE_CMD_DNS_FAILED_MONITOR] = [this](InternalMessagePtr msg) { this->HandleDnsFailedMonitor(msg); }; + selfCureCmsHandleFuncMap_[WIFI_CURE_CMD_NETWORK_ROAMING_DETECT] = [this](InternalMessagePtr msg) { + this->HandleRoamingDetected(msg); + }; return WIFI_OPT_SUCCESS; } void SelfCureStateMachine::ConnectedMonitorState::TransitionToSelfCureState(int reason) { - if (isMobileHotspot_ || pSelfCureStateMachine_->IsCustNetworkSelfCure()) { + if ((isMobileHotspot_ || pSelfCureStateMachine_->IsCustNetworkSelfCure()) && + reason != WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING) { WIFI_LOGW("transitionToSelfCureState, don't support SCE, do nothing"); return; } @@ -500,6 +504,34 @@ void SelfCureStateMachine::ConnectedMonitorState::HandleDnsFailedMonitor(Interna } } +void SelfCureStateMachine::ConnectedMonitorState::HandleRoamingDetected(InternalMessagePtr msg) +{ + WIFI_LOGI("enter HandleRoamingDetected"); + if (msg == nullptr) { + WIFI_LOGE("%{public}s msg is nullper", __FUNCTION__); + return; + } + std::string currentBssid; + msg->GetMessageObj(currentBssid); + if ((!currentBssid.empty()) && (lastConnectedBssid_ == currentBssid)) { + WIFI_LOGW("HandleRoamingDetected, but bssid is unchanged, ignore it"); + return; + } + if (isUserSetStaticIpConfig_) { + WIFI_LOGW("ip is staticip"); + return; + } + if ((!isHasInternetRecently_) && (!isPortalUnthenEver_) && (!pSelfCureStateMachine_->isInternetUnknown_)) { + WIFI_LOGW("no internet access always"); + return; + } + if (!pSelfCureStateMachine_->CanArpReachable()) { + WIFI_LOGI("arp is unreachable"); + pSelfCureStateMachine_->selfCureReason_ = WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING; + TransitionToSelfCureState(WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING); + } +} + bool SelfCureStateMachine::ConnectedMonitorState::IsNeedSelfCure() { if (pSelfCureStateMachine_->GetCurrentRssi() < MIN_VAL_LEVEL_3) { @@ -910,6 +942,15 @@ int SelfCureStateMachine::InternetSelfCureState::InitSelfCureIssHandleMap() selfCureIssHandleFuncMap_[WIFI_CURE_CMD_SELF_CURE_FAILED] = [this](InternalMessagePtr msg) { this->HandleSelfCureResultFailed(msg); }; + selfCureIssHandleFuncMap_[WIFI_CURE_CMD_IP_CONFIG_TIMEOUT] = [this](InternalMessagePtr msg) { + this->HandleRenewDhcpFailed(msg); + }; + selfCureIssHandleFuncMap_[WIFI_CURE_CMD_NETWORK_ROAMING_DETECT] = [this](InternalMessagePtr msg) { + this->HandleInRoamingDetected(msg); + }; + selfCureIssHandleFuncMap_[WIFI_CURE_CMD_IP_CONFIG_COMPLETED] = [this](InternalMessagePtr msg) { + this->HandleIpStateCompleted(msg); + }; return WIFI_OPT_SUCCESS; } @@ -1033,7 +1074,8 @@ void SelfCureStateMachine::InternetSelfCureState::SelectSelfCureByFailedReason(i } if (isUserSetStaticIpConfig_ && ((internetFailedType == WIFI_CURE_INTERNET_FAILED_TYPE_DNS) || - (internetFailedType == WIFI_CURE_INTERNET_FAILED_TYPE_GATEWAY))) { + (internetFailedType == WIFI_CURE_INTERNET_FAILED_TYPE_GATEWAY) || + (internetFailedType == WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING))) { HandleInternetFailedAndUserSetStaticIp(internetFailedType); return; } @@ -1110,7 +1152,13 @@ int SelfCureStateMachine::InternetSelfCureState::SelectBestSelfCureSolutionExt(i selfCureHistoryInfo_, WIFI_CURE_RESET_LEVEL_MIDDLE_REASSOC)) { bestSelfCureLevel = WIFI_CURE_RESET_LEVEL_MIDDLE_REASSOC; - } + } else if ((internetFailedType == WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING) && + (!HasBeenTested(WIFI_CURE_RESET_LEVEL_RENEW_DHCP) || + ((HasBeenTested(WIFI_CURE_RESET_LEVEL_RENEW_DHCP)) && (renewDhcpCount_ == 1))) && + (!pSelfCureStateMachine_->isSelfCureOnGoing_) && + (!(isDelayedReassocSelfCure_ || isDelayedResetSelfCure_))) { + bestSelfCureLevel = WIFI_CURE_RESET_LEVEL_RENEW_DHCP; +} return bestSelfCureLevel; } @@ -1128,6 +1176,8 @@ void SelfCureStateMachine::InternetSelfCureState::SelfCureWifiLink(int requestCu SelfCureForRandMacReassoc(requestCureLevel); } else if (requestCureLevel == WIFI_CURE_RESET_LEVEL_HIGH_RESET) { SelfCureForReset(requestCureLevel); + } else if (requestCureLevel == WIFI_CURE_RESET_LEVEL_RENEW_DHCP) { + SelfCureForReset(requestCureLevel); } } @@ -1328,6 +1378,29 @@ void SelfCureStateMachine::InternetSelfCureState::HandleSelfCureResultFailed(Int pSelfCureStateMachine_->SwitchState(pSelfCureStateMachine_->pDisconnectedMonitorState_); } +void SelfCureStateMachine::InternetSelfCureState::HandleRenewDhcpFailed(InternalMessagePtr msg) +{ + WIFI_LOGI("ip config timeout"); + pSelfCureStateMachine_->UpdateSelfcureState(WIFI_CURE_RESET_LEVEL_RENEW_DHCP, false); + pSelfCureStateMachine_->SwitchState(pSelfCureStateMachine_->pNoInternetState_); +} + +void SelfCureStateMachine::InternetSelfCureState::HandleInRoamingDetected(InternalMessagePtr msg) +{ + WIFI_LOGI("enter HandleInRoamingDetected"); + if (!pSelfCureStateMachine_->CanArpReachable()) { + WIFI_LOGI("arp is unreachable"); + pSelfCureStateMachine_->SendMessage(WIFI_CURE_CMD_SELF_CURE_WIFI_LINK, WIFI_CURE_RESET_LEVEL_RENEW_DHCP); + } +} + +void SelfCureStateMachine::InternetSelfCureState::HandleIpStateCompleted(InternalMessagePtr msg) +{ + WIFI_LOGI("CMD_IP_CONFIG_TIMEOUT msg removed because of ip config success"); + pSelfCureStateMachine_->StopTimer(WIFI_CURE_CMD_IP_CONFIG_TIMEOUT); + pSelfCureStateMachine_->SendMessage(WIFI_CURE_CMD_INTERNET_RECOVERY_CONFIRM, IP_CONFIG_CONFIRM_DELAYED_MS); +} + void SelfCureStateMachine::InternetSelfCureState::SelfCureForRandMacReassoc(int requestCureLevel) { if ((currentRssi_ < MIN_VAL_LEVEL_3) || pSelfCureStateMachine_->IfP2pConnected() || @@ -1396,6 +1469,33 @@ void SelfCureStateMachine::InternetSelfCureState::SelfCureForReset(int requestCu wifiControllerMachine->SelfcureResetWifi(pSelfCureStateMachine_->instId_); } +void SelfCureStateMachine::InternetSelfCureState::SelfCureForRenewDhcp(int requestCureLevel) +{ + if (isUserSetStaticIpConfig_) { + WIFI_LOGW("ip is staticip"); + return; + } + if ((!isHasInternetRecently_) && (!isPortalUnthenEver_) && (!pSelfCureStateMachine_->isInternetUnknown_)) { + WIFI_LOGW("no internet access always"); + return; + } + WIFI_LOGI("begin to self cure for internet access: RenewDhcp"); + pSelfCureStateMachine_->UpdateSelfcureState(WIFI_CURE_RESET_LEVEL_RENEW_DHCP, true); + testedSelfCureLevel_.push_back(requestCureLevel); + renewDhcpCount_ += 1; + IStaService *pStaService = WifiServiceManager::GetInstance().GetStaServiceInst(0); + if (pStaService == nullptr) { + WIFI_LOGE("Get pStaService failed!"); + return; + } + if (pStaService->StartRenewDhcp() != WIFI_OPT_SUCCESS) { + WIFI_LOGE("StartRenewDhcp failed!"); + return; + } + WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); + pSelfCureStateMachine_->MessageExecutedLater(WIFI_CURE_CMD_IP_CONFIG_TIMEOUT, DHCP_RENEW_TIMEOUT_MS); +} + bool SelfCureStateMachine::InternetSelfCureState::SelectedSelfCureAcceptable() { if (currentAbnormalType_ == WIFI_CURE_INTERNET_FAILED_TYPE_DNS || @@ -1538,6 +1638,8 @@ void SelfCureStateMachine::InternetSelfCureState::HandleHttpReachableAfterSelfCu WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::RESET_SELFCURE_SUCC)); } else if (currentCureLevel == WIFI_CURE_RESET_LEVEL_RAND_MAC_REASSOC) { WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::RAND_MAC_REASSOC_SELFCURE_SUCC)); + } else if (currentCureLevel == WIFI_CURE_RESET_LEVEL_RENEW_DHCP) { + WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::RENEW_DHCP_SELFCURE_SUCC)); } } @@ -1818,6 +1920,9 @@ void SelfCureStateMachine::NoInternetState::GoInState() pSelfCureStateMachine_->UpdateSelfcureState(WIFI_CURE_RESET_LEVEL_IDLE, false); pSelfCureStateMachine_->MessageExecutedLater(CMD_INTERNET_STATUS_DETECT_INTERVAL, NO_INTERNET_DETECT_INTERVAL_MS); + WifiLinkedInfo linkedInfo; + WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo); + lastConnectedBssid_ = linkedInfo.bssid; } void SelfCureStateMachine::NoInternetState::GoOutState() @@ -1859,6 +1964,10 @@ bool SelfCureStateMachine::NoInternetState::ExecuteStateMsg(InternalMessagePtr m ret = EXECUTED; HandleArpFailedDetected(msg); break; + case WIFI_CURE_CMD_NETWORK_ROAMING_DETECT: + ret = EXECUTED; + HandleNoIntStaRoamingDetected(msg); + break; default: WIFI_LOGD("NoInternetState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); break; @@ -1888,6 +1997,26 @@ void SelfCureStateMachine::NoInternetState::HandleArpFailedDetected(InternalMess } } +void SelfCureStateMachine::NoInternetState::HandleNoIntStaRoamingDetected(InternalMessagePtr msg) +{ + WIFI_LOGI("enter HandleNoIntStaRoamingDetected"); + if (msg == nullptr) { + WIFI_LOGE("HandleNoIntStaRoamingDetected, msg is nullptr"); + return; + } + std::string currentBssid; + msg->GetMessageObj(currentBssid); + if ((!currentBssid.empty()) && (lastConnectedBssid_ == currentBssid)) { + WIFI_LOGW("HandleNoIntStaRoamingDetected, but bssid is unchanged, ignore it"); + return; + } + if (!pSelfCureStateMachine_->CanArpReachable()) { + WIFI_LOGI("arp is unreachable"); + pSelfCureStateMachine_->selfCureReason_ = WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING; + pSelfCureStateMachine_->SwitchState(pSelfCureStateMachine_->pInternetSelfCureState_); + } +} + void SelfCureStateMachine::SendBlaListToDriver(int blaListType) { AgeOutWifiCategoryBlack(blaListType); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.h index 2312cf5c6..0686429d3 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_state_machine.h @@ -129,6 +129,7 @@ public: void HandleGatewayChanged(InternalMessagePtr msg); bool IsGatewayChanged(); void HandleDnsFailedMonitor(InternalMessagePtr msg); + void HandleRoamingDetected(InternalMessagePtr msg); bool IsNeedSelfCure(); }; @@ -219,6 +220,9 @@ public: void HandleArpFailedDetected(InternalMessagePtr msg); void HandleHttpReachableRecv(InternalMessagePtr msg); void HandleSelfCureResultFailed(InternalMessagePtr msg); + void HandleRenewDhcpFailed(InternalMessagePtr msg); + void HandleInRoamingDetected(InternalMessagePtr msg); + void HandleIpStateCompleted(InternalMessagePtr msg); void SelectSelfCureByFailedReason(int internetFailedType); int SelectBestSelfCureSolution(int internetFailedType); int SelectBestSelfCureSolutionExt(int internetFailedType); @@ -240,6 +244,7 @@ public: void SelfcureForMultiGateway(InternalMessagePtr msg); bool IsNeedMultiGatewaySelfcure(); void SelfCureForStaticIp(int requestCureLevel); + void SelfCureForRenewDhcp(int requestCureLevel); void RequestUseStaticIpConfig(IpInfo &dhcpResult); IpInfo GetNextTestDhcpResults(); IpInfo GetRecordDhcpResults(); @@ -284,6 +289,8 @@ public: bool ExecuteStateMsg(InternalMessagePtr msg) override; private: + std::string lastConnectedBssid_; + void HandleNoIntStaRoamingDetected(InternalMessagePtr msg); void HandleArpFailedDetected(InternalMessagePtr msg); SelfCureStateMachine *pSelfCureStateMachine_; }; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_utils.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_utils.cpp index ee1337eef..e3f633d8a 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_utils.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/self_cure_utils.cpp @@ -147,6 +147,9 @@ int32_t SelfCureUtils::GetSelfCureType(int32_t currentCureLevel) case WIFI_CURE_RESET_LEVEL_HIGH_RESET_WIFI_ON: ret = SelfCureType::SCE_TYPE_RESET_WIFI_ON; break; + case WIFI_CURE_RESET_LEVEL_RENEW_DHCP: + ret = SelfCureType::SCE_TYPE_RENEW_DHCP; + break; default: break; } @@ -241,6 +244,14 @@ void SelfCureUtils::UpdateSelfCureHistoryInfo(WifiSelfCureHistoryInfo &historyIn historyInfo.resetSelfCureFailedCnt += 1; historyInfo.lastResetSelfCureFailedTs = currentMs; } + } else if (requestCureLevel == WIFI_CURE_RESET_LEVEL_RENEW_DHCP) { + if (success) { + historyInfo.renewDhcpSelfCureConnectFailedCnt = 0; + historyInfo.lastRenewDhcpSelfCureConnectFailedTs = 0; + } else { + historyInfo.renewDhcpSelfCureConnectFailedCnt += 1; + historyInfo.lastRenewDhcpSelfCureConnectFailedTs = currentMs; + } } } @@ -273,6 +284,14 @@ void SelfCureUtils::UpdateSelfCureConnectHistoryInfo(WifiSelfCureHistoryInfo &hi historyInfo.resetSelfCureConnectFailedCnt += 1; historyInfo.lastResetSelfCureConnectFailedTs = currentMs; } + } else if (requestCureLevel == WIFI_CURE_RESET_LEVEL_RENEW_DHCP) { + if (success) { + historyInfo.renewDhcpSelfCureConnectFailedCnt = 0; + historyInfo.lastRenewDhcpSelfCureConnectFailedTs = 0; + } else { + historyInfo.renewDhcpSelfCureConnectFailedCnt += 1; + historyInfo.lastRenewDhcpSelfCureConnectFailedTs = currentMs; + } } } 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 ac4bb9cf1..5e1a52d48 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 @@ -112,6 +112,13 @@ public: * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED */ virtual ErrCode ReAssociate() = 0; + + /** + * @Description ReAssociate network + * + * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED + */ + virtual ErrCode StartRenewDhcp() = 0; /** * @Description Add a specified candidate hotspot configuration. 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 b946fb8a9..1e5a97ab0 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 @@ -38,6 +38,7 @@ namespace Wifi { #define WIFI_SVR_COM_STA_HILINK_DELIVER_MAC 0x200D #define WIFI_SVR_COM_STA_HILINK_TRIGGER_WPS 0x200E #define WIFI_SVR_COM_STA_NETWORK_REMOVED 0x200F +#define WIFI_SVR_COM_STA_RENEW_DHCP_NETWORK 0x2010 #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 39d23e6da..0acd45a99 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 @@ -152,6 +152,18 @@ ErrCode StaInterface::ReAssociate() return WIFI_OPT_SUCCESS; } +ErrCode StaInterface::StartRenewDhcp() +{ + LOGI("Enter StartRenewDhcp.\n"); + std::lock_guard lock(mutex); + CHECK_NULL_AND_RETURN(pStaService, WIFI_OPT_FAILED); + if (pStaService->StartRenewDhcp() != WIFI_OPT_SUCCESS) { + LOGE("StartRenewDhcp failed.\n"); + return WIFI_OPT_FAILED; + } + return WIFI_OPT_SUCCESS; +} + ErrCode StaInterface::Disconnect() { LOGI("Enter Disconnect.\n"); 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 4eaf96032..376412697 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 @@ -110,6 +110,13 @@ public: * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED */ virtual ErrCode ReAssociate() override; + + /** + * @Description StartRenewDhcp network + * + * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED + */ + virtual ErrCode StartRenewDhcp() override; /** * @Description Add a specified candidate hotspot configuration. * 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 9b648d8d3..8992e8b83 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 @@ -658,6 +658,14 @@ ErrCode StaService::ReAssociate() const return WIFI_OPT_SUCCESS; } +ErrCode StaService::StartRenewDhcp() const +{ + WIFI_LOGI("Enter StartRenewDhcp.\n"); + CHECK_NULL_AND_RETURN(pStaStateMachine, WIFI_OPT_FAILED); + pStaStateMachine->SendMessage(WIFI_SVR_COM_STA_RENEW_DHCP_NETWORK); + return WIFI_OPT_SUCCESS; +} + ErrCode StaService::EnableDeviceConfig(int networkId, bool attemptEnable) const { WIFI_LOGI("Enter EnableDeviceConfig, networkid is %{public}d", networkId); 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 8c7b981bd..36a2b368e 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 @@ -116,6 +116,14 @@ public: * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED */ virtual ErrCode ReAssociate() const; + + /** + * @Description StartRenewDhcp network + * + * @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED + */ + virtual ErrCode StartRenewDhcp() const; + /** * @Description Add a specified candidate hotspot configuration. * 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 c28db3bc4..485676750 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 @@ -702,6 +702,9 @@ int StaStateMachine::LinkState::InitStaSMHandleMap() staSmHandleFuncMap[WIFI_SVR_CMD_STA_REASSOCIATE_NETWORK] = [this](InternalMessagePtr msg) { return this->pStaStateMachine->DealReassociateCmd(msg); }; + staSmHandleFuncMap[WIFI_SVR_COM_STA_RENEW_DHCP_NETWORK] = [this](InternalMessagePtr msg) { + return this->DealRenewDhcp(msg); + }; staSmHandleFuncMap[WIFI_SCREEN_STATE_CHANGED_NOTIFY_EVENT] = [this](InternalMessagePtr msg) { return this->pStaStateMachine->DealScreenStateChangedEvent(msg); }; @@ -1439,6 +1442,9 @@ void StaStateMachine::ApLinkedState::HandleNetWorkConnectionEvent(InternalMessag } else { WIFI_LOGI("Arp reachable, stay in linked state."); } + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); + } } void StaStateMachine::ApLinkedState::HandleStaBssidChangedEvent(InternalMessagePtr msg) @@ -2783,6 +2789,9 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa WIFI_LOGI("Arp is reachable"); pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); } + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); + } return ret; } @@ -4245,6 +4254,16 @@ void StaStateMachine::DealReassociateCmd(InternalMessagePtr msg) } } +void StaStateMachine::LinkState::DealRenewDhcp(InternalMessagePtr msg) +{ + WIFI_LOGI("enter DealRenewDhcp.\n"); + if (msg == nullptr) { + WIFI_LOGE("msg is null\n"); + return; + } + pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); +} + void StaStateMachine::UserSelectConnectToNetwork(WifiDeviceConfig& deviceConfig, std::string& ifaceName) { WIFI_LOGI("SetBssid userSelectBssid=%{public}s", MacAnonymize(deviceConfig.userSelectBssid).c_str()); 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 09b84c86b..76087962f 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 @@ -234,6 +234,7 @@ public: void DealWpaStateChange(InternalMessagePtr msg); void DealMloStateChange(InternalMessagePtr msg); void DealWpaCustomEapAuthEvent(InternalMessagePtr msg); + void DealRenewDhcp(InternalMessagePtr msg); }; /** * @Description Definition of member function of SeparatedState class in StaStateMachine. diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp index e180d7e1a..7a95732f0 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp @@ -83,6 +83,12 @@ ErrCode StaInterface::ReAssociate() return WIFI_OPT_SUCCESS; } +ErrCode StaInterface::StartRenewDhcp() +{ + LOGI("Enter StartRenewDhcp.\n"); + return WIFI_OPT_SUCCESS; +} + ErrCode StaInterface::Disconnect() { LOGI("Enter Disconnect.\n"); diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_service.h b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_service.h index d639b779c..dcf6b6cc9 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_service.h +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_service.h @@ -32,6 +32,7 @@ public: MOCK_CONST_METHOD0(ReConnect, ErrCode()); MOCK_CONST_METHOD0(Disconnect, ErrCode()); MOCK_CONST_METHOD0(ReAssociate, ErrCode()); + MOCK_CONST_METHOD0(StartRenewDhcp, ErrCode()); MOCK_CONST_METHOD1(AddDeviceConfig, int(const WifiDeviceConfig &config)); MOCK_CONST_METHOD1(UpdateDeviceConfig, int(const WifiDeviceConfig &config)); MOCK_CONST_METHOD1(RemoveDevice, ErrCode(int networkId)); diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp index 7060a23a7..6aefc608c 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp @@ -150,6 +150,18 @@ HWTEST_F(SelfCureInterfaceTest, DealRssiLevelChangedTest, TestSize.Level1) EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); } +HWTEST_F(SelfCureInterfaceTest, NotifyWifiRoamingCompletedTest, TestSize.Level1) +{ + NotifyWifiRoamingCompletedTest(); + EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); +} + +HWTEST_F(SelfCureInterfaceTest, NotifyIpConfigCompletedTest, TestSize.Level1) +{ + NotifyIpConfigCompletedTest(); + EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); +} + HWTEST_F(SelfCureInterfaceTest, NotifyInternetFailureDetectedTest, TestSize.Level1) { int forceNoHttpCheck = 0; diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_service_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_service_test.cpp index b16c5dce9..30bc83c4a 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_service_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_service_test.cpp @@ -222,5 +222,17 @@ HWTEST_F(SelfCureServiceTest, CheckSelfCureWifiResultTest, TestSize.Level1) EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); } +HWTEST_F(SelfCureServiceTest, NotifyWifiRoamingCompletedTest, TestSize.Level1) +{ + std::string bssid = "0.0.0.0"; + pSelfCureService->NotifyWifiRoamingCompleted(bssid); + EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); +} + +HWTEST_F(SelfCureServiceTest, NotifyIpConfigCompletedTest, TestSize.Level1) +{ + pSelfCureService->NotifyIpConfigCompleted(); + EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); +} } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_state_machine_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_state_machine_test.cpp index 784e4c08b..dfcfec1a0 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_state_machine_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_state_machine_test.cpp @@ -650,6 +650,8 @@ public: pSelfCureStateMachine_->pInternetSelfCureState_->SelectSelfCureByFailedReason(internetFailedType); internetFailedType = WIFI_CURE_INTERNET_FAILED_TYPE_TCP; pSelfCureStateMachine_->pInternetSelfCureState_->SelectSelfCureByFailedReason(internetFailedType); + internetFailedType = WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING; + pSelfCureStateMachine_->pInternetSelfCureState_->SelectSelfCureByFailedReason(internetFailedType); pSelfCureStateMachine_->pInternetSelfCureState_->selfCureHistoryInfo_.resetSelfCureFailedCnt = SELFCURE_FAILED_CNT; @@ -715,6 +717,8 @@ public: pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureWifiLink(requestCureLevel); requestCureLevel = WIFI_CURE_RESET_LEVEL_HIGH_RESET; pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureWifiLink(requestCureLevel); + requestCureLevel = WIFI_CURE_RESET_LEVEL_RENEW_DHCP; + pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureWifiLink(requestCureLevel); } void SelfCureForStaticIpTest() @@ -785,6 +789,19 @@ public: pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureForReassoc(requestCureLevel); } + void SelfCureForRenewDhcpTest() + { + LOGI("Enter SelfCureForRenewDhcpTest"); + int requestCureLevel = WIFI_CURE_RESET_LEVEL_RENEW_DHCP; + pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureForReassoc(requestCureLevel); + + EXPECT_CALL(*pMockStaService, ReAssociate()).WillRepeatedly(Return(WIFI_OPT_FAILED)); + pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureForReassoc(requestCureLevel); + + EXPECT_CALL(*pMockStaService, ReAssociate()).WillRepeatedly(Return(WIFI_OPT_SUCCESS)); + pSelfCureStateMachine_->pInternetSelfCureState_->SelfCureForReassoc(requestCureLevel); + } + void IsNeedMultiGatewaySelfcureTest() { LOGI("Enter IsNeedMultiGatewaySelfcureTest"); @@ -2087,6 +2104,11 @@ HWTEST_F(SelfCureStateMachineTest, HandleSelfCureResultFailedTest, TestSize.Leve HandleSelfCureResultFailedTest(); } +HWTEST_F(SelfCureStateMachineTest, SelfCureForRenewDhcpTest, TestSize.Level1) +{ + SelfCureForReassocTest(); +} + HWTEST_F(SelfCureStateMachineTest, SelfcureForMultiGatewayTest, TestSize.Level1) { SelfcureForMultiGatewayTest(); diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface_test.cpp index 85fd03610..629aed95c 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface_test.cpp @@ -139,6 +139,20 @@ public: EXPECT_TRUE(pStaInterface->ReAssociate() == WIFI_OPT_FAILED); } + void StartRenewDhcpSuceess() + { + WifiDeviceConfig config; + EXPECT_CALL(*pMockStaService, ReAssociate()).WillRepeatedly(Return(WIFI_OPT_SUCCESS)); + EXPECT_TRUE(pStaInterface->StartRenewDhcp() == WIFI_OPT_SUCCESS); + } + + void StartRenewDhcpFail1() + { + WifiDeviceConfig config; + EXPECT_CALL(*pMockStaService, ReAssociate()).WillRepeatedly(Return(WIFI_OPT_FAILED)); + EXPECT_TRUE(pStaInterface->StartRenewDhcp() == WIFI_OPT_FAILED); + } + void DisconnectSuceess() { WifiDeviceConfig config; @@ -508,6 +522,16 @@ HWTEST_F(StaInterfaceTest, ReAssociateFail1, TestSize.Level1) ReAssociateFail1(); } +HWTEST_F(StaInterfaceTest, StartRenewDhcpSuceess, TestSize.Level1) +{ + StartRenewDhcpSuceess(); +} + +HWTEST_F(StaInterfaceTest, StartRenewDhcpFail1, TestSize.Level1) +{ + StartRenewDhcpFail1(); +} + HWTEST_F(StaInterfaceTest, DisconnectSuceess, TestSize.Level1) { DisconnectSuceess(); -- Gitee From 67adbc3530b9b1f8e7589f0795c5c5290e6ef296 Mon Sep 17 00:00:00 2001 From: xionglei Date: Thu, 26 Jun 2025 06:23:20 +0000 Subject: [PATCH 2/4] update wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp. renwe dhcp Signed-off-by: xionglei --- .../wifi_sta/self_cure_interface_test.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp index 6aefc608c..d976a7905 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/self_cure_interface_test.cpp @@ -114,6 +114,21 @@ public: pSelfCureInterface->pSelfCureService = nullptr; EXPECT_FALSE(pSelfCureInterface->IsWifiSelfcureDone()); } + + void NotifyWifiRoamingCompletedTest() + { + std::string bssid = "0.0.0.0"; + pSelfCureInterface->NotifyWifiRoamingCompleted(bssid); + pSelfCureInterface->pSelfCureService = nullptr; + pSelfCureInterface->NotifyWifiRoamingCompleted(bssid); + } + + void NotifyIpConfigCompletedTest() + { + pSelfCureInterface->NotifyIpConfigCompleted(); + pSelfCureInterface->pSelfCureService = nullptr; + pSelfCureInterface->NotifyIpConfigCompleted(); + } }; HWTEST_F(SelfCureInterfaceTest, IsWifiSelfcureDoneTest_01, TestSize.Level1) -- Gitee From 6c7fe1fe07cceaa115e6f6f07f9c43e4d488888a Mon Sep 17 00:00:00 2001 From: xionglei Date: Thu, 26 Jun 2025 06:27:31 +0000 Subject: [PATCH 3/4] update wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp. Signed-off-by: xionglei --- .../wifi_manage/wifi_sta/sta_state_machine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 485676750..50dd98db7 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 @@ -1442,7 +1442,7 @@ void StaStateMachine::ApLinkedState::HandleNetWorkConnectionEvent(InternalMessag } else { WIFI_LOGI("Arp reachable, stay in linked state."); } - if (pStaStateMachine->selfCureService_ != nullptr) { + if (pStaStateMachine->selfCureService_ != nullptr) { pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); } } @@ -2469,6 +2469,9 @@ void StaStateMachine::LinkedState::GoInState() pStaStateMachine->SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT); pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, pStaStateMachine->linkedInfo); + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyIpConfigCompleted(); + } return; } @@ -2789,9 +2792,6 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa WIFI_LOGI("Arp is reachable"); pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); } - if (pStaStateMachine->selfCureService_ != nullptr) { - pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); - } return ret; } -- Gitee From f42e38458bd3bdbcbf27b48d767f95ce01ce6a0d Mon Sep 17 00:00:00 2001 From: xionglei Date: Thu, 26 Jun 2025 08:02:54 +0000 Subject: [PATCH 4/4] update wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp. Signed-off-by: xionglei --- .../wifi_manage/wifi_sta/sta_state_machine.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 50dd98db7..753631b6a 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 @@ -1435,6 +1435,11 @@ void StaStateMachine::ApLinkedState::HandleNetWorkConnectionEvent(InternalMessag pStaStateMachine->linkedInfo.detailedState = DetailedState::CONNECTED; WifiConfigCenter::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo, pStaStateMachine->m_instId); pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, pStaStateMachine->linkedInfo); +#ifdef FEATURE_SELF_CURE_SUPPORT + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); + } +#else if (!pStaStateMachine->CanArpReachable()) { WIFI_LOGI("Arp not reachable, start to dhcp."); WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); @@ -1442,9 +1447,7 @@ void StaStateMachine::ApLinkedState::HandleNetWorkConnectionEvent(InternalMessag } else { WIFI_LOGI("Arp reachable, stay in linked state."); } - if (pStaStateMachine->selfCureService_ != nullptr) { - pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); - } +#endif } void StaStateMachine::ApLinkedState::HandleStaBssidChangedEvent(InternalMessagePtr msg) @@ -2783,6 +2786,11 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa pStaStateMachine->StopTimer(static_cast(CMD_AP_ROAMING_TIMEOUT_CHECK)); pStaStateMachine->StopTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT)); pStaStateMachine->AfterApLinkedprocess(bssid); +#ifdef FEATURE_SELF_CURE_SUPPORT + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); + } +#else if (!pStaStateMachine->CanArpReachable()) { WIFI_LOGI("Arp is not reachable"); WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); @@ -2792,6 +2800,7 @@ bool StaStateMachine::ApRoamingState::HandleNetworkConnectionEvent(InternalMessa WIFI_LOGI("Arp is reachable"); pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); } +#endif return ret; } -- Gitee