18e745fdaSopenharmony_ci/* 28e745fdaSopenharmony_ci * Copyright (C) 2022-2023 Huawei Device Co., Ltd. 38e745fdaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48e745fdaSopenharmony_ci * you may not use this file except in compliance with the License. 58e745fdaSopenharmony_ci * You may obtain a copy of the License at 68e745fdaSopenharmony_ci * 78e745fdaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88e745fdaSopenharmony_ci * 98e745fdaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108e745fdaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118e745fdaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128e745fdaSopenharmony_ci * See the License for the specific language governing permissions and 138e745fdaSopenharmony_ci * limitations under the License. 148e745fdaSopenharmony_ci */ 158e745fdaSopenharmony_ci 168e745fdaSopenharmony_ci#ifndef ETHERNET_CONFIGURATION_H 178e745fdaSopenharmony_ci#define ETHERNET_CONFIGURATION_H 188e745fdaSopenharmony_ci 198e745fdaSopenharmony_ci#include <map> 208e745fdaSopenharmony_ci#include <mutex> 218e745fdaSopenharmony_ci#include <numeric> 228e745fdaSopenharmony_ci#include <set> 238e745fdaSopenharmony_ci#include <string> 248e745fdaSopenharmony_ci#include <vector> 258e745fdaSopenharmony_ci 268e745fdaSopenharmony_ci#include "cJSON.h" 278e745fdaSopenharmony_ci#include "ethernet_dhcp_callback.h" 288e745fdaSopenharmony_ci#include "http_proxy.h" 298e745fdaSopenharmony_ci#include "interface_configuration.h" 308e745fdaSopenharmony_ci#include "net_all_capabilities.h" 318e745fdaSopenharmony_ci#include "net_link_info.h" 328e745fdaSopenharmony_ci 338e745fdaSopenharmony_cinamespace OHOS { 348e745fdaSopenharmony_cinamespace NetManagerStandard { 358e745fdaSopenharmony_ciclass EthernetConfiguration { 368e745fdaSopenharmony_cipublic: 378e745fdaSopenharmony_ci EthernetConfiguration(); 388e745fdaSopenharmony_ci ~EthernetConfiguration() = default; 398e745fdaSopenharmony_ci 408e745fdaSopenharmony_ci bool ReadSystemConfiguration(std::map<std::string, std::set<NetCap>> &devCaps, 418e745fdaSopenharmony_ci std::map<std::string, sptr<InterfaceConfiguration>> &devCfgs); 428e745fdaSopenharmony_ci bool ReadUserConfiguration(std::map<std::string, sptr<InterfaceConfiguration>> &devCfgs); 438e745fdaSopenharmony_ci bool WriteUserConfiguration(const std::string &iface, sptr<InterfaceConfiguration> &cfg); 448e745fdaSopenharmony_ci bool ClearAllUserConfiguration(); 458e745fdaSopenharmony_ci bool ConvertToConfiguration(const EthernetDhcpCallback::DhcpResult &dhcpResult, sptr<StaticConfiguration> &config); 468e745fdaSopenharmony_ci sptr<InterfaceConfiguration> MakeInterfaceConfiguration(const sptr<InterfaceConfiguration> &devCfg, 478e745fdaSopenharmony_ci const sptr<NetLinkInfo> &devLinkInfo); 488e745fdaSopenharmony_ci 498e745fdaSopenharmony_ciprivate: 508e745fdaSopenharmony_ci void ParseDevice(const std::string &fileContent, std::string &iface); 518e745fdaSopenharmony_ci void ParseBootProto(const std::string &fileContent, sptr<InterfaceConfiguration> cfg); 528e745fdaSopenharmony_ci void ParseStaticConfig(const std::string &fileContent, sptr<InterfaceConfiguration> cfg); 538e745fdaSopenharmony_ci 548e745fdaSopenharmony_ci bool ReadEthernetInterfaces(std::map<std::string, std::set<NetCap>> &devCaps, 558e745fdaSopenharmony_ci std::map<std::string, sptr<InterfaceConfiguration>> &devCfgs, 568e745fdaSopenharmony_ci const cJSON* const json); 578e745fdaSopenharmony_ci std::string ReadJsonFile(const std::string &filePath); 588e745fdaSopenharmony_ci sptr<InterfaceConfiguration> ConvertJsonToConfiguration(const cJSON* const jsonData, bool isLan); 598e745fdaSopenharmony_ci bool IsDirExist(const std::string &dirPath); 608e745fdaSopenharmony_ci bool CreateDir(const std::string &dirPath); 618e745fdaSopenharmony_ci bool DelDir(const std::string &dirPath); 628e745fdaSopenharmony_ci bool IsFileExist(const std::string &filePath, std::string &realPath); 638e745fdaSopenharmony_ci bool ReadFile(const std::string &filePath, std::string &fileContent); 648e745fdaSopenharmony_ci bool WriteFile(const std::string &filePath, const std::string &fileContent); 658e745fdaSopenharmony_ci void ParserFileConfig(const std::string &fileContent, std::string &iface, sptr<InterfaceConfiguration> cfg); 668e745fdaSopenharmony_ci void ParserFileHttpProxy(const std::string &fileContent, const sptr<InterfaceConfiguration> &cfg); 678e745fdaSopenharmony_ci void ParserIfaceIpAndRoute(sptr<InterfaceConfiguration> &cfg, const std::string &rootNetMask); 688e745fdaSopenharmony_ci void GenCfgContent(const std::string &iface, sptr<InterfaceConfiguration> cfg, std::string &fileContent); 698e745fdaSopenharmony_ci void GenHttpProxyContent(const sptr<InterfaceConfiguration> &cfg, std::string &fileContent); 708e745fdaSopenharmony_ci std::string AccumulateNetAddress(const std::vector<INetAddr> &netAddrList); 718e745fdaSopenharmony_ci bool IsValidDhcpResult(const EthernetDhcpCallback::DhcpResult &dhcpResult, sptr<StaticConfiguration> &config); 728e745fdaSopenharmony_ci std::string GetIfaceMode(IPSetMode mode); 738e745fdaSopenharmony_ci std::vector<INetAddr> GetGatewayFromMap(const std::unordered_map<std::string, INetAddr> &temp); 748e745fdaSopenharmony_ci std::vector<INetAddr> GetGatewayFromRouteList(std::list<Route> &routeList); 758e745fdaSopenharmony_ci 768e745fdaSopenharmony_ciprivate: 778e745fdaSopenharmony_ci std::mutex mutex_; 788e745fdaSopenharmony_ci}; 798e745fdaSopenharmony_ci} // namespace NetManagerStandard 808e745fdaSopenharmony_ci} // namespace OHOS 818e745fdaSopenharmony_ci#endif // ETHERNET_CONFIGURATION_H 82