• 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;
WifiScanInfoWifiScanInfo138     WifiScanInfo()
139     {
140         bssidType = REAL_DEVICE_ADDRESS;
141         frequency = 0;
142         band = 0;
143         channelWidth = WifiChannelWidth::WIDTH_INVALID;
144         centerFrequency0 = 0;
145         centerFrequency1 = 0;
146         rssi = 0;
147         securityType = WifiSecurity::INVALID;
148         features = 0;
149         timestamp = 0;
150         wifiStandard = 0;
151         maxSupportedRxLinkSpeed = 0;
152         maxSupportedTxLinkSpeed = 0;
153     }
154 };
155 
156 typedef struct tagScanForbidMode {
157     int scanScene;     /* current scanned scene */
158     int forbidTime;    /*
159                         * Specifies the scanning duration.
160                         * If the value is 0, all invalid values are restricted.
161                         */
162     int forbidCount;   /*
163                         * Indicates the number of scanning times after a scanning scenario is entered.
164                         * If the value is 0, all scanning times are restricted.
165                         */
166     ScanMode scanMode; /* Restricted Scan Mode */
tagScanForbidModetagScanForbidMode167     tagScanForbidMode()
168     {
169         scanScene = 0;
170         forbidTime = 0;
171         forbidCount = 0;
172         scanMode = ScanMode::SCAN_MODE_MAX;
173     }
174 
~tagScanForbidModetagScanForbidMode175     ~tagScanForbidMode()
176     {}
177 } ScanForbidMode;
178 
179 enum class IntervalMode {
180     INTERVAL_FIXED = 0,     /*
181                              * The interval is set to 120 and the count is set to 4.
182                              * For example, the interval is set to 120 and the count is set to 4.
183                              */
184     INTERVAL_EXP = 1,       /*
185                              * Exponential interval. The value of interval is the initial value.
186                              * After the value is multiplied by 2, the last fixed interval is used.
187                              */
188     INTERVAL_CONTINUE = 2,  /*
189                              * If the number of consecutive count times is less than interval,
190                              * the subsequent interval must be greater than interval.
191                              */
192     INTERVAL_BLOCKLIST = 3, /*
193                              * If the number of consecutive count times is less than the value of interval,
194                              * the user is added to the blocklist and cannot be scanned.
195                              */
196     INTERVAL_MAX            /* invalid value */
197 };
198 
199 typedef struct tagScanInterval {
200     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
201     int interval;              /* Interval, in seconds. */
202     int count;                 /* Number of times allowed in the interval */
tagScanIntervaltagScanInterval203     tagScanInterval()
204     {
205         intervalMode = IntervalMode::INTERVAL_FIXED;
206         interval = 0;
207         count = 0;
208     }
209 } ScanInterval;
210 
211 typedef struct tagScanIntervalMode {
212     int scanScene;             /*
213                                 * This parameter can be set to SCAN_SCENE_ALL
214                                 * if the configuration takes effect at intervals.
215                                 */
216     ScanMode scanMode;         /* scan mode */
217     bool isSingle;             /*
218                                 * Indicates whether to limit the time of a single application.
219                                 * If this parameter is set to false, the time of all applications is recorded.
220                                 */
221     IntervalMode intervalMode; /* Interval mode, which can be interval or count. */
222     int interval;              /* Interval, in seconds. */
223     int count;                 /* Number of times allowed in the interval */
tagScanIntervalModetagScanIntervalMode224     tagScanIntervalMode()
225     {
226         scanScene = SCAN_SCENE_ALL;
227         scanMode = ScanMode::SCAN_MODE_MAX;
228         isSingle = false;
229         intervalMode = IntervalMode::INTERVAL_FIXED;
230         interval = 0;
231         count = 0;
232     }
233 } ScanIntervalMode;
234 
235 typedef std::vector<ScanForbidMode> ScanForbidList;
236 typedef std::vector<ScanIntervalMode> ScanIntervalList;
237 
238 typedef struct tagScanControlInfo {
239     ScanForbidList scanForbidList;       /* Scanning forbidden list corresponding to the scenario */
240     ScanIntervalList scanIntervalList; /*
241                                         * Interval for scanning mode.
242                                         * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan.
243                                         */
244 } ScanControlInfo;
245 
246 struct SystemScanIntervalMode {
247     ScanIntervalMode scanIntervalMode;
248     int expScanCount; /* INTERVAL_EXP scan mode,Number of Scanned Times */
SystemScanIntervalModeSystemScanIntervalMode249     SystemScanIntervalMode()
250     {
251         expScanCount = 0;
252     }
253 };
254 
255 struct PnoScanIntervalMode {
256     ScanIntervalMode scanIntervalMode;
257     time_t fixedCurrentTime;
258     int fixedScanCount;
259     time_t fixedScanTime;
PnoScanIntervalModePnoScanIntervalMode260     PnoScanIntervalMode()
261     {
262         fixedCurrentTime = 0;
263         fixedCurrentTime = 0;
264         fixedScanTime = 0;
265         fixedScanCount = 0;
266     }
267 };
268 }  // namespace Wifi
269 }  // namespace OHOS
270 #endif