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 "wifi_ap_msg.h" 20 #include "wifi_hid2d_msg.h" 21 #include "wifi_msg.h" 22 #include "wifi_p2p_msg.h" 23 #include "wifi_scan_msg.h" 24 25 namespace OHOS { 26 namespace Wifi { 27 constexpr int REOPEN_STA_INTERVAL = 500; /* when reopen sta, need over last close sta time then interval */ 28 constexpr int DEVICE_CONFIG_INDEX_SSID = 0; 29 constexpr int DEVICE_CONFIG_INDEX_BSSID = 1; 30 constexpr int PRIORITY_1 = 1; 31 constexpr int PRIORITY_2 = 2; 32 constexpr int PRIORITY_3 = 3; 33 constexpr int SCORE_SLOPE = 5; 34 constexpr int INIT_SCORE = 10; 35 constexpr int SAME_BSSID_SCORE = 8; 36 constexpr int SAME_NETWORK_SCORE = 5; 37 constexpr int FREQUENCY_5_GHZ_SCORE = 10; 38 constexpr int LAST_SELECTION_SCORE = 120; 39 constexpr int SECURITY_SCORE = 20; 40 constexpr int NORMAL_SCORE = 10; 41 constexpr int MIN_RSSI_24GHZ = -80; 42 constexpr int MIN_RSSI_5GHZ = -77; 43 constexpr int RSSI_LEVEL_1_2G = -88; 44 constexpr int RSSI_LEVEL_2_2G = -82; 45 constexpr int RSSI_LEVEL_3_2G = -75; 46 constexpr int RSSI_LEVEL_4_2G = -65; 47 constexpr int RSSI_LEVEL_1_5G = -85; 48 constexpr int RSSI_LEVEL_2_5G = -79; 49 constexpr int RSSI_LEVEL_3_5G = -72; 50 constexpr int RSSI_LEVEL_4_5G = -65; 51 52 enum class WifiOprMidState { CLOSED = 0, OPENING = 1, RUNNING = 2, CLOSING = 3, UNKNOWN }; 53 54 enum class WifiFeatures { 55 WIFI_FEATURE_INFRA = 0x0001, // The feature id indicates support basic infrastructure mode 56 WIFI_FEATURE_INFRA_5G = 0x0002, // The feature id indicates support 5 GHz Band 57 WIFI_FEATURE_PASSPOINT = 0x0004, // The feature id indicates support GAS/ANQP 58 WIFI_FEATURE_P2P = 0x0008, // The feature id indicates support Wifi-Direct 59 WIFI_FEATURE_MOBILE_HOTSPOT = 0x0010, // The feature id indicates support Soft AP 60 WIFI_FEATURE_AWARE = 0x0040, // The feature id indicates support Wi-Fi AWare networking 61 WIFI_FEATURE_AP_STA = 0x8000, // The feature id indicates support AP STA Concurrency 62 WIFI_FEATURE_WPA3_SAE = 0x8000000, // The feature id indicates support WPA3-Personal SAE 63 WIFI_FEATURE_WPA3_SUITE_B = 0x10000000, // The feature id indicates support WPA3-Enterprise Suite-B 64 WIFI_FEATURE_OWE = 0x20000000, // The feature id indicates support Enhanced Open 65 }; 66 67 enum class OperateResState { 68 OPEN_WIFI_OPENING = 0, /* open wifi opening */ 69 OPEN_WIFI_SUCCEED, /* open wifi succeed */ 70 OPEN_WIFI_FAILED, /* open wifi failed */ 71 OPEN_WIFI_OVERRIDE_OPEN_FAILED, /* enable wifi repeatedly */ 72 OPEN_WIFI_DISABLED, /* open wifi failed, set wifi disabled */ 73 OPEN_WIFI_SUPPLICANT_INIT_FAILED, /* wpa_supplicant not inited or init failed */ 74 OPEN_WIFI_OPEN_SUPPLICANT_FAILED, /* wpa_supplicant start failed */ 75 OPEN_WIFI_CONN_SUPPLICANT_FAILED, /* connect wpa_supplicant failed */ 76 CLOSE_WIFI_CLOSING, /* close wifi closing */ 77 CLOSE_WIFI_SUCCEED, /* close wifi succeed */ 78 CLOSE_WIFI_FAILED, /* close wifi failed */ 79 CONNECT_CONNECTING, /* connecting */ 80 CONNECT_CONNECTING_TIMEOUT, /* connecting time out */ 81 CONNECT_TO_OWN_AP_FAILED, /* connect own ap failed */ 82 CONNECT_ENABLE_NETWORK_FAILED, /* wpa_supplicant enable network failed */ 83 CONNECT_SELECT_NETWORK_FAILED, /* wpa_supplicant select network failed */ 84 CONNECT_SAVE_DEVICE_CONFIG_FAILED, /* wpa_supplicant save network config failed */ 85 CONNECT_AP_CONNECTED, /* connect succeed */ 86 CONNECT_CHECK_PORTAL, /* check connect to a portal hotspot */ 87 CONNECT_NETWORK_ENABLED, /* can visit internet */ 88 CONNECT_NETWORK_DISABLED, /* cannot visit internet */ 89 DISCONNECT_DISCONNECTING, /* disconnecting */ 90 DISCONNECT_DISCONNECT_FAILED, /* disconnect failed */ 91 DISCONNECT_DISCONNECTED, /* disconnect succeed */ 92 CONNECT_PASSWORD_WRONG, /* wrong password */ 93 CONNECT_CONNECTION_FULL, /* connection full */ 94 CONNECT_CONNECTION_REJECT, /* connection reject */ 95 CONNECT_OBTAINING_IP, /* obtain ip */ 96 CONNECT_OBTAINING_IP_FAILED, /* obtain ip FAILED */ 97 CONNECT_ASSOCIATING, 98 CONNECT_ASSOCIATED, 99 }; 100 101 /* is wps connected to a network */ 102 enum class IsWpsConnected { 103 WPS_CONNECTED = 0, 104 WPS_INVALID = -1, 105 }; 106 107 enum class Ant { 108 NETWORK_PRIVATE = 0, 109 NETWORK_PRIVATEWITHGUEST = 1, 110 NETWORK_CHARGEABLEPUBLIC = 2, 111 NETWORK_FREEPUBLIC = 3, 112 NETWORK_PERSONAL = 4, 113 NETWORK_EMERGENCYONLY = 5, 114 NETWORK_RESVD6 = 6, 115 NETWORK_RESVD7 = 7, 116 NETWORK_RESVD8 = 8, 117 NETWORK_RESVD9 = 9, 118 NETWORK_RESVD10 = 10, 119 NETWORK_RESVD11 = 11, 120 NETWORK_RESVD12 = 12, 121 NETWORK_RESVD13 = 13, 122 NETWORK_TESTOREXPERIMENTAL = 14, 123 NETWORK_WILDCARD = 15, 124 NETWORK_ANT_INVALID = 16 125 }; 126 127 struct InterScanInfo { 128 std::string bssid; 129 std::string ssid; 130 /** 131 * Network performance, including authentication, 132 * key management, and encryption mechanisms 133 * supported by the access point 134 */ 135 std::string capabilities; 136 int frequency; 137 int band; /* ap band, 1: 2.4G, 2: 5G */ 138 WifiChannelWidth channelWidth; 139 int centerFrequency0; 140 int centerFrequency1; 141 int rssi; /* signal level */ 142 WifiSecurity securityType; 143 std::vector<WifiInfoElem> infoElems; 144 int64_t features; 145 int64_t timestamp; 146 Ant ant; 147 InterScanInfoInterScanInfo148 InterScanInfo() 149 : frequency(0), 150 band(0), 151 channelWidth(WifiChannelWidth::WIDTH_INVALID), 152 centerFrequency0(0), 153 centerFrequency1(0), 154 rssi(0), 155 securityType(WifiSecurity::INVALID), 156 features(0), 157 timestamp(0), 158 ant(Ant::NETWORK_ANT_INVALID) 159 {} 160 ~InterScanInfoInterScanInfo161 ~InterScanInfo() 162 {} 163 GetDeviceMgmtInterScanInfo164 void GetDeviceMgmt(std::string &mgmt) 165 { 166 switch (securityType) { 167 case WifiSecurity::PSK: 168 mgmt = "WPA-PSK"; 169 break; 170 case WifiSecurity::EAP: 171 mgmt = "WPA-EAP"; 172 break; 173 case WifiSecurity::SAE: 174 mgmt = "SAE"; 175 break; 176 case WifiSecurity::OWE: 177 mgmt = "OWE"; 178 break; 179 default: 180 mgmt = "NONE"; 181 break; 182 } 183 } 184 }; 185 186 struct WifiCallingInfo { 187 int callingUid; 188 int callingPid; 189 }; 190 191 struct SingleAppForbid { 192 int appID; 193 ScanIntervalMode scanIntervalMode; 194 int lessThanIntervalCount; 195 time_t continueScanTime; 196 time_t blockListScanTime; 197 int expScanCount; 198 int fixedScanCount; 199 time_t fixedCurrentTime; SingleAppForbidSingleAppForbid200 SingleAppForbid() 201 { 202 appID = 0; 203 lessThanIntervalCount = 0; 204 continueScanTime = 0; 205 blockListScanTime = 0; 206 expScanCount = 0; 207 fixedScanCount = 0; 208 fixedCurrentTime = 0; 209 } 210 }; 211 212 struct CfgInfo { 213 CfgType type; 214 char* data; 215 int dataLen; CfgInfoCfgInfo216 CfgInfo() 217 { 218 type = CfgType::CFG_INVALID; 219 data = nullptr; 220 dataLen = 0; 221 } 222 }; 223 224 struct WifiEventCallbackMsg { 225 int msgCode; 226 int msgData; 227 int id; 228 std::string pinCode; /* wps pin mode code */ 229 WifiLinkedInfo linkInfo; 230 StationInfo staInfo; 231 std::vector<WifiP2pDevice> device; 232 std::vector<WifiP2pServiceInfo> serviceInfo; 233 WifiP2pLinkedInfo p2pInfo; 234 WifiP2pDevice p2pDevice; 235 P2pActionCallback p2pAction; 236 CfgInfo* cfgInfo; WifiEventCallbackMsgWifiEventCallbackMsg237 WifiEventCallbackMsg() 238 { 239 msgCode = 0; 240 msgData = 0; 241 id = 0; 242 p2pAction = P2pActionCallback::UNKNOWN; 243 cfgInfo = nullptr; 244 } 245 }; 246 247 enum class DhcpIpType { /* dhcp IP type: ipv4 ipv6 mix */ 248 DHCP_IPTYPE_IPV4, 249 DHCP_IPTYPE_IPV6, 250 DHCP_IPTYPE_MIX, 251 }; 252 253 /* wifi config store */ 254 struct WifiConfig { 255 bool scanAlwaysSwitch; /* scan always switch */ 256 bool staAirplaneMode; /* when open airplane mode, whether close sta */ 257 bool canOpenStaWhenAirplane; /* if airplane is opened, whether can open sta */ 258 /** 259 * last sta service state, when service started, power 260 * saving off, airplane mode off we use this saved state to 261 * discuss whether need restore sta service. when open sta 262 * service, set true; when user call DisableWifi succeed, 263 * set false; 264 */ 265 bool staLastState; 266 int savedDeviceAppraisalPriority; 267 int scoretacticsScoreSlope; 268 int scoretacticsInitScore; 269 int scoretacticsSameBssidScore; 270 int scoretacticsSameNetworkScore; 271 int scoretacticsFrequency5GHzScore; 272 int scoretacticsLastSelectionScore; 273 int scoretacticsSecurityScore; 274 int scoretacticsNormalScore; 275 bool whetherToAllowNetworkSwitchover; 276 int dhcpIpType; 277 std::string defaultWifiInterface; 278 bool preLoadSta; 279 bool preLoadScan; 280 bool preLoadAp; 281 bool preLoadP2p; 282 bool preLoadAware; 283 bool supportHwPnoFlag; 284 int minRssi2Dot4Ghz; 285 int minRssi5Ghz; 286 int firstRssiLevel2G; 287 int secondRssiLevel2G; 288 int thirdRssiLevel2G; 289 int fourthRssiLevel2G; 290 int firstRssiLevel5G; 291 int secondRssiLevel5G; 292 int thirdRssiLevel5G; 293 int fourthRssiLevel5G; 294 std::string strDnsBak; 295 bool isLoadStabak; 296 WifiConfigWifiConfig297 WifiConfig() 298 { 299 scanAlwaysSwitch = false; 300 staAirplaneMode = false; 301 canOpenStaWhenAirplane = false; 302 staLastState = false; 303 savedDeviceAppraisalPriority = PRIORITY_1; 304 scoretacticsScoreSlope = SCORE_SLOPE; 305 scoretacticsInitScore = INIT_SCORE; 306 scoretacticsSameBssidScore = SAME_BSSID_SCORE; 307 scoretacticsSameNetworkScore = SAME_NETWORK_SCORE; 308 scoretacticsFrequency5GHzScore = FREQUENCY_5_GHZ_SCORE; 309 scoretacticsLastSelectionScore = LAST_SELECTION_SCORE; 310 scoretacticsSecurityScore = SECURITY_SCORE; 311 scoretacticsNormalScore = NORMAL_SCORE; 312 whetherToAllowNetworkSwitchover = true; 313 dhcpIpType = static_cast<int>(DhcpIpType::DHCP_IPTYPE_MIX); 314 defaultWifiInterface = "wlan0"; 315 preLoadSta = false; 316 preLoadScan = false; 317 preLoadAp = false; 318 preLoadP2p = false; 319 preLoadAware = false; 320 supportHwPnoFlag = true; 321 minRssi2Dot4Ghz = MIN_RSSI_24GHZ; 322 minRssi5Ghz = MIN_RSSI_5GHZ; 323 firstRssiLevel2G = RSSI_LEVEL_1_2G; 324 secondRssiLevel2G = RSSI_LEVEL_2_2G; 325 thirdRssiLevel2G = RSSI_LEVEL_3_2G; 326 fourthRssiLevel2G = RSSI_LEVEL_4_2G; 327 firstRssiLevel5G = RSSI_LEVEL_1_5G; 328 secondRssiLevel5G = RSSI_LEVEL_2_5G; 329 thirdRssiLevel5G = RSSI_LEVEL_3_5G; 330 fourthRssiLevel5G = RSSI_LEVEL_4_5G; 331 strDnsBak = "8.8.8.8"; 332 isLoadStabak = true; 333 } 334 }; 335 336 struct TrustListPolicy { 337 int sceneId = 0; /* scene id */ 338 std::string sceneName; /* scene name, just to read. */ 339 std::string trustList; /* trust list, eg: for A,B,and C,the format is A|B|C */ 340 TrustListPolicyTrustListPolicy341 TrustListPolicy() 342 { 343 sceneId = 0; 344 sceneName = ""; 345 trustList = ""; 346 } 347 }; 348 349 struct MovingFreezePolicy { 350 std::string trustList; /* trust list */ 351 MovingFreezePolicyMovingFreezePolicy352 MovingFreezePolicy() 353 { 354 trustList = ""; 355 } 356 }; 357 358 /* wifi RandomMac store */ 359 struct WifiStoreRandomMac { 360 std::string ssid; 361 std::string keyMgmt; 362 std::string peerBssid; 363 std::string randomMac; 364 }; 365 } // namespace Wifi 366 } // namespace OHOS 367 #endif 368