• 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_SETTINGS_H
16 #define OHOS_WIFI_SETTINGS_H
17 
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include <atomic>
22 #include <memory>
23 #include <mutex>
24 #include <algorithm>
25 #include "wifi_common_def.h"
26 #include "wifi_common_msg.h"
27 #include "wifi_config_file_impl.h"
28 constexpr int RANDOM_STR_LEN = 6;
29 constexpr int MSEC = 1000;
30 constexpr int FOREGROUND_SCAN_CONTROL_TIMES = 4;
31 constexpr int FOREGROUND_SCAN_CONTROL_INTERVAL = 2 * 60;
32 constexpr int BACKGROUND_SCAN_CONTROL_TIMES = 1;
33 constexpr int BACKGROUND_SCAN_CONTROL_INTERVAL = 30 * 60;
34 constexpr int PNO_SCAN_CONTROL_TIMES = 1;
35 constexpr int PNO_SCAN_CONTROL_INTERVAL = 20;
36 constexpr int SYSTEM_TIMER_SCAN_CONTROL_TIMES = 4;
37 constexpr int SYSTEM_TIMER_SCAN_CONTROL_INTERVAL = 20;
38 constexpr int MODE_ADD = 0;
39 constexpr int MODE_DEL = 1;
40 constexpr int MODE_UPDATE = 2;
41 /* Obtain the scanning result that is valid within 180s. */
42 constexpr int WIFI_GET_SCAN_INFO_VALID_TIMESTAMP = 180;
43 /* Hotspot idle status auto close timeout 10min. */
44 constexpr int HOTSPOT_IDLE_TIMEOUT_INTERVAL_MS = 10 * 60 * 1000;
45 
46 
47 constexpr char DEVICE_CONFIG_FILE_PATH[] = CONFIG_ROOR_DIR"/device_config.conf";
48 constexpr char HOTSPOT_CONFIG_FILE_PATH[] = CONFIG_ROOR_DIR"/hotspot_config.conf";
49 constexpr char BLOCK_LIST_FILE_PATH[] = CONFIG_ROOR_DIR"/block_list.conf";
50 constexpr char WIFI_CONFIG_FILE_PATH[] = CONFIG_ROOR_DIR"/wifi_config.conf";
51 constexpr char WIFI_P2P_GROUP_INFO_FILE_PATH[] = CONFIG_ROOR_DIR"/p2p_groups.conf";
52 constexpr char WIFI_P2P_VENDOR_CONFIG_FILE_PATH[] = CONFIG_ROOR_DIR"/p2p_vendor_config.conf";
53 const std::string WIFI_TRUST_LIST_POLICY_FILE_PATH = CONFIG_ROOR_DIR"/trust_list_polices.conf";
54 const std::string WIFI_MOVING_FREEZE_POLICY_FILE_PATH = CONFIG_ROOR_DIR"/moving_freeze_policy.conf";
55 constexpr char WIFI_STA_RANDOM_MAC_FILE_PATH[] = CONFIG_ROOR_DIR"/sta_randomMac.conf";
56 
57 namespace OHOS {
58 namespace Wifi {
59 using ChannelsTable = std::map<BandType, std::vector<int32_t>>;
60 
61 enum class ThermalLevel {
62     COOL = 0,
63     NORMAL = 1,
64     WARM = 2,
65     HOT = 3,
66     OVERHEATED = 4,
67     WARNING = 5,
68     EMERGENCY = 6,
69 };
70 
71 enum class WifiMacAddrInfoType {
72     WIFI_SCANINFO_MACADDR_INFO = 0,
73     HOTSPOT_MACADDR_INFO = 1,
74     P2P_MACADDR_INFO = 2,
75     INVALID_MACADDR_INFO
76 };
77 
78 enum WifiMacAddrErrCode {
79     WIFI_MACADDR_OPER_SUCCESS = 0,
80     WIFI_MACADDR_HAS_EXISTED = 1,
81     WIFI_MACADDR_INVALID_PARAM = 2,
82     WIFI_MACADDR_BUTT
83 };
84 
85 class WifiSettings {
86 public:
87     ~WifiSettings();
88     static WifiSettings &GetInstance();
89 
90     /**
91      * @Description Init the WifiSettings object
92      *
93      * @return int - init result, when 0 means success, other means some fails happened
94      */
95     int Init();
96 
97     /**
98      * @Description Get the Wifi Sta Capabilities
99      *
100      * @return int - mWifiStaCapabilities
101      */
102     int GetWifiStaCapabilities() const;
103 
104     /**
105      * @Description Save the Wifi Sta Capabilities
106      *
107      * @param capabilities - input capability
108      * @return int - 0 success
109      */
110     int SetWifiStaCapabilities(int capabilities);
111 
112     /**
113      * @Description Get current STA service state
114      *
115      * @return int - the wifi state, DISABLING/DISABLED/ENABLING/ENABLED/UNKNOWN
116      */
117     int GetWifiState() const;
118 
119     /**
120      * @Description Save STA service state
121      *
122      * @param state - the wifi state
123      * @return int - 0 success
124      */
125     int SetWifiState(int state);
126 
127     /**
128      * @Description Get the ScanAlways switch state
129      *
130      * @return true - ScanAlways on, false - ScanAlways off
131      */
132     bool GetScanAlwaysState() const;
133 
134     /**
135      * @Description Set the ScanAlways switch state
136      *
137      * @param isActive - ScanAlways on/off
138      * @return int - 0 success
139      */
140     int SetScanAlwaysState(bool isActive);
141 
142     /**
143      * @Description Save scan results
144      *
145      * @param results - vector scan results
146      * @return int - 0 success
147      */
148     int SaveScanInfoList(const std::vector<WifiScanInfo> &results);
149     /**
150      * @Description Clear scan results
151      *
152      * @return int - 0 success
153      */
154     int ClearScanInfoList();
155     /**
156      * @Description UpdateLinkedChannelWidth
157      *
158      * @param bssid ap ssid
159      * @param channelWidth ap channelwidth
160      * @return void
161      */
162     void UpdateLinkedChannelWidth(std::string bssid, WifiChannelWidth channelWidth);
163 
164     /**
165      * @Description Get scan results
166      *
167      * @param results - output vector of scan results
168      * @return int - 0 success
169      */
170     int GetScanInfoList(std::vector<WifiScanInfo> &results);
171 
172     /**
173      * @Description Get scan result by bssid
174      *
175      * @param results - output scan result
176      * @return int - 0 success
177      */
178     int SetWifiLinkedStandardAndMaxSpeed(WifiLinkedInfo &linkInfo);
179     /**
180      * @Description save the p2p connected info
181      *
182      * @param linkedInfo - WifiP2pLinkedInfo object
183      * @return int - 0 success
184      */
185     int SaveP2pInfo(WifiP2pLinkedInfo &linkedInfo);
186 
187     /**
188      * @Description Get the p2p connected info
189      *
190      * @param linkedInfo - output the p2p connected info
191      * @return int - 0 success
192      */
193     int GetP2pInfo(WifiP2pLinkedInfo &linkedInfo);
194 
195     /**
196      * @Description Get the scan control policy info
197      *
198      * @param info - output ScanControlInfo struct
199      * @return int - 0 success
200      */
201     int GetScanControlInfo(ScanControlInfo &info);
202 
203     /**
204      * @Description Save the scan control policy info
205      *
206      * @param info - input ScanControlInfo struct
207      * @return int - 0 success
208      */
209     int SetScanControlInfo(const ScanControlInfo &info);
210 
211     /**
212      * @Description Add Device Configuration
213      *
214      * @param config - WifiDeviceConfig object
215      * @return int - network id
216      */
217     int AddDeviceConfig(const WifiDeviceConfig &config);
218 
219     /**
220      * @Description Remove a wifi device config who's networkId equals input networkId
221      *
222      * @param networkId - a networkId that is to be removed
223      * @return int - 0 success ,other is failed
224      */
225     int RemoveDevice(int networkId);
226 
227     /**
228      * @Description Remove all saved wifi device config
229      *
230      */
231     void ClearDeviceConfig(void);
232 
233     /**
234      * @Description Get all saved wifi device config
235      *
236      * @param results - output wifi device config results
237      * @return int - 0 success
238      */
239     int GetDeviceConfig(std::vector<WifiDeviceConfig> &results);
240 
241     /**
242      * @Description Get the specify networkId's wifi device config
243      *
244      * @param networkId - network id
245      * @param config - output WifiDeviceConfig struct
246      * @return int - 0 success; -1 not find the device config
247      */
248     int GetDeviceConfig(const int &networkId, WifiDeviceConfig &config);
249 
250     /**
251      * @brief Get the specify wifi device config which bssid is equal to input bssid
252      *
253      * @param index - bssid string or ssid string
254      * @param indexType - index type 0:ssid 1:bssid
255      * @param config - output WifiDeviceConfig struct
256      * @return int - 0 success; -1 not find the device config
257      */
258     int GetDeviceConfig(const std::string &index, const int &indexType, WifiDeviceConfig &config);
259 
260     /**
261      * @Description Get the specify wifi device config which ssid is equal to input ssid and keymgmt is equal to input
262      * keymgmt
263      *
264      * @param ssid - ssid string
265      * @param keymgmt - keymgmt string
266      * @param config - output WifiDeviceConfig struct
267      * @return int - 0 success; -1 not find the device config
268      */
269     int GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config);
270     /**
271      * @Description Get the wifi device configs which hiddenSSID is true
272      *
273      * @param results - output WifiDeviceConfig structs
274      * @return int - 0 success
275      */
276     int GetHiddenDeviceConfig(std::vector<WifiDeviceConfig> &results);
277 
278     /**
279      * @Description Set a wifi device's state who's networkId equals input networkId;
280      * when the param bSetOther is true and the state is ENABLED, that means we need
281      * to set other wifi device DISABLED
282      * @param networkId - the wifi device's id
283      * @param state - WifiDeviceConfigStatus DISABLED/ENABLED/UNKNOWN
284      * @param bSetOther - whether set other device config disabled
285      * @return int - when 0 means success, other means some fails happened,
286      *               Input state invalid or not find the wifi device config
287      */
288     int SetDeviceState(int networkId, int state, bool bSetOther = false);
289 
290     /**
291      * @Description Set a wifi device's attributes who's networkId equals input networkId after connect;
292      *
293      * @param networkId - the wifi device's id
294      * @return int - when 0 means success, other means some fails happened,
295      *               Input state invalid or not find the wifi device config
296      */
297     int SetDeviceAfterConnect(int networkId);
298 
299     /**
300      * @Description Get the candidate device configuration
301      *
302      * @param uid - call app uid
303      * @param networkId - a networkId that is to be get
304      * @param config - WifiDeviceConfig object
305      * @return int - network id
306      */
307     int GetCandidateConfig(const int uid, const int &networkId, WifiDeviceConfig &config);
308 
309     /**
310      * @Description  Get all the Candidate Device Configurations set key uuid
311      *
312      * @param uid - call app uid
313      * @param configs - WifiDeviceConfig objects
314      * @return int - 0 success
315      */
316     int GetAllCandidateConfig(const int uid, std::vector<WifiDeviceConfig> &configs);
317 
318     /**
319      * @Description Synchronizing saved the wifi device config into config file
320      *
321      * @return int - 0 success; -1 save file failed
322      */
323     int SyncDeviceConfig();
324 
325     /**
326      * @Description Increments the number of reboots since last use for each configuration
327      *
328      * @return int - 0 success; -1 save file failed
329      */
330     int IncreaseNumRebootsSinceLastUse();
331     /**
332      * @Description Remove excess networks in case the number of saved networks exceeds the mas limit
333      *
334      * @param configs - WifiDeviceConfig objects
335      * @return int - 0 if networks were removed, 1 otherwise.
336      */
337     int RemoveExcessDeviceConfigs(std::vector<WifiDeviceConfig> &configs) const;
338 
339     /**
340      * @Description Reload wifi device config from config file
341      *
342      * @return int - 0 success; -1 read config file failed
343      */
344     int ReloadDeviceConfig();
345 
346     /**
347      * @Description Synchronizing saved the wifi WifiP2pGroupInfo config into config file
348      *
349      * @return int - 0 success; -1 save file failed
350      */
351     int SyncWifiP2pGroupInfoConfig();
352 
353     /**
354      * @Description Reload wifi WifiP2pGroupInfo config from config file
355      *
356      * @return int - 0 success; -1 read config file failed
357      */
358     int ReloadWifiP2pGroupInfoConfig();
359 
360     /**
361      * @Description Save WifiP2pGroupInfo
362      *
363      * @param groups - input wifi p2p groups config results
364      * @return int - 0 success
365      */
366     int SetWifiP2pGroupInfo(const std::vector<WifiP2pGroupInfo> &groups);
367 
368     /**
369      * @brief increase sta connected failed count
370      *
371      * @param index - bssid string or ssid string
372      * @param indexType - index type 0:ssid 1:bssid
373      * @param count - the increase count to set
374      * @return int - 0 success; -1 not find the device config
375      */
376     int IncreaseDeviceConnFailedCount(const std::string &index, const int &indexType, int count);
377 
378     /**
379      * @brief set sta connected failed count
380      *
381      * @param index - bssid string or ssid string
382      * @param indexType - index type 0:ssid 1:bssid
383      * @param count - the count to set
384      * @return int - 0 success; -1 not find the device config
385      */
386     int SetDeviceConnFailedCount(const std::string &index, const int &indexType, int count);
387 
388     /**
389      * @Description Delete a WifiP2pGroupInfo node
390      *
391      * @return int
392      */
393     int RemoveWifiP2pGroupInfo();
394 
395     /**
396      * @Description Get all saved wifi p2p groups config
397      *
398      * @param results - output wifi p2p groups config results
399      * @return int - 0 success
400      */
401     int GetWifiP2pGroupInfo(std::vector<WifiP2pGroupInfo> &groups);
402 
403     /**
404      * @Description Get the dhcp info
405      *
406      * @param info - output IpInfo struct
407      * @return int - 0 success
408      */
409     int GetIpInfo(IpInfo &info);
410 
411     /**
412      * @Description Save dhcp info
413      *
414      * @param info - input IpInfo struct
415      * @return int - 0 success
416      */
417     int SaveIpInfo(const IpInfo &info);
418 
419     /**
420      * @Description Get the dhcp ipv6info
421      *
422      * @param info - output IpV6Info struct
423      * @return int - 0 success
424      */
425     int GetIpv6Info(IpV6Info &info);
426 
427     /**
428      * @Description Save dhcp inV6fo
429      *
430      * @param info - input IpV6Info struct
431      * @return int - 0 success
432      */
433     int SaveIpV6Info(const IpV6Info &info);
434 
435     /**
436      * @Description Get current link info
437      *
438      * @param info - output WifiLinkedInfo struct
439      * @return int - 0 success
440      */
441     int GetLinkedInfo(WifiLinkedInfo &info);
442 
443     /**
444      * @Description Save link info
445      *
446      * @param info - input WifiLinkedInfo struct
447      * @return int - 0 success
448      */
449     int SaveLinkedInfo(const WifiLinkedInfo &info);
450 
451     /**
452      * @Description Save mac address
453      *
454      * @param macAddress - mac address info
455      * @return int - 0 success
456      */
457     int SetMacAddress(const std::string &macAddress);
458 
459     /**
460      * @Description Get the mac address
461      *
462      * @param macAddress - output mac address info
463      * @return int - 0 success
464      */
465     int GetMacAddress(std::string &macAddress);
466 
467     /**
468      * @Description reload mac address
469      *
470      * @return int - 0 success
471      */
472     int ReloadStaRandomMac();
473 
474     /**
475      * @Description add random mac address
476      *
477      * @param randomMacInfo - randmon mac address info
478      * @return int - 0 success
479      */
480     bool AddRandomMac(WifiStoreRandomMac &randomMacInfo);
481 
482     /**
483      * @Description Get random mac address
484      *
485      * @param randomMacInfo - randmon mac address info
486      * @return int - 0 success
487      */
488     bool GetRandomMac(WifiStoreRandomMac &randomMacInfo);
489 
490     /**
491      * @Description remove random mac address
492      *
493      * @param bssid - bssid string
494      * @param randomMac - randmon mac address string
495      * @return int - 1 success
496      */
497     bool RemoveRandomMac(const std::string &bssid, const std::string &randomMac);
498 
499     /**
500      * @Description Save the country code
501      *
502      * @param countryCode - input country code
503      * @return int - 0 success
504      */
505     int SetCountryCode(const std::string &countryCode);
506 
507     /**
508      * @Description Get the country code
509      *
510      * @param countryCode - output country code
511      * @return int - 0 success
512      */
513     int GetCountryCode(std::string &countryCode);
514 
515     /**
516      * @Description Get current hotspot state
517      *
518      * @return int - the hotspot state, IDLE/STARTING/STARTED/CLOSING/CLOSED
519      */
520     int GetHotspotState(int id = 0);
521 
522     /**
523      * @Description Save current hotspot state
524      *
525      * @param state - hotspot state
526      * @return int - 0 success
527      */
528     int SetHotspotState(int state, int id = 0);
529 
530     /**
531      * @Description Set the hotspot config
532      *
533      * @param config - input HotspotConfig struct
534      * @return int - 0 success
535      */
536     int SetHotspotConfig(const HotspotConfig &config, int id = 0);
537 
538     /**
539      * @Description Get the hotspot config
540      *
541      * @param config - output HotspotConfig struct
542      * @return int - 0 success
543      */
544     int GetHotspotConfig(HotspotConfig &config, int id = 0);
545 
546     /**
547      * @Description Set the idel timeout of Hotspot
548      *
549      * @return int - 0 success
550      */
551     int SetHotspotIdleTimeout(int time);
552 
553     /**
554      * @Description Get the idel timeout of Hotspot
555      *
556      * @param time -input time,
557      * @return int - the hotspot idle timeout
558      */
559     int GetHotspotIdleTimeout() const;
560 
561     /**
562      * @Description Synchronizing saved the Hotspot config into config file
563      *
564      * @return int - 0 success; -1 save file failed
565      */
566     int SyncHotspotConfig();
567 
568     /**
569      * @Description Set the p2p vendor config
570      *
571      * @param config - input P2pVendorConfig struct
572      * @return int - 0 success
573      */
574     int SetP2pVendorConfig(const P2pVendorConfig &config);
575 
576     /**
577      * @Description Get the p2p vendor config
578      *
579      * @param config - output P2pVendorConfig struct
580      * @return int - 0 success
581      */
582     int GetP2pVendorConfig(P2pVendorConfig &config);
583 
584     /**
585      * @Description Synchronizing saved the P2p Vendor config into config file
586      *
587      * @return int - 0 success; -1 save file failed
588      */
589     int SyncP2pVendorConfig();
590 
591     /**
592      * @Description Get current hotspot accept linked stations
593      *
594      * @param results - output StationInfo results
595      * @return int - 0 success
596      */
597     int GetStationList(std::vector<StationInfo> &results, int id = 0);
598 
599     /**
600      * @Description Management (add/update/delete) connected station list
601      *
602      * @param info - input StationInfo struct
603      * @param mode - mode of MODE_ADD MODE_UPDATE MODE_DEL
604      * @return int - 0 success; -1 mode not correct
605      */
606     int ManageStation(const StationInfo &info, int mode, int id = 0); /* add / update / remove */
607 
608     /**
609      * @Description Clear connected station list
610      *
611      * @return int - 0 success
612      */
613     int ClearStationList(int id = 0);
614 
615     /**
616      * @Description Get the block list
617      *
618      * @param results - output StationInfo results
619      * @return int - 0 success
620      */
621     int GetBlockList(std::vector<StationInfo> &results, int id = 0);
622 
623     /**
624      * @Description Manager (add/update/delete) station connect Blocklist
625      *
626      * @param info - input StationInfo struct
627      * @param mode - mode of MODE_ADD MODE_DEL MODE_UPDATE
628      * @return int - 0 success; -1 mode not correct
629      */
630     int ManageBlockList(const StationInfo &info, int mode, int id = 0); /* add / remove */
631 
632     /**
633      * @Description Judge whether the station is in current linked station list
634      *
635      * @param info - input StationInfo struct
636      * @return int - 0 find the station, exist; -1 not find, not exist
637      */
638     int FindConnStation(const StationInfo &info, int id = 0);
639 
640     /**
641      * @Description Synchronizing saved the block list config into config file
642      *
643      * @return int - 0 success; -1 save file failed
644      */
645     int SyncBlockList();
646 
647     /**
648      * @Description Get the Valid Bands object
649      *
650      * @param bands - output vector for BandType
651      * @return int - 0 success
652      */
653     int GetValidBands(std::vector<BandType> &bands);
654 
655     /**
656      * @Description Set the Valid Channels object
657      *
658      * @param channelsInfo - input ChannelsTable struct
659      * @return int - 0 success
660      */
661     int SetValidChannels(const ChannelsTable &channelsInfo);
662 
663     /**
664      * @Description Get the Valid Channels object
665      *
666      * @param channelsInfo - output ChannelsTable struct
667      * @return int - 0 success
668      */
669     int GetValidChannels(ChannelsTable &channelsInfo);
670 
671     /**
672      * @Description Clear the number of valid channels
673      *
674      * @return int - 0 success
675      */
676     int ClearValidChannels();
677 
678     /**
679      * @Description Get supported power model list
680      *
681      * @param model - the model to be set
682      * @return ErrCode - operation result
683      */
684     int SetPowerModel(const PowerModel& model, int id = 0);
685 
686     /**
687      * @Description Get power model
688      *
689      * @param model - current power model
690      * @return ErrCode - operation result
691      */
692     int GetPowerModel(PowerModel& model, int id = 0);
693 
694     /**
695      * @Description set the p2p state
696      *
697      * @param state - the p2p state
698      * @return int - 0 success
699      */
700     int SetP2pState(int state);
701 
702     /**
703      * @Description Get current p2p state
704      *
705      * @return int - the p2p state, NONE/IDLE/STARTING/STARTED/CLOSING/CLOSED
706      */
707     int GetP2pState();
708 
709     /**
710      * @Description set the p2p discover state
711      *
712      * @param state - the p2p discover state
713      * @return int - 0 success
714      */
715     int SetP2pDiscoverState(int state);
716 
717     /**
718      * @Description Get current p2p discover state
719      *
720      * @return int -the p2p discover state, P2P_DISCOVER_NONE/P2P_DISCOVER_STARTING/P2P_DISCOVER_CLOSED
721      */
722     int GetP2pDiscoverState();
723 
724     /**
725      * @Description set the p2p connected state
726      *
727      * @param state - the p2p connected state
728      * @return int - 0 success
729      */
730     int SetP2pConnectedState(int state);
731 
732     /**
733      * @Description Get current p2p connected state
734      *
735      * @return int - the connected state, P2P_CONNECTED_NONE/P2P_CONNECTED_STARTING/P2P_CONNECTED_CLOSED
736      */
737     int GetP2pConnectedState();
738 
739     /**
740      * @Description Get signal level about given rssi and band
741      *
742      * @param rssi - rssi info
743      * @param band - band info
744      * @return int - level
745      */
746     int GetSignalLevel(const int &rssi, const int &band);
747 
748     /**
749      * @Description Get the Ap Max Conn Num
750      *
751      * @return int - number
752      */
753     int GetApMaxConnNum();
754 
755     /**
756      * @Description Enable Network
757      *
758      * @param networkId - enable network id
759      * @param disableOthers - when set, save this network id, and can use next time
760      * @return true
761      * @return false
762      */
763     bool EnableNetwork(int networkId, bool disableOthers);
764 
765     /**
766      * @Description Set the User Last Selected Network Id
767      *
768      * @param networkId - network id
769      */
770     void SetUserLastSelectedNetworkId(int networkId);
771 
772     /**
773      * @Description Get the User Last Selected Network Id
774      *
775      * @return int - network id
776      */
777     int GetUserLastSelectedNetworkId();
778 
779     /**
780      * @Description Get the User Last Selected Network time
781      *
782      * @return time_t - timestamp
783      */
784     time_t GetUserLastSelectedNetworkTimeVal();
785 
786     /**
787      * @Description Synchronizing saved the WifiConfig into config file
788      *
789      * @return int - 0 success; -1 save file failed
790      */
791     int SyncWifiConfig();
792 
793     /**
794      * @Description Get operator wifi state
795      *
796      * @return type - enum OperatorWifiType
797      */
798     int GetOperatorWifiType();
799 
800     /**
801      * @Description Set operator wifi state
802      *
803      * @param type - enum OperatorWifiType
804      * @return int - 0 success
805      */
806     int SetOperatorWifiType(int type);
807 
808     /**
809      * @Description Get the config whether can open sta when airplane mode opened
810      *
811      * @return true - can open
812      * @return false - can't open
813      */
814     bool GetCanOpenStaWhenAirplaneMode();
815 
816     /**
817      * @Description Get the STA service last running state
818      *
819      * @return true - running
820      * @return false - not running
821      */
822     bool GetStaLastRunState();
823 
824     /**
825      * @Description Set the STA service running state
826      *
827      * @param bRun - running or not
828      * @return int - 0 success
829      */
830     int SetStaLastRunState(bool bRun);
831 
832     /**
833      * @Description Get the Dhcp Ip Type
834      *
835      * @return int - dhcp ip type, ipv4/ipv6/double
836      */
837     int GetDhcpIpType();
838 
839     /**
840      * @Description Set the Dhcp Ip Type
841      *
842      * @param dhcpIpType - ipv4/ipv6/double
843      * @return int - 0 success
844      */
845     int SetDhcpIpType(int dhcpIpType);
846 
847     /**
848      * @Description Get the Default Wifi Interface
849      *
850      * @return std::string - interface name
851      */
852     std::string GetDefaultWifiInterface();
853 
854     /**
855      * @Description Set the Screen State
856      *
857      * @param state - 1 on; 2 off
858      */
859     void SetScreenState(const int &state);
860 
861     /**
862      * @Description Get the Screen State
863      *
864      * @return int - 1 on; 2 off
865      */
866     int GetScreenState() const;
867 
868     /**
869      * @Description Set the Airplane Mode State
870      *
871      * @param state - 1 open; 2 close
872      */
873     void SetAirplaneModeState(const int &state);
874 
875     /**
876      * @Description Get the Airplane Mode State
877      *
878      * @return int - 1 open; 2 close
879      */
880     int GetAirplaneModeState() const;
881 
882     /**
883      * @Description Set the App Running State
884      *
885      * @param appRunMode - app run mode
886      */
887     void SetAppRunningState(ScanMode appRunMode);
888 
889     /**
890      * @Description Get the App Running State
891      *
892      * @return ScanMode
893      */
894     ScanMode GetAppRunningState() const;
895 
896     /**
897      * @Description Set the Power Saving Mode State
898      *
899      * @param state - 1 open; 2 close
900      */
901     void SetPowerSavingModeState(const int &state);
902 
903     /**
904      * @Description Get the Power Saving Mode State
905      *
906      * @return int - 1 open; 2 close
907      */
908     int GetPowerSavingModeState() const;
909 
910     /**
911      * @Description Set app package name.
912      *
913      * @param appPackageName - app package name
914      */
915     void SetAppPackageName(const std::string &appPackageName);
916 
917     /**
918      * @Description Get app package name.
919      *
920      * @return const std::string - app package name.
921      */
922     const std::string GetAppPackageName() const;
923 
924     /**
925      * @Description Set freeze mode state.
926      *
927      * @param state - 1 freeze mode; 2 moving mode
928      */
929     void SetFreezeModeState(int state);
930 
931     /**
932      * @Description Get freeze mode state.
933      *
934      * @return freeze mode.
935      */
936     int GetFreezeModeState() const;
937 
938     /**
939      * @Description Set no charger plugged in mode.
940      *
941      * @param state - 1 no charger plugged in mode; 2 charger plugged in mode
942      */
943     void SetNoChargerPlugModeState(int state);
944 
945     /**
946      * @Description Get no charger plugged in mode.
947      *
948      * @return no charger plugged in mode.
949      */
950     int GetNoChargerPlugModeState() const;
951 
952     /**
953      * @Description Set enable/disable Whether to allow network switchover
954      *
955      * @param bSwitch - enable/disable
956      * @return int - 0 success
957      */
958     int SetWhetherToAllowNetworkSwitchover(bool bSwitch);
959 
960     /**
961      * @Description Check whether enable network switchover
962      *
963      * @return true - enable
964      * @return false - disable
965      */
966     bool GetWhetherToAllowNetworkSwitchover();
967 
968     /**
969      * @Description Set the policy score slope
970      *
971      * @param score - score
972      * @return int - 0 success
973      */
974     int SetScoretacticsScoreSlope(const int &score);
975 
976     /**
977      * @Description Get the policy score slope
978      *
979      * @return int - score
980      */
981     int GetScoretacticsScoreSlope();
982 
983     /**
984      * @Description Initial score of the set strategy
985      *
986      * @param score - score
987      * @return int - 0 success
988      */
989     int SetScoretacticsInitScore(const int &score);
990 
991     /**
992      * @Description Obtain the initial score of the tactic
993      *
994      * @return int - score
995      */
996     int GetScoretacticsInitScore();
997 
998     /**
999      * @Description Set the scoring policy to the same BSSID score
1000      *
1001      * @param score - score
1002      * @return int - 0 success
1003      */
1004     int SetScoretacticsSameBssidScore(const int &score);
1005 
1006     /**
1007      * @Description Get the scoring policy to the same BSSID score
1008      *
1009      * @return int - score
1010      */
1011     int GetScoretacticsSameBssidScore();
1012 
1013     /**
1014      * @Description Set the score policy for the same network
1015      *
1016      * @param score - score
1017      * @return int - 0 success
1018      */
1019     int SetScoretacticsSameNetworkScore(const int &score);
1020 
1021     /**
1022      * @Description Get the score policy for the same network
1023      *
1024      * @return int - score
1025      */
1026     int GetScoretacticsSameNetworkScore();
1027 
1028     /**
1029      * @Description Set the 5 GHz score of the policy frequency
1030      *
1031      * @param score - score
1032      * @return int - 0 success
1033      */
1034     int SetScoretacticsFrequency5GHzScore(const int &score);
1035 
1036     /**
1037      * @Description Get the 5 GHz score of the policy frequency
1038      *
1039      * @return int - score
1040      */
1041     int GetScoretacticsFrequency5GHzScore();
1042 
1043     /**
1044      * @Description Set the score policy. last select score
1045      *
1046      * @param score - score
1047      * @return int - 0 success
1048      */
1049     int SetScoretacticsLastSelectionScore(const int &score);
1050 
1051     /**
1052      * @Description Get the score policy, last select score
1053      *
1054      * @return int - score
1055      */
1056     int GetScoretacticsLastSelectionScore();
1057 
1058     /**
1059      * @Description Setting the Score Policy Security Score
1060      *
1061      * @param score - score
1062      * @return int - 0 success
1063      */
1064     int SetScoretacticsSecurityScore(const int &score);
1065 
1066     /**
1067      * @Description Get the Score Policy Security Score
1068      *
1069      * @return int - priority
1070      */
1071     int GetScoretacticsSecurityScore();
1072 
1073     /**
1074      * @Description Setting the Score Policy Candidate Score
1075      *
1076      * @param score - score
1077      * @return int - 0 success
1078      */
1079     int SetScoretacticsNormalScore(const int &score);
1080 
1081     /**
1082      * @Description Get the Score Policy Candidate Score
1083      *
1084      * @return int - score
1085      */
1086     int GetScoretacticsNormalScore();
1087 
1088     /**
1089      * @Description Set the saved device appraisal priority
1090      *
1091      * @param priority - priority
1092      * @return int - 0 success
1093      */
1094     int SetSavedDeviceAppraisalPriority(const int &priority);
1095 
1096     /**
1097      * @Description Get the saved device appraisal priority
1098      *
1099      * @return int - priority
1100      */
1101     int GetSavedDeviceAppraisalPriority();
1102 
1103     /**
1104      * @Description Judge the Module need preloaded or not
1105      *
1106      * @param name - module name
1107      * @return true - need preload
1108      * @return false - no need preload
1109      */
1110     bool IsModulePreLoad(const std::string &name);
1111 
1112     /**
1113      * @Description Save wps connection device config
1114      *
1115      * @param config - input WifiDeviceConfig struct
1116      * @return int - 0 success; -1 load the device config file failed
1117      */
1118     int AddWpsDeviceConfig(const WifiDeviceConfig &config);
1119     /**
1120      * @Description Get the Support HwPno Flag object
1121      *
1122      * @return true - support HwPno scan
1123      * @return false - not support HwPno scan
1124      */
1125     bool GetSupportHwPnoFlag();
1126     /**
1127      * @Description Get the Min 2.4G strength object
1128      *
1129      * @return int Min 2.4G strength
1130      */
1131     int GetMinRssi2Dot4Ghz();
1132     /**
1133      * @Description Get the Min 5G strength object
1134      *
1135      * @return int Min 5G strength
1136      */
1137     int GetMinRssi5Ghz();
1138 
1139     /**
1140      * @Description Get the Alternate dns.
1141      *
1142      * @return string - dns
1143      */
1144     std::string GetStrDnsBak();
1145     /**
1146      * @Description Obtaining Whether to Load the Configuration of the Standby STA.
1147      *
1148      * @return bool - Indicates whether to load the configuration of the standby STA.
1149      */
1150     bool IsLoadStabak();
1151 
1152     /**
1153      * @Description Set the real mac address
1154      *
1155      * @param macAddress - the real mac address
1156      * @return int - 0 success
1157      */
1158     int SetRealMacAddress(const std::string &macAddress);
1159 
1160     /**
1161      * @Description Get the real mac address
1162      *
1163      * @param macAddress - the real mac address
1164      * @return int - 0 success
1165      */
1166     int GetRealMacAddress(std::string &macAddress);
1167 
1168     /**
1169      * @Description set the device name
1170      *
1171      * @param deviceName - device name
1172      * @return int - result
1173      */
1174     int SetP2pDeviceName(const std::string &deviceName);
1175 
1176     /**
1177      * @Description get trustlist policies.
1178      *
1179      * @return const std::vector<TrustListPolicy> - trustlist policies.
1180      */
1181     const std::vector<TrustListPolicy> ReloadTrustListPolicies();
1182 
1183     /**
1184      * @Description get moving freeze state trustlist.
1185      *
1186      * @return const MovingFreezePolicy - moving freeze policy.
1187      */
1188     const MovingFreezePolicy ReloadMovingFreezePolicy();
1189 
1190     /**
1191      * @Description get bssid of connection timeout for last time.
1192      *
1193      * @return bssid.
1194      */
1195     std::string GetConnectTimeoutBssid();
1196 
1197     /**
1198      * @Description set bssid of connection timeout for last time.
1199      *
1200      * @return int - result
1201      */
1202     int SetConnectTimeoutBssid(std::string &bssid);
1203 
1204     /**
1205      * @Description set default frequencies for specify country band.
1206      *
1207      */
1208     void SetDefaultFrequenciesByCountryBand(const BandType band, std::vector<int> &frequencies);
1209 
1210     /**
1211      * @Description set type of GO group
1212      *
1213      * @param isExplicit true: created by user; false: created by auto negotiation
1214      */
1215     void SetExplicitGroup(bool isExplicit);
1216 
1217     /**
1218      * @Description get type of Go group
1219      *
1220      * @return true: created by user; false: created by auto negotiation
1221      */
1222     bool IsExplicitGroup(void);
1223 
1224     /**
1225      * @Description Set the thermal level
1226      *
1227      * @param level 0 COOL, 1 NORMAL, 2 WARM, 3 HOT, 4 OVERHEATED, 5 WARNING, 6 EMERGENCY
1228      */
1229     void SetThermalLevel(const int &level);
1230 
1231     /**
1232      * @Description Get the thermal level
1233      *
1234      * @return int 0 COOL, 1 NORMAL, 2 WARM, 3 HOT, 4 OVERHEATED, 5 WARNING, 6 EMERGENCY
1235      */
1236     int GetThermalLevel() const;
1237 
1238     /**
1239      * @Description SetThreadStatusFlag
1240      *
1241      * @param state true thread start, false thread end
1242      */
1243     void SetThreadStatusFlag(bool state);
1244 
1245     /**
1246      * @Description GetThreadStatusFlag
1247      *
1248      * @return ThreadStatusFlag
1249      */
1250     bool GetThreadStatusFlag(void) const;
1251 
1252     /**
1253      * @Description GetThreadStartTime
1254      *
1255      * @return StartTime
1256      */
1257     uint64_t GetThreadStartTime(void) const;
1258 
1259     /**
1260      * @Description Save the last disconnected reason
1261      *
1262      * @param discReason - discReason
1263      */
1264     void SaveDisconnectedReason(DisconnectedReason discReason);
1265 
1266     /**
1267      * @Description Get the last disconnected reason
1268      *
1269      * @param discReason - discReason
1270      * @return int - 0 success
1271      */
1272     int GetDisconnectedReason(DisconnectedReason &discReason) const;
1273 
1274     /**
1275      * @Description Set the Scan Only Switch State
1276      *
1277      * @param state - 1 on; 2 off
1278      */
1279     void SetScanOnlySwitchState(const int &state);
1280 
1281     /**
1282      * @Description Get the Scan Only Switch State
1283      *
1284      * @return int - 1 on; 2 off
1285      */
1286     int GetScanOnlySwitchState();
1287     /**
1288      * @Description Get the Scan Only Whether Available
1289      *
1290      * @return int - 1 on; 2 off
1291      */
1292     bool CheckScanOnlyAvailable();
1293 
1294     /**
1295      * @Description Get sta ap exclusion type
1296      *
1297      * @return type - enum StaApExclusionType
1298      */
1299     int GetStaApExclusionType();
1300 
1301     /**
1302      * @Description Set sta ap exclusion type
1303      *
1304      * @param type - enum StaApExclusionType
1305      * @return int - 0 success
1306      */
1307     int SetStaApExclusionType(int type);
1308 #ifdef SUPPORT_RANDOM_MAC_ADDR
1309     /**
1310      * @Description generate a MAC address
1311      *
1312      * @param peerBssid - real MAC address[in]
1313      * @param randomMacAddr - random MAC address[out]
1314      */
1315     void GenerateRandomMacAddress(std::string peerBssid, std::string &randomMacAddr);
1316     /**
1317      * @Description save a MAC address pair
1318      *
1319      * @param type - MAC address type[in]
1320      * @param realMacAddr - real MAC address[in]
1321      * @return bool - false fail to save the MAC address, true success to save the MAC address
1322      */
1323     bool StoreWifiMacAddrPairInfo(WifiMacAddrInfoType type, const std::string &realMacAddr);
1324     /**
1325      * @Description add a MAC address pair
1326      *
1327      * @param type - MAC address type[in]
1328      * @param macAddrInfo - MAC address info[in]
1329      * @param randomMacAddr - random MAC address[out]
1330      * @return WifiMacAddrErrCode - 0 success
1331      */
1332     WifiMacAddrErrCode AddMacAddrPairs(WifiMacAddrInfoType type, const WifiMacAddrInfo &macAddrInfo, std::string randomMacAddr);
1333     /**
1334      * @Description remove a MAC address pair
1335      *
1336      * @param type - MAC address type[in]
1337      * @param macAddrInfo - MAC address info[in]
1338      * @return int - 0 success
1339      */
1340     int RemoveMacAddrPairs(WifiMacAddrInfoType type, const WifiMacAddrInfo &macAddrInfo);
1341     /**
1342      * @Description query a MAC address pair
1343      *
1344      * @param type - MAC address type[in]
1345      * @param macAddrInfo - MAC address info[in]
1346      * @return std::string - an empty string indicates failure
1347      */
1348     std::string GetMacAddrPairs(WifiMacAddrInfoType type, const WifiMacAddrInfo &macAddrInfo);
1349     /**
1350      * @Description print MAC address pair
1351      *
1352      * @param type - MAC address type[in]
1353      */
1354     void PrintMacAddrPairs(WifiMacAddrInfoType type);
1355     /**
1356          * @Description Clear MAC address pair
1357      *
1358      * @param type - MAC address type[in]
1359      * @return std::string - an empty string indicates failure
1360      */
1361     void ClearMacAddrPairs(WifiMacAddrInfoType type);
1362 #endif
1363 private:
1364     WifiSettings();
1365     void InitWifiConfig();
1366     void InitDefaultHotspotConfig();
1367     void InitHotspotConfig();
1368     void InitDefaultP2pVendorConfig();
1369     void InitP2pVendorConfig();
1370     void InitSettingsNum();
1371     void InitScanControlForbidList();
1372     void InitScanControlIntervalList();
1373     void InitScanControlInfo();
1374     void GetLinkedChannelWidth();
1375 
1376 private:
1377     int mWifiStaCapabilities;            /* Sta capability */
1378     std::atomic<int> mWifiState;         /* Sta service state */
1379     std::atomic<bool> mScanAlwaysActive; /* if scan always */
1380     std::vector<WifiScanInfo> mWifiScanInfoList;
1381     std::vector<WifiP2pGroupInfo> mGroupInfoList;
1382     std::vector<WifiStoreRandomMac> mWifiStoreRandomMac;
1383     ScanControlInfo mScanControlInfo;
1384     WifiP2pLinkedInfo mWifiP2pInfo;
1385     std::map<int, WifiDeviceConfig> mWifiDeviceConfig;
1386     IpInfo mWifiIpInfo;
1387     IpV6Info mWifiIpV6Info;
1388     WifiLinkedInfo mWifiLinkedInfo;
1389     std::string mMacAddress;
1390     std::string mCountryCode;
1391     std::map <int, std::atomic<int>> mHotspotState;
1392     std::map <int, HotspotConfig> mHotspotConfig;
1393     P2pVendorConfig mP2pVendorConfig;
1394     std::map<std::string, StationInfo> mConnectStationInfo;
1395     std::map<std::string, StationInfo> mBlockListInfo;
1396     ChannelsTable mValidChannels;
1397     std::atomic<int> mP2pState;
1398     std::atomic<int> mP2pDiscoverState;
1399     std::atomic<int> mP2pConnectState;
1400     int mApMaxConnNum;           /* ap support max sta numbers */
1401     int mMaxNumConfigs;          /* max saved configs numbers */
1402     int mLastSelectedNetworkId;  /* last selected networkid */
1403     time_t mLastSelectedTimeVal; /* last selected time */
1404     int mScreenState;            /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
1405     int mThermalLevel;           /* 1 COOL, 2 NORMAL, 3 WARM, 4 HOT, 5 OVERHEATED, 6 WARNING, 7 EMERGENCY */
1406     std::atomic<int> mAirplaneModeState;      /* 1 on 2 off */
1407     ScanMode mAppRunningModeState; /* 0 app for 1 app back 2 sys for 3 sys back */
1408     int mPowerSavingModeState;   /* 1 on 2 off */
1409     std::string mAppPackageName;
1410     int mFreezeModeState;        /* 1 on 2 off */
1411     int mNoChargerPlugModeState;  /* 1 on 2 off */
1412     WifiConfig mWifiConfig;
1413     std::pair<std::string, int> mBssidToTimeoutTime;
1414     std::map<int, PowerModel> powerModel;
1415     int mHotspotIdleTimeout;
1416     DisconnectedReason mLastDiscReason;
1417 
1418     std::map<WifiMacAddrInfo, std::string> mWifiScanMacAddrPair;
1419     std::map<WifiMacAddrInfo, std::string> mDeviceConfigMacAddrPair;
1420     std::map<WifiMacAddrInfo, std::string> mHotspotMacAddrPair;
1421     std::map<WifiMacAddrInfo, std::string> mP2pMacAddrPair;
1422 
1423     std::mutex mMacAddrPairMutex;
1424     std::mutex mStaMutex;
1425     std::mutex mApMutex;
1426     std::mutex mConfigMutex;
1427     std::mutex mInfoMutex;
1428     std::mutex mP2pMutex;
1429     std::mutex mWifiConfigMutex;
1430 
1431     std::atomic_flag deviceConfigLoadFlag = ATOMIC_FLAG_INIT;
1432 
1433     WifiConfigFileImpl<WifiDeviceConfig> mSavedDeviceConfig; /* Persistence device config */
1434     WifiConfigFileImpl<HotspotConfig> mSavedHotspotConfig;
1435     WifiConfigFileImpl<StationInfo> mSavedBlockInfo;
1436     WifiConfigFileImpl<WifiConfig> mSavedWifiConfig;
1437     WifiConfigFileImpl<WifiP2pGroupInfo> mSavedWifiP2pGroupInfo;
1438     WifiConfigFileImpl<P2pVendorConfig> mSavedWifiP2pVendorConfig;
1439     WifiConfigFileImpl<TrustListPolicy> mTrustListPolicies;
1440     WifiConfigFileImpl<MovingFreezePolicy> mMovingFreezePolicy;
1441     MovingFreezePolicy mFPolicy;
1442     WifiConfigFileImpl<WifiStoreRandomMac> mSavedWifiStoreRandomMac;
1443     bool explicitGroup;
1444     std::atomic_bool mThreadStatusFlag_ { false };
1445     std::atomic_uint64_t mThreadStartTime { 0 };
1446 };
1447 }  // namespace Wifi
1448 }  // namespace OHOS
1449 #endif
1450