• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_INTERNAL_MSG_H
17 #define OHOS_WIFI_INTERNAL_MSG_H
18 
19 #include <unordered_set>
20 #include "wifi_ap_msg.h"
21 #include "wifi_hid2d_msg.h"
22 #include "wifi_msg.h"
23 #include "wifi_p2p_msg.h"
24 #include "wifi_scan_msg.h"
25 #include "inter_scan_info.h"
26 
27 namespace OHOS {
28 namespace Wifi {
29 constexpr int REOPEN_STA_INTERVAL = 500; /* when reopen sta, need over last close sta time then interval */
30 constexpr int DEVICE_CONFIG_INDEX_SSID = 0;
31 constexpr int DEVICE_CONFIG_INDEX_BSSID = 1;
32 constexpr int PRIORITY_1 = 1;
33 constexpr int PRIORITY_2 = 2;
34 constexpr int PRIORITY_3 = 3;
35 constexpr int SCORE_SLOPE = 5;
36 constexpr int INIT_SCORE = 10;
37 constexpr int SAME_BSSID_SCORE = 8;
38 constexpr int SAME_NETWORK_SCORE = 5;
39 constexpr int FREQUENCY_5_GHZ_SCORE = 10;
40 constexpr int LAST_SELECTION_SCORE = 120;
41 constexpr int SECURITY_SCORE = 20;
42 constexpr int NORMAL_SCORE = 10;
43 constexpr int MIN_RSSI_24GHZ = -80;
44 constexpr int MIN_RSSI_5GHZ = -77;
45 constexpr int RSSI_LEVEL_1_2G = -88;
46 constexpr int RSSI_LEVEL_2_2G = -82;
47 constexpr int RSSI_LEVEL_3_2G = -75;
48 constexpr int RSSI_LEVEL_4_2G = -65;
49 constexpr int RSSI_LEVEL_1_5G = -85;
50 constexpr int RSSI_LEVEL_2_5G = -79;
51 constexpr int RSSI_LEVEL_3_5G = -72;
52 constexpr int RSSI_LEVEL_4_5G = -65;
53 constexpr int AIRPLANE_MODE_OPEN = 1;
54 constexpr int AIRPLANE_MODE_CLOSE = 2;
55 const int64_t ONE_DAY_TIME_SECONDS = 24 * 60 * 60;
56 
57 #define DNS_IP_ADDR_LEN 15
58 #define WIFI_FIRST_DNS_NAME "const.wifi.wifi_first_dns"
59 
60 constexpr int FUZZY_BSSID_MAX_MATCH_CNT = 30;
61 
62 enum class WifiOprMidState { CLOSED = 0, OPENING = 1, RUNNING = 2, CLOSING = 3, SEMI_ACTIVE, UNKNOWN };
63 
64 enum class WifiFeatures {
65     WIFI_FEATURE_INFRA = 0x0001,             // The feature id indicates support basic infrastructure mode
66     WIFI_FEATURE_INFRA_5G = 0x0002,          // The feature id indicates support 5 GHz Band
67     WIFI_FEATURE_PASSPOINT = 0x0004,         // The feature id indicates support GAS/ANQP
68     WIFI_FEATURE_P2P = 0x0008,               // The feature id indicates support Wifi-Direct
69     WIFI_FEATURE_MOBILE_HOTSPOT = 0x0010,    // The feature id indicates support Soft AP
70     WIFI_FEATURE_AWARE = 0x0040,             // The feature id indicates support Wi-Fi AWare networking
71     WIFI_FEATURE_AP_STA = 0x8000,            // The feature id indicates support AP STA Concurrency
72     WIFI_FEATURE_WPA3_SAE = 0x8000000,       // The feature id indicates support WPA3-Personal SAE
73     WIFI_FEATURE_WPA3_SUITE_B = 0x10000000,  // The feature id indicates support WPA3-Enterprise Suite-B
74     WIFI_FEATURE_OWE = 0x20000000,           // The feature id indicates support Enhanced Open
75 };
76 
77 enum class OperateResState {
78     OPEN_WIFI_OPENING = 0,             /* open wifi opening */
79     OPEN_WIFI_SUCCEED,                 /* open wifi succeed */
80     OPEN_WIFI_FAILED,                  /* open wifi failed */
81     OPEN_WIFI_OVERRIDE_OPEN_FAILED,    /* enable wifi repeatedly */
82     OPEN_WIFI_DISABLED,                /* open wifi failed, set wifi disabled */
83     OPEN_WIFI_SUPPLICANT_INIT_FAILED,  /* wpa_supplicant not inited or init failed */
84     OPEN_WIFI_OPEN_SUPPLICANT_FAILED,  /* wpa_supplicant start failed */
85     OPEN_WIFI_CONN_SUPPLICANT_FAILED,  /* connect wpa_supplicant failed */
86     CLOSE_WIFI_CLOSING,                /* close wifi closing */
87     CLOSE_WIFI_SUCCEED,                /* close wifi succeed */
88     CLOSE_WIFI_FAILED,                 /* close wifi failed */
89     CONNECT_CONNECTING,                /* connecting */
90     CONNECT_CONNECTING_TIMEOUT,        /* connecting time out */
91     CONNECT_TO_OWN_AP_FAILED,          /* connect own ap failed */
92     CONNECT_ENABLE_NETWORK_FAILED,     /* wpa_supplicant enable network failed */
93     CONNECT_SELECT_NETWORK_FAILED,     /* wpa_supplicant select network failed */
94     CONNECT_SAVE_DEVICE_CONFIG_FAILED, /* wpa_supplicant save network config failed */
95     CONNECT_AP_CONNECTED,              /* connect succeed */
96     CONNECT_CHECK_PORTAL,              /* check connect to a portal hotspot */
97     CONNECT_NETWORK_ENABLED,           /* can visit internet */
98     CONNECT_NETWORK_DISABLED,          /* cannot visit internet */
99     CONNECT_NETWORK_NORELATED,
100     DISCONNECT_DISCONNECTING,          /* disconnecting */
101     DISCONNECT_DISCONNECT_FAILED,      /* disconnect failed */
102     DISCONNECT_DISCONNECTED,           /* disconnect succeed */
103     CONNECT_PASSWORD_WRONG,            /* wrong password */
104     CONNECT_CONNECTION_FULL,           /* connection full */
105     CONNECT_CONNECTION_REJECT,         /* connection reject */
106     CONNECT_OBTAINING_IP,              /* obtain ip */
107     CONNECT_OBTAINING_IP_FAILED,       /* obtain ip FAILED */
108     CONNECT_ASSOCIATING,
109     CONNECT_ASSOCIATED,
110     OPEN_SCAN_ONLY_OPENING,                  /* open scan only opening */
111     OPEN_SCAN_ONLY_SUCCEED,                 /* open scan only succeed */
112     OPEN_SCAN_ONLY_FAILED,                  /* open scan only failed */
113     CLOSE_SCAN_ONLY_CLOSING,                /* close scan only closing */
114     CLOSE_SCAN_ONLY_SUCCEED,                /* close scan only succeed */
115     CLOSE_SCAN_ONLY_FAILED,                 /* close scan only failed */
116     SPECIAL_CONNECTED,                  /* special connected */
117     ENABLE_SEMI_WIFI_OPENING,               /* enable semi wifi opening */
118     ENABLE_SEMI_WIFI_SUCCEED,               /* enable semi wifi succeed */
119     ENABLE_SEMI_WIFI_FAILED,                /* enable semi wifi failed */
120     CONNECT_MISS_MATCH,                 /* miss match in scan when connect */
121     CONNECT_EMLSR_START,                /* emlsr start */
122     CONNECT_EMLSR_END,                  /* emlsr end */
123 };
124 
125 enum SystemMode : int {
126     M_DEFAULT = 1,
127     M_FACTORY_MODE = 2,
128 };
129 
130 enum ProductDeviceType : int {
131     DEFAULT = -1,
132     PHONE = 0,
133     TABLET = 1,
134     WEARABLE = 2,
135 	TV = 3,
136     PC = 4
137 };
138 
139 struct WifiCallingInfo {
140     int callingUid;
141     int callingPid;
142     int callingTokenId;
143     std::unordered_set<int> regCallBackEventId;
144 };
145 
146 struct SingleAppForbid {
147     int appID;
148     ScanIntervalMode scanIntervalMode;
149     int lessThanIntervalCount;
150     time_t continueScanTime;
151     time_t blockListScanTime;
152     int expScanCount;
153     int fixedScanCount;
154     time_t fixedCurrentTime;
SingleAppForbidSingleAppForbid155     SingleAppForbid()
156     {
157         appID = 0;
158         lessThanIntervalCount = 0;
159         continueScanTime = 0;
160         blockListScanTime = 0;
161         expScanCount = 0;
162         fixedScanCount = 0;
163         fixedCurrentTime = 0;
164     }
165 };
166 
167 struct CfgInfo {
168     CfgType type;
169     char* data;
170     int dataLen;
CfgInfoCfgInfo171     CfgInfo()
172     {
173         type = CfgType::CFG_INVALID;
174         data = nullptr;
175         dataLen = 0;
176     }
177 };
178 
179 struct WifiEventCallbackMsg {
180     int msgCode;
181     int msgData;
182     int id;
183     std::string pinCode; /* wps pin mode code */
184     WifiLinkedInfo linkInfo;
185     StationInfo staInfo;
186     std::vector<WifiP2pDevice> device;
187     std::vector<WifiP2pServiceInfo> serviceInfo;
188     WifiP2pLinkedInfo p2pInfo;
189     WifiP2pDevice p2pDevice;
190     P2pActionCallback p2pAction;
191     CfgInfo* cfgInfo;
192     GcInfo gcInfo;
193     std::string privateWfdInfo;
194     int errCode;
WifiEventCallbackMsgWifiEventCallbackMsg195     WifiEventCallbackMsg()
196     {
197         msgCode = 0;
198         msgData = 0;
199         id = 0;
200         p2pAction = P2pActionCallback::UNKNOWN;
201         cfgInfo = nullptr;
202         errCode = 0;
203     }
204 };
205 
206 enum class DhcpIpType { /* dhcp IP type: ipv4 ipv6 mix */
207     DHCP_IPTYPE_IPV4,
208     DHCP_IPTYPE_IPV6,
209     DHCP_IPTYPE_MIX,
210 };
211 
212 enum class OperatorWifiType {
213     WIFI_DISABLED,
214     WIFI_ENABLED,
215     WIFI_ENABLED_AIRPLANEMODE_OVERRIDE,
216     WIFI_DISABLED_AIRPLANEMODE_ON,
217 };
218 
219 enum class StaApExclusionType {
220     USER_OPEN_WIFI_AUTO_STOP_AP,         /* User open wifi auto stop ap */
221     USER_OPEN_AP_AUTO_STOP_WIFI,         /* User open ap auto stop wifi */
222     USER_CLOSE_AP_AUTO_START_WIFI,       /* User close ap auto start wifi */
223     INITIAL_TYPE,                        /* initial type */
224 };
225 
226 /* wifi config store */
227 struct WifiConfig {
228     bool scanAlwaysSwitch; /* scan always switch */
229     int staAirplaneMode; /* operator wifi type */
230     int64_t persistWifiTime; /* persist wifi state time */
231     int toggleWifiCaller;
232     bool canOpenStaWhenAirplane; /* if airplane is opened, whether can open sta */
233     bool openWifiWhenAirplane;
234     bool wifiDisabledByAirplane;
235     /**
236      * last sta service state, when service started, power
237      * saving off, airplane mode off we use this saved state to
238      * discuss whether need restore sta service. when open sta
239      * service, set 1; when user call DisableWifi succeed,
240      * set 0; when sta is semi active, set 2;
241      */
242     int staLastState;
243     int lastAirplaneMode;
244     int savedDeviceAppraisalPriority;
245     int scoretacticsScoreSlope;
246     int scoretacticsInitScore;
247     int scoretacticsSameBssidScore;
248     int scoretacticsSameNetworkScore;
249     int scoretacticsFrequency5GHzScore;
250     int scoretacticsLastSelectionScore;
251     int scoretacticsSecurityScore;
252     int scoretacticsNormalScore;
253     bool whetherToAllowNetworkSwitchover;
254     int dhcpIpType;
255     std::string defaultWifiInterface;
256     bool preLoadSta;
257     bool preLoadScan;
258     bool preLoadAp;
259     bool preLoadP2p;
260     bool preLoadAware;
261     bool preLoadEnhance;
262     bool supportHwPnoFlag;
263     int minRssi2Dot4Ghz;
264     int minRssi5Ghz;
265     int firstRssiLevel2G;
266     int secondRssiLevel2G;
267     int thirdRssiLevel2G;
268     int fourthRssiLevel2G;
269     int firstRssiLevel5G;
270     int secondRssiLevel5G;
271     int thirdRssiLevel5G;
272     int fourthRssiLevel5G;
273     std::string strDnsBak;
274     bool isLoadStabak;
275     bool scanOnlySwitch;
276     std::string realMacAddress;
277     int staApExclusionType;
278 
WifiConfigWifiConfig279     WifiConfig()
280     {
281         scanAlwaysSwitch = false;
282         staAirplaneMode = static_cast<int>(OperatorWifiType::WIFI_DISABLED);
283         persistWifiTime = 0;
284         toggleWifiCaller = 0;
285         canOpenStaWhenAirplane = true;
286         openWifiWhenAirplane = false;
287         wifiDisabledByAirplane = false;
288         staLastState = 0;
289         lastAirplaneMode = AIRPLANE_MODE_CLOSE;
290         savedDeviceAppraisalPriority = PRIORITY_1;
291         scoretacticsScoreSlope = SCORE_SLOPE;
292         scoretacticsInitScore = INIT_SCORE;
293         scoretacticsSameBssidScore = SAME_BSSID_SCORE;
294         scoretacticsSameNetworkScore = SAME_NETWORK_SCORE;
295         scoretacticsFrequency5GHzScore = FREQUENCY_5_GHZ_SCORE;
296         scoretacticsLastSelectionScore = LAST_SELECTION_SCORE;
297         scoretacticsSecurityScore = SECURITY_SCORE;
298         scoretacticsNormalScore = NORMAL_SCORE;
299         whetherToAllowNetworkSwitchover = true;
300         dhcpIpType = static_cast<int>(DhcpIpType::DHCP_IPTYPE_MIX);
301         defaultWifiInterface = "wlan0";
302         preLoadSta = false;
303         preLoadScan = false;
304         preLoadAp = false;
305         preLoadP2p = false;
306         preLoadAware = false;
307         supportHwPnoFlag = true;
308         minRssi2Dot4Ghz = MIN_RSSI_24GHZ;
309         minRssi5Ghz = MIN_RSSI_5GHZ;
310         firstRssiLevel2G = RSSI_LEVEL_1_2G;
311         secondRssiLevel2G = RSSI_LEVEL_2_2G;
312         thirdRssiLevel2G = RSSI_LEVEL_3_2G;
313         fourthRssiLevel2G = RSSI_LEVEL_4_2G;
314         firstRssiLevel5G = RSSI_LEVEL_1_5G;
315         secondRssiLevel5G = RSSI_LEVEL_2_5G;
316         thirdRssiLevel5G = RSSI_LEVEL_3_5G;
317         fourthRssiLevel5G = RSSI_LEVEL_4_5G;
318         strDnsBak = "0.0.0.0";
319         isLoadStabak = true;
320         preLoadEnhance = false;
321         scanOnlySwitch = true;
322         realMacAddress = "";
323         staApExclusionType = static_cast<int>(StaApExclusionType::INITIAL_TYPE);
324     }
325 };
326 
327 struct TrustListPolicy {
328     int sceneId = 0;        /* scene id */
329     std::string sceneName;  /* scene name, just to read. */
330     std::string trustList;  /* trust list, eg: for A,B,and C,the format is A|B|C */
331 
TrustListPolicyTrustListPolicy332     TrustListPolicy()
333     {
334         sceneId = 0;
335         sceneName = "";
336         trustList = "";
337     }
338 };
339 
340 struct MovingFreezePolicy {
341     std::string trustList;  /* trust list */
342 
MovingFreezePolicyMovingFreezePolicy343     MovingFreezePolicy()
344     {
345         trustList = "";
346     }
347 };
348 
349 /* wifi RandomMac store */
350 struct WifiStoreRandomMac {
351     int version = 0;
352     std::string ssid;
353     std::string keyMgmt;
354     std::string peerBssid;
355     std::string randomMac;
356     std::string preSharedKey;
357     std::unordered_set<std::string> fuzzyBssids;
358 };
359 }  // namespace Wifi
360 }  // namespace OHOS
361 #endif
362