1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_SELF_CURE_UTILS_H 17 #define OHOS_SELF_CURE_UTILS_H 18 19 #include "singleton.h" 20 #include "netsys_dns_report_callback.h" 21 #include "self_cure_state_machine.h" 22 23 namespace OHOS { 24 namespace Wifi { 25 constexpr int VEC_POS_3 = 3; 26 constexpr int GET_NEXT_IP_MAC_CNT = 10; 27 28 inline constexpr const char* CONST_WIFI_DNSCURE_IPCFG = "const.wifi.dnscure_ipcfg"; 29 class SelfCureUtils { 30 public: 31 SelfCureUtils(); 32 ~SelfCureUtils(); 33 static SelfCureUtils& GetInstance(); 34 void RegisterDnsResultCallback(); 35 void UnRegisterDnsResultCallback(); 36 int32_t GetCurrentDnsFailedCounter(); 37 void ClearDnsFailedCounter(); 38 int32_t GetSelfCureType(int32_t currentCureLevel); 39 40 std::string GetNextIpAddr(const std::string& gateway, const std::string& currentAddr, 41 const std::vector<std::string>& testedAddr); 42 static void UpdateSelfCureHistoryInfo(WifiSelfCureHistoryInfo &historyInfo, int requestCureLevel, bool success); 43 static void UpdateSelfCureConnectHistoryInfo(WifiSelfCureHistoryInfo &historyInfo, int requestCureLevel, 44 bool success); 45 bool AllowSelfCure(const WifiSelfCureHistoryInfo &historyInfo, int requestCureLevel); 46 bool SelfCureAcceptable(WifiSelfCureHistoryInfo &historyInfo, int requestCureLevel); 47 std::vector<std::string> TransStrToVec(std::string str, char c); 48 std::string TransVecToIpAddress(const std::vector<uint32_t>& vec); 49 std::vector<uint32_t> TransIpAddressToVec(std::string addr); 50 int String2InternetSelfCureHistoryInfo(const std::string selfCureHistory, WifiSelfCureHistoryInfo &info); 51 int SetSelfCureFailInfo(OHOS::Wifi::WifiSelfCureHistoryInfo &info, std::vector<std::string>& histories, int cnt); 52 int SetSelfCureConnectFailInfo(WifiSelfCureHistoryInfo &info, std::vector<std::string>& histories, int cnt); 53 bool IsIpConflictDetect(); 54 std::string GetSelfCureHistory(); 55 void ReportNoInternetChrEvent(); 56 private: 57 class SelfCureDnsResultCallback : public NetManagerStandard::NetsysDnsReportCallback { 58 public: SelfCureDnsResultCallback()59 SelfCureDnsResultCallback() {}; ~SelfCureDnsResultCallback()60 ~SelfCureDnsResultCallback() {}; 61 int32_t OnDnsResultReport(uint32_t size, const std::list<NetsysNative::NetDnsResultReport> reports); 62 private: 63 int32_t GetWifiNetId(); 64 int32_t GetDefaultNetId(); 65 public: 66 int32_t dnsFailedCounter_ = 0; 67 }; 68 69 private: 70 sptr<SelfCureDnsResultCallback> dnsResultCallback_{nullptr}; 71 }; 72 } // namespace Wifi 73 } // namespace OHOS 74 #endif // OHOS_SELF_CURE_UTILS_H