/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ETHERNET_MANAGEMENT_H #define ETHERNET_MANAGEMENT_H #include #include #include "dev_interface_state.h" #include "ethernet_configuration.h" #include "ethernet_dhcp_controller.h" #include "iservice_registry.h" #include "mac_address_info.h" #include "netsys_controller_callback.h" #include "system_ability_definition.h" #include "ethernet_lan_management.h" namespace OHOS { namespace NetManagerStandard { class EthernetManagement { private: class EhternetDhcpNotifyCallback : public EthernetDhcpCallback { public: EhternetDhcpNotifyCallback(EthernetManagement ðernetManagement) : ethernetManagement_(ethernetManagement) {} int32_t OnDhcpSuccess(EthernetDhcpCallback::DhcpResult &dhcpResult) override; private: EthernetManagement ðernetManagement_; }; private: class DevInterfaceStateCallback : public NetsysControllerCallback { public: DevInterfaceStateCallback(EthernetManagement ðernetManagement) : ethernetManagement_(ethernetManagement) {} ~DevInterfaceStateCallback() = default; int32_t OnInterfaceAddressUpdated(const std::string &, const std::string &, int, int) override; int32_t OnInterfaceAddressRemoved(const std::string &, const std::string &, int, int) override; int32_t OnInterfaceAdded(const std::string &iface) override; int32_t OnInterfaceRemoved(const std::string &iface) override; int32_t OnInterfaceChanged(const std::string &, bool) override; int32_t OnInterfaceLinkStateChanged(const std::string &ifName, bool up) override; int32_t OnRouteChanged(bool, const std::string &, const std::string &, const std::string &) override; int32_t OnDhcpSuccess(NetsysControllerCallback::DhcpResult &dhcpResult) override; int32_t OnBandwidthReachedLimit(const std::string &limitName, const std::string &iface) override; private: EthernetManagement ðernetManagement_; }; public: static EthernetManagement& GetInstance(); void Init(); int32_t UpdateDevInterfaceLinkInfo(EthernetDhcpCallback::DhcpResult &dhcpResult); void UpdateInterfaceState(const std::string &dev, bool up); int32_t GetMacAddress(std::vector &macAddrList); int32_t UpdateDevInterfaceCfg(const std::string &iface, sptr cfg); int32_t GetDevInterfaceCfg(const std::string &iface, sptr &ifaceConfig); int32_t IsIfaceActive(const std::string &iface, int32_t &activeStatus); int32_t GetAllActiveIfaces(std::vector &activeIfaces); int32_t ResetFactory(); void GetDumpInfo(std::string &info); void DevInterfaceAdd(const std::string &devName); void DevInterfaceRemove(const std::string &devName); private: EthernetManagement(); ~EthernetManagement(); EthernetManagement(const EthernetManagement&) = delete; EthernetManagement& operator=(const EthernetManagement&) = delete; std::string GetMacAddr(const std::string &iface); std::string HwAddrToStr(char *hwaddr); void StartDhcpClient(const std::string &dev, sptr &devState); void StopDhcpClient(const std::string &dev, sptr &devState); void StartSetDevUpThd(); bool IsIfaceLinkUp(const std::string &iface); bool ModeInputCheck(IPSetMode origin, IPSetMode input); private: std::map> devCaps_; std::map> devCfgs_; std::map> devs_; std::unique_ptr ethConfiguration_ = nullptr; std::unique_ptr ethDhcpController_ = nullptr; sptr ethDhcpNotifyCallback_ = nullptr; sptr ethDevInterfaceStateCallback_ = nullptr; std::map> netLinkConfigs_; std::unique_ptr ethLanManageMent_ = nullptr; std::mutex mutex_; }; } // namespace NetManagerStandard } // namespace OHOS #endif // ETHERNET_MANAGEMENT_H