• 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 
26 namespace OHOS {
27 namespace Wifi {
28 constexpr int REOPEN_STA_INTERVAL = 500; /* when reopen sta, need over last close sta time then interval */
29 constexpr int DEVICE_CONFIG_INDEX_SSID = 0;
30 constexpr int DEVICE_CONFIG_INDEX_BSSID = 1;
31 constexpr int PRIORITY_1 = 1;
32 constexpr int PRIORITY_2 = 2;
33 constexpr int PRIORITY_3 = 3;
34 constexpr int SCORE_SLOPE = 5;
35 constexpr int INIT_SCORE = 10;
36 constexpr int SAME_BSSID_SCORE = 8;
37 constexpr int SAME_NETWORK_SCORE = 5;
38 constexpr int FREQUENCY_5_GHZ_SCORE = 10;
39 constexpr int LAST_SELECTION_SCORE = 120;
40 constexpr int SECURITY_SCORE = 20;
41 constexpr int NORMAL_SCORE = 10;
42 constexpr int MIN_RSSI_24GHZ = -80;
43 constexpr int MIN_RSSI_5GHZ = -77;
44 constexpr int RSSI_LEVEL_1_2G = -88;
45 constexpr int RSSI_LEVEL_2_2G = -82;
46 constexpr int RSSI_LEVEL_3_2G = -75;
47 constexpr int RSSI_LEVEL_4_2G = -65;
48 constexpr int RSSI_LEVEL_1_5G = -85;
49 constexpr int RSSI_LEVEL_2_5G = -79;
50 constexpr int RSSI_LEVEL_3_5G = -72;
51 constexpr int RSSI_LEVEL_4_5G = -65;
52 constexpr int WIFI_MODE_UNDEFINED = 0;
53 constexpr int WIFI_802_11A = 1;
54 constexpr int WIFI_802_11B = 2;
55 constexpr int WIFI_802_11G = 3;
56 constexpr int WIFI_802_11N = 4;
57 constexpr int WIFI_802_11AC = 5;
58 constexpr int WIFI_802_11AX = 6;
59 
60 enum class WifiOprMidState { CLOSED = 0, OPENING = 1, RUNNING = 2, CLOSING = 3, 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     DISCONNECT_DISCONNECTING,          /* disconnecting */
98     DISCONNECT_DISCONNECT_FAILED,      /* disconnect failed */
99     DISCONNECT_DISCONNECTED,           /* disconnect succeed */
100     CONNECT_PASSWORD_WRONG,            /* wrong password */
101     CONNECT_CONNECTION_FULL,           /* connection full */
102     CONNECT_CONNECTION_REJECT,         /* connection reject */
103     CONNECT_OBTAINING_IP,              /* obtain ip */
104     CONNECT_OBTAINING_IP_FAILED,       /* obtain ip FAILED */
105     CONNECT_ASSOCIATING,
106     CONNECT_ASSOCIATED,
107     OPEN_SCAN_ONLY_OPENING,                  /* open scan only opening */
108     OPEN_SCAN_ONLY_SUCCEED,                 /* open scan only succeed */
109     OPEN_SCAN_ONLY_FAILED,                  /* open scan only failed */
110     CLOSE_SCAN_ONLY_CLOSING,                /* close scan only closing */
111     CLOSE_SCAN_ONLY_SUCCEED,                /* close scan only succeed */
112     CLOSE_SCAN_ONLY_FAILED,                 /* close scan only failed */
113 };
114 
115 /* is wps connected to a network */
116 enum class IsWpsConnected {
117     WPS_CONNECTED = 0,
118     WPS_INVALID = -1,
119 };
120 
121 enum class Ant {
122     NETWORK_PRIVATE = 0,
123     NETWORK_PRIVATEWITHGUEST = 1,
124     NETWORK_CHARGEABLEPUBLIC = 2,
125     NETWORK_FREEPUBLIC = 3,
126     NETWORK_PERSONAL = 4,
127     NETWORK_EMERGENCYONLY = 5,
128     NETWORK_RESVD6 = 6,
129     NETWORK_RESVD7 = 7,
130     NETWORK_RESVD8 = 8,
131     NETWORK_RESVD9 = 9,
132     NETWORK_RESVD10 = 10,
133     NETWORK_RESVD11 = 11,
134     NETWORK_RESVD12 = 12,
135     NETWORK_RESVD13 = 13,
136     NETWORK_TESTOREXPERIMENTAL = 14,
137     NETWORK_WILDCARD = 15,
138     NETWORK_ANT_INVALID = 16
139 };
140 
141 enum class AutoStartOrStopServiceReason {
142     AUTO_START_UPON_STARTUP = 0,                /* auto-start upon startup */
143     AIRPLANE_MODE,                              /* airplane mode */
144     STA_AP_EXCLUSION,                           /* sta and ap exclusion */
145     TRYTO_OPERATE_P2P_WHEN_STA_STATE_CHANGE,    /* Try to operate p2p service again, when the sta state change */
146 };
147 
148 struct InterScanInfo {
149     std::string bssid;
150     std::string ssid;
151     /**
152      * Network performance, including authentication,
153      * key management, and encryption mechanisms
154      * supported by the access point
155      */
156     std::string capabilities;
157     int frequency;
158     int band;  /* ap band, 1: 2.4G, 2: 5G */
159     WifiChannelWidth channelWidth;
160     int centerFrequency0;
161     int centerFrequency1;
162     int rssi; /* signal level */
163     WifiSecurity securityType;
164     std::vector<WifiInfoElem> infoElems;
165     int64_t features;
166     int64_t timestamp;
167     Ant ant;
168     int wifiMode;
169     bool isVhtInfoExist;
170     bool isHtInfoExist;
171     bool isHeInfoExist;
172     bool isErpExist;
173     int maxRates;
174 
InterScanInfoInterScanInfo175     InterScanInfo()
176         : frequency(0),
177           band(0),
178           channelWidth(WifiChannelWidth::WIDTH_INVALID),
179           centerFrequency0(0),
180           centerFrequency1(0),
181           rssi(0),
182           securityType(WifiSecurity::INVALID),
183           features(0),
184           timestamp(0),
185           ant(Ant::NETWORK_ANT_INVALID),
186           wifiMode(WIFI_MODE_UNDEFINED),
187           isVhtInfoExist(false),
188           isHtInfoExist(false),
189           isHeInfoExist(false),
190           isErpExist(false),
191           maxRates(0)
192     {}
193 
~InterScanInfoInterScanInfo194     ~InterScanInfo()
195     {}
196 
GetDeviceMgmtInterScanInfo197     void GetDeviceMgmt(std::string &mgmt)
198     {
199         switch (securityType) {
200             case WifiSecurity::PSK:
201                 mgmt = "WPA-PSK";
202                 break;
203             case WifiSecurity::EAP:
204                 mgmt = "WPA-EAP";
205                 break;
206             case WifiSecurity::SAE:
207                 mgmt = "SAE";
208                 break;
209             case WifiSecurity::OWE:
210                 mgmt = "OWE";
211                 break;
212             default:
213                 mgmt = "NONE";
214                 break;
215         }
216     }
217 
GetWifiStandardInterScanInfo218     void GetWifiStandard(int &standard) const
219     {
220         standard = wifiMode;
221     }
222 
IsWifi11bModeInterScanInfo223     bool IsWifi11bMode() const
224     {
225         return wifiMode == WIFI_802_11B;
226     }
227 };
228 
229 struct WifiCallingInfo {
230     int callingUid;
231     int callingPid;
232     int callingTokenId;
233     std::unordered_set<int> regCallBackEventId;
234 };
235 
236 struct SingleAppForbid {
237     int appID;
238     ScanIntervalMode scanIntervalMode;
239     int lessThanIntervalCount;
240     time_t continueScanTime;
241     time_t blockListScanTime;
242     int expScanCount;
243     int fixedScanCount;
244     time_t fixedCurrentTime;
SingleAppForbidSingleAppForbid245     SingleAppForbid()
246     {
247         appID = 0;
248         lessThanIntervalCount = 0;
249         continueScanTime = 0;
250         blockListScanTime = 0;
251         expScanCount = 0;
252         fixedScanCount = 0;
253         fixedCurrentTime = 0;
254     }
255 };
256 
257 struct CfgInfo {
258     CfgType type;
259     char* data;
260     int dataLen;
CfgInfoCfgInfo261     CfgInfo()
262     {
263         type = CfgType::CFG_INVALID;
264         data = nullptr;
265         dataLen = 0;
266     }
267 };
268 
269 struct WifiEventCallbackMsg {
270     int msgCode;
271     int msgData;
272     int id;
273     std::string pinCode; /* wps pin mode code */
274     WifiLinkedInfo linkInfo;
275     StationInfo staInfo;
276     std::vector<WifiP2pDevice> device;
277     std::vector<WifiP2pServiceInfo> serviceInfo;
278     WifiP2pLinkedInfo p2pInfo;
279     WifiP2pDevice p2pDevice;
280     P2pActionCallback p2pAction;
281     CfgInfo* cfgInfo;
WifiEventCallbackMsgWifiEventCallbackMsg282     WifiEventCallbackMsg()
283     {
284         msgCode = 0;
285         msgData = 0;
286         id = 0;
287         p2pAction = P2pActionCallback::UNKNOWN;
288         cfgInfo = nullptr;
289     }
290 };
291 
292 enum class DhcpIpType { /* dhcp IP type: ipv4 ipv6 mix */
293     DHCP_IPTYPE_IPV4,
294     DHCP_IPTYPE_IPV6,
295     DHCP_IPTYPE_MIX,
296 };
297 
298 enum class OperatorWifiType {
299     USER_OPEN_WIFI_IN_NO_AIRPLANEMODE,      /* User open Wifi in non-airplane mode */
300     USER_CLOSE_WIFI_IN_NO_AIRPLANEMODE,     /* User clsoe Wifi in non-airplane mode */
301     USER_OPEN_WIFI_IN_AIRPLANEMODE,         /* User open Wifi in airplane mode */
302     USER_CLOSE_WIFI_IN_AIRPLANEMODE,        /* User close Wifi in airplane mode */
303     OPEN_WIFI_DUE_TO_AIRPLANEMODE_CLOSED,   /* Open Wifi due to airplane mode closed */
304     CLOSE_WIFI_DUE_TO_AIRPLANEMODE_OPENED,  /* Close Wifi due to airplane mode opened */
305     INITIAL_TYPE,                            /* initial type */
306 };
307 
308 enum class StaApExclusionType {
309     USER_OPEN_WIFI_AUTO_STOP_AP,      /* User open wifi auto stop ap */
310     USER_OPEN_AP_AUTO_STOP_WIFI,      /* User open ap auto stop wifi */
311     USER_CLOSE_AP_AUTO_START_WIFI,    /* User close ap auto start wifi */
312     INITIAL_TYPE,                     /* initial type */
313 };
314 
315 /* wifi config store */
316 struct WifiConfig {
317     bool scanAlwaysSwitch; /* scan always switch */
318     int staAirplaneMode; /* operator wifi type */
319     bool canOpenStaWhenAirplane; /* if airplane is opened, whether can open sta */
320     /**
321      * last sta service state, when service started, power
322      * saving off, airplane mode off we use this saved state to
323      * discuss whether need restore sta service. when open sta
324      * service, set true; when user call DisableWifi succeed,
325      * set false;
326      */
327     bool staLastState;
328     int savedDeviceAppraisalPriority;
329     int scoretacticsScoreSlope;
330     int scoretacticsInitScore;
331     int scoretacticsSameBssidScore;
332     int scoretacticsSameNetworkScore;
333     int scoretacticsFrequency5GHzScore;
334     int scoretacticsLastSelectionScore;
335     int scoretacticsSecurityScore;
336     int scoretacticsNormalScore;
337     bool whetherToAllowNetworkSwitchover;
338     int dhcpIpType;
339     std::string defaultWifiInterface;
340     bool preLoadSta;
341     bool preLoadScan;
342     bool preLoadAp;
343     bool preLoadP2p;
344     bool preLoadAware;
345     bool preLoadEnhance;
346     bool supportHwPnoFlag;
347     int minRssi2Dot4Ghz;
348     int minRssi5Ghz;
349     int firstRssiLevel2G;
350     int secondRssiLevel2G;
351     int thirdRssiLevel2G;
352     int fourthRssiLevel2G;
353     int firstRssiLevel5G;
354     int secondRssiLevel5G;
355     int thirdRssiLevel5G;
356     int fourthRssiLevel5G;
357     std::string strDnsBak;
358     bool isLoadStabak;
359     bool scanOnlySwitch;
360     std::string realMacAddress;
361     int staApExclusionType;
362 
WifiConfigWifiConfig363     WifiConfig()
364     {
365         scanAlwaysSwitch = false;
366         staAirplaneMode = static_cast<int>(OperatorWifiType::INITIAL_TYPE);
367         canOpenStaWhenAirplane = true;
368         staLastState = false;
369         savedDeviceAppraisalPriority = PRIORITY_1;
370         scoretacticsScoreSlope = SCORE_SLOPE;
371         scoretacticsInitScore = INIT_SCORE;
372         scoretacticsSameBssidScore = SAME_BSSID_SCORE;
373         scoretacticsSameNetworkScore = SAME_NETWORK_SCORE;
374         scoretacticsFrequency5GHzScore = FREQUENCY_5_GHZ_SCORE;
375         scoretacticsLastSelectionScore = LAST_SELECTION_SCORE;
376         scoretacticsSecurityScore = SECURITY_SCORE;
377         scoretacticsNormalScore = NORMAL_SCORE;
378         whetherToAllowNetworkSwitchover = true;
379         dhcpIpType = static_cast<int>(DhcpIpType::DHCP_IPTYPE_MIX);
380         defaultWifiInterface = "wlan0";
381         preLoadSta = false;
382         preLoadScan = false;
383         preLoadAp = false;
384         preLoadP2p = false;
385         preLoadAware = false;
386         supportHwPnoFlag = true;
387         minRssi2Dot4Ghz = MIN_RSSI_24GHZ;
388         minRssi5Ghz = MIN_RSSI_5GHZ;
389         firstRssiLevel2G = RSSI_LEVEL_1_2G;
390         secondRssiLevel2G = RSSI_LEVEL_2_2G;
391         thirdRssiLevel2G = RSSI_LEVEL_3_2G;
392         fourthRssiLevel2G = RSSI_LEVEL_4_2G;
393         firstRssiLevel5G = RSSI_LEVEL_1_5G;
394         secondRssiLevel5G = RSSI_LEVEL_2_5G;
395         thirdRssiLevel5G = RSSI_LEVEL_3_5G;
396         fourthRssiLevel5G = RSSI_LEVEL_4_5G;
397         strDnsBak = "8.8.8.8";
398         isLoadStabak = true;
399         preLoadEnhance = false;
400         scanOnlySwitch = false;
401         realMacAddress = "";
402         staApExclusionType = static_cast<int>(StaApExclusionType::INITIAL_TYPE);
403     }
404 };
405 
406 struct TrustListPolicy {
407     int sceneId = 0;        /* scene id */
408     std::string sceneName;  /* scene name, just to read. */
409     std::string trustList;  /* trust list, eg: for A,B,and C,the format is A|B|C */
410 
TrustListPolicyTrustListPolicy411     TrustListPolicy()
412     {
413         sceneId = 0;
414         sceneName = "";
415         trustList = "";
416     }
417 };
418 
419 struct MovingFreezePolicy {
420     std::string trustList;  /* trust list */
421 
MovingFreezePolicyMovingFreezePolicy422     MovingFreezePolicy()
423     {
424         trustList = "";
425     }
426 };
427 
428 /* wifi RandomMac store */
429 struct WifiStoreRandomMac {
430     std::string ssid;
431     std::string keyMgmt;
432     std::string peerBssid;
433     std::string randomMac;
434     std::string preSharedKey;
435 };
436 }  // namespace Wifi
437 }  // namespace OHOS
438 #endif
439