1 /*
2  * Copyright (C) 2023-2023 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 SOFTAP_PARSER
16 #define SOFTAP_PARSER
17 #include "xml_parser.h"
18 #include <unordered_map>
19 #include "wifi_ap_msg.h"
20 
21 constexpr auto XML_TAG_HEADER_SOFTAP = "SoftAp";
22 constexpr auto XML_TAG_SOFTAP_SSID = "SSID";
23 constexpr auto XML_SECURITY_TYPE = "SecurityType";
24 constexpr auto XML_PASSPHRASE = "Passphrase";
25 constexpr auto XML_BAND_CHANNEL_MAP = "BandChannelMap";
26 constexpr auto XML_BAND_CHANNEL = "BandChannel";
27 constexpr auto XML_BAND = "Band";
28 constexpr auto XML_CHANNEL = "Channel";
29 
30 enum class HotspotConfigType {
31     SOFTAP_SSID = 0,
32     SECURITYTYPE,
33     PASSPHRASE,
34     UNUSED,
35 };
36 
37 const std::unordered_map<std::string, HotspotConfigType> g_hotspotConfigMap = {
38     {XML_TAG_SOFTAP_SSID, HotspotConfigType::SOFTAP_SSID},
39     {XML_SECURITY_TYPE, HotspotConfigType::SECURITYTYPE},
40     {XML_PASSPHRASE, HotspotConfigType::PASSPHRASE},
41 };
42 
43 namespace OHOS {
44 namespace Wifi {
45 class SoftapXmlParser : public XmlParser {
46 public:
47     SoftapXmlParser() = default;
48     ~SoftapXmlParser() override;
49 
50     /**
51      * @Description get softap configs
52      *
53      * @return std::vector<HotspotConfig> - softap configs
54     */
55     std::vector<HotspotConfig> GetSoftapConfigs();
56 private:
57     HotspotConfig hotspotConfig{};
58 
59     bool ParseInternal(xmlNodePtr node) override;
60     HotspotConfigType GetConfigNameAsInt(xmlNodePtr node);
61     xmlNodePtr GotoSoftApNode(xmlNodePtr innode);
62     void GetBandInfo(xmlNodePtr innode);
63     void TransBandinfo(xmlNodePtr innode);
64     void ParseSoftap(xmlNodePtr innode);
65 };
66 }
67 }
68 #endif