1/* 2 * Copyright (C) 2022-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 */ 15import type { AsyncCallback, Callback } from './@ohos.base'; 16import type connection from './@ohos.net.connection'; 17 18/** 19 * Provides interfaces to manage ethernet. 20 * @namespace ethernet 21 * @syscap SystemCapability.Communication.NetManager.Ethernet 22 * @since 9 23 */ 24declare namespace ethernet { 25 /** 26 * @syscap SystemCapability.Communication.NetManager.Ethernet 27 * @since 10 28 */ 29 type HttpProxy = connection.HttpProxy; 30 31 /** 32 * Get the specified network interface information. 33 * @permission ohos.permission.GET_NETWORK_INFO 34 * @param { string } iface - Indicates the network interface name. 35 * @param { AsyncCallback<InterfaceConfiguration> } callback - the callback of getIfaceConfig. 36 * @throws { BusinessError } 201 - Permission denied. 37 * @throws { BusinessError } 202 - Non-system applications use system APIs. 38 * @throws { BusinessError } 401 - Parameter error. 39 * @throws { BusinessError } 2200001 - Invalid parameter value. 40 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 41 * @throws { BusinessError } 2200003 - System internal error. 42 * @throws { BusinessError } 2201005 - Device information does not exist. 43 * @syscap SystemCapability.Communication.NetManager.Ethernet 44 * @systemapi Hide this for inner system use. 45 * @since 9 46 */ 47 function getIfaceConfig(iface: string, callback: AsyncCallback<InterfaceConfiguration>): void; 48 49 /** 50 * Get the specified network interface information. 51 * @permission ohos.permission.GET_NETWORK_INFO 52 * @param { string } iface - Indicates the network interface name. 53 * @returns { Promise<InterfaceConfiguration> } the promise returned by the function. 54 * @throws { BusinessError } 201 - Permission denied. 55 * @throws { BusinessError } 202 - Non-system applications use system APIs. 56 * @throws { BusinessError } 401 - Parameter error. 57 * @throws { BusinessError } 2200001 - Invalid parameter value. 58 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 59 * @throws { BusinessError } 2200003 - System internal error. 60 * @throws { BusinessError } 2201005 - Device information does not exist. 61 * @syscap SystemCapability.Communication.NetManager.Ethernet 62 * @systemapi Hide this for inner system use. 63 * @since 9 64 */ 65 function getIfaceConfig(iface: string): Promise<InterfaceConfiguration>; 66 67 /** 68 * Set the specified network interface parameters. 69 * @permission ohos.permission.CONNECTIVITY_INTERNAL 70 * @param { string } iface - Indicates the network interface name of the network parameter. 71 * @param { InterfaceConfiguration } ic - Indicates the ic. See {@link InterfaceConfiguration}. 72 * @param { AsyncCallback<void> } callback - the callback of setIfaceConfig. 73 * @throws { BusinessError } 201 - Permission denied. 74 * @throws { BusinessError } 202 - Non-system applications use system APIs. 75 * @throws { BusinessError } 401 - Parameter error. 76 * @throws { BusinessError } 2200001 - Invalid parameter value. 77 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 78 * @throws { BusinessError } 2200003 - System internal error. 79 * @throws { BusinessError } 2201004 - Invalid Ethernet profile. 80 * @throws { BusinessError } 2201005 - Device information does not exist. 81 * @throws { BusinessError } 2201006 - Ethernet device not connected. 82 * @throws { BusinessError } 2201007 - Ethernet failed to write user configuration information. 83 * @syscap SystemCapability.Communication.NetManager.Ethernet 84 * @systemapi Hide this for inner system use. 85 * @since 9 86 */ 87 function setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback<void>): void; 88 89 /** 90 * Set the specified network interface parameters. 91 * @permission ohos.permission.CONNECTIVITY_INTERNAL 92 * @param { string } iface - Indicates the network interface name of the network parameter. 93 * @param { InterfaceConfiguration } ic - Indicates the ic. See {@link InterfaceConfiguration}. 94 * @returns { Promise<void> } the promise returned by the function. 95 * @throws { BusinessError } 201 - Permission denied. 96 * @throws { BusinessError } 202 - Non-system applications use system APIs. 97 * @throws { BusinessError } 401 - Parameter error. 98 * @throws { BusinessError } 2200001 - Invalid parameter value. 99 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 100 * @throws { BusinessError } 2200003 - System internal error. 101 * @throws { BusinessError } 2201004 - Invalid Ethernet profile. 102 * @throws { BusinessError } 2201005 - Device information does not exist. 103 * @throws { BusinessError } 2201006 - Ethernet device not connected. 104 * @throws { BusinessError } 2201007 - Ethernet failed to write user configuration information. 105 * @syscap SystemCapability.Communication.NetManager.Ethernet 106 * @systemapi Hide this for inner system use. 107 * @since 9 108 */ 109 function setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise<void>; 110 111 /** 112 * Check whether the specified network is active. 113 * @permission ohos.permission.GET_NETWORK_INFO 114 * @param { string } iface - Indicates the network interface name. 115 * @param { AsyncCallback<number> } callback - the callback of isIfaceActive. 116 * @throws { BusinessError } 201 - Permission denied. 117 * @throws { BusinessError } 202 - Non-system applications use system APIs. 118 * @throws { BusinessError } 401 - Parameter error. 119 * @throws { BusinessError } 2200001 - Invalid parameter value. 120 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 121 * @throws { BusinessError } 2200003 - System internal error. 122 * @throws { BusinessError } 2201005 - Device information does not exist. 123 * @syscap SystemCapability.Communication.NetManager.Ethernet 124 * @systemapi Hide this for inner system use. 125 * @since 9 126 */ 127 function isIfaceActive(iface: string, callback: AsyncCallback<number>): void; 128 129 /** 130 * Check whether the specified network is active. 131 * @permission ohos.permission.GET_NETWORK_INFO 132 * @param { string } iface - Indicates the network interface name. 133 * @returns { Promise<number> } the promise returned by the function. 134 * @throws { BusinessError } 201 - Permission denied. 135 * @throws { BusinessError } 202 - Non-system applications use system APIs. 136 * @throws { BusinessError } 401 - Parameter error. 137 * @throws { BusinessError } 2200001 - Invalid parameter value. 138 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 139 * @throws { BusinessError } 2200003 - System internal error. 140 * @throws { BusinessError } 2201005 - Device information does not exist. 141 * @syscap SystemCapability.Communication.NetManager.Ethernet 142 * @systemapi Hide this for inner system use. 143 * @since 9 144 */ 145 function isIfaceActive(iface: string): Promise<number>; 146 147 /** 148 * Gets the names of all active network interfaces. 149 * @permission ohos.permission.GET_NETWORK_INFO 150 * @param { AsyncCallback<Array<string>> } callback - the callback of getAllActiveIfaces. 151 * @throws { BusinessError } 201 - Permission denied. 152 * @throws { BusinessError } 202 - Non-system applications use system APIs. 153 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 154 * @throws { BusinessError } 2200003 - System internal error. 155 * @syscap SystemCapability.Communication.NetManager.Ethernet 156 * @systemapi Hide this for inner system use. 157 * @since 9 158 */ 159 function getAllActiveIfaces(callback: AsyncCallback<Array<string>>): void; 160 161 /** 162 * Gets the names of all active network interfaces. 163 * @permission ohos.permission.GET_NETWORK_INFO 164 * @returns { Promise<Array<string>> } the promise returned by the function. 165 * @throws { BusinessError } 201 - Permission denied. 166 * @throws { BusinessError } 202 - Non-system applications use system APIs. 167 * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service. 168 * @throws { BusinessError } 2200003 - System internal error. 169 * @syscap SystemCapability.Communication.NetManager.Ethernet 170 * @systemapi Hide this for inner system use. 171 * @since 9 172 */ 173 function getAllActiveIfaces(): Promise<Array<string>>; 174 175 /** 176 * Register a callback for the ethernet interface active state change. 177 * @permission ohos.permission.GET_NETWORK_INFO 178 * @param { 'interfaceStateChange' } type - Indicates Event name. 179 * @param { Callback<{ iface: string, active: boolean }> } callback - Including iface Indicates the ethernet interface, 180 * and active Indicates whether the interface is active. 181 * @throws { BusinessError } 201 - Permission denied. 182 * @throws { BusinessError } 202 - Non-system applications use system APIs. 183 * @throws { BusinessError } 401 - Parameter error. 184 * @syscap SystemCapability.Communication.NetManager.Ethernet 185 * @systemapi Hide this for inner system use. 186 * @since 10 187 */ 188 function on(type: 'interfaceStateChange', callback: Callback<{ iface: string, active: boolean }>): void; 189 190 /** 191 * Unregister a callback from the ethernet interface active state change. 192 * @permission ohos.permission.GET_NETWORK_INFO 193 * @param { 'interfaceStateChange' } type - Indicates Event name. 194 * @param { Callback<{ iface: string, active: boolean }> } callback - Including iface Indicates the ethernet interface, 195 * and active Indicates whether the interface is active. 196 * @throws { BusinessError } 201 - Permission denied. 197 * @throws { BusinessError } 202 - Non-system applications use system APIs. 198 * @throws { BusinessError } 401 - Parameter error. 199 * @syscap SystemCapability.Communication.NetManager.Ethernet 200 * @systemapi Hide this for inner system use. 201 * @since 10 202 */ 203 function off(type: 'interfaceStateChange', callback?: Callback<{ iface: string, active: boolean }>): void; 204 205 /** 206 * Defines the network configuration for the Ethernet connection. 207 * @interface InterfaceConfiguration 208 * @syscap SystemCapability.Communication.NetManager.Ethernet 209 * @systemapi Hide this for inner system use. 210 * @since 9 211 */ 212 export interface InterfaceConfiguration { 213 /** 214 * @type {IPSetMode} 215 * See {@link IPSetMode} 216 * @syscap SystemCapability.Communication.NetManager.Ethernet 217 * @systemapi Hide this for inner system use. 218 * @since 9 219 */ 220 mode: IPSetMode; 221 /** 222 * Ethernet connection static configuration IP information. 223 * The address value range is 0-255.0-255.0-255.0-255.0-255 224 * (DHCP mode does not need to be configured) 225 * @type {string} 226 * @syscap SystemCapability.Communication.NetManager.Ethernet 227 * @systemapi Hide this for inner system use. 228 * @since 9 229 */ 230 ipAddr: string; 231 232 /** 233 * Ethernet connection static configuration route information. 234 * The address value range is 0-255.0-255.0-255.0-255.0-255 235 * (DHCP mode does not need to be configured) 236 * @type {string} 237 * @syscap SystemCapability.Communication.NetManager.Ethernet 238 * @systemapi Hide this for inner system use. 239 * @since 9 240 */ 241 route: string; 242 243 /** 244 * Ethernet connection static configuration gateway information. 245 * The address value range is 0-255.0-255.0-255.0-255.0-255 246 * (DHCP mode does not need to be configured) 247 * @type {string} 248 * @syscap SystemCapability.Communication.NetManager.Ethernet 249 * @systemapi Hide this for inner system use. 250 * @since 9 251 */ 252 gateway: string; 253 254 /** 255 * Ethernet connection static configuration netMask information. 256 * The address value range is 0-255.0-255.0-255.0-255.0-255 257 * (DHCP mode does not need to be configured) 258 * @type {string} 259 * @syscap SystemCapability.Communication.NetManager.Ethernet 260 * @systemapi Hide this for inner system use. 261 * @since 9 262 */ 263 netMask: string; 264 265 /** 266 * The Ethernet connection is configured with the dns service address. 267 * The address value range is 0-255.0-255.0-255.0-255.0-255 268 * (DHCP mode does not need to be configured, Multiple addresses are separated by ",") 269 * @type {string} 270 * @syscap SystemCapability.Communication.NetManager.Ethernet 271 * @systemapi Hide this for inner system use. 272 * @since 9 273 */ 274 dnsServers: string; 275 276 /** 277 * Indicates the HttpProxy settings, no proxy is to be used as default. 278 * @type {?HttpProxy} 279 * @syscap SystemCapability.Communication.NetManager.Ethernet 280 * @systemapi Hide this for inner system use. 281 * @since 10 282 */ 283 httpProxy?: HttpProxy; 284 } 285 286 /** 287 * Defines the configuration mode of the Ethernet connection. 288 * @enum {number} 289 * @syscap SystemCapability.Communication.NetManager.Ethernet 290 * @systemapi Hide this for inner system use. 291 * @since 9 292 */ 293 export enum IPSetMode { 294 /** 295 * Static configuration. 296 * @syscap SystemCapability.Communication.NetManager.Ethernet 297 * @systemapi Hide this for inner system use. 298 * @since 9 299 */ 300 STATIC = 0, 301 302 /** 303 * Dynamic configuration. 304 * @syscap SystemCapability.Communication.NetManager.Ethernet 305 * @systemapi Hide this for inner system use. 306 * @since 9 307 */ 308 DHCP = 1 309 } 310} 311 312export default ethernet;