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 16 #ifndef NETWORK_PARSER 17 #define NETWORK_PARSER 18 #include "xml_parser.h" 19 #include <unordered_map> 20 #include "wifi_msg.h" 21 #include "wifi_internal_msg.h" 22 23 const unsigned int MGMT_NONE = 1 << 0; 24 const unsigned int MGMT_WPA_PSK = 1 << 1; 25 const unsigned int MGMT_WPA_EAP = 1 << 2; 26 const unsigned int MGMT_IEEE8021X = 1 << 3; 27 const unsigned int MGMT_WPA2_PSK = 1 << 4; 28 const unsigned int MGMT_OSEN = 1 << 5; 29 const unsigned int MGMT_FT_PSK = 1 << 6; 30 const unsigned int MGMT_FT_EAP = 1 << 7; 31 const unsigned int MGMT_SAE = 1 << 8; 32 const unsigned int MGMT_OWE = 1 << 9; 33 const unsigned int MGMT_SUITE_B_192 = 1 << 10; 34 const unsigned int MGMT_WPA_PSK_SHA256 = 1 << 11; 35 const unsigned int MGMT_WPA_EAP_SHA256 = 1 << 12; 36 const unsigned int MGMT_WAPI_PSK = 1 << 13; 37 const unsigned int MGMT_WAPI_CERT = 1 << 14; 38 const unsigned int MGMT_FILS_SHA384 = 1 << 15; 39 const unsigned int MGMT_Q_WAPI_PSK = 1 << 16; 40 const unsigned int MGMT_Q_WAPI_CERT = 1 << 17; 41 42 enum class WifiConfigType { 43 SSID = 0, 44 PRESHAREDKEY, 45 HIDDENSSID, 46 ALLOWEDKEYMGMT, 47 RANDOMIZATIONSETTING, 48 RANDOMIZEDMACADDRESS, 49 STATUS, 50 WEPKEYINDEX, 51 WEPKEYS, 52 IPASSIGNMENT, 53 LINKADDRESS, 54 PREFIXLENGTH, 55 GATEWAYADDRESS, 56 DNSSERVERADDRESSES, 57 PROXYSETTINGS, 58 PROXYPAC, 59 PROXYHOST, 60 PROXYPORT, 61 PROXYEXCLUSIONLIST, 62 VALIDATEDINTERNETACCESS, 63 PORTALNETWORK, 64 INTERNETHISTORY, 65 UNVALID, 66 }; 67 68 enum class NetworkSection { 69 WIFI_CONFIGURATION, 70 NETWORK_STATUS, 71 IP_CONFIGURATION, 72 ENTERPRISE_CONFIGURATION, 73 UNVALID, 74 }; 75 76 enum class NetworkParseType { 77 UNKNOWN, 78 MIGRATE, 79 CLONE 80 }; 81 82 namespace OHOS { 83 namespace Wifi { 84 class NetworkXmlParser : public XmlParser { 85 public: 86 NetworkXmlParser() = default; 87 ~NetworkXmlParser() override; 88 89 /** 90 * @Description get networkconfigs 91 * 92 * @return std::vector<WifiDeviceConfig> - networkconfigs 93 */ 94 std::vector<WifiDeviceConfig> GetNetworks(); 95 96 /** 97 * @Description get randommac map 98 * 99 * @return std::vector<WifiStoreRandomMac> - randommac map 100 */ 101 std::vector<WifiStoreRandomMac> GetRandomMacmap(); 102 private: 103 std::vector<WifiDeviceConfig> wifiConfigs{}; 104 std::vector<WifiStoreRandomMac> wifiStoreRandomMacs{}; 105 106 bool ParseInternal(xmlNodePtr node) override; 107 void ParseNetworkList(xmlNodePtr innode); 108 NetworkParseType GetParseType(xmlNodePtr node); 109 void EnableNetworks(); 110 xmlNodePtr GotoNetworkList(xmlNodePtr innode); 111 WifiDeviceConfig ParseNetwork(xmlNodePtr innode); 112 WifiConfigType GetConfigNameAsInt(xmlNodePtr node); 113 NetworkSection GetNodeNameAsInt(xmlNodePtr node); 114 WifiDeviceConfig ParseWifiConfig(xmlNodePtr innode); 115 void ParseNetworkStatus(xmlNodePtr node, WifiDeviceConfig& wifiConfig); 116 WifiIpConfig ParseIpConfig(xmlNodePtr innode); 117 ConfigureProxyMethod GetProxyMethod(xmlNodePtr innode); 118 WifiProxyConfig ParseProxyConfig(xmlNodePtr innode); 119 AssignIpMethod GetIpConfig(xmlNodePtr innode); 120 void GetKeyMgmt(xmlNodePtr node, WifiDeviceConfig& wifiConfig); 121 OHOS::Wifi::WifiPrivacyConfig GetRandMacSetting(xmlNodePtr node); 122 bool HasWepKeys(WifiDeviceConfig wifiConfig); 123 void ParseMacMap(); 124 void ParseWepKeys(xmlNodePtr node, WifiDeviceConfig& wifiDeviceConfig); 125 void ParseStatus(xmlNodePtr node, WifiDeviceConfig& wifiDeviceConfig); 126 bool IsWifiConfigValid(WifiDeviceConfig wifiConfig); 127 bool IsRandomMacValid(const std::string &macAddress); 128 void ParseMacMapPlus(xmlNodePtr innode); 129 xmlNodePtr GotoMacAddressMap(xmlNodePtr innode); 130 void SetMacByMacMapPlus(std::map<std::string, std::string> macMap); 131 void FillupMacByConfig(); 132 void ParseSsid(xmlNodePtr node, WifiDeviceConfig& wifiConfig); 133 void ParsePreSharedKey(xmlNodePtr node, WifiDeviceConfig& wifiConfig); 134 void ParseInternetHistory(xmlNodePtr node, WifiDeviceConfig& wifiConfig); 135 }; 136 } 137 } 138 #endif