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