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