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