1 /* 2 * Copyright (C) 2021-2022 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_INTERNAL_MSG_H 17 #define OHOS_WIFI_INTERNAL_MSG_H 18 19 #include <unordered_set> 20 #include "wifi_ap_msg.h" 21 #include "wifi_hid2d_msg.h" 22 #include "wifi_msg.h" 23 #include "wifi_p2p_msg.h" 24 #include "wifi_scan_msg.h" 25 #include "inter_scan_info.h" 26 27 namespace OHOS { 28 namespace Wifi { 29 constexpr int REOPEN_STA_INTERVAL = 500; /* when reopen sta, need over last close sta time then interval */ 30 constexpr int DEVICE_CONFIG_INDEX_SSID = 0; 31 constexpr int DEVICE_CONFIG_INDEX_BSSID = 1; 32 constexpr int PRIORITY_1 = 1; 33 constexpr int PRIORITY_2 = 2; 34 constexpr int PRIORITY_3 = 3; 35 constexpr int SCORE_SLOPE = 5; 36 constexpr int INIT_SCORE = 10; 37 constexpr int SAME_BSSID_SCORE = 8; 38 constexpr int SAME_NETWORK_SCORE = 5; 39 constexpr int FREQUENCY_5_GHZ_SCORE = 10; 40 constexpr int LAST_SELECTION_SCORE = 120; 41 constexpr int SECURITY_SCORE = 20; 42 constexpr int NORMAL_SCORE = 10; 43 constexpr int MIN_RSSI_24GHZ = -80; 44 constexpr int MIN_RSSI_5GHZ = -77; 45 constexpr int RSSI_LEVEL_1_2G = -88; 46 constexpr int RSSI_LEVEL_2_2G = -82; 47 constexpr int RSSI_LEVEL_3_2G = -75; 48 constexpr int RSSI_LEVEL_4_2G = -65; 49 constexpr int RSSI_LEVEL_1_5G = -85; 50 constexpr int RSSI_LEVEL_2_5G = -79; 51 constexpr int RSSI_LEVEL_3_5G = -72; 52 constexpr int RSSI_LEVEL_4_5G = -65; 53 constexpr int AIRPLANE_MODE_OPEN = 1; 54 constexpr int AIRPLANE_MODE_CLOSE = 2; 55 #define DNS_IP_ADDR_LEN 15 56 #define WIFI_FIRST_DNS_NAME "const.wifi.wifi_first_dns" 57 58 constexpr int FUZZY_BSSID_MAX_MATCH_CNT = 30; 59 60 enum class WifiOprMidState { CLOSED = 0, OPENING = 1, RUNNING = 2, CLOSING = 3, SEMI_ACTIVE, UNKNOWN }; 61 62 enum class WifiFeatures { 63 WIFI_FEATURE_INFRA = 0x0001, // The feature id indicates support basic infrastructure mode 64 WIFI_FEATURE_INFRA_5G = 0x0002, // The feature id indicates support 5 GHz Band 65 WIFI_FEATURE_PASSPOINT = 0x0004, // The feature id indicates support GAS/ANQP 66 WIFI_FEATURE_P2P = 0x0008, // The feature id indicates support Wifi-Direct 67 WIFI_FEATURE_MOBILE_HOTSPOT = 0x0010, // The feature id indicates support Soft AP 68 WIFI_FEATURE_AWARE = 0x0040, // The feature id indicates support Wi-Fi AWare networking 69 WIFI_FEATURE_AP_STA = 0x8000, // The feature id indicates support AP STA Concurrency 70 WIFI_FEATURE_WPA3_SAE = 0x8000000, // The feature id indicates support WPA3-Personal SAE 71 WIFI_FEATURE_WPA3_SUITE_B = 0x10000000, // The feature id indicates support WPA3-Enterprise Suite-B 72 WIFI_FEATURE_OWE = 0x20000000, // The feature id indicates support Enhanced Open 73 }; 74 75 enum class OperateResState { 76 OPEN_WIFI_OPENING = 0, /* open wifi opening */ 77 OPEN_WIFI_SUCCEED, /* open wifi succeed */ 78 OPEN_WIFI_FAILED, /* open wifi failed */ 79 OPEN_WIFI_OVERRIDE_OPEN_FAILED, /* enable wifi repeatedly */ 80 OPEN_WIFI_DISABLED, /* open wifi failed, set wifi disabled */ 81 OPEN_WIFI_SUPPLICANT_INIT_FAILED, /* wpa_supplicant not inited or init failed */ 82 OPEN_WIFI_OPEN_SUPPLICANT_FAILED, /* wpa_supplicant start failed */ 83 OPEN_WIFI_CONN_SUPPLICANT_FAILED, /* connect wpa_supplicant failed */ 84 CLOSE_WIFI_CLOSING, /* close wifi closing */ 85 CLOSE_WIFI_SUCCEED, /* close wifi succeed */ 86 CLOSE_WIFI_FAILED, /* close wifi failed */ 87 CONNECT_CONNECTING, /* connecting */ 88 CONNECT_CONNECTING_TIMEOUT, /* connecting time out */ 89 CONNECT_TO_OWN_AP_FAILED, /* connect own ap failed */ 90 CONNECT_ENABLE_NETWORK_FAILED, /* wpa_supplicant enable network failed */ 91 CONNECT_SELECT_NETWORK_FAILED, /* wpa_supplicant select network failed */ 92 CONNECT_SAVE_DEVICE_CONFIG_FAILED, /* wpa_supplicant save network config failed */ 93 CONNECT_AP_CONNECTED, /* connect succeed */ 94 CONNECT_CHECK_PORTAL, /* check connect to a portal hotspot */ 95 CONNECT_NETWORK_ENABLED, /* can visit internet */ 96 CONNECT_NETWORK_DISABLED, /* cannot visit internet */ 97 DISCONNECT_DISCONNECTING, /* disconnecting */ 98 DISCONNECT_DISCONNECT_FAILED, /* disconnect failed */ 99 DISCONNECT_DISCONNECTED, /* disconnect succeed */ 100 CONNECT_PASSWORD_WRONG, /* wrong password */ 101 CONNECT_CONNECTION_FULL, /* connection full */ 102 CONNECT_CONNECTION_REJECT, /* connection reject */ 103 CONNECT_OBTAINING_IP, /* obtain ip */ 104 CONNECT_OBTAINING_IP_FAILED, /* obtain ip FAILED */ 105 CONNECT_ASSOCIATING, 106 CONNECT_ASSOCIATED, 107 OPEN_SCAN_ONLY_OPENING, /* open scan only opening */ 108 OPEN_SCAN_ONLY_SUCCEED, /* open scan only succeed */ 109 OPEN_SCAN_ONLY_FAILED, /* open scan only failed */ 110 CLOSE_SCAN_ONLY_CLOSING, /* close scan only closing */ 111 CLOSE_SCAN_ONLY_SUCCEED, /* close scan only succeed */ 112 CLOSE_SCAN_ONLY_FAILED, /* close scan only failed */ 113 SPECIAL_CONNECTED, /* special connected */ 114 ENABLE_SEMI_WIFI_OPENING, /* enable semi wifi opening */ 115 ENABLE_SEMI_WIFI_SUCCEED, /* enable semi wifi succeed */ 116 ENABLE_SEMI_WIFI_FAILED, /* enable semi wifi failed */ 117 }; 118 119 /* is wps connected to a network */ 120 enum class IsWpsConnected { 121 WPS_CONNECTED = 0, 122 WPS_INVALID = -1, 123 }; 124 125 struct WifiCallingInfo { 126 int callingUid; 127 int callingPid; 128 int callingTokenId; 129 std::unordered_set<int> regCallBackEventId; 130 }; 131 132 struct SingleAppForbid { 133 int appID; 134 ScanIntervalMode scanIntervalMode; 135 int lessThanIntervalCount; 136 time_t continueScanTime; 137 time_t blockListScanTime; 138 int expScanCount; 139 int fixedScanCount; 140 time_t fixedCurrentTime; SingleAppForbidSingleAppForbid141 SingleAppForbid() 142 { 143 appID = 0; 144 lessThanIntervalCount = 0; 145 continueScanTime = 0; 146 blockListScanTime = 0; 147 expScanCount = 0; 148 fixedScanCount = 0; 149 fixedCurrentTime = 0; 150 } 151 }; 152 153 struct CfgInfo { 154 CfgType type; 155 char* data; 156 int dataLen; CfgInfoCfgInfo157 CfgInfo() 158 { 159 type = CfgType::CFG_INVALID; 160 data = nullptr; 161 dataLen = 0; 162 } 163 }; 164 165 struct WifiEventCallbackMsg { 166 int msgCode; 167 int msgData; 168 int id; 169 std::string pinCode; /* wps pin mode code */ 170 WifiLinkedInfo linkInfo; 171 StationInfo staInfo; 172 std::vector<WifiP2pDevice> device; 173 std::vector<WifiP2pServiceInfo> serviceInfo; 174 WifiP2pLinkedInfo p2pInfo; 175 WifiP2pDevice p2pDevice; 176 P2pActionCallback p2pAction; 177 CfgInfo* cfgInfo; 178 GcInfo gcInfo; 179 std::string privateWfdInfo; WifiEventCallbackMsgWifiEventCallbackMsg180 WifiEventCallbackMsg() 181 { 182 msgCode = 0; 183 msgData = 0; 184 id = 0; 185 p2pAction = P2pActionCallback::UNKNOWN; 186 cfgInfo = nullptr; 187 } 188 }; 189 190 enum class DhcpIpType { /* dhcp IP type: ipv4 ipv6 mix */ 191 DHCP_IPTYPE_IPV4, 192 DHCP_IPTYPE_IPV6, 193 DHCP_IPTYPE_MIX, 194 }; 195 196 enum class OperatorWifiType { 197 WIFI_DISABLED, 198 WIFI_ENABLED, 199 WIFI_ENABLED_AIRPLANEMODE_OVERRIDE, 200 WIFI_DISABLED_AIRPLANEMODE_ON, 201 }; 202 203 enum class StaApExclusionType { 204 USER_OPEN_WIFI_AUTO_STOP_AP, /* User open wifi auto stop ap */ 205 USER_OPEN_AP_AUTO_STOP_WIFI, /* User open ap auto stop wifi */ 206 USER_CLOSE_AP_AUTO_START_WIFI, /* User close ap auto start wifi */ 207 INITIAL_TYPE, /* initial type */ 208 }; 209 210 /* wifi config store */ 211 struct WifiConfig { 212 bool scanAlwaysSwitch; /* scan always switch */ 213 int staAirplaneMode; /* operator wifi type */ 214 int64_t persistWifiTime; /* persist wifi state time */ 215 int toggleWifiCaller; 216 bool canOpenStaWhenAirplane; /* if airplane is opened, whether can open sta */ 217 bool openWifiWhenAirplane; 218 bool wifiDisabledByAirplane; 219 /** 220 * last sta service state, when service started, power 221 * saving off, airplane mode off we use this saved state to 222 * discuss whether need restore sta service. when open sta 223 * service, set 1; when user call DisableWifi succeed, 224 * set 0; when sta is semi active, set 2; 225 */ 226 int staLastState; 227 int lastAirplaneMode; 228 int savedDeviceAppraisalPriority; 229 int scoretacticsScoreSlope; 230 int scoretacticsInitScore; 231 int scoretacticsSameBssidScore; 232 int scoretacticsSameNetworkScore; 233 int scoretacticsFrequency5GHzScore; 234 int scoretacticsLastSelectionScore; 235 int scoretacticsSecurityScore; 236 int scoretacticsNormalScore; 237 bool whetherToAllowNetworkSwitchover; 238 int dhcpIpType; 239 std::string defaultWifiInterface; 240 bool preLoadSta; 241 bool preLoadScan; 242 bool preLoadAp; 243 bool preLoadP2p; 244 bool preLoadAware; 245 bool preLoadEnhance; 246 bool supportHwPnoFlag; 247 int minRssi2Dot4Ghz; 248 int minRssi5Ghz; 249 int firstRssiLevel2G; 250 int secondRssiLevel2G; 251 int thirdRssiLevel2G; 252 int fourthRssiLevel2G; 253 int firstRssiLevel5G; 254 int secondRssiLevel5G; 255 int thirdRssiLevel5G; 256 int fourthRssiLevel5G; 257 std::string strDnsBak; 258 bool isLoadStabak; 259 bool scanOnlySwitch; 260 std::string realMacAddress; 261 int staApExclusionType; 262 WifiConfigWifiConfig263 WifiConfig() 264 { 265 scanAlwaysSwitch = false; 266 staAirplaneMode = static_cast<int>(OperatorWifiType::WIFI_DISABLED); 267 persistWifiTime = 0; 268 toggleWifiCaller = 0; 269 canOpenStaWhenAirplane = true; 270 openWifiWhenAirplane = false; 271 wifiDisabledByAirplane = false; 272 staLastState = 0; 273 lastAirplaneMode = AIRPLANE_MODE_CLOSE; 274 savedDeviceAppraisalPriority = PRIORITY_1; 275 scoretacticsScoreSlope = SCORE_SLOPE; 276 scoretacticsInitScore = INIT_SCORE; 277 scoretacticsSameBssidScore = SAME_BSSID_SCORE; 278 scoretacticsSameNetworkScore = SAME_NETWORK_SCORE; 279 scoretacticsFrequency5GHzScore = FREQUENCY_5_GHZ_SCORE; 280 scoretacticsLastSelectionScore = LAST_SELECTION_SCORE; 281 scoretacticsSecurityScore = SECURITY_SCORE; 282 scoretacticsNormalScore = NORMAL_SCORE; 283 whetherToAllowNetworkSwitchover = true; 284 dhcpIpType = static_cast<int>(DhcpIpType::DHCP_IPTYPE_MIX); 285 defaultWifiInterface = "wlan0"; 286 preLoadSta = false; 287 preLoadScan = false; 288 preLoadAp = false; 289 preLoadP2p = false; 290 preLoadAware = false; 291 supportHwPnoFlag = true; 292 minRssi2Dot4Ghz = MIN_RSSI_24GHZ; 293 minRssi5Ghz = MIN_RSSI_5GHZ; 294 firstRssiLevel2G = RSSI_LEVEL_1_2G; 295 secondRssiLevel2G = RSSI_LEVEL_2_2G; 296 thirdRssiLevel2G = RSSI_LEVEL_3_2G; 297 fourthRssiLevel2G = RSSI_LEVEL_4_2G; 298 firstRssiLevel5G = RSSI_LEVEL_1_5G; 299 secondRssiLevel5G = RSSI_LEVEL_2_5G; 300 thirdRssiLevel5G = RSSI_LEVEL_3_5G; 301 fourthRssiLevel5G = RSSI_LEVEL_4_5G; 302 strDnsBak = "0.0.0.0"; 303 isLoadStabak = true; 304 preLoadEnhance = false; 305 scanOnlySwitch = true; 306 realMacAddress = ""; 307 staApExclusionType = static_cast<int>(StaApExclusionType::INITIAL_TYPE); 308 } 309 }; 310 311 struct TrustListPolicy { 312 int sceneId = 0; /* scene id */ 313 std::string sceneName; /* scene name, just to read. */ 314 std::string trustList; /* trust list, eg: for A,B,and C,the format is A|B|C */ 315 TrustListPolicyTrustListPolicy316 TrustListPolicy() 317 { 318 sceneId = 0; 319 sceneName = ""; 320 trustList = ""; 321 } 322 }; 323 324 struct MovingFreezePolicy { 325 std::string trustList; /* trust list */ 326 MovingFreezePolicyMovingFreezePolicy327 MovingFreezePolicy() 328 { 329 trustList = ""; 330 } 331 }; 332 333 /* wifi RandomMac store */ 334 struct WifiStoreRandomMac { 335 int version = 0; 336 std::string ssid; 337 std::string keyMgmt; 338 std::string peerBssid; 339 std::string randomMac; 340 std::string preSharedKey; 341 std::unordered_set<std::string> fuzzyBssids; 342 }; 343 344 struct PackageFilterConf { 345 std::string filterName; 346 std::vector<std::string> packageList; 347 }; 348 349 struct VariableConf { 350 std::string variableName; 351 std::string variableValue; 352 }; 353 } // namespace Wifi 354 } // namespace OHOS 355 #endif 356