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