• 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 
25 namespace OHOS {
26 namespace Wifi {
27 #define MIN_SCAN_INTERVAL 20
28 #define DEFAULT_MAX_SCAN_INTERVAL 160
29 #define SCAN_SCENE_SCREEN_OFF 0       // Screen off state
30 #define SCAN_SCENE_SCANNING 1         // scanning state
31 #define SCAN_SCENE_CONNECTING 2       // connecting state
32 #define SCAN_SCENE_DISCONNCTED 3      // disconnected state
33 #define SCAN_SCENE_CONNECTED 4        // connected state
34 #define SCAN_SCENE_ASSOCIATING 5      // associating state
35 #define SCAN_SCENE_ASSOCIATED 6       // associated state
36 #define SCAN_SCENE_OBTAINING_IP 7     // Obtaining IP state
37 #define SCAN_SCENE_DEEP_SLEEP 8       // Deep sleep state
38 #define SCAN_SCENE_FREQUENCY_ORIGIN 9 // Scan frequency, origin.
39 #define SCAN_SCENE_FREQUENCY_CUSTOM 10 // Scan frequency, custom.
40 #define SCAN_SCENE_CUSTOM (SCAN_SCENE_FREQUENCY_CUSTOM + 1)
41 
42 /* SCAN_SCENE_CUSTOM~253 Custom Scenario */
43 #define SCAN_SCENE_ALL 254 /* all Scenario */
44 #define SCAN_SCENE_MAX 255 /* invalid value */
45 
46 /* Scanning mode of the control policy */
47 enum class ScanMode {
48     APP_FOREGROUND_SCAN = 0, /* Scan initiated by the foreground application */
49     APP_BACKGROUND_SCAN = 1, /* Scan initiated by background applications */
50     SYS_FOREGROUND_SCAN = 2, /* System foreground scan */
51     SYS_BACKGROUND_SCAN = 3, /* System background scan */
52     ALL_EXTERN_SCAN = 4,     /* All external scans, including the first four */
53     PNO_SCAN = 5,            /* PNO scan */
54     SYSTEM_TIMER_SCAN = 6,   /* Scheduled system scan */
55     ANYTIME_SCAN = 7,        /* Scan at any time */
56     BAND_24GHZ_SCAN = 8,     /* 2.4 GHz scan */
57     BAND_5GHZ_SCAN = 9,      /* 5G scan */
58     SCAN_MODE_MAX            /* Invalid value */
59 };
60 
61 enum class WifiSecurity {
62     OPEN = 0,
63     WEP = 1,
64     PSK = 2,
65     EAP = 3,
66     SAE = 4,
67     EAP_SUITE_B = 5,
68     OWE = 6,
69     WAPI_CERT = 7,
70     WAPI_PSK = 8,
71     INVALID = -1
72 };
73 
74 enum class WifiChannelWidth {
75     WIDTH_20MHZ = 0,
76     WIDTH_40MHZ = 1,
77     WIDTH_80MHZ = 2,
78     WIDTH_160MHZ = 3,
79     WIDTH_80MHZ_PLUS = 4,
80     WIDTH_INVALID
81 };
82 
83 struct WifiInfoElem {
84     unsigned int id;
85     std::vector<char> content;
86 
WifiInfoElemWifiInfoElem87     WifiInfoElem() : id(0)
88     {}
89 
~WifiInfoElemWifiInfoElem90     ~WifiInfoElem()
91     {}
92 };
93 
94 enum class ScanHandleNotify {
95     SCAN_FAIL = 0,
96     SCAN_OK = 1,
97 };
98 
99 struct WifiScanParams {
100     std::string ssid;
101     std::string bssid;
102     std::vector<int> freqs;
103     unsigned int band;
104     int scanStyle;
105 
WifiScanParamsWifiScanParams106     WifiScanParams()
107     {
108         band = 0;
109         scanStyle = 0xFF;
110     }
111 };
112 
113 /* scan result info */
114 struct WifiScanInfo {
115     std::string bssid;
116     std::string ssid;
117     /**
118      * Network performance, including authentication,
119      * key management, and encryption mechanisms
120      * supported by the access point
121      */
122     std::string capabilities;
123     int frequency;
124     int band;  /* ap band: 1 - 2.4GHZ, 2 - 5GHZ */
125     WifiChannelWidth channelWidth;
126     int centerFrequency0;
127     int centerFrequency1;
128     int rssi; /* signal level */
129     WifiSecurity securityType;
130     std::vector<WifiInfoElem> infoElems;
131     int64_t features;
132     int64_t timestamp;
133 
WifiScanInfoWifiScanInfo134     WifiScanInfo()
135     {
136         frequency = 0;
137         band = 0;
138         channelWidth = WifiChannelWidth::WIDTH_INVALID;
139         centerFrequency0 = 0;
140         centerFrequency1 = 0;
141         rssi = 0;
142         securityType = WifiSecurity::INVALID;
143         features = 0;
144         timestamp = 0;
145     }
146 };
147 
148 typedef struct tagScanForbidMode {
149     int scanScene;     /* current scanned scene */
150     int forbidTime;    /*
151                         * Specifies the scanning duration.
152                         * If the value is 0, all invalid values are restricted.
153                         */
154     int forbidCount;   /*
155                         * Indicates the number of scanning times after a scanning scenario is entered.
156                         * If the value is 0, all scanning times are restricted.
157                         */
158     ScanMode scanMode; /* Restricted Scan Mode */
tagScanForbidModetagScanForbidMode159     tagScanForbidMode()
160     {
161         forbidTime = 0;
162         forbidCount = 0;
163         scanMode = ScanMode::SCAN_MODE_MAX;
164     }
165 
~tagScanForbidModetagScanForbidMode166     ~tagScanForbidMode()
167     {}
168 } ScanForbidMode;
169 
170 enum class IntervalMode {
171     INTERVAL_FIXED = 0,     /*
172                              * The interval is set to 120 and the count is set to 4.
173                              * For example, the interval is set to 120 and the count is set to 4.
174                              */
175     INTERVAL_EXP = 1,       /*
176                              * Exponential interval. The value of interval is the initial value.
177                              * After the value is multiplied by 2, the last fixed interval is used.
178                              */
179     INTERVAL_CONTINUE = 2,  /*
180                              * If the number of consecutive count times is less than interval,
181                              * the subsequent interval must be greater than interval.
182                              */
183     INTERVAL_BLOCKLIST = 3, /*
184                              * If the number of consecutive count times is less than the value of interval,
185                              * the user is added to the blocklist and cannot be scanned.
186                              */
187     INTERVAL_MAX            /* invalid value */
188 };
189 
190 typedef struct tagScanInterval {
191     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
192     int interval;              /* Interval, in seconds. */
193     int count;                 /* Number of times allowed in the interval */
tagScanIntervaltagScanInterval194     tagScanInterval()
195     {
196         intervalMode = IntervalMode::INTERVAL_FIXED;
197         interval = 0;
198         count = 0;
199     }
200 } ScanInterval;
201 
202 typedef struct tagScanIntervalMode {
203     int scanScene;             /*
204                                 * This parameter can be set to SCAN_SCENE_ALL
205                                 * if the configuration takes effect at intervals.
206                                 */
207     ScanMode scanMode;         /* scan mode */
208     bool isSingle;             /*
209                                 * Indicates whether to limit the time of a single application.
210                                 * If this parameter is set to false, the time of all applications is recorded.
211                                 */
212     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
213     int interval;              /* Interval, in seconds. */
214     int count;                 /* Number of times allowed in the interval */
tagScanIntervalModetagScanIntervalMode215     tagScanIntervalMode()
216     {
217         scanScene = SCAN_SCENE_ALL;
218         scanMode = ScanMode::SCAN_MODE_MAX;
219         isSingle = false;
220         intervalMode = IntervalMode::INTERVAL_FIXED;
221         interval = 0;
222         count = 0;
223     }
224 } ScanIntervalMode;
225 
226 typedef std::vector<ScanForbidMode> ScanForbidList;
227 typedef std::vector<ScanIntervalMode> ScanIntervalList;
228 
229 typedef struct tagScanControlInfo {
230     ScanForbidList scanForbidList;       /* Scanning forbidden list corresponding to the scenario */
231     ScanIntervalList scanIntervalList; /*
232                                         * Interval for scanning mode.
233                                         * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan.
234                                         */
235 } ScanControlInfo;
236 
237 struct SystemScanIntervalMode {
238     ScanIntervalMode scanIntervalMode;
239     int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */
SystemScanIntervalModeSystemScanIntervalMode240     SystemScanIntervalMode()
241     {
242         expScanCount = 0;
243     }
244 };
245 
246 struct PnoScanIntervalMode {
247     ScanIntervalMode scanIntervalMode;
248     time_t fixedCurrentTime;
249     int fixedScanCount;
250     time_t fixedScanTime;
PnoScanIntervalModePnoScanIntervalMode251     PnoScanIntervalMode()
252     {
253         fixedCurrentTime = 0;
254         fixedCurrentTime = 0;
255         fixedScanTime = 0;
256         fixedScanCount = 0;
257     }
258 };
259 }  // namespace Wifi
260 }  // namespace OHOS
261 #endif