1 /* 2 * Copyright (C) 2021-2023 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_WIFI_WIFI_SCORER_IMPL_H_ 17 #define OHOS_WIFI_WIFI_SCORER_IMPL_H_ 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include <iomanip> 23 #include <sstream> 24 #include "network_selection.h" 25 26 27 namespace OHOS::Wifi::NetworkSelection { 28 29 class RssiScorer : public SimpleWifiScorer { 30 public: 31 RssiScorer(); 32 double Score(NetworkCandidate &networkCandidate) override; 33 }; 34 35 class LastHaveInternetTimeScorer : public SimpleWifiScorer { 36 public: 37 LastHaveInternetTimeScorer(); 38 double Score(NetworkCandidate &networkCandidate) override; 39 }; 40 41 class NetworkStatusHistoryScorer : public SimpleWifiScorer { 42 public: 43 NetworkStatusHistoryScorer(); 44 double Score(NetworkCandidate &networkCandidate) override; 45 }; 46 47 class ThroughputScorer : public IWifiScorer { 48 public: 49 void DoScore(NetworkCandidate &networkCandidate, ScoreResult &scoreResult) override; 50 51 private: 52 static double GetRssiBaseScore(NetworkCandidate &networkCandidate); 53 54 static double GetSavedNetworkAward(NetworkCandidate &networkCandidate); 55 56 bool IsRecentUserSelected(NetworkCandidate &networkCandidate) const; 57 58 bool IsSecurityNetwork(NetworkCandidate &networkCandidate) const; 59 static constexpr int SECURITY_AWARD_SCORE = 40; 60 static constexpr int SAVED_NETWORK_AWARD_SCORE = 40; 61 }; 62 63 class SecurityBonusScorer : public SimpleWifiScorer { 64 public: 65 SecurityBonusScorer(); 66 double Score(NetworkCandidate &networkCandidate) override; 67 private: 68 /** 69 * Function to determine whether the security type of the scanInfo is more secure. 70 * 71 * @param interScanInfo scanInfo 72 * @return true if the security of the scanInfo is more secure. 73 */ 74 bool IsHigherSecurityTypeFromScanResult(const InterScanInfo &interScanInfo); 75 76 /** 77 * Function to determine whether the security type of the scanInfo is Sae. 78 * 79 * @param interScanInfo scanInfo 80 * @return true if the security of the scanInfo is Sae. 81 */ 82 bool IsEncryptionSae(const InterScanInfo &interScanInfo); 83 84 /** 85 * Function to determine whether the security type of the scanInfo is PskSae. 86 * 87 * @param interScanInfo scanInfo 88 * @return true if the security of the scanInfo is PskSae. 89 */ 90 bool IsEncryptionPskSaeTransition(const InterScanInfo &interScanInfo); 91 92 /** 93 * Function to determine whether the security type of the scanInfo is Owe. 94 * 95 * @param interScanInfo scanInfo 96 * @return true if the security of the scanInfo is Owe. 97 */ 98 bool IsEncryptionOwe(const InterScanInfo &interScanInfo); 99 100 /** 101 * Function to determine whether the security type of the scanInfo is OweTransition. 102 * 103 * @param interScanInfo scanInfo 104 * @return true if the security of the scanInfo is OweTransition. 105 */ 106 bool IsEncryptionOweTransition(const InterScanInfo &interScanInfo); 107 108 /** 109 * Function to determine whether the security type of the scanInfo is Wpa3EnterpriseOnly. 110 * 111 * @param interScanInfo scanInfo 112 * @return true if the security of the scanInfo is Wpa3EnterpriseOnly. 113 */ 114 bool IsWpa3EnterpriseOnlyNetwork(const InterScanInfo &interScanInfo); 115 116 /** 117 * Function to determine whether the security type of the scanInfo is Wpa3EnterpriseTransition. 118 * 119 * @param interScanInfo scanInfo 120 * @return true if the security of the scanInfo is Wpa3EnterpriseTransition. 121 */ 122 bool IsWpa3EnterpriseTransitionNetwork(const InterScanInfo &interScanInfo); 123 124 /** 125 * Function to determine whether the security type is existed in the scanInfo. 126 * 127 * @param interScanInfo scanInfo 128 * @param securityType target security type 129 * @return true if the security type existed 130 */ 131 bool ExistSecurityType(const InterScanInfo &interScanInfo, const std::string &securityType); 132 }; 133 134 class RssiLevelBonusScorer : public SimpleWifiScorer { 135 public: 136 RssiLevelBonusScorer(); 137 double Score(NetworkCandidate &networkCandidate) override; 138 }; 139 140 class SignalLevelScorer : public SimpleWifiScorer { 141 public: 142 SignalLevelScorer(); 143 double Score(NetworkCandidate &networkCandidate) override; 144 }; 145 146 class Network5gBonusScorer : public SimpleWifiScorer { 147 public: 148 Network5gBonusScorer(); 149 double Score(NetworkCandidate &networkCandidate) override; 150 }; 151 152 class SavedNetworkScorer : public CompositeWifiScorer { 153 public: 154 explicit SavedNetworkScorer(const std::string &scorerName); 155 }; 156 157 class NoInternetNetworkStatusHistoryScorer : public SimpleWifiScorer { 158 public: 159 NoInternetNetworkStatusHistoryScorer(); 160 double Score(NetworkCandidate &networkCandidate) override; 161 }; 162 163 class ApQualityScorer : public CompositeWifiScorer { 164 public: 165 explicit ApQualityScorer(const std::string &scorerName); 166 }; 167 168 } 169 170 #endif 171