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