• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1-/*
2 * Copyright (C) 2022-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
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  /**
29   * Get the specified network interface information.
30   * @permission ohos.permission.GET_NETWORK_INFO
31   * @param { string } iface Indicates the network interface name.
32   * @param { AsyncCallback<InterfaceConfiguration> } callback - the callback of getIfaceConfig.
33   * @throws { BusinessError } 201 - Permission denied.
34   * @throws { BusinessError } 202 - Non-system applications use system APIs.
35   * @throws { BusinessError } 401 - Parameter error.
36   * @throws { BusinessError } 2200001 - Invalid parameter value.
37   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
38   * @throws { BusinessError } 2200003 - System internal error.
39   * @throws { BusinessError } 2201005 - Device information does not exist.
40   * @syscap SystemCapability.Communication.NetManager.Ethernet
41   * @systemapi Hide this for inner system use.
42   * @since 9
43   */
44  function getIfaceConfig(iface: string, callback: AsyncCallback<InterfaceConfiguration>): void;
45
46  /**
47   * Get the specified network interface information.
48   * @permission ohos.permission.GET_NETWORK_INFO
49   * @param { string } iface Indicates the network interface name.
50   * @returns { Promise<InterfaceConfiguration> } the promise returned by the function.
51   * @throws { BusinessError } 201 - Permission denied.
52   * @throws { BusinessError } 202 - Non-system applications use system APIs.
53   * @throws { BusinessError } 401 - Parameter error.
54   * @throws { BusinessError } 2200001 - Invalid parameter value.
55   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
56   * @throws { BusinessError } 2200003 - System internal error.
57   * @throws { BusinessError } 2201005 - Device information does not exist.
58   * @syscap SystemCapability.Communication.NetManager.Ethernet
59   * @systemapi Hide this for inner system use.
60   * @since 9
61   */
62  function getIfaceConfig(iface: string): Promise<InterfaceConfiguration>;
63
64  /**
65   * Set the specified network interface parameters.
66   * @permission ohos.permission.CONNECTIVITY_INTERNAL
67   * @param { string } iface Indicates the network interface name of the network parameter.
68   * @param { InterfaceConfiguration } ic Indicates the ic. See {@link InterfaceConfiguration}.
69   * @param { AsyncCallback<void> } callback - the callback of setIfaceConfig.
70   * @throws { BusinessError } 201 - Permission denied.
71   * @throws { BusinessError } 202 - Non-system applications use system APIs.
72   * @throws { BusinessError } 401 - Parameter error.
73   * @throws { BusinessError } 2200001 - Invalid parameter value.
74   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
75   * @throws { BusinessError } 2200003 - System internal error.
76   * @throws { BusinessError } 2201004 - Invalid Ethernet profile.
77   * @throws { BusinessError } 2201005 - Device information does not exist.
78   * @throws { BusinessError } 2201006 - Ethernet device not connected.
79   * @throws { BusinessError } 2201007 - Ethernet failed to write user configuration information.
80   * @syscap SystemCapability.Communication.NetManager.Ethernet
81   * @systemapi Hide this for inner system use.
82   * @since 9
83   */
84  function setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback<void>): void;
85
86  /**
87   * Set the specified network interface parameters.
88   * @permission ohos.permission.CONNECTIVITY_INTERNAL
89   * @param { string } iface Indicates the network interface name of the network parameter.
90   * @param { InterfaceConfiguration } ic Indicates the ic. See {@link InterfaceConfiguration}.
91   * @returns { Promise<void> } the promise returned by the function.
92   * @throws { BusinessError } 201 - Permission denied.
93   * @throws { BusinessError } 202 - Non-system applications use system APIs.
94   * @throws { BusinessError } 401 - Parameter error.
95   * @throws { BusinessError } 2200001 - Invalid parameter value.
96   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
97   * @throws { BusinessError } 2200003 - System internal error.
98   * @throws { BusinessError } 2201004 - Invalid Ethernet profile.
99   * @throws { BusinessError } 2201005 - Device information does not exist.
100   * @throws { BusinessError } 2201006 - Ethernet device not connected.
101   * @throws { BusinessError } 2201007 - Ethernet failed to write user configuration information.
102   * @syscap SystemCapability.Communication.NetManager.Ethernet
103   * @systemapi Hide this for inner system use.
104   * @since 9
105   */
106  function setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise<void>;
107
108  /**
109   * Check whether the specified network is active.
110   * @permission ohos.permission.GET_NETWORK_INFO
111   * @param { string } iface Indicates the network interface name.
112   * @param { AsyncCallback<number> } callback - the callback of isIfaceActive.
113   * @throws { BusinessError } 201 - Permission denied.
114   * @throws { BusinessError } 202 - Non-system applications use system APIs.
115   * @throws { BusinessError } 401 - Parameter error.
116   * @throws { BusinessError } 2200001 - Invalid parameter value.
117   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
118   * @throws { BusinessError } 2200003 - System internal error.
119   * @throws { BusinessError } 2201005 - Device information does not exist.
120   * @syscap SystemCapability.Communication.NetManager.Ethernet
121   * @systemapi Hide this for inner system use.
122   * @since 9
123   */
124  function isIfaceActive(iface: string, callback: AsyncCallback<number>): void;
125
126  /**
127   * Check whether the specified network is active.
128   * @permission ohos.permission.GET_NETWORK_INFO
129   * @param { string } iface Indicates the network interface name.
130   * @returns { Promise<number> } the promise returned by the function.
131   * @throws { BusinessError } 201 - Permission denied.
132   * @throws { BusinessError } 202 - Non-system applications use system APIs.
133   * @throws { BusinessError } 401 - Parameter error.
134   * @throws { BusinessError } 2200001 - Invalid parameter value.
135   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
136   * @throws { BusinessError } 2200003 - System internal error.
137   * @throws { BusinessError } 2201005 - Device information does not exist.
138   * @syscap SystemCapability.Communication.NetManager.Ethernet
139   * @systemapi Hide this for inner system use.
140   * @since 9
141   */
142  function isIfaceActive(iface: string): Promise<number>;
143
144  /**
145   * Gets the names of all active network interfaces.
146   * @permission ohos.permission.GET_NETWORK_INFO
147   * @param { AsyncCallback<Array<string>> } callback - the callback of getAllActiveIfaces.
148   * @throws { BusinessError } 201 - Permission denied.
149   * @throws { BusinessError } 202 - Non-system applications use system APIs.
150   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
151   * @throws { BusinessError } 2200003 - System internal error.
152   * @syscap SystemCapability.Communication.NetManager.Ethernet
153   * @systemapi Hide this for inner system use.
154   * @since 9
155   */
156  function getAllActiveIfaces(callback: AsyncCallback<Array<string>>): void;
157
158  /**
159   * Gets the names of all active network interfaces.
160   * @permission ohos.permission.GET_NETWORK_INFO
161   * @returns { Promise<Array<string>> } the promise returned by the function.
162   * @throws { BusinessError } 201 - Permission denied.
163   * @throws { BusinessError } 202 - Non-system applications use system APIs.
164   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
165   * @throws { BusinessError } 2200003 - System internal error.
166   * @syscap SystemCapability.Communication.NetManager.Ethernet
167   * @systemapi Hide this for inner system use.
168   * @since 9
169   */
170  function getAllActiveIfaces(): Promise<Array<string>>;
171
172  /**
173   * Register a callback for the ethernet interface active state change.
174   * @permission ohos.permission.GET_NETWORK_INFO
175   * @param { 'interfaceStateChange' } type Indicates Event name.
176   * @param { Callback<{ iface: string, active: boolean }> } callback including iface Indicates the ethernet interface,
177   * and active Indicates whether the interface is active.
178   * @throws { BusinessError } 201 Permission denied.
179   * @throws { BusinessError } 202 - Non-system applications use system APIs.
180   * @throws { BusinessError } 401 Parameter error.
181   * @syscap SystemCapability.Communication.NetManager.Ethernet
182   * @systemapi Hide this for inner system use.
183   * @since 10
184   */
185  function on(type: 'interfaceStateChange', callback: Callback<{ iface: string, active: boolean }>): void;
186
187  /**
188   * Unregister a callback from the ethernet interface active state change.
189   * @permission ohos.permission.GET_NETWORK_INFO
190   * @param { 'interfaceStateChange' } type Indicates Event name.
191   * @param { Callback<{ iface: string, active: boolean }> } callback including iface Indicates the ethernet interface,
192   * and active Indicates whether the interface is active.
193   * @throws { BusinessError } 201 Permission denied.
194   * @throws { BusinessError } 202 - Non-system applications use system APIs.
195   * @throws { BusinessError } 401 Parameter error.
196   * @syscap SystemCapability.Communication.NetManager.Ethernet
197   * @systemapi Hide this for inner system use.
198   * @since 10
199   */
200  function off(type: 'interfaceStateChange', callback?: Callback<{ iface: string, active: boolean }>): void;
201
202  /**
203   * Get the ethernet mac address list.
204   * @permission ohos.permission.GET_ETHERNET_LOCAL_MAC
205   * @returns { Promise<Array<MacAddressInfo>> } the promise returned by the function.
206   * @throws { BusinessError } 201 - Permission denied.
207   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
208   * @throws { BusinessError } 2201005 - Device information does not exist.
209   * @syscap SystemCapability.Communication.NetManager.Ethernet
210   * @since 14
211   */
212  function getMacAddress(): Promise<Array<MacAddressInfo>>;
213
214  /**
215   * Get the ethernet mac address list.
216   * @permission ohos.permission.GET_NETWORK_INFO
217   * @returns { Promise<Array<EthernetDeviceInfos>> } the promise returned by the function.
218   * @throws { BusinessError } 201 - Permission denied.
219   * @throws { BusinessError } 202 - Non-system applications use system APIs.
220   * @throws { BusinessError } 2201005 - Device information does not exist.
221   * @syscap SystemCapability.Communication.NetManager.Ethernet
222   * @systemapi Hide this for inner system use.
223   * @since 20
224   */
225  function getEthernetDeviceInfos(): Promise<Array<EthernetDeviceInfos>>;
226
227  /**
228   * Defines the network configuration for the Ethernet connection.
229   * @interface InterfaceConfiguration
230   * @syscap SystemCapability.Communication.NetManager.Ethernet
231   * @systemapi Hide this for inner system use.
232   * @since 9
233   */
234  export interface InterfaceConfiguration {
235    /**
236     * @type {IPSetMode}
237     * See {@link IPSetMode}
238     * @syscap SystemCapability.Communication.NetManager.Ethernet
239     * @systemapi Hide this for inner system use.
240     * @since 9
241     */
242    mode: IPSetMode;
243    /**
244     * Ethernet connection static configuration IP 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    ipAddr: string;
253
254    /**
255     * Ethernet connection static configuration route 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    route: string;
264
265    /**
266     * Ethernet connection static configuration gateway 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    gateway: string;
275
276    /**
277     * Ethernet connection static configuration netMask 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    netMask: string;
286
287    /**
288     * The Ethernet connection is configured with the dns service address.
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, Multiple addresses are separated by ",")
291     * @type {string}
292     * @syscap SystemCapability.Communication.NetManager.Ethernet
293     * @systemapi Hide this for inner system use.
294     * @since 9
295     */
296    dnsServers: string;
297
298    /**
299     * Indicates the HttpProxy settings, Default does not use HttpProxy.
300     * @type {?HttpProxy}
301     * @syscap SystemCapability.Communication.NetManager.Ethernet
302     * @since 10
303     */
304    httpProxy?: HttpProxy;
305  }
306
307  /**
308   * Defines the configuration mode of the Ethernet connection.
309   * @enum {number}
310   * @syscap SystemCapability.Communication.NetManager.Ethernet
311   * @systemapi Hide this for inner system use.
312   * @since 9
313   */
314  export enum IPSetMode {
315    /**
316     * Static configuration.
317     * @syscap SystemCapability.Communication.NetManager.Ethernet
318     * @systemapi Hide this for inner system use.
319     * @since 9
320     */
321    STATIC = 0,
322
323    /**
324     * Dynamic configuration.
325     * @syscap SystemCapability.Communication.NetManager.Ethernet
326     * @systemapi Hide this for inner system use.
327     * @since 9
328     */
329    DHCP = 1
330  }
331
332  /**
333   * Defines the mac address info of the Ethernet.
334   * @interface MacAddressInfo
335   * @syscap SystemCapability.Communication.NetManager.Ethernet
336   * @since 14
337   */
338  export interface MacAddressInfo {
339    /**
340     * Ethernet interface name.
341     * @type {string}
342     * @syscap SystemCapability.Communication.NetManager.Ethernet
343     * @since 14
344     */
345    iface: string;
346    /**
347     * Ethernet specific mac address.
348     * @type {string}
349     * @syscap SystemCapability.Communication.NetManager.Ethernet
350     * @since 14
351     */
352    macAddress: string;
353  }
354
355  /**
356   * Defines the device information of the Ethernet.
357   * @interface EthernetDeviceInfos
358   * @syscap SystemCapability.Communication.NetManager.Ethernet
359   * @systemapi Hide this for inner system use.
360   * @since 20
361   */
362  export interface EthernetDeviceInfos {
363    /**
364     * Ethernet interface name.
365     * @type { string }
366     * @syscap SystemCapability.Communication.NetManager.Ethernet
367     * @systemapi Hide this for inner system use.
368     * @since 20
369     */
370    ifaceName: string;
371
372    /**
373     * Ethernet device name.
374     * @type { string }
375     * @syscap SystemCapability.Communication.NetManager.Ethernet
376     * @systemapi Hide this for inner system use.
377     * @since 20
378     */
379    deviceName: string;
380
381    /**
382     * Device connection mode.
383     * @type { DeviceConnectionType }
384     * @syscap SystemCapability.Communication.NetManager.Ethernet
385     * @systemapi Hide this for inner system use.
386     * @since 20
387     */
388    connectionMode: DeviceConnectionType;
389
390    /**
391     * Supplier name of device.
392     * @type { string }
393     * @syscap SystemCapability.Communication.NetManager.Ethernet
394     * @systemapi Hide this for inner system use.
395     * @since 20
396     */
397    supplierName: string;
398
399    /**
400     * Supplier id of device.
401     * @type { string }
402     * @syscap SystemCapability.Communication.NetManager.Ethernet
403     * @systemapi Hide this for inner system use.
404     * @since 20
405     */
406    supplierId: string;
407
408    /**
409     * Product name of device.
410     * @type { string }
411     * @syscap SystemCapability.Communication.NetManager.Ethernet
412     * @systemapi Hide this for inner system use.
413     * @since 20
414     */
415    productName: string;
416
417    /**
418     * Maximum Rate of device.
419     * @type { string }
420     * @syscap SystemCapability.Communication.NetManager.Ethernet
421     * @systemapi Hide this for inner system use.
422     * @since 20
423     */
424    maximumRate: string;
425  }
426
427  /**
428   * Defines the Device Connection Mode of the Ethernet.
429   * @enum {number}
430   * @syscap SystemCapability.Communication.NetManager.Ethernet
431   * @systemapi Hide this for inner system use.
432   * @since 20
433   */
434  export enum DeviceConnectionType {
435    /**
436     * Ethernet in built-in mode.
437     * @syscap SystemCapability.Communication.NetManager.Ethernet
438     * @systemapi Hide this for inner system use.
439     * @since 20
440     */
441    BUILT_IN = 0,
442
443    /**
444     * Ethernet in external mode. For example, an ethernet connection via USB.
445     * @syscap SystemCapability.Communication.NetManager.Ethernet
446     * @systemapi Hide this for inner system use.
447     * @since 20
448     */
449    EXTERNAL = 1
450  }
451}
452
453export default ethernet;