• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEFAULT = 0,
95     SCAN_TYPE_EXTERN,
96     SCAN_TYPE_NATIVE_EXTERN,
97     SCAN_TYPE_SYSTEMTIMER,
98     SCAN_TYPE_PNO,
99     SCAN_TYPE_WIFIPRO,
100     SCAN_TYPE_5G_AP,
101     SCAN_TYPE_HIDDEN_AP,
102     SCAN_TYPE_SINGLE_SCAN_TIMER,
103 };
104 
105 enum ScanBandType {
106     SCAN_BAND_UNSPECIFIED = 0,    /* not specified */
107     SCAN_BAND_24_GHZ = 1,         /* 2.4 GHz band */
108     SCAN_BAND_5_GHZ = 2,          /* 5 GHz band without DFS channels */
109     SCAN_BAND_BOTH = 3,           /* both bands without DFS channels */
110     SCAN_BAND_5_GHZ_DFS_ONLY = 4, /* 5 GHz band with DFS channels */
111     SCAN_BAND_5_GHZ_WITH_DFS = 6, /* 5 GHz band with DFS channels */
112     SCAN_BAND_BOTH_WITH_DFS = 7,  /* both bands with DFS channels */
113 };
114 
115 struct WifiInfoElem {
116     unsigned int id;
117     std::vector<char> content;
118 
WifiInfoElemWifiInfoElem119     WifiInfoElem() : id(0)
120     {}
121 
~WifiInfoElemWifiInfoElem122     ~WifiInfoElem()
123     {}
124 };
125 
126 enum class ScanHandleNotify {
127     SCAN_FAIL = 0,
128     SCAN_OK = 1,
129 };
130 
131 struct WifiScanParams {
132     std::string ssid;
133     std::string bssid;
134     std::vector<int> freqs;
135     unsigned int band;
136     int scanStyle;
137 
WifiScanParamsWifiScanParams138     WifiScanParams()
139     {
140         band = 0;
141         scanStyle = 0xFF;
142     }
143 };
144 
145 /* scan result info */
146 struct WifiScanInfo {
147     std::string bssid;
148     std::string ssid;
149     // Original SSID, used to store the original SSID of different charts like GBK, UTF-8, etc.
150     std::string oriSsid;
151     int bssidType; /* bssid type. */
152     /**
153      * Network performance, including authentication,
154      * key management, and encryption mechanisms
155      * supported by the access point
156      */
157     std::string capabilities;
158     int frequency;
159     int band;  /* ap band: 1 - 2.4GHZ, 2 - 5GHZ */
160     WifiChannelWidth channelWidth;
161     int centerFrequency0;
162     int centerFrequency1;
163     int rssi; /* signal level */
164     WifiSecurity securityType;
165     std::vector<WifiInfoElem> infoElems;
166     int64_t features;
167     int64_t timestamp;
168     int wifiStandard;
169     int maxSupportedRxLinkSpeed;
170     int maxSupportedTxLinkSpeed;
171     int disappearCount;
172     bool isHiLinkNetwork;
173     WifiCategory supportedWifiCategory;
WifiScanInfoWifiScanInfo174     WifiScanInfo()
175     {
176         bssidType = REAL_DEVICE_ADDRESS;
177         frequency = 0;
178         band = 0;
179         channelWidth = WifiChannelWidth::WIDTH_INVALID;
180         centerFrequency0 = 0;
181         centerFrequency1 = 0;
182         rssi = 0;
183         securityType = WifiSecurity::INVALID;
184         features = 0;
185         timestamp = 0;
186         wifiStandard = 0;
187         maxSupportedRxLinkSpeed = 0;
188         maxSupportedTxLinkSpeed = 0;
189         isHiLinkNetwork = false;
190         supportedWifiCategory = WifiCategory::DEFAULT;
191     }
192 
GetDeviceMgmtWifiScanInfo193     void GetDeviceMgmt(std::string &mgmt) const
194     {
195         switch (securityType) {
196             case WifiSecurity::PSK:
197                 mgmt = "WPA-PSK";
198                 break;
199             case WifiSecurity::EAP:
200                 mgmt = "WPA-EAP";
201                 break;
202             case WifiSecurity::SAE:
203                 mgmt = "SAE";
204                 break;
205             case WifiSecurity::OWE:
206                 mgmt = "OWE";
207                 break;
208             case WifiSecurity::WEP:
209                 mgmt = "WEP";
210                 break;
211             case WifiSecurity::EAP_SUITE_B:
212                 mgmt = "WPA-EAP-SUITE-B-192";
213                 break;
214             case WifiSecurity::WAPI_CERT:
215                 mgmt = "WAPI-CERT";
216                 break;
217             case WifiSecurity::WAPI_PSK:
218                 mgmt = "WAPI-PSK";
219                 break;
220             case WifiSecurity::PSK_SAE:
221                 mgmt = "WPA-PSK+SAE";
222                 break;
223             default:
224                 mgmt = "NONE";
225                 break;
226         }
227     }
228 };
229 
230 typedef struct tagScanForbidMode {
231     int scanScene;     /* current scanned scene */
232     int forbidTime;    /*
233                         * Specifies the scanning duration.
234                         * If the value is 0, all invalid values are restricted.
235                         */
236     int forbidCount;   /*
237                         * Indicates the number of scanning times after a scanning scenario is entered.
238                         * If the value is 0, all scanning times are restricted.
239                         */
240     ScanMode scanMode; /* Restricted Scan Mode */
tagScanForbidModetagScanForbidMode241     tagScanForbidMode()
242     {
243         scanScene = 0;
244         forbidTime = 0;
245         forbidCount = 0;
246         scanMode = ScanMode::SCAN_MODE_MAX;
247     }
248 
~tagScanForbidModetagScanForbidMode249     ~tagScanForbidMode()
250     {}
251 } ScanForbidMode;
252 
253 enum class IntervalMode {
254     INTERVAL_FIXED = 0,     /*
255                              * The interval is set to 120 and the count is set to 4.
256                              * For example, the interval is set to 120 and the count is set to 4.
257                              */
258     INTERVAL_EXP = 1,       /*
259                              * Exponential interval. The value of interval is the initial value.
260                              * After the value is multiplied by 2, the last fixed interval is used.
261                              */
262     INTERVAL_CONTINUE = 2,  /*
263                              * If the number of consecutive count times is less than interval,
264                              * the subsequent interval must be greater than interval.
265                              */
266     INTERVAL_BLOCKLIST = 3, /*
267                              * If the number of consecutive count times is less than the value of interval,
268                              * the user is added to the blocklist and cannot be scanned.
269                              */
270     INTERVAL_MAX            /* invalid value */
271 };
272 
273 typedef struct tagScanInterval {
274     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
275     int interval;              /* Interval, in seconds. */
276     int count;                 /* Number of times allowed in the interval */
tagScanIntervaltagScanInterval277     tagScanInterval()
278     {
279         intervalMode = IntervalMode::INTERVAL_FIXED;
280         interval = 0;
281         count = 0;
282     }
283 } ScanInterval;
284 
285 typedef struct tagScanIntervalMode {
286     int scanScene;             /*
287                                 * This parameter can be set to SCAN_SCENE_ALL
288                                 * if the configuration takes effect at intervals.
289                                 */
290     ScanMode scanMode;         /* scan mode */
291     bool isSingle;             /*
292                                 * Indicates whether to limit the time of a single application.
293                                 * If this parameter is set to false, the time of all applications is recorded.
294                                 */
295     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
296     int interval;              /* Interval, in seconds. */
297     int count;                 /* Number of times allowed in the interval */
tagScanIntervalModetagScanIntervalMode298     tagScanIntervalMode()
299     {
300         scanScene = SCAN_SCENE_ALL;
301         scanMode = ScanMode::SCAN_MODE_MAX;
302         isSingle = false;
303         intervalMode = IntervalMode::INTERVAL_FIXED;
304         interval = 0;
305         count = 0;
306     }
307 } ScanIntervalMode;
308 
309 typedef std::vector<ScanForbidMode> ScanForbidList;
310 typedef std::vector<ScanIntervalMode> ScanIntervalList;
311 
312 typedef struct tagScanControlInfo {
313     ScanForbidList scanForbidList;       /* Scanning forbidden list corresponding to the scenario */
314     ScanIntervalList scanIntervalList; /*
315                                         * Interval for scanning mode.
316                                         * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan.
317                                         */
318 } ScanControlInfo;
319 
320 struct SystemScanIntervalMode {
321     ScanIntervalMode scanIntervalMode;
322     int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */
SystemScanIntervalModeSystemScanIntervalMode323     SystemScanIntervalMode()
324     {
325         expScanCount = 0;
326     }
327 };
328 
329 struct PnoScanIntervalMode {
330     ScanIntervalMode scanIntervalMode;
331     time_t fixedCurrentTime;
332     int fixedScanCount;
333     time_t fixedScanTime;
PnoScanIntervalModePnoScanIntervalMode334     PnoScanIntervalMode()
335     {
336         fixedCurrentTime = 0;
337         fixedCurrentTime = 0;
338         fixedScanTime = 0;
339         fixedScanCount = 0;
340     }
341 };
342 }  // namespace Wifi
343 }  // namespace OHOS
344 #endif