1 /* 2 * Copyright (C) 2021 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_SCAN_MSG_H 17 #define OHOS_WIFI_SCAN_MSG_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 #include <cstdint> 23 #include <ctime> 24 #include "wifi_common_msg.h" 25 26 namespace OHOS { 27 namespace Wifi { 28 #define MIN_SCAN_INTERVAL 20 29 #define DEFAULT_MAX_SCAN_INTERVAL 160 30 #define SCAN_SCENE_SCREEN_OFF 0 // Screen off state 31 #define SCAN_SCENE_SCANNING 1 // scanning state 32 #define SCAN_SCENE_CONNECTING 2 // connecting state 33 #define SCAN_SCENE_DISCONNCTED 3 // disconnected state 34 #define SCAN_SCENE_CONNECTED 4 // connected state 35 #define SCAN_SCENE_ASSOCIATING 5 // associating state 36 #define SCAN_SCENE_ASSOCIATED 6 // associated state 37 #define SCAN_SCENE_OBTAINING_IP 7 // Obtaining IP state 38 #define SCAN_SCENE_DEEP_SLEEP 8 // Deep sleep state 39 #define SCAN_SCENE_FREQUENCY_ORIGIN 9 // Scan frequency, origin. 40 #define SCAN_SCENE_FREQUENCY_CUSTOM 10 // Scan frequency, custom. 41 #define SCAN_SCENE_CUSTOM (SCAN_SCENE_FREQUENCY_CUSTOM + 1) 42 43 /* SCAN_SCENE_CUSTOM~253 Custom Scenario */ 44 #define SCAN_SCENE_ALL 254 /* all Scenario */ 45 #define SCAN_SCENE_MAX 255 /* invalid value */ 46 47 /* Scanning mode of the control policy */ 48 enum class ScanMode { 49 APP_FOREGROUND_SCAN = 0, /* Scan initiated by the foreground application */ 50 APP_BACKGROUND_SCAN = 1, /* Scan initiated by background applications */ 51 SYS_FOREGROUND_SCAN = 2, /* System foreground scan */ 52 SYS_BACKGROUND_SCAN = 3, /* System background scan */ 53 ALL_EXTERN_SCAN = 4, /* All external scans, including the first four */ 54 PNO_SCAN = 5, /* PNO scan */ 55 SYSTEM_TIMER_SCAN = 6, /* Scheduled system scan */ 56 ANYTIME_SCAN = 7, /* Scan at any time */ 57 BAND_24GHZ_SCAN = 8, /* 2.4 GHz scan */ 58 BAND_5GHZ_SCAN = 9, /* 5G scan */ 59 SCAN_MODE_MAX /* Invalid value */ 60 }; 61 62 enum class WifiSecurity { 63 OPEN = 0, 64 WEP = 1, 65 PSK = 2, 66 EAP = 3, 67 SAE = 4, 68 EAP_SUITE_B = 5, 69 OWE = 6, 70 WAPI_CERT = 7, 71 WAPI_PSK = 8, 72 PSK_SAE = 9, 73 INVALID = -1 74 }; 75 76 enum class WifiChannelWidth { 77 WIDTH_20MHZ = 0, 78 WIDTH_40MHZ = 1, 79 WIDTH_80MHZ = 2, 80 WIDTH_160MHZ = 3, 81 WIDTH_80MHZ_PLUS = 4, 82 WIDTH_INVALID 83 }; 84 85 enum class WifiCategory { 86 DEFAULT = 1, 87 WIFI6 = 2, 88 WIFI6_PLUS = 3, 89 WIFI7 = 4, 90 WIFI7_PLUS = 5 91 }; 92 93 enum class ScanType { 94 SCAN_TYPE_EXTERN = 0, 95 SCAN_TYPE_NATIVE_EXTERN, 96 SCAN_TYPE_SYSTEMTIMER, 97 SCAN_TYPE_PNO, 98 }; 99 100 enum ScanBandType { 101 SCAN_BAND_UNSPECIFIED = 0, /* not specified */ 102 SCAN_BAND_24_GHZ = 1, /* 2.4 GHz band */ 103 SCAN_BAND_5_GHZ = 2, /* 5 GHz band without DFS channels */ 104 SCAN_BAND_BOTH = 3, /* both bands without DFS channels */ 105 SCAN_BAND_5_GHZ_DFS_ONLY = 4, /* 5 GHz band with DFS channels */ 106 SCAN_BAND_5_GHZ_WITH_DFS = 6, /* 5 GHz band with DFS channels */ 107 SCAN_BAND_BOTH_WITH_DFS = 7, /* both bands with DFS channels */ 108 }; 109 110 struct WifiInfoElem { 111 unsigned int id; 112 std::vector<char> content; 113 WifiInfoElemWifiInfoElem114 WifiInfoElem() : id(0) 115 {} 116 ~WifiInfoElemWifiInfoElem117 ~WifiInfoElem() 118 {} 119 }; 120 121 enum class ScanHandleNotify { 122 SCAN_FAIL = 0, 123 SCAN_OK = 1, 124 }; 125 126 struct WifiScanParams { 127 std::string ssid; 128 std::string bssid; 129 std::vector<int> freqs; 130 unsigned int band; 131 int scanStyle; 132 WifiScanParamsWifiScanParams133 WifiScanParams() 134 { 135 band = 0; 136 scanStyle = 0xFF; 137 } 138 }; 139 140 /* scan result info */ 141 struct WifiScanInfo { 142 std::string bssid; 143 std::string ssid; 144 // Original SSID, used to store the original SSID of different charts like GBK, UTF-8, etc. 145 std::string oriSsid; 146 int bssidType; /* bssid type. */ 147 /** 148 * Network performance, including authentication, 149 * key management, and encryption mechanisms 150 * supported by the access point 151 */ 152 std::string capabilities; 153 int frequency; 154 int band; /* ap band: 1 - 2.4GHZ, 2 - 5GHZ */ 155 WifiChannelWidth channelWidth; 156 int centerFrequency0; 157 int centerFrequency1; 158 int rssi; /* signal level */ 159 WifiSecurity securityType; 160 std::vector<WifiInfoElem> infoElems; 161 int64_t features; 162 int64_t timestamp; 163 int wifiStandard; 164 int maxSupportedRxLinkSpeed; 165 int maxSupportedTxLinkSpeed; 166 int disappearCount; 167 bool isHiLinkNetwork; 168 WifiCategory supportedWifiCategory; WifiScanInfoWifiScanInfo169 WifiScanInfo() 170 { 171 bssidType = REAL_DEVICE_ADDRESS; 172 frequency = 0; 173 band = 0; 174 channelWidth = WifiChannelWidth::WIDTH_INVALID; 175 centerFrequency0 = 0; 176 centerFrequency1 = 0; 177 rssi = 0; 178 securityType = WifiSecurity::INVALID; 179 features = 0; 180 timestamp = 0; 181 wifiStandard = 0; 182 maxSupportedRxLinkSpeed = 0; 183 maxSupportedTxLinkSpeed = 0; 184 isHiLinkNetwork = false; 185 supportedWifiCategory = WifiCategory::DEFAULT; 186 } 187 GetDeviceMgmtWifiScanInfo188 void GetDeviceMgmt(std::string &mgmt) const 189 { 190 switch (securityType) { 191 case WifiSecurity::PSK: 192 mgmt = "WPA-PSK"; 193 break; 194 case WifiSecurity::EAP: 195 mgmt = "WPA-EAP"; 196 break; 197 case WifiSecurity::SAE: 198 mgmt = "SAE"; 199 break; 200 case WifiSecurity::OWE: 201 mgmt = "OWE"; 202 break; 203 case WifiSecurity::WEP: 204 mgmt = "WEP"; 205 break; 206 case WifiSecurity::EAP_SUITE_B: 207 mgmt = "WPA-EAP-SUITE-B-192"; 208 break; 209 case WifiSecurity::WAPI_CERT: 210 mgmt = "WAPI-CERT"; 211 break; 212 case WifiSecurity::WAPI_PSK: 213 mgmt = "WAPI-PSK"; 214 break; 215 case WifiSecurity::PSK_SAE: 216 mgmt = "WPA-PSK+SAE"; 217 break; 218 default: 219 mgmt = "NONE"; 220 break; 221 } 222 } 223 }; 224 225 typedef struct tagScanForbidMode { 226 int scanScene; /* current scanned scene */ 227 int forbidTime; /* 228 * Specifies the scanning duration. 229 * If the value is 0, all invalid values are restricted. 230 */ 231 int forbidCount; /* 232 * Indicates the number of scanning times after a scanning scenario is entered. 233 * If the value is 0, all scanning times are restricted. 234 */ 235 ScanMode scanMode; /* Restricted Scan Mode */ tagScanForbidModetagScanForbidMode236 tagScanForbidMode() 237 { 238 scanScene = 0; 239 forbidTime = 0; 240 forbidCount = 0; 241 scanMode = ScanMode::SCAN_MODE_MAX; 242 } 243 ~tagScanForbidModetagScanForbidMode244 ~tagScanForbidMode() 245 {} 246 } ScanForbidMode; 247 248 enum class IntervalMode { 249 INTERVAL_FIXED = 0, /* 250 * The interval is set to 120 and the count is set to 4. 251 * For example, the interval is set to 120 and the count is set to 4. 252 */ 253 INTERVAL_EXP = 1, /* 254 * Exponential interval. The value of interval is the initial value. 255 * After the value is multiplied by 2, the last fixed interval is used. 256 */ 257 INTERVAL_CONTINUE = 2, /* 258 * If the number of consecutive count times is less than interval, 259 * the subsequent interval must be greater than interval. 260 */ 261 INTERVAL_BLOCKLIST = 3, /* 262 * If the number of consecutive count times is less than the value of interval, 263 * the user is added to the blocklist and cannot be scanned. 264 */ 265 INTERVAL_MAX /* invalid value */ 266 }; 267 268 typedef struct tagScanInterval { 269 IntervalMode intervalMode; /* Interval mode, which can be interval or count. */ 270 int interval; /* Interval, in seconds. */ 271 int count; /* Number of times allowed in the interval */ tagScanIntervaltagScanInterval272 tagScanInterval() 273 { 274 intervalMode = IntervalMode::INTERVAL_FIXED; 275 interval = 0; 276 count = 0; 277 } 278 } ScanInterval; 279 280 typedef struct tagScanIntervalMode { 281 int scanScene; /* 282 * This parameter can be set to SCAN_SCENE_ALL 283 * if the configuration takes effect at intervals. 284 */ 285 ScanMode scanMode; /* scan mode */ 286 bool isSingle; /* 287 * Indicates whether to limit the time of a single application. 288 * If this parameter is set to false, the time of all applications is recorded. 289 */ 290 IntervalMode intervalMode; /* Interval mode, which can be interval or count. */ 291 int interval; /* Interval, in seconds. */ 292 int count; /* Number of times allowed in the interval */ tagScanIntervalModetagScanIntervalMode293 tagScanIntervalMode() 294 { 295 scanScene = SCAN_SCENE_ALL; 296 scanMode = ScanMode::SCAN_MODE_MAX; 297 isSingle = false; 298 intervalMode = IntervalMode::INTERVAL_FIXED; 299 interval = 0; 300 count = 0; 301 } 302 } ScanIntervalMode; 303 304 typedef std::vector<ScanForbidMode> ScanForbidList; 305 typedef std::vector<ScanIntervalMode> ScanIntervalList; 306 307 typedef struct tagScanControlInfo { 308 ScanForbidList scanForbidList; /* Scanning forbidden list corresponding to the scenario */ 309 ScanIntervalList scanIntervalList; /* 310 * Interval for scanning mode. 311 * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan. 312 */ 313 } ScanControlInfo; 314 315 struct SystemScanIntervalMode { 316 ScanIntervalMode scanIntervalMode; 317 int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */ SystemScanIntervalModeSystemScanIntervalMode318 SystemScanIntervalMode() 319 { 320 expScanCount = 0; 321 } 322 }; 323 324 struct PnoScanIntervalMode { 325 ScanIntervalMode scanIntervalMode; 326 time_t fixedCurrentTime; 327 int fixedScanCount; 328 time_t fixedScanTime; PnoScanIntervalModePnoScanIntervalMode329 PnoScanIntervalMode() 330 { 331 fixedCurrentTime = 0; 332 fixedCurrentTime = 0; 333 fixedScanTime = 0; 334 fixedScanCount = 0; 335 } 336 }; 337 } // namespace Wifi 338 } // namespace OHOS 339 #endif