1 /* 2 * Copyright (c) 2021-2024 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 ETHERNET_CLIENT_H 17 #define ETHERNET_CLIENT_H 18 19 #include <string> 20 21 #include "eth_eap_profile.h" 22 #include "iethernet_service.h" 23 #include "interface_state_callback.h" 24 #include "net_eap_callback_stub.h" 25 #include "parcel.h" 26 #include "singleton.h" 27 28 namespace OHOS { 29 namespace NetManagerStandard { 30 class EthernetClient { 31 DECLARE_DELAYED_SINGLETON(EthernetClient) 32 33 public: 34 /** 35 * Get the ethernet MAC address 36 * 37 * @param macAddrList MAC address info list 38 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 39 * @permission ohos.permission.GET_ETHERNET_LOCAL_MAC 40 * @systemapi Hide this for inner system use. 41 */ 42 int32_t GetMacAddress(std::vector<MacAddressInfo> &macAddrList); 43 44 /** 45 * Set the network interface configuration 46 * 47 * @param iface interface name 48 * @param ic interface configuration 49 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 50 * @permission ohos.permission.CONNECTIVITY_INTERNAL 51 * @systemapi Hide this for inner system use. 52 */ 53 int32_t SetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ic); 54 55 /** 56 * Gets the network interface configuration parameters 57 * 58 * @param iface interface name 59 * @param ifaceConfig interface configuration 60 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 61 * @permission ohos.permission.CONNECTIVITY_INTERNAL 62 * @systemapi Hide this for inner system use. 63 */ 64 int32_t GetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ifaceConfig); 65 66 /** 67 * check the network interface is active or not 68 * 69 * @param iface interface name 70 * @param activeStatus active status 71 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 72 * @permission ohos.permission.CONNECTIVITY_INTERNAL 73 * @systemapi Hide this for inner system use. 74 */ 75 int32_t IsIfaceActive(const std::string &iface, int32_t &activeStatus); 76 77 /** 78 * Gets the list of active devices 79 * 80 * @param activeIfaces list of active interface 81 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 82 * @permission ohos.permission.CONNECTIVITY_INTERNAL 83 * @systemapi Hide this for inner system use. 84 */ 85 int32_t GetAllActiveIfaces(std::vector<std::string> &activeIfaces); 86 87 /** 88 * Reset all configuration information 89 * 90 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 91 * @permission ohos.permission.CONNECTIVITY_INTERNAL 92 * @systemapi Hide this for inner system use. 93 */ 94 int32_t ResetFactory(); 95 96 /** 97 * Register the callback to monitor interface add/remove state 98 * 99 * @param callback use to receive interface add/remove event. 100 * @return Returns NETMANAGER_EXT_SUCCESS as success, other values as failure 101 * @permission ohos.permission.CONNECTIVITY_INTERNAL 102 * @systemapi Hide this for inner system use. 103 */ 104 int32_t RegisterIfacesStateChanged(const sptr<InterfaceStateCallback> &callback); 105 106 /** 107 * Cancel register the callback to monitor interface add/remove state 108 * 109 * @param callback use to receive interface add/remove event. 110 * @return Returns NETMANAGER_EXT_SUCCESS as success, other values as failure 111 * @permission ohos.permission.CONNECTIVITY_INTERNAL 112 * @systemapi Hide this for inner system use. 113 */ 114 int32_t UnregisterIfacesStateChanged(const sptr<InterfaceStateCallback> &callback); 115 116 /** 117 * Set the specified network port up 118 * 119 * @param iface interface name 120 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 121 * @permission ohos.permission.CONNECTIVITY_INTERNAL 122 * @systemapi Hide this for inner system use. 123 */ 124 int32_t SetInterfaceUp(const std::string &iface); 125 126 /** 127 * Set the specified network port down 128 * 129 * @param iface interface name 130 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 131 * @permission ohos.permission.CONNECTIVITY_INTERNAL 132 * @systemapi Hide this for inner system use. 133 */ 134 int32_t SetInterfaceDown(const std::string &iface); 135 136 /** 137 * Get the specified network port configuration 138 * 139 * @param iface interface name 140 * @param cfg interface configuration 141 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 142 * @permission ohos.permission.CONNECTIVITY_INTERNAL 143 * @systemapi Hide this for inner system use. 144 */ 145 int32_t GetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg); 146 147 /** 148 * Set the specified network port configuration 149 * 150 * @param iface interface name 151 * @param cfg interface configuration 152 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 153 * @permission ohos.permission.CONNECTIVITY_INTERNAL 154 * @systemapi Hide this for inner system use. 155 */ 156 int32_t SetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg); 157 158 /** 159 * Register custom eap info and callback 160 * @param netType Indicates net type need to customize 161 * @param regCmd Indicates some eapCode and eapType info. eg: 2:277:278 162 * @param callback the func of post back eap data 163 * @return Returns 0, successfully register custom eap callback, otherwise it will failed 164 * @permission ohos.permission.ENTERPRISE_MANAGE_EAP 165 * @systemapi Hide this for inner system use. 166 */ 167 int32_t RegCustomEapHandler(NetType netType, const std::string ®Cmd, 168 const sptr<INetEapPostbackCallback> &callback); 169 170 /** 171 * Reply custom eap data of app 172 * 173 * @param result The result of app 174 * @param eapData sptr of EapData 175 * @return Returns 0, successfully replyl custom eap data, otherwise it will failed 176 * @permission ohos.permission.ENTERPRISE_MANAGE_EAP 177 * @systemapi Hide this for inner system use. 178 */ 179 int32_t ReplyCustomEapData(int result, const sptr<EapData> &eapData); 180 181 /** 182 * Register module callback, such as wifi or eth 183 * 184 * @param netType Indicates net interface type need to customize 185 * @param callback The callback of INetRegisterEapCallback interface 186 * @return Returns 0, successfully register custom eap callback, otherwise it will failed 187 * @systemapi Hide this for inner system use. 188 */ 189 int32_t RegisterCustomEapCallback(const NetType netType, const sptr<INetRegisterEapCallback> &callback); 190 191 /** 192 * unRegister custom eap callback 193 * 194 * @param netType Indicates net interface type need to customize 195 * @param callback The callback of INetRegisterEapCallback interface 196 * @return Returns 0, successfully unregister custom eap callback, otherwise it will failed 197 * @systemapi Hide this for inner system use. 198 */ 199 int32_t UnRegisterCustomEapCallback(const NetType netType, const sptr<INetRegisterEapCallback> &callback); 200 201 /** 202 * Notify Wap Eap Intercept Info 203 * 204 * @param netType Indicates net interface type need to customize 205 * @param eapData the sptr of eapData 206 * @return Returns 0, successfully notity success, otherwise it will failed 207 * @systemapi Hide this for inner system use. 208 */ 209 int32_t NotifyWpaEapInterceptInfo(const NetType netType, const sptr<EapData> &eapData); 210 211 /** 212 * Get the ethernet device infomation 213 * 214 * @param deviceInfoList device information list 215 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 216 * @permission ohos.permission.GET_NETWORK_INFO 217 * @systemapi Hide this for inner system use. 218 */ 219 int32_t GetDeviceInformation(std::vector<EthernetDeviceInfo> &deviceInfoList); 220 221 /** 222 * Start EAP authentication on specified network interface. 223 * 224 * @param netId Indicates the eth network id to start EAP authentication. 225 * @param profile Indicates the eap profile. 226 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 227 * @syscap SystemCapability.Communication.NetManager.Eap 228 */ 229 int32_t StartEthEap(int32_t netId, const EthEapProfile& profile); 230 231 /** 232 * Log off EAP authentication on specified network interface. 233 * 234 * @param netId Indicates the eth network id to Log off EAP authentication. 235 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 236 * @syscap SystemCapability.Communication.NetManager.Eap 237 */ 238 int32_t LogOffEthEap(int32_t netId); 239 240 private: 241 class EthernetDeathRecipient : public IRemoteObject::DeathRecipient { 242 public: EthernetDeathRecipient(EthernetClient & client)243 explicit EthernetDeathRecipient(EthernetClient &client) : client_(client) {} 244 ~EthernetDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)245 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 246 { 247 client_.OnRemoteDied(remote); 248 } 249 250 private: 251 EthernetClient &client_; 252 }; 253 254 private: 255 sptr<IEthernetService> GetProxy(); 256 void RecoverCallback(); 257 void OnRemoteDied(const wptr<IRemoteObject> &remote); 258 259 private: 260 std::mutex mutex_; 261 sptr<IEthernetService> ethernetService_; 262 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 263 sptr<InterfaceStateCallback> callback_; 264 }; 265 } // namespace NetManagerStandard 266 } // namespace OHOS 267 #endif // ETHERNET_CLIENT_H