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 DEV_INTERFACE_STATE_H 17 #define DEV_INTERFACE_STATE_H 18 19 #include <cstdint> 20 #include <iosfwd> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include "__functional_base" 26 #include "interface_configuration.h" 27 #include "net_all_capabilities.h" 28 #include "net_link_info.h" 29 #include "net_specifier.h" 30 #include "net_supplier_info.h" 31 #include "refbase.h" 32 33 namespace OHOS { 34 namespace NetManagerStandard { 35 class DevInterfaceState : public virtual RefBase { 36 enum ConnLinkState { REGISTERED, UNREGISTERED, LINK_AVAILABLE, LINK_UNAVAILABLE }; 37 38 public: 39 DevInterfaceState(); 40 ~DevInterfaceState() = default; 41 void SetDevName(const std::string &devName); 42 void SetNetCaps(const std::set<NetCap> &netCaps); 43 void SetLinkUp(bool up); 44 void SetlinkInfo(sptr<NetLinkInfo> &linkInfo); 45 void SetIfcfg(sptr<InterfaceConfiguration> &ifCfg); 46 void SetDhcpReqState(bool dhcpReqState); 47 void UpdateLinkInfo(const INetAddr &ipAddr, const INetAddr &netMask, const INetAddr &gateWay, const INetAddr &route, 48 const INetAddr &dns1, const INetAddr &dns2); 49 std::string GetDevName() const; 50 const std::set<NetCap> &GetNetCaps() const; 51 std::set<NetCap> GetNetCaps(); 52 bool GetLinkUp() const; 53 sptr<NetLinkInfo> GetLinkInfo() const; 54 sptr<InterfaceConfiguration> GetIfcfg() const; 55 IPSetMode GetIPSetMode() const; 56 bool GetDhcpReqState() const; 57 58 void RemoteRegisterNetSupplier(); 59 void RemoteUnregisterNetSupplier(); 60 void RemoteUpdateNetLinkInfo(); 61 void RemoteUpdateNetSupplierInfo(); 62 63 void GetDumpInfo(std::string &info); 64 65 private: 66 void UpdateLinkInfo(); 67 void UpdateSupplierAvailable(); 68 Route CreateLocalRoute(const std::string &iface, const std::string &ipAddr, const std::string &maskAddr); 69 70 private: 71 ConnLinkState connLinkState_ = UNREGISTERED; 72 uint32_t netSupplier_ = 0; 73 std::string devName_; 74 bool linkUp_ = false; 75 bool dhcpReqState_ = false; 76 sptr<NetLinkInfo> linkInfo_ = nullptr; 77 sptr<NetSupplierInfo> netSupplierInfo_ = nullptr; 78 sptr<InterfaceConfiguration> ifCfg_ = nullptr; 79 std::set<NetCap> netCaps_; 80 NetBearType bearerType_ = BEARER_ETHERNET; 81 }; 82 } // namespace NetManagerStandard 83 } // namespace OHOS 84 #endif // DEV_INTERFACE_STATE_H 85