• 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     INVALID = -1
73 };
74 
75 enum class WifiChannelWidth {
76     WIDTH_20MHZ = 0,
77     WIDTH_40MHZ = 1,
78     WIDTH_80MHZ = 2,
79     WIDTH_160MHZ = 3,
80     WIDTH_80MHZ_PLUS = 4,
81     WIDTH_INVALID
82 };
83 
84 struct WifiInfoElem {
85     unsigned int id;
86     std::vector<char> content;
87 
WifiInfoElemWifiInfoElem88     WifiInfoElem() : id(0)
89     {}
90 
~WifiInfoElemWifiInfoElem91     ~WifiInfoElem()
92     {}
93 };
94 
95 enum class ScanHandleNotify {
96     SCAN_FAIL = 0,
97     SCAN_OK = 1,
98 };
99 
100 struct WifiScanParams {
101     std::string ssid;
102     std::string bssid;
103     std::vector<int> freqs;
104     unsigned int band;
105     int scanStyle;
106 
WifiScanParamsWifiScanParams107     WifiScanParams()
108     {
109         band = 0;
110         scanStyle = 0xFF;
111     }
112 };
113 
114 /* scan result info */
115 struct WifiScanInfo {
116     std::string bssid;
117     std::string ssid;
118     int bssidType; /* bssid type. */
119     /**
120      * Network performance, including authentication,
121      * key management, and encryption mechanisms
122      * supported by the access point
123      */
124     std::string capabilities;
125     int frequency;
126     int band;  /* ap band: 1 - 2.4GHZ, 2 - 5GHZ */
127     WifiChannelWidth channelWidth;
128     int centerFrequency0;
129     int centerFrequency1;
130     int rssi; /* signal level */
131     WifiSecurity securityType;
132     std::vector<WifiInfoElem> infoElems;
133     int64_t features;
134     int64_t timestamp;
135     int wifiStandard;
136     int maxSupportedRxLinkSpeed;
137     int maxSupportedTxLinkSpeed;
138     int disappearCount;
WifiScanInfoWifiScanInfo139     WifiScanInfo()
140     {
141         bssidType = REAL_DEVICE_ADDRESS;
142         frequency = 0;
143         band = 0;
144         channelWidth = WifiChannelWidth::WIDTH_INVALID;
145         centerFrequency0 = 0;
146         centerFrequency1 = 0;
147         rssi = 0;
148         securityType = WifiSecurity::INVALID;
149         features = 0;
150         timestamp = 0;
151         wifiStandard = 0;
152         maxSupportedRxLinkSpeed = 0;
153         maxSupportedTxLinkSpeed = 0;
154     }
155 };
156 
157 typedef struct tagScanForbidMode {
158     int scanScene;     /* current scanned scene */
159     int forbidTime;    /*
160                         * Specifies the scanning duration.
161                         * If the value is 0, all invalid values are restricted.
162                         */
163     int forbidCount;   /*
164                         * Indicates the number of scanning times after a scanning scenario is entered.
165                         * If the value is 0, all scanning times are restricted.
166                         */
167     ScanMode scanMode; /* Restricted Scan Mode */
tagScanForbidModetagScanForbidMode168     tagScanForbidMode()
169     {
170         scanScene = 0;
171         forbidTime = 0;
172         forbidCount = 0;
173         scanMode = ScanMode::SCAN_MODE_MAX;
174     }
175 
~tagScanForbidModetagScanForbidMode176     ~tagScanForbidMode()
177     {}
178 } ScanForbidMode;
179 
180 enum class IntervalMode {
181     INTERVAL_FIXED = 0,     /*
182                              * The interval is set to 120 and the count is set to 4.
183                              * For example, the interval is set to 120 and the count is set to 4.
184                              */
185     INTERVAL_EXP = 1,       /*
186                              * Exponential interval. The value of interval is the initial value.
187                              * After the value is multiplied by 2, the last fixed interval is used.
188                              */
189     INTERVAL_CONTINUE = 2,  /*
190                              * If the number of consecutive count times is less than interval,
191                              * the subsequent interval must be greater than interval.
192                              */
193     INTERVAL_BLOCKLIST = 3, /*
194                              * If the number of consecutive count times is less than the value of interval,
195                              * the user is added to the blocklist and cannot be scanned.
196                              */
197     INTERVAL_MAX            /* invalid value */
198 };
199 
200 typedef struct tagScanInterval {
201     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
202     int interval;              /* Interval, in seconds. */
203     int count;                 /* Number of times allowed in the interval */
tagScanIntervaltagScanInterval204     tagScanInterval()
205     {
206         intervalMode = IntervalMode::INTERVAL_FIXED;
207         interval = 0;
208         count = 0;
209     }
210 } ScanInterval;
211 
212 typedef struct tagScanIntervalMode {
213     int scanScene;             /*
214                                 * This parameter can be set to SCAN_SCENE_ALL
215                                 * if the configuration takes effect at intervals.
216                                 */
217     ScanMode scanMode;         /* scan mode */
218     bool isSingle;             /*
219                                 * Indicates whether to limit the time of a single application.
220                                 * If this parameter is set to false, the time of all applications is recorded.
221                                 */
222     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
223     int interval;              /* Interval, in seconds. */
224     int count;                 /* Number of times allowed in the interval */
tagScanIntervalModetagScanIntervalMode225     tagScanIntervalMode()
226     {
227         scanScene = SCAN_SCENE_ALL;
228         scanMode = ScanMode::SCAN_MODE_MAX;
229         isSingle = false;
230         intervalMode = IntervalMode::INTERVAL_FIXED;
231         interval = 0;
232         count = 0;
233     }
234 } ScanIntervalMode;
235 
236 typedef std::vector<ScanForbidMode> ScanForbidList;
237 typedef std::vector<ScanIntervalMode> ScanIntervalList;
238 
239 typedef struct tagScanControlInfo {
240     ScanForbidList scanForbidList;       /* Scanning forbidden list corresponding to the scenario */
241     ScanIntervalList scanIntervalList; /*
242                                         * Interval for scanning mode.
243                                         * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan.
244                                         */
245 } ScanControlInfo;
246 
247 struct SystemScanIntervalMode {
248     ScanIntervalMode scanIntervalMode;
249     int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */
SystemScanIntervalModeSystemScanIntervalMode250     SystemScanIntervalMode()
251     {
252         expScanCount = 0;
253     }
254 };
255 
256 struct PnoScanIntervalMode {
257     ScanIntervalMode scanIntervalMode;
258     time_t fixedCurrentTime;
259     int fixedScanCount;
260     time_t fixedScanTime;
PnoScanIntervalModePnoScanIntervalMode261     PnoScanIntervalMode()
262     {
263         fixedCurrentTime = 0;
264         fixedCurrentTime = 0;
265         fixedScanTime = 0;
266         fixedScanCount = 0;
267     }
268 };
269 }  // namespace Wifi
270 }  // namespace OHOS
271 #endif