• 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 #ifndef OHOS_WIFI_MSG_H
16 #define OHOS_WIFI_MSG_H
17 
18 #include <algorithm>
19 #include <cstring>
20 #include <ctime>
21 #include <iomanip>
22 #include <map>
23 #include <sstream>
24 #include <string>
25 #include <vector>
26 #include "ip_tools.h"
27 #include "wifi_scan_msg.h"
28 #include "securec.h"
29 
30 namespace OHOS {
31 namespace Wifi {
32 #define WIFI_COUNTRY_CODE_LEN 2
33 #define WEPKEYS_SIZE 4
34 #define INVALID_NETWORK_ID (-1)
35 #define UNKNOWN_HILINK_NETWORK_ID (-2)
36 #define WIFI_INVALID_UID (-1)
37 #define INVALID_SIGNAL_LEVEL (-1)
38 #define INVALID_LINK_ID (-1)
39 #define IPV4_ADDRESS_TYPE 0
40 #define IPV6_ADDRESS_TYPE 1
41 #define WIFI_INVALID_SIM_ID (0)
42 #define WIFI_EAP_OPEN_EXTERNAL_SIM 1
43 #define WIFI_EAP_CLOSE_EXTERNAL_SIM 0
44 #define WIFI_PASSWORD_LEN 128
45 #define MAX_PID_LIST_SIZE 128
46 #define REGISTERINFO_MAX_NUM 1000
47 #define WIFI_MAX_MLO_LINK_NUM 2
48 #define EXTERNAL_HILINK_MAX_VALUE 3
49 #define INTERNAL_HILINK_MAX_VALUE 10
50 
51 inline const std::string KEY_MGMT_NONE = "NONE";
52 inline const std::string KEY_MGMT_WEP = "WEP";
53 inline const std::string KEY_MGMT_WPA_PSK = "WPA-PSK";
54 inline const std::string KEY_MGMT_SAE = "SAE";
55 inline const std::string KEY_MGMT_EAP = "WPA-EAP";
56 inline const std::string KEY_MGMT_SUITE_B_192 = "WPA-EAP-SUITE-B-192";
57 inline const std::string KEY_MGMT_WAPI_CERT = "WAPI-CERT";
58 inline const std::string KEY_MGMT_WAPI_PSK = "WAPI-PSK";
59 inline const std::string KEY_MGMT_WAPI = "WAPI";
60 inline const int KEY_MGMT_TOTAL_NUM = 8;
61 inline const std::string KEY_MGMT_ARRAY[KEY_MGMT_TOTAL_NUM] = {
62     KEY_MGMT_NONE,
63     KEY_MGMT_WEP,
64     KEY_MGMT_WPA_PSK,
65     KEY_MGMT_SAE,
66     KEY_MGMT_EAP,
67     KEY_MGMT_SUITE_B_192,
68     KEY_MGMT_WAPI_CERT,
69     KEY_MGMT_WAPI_PSK
70 };
71 inline const std::string EAP_METHOD_NONE = "NONE";
72 inline const std::string EAP_METHOD_PEAP = "PEAP";
73 inline const std::string EAP_METHOD_TLS = "TLS";
74 inline const std::string EAP_METHOD_TTLS = "TTLS";
75 inline const std::string EAP_METHOD_PWD = "PWD";
76 inline const std::string EAP_METHOD_SIM = "SIM";
77 inline const std::string EAP_METHOD_AKA = "AKA";
78 inline const std::string EAP_METHOD_AKA_PRIME = "AKA'";
79 
80 inline const int INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP = -1;
81 
82 enum SigLevel {
83     SIG_LEVEL_0 = 0,
84     SIG_LEVEL_1 = 1,
85     SIG_LEVEL_2 = 2,
86     SIG_LEVEL_3 = 3,
87     SIG_LEVEL_4 = 4,
88     SIG_LEVEL_MAX = 4,
89 };
90 
91 enum WifiRestrictedType {
92     MDM_BLOCKLIST = 0,
93     MDM_WHITELIST = 1,
94     MDM_INVALID_LIST = 2
95 };
96 
97 enum GameSceneId : int {
98     MSG_GAME_STATE_START = 0,
99     MSG_GAME_STATE_END = 1,
100     MSG_GAME_ENTER_PVP_BATTLE = 2,
101     MSG_GAME_EXIT_PVP_BATTLE = 3,
102     MSG_GAME_STATE_FOREGROUND = 4,
103     MSG_GAME_STATE_BACKGROUND = 5,
104 };
105 
106 enum class SupplicantState {
107     DISCONNECTED = 0,
108     INTERFACE_DISABLED = 1,
109     INACTIVE = 2,
110     SCANNING = 3,
111     AUTHENTICATING = 4,
112     ASSOCIATING = 5,
113     ASSOCIATED = 6,
114     FOUR_WAY_HANDSHAKE = 7,
115     GROUP_HANDSHAKE = 8,
116     COMPLETED = 9,
117     UNKNOWN = 10,
118 
119     INVALID = 0xFF,
120 };
121 
122 enum class DetailedState {
123     AUTHENTICATING = 0,
124     BLOCKED = 1,
125     CAPTIVE_PORTAL_CHECK = 2,
126     CONNECTED = 3,
127     CONNECTING = 4,
128     DISCONNECTED = 5,
129     DISCONNECTING = 6,
130     FAILED = 7,
131     IDLE = 8,
132     OBTAINING_IPADDR = 9,
133     WORKING = 10,
134     NOTWORKING = 11,
135     SCANNING = 12,
136     SUSPENDED = 13,
137     VERIFYING_POOR_LINK = 14,
138     PASSWORD_ERROR = 15,
139     CONNECTION_REJECT = 16,
140     CONNECTION_FULL = 17,
141     CONNECTION_TIMEOUT = 18,
142     OBTAINING_IPADDR_FAIL = 19,
143     INVALID = 0xFF,
144 };
145 
146 enum ConnState {
147     /** The device is searching for an available AP. */
148     SCANNING,
149 
150     /** The Wi-Fi connection is being set up. */
151     CONNECTING,
152 
153     /** The Wi-Fi connection is being authenticated. */
154     AUTHENTICATING,
155 
156     /** The IP address of the Wi-Fi connection is being obtained. */
157     OBTAINING_IPADDR,
158 
159     /** The Wi-Fi connection has been set up. */
160     CONNECTED,
161 
162     /** The Wi-Fi connection is being torn down. */
163     DISCONNECTING,
164 
165     /** The Wi-Fi connection has been torn down. */
166     DISCONNECTED,
167 
168     /** The Wi-Fi special connection. */
169     SPECIAL_CONNECT,
170 
171     /** Failed to set up the Wi-Fi connection. */
172     UNKNOWN
173 };
174 
175 enum WurState {
176     WUR_DISABLE = 0,
177     WUR_ENABLE = 1,
178     WUR_ENABLE_FAIL = 2
179 };
180 
181 enum WifiLinkType:int32_t {
182     DISCONNECT = -1,
183     DEFAULT_LINK = 0,
184     WIFI7_SINGLE_LINK = 1,
185     WIFI7_MLSR = 2,
186     WIFI7_EMLSR = 3,
187     WIFI7_STR = 4
188 };
189 
190 enum class DisconnectedReason {
191     /* Default reason */
192     DISC_REASON_DEFAULT = 0,
193 
194     /* Password is wrong */
195     DISC_REASON_WRONG_PWD = 1,
196 
197     /* The number of router's connection reaches the maximum number limit */
198     DISC_REASON_CONNECTION_FULL = 2,
199 
200     /* Connection Rejected */
201     DISC_REASON_CONNECTION_REJECTED = 3,
202 
203     /* Connect mdm blocklist or  wifi is fail*/
204     DISC_REASON_CONNECTION_MDM_BLOCKLIST_FAIL = 5,
205 
206     /* Connect fail reason max value, add new reason before this*/
207     DISC_REASON_MAX_VALUE
208 };
209 
210 enum class WifiOperateType {
211     STA_OPEN,
212     STA_CLOSE,
213     STA_CONNECT,
214     STA_ASSOC,
215     STA_AUTH,
216     STA_DHCP,
217     STA_SEMI_OPEN
218 };
219 
220 enum class WifiOperateState {
221     STA_OPENING,
222     STA_OPENED,
223     STA_CONNECTING,
224     STA_CONNECTED,
225     STA_CONNECT_EXCEPTION,
226     STA_DISCONNECTED,
227     STA_ASSOCIATING,
228     STA_ASSOCIATED,
229     STA_ASSOC_FULL_REJECT,
230     STA_AUTHING,
231     STA_AUTHED,
232     STA_DHCP,
233     STA_DHCP_SUCCESS,
234     STA_DISCONNECT,
235     STA_DHCP_FAIL,
236     STA_CLOSING,
237     STA_CLOSED,
238     STA_SEMI_OPENING,
239     STA_SEMI_OPENED,
240 };
241 
242 enum class DisconnectDetailReason {
243     UNUSED = 0,
244     UNSPECIFIED = 1,
245     PREV_AUTH_NOT_VALID = 2,
246     DEAUTH_STA_IS_LEFING = 3,
247     DISASSOC_DUE_TO_INACTIVITY = 4,
248     DISASSOC_AP_BUSY = 5,
249     DISASSOC_STA_HAS_LEFT = 8,
250     DISASSOC_IEEE_802_1X_AUTH_FAILED = 23,
251     DISASSOC_LOW_ACK = 34
252 };
253 
254 struct WifiMloSignalInfo {
255     int32_t linkId {INVALID_LINK_ID};
256     int32_t frequency {0};
257     int32_t rssi {0};
258     int32_t linkSpeed {0};
259     int32_t rxLinkSpeed {0};
260     int32_t txLinkSpeed {0};
261     int32_t rxPackets {0};
262     int32_t txPackets {0};
263     WifiChannelWidth channelWidth {WifiChannelWidth::WIDTH_INVALID};
264 };
265 
266 struct WifiLinkedInfo {
267     int networkId;
268     std::string ssid;
269     std::string bssid;
270     int rssi; /* signal level */
271     int band; /* 2.4G / 5G */
272     int frequency;
273     int linkSpeed; /* units: Mbps */
274     std::string macAddress;
275     int macType;
276     unsigned int ipAddress;
277     ConnState connState;
278     bool ifHiddenSSID;
279     int rxLinkSpeed; /* Downstream network speed */
280     int txLinkSpeed; /* Upstream network speed */
281     int chload;
282     int snr;                         /* Signal-to-Noise Ratio */
283     int isDataRestricted;
284     std::string platformType;
285     std::string portalUrl;
286     SupplicantState supplicantState; /* wpa_supplicant state */
287     DetailedState detailedState;     /* connection state */
288     WifiLinkType wifiLinkType; /* MLO connected state */
289     int wifiStandard;                /* wifi standard */
290     int maxSupportedRxLinkSpeed;
291     int maxSupportedTxLinkSpeed;
292     WifiChannelWidth channelWidth; /* curr ap channel width */
293     int lastPacketDirection;
294     int lastRxPackets;
295     int lastTxPackets;
296     bool isAncoConnected;
297     WifiCategory supportedWifiCategory;
298     bool isMloConnected;
299     int isHiLinkNetwork;
300     bool isHiLinkProNetwork;
301     bool isWurEnable;
302     int c0Rssi;
303     int c1Rssi;
304     int linkId;
305     int centerFrequency0; /* 40M center frequency */
306     int centerFrequency1; /* 160M center frequency */
WifiLinkedInfoWifiLinkedInfo307     WifiLinkedInfo()
308     {
309         networkId = INVALID_NETWORK_ID;
310         rssi = 0;
311         band = 0;
312         frequency = 0;
313         linkSpeed = 0;
314         macType = 0;
315         ipAddress = 0;
316         connState = ConnState::UNKNOWN;
317         ifHiddenSSID = false;
318         rxLinkSpeed = 0;
319         txLinkSpeed = 0;
320         chload = 0;
321         snr = 0;
322         isDataRestricted = 0;
323         supplicantState = SupplicantState::INVALID;
324         detailedState = DetailedState::INVALID;
325         wifiLinkType = WifiLinkType::DEFAULT_LINK;
326         wifiStandard = 0;
327         maxSupportedRxLinkSpeed = 0;
328         maxSupportedTxLinkSpeed = 0;
329         channelWidth = WifiChannelWidth::WIDTH_INVALID;
330         lastPacketDirection = 0;
331         lastRxPackets = 0;
332         lastTxPackets = 0;
333         isAncoConnected = false;
334         isHiLinkNetwork = 0;
335         isHiLinkProNetwork = false;
336         supportedWifiCategory = WifiCategory::DEFAULT;
337         isMloConnected = false;
338         isWurEnable = false;
339         c0Rssi = 0;
340         c1Rssi = 0;
341         linkId = INVALID_LINK_ID;
342         centerFrequency0 = 0;
343         centerFrequency1 = 0;
344     }
345 };
346 
347 /* Wifi access list info */
348 struct WifiRestrictedInfo {
349     std::string ssid;
350     std::string bssid;
351     WifiRestrictedType wifiRestrictedType;
352     int uid;
353 
WifiRestrictedInfoWifiRestrictedInfo354     WifiRestrictedInfo()
355     {
356         ssid = "";
357         bssid = "";
358         wifiRestrictedType = MDM_INVALID_LIST;
359         uid = 0;
360     }
361 };
362 
363 /* use WPS type */
364 enum class SetupMethod {
365     PBC = 0,
366     DISPLAY = 1,
367     KEYPAD = 2,
368     LABEL = 3,
369     INVALID = 4,
370 };
371 
372 /* WPS config */
373 struct WpsConfig {
374     SetupMethod setup; /* WPS type */
375     std::string pin;   /* pin code */
376     std::string bssid; /* KEYPAD mode pin code */
377 
WpsConfigWpsConfig378     WpsConfig()
379     {
380         setup = SetupMethod::INVALID;
381     }
382 };
383 
384 enum class WifiDeviceConfigStatus {
385     ENABLED, /* enable */
386     DISABLED, /* disabled */
387     PERMEMANTLY_DISABLED, /* permanently disabled */
388     UNKNOWN
389 };
390 
391 enum class AssignIpMethod { DHCP, STATIC, UNASSIGNED };
392 
393 enum class ConfigChange {
394     CONFIG_ADD = 0,
395     CONFIG_UPDATE = 1,
396     CONFIG_REMOVE = 2,
397 };
398 
399 enum class CandidateApprovalStatus {
400     USER_ACCEPT = 0,
401     USER_REJECT = 1,
402     USER_NO_RESPOND = 2,
403 };
404 
405 struct VoWifiSignalInfo {
406     int rssi;
407     int noise;
408     int bler;
409     int deltaTxPacketCounter;
410     int accessType;
411     int reverse;
412     int64_t txGood;
413     int64_t txBad;
414     std::string macAddress;
415 };
416 
417 struct WifiDetectConfInfo {
418     int wifiDetectMode;
419     int threshold;
420     int envalueCount;
421 };
422 
423 class WifiIpAddress {
424 public:
425     int family;                             /* ip type */
426     unsigned int addressIpv4;               /* IPv4 */
427     std::vector<unsigned char> addressIpv6; /* IPv6 */
428 
WifiIpAddress()429     WifiIpAddress()
430     {
431         family = -1;
432         addressIpv4 = 0;
433     }
434 
~WifiIpAddress()435     ~WifiIpAddress()
436     {}
437 
GetIpv4Address()438     std::string GetIpv4Address()
439     {
440         return IpTools::ConvertIpv4Address(addressIpv4);
441     }
442 
SetIpv4Address(const std::string & address)443     void SetIpv4Address(const std::string &address)
444     {
445         addressIpv4 = IpTools::ConvertIpv4Address(address);
446         if (addressIpv4 != 0) {
447             family = IPV4_ADDRESS_TYPE;
448         }
449         return;
450     }
451 
GetIpv6Address()452     std::string GetIpv6Address() const
453     {
454         return IpTools::ConvertIpv6Address(addressIpv6);
455     }
456 
SetIpv6Address(const std::string & address)457     void SetIpv6Address(const std::string &address)
458     {
459         IpTools::ConvertIpv6Address(address, addressIpv6);
460         if (addressIpv6.size() != 0) {
461             family = IPV6_ADDRESS_TYPE;
462         }
463         return;
464     }
465 };
466 
467 class WifiLinkAddress {
468 public:
469     WifiIpAddress address; /* IP address */
470     int prefixLength;
471     int flags;
472     int scope;
473 
WifiLinkAddress()474     WifiLinkAddress()
475     {
476         prefixLength = 0;
477         flags = 0;
478         scope = 0;
479     }
480 
~WifiLinkAddress()481     ~WifiLinkAddress()
482     {}
483 };
484 
485 class StaticIpAddress {
486 public:
487     WifiLinkAddress ipAddress;
488     WifiIpAddress gateway;
489     WifiIpAddress dnsServer1; /* main DNS */
490     WifiIpAddress dnsServer2; /* backup DNS */
491     std::string domains;
492 
GetIpv4Mask()493     std::string GetIpv4Mask()
494     {
495         return IpTools::ConvertIpv4Mask(ipAddress.prefixLength);
496     }
497 
GetIpv6Mask()498     std::string GetIpv6Mask()
499     {
500         return IpTools::ConvertIpv6Mask(ipAddress.prefixLength);
501     }
502 };
503 
504 class WifiIpConfig {
505 public:
506     AssignIpMethod assignMethod;
507     StaticIpAddress staticIpAddress;
508 
WifiIpConfig()509     WifiIpConfig()
510     {
511         assignMethod = AssignIpMethod::DHCP;
512     }
~WifiIpConfig()513     ~WifiIpConfig()
514     {}
515 };
516 
517 enum class EapMethod {
518     EAP_NONE       = 0,
519     EAP_PEAP       = 1,
520     EAP_TLS        = 2,
521     EAP_TTLS       = 3,
522     EAP_PWD        = 4,
523     EAP_SIM        = 5,
524     EAP_AKA        = 6,
525     EAP_AKA_PRIME  = 7,
526     EAP_UNAUTH_TLS = 8
527 };
528 
529 enum class Phase2Method {
530     NONE      = 0,
531     PAP       = 1,  // only EAP-TTLS support this mode
532     MSCHAP    = 2,  // only EAP-TTLS support this mode
533     MSCHAPV2  = 3,  // only EAP-PEAP/EAP-TTLS support this mode
534     GTC       = 4,  // only EAP-PEAP/EAP-TTLS support this mode
535     SIM       = 5,  // only EAP-PEAP support this mode
536     AKA       = 6,  // only EAP-PEAP support this mode
537     AKA_PRIME = 7   // only EAP-PEAP support this mode
538 };
539 
540 class WifiEapConfig {
541 public:
542     std::string eap;                        /* EAP authentication mode:PEAP/TLS/TTLS/PWD/SIM/AKA/AKA' */
543     Phase2Method phase2Method;              /* Second stage authentication method */
544     std::string identity;                   /* Identity information */
545     std::string anonymousIdentity;          /* Anonymous identity information */
546     std::string password;                   /* EAP mode password */
547     std::string encryptedData;              /* EAP mode password encryptedData */
548     std::string IV;                         /* EAP mode password encrypted IV */
549 
550     std::string caCertPath;                 /* CA certificate path */
551     std::string caCertAlias;                /* CA certificate alias */
552     std::vector<uint8_t> certEntry;         /* CA certificate entry */
553 
554     std::string clientCert;                 /* Client certificate */
555     char certPassword[WIFI_PASSWORD_LEN];   /* Certificate password */
556     std::string privateKey;                 /* Client certificate private key */
557 
558     std::string altSubjectMatch;            /* Alternative topic matching */
559     std::string domainSuffixMatch;          /* Domain suffix matching */
560     std::string realm;                      /* The field of passport credentials */
561     std::string plmn;                       /* PLMN */
562     int eapSubId;                           /* Sub ID of SIM card */
563 
WifiEapConfig()564     WifiEapConfig()
565     {
566         phase2Method = Phase2Method::NONE;
567         (void) memset_s(certPassword, sizeof(certPassword), 0, sizeof(certPassword));
568         eapSubId = -1;
569     }
~WifiEapConfig()570     ~WifiEapConfig()
571     {}
572     /**
573      * @Description convert Phase2Method to string
574      *
575      * @param eap - eap method
576      * @param method - phase2method
577      * @return string
578      */
579     static std::string Phase2MethodToStr(const std::string& eap, const int& method);
580 
581     /**
582      * @Description convert string to Phase2Method
583      *
584      * @param str - phase2method string
585      * @return Phase2Method
586      */
587     static Phase2Method Phase2MethodFromStr(const std::string& str);
588 
589     /**
590      * @Description convert string to EapMethod
591      *
592      * @param str - EapMethod string
593      * @return EapMethod
594      */
595     static EapMethod Str2EapMethod(const std::string& str);
596 };
597 
598 enum class ConfigureProxyMethod { CLOSED, AUTOCONFIGUE, MANUALCONFIGUE };
599 
600 class AutoProxyConfig {
601 public:
602     std::string pacWebAddress;
603 };
604 
605 class ManualProxyConfig {
606 public:
607     std::string serverHostName;
608     int serverPort;
609     std::string exclusionObjectList;
610 
GetExclusionObjectList(std::vector<std::string> & exclusionList)611     void GetExclusionObjectList(std::vector<std::string> &exclusionList)
612     {
613         IpTools::GetExclusionObjectList(exclusionObjectList, exclusionList);
614         return;
615     }
616 
ManualProxyConfig()617     ManualProxyConfig()
618     {
619         serverPort = 0;
620     }
~ManualProxyConfig()621     ~ManualProxyConfig()
622     {}
623 };
624 
625 class WifiProxyConfig {
626 public:
627     ConfigureProxyMethod configureMethod;
628     AutoProxyConfig autoProxyConfig;
629     ManualProxyConfig manualProxyConfig;
630 
WifiProxyConfig()631     WifiProxyConfig()
632     {
633         configureMethod = ConfigureProxyMethod::CLOSED;
634     }
~WifiProxyConfig()635     ~WifiProxyConfig()
636     {}
637 };
638 
639 enum class WifiPrivacyConfig { RANDOMMAC, DEVICEMAC };
640 
641 enum class DisabledReason {
642     DISABLED_UNKNOWN_REASON = -1,
643     DISABLED_NONE = 0,
644     DISABLED_ASSOCIATION_REJECTION = 1,
645     DISABLED_AUTHENTICATION_FAILURE = 2,
646     DISABLED_DHCP_FAILURE = 3,
647     DISABLED_NO_INTERNET_TEMPORARY = 4,
648     DISABLED_AUTHENTICATION_NO_CREDENTIALS = 5,
649     DISABLED_NO_INTERNET_PERMANENT = 6,
650     DISABLED_BY_WIFI_MANAGER = 7,
651     DISABLED_BY_WRONG_PASSWORD = 8,
652     DISABLED_AUTHENTICATION_NO_SUBSCRIPTION = 9,
653     DISABLED_AUTHENTICATION_PRIVATE_EAP_ERROR = 10,
654     DISABLED_NETWORK_NOT_FOUND = 11,
655     DISABLED_CONSECUTIVE_FAILURES = 12,
656     DISABLED_BY_SYSTEM = 13,
657     DISABLED_EAP_AKA_FAILURE = 14,
658     DISABLED_DISASSOC_REASON = 15,
659     DISABLED_MDM_RESTRICTED = 16,
660     NETWORK_SELECTION_DISABLED_MAX = 17
661 };
662 
663 struct NetworkSelectionStatus {
664     WifiDeviceConfigStatus status;
665     DisabledReason networkSelectionDisableReason;
666     int64_t networkDisableTimeStamp;
667     int networkDisableCount;
668 
669     /**
670      * Connect Choice over this configuration
671      * when current wifi config is visible to the user but user explicitly choose to connect to another network X,
672      * the another network X's config network ID will be stored here. We will consider user has a preference of X
673      * over this network. And in the future, network Select will always give X a higher preference over this config
674      */
675     int connectChoice;
676 
677     /**
678      * The system timestamp when we records the connectChoice. Used to calculate if timeout of network selected by user
679      */
680     long connectChoiceTimestamp;
681 
682     /**
683      * Indicate whether this network is visible in last Qualified Network Selection. This means there is scan result
684      * found to this WifiDeviceConfig and meet the minimum requirement.
685      */
686     bool seenInLastQualifiedNetworkSelection;
NetworkSelectionStatusNetworkSelectionStatus687     NetworkSelectionStatus()
688     {
689         status = WifiDeviceConfigStatus::ENABLED;
690         networkSelectionDisableReason = DisabledReason::DISABLED_NONE;
691         networkDisableTimeStamp = -1;
692         networkDisableCount = 0;
693         connectChoice = INVALID_NETWORK_ID;
694         connectChoiceTimestamp = INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP;
695         seenInLastQualifiedNetworkSelection = false;
696     }
697 };
698 
699 class WifiWapiConfig {
700 public:
701     int wapiPskType;
702     std::string wapiAsCertData;
703     std::string wapiUserCertData;
704     std::string encryptedAsCertData;
705     std::string asCertDataIV;
706     std::string encryptedUserCertData;
707     std::string userCertDataIV;
708 
WifiWapiConfig()709     WifiWapiConfig()
710     {
711         wapiPskType = -1;
712     }
713 
~WifiWapiConfig()714     ~WifiWapiConfig()
715     {}
716 };
717 
718 /* DHCP info */
719 struct IpInfo {
720     unsigned int ipAddress;     /* ip address */
721     unsigned int gateway;       /* gate */
722     unsigned int netmask;       /* mask */
723     unsigned int primaryDns;          /* main dns */
724     unsigned int secondDns;          /* backup dns */
725     unsigned int serverIp; /* DHCP server's address */
726     unsigned int leaseDuration;
727     std::vector<unsigned int> dnsAddr;
728 
IpInfoIpInfo729     IpInfo()
730     {
731         ipAddress = 0;
732         gateway = 0;
733         netmask = 0;
734         primaryDns = 0;
735         secondDns = 0;
736         serverIp = 0;
737         leaseDuration = 0;
738         dnsAddr.clear();
739     }
740 };
741 
742 /* Network control information */
743 struct WifiNetworkControlInfo {
744     int uid;
745     int pid;
746     std::string bundleName;
747     int state;
748     int sceneId;
749     int rtt;
750 
WifiNetworkControlInfoWifiNetworkControlInfo751     WifiNetworkControlInfo()
752     {
753         uid = -1;
754         pid = -1;
755         bundleName = "";
756         state = -1;
757         sceneId = -1;
758         rtt = -1;
759     }
760 };
761 
762 /* Network configuration information */
763 struct WifiDeviceConfig {
764     int instanceId;
765     int networkId;
766     /* int status; @deprecated : CURRENT, using 1: DISABLED 2: ENABLED */
767     /*  network selection status*/
768     NetworkSelectionStatus networkSelectionStatus;
769     /* mac address */
770     std::string bssid;
771     /* bssid type. */
772     int bssidType;
773     /* network name */
774     std::string ssid;
775     int band;
776     int channel;
777     int frequency;
778     /* Signal strength */
779     int rssi;
780     /**
781      * signal level,
782      * rssi<=-100    level : 0
783      * (-100, -88]   level : 1
784      * (-88, -77]    level : 2
785      * (-66, -55]    level : 3
786      * rssi>=-55     level : 4
787      */
788     int level;
789     /* Is Passpoint network */
790     bool isPasspoint;
791     /* is ephemeral network */
792     bool isEphemeral;
793     /* WPA-PSK mode pre shared key */
794     std::string preSharedKey;
795     std::string encryptedData;
796     std::string IV;
797     /* Encryption Mode */
798     std::string keyMgmt;
799     /* Available Encryption Mode */
800     uint32_t keyMgmtBitset;
801     /* WEP mode key, max size: 4 */
802     std::string wepKeys[WEPKEYS_SIZE];
803     /* use WEP key index */
804     int wepTxKeyIndex;
805     std::string encryWepKeys[WEPKEYS_SIZE];
806     std::string IVWep;
807     /* network priority */
808     int priority;
809     /* is hidden network */
810     bool hiddenSSID;
811     /* Random mac address */
812     std::string macAddress;
813     int uid;
814     time_t lastConnectTime;
815     /* last update time */
816     time_t lastUpdateTime;
817     int numRebootsSinceLastUse;
818     int numAssociation;
819     int connFailedCount;
820     unsigned int networkStatusHistory;
821     bool isPortal;
822     time_t portalAuthTime;
823     time_t lastHasInternetTime;
824     bool noInternetAccess;
825     /* save select mac address */
826     std::string userSelectBssid;
827     WifiIpConfig wifiIpConfig;
828     WifiEapConfig wifiEapConfig;
829     WifiProxyConfig wifiProxyconfig;
830     WifiPrivacyConfig wifiPrivacySetting;
831     std::string callProcessName;
832     std::string ancoCallProcessName;
833     std::string internetSelfCureHistory;
834     int isReassocSelfCureWithFactoryMacAddress;
835     int version;
836     bool randomizedMacSuccessEver;
837     bool everConnected;
838     bool acceptUnvalidated;
839     WifiWapiConfig wifiWapiConfig;
840     IpInfo lastDhcpResult;
841     bool isShared;
842     int64_t lastTrySwitchWifiTimestamp { -1 };
843     bool isAllowAutoConnect { true };
844     bool isSecureWifi { true };
845     time_t lastDetectTime;
846 
WifiDeviceConfigWifiDeviceConfig847     WifiDeviceConfig()
848     {
849         instanceId = 0;
850         networkId = INVALID_NETWORK_ID;
851         bssidType = REAL_DEVICE_ADDRESS;
852         band = 0;
853         channel = 0;
854         frequency = 0;
855         level = 0;
856         isPasspoint = false;
857         isEphemeral = false;
858         keyMgmtBitset = 0u;
859         wepTxKeyIndex = 0;
860         priority = 0;
861         hiddenSSID = false;
862         wifiPrivacySetting = WifiPrivacyConfig::RANDOMMAC;
863         rssi = -100;
864         uid = WIFI_INVALID_UID;
865         lastConnectTime = -1;
866         lastUpdateTime = -1;
867         numRebootsSinceLastUse = 0;
868         numAssociation = 0;
869         connFailedCount = 0;
870         networkStatusHistory = 0;
871         isPortal = false;
872         portalAuthTime = -1;
873         lastHasInternetTime = -1;
874         noInternetAccess = false;
875         callProcessName = "";
876         ancoCallProcessName = "";
877         internetSelfCureHistory = "";
878         isReassocSelfCureWithFactoryMacAddress = 0;
879         version = -1;
880         randomizedMacSuccessEver = false;
881         isShared = true;
882         everConnected = false;
883         acceptUnvalidated = false;
884         lastDetectTime = -1;
885     }
886 };
887 
888 enum class WifiState { DISABLING = 0, DISABLED = 1, ENABLING = 2, ENABLED = 3, UNKNOWN = 4 };
889 
890 enum class WifiDetailState {
891     STATE_UNKNOWN = -1,
892     STATE_INACTIVE = 0,
893     STATE_ACTIVATED = 1,
894     STATE_ACTIVATING = 2,
895     STATE_DEACTIVATING = 3,
896     STATE_SEMI_ACTIVATING = 4,
897     STATE_SEMI_ACTIVE = 5
898 };
899 
900 /* wps state */
901 enum class WpsStartState {
902     START_PBC_SUCCEED = 0,
903     START_PIN_SUCCEED = 1,
904     START_PBC_FAILED = 2,
905     PBC_STARTED_ALREADY = 3,
906     START_PIN_FAILED = 4,
907     PIN_STARTED_ALREADY = 5,
908     STOP_PBC_SUCCEED = 6,
909     STOP_PBC_FAILED = 7,
910     STOP_PIN_SUCCEED = 8,
911     STOP_PIN_FAILED = 9,
912     START_PBC_FAILED_OVERLAP = 10,
913     START_WPS_FAILED = 11,
914     WPS_TIME_OUT = 12,
915     START_AP_PIN_SUCCEED = 13,
916     START_AP_PIN_FAILED = 14,
917     STOP_AP_PIN_SUCCEED = 15,
918     STOP_AP_PIN_FAILED = 16,
919 };
920 
921 enum class StreamDirection {
922     STREAM_DIRECTION_NONE = 0,
923     STREAM_DIRECTION_DOWN = 1,
924     STREAM_DIRECTION_UP = 2,
925     STREAM_DIRECTION_UPDOWN = 3,
926 };
927 
928 /* WifiProtectType  */
929 enum class WifiProtectType  {
930     WIFI_PROTECT_MULTICAST = 0,
931     WIFI_PROTECT_COMMON = 1
932 };
933 
934 /* WifiProtectMode  */
935 enum class WifiProtectMode {
936     WIFI_PROTECT_DEFAULT = -1,
937     WIFI_PROTECT_FULL = 0,
938     WIFI_PROTECT_SCAN_ONLY = 1,
939     WIFI_PROTECT_FULL_HIGH_PERF = 2,
940     WIFI_PROTECT_FULL_LOW_LATENCY = 3,
941     WIFI_PROTECT_NO_HELD = 4
942 };
943 
944 /* DHCP IpV6Info */
945 struct IpV6Info {
946     std::string linkIpV6Address;
947     std::string globalIpV6Address;
948     std::string randGlobalIpV6Address;
949     std::string gateway;
950     std::string netmask;
951     std::string primaryDns;
952     std::string secondDns;
953     std::string uniqueLocalAddress1;
954     std::string uniqueLocalAddress2;
955     std::vector<std::string> dnsAddr;
956 
IpV6InfoIpV6Info957     IpV6Info()
958     {
959         linkIpV6Address = "";
960         globalIpV6Address = "";
961         randGlobalIpV6Address = "";
962         gateway = "";
963         netmask = "";
964         primaryDns = "";
965         secondDns = "";
966         uniqueLocalAddress1 = "";
967         uniqueLocalAddress2 = "";
968         dnsAddr.clear();
969     }
970 };
971 
972 struct WifiCategoryBlackListInfo {
973     /* 0:HTC, 1:WIFI6, -1:invalid */
974     /* 0:MLD, 1:WIFI7, -1:invalid */
975     int actionType = -1;
976     int64_t updateTime = 0;
977 
WifiCategoryBlackListInfoWifiCategoryBlackListInfo978     WifiCategoryBlackListInfo() {}
979 
WifiCategoryBlackListInfoWifiCategoryBlackListInfo980     WifiCategoryBlackListInfo(int type, int64_t time)
981     {
982         this->actionType = type;
983         this->updateTime = time;
984     }
985 };
986 
987 struct WifiCategoryConnectFailInfo {
988     /* 0:MLD, 1:WIFI7, 2:Cure Fail,-1:invalid */
989     int actionType = -1;
990     int connectFailTimes = 0;
991     int64_t updateTime = 0;
992 
WifiCategoryConnectFailInfoWifiCategoryConnectFailInfo993     WifiCategoryConnectFailInfo() {}
994 
WifiCategoryConnectFailInfoWifiCategoryConnectFailInfo995     WifiCategoryConnectFailInfo(int type, int failTimes, int64_t time)
996     {
997         this->actionType = type;
998         this->connectFailTimes = failTimes;
999         this->updateTime = time;
1000     }
1001 };
1002 
1003 // SIM authentication
1004 struct EapSimGsmAuthParam {
1005     std::vector<std::string> rands;
1006 };
1007 
1008 // AKA/AKA' authentication
1009 struct EapSimUmtsAuthParam {
1010     std::string rand;
1011     std::string autn;
EapSimUmtsAuthParamEapSimUmtsAuthParam1012     EapSimUmtsAuthParam()
1013     {
1014         rand = "";
1015         autn = "";
1016     }
1017 };
1018 
1019 struct MloStateParam {
1020     uint8_t feature;
1021     uint8_t state;
1022     uint16_t reasonCode;
1023 };
1024 
1025 typedef enum {
1026     BG_LIMIT_CONTROL_ID_GAME = 1,
1027     BG_LIMIT_CONTROL_ID_STREAM,
1028     BG_LIMIT_CONTROL_ID_TEMP,
1029     BG_LIMIT_CONTROL_ID_KEY_FG_APP,
1030     BG_LIMIT_CONTROL_ID_AUDIO_PLAYBACK,
1031     BG_LIMIT_CONTROL_ID_WINDOW_VISIBLE,
1032     BG_LIMIT_CONTROL_ID_MODULE_FOREGROUND_OPT,
1033     BG_LIMIT_CONTROL_ID_VIDEO_CALL,
1034 } BgLimitControl;
1035 
1036 typedef enum {
1037     BG_LIMIT_OFF = 0,
1038     BG_LIMIT_LEVEL_1,
1039     BG_LIMIT_LEVEL_2,
1040     BG_LIMIT_LEVEL_3,
1041     BG_LIMIT_LEVEL_4,
1042     BG_LIMIT_LEVEL_5,
1043     BG_LIMIT_LEVEL_6,
1044     BG_LIMIT_LEVEL_7,
1045     BG_LIMIT_LEVEL_8,
1046     BG_LIMIT_LEVEL_9,
1047     BG_LIMIT_LEVEL_10,
1048     BG_LIMIT_LEVEL_11,
1049 } BgLimitLevel;
1050 
1051 enum class WapiPskType {
1052     WAPI_PSK_ASCII = 0,
1053     WAPI_PSK_HEX = 1,
1054 };
1055 
1056 typedef struct {
1057     std::string ifName;
1058     int scene;
1059     int rssiThreshold;
1060     std::string peerMacaddr;
1061     std::string powerParam;
1062     int powerParamLen;
1063 } WifiLowPowerParam;
1064 
1065 enum class OperationCmd {
1066     DHCP_OFFER_ADD,
1067     DHCP_OFFER_SIZE_GET,
1068     DHCP_OFFER_CLEAR,
1069     CURRENT_IP_INFO_SET,
1070 };
1071 
1072 enum class WifiSelfcureType {
1073     DNS_ABNORMAL,
1074     TCP_RX_ABNORMAL,
1075     ROAMING_ABNORMAL,
1076     GATEWAY_ABNORMAL,
1077     RAND_MAC_REASSOC_SELFCURE,
1078     MULTI_GATEWAY_SELFCURE,
1079     DNS_SELFCURE_SUCC,
1080     STATIC_IP_SELFCURE_SUCC,
1081     REASSOC_SELFCURE_SUCC,
1082     RESET_SELFCURE_SUCC,
1083     RAND_MAC_REASSOC_SELFCURE_SUCC,
1084     MULTI_GATEWAY_SELFCURE_SUCC,
1085 };
1086 
1087 enum class Wifi3VapConflictType {
1088     STA_HML_SOFTAP_CONFLICT_CNT,
1089     STA_P2P_SOFTAP_CONFLICT_CNT,
1090     P2P_HML_SOFTAP_CONFLICT_CNT,
1091     HML_SOFTAP_STA_CONFLICT_CNT,
1092     P2P_SOFTAP_STA_CONFLICT_CNT,
1093     P2P_HML_STA_CONFLICT_CNT,
1094 };
1095 
1096 enum class NetworkLagType {
1097     DEFAULT = 0,
1098     WIFIPRO_QOE_SLOW,
1099     WIFIPRO_QOE_REPORT,
1100 };
1101 
1102 struct NetworkLagInfo {
1103     uint32_t uid { 0 };
1104     uint32_t rssi { 0 };
1105     uint32_t tcpRtt { 0 };
1106 
NetworkLagInfoNetworkLagInfo1107     NetworkLagInfo()
1108     {
1109         uid = 0;
1110         rssi = 0;
1111         tcpRtt = 0;
1112     }
1113 };
1114 
1115 struct WifiSignalPollInfo {
1116     int signal;
1117     int txrate;
1118     int rxrate;
1119     int noise;
1120     int frequency;
1121     int txPackets;
1122     int rxPackets;
1123     int snr;
1124     int chload;
1125     int ulDelay;
1126     unsigned int txBytes;
1127     unsigned int rxBytes;
1128     int txFailed;
1129     int chloadSelf;
1130     int c0Rssi;
1131     int c1Rssi;
1132     std::vector<uint8_t> ext;
1133     int extLen;
1134     int64_t timeStamp;
1135 
WifiSignalPollInfoWifiSignalPollInfo1136     WifiSignalPollInfo() : signal(0), txrate(0), rxrate(0), noise(0), frequency(0),
1137         txPackets(0), rxPackets(0), snr(0), chload(0), ulDelay(0), txBytes(0), rxBytes(0),
1138         txFailed(0), chloadSelf(0), c0Rssi(0), c1Rssi(0), ext(), extLen(0), timeStamp(0)
1139     {}
1140 
~WifiSignalPollInfoWifiSignalPollInfo1141     ~WifiSignalPollInfo()
1142     {}
1143 };
1144 
1145 enum class LimitSwitchScenes {
1146     NOT_LIMIT = 0,
1147     DUAL_BAND_ROAM = 1,
1148 };
1149 struct WpaEapData {
1150     int32_t msgId;
1151     int32_t code; /* eap code */
1152     int32_t type; /* eap type */
1153     int32_t bufferLen; /* length of data in the buffer */
1154     std::vector<uint8_t> eapBuffer; /* eap Data */
1155 };
1156 }  // namespace Wifi
1157 }  // namespace OHOS
1158 #endif
1159