• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_AP_CONFIG_UTIL_H
17 #define OHOS_AP_CONFIG_UTIL_H
18 
19 #include <vector>
20 #include <map>
21 #include "ap_define.h"
22 #include "ap_macro.h"
23 #include "wifi_ap_msg.h"
24 #include "xml_parser.h"
25 
26 namespace OHOS {
27 namespace Wifi {
28 class ApConfigUse {
29     FRIEND_GTEST(ApIdleState);
30 public:
31     /**
32      * @Description  construction method
33      *
34      * @param None
35      * @return None
36      */
37     explicit ApConfigUse(int id = 0);
38 
39     /**
40      * @Description  destructor method
41      *
42      * @param None
43      * @return None
44      */
45     virtual ~ApConfigUse() = default;
46 
47     /**
48      * @Description update ap channel config
49      *
50      * @param apConfig - ap configuration input
51      */
52     void UpdateApChannelConfig(HotspotConfig &apConfig) const;
53 private:
54     static constexpr int DEFAULT_STA_INSTANCE_ID = 0;
55 
56     class SoftapChannelPolicyParser : public XmlParser {
57     public:
58         enum class SoftapChannelsPolicyType {
59             UNVALID,
60             COUNTRY_CODE,
61             INDOOR_CHANNELS
62         };
63         static constexpr const char* SOFTAP_CHANNELS_POLICY_FILE_PATH = "/system/etc/wifi/softap_channels_policy.xml";
64         static constexpr const char* XML_TAG_SOFTAP_CHANNELS_POLICY = "SoftapChannelsPolicy";
65         static constexpr const char* XML_TAG_CHANNELS_POLICY = "CountryPolicy";
66         static constexpr const char* XML_TAG_POLICY_ITEM = "PolicyItem";
67         static constexpr const char* XML_TAG_COUNTRY_CODE = "CountryCode";
68         static constexpr const char* XML_TAG_INDOOR_CHANNELS = "IndoorChannels";
69         static constexpr const char* XML_TAG_SOFTAP_SUPPORT_CHANNELS = "SoftapSupportChannels";
70         static constexpr const char* XML_TAG_CHANNEL_2G_LIST = "Channel2gList";
71         static constexpr const char* XML_TAG_CHANNEL_5G_LIST = "Channel5gList";
72         static constexpr const char* XML_TAG_CHANNEL_6G_LIST = "Channel6gList";
73         static constexpr const char* XML_TAG_CHANNEL_60G_LIST = "Channel60gList";
74 
75         SoftapChannelPolicyParser();
76         ~SoftapChannelPolicyParser();
77         std::map<std::string, std::set<int>> GetAllIndoorChannels() const;
78         std::map<BandType, std::vector<int>> GetAllPreferredChannels() const;
79     private:
80         std::map<std::string, std::set<int>> m_indoorChannels;
81         std::map<BandType, std::vector<int>> m_preferredChannels;
82         std::unordered_map<std::string, SoftapChannelPolicyParser::SoftapChannelsPolicyType> g_softapChannelsPolicyMap;
83         std::unordered_map<std::string, BandType> g_bandTypeMap;
84 
85         bool InitParser();
86         bool ParseInternal(xmlNodePtr node) override;
87         void ParseCountryPolicyList(xmlNodePtr innode);
88         void ParsePreferredChannelsList(xmlNodePtr innode);
89         std::set<int> ParseChannels(xmlNodePtr innode);
90         xmlNodePtr GotoCountryPolicy(xmlNodePtr innode) const;
91         ApConfigUse::SoftapChannelPolicyParser::SoftapChannelsPolicyType GetPolicyItem(xmlNodePtr node);
92         xmlNodePtr GotoSoftapSupportChannels(xmlNodePtr innode) const;
93         BandType GetSupportChannelsItem(xmlNodePtr node);
94         std::vector<int> ParseSupportChannels(xmlNodePtr innode, const char* const &bandXml);
95     };
96     int m_id;
97     std::unique_ptr<SoftapChannelPolicyParser> m_softapChannelPolicyPtr;
98     std::map<std::string, std::set<int>> m_softapIndoorChannels;
99     std::map<BandType, std::vector<int>> m_softapPreferredChannels;
100     DISALLOW_COPY_AND_ASSIGN(ApConfigUse)
101 
102     int GetBestChannelFor2G() const;
103     int GetBestChannelFor5G(HotspotConfig &apConfig) const;
104     std::vector<int> GetChannelFromDrvOrXmlByBand(const BandType &bandType) const;
105     void FilterIndoorChannel(std::vector<int> &channels) const;
106     void Filter165Channel(std::vector<int> &channels) const;
107     void JudgeDbacWithP2p(HotspotConfig &apConfig) const;
108     std::set<int> GetIndoorChanByCountryCode(const std::string &countryCode) const;
109     std::vector<int> GetPreferredChannelByBand(const BandType &bandType) const;
110 };
111 }  // namespace Wifi
112 }  // namespace OHOS
113 #endif