• 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     int isHiLinkNetwork;
173     bool isHiLinkProNetwork;
174     WifiCategory supportedWifiCategory;
WifiScanInfoWifiScanInfo175     WifiScanInfo()
176     {
177         bssidType = REAL_DEVICE_ADDRESS;
178         frequency = 0;
179         band = 0;
180         channelWidth = WifiChannelWidth::WIDTH_INVALID;
181         centerFrequency0 = 0;
182         centerFrequency1 = 0;
183         rssi = 0;
184         securityType = WifiSecurity::INVALID;
185         features = 0;
186         timestamp = 0;
187         wifiStandard = 0;
188         maxSupportedRxLinkSpeed = 0;
189         maxSupportedTxLinkSpeed = 0;
190         isHiLinkNetwork = 0;
191         isHiLinkProNetwork = false;
192         supportedWifiCategory = WifiCategory::DEFAULT;
193     }
194 
GetDeviceMgmtWifiScanInfo195     void GetDeviceMgmt(std::string &mgmt) const
196     {
197         switch (securityType) {
198             case WifiSecurity::PSK:
199                 mgmt = "WPA-PSK";
200                 break;
201             case WifiSecurity::EAP:
202                 mgmt = "WPA-EAP";
203                 break;
204             case WifiSecurity::SAE:
205                 mgmt = "SAE";
206                 break;
207             case WifiSecurity::OWE:
208                 mgmt = "OWE";
209                 break;
210             case WifiSecurity::WEP:
211                 mgmt = "WEP";
212                 break;
213             case WifiSecurity::EAP_SUITE_B:
214                 mgmt = "WPA-EAP-SUITE-B-192";
215                 break;
216             case WifiSecurity::WAPI_CERT:
217                 mgmt = "WAPI-CERT";
218                 break;
219             case WifiSecurity::WAPI_PSK:
220                 mgmt = "WAPI-PSK";
221                 break;
222             case WifiSecurity::PSK_SAE:
223                 mgmt = "WPA-PSK+SAE";
224                 break;
225             default:
226                 mgmt = "NONE";
227                 break;
228         }
229     }
230 };
231 
232 typedef struct tagScanForbidMode {
233     int scanScene;     /* current scanned scene */
234     int forbidTime;    /*
235                         * Specifies the scanning duration.
236                         * If the value is 0, all invalid values are restricted.
237                         */
238     int forbidCount;   /*
239                         * Indicates the number of scanning times after a scanning scenario is entered.
240                         * If the value is 0, all scanning times are restricted.
241                         */
242     ScanMode scanMode; /* Restricted Scan Mode */
tagScanForbidModetagScanForbidMode243     tagScanForbidMode()
244     {
245         scanScene = 0;
246         forbidTime = 0;
247         forbidCount = 0;
248         scanMode = ScanMode::SCAN_MODE_MAX;
249     }
250 
~tagScanForbidModetagScanForbidMode251     ~tagScanForbidMode()
252     {}
253 } ScanForbidMode;
254 
255 enum class IntervalMode {
256     INTERVAL_FIXED = 0,     /*
257                              * The interval is set to 120 and the count is set to 4.
258                              * For example, the interval is set to 120 and the count is set to 4.
259                              */
260     INTERVAL_EXP = 1,       /*
261                              * Exponential interval. The value of interval is the initial value.
262                              * After the value is multiplied by 2, the last fixed interval is used.
263                              */
264     INTERVAL_CONTINUE = 2,  /*
265                              * If the number of consecutive count times is less than interval,
266                              * the subsequent interval must be greater than interval.
267                              */
268     INTERVAL_BLOCKLIST = 3, /*
269                              * If the number of consecutive count times is less than the value of interval,
270                              * the user is added to the blocklist and cannot be scanned.
271                              */
272     INTERVAL_MAX            /* invalid value */
273 };
274 
275 typedef struct tagScanInterval {
276     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
277     int interval;              /* Interval, in seconds. */
278     int count;                 /* Number of times allowed in the interval */
tagScanIntervaltagScanInterval279     tagScanInterval()
280     {
281         intervalMode = IntervalMode::INTERVAL_FIXED;
282         interval = 0;
283         count = 0;
284     }
285 } ScanInterval;
286 
287 typedef struct tagScanIntervalMode {
288     int scanScene;             /*
289                                 * This parameter can be set to SCAN_SCENE_ALL
290                                 * if the configuration takes effect at intervals.
291                                 */
292     ScanMode scanMode;         /* scan mode */
293     bool isSingle;             /*
294                                 * Indicates whether to limit the time of a single application.
295                                 * If this parameter is set to false, the time of all applications is recorded.
296                                 */
297     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
298     int interval;              /* Interval, in seconds. */
299     int count;                 /* Number of times allowed in the interval */
tagScanIntervalModetagScanIntervalMode300     tagScanIntervalMode()
301     {
302         scanScene = SCAN_SCENE_ALL;
303         scanMode = ScanMode::SCAN_MODE_MAX;
304         isSingle = false;
305         intervalMode = IntervalMode::INTERVAL_FIXED;
306         interval = 0;
307         count = 0;
308     }
309 } ScanIntervalMode;
310 
311 typedef std::vector<ScanForbidMode> ScanForbidList;
312 typedef std::vector<ScanIntervalMode> ScanIntervalList;
313 
314 typedef struct tagScanControlInfo {
315     ScanForbidList scanForbidList;       /* Scanning forbidden list corresponding to the scenario */
316     ScanIntervalList scanIntervalList; /*
317                                         * Interval for scanning mode.
318                                         * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan.
319                                         */
320 } ScanControlInfo;
321 
322 struct SystemScanIntervalMode {
323     ScanIntervalMode scanIntervalMode;
324     int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */
SystemScanIntervalModeSystemScanIntervalMode325     SystemScanIntervalMode()
326     {
327         expScanCount = 0;
328     }
329 };
330 
331 struct PnoScanIntervalMode {
332     ScanIntervalMode scanIntervalMode;
333     time_t fixedCurrentTime;
334     int fixedScanCount;
335     time_t fixedScanTime;
PnoScanIntervalModePnoScanIntervalMode336     PnoScanIntervalMode()
337     {
338         fixedCurrentTime = 0;
339         fixedCurrentTime = 0;
340         fixedScanTime = 0;
341         fixedScanCount = 0;
342     }
343 };
344 }  // namespace Wifi
345 }  // namespace OHOS
346 #endif