diff --git a/wifi/interfaces/inner_api/wifi_msg.h b/wifi/interfaces/inner_api/wifi_msg.h index ef67d38a78bfbb7addccd4b707603e9e0f00ac55..f5e4b644c4fa3199eb0440d96ffa999f6d229e2f 100644 --- a/wifi/interfaces/inner_api/wifi_msg.h +++ b/wifi/interfaces/inner_api/wifi_msg.h @@ -1016,6 +1016,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 645f417220c3248492e7853f1e1522bbc50dd40f..21ed14fc03801ada013bdbd3612a4f26a009600b 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 @@ -85,6 +85,22 @@ public: * @return result - true: no need broadcast state change, false: broadcast state normally */ virtual bool CheckSelfCureWifiResult(int event) = 0; + + /** + * @Description Check if Selfcure state, + * + * @param bssid - string + * @return notify WiFi to enter roaming selfcure + */ + virtual void NotifyWifiRoamingCompleted(std::string bssid) = 0; + + /** + * @Description Check if Selfcure state, + * + * + * @return 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 6e5b77f0f505b50f21d46981a66eee68d670bc44..ef2192c95dbbed8ba4dce0adac3cb9b60598b6dd 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 @@ -71,6 +71,8 @@ namespace Wifi { #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 #define WIFI_CURE_INTERNET_FAILED_TYPE_DNS 303 @@ -89,6 +91,8 @@ namespace Wifi { #define WIFI_CURE_CMD_SELF_CURE_FAILED 315 #define WIFI_CURE_CMD_STOP_SELF_CURE 316 +#define WIFI_CURE_INTERNET_FAILED_TYPE_ROAMING 317 + #define SELFCURE_FAIL_LENGTH 12 #define SELFCURE_HISTORY_LENGTH 14 @@ -124,7 +128,7 @@ namespace Wifi { #define FAST_ARP_DETECTED_MS (10 * 1000) #define DEFAULT_ARP_DETECTED_MS (60 * 1000) #define SELF_CURE_MONITOR_DELAYED_MS (2 * 1000) -#define DHCP_RENEW_TIMEOUT_MS (6 * 1000) +#define DHCP_RENEW_TIMEOUT_MS (18 * 1000) #define DNS_UPDATE_CONFIRM_DELAYED_MS (1 * 1000) #define IP_CONFIG_CONFIRM_DELAYED_MS (2 * 1000) #define DELAYED_DAYS_LOW (24 * 60 * 60 * 1000) 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 e1271443c572bec43b371fc7aa66038b4531aca3..9aab0428b15bd4cef02bc2bf812f913aee111791 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 @@ -179,5 +179,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 fd2e485d77145e0f2f7f7397c61da44a4a14a85e..224e6e0a6202587a85296fc95a46c4f76b127d06 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 @@ -119,6 +119,22 @@ public: * @return result - true: no need broadcast state change, false: broadcast state normally */ bool CheckSelfCureWifiResult(int event) override; + + /** + * @Description Check if Selfcure state, + * + * @param bssid - string + * @return notify WiFi to enter roaming selfcure + */ + void NotifyWifiRoamingCompleted(std::string bssid) override; + + /** + * @Description Check if Selfcure state, + * + * + * @return 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 4aa55d4dffbea2394a80f9526de1c31999d7d366..bc4f8e0420991a7da6692325585319e59580f6fc 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 e97385c742bdf50eaefa8a271c799a01333a137d..dbaed0a6ca855524ddd81cd08054b3c0d728354c 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 @@ -205,5 +205,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 88b5c3905032731c53e11be9ca2fc17067725942..08ae6fc473e4accb60d01f7729c47fa7d184343a 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 @@ -42,6 +42,8 @@ public: bool IsSelfCureL2Connecting(); void StopSelfCureWifi(int32_t status); bool CheckSelfCureWifiResult(int event); + 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 35c2d6497485dbaba8329c6d9f160f309d99f40c..a10ea5078f5328ad95ff8ce81171cb21bfd62553 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) @@ -311,12 +311,16 @@ int SelfCureStateMachine::ConnectedMonitorState::InitSelfCureCmsHandleMap() selfCureCmsHandleFuncMap_[WIFI_CURE_CMD_GATEWAY_CHANGED_DETECT] = [this](InternalMessagePtr msg) { this->HandleGatewayChanged(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; } @@ -492,6 +496,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) { @@ -890,6 +922,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; } @@ -1013,7 +1054,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; } @@ -1090,7 +1132,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; } @@ -1108,6 +1156,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); } } @@ -1307,6 +1357,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() || @@ -1379,6 +1452,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 || @@ -1527,6 +1627,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)); } } @@ -1805,6 +1907,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() @@ -1846,6 +1951,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; @@ -1875,6 +1984,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 b55abfa4caf5589d78fd43c6ec00d6af42bb706d..d7369963e42d7378124827ec3c2fe98103b5faee 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(); }; @@ -220,6 +221,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); @@ -241,6 +245,7 @@ public: void SelfcureForMultiGateway(InternalMessagePtr msg); bool IsNeedMultiGatewaySelfcure(); void SelfCureForStaticIp(int requestCureLevel); + void SelfCureForRenewDhcp(int requestCureLevel); void RequestUseStaticIpConfig(IpInfo &dhcpResult); IpInfo GetNextTestDhcpResults(); IpInfo GetRecordDhcpResults(); @@ -285,6 +290,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 471a3e690470f913060ae46794d4fa0df685953c..9aeedf5b1b5b33911c43803c60ec61a401f3b500 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 @@ -146,6 +146,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; } @@ -240,6 +243,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; + } } } @@ -272,6 +283,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 59b186b535e88ce900358bcd39607b2101793c09..49bb7a162be1aa965716b660bef2265143b673f9 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 127c57af6fa4790ede9eadb21d0da09288301d92..7ef42777c4947d327497c863316521c3f4fa85a1 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 521994973ebbe9a27f2544cd27092927353ff6a1..f6d05d227f6bc1a877ac7d81021ef0d1d16fb065 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 4d247e2cb51b7db2319dcc6aba859d5dc7ba3909..e9ec2d30af5f6c23245080d2386325f2c8efa4da 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,12 @@ 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 28d8230ef617649ac3ec676f8d6bc58ccd424fc9..b73475bb31ad1f6c84458e269f90858a4ac2b022 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 @@ -647,6 +647,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 497e732aca68f77a6b7302af97859557ca5bb036..4888b61acf3e269f5548638b6177d9ed9a6bbe18 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,12 @@ 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 26b750619c8e831423d5018e5f5b0a74604e169e..e6aecc7594e335916ba042075d9e049aeae11352 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 @@ -637,6 +637,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); }; @@ -1385,13 +1388,10 @@ void StaStateMachine::ApLinkedState::HandleStaBssidChangedEvent(InternalMessageP WifiConfigCenter::GetInstance().GetStaIfaceName(pStaStateMachine->m_instId)) != WIFI_HAL_OPT_OK) { WIFI_LOGE("SetBssid return fail."); } - if (!pStaStateMachine->CanArpReachable()) { - WIFI_LOGI("Arp not reachable, start to dhcp."); - WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); - pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); - } else { - WIFI_LOGI("Arp reachable, stay in linked state."); + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyWifiRoamingCompleted(bssid); } + WIFI_LOGI("Arp reachable, stay in linked state."); } void StaStateMachine::ApLinkedState::HandleLinkSwitchEvent(InternalMessagePtr msg) @@ -2271,6 +2271,9 @@ void StaStateMachine::LinkedState::GoInState() WifiSettings::GetInstance().SyncDeviceConfig(); pStaStateMachine->SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT); pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); + if (pStaStateMachine->selfCureService_ != nullptr) { + pStaStateMachine->selfCureService_->NotifyIpConfigCompleted(); + } pStaStateMachine->InvokeOnStaConnChanged(OperateResState::CONNECT_AP_CONNECTED, pStaStateMachine->linkedInfo); return; } @@ -2583,44 +2586,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); - if (!pStaStateMachine->CanArpReachable()) { - WIFI_LOGI("Arp is not reachable"); - WriteWifiSelfcureHisysevent(static_cast(WifiSelfcureType::ROAMING_ABNORMAL)); - /* The current state of StaStateMachine transfers to GetIpState. */ - pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); - } else { - WIFI_LOGI("Arp is reachable"); - pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); - } + WIFI_LOGI("Arp is reachable"); + pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); return ret; } -bool StaStateMachine::CanArpReachable() -{ - ArpChecker arpChecker; - std::string macAddress; - WifiConfigCenter::GetInstance().GetMacAddress(macAddress, m_instId); - IpInfo ipInfo; - WifiConfigCenter::GetInstance().GetIpInfo(ipInfo, m_instId); - std::string ipAddress = IpTools::ConvertIpv4Address(ipInfo.ipAddress); - std::string ifName = WifiConfigCenter::GetInstance().GetStaIfaceName(m_instId); - if (ipInfo.gateway == 0) { - WIFI_LOGI("gateway is empty"); - return false; - } - uint64_t arpRtt = 0; - std::string gateway = IpTools::ConvertIpv4Address(ipInfo.gateway); - arpChecker.Start(ifName, macAddress, ipAddress, gateway); - for (int i = 0; i < DEFAULT_NUM_ARP_PINGS; i++) { - if (arpChecker.DoArpCheck(MAX_ARP_CHECK_TIME, true, arpRtt)) { - WriteArpInfoHiSysEvent(arpRtt, 0); - return true; - } - } - WriteArpInfoHiSysEvent(arpRtt, 1); - return false; -} - ErrCode StaStateMachine::ConfigRandMacSelfCure(const int networkId) { WifiDeviceConfig config; @@ -4025,6 +3995,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 a6995de2685af3eb6518fc1fc178d8445bc5f952..6b9d7bdd8b5952668862ba3ec8b04292dbd0e8c4 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 @@ -231,6 +231,7 @@ public: void DealNetworkRemoved(InternalMessagePtr msg); void DealWpaStateChange(InternalMessagePtr msg); void DealMloStateChange(InternalMessagePtr msg); + void DealRenewDhcp(InternalMessagePtr msg); }; /** * @Description Definition of member function of SeparatedState class in StaStateMachine. @@ -996,7 +997,6 @@ private: void InvokeOnDhcpOfferReport(IpInfo ipInfo); WifiDeviceConfig getCurrentWifiDeviceConfig(); void InsertOrUpdateNetworkStatusHistory(const NetworkStatus &networkStatus, bool updatePortalAuthTime); - bool CanArpReachable(); void AddRandomMacCure(); ErrCode ConfigRandMacSelfCure(const int networkId); void UpdateLinkedBssid(std::string &bssid); diff --git a/wifi/test/wifi_standard/precompiled_macro/sta_state_machine_test.cpp b/wifi/test/wifi_standard/precompiled_macro/sta_state_machine_test.cpp index 6815044fd592b8aa05052957170d7075aa1fde39..1ebb8feb5d6b309113d94e5a0f57f423bed7fd59 100644 --- a/wifi/test/wifi_standard/precompiled_macro/sta_state_machine_test.cpp +++ b/wifi/test/wifi_standard/precompiled_macro/sta_state_machine_test.cpp @@ -66,7 +66,6 @@ static const std::string RANDOMMAC_BSSID = "01:23:45:67:89:a0"; static constexpr int NAPI_MAX_STR_LENT = 127; static constexpr int MIN_5G_FREQUENCY = 5160; static constexpr int INVALID_RSSI1 = -128; -static constexpr int GATE_WAY = 124; constexpr int TEN = 10; class StaStateMachineTest : public testing::Test { @@ -408,12 +407,6 @@ public: pStaStateMachine->DealScreenStateChangedEvent(msg); } - void CanArpReachableTest() - { - IpInfo ipInfo; - ipInfo.gateway =GATE_WAY; - pStaStateMachine->CanArpReachable(); - } void PortalExpiredDetectTest() { pStaStateMachine->portalState = PortalState::AUTHED; @@ -580,12 +573,6 @@ HWTEST_F(StaStateMachineTest, InvokeOnDhcpOfferReportTest, TestSize.Level1) EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); } -HWTEST_F(StaStateMachineTest, CanArpReachableTest, TestSize.Level1) -{ - CanArpReachableTest(); - EXPECT_FALSE(g_errLog.find("service is null") != std::string::npos); -} - HWTEST_F(StaStateMachineTest, PortalExpiredDetectTest, TestSize.Level1) { PortalExpiredDetectTest(); 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 4dc59cabedd06fe75f80a1e66c314492b7e25ddd..6e59245550dcc8d5c71a15bab3ebd5bc6bb10687 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 471d67150b4be8bc76b685df45d2340264f5dc14..47a18f457604a76518859371084e94a6d69a7952 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 1c3aa8c0bf4e4cb001e0a5f323871e8dd895e8e9..7b96ad65d82c1fd07fcbdc8fa56de13ed33ddcff 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 @@ -98,6 +98,21 @@ public: pSelfCureInterface->pSelfCureService = nullptr; pSelfCureInterface->DealRssiLevelChanged(rssi, instId); } + + 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, InitSelfCureServiceTest, TestSize.Level1) @@ -129,6 +144,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 e9d291a9b22dce70ca32b0fa4f7aa66b114467b0..b8f4a66d07ee3d92d43f17dc14525d8aae7ef232 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 @@ -152,6 +152,19 @@ HWTEST_F(SelfCureServiceTest, NotifyInternetFailureDetectedTest, 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); +} + HWTEST_F(SelfCureServiceTest, IsSelfCureOnGoingTest, TestSize.Level1) { EXPECT_EQ(pSelfCureService->IsSelfCureOnGoing(), false); 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 9b00106aca192cc0dc068292b40357170484e077..0a713a41b23e49180d4dffa65b92500da188ce8e 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 @@ -583,6 +583,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; @@ -648,6 +650,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() @@ -718,6 +722,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"); @@ -1928,6 +1945,11 @@ HWTEST_F(SelfCureStateMachineTest, SelfCureForReassocTest, TestSize.Level1) SelfCureForReassocTest(); } +HWTEST_F(SelfCureStateMachineTest, SelfCureForRenewDhcpTest, TestSize.Level1) +{ + SelfCureForReassocTest(); +} + HWTEST_F(SelfCureStateMachineTest, IsNeedMultiGatewaySelfcureTest, TestSize.Level1) { IsNeedMultiGatewaySelfcureTest(); 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 85fd03610aa3785cef1a3e5ff33a72ef6f2ba476..629aed95cbbd56d90cf64b95b7617317a3d2480d 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();