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 } 202 - Non-system applications use system APIs.
208   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
209   * @throws { BusinessError } 2201005 - Device information does not exist.
210   * @syscap SystemCapability.Communication.NetManager.Ethernet
211   * @systemapi Hide this for inner system use.
212   * @since 13
213   */
214  function getMacAddress(): Promise<Array<MacAddressInfo>>;
215
216  /**
217   * Defines the network configuration for the Ethernet connection.
218   * @interface InterfaceConfiguration
219   * @syscap SystemCapability.Communication.NetManager.Ethernet
220   * @systemapi Hide this for inner system use.
221   * @since 9
222   */
223  export interface InterfaceConfiguration {
224    /**
225     * @type {IPSetMode}
226     * See {@link IPSetMode}
227     * @syscap SystemCapability.Communication.NetManager.Ethernet
228     * @systemapi Hide this for inner system use.
229     * @since 9
230     */
231    mode: IPSetMode;
232    /**
233     * Ethernet connection static configuration IP 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    ipAddr: string;
242
243    /**
244     * Ethernet connection static configuration route 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    route: string;
253
254    /**
255     * Ethernet connection static configuration gateway 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    gateway: string;
264
265    /**
266     * Ethernet connection static configuration netMask 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    netMask: string;
275
276    /**
277     * The Ethernet connection is configured with the dns service address.
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, Multiple addresses are separated by ",")
280     * @type {string}
281     * @syscap SystemCapability.Communication.NetManager.Ethernet
282     * @systemapi Hide this for inner system use.
283     * @since 9
284     */
285    dnsServers: string;
286
287    /**
288     * Indicates the HttpProxy settings, Default does not use HttpProxy.
289     * @type {?HttpProxy}
290     * @syscap SystemCapability.Communication.NetManager.Ethernet
291     * @since 10
292     */
293    httpProxy?: HttpProxy;
294  }
295
296  /**
297   * Defines the configuration mode of the Ethernet connection.
298   * @enum {number}
299   * @syscap SystemCapability.Communication.NetManager.Ethernet
300   * @systemapi Hide this for inner system use.
301   * @since 9
302   */
303  export enum IPSetMode {
304    /**
305     * Static configuration.
306     * @syscap SystemCapability.Communication.NetManager.Ethernet
307     * @systemapi Hide this for inner system use.
308     * @since 9
309     */
310    STATIC = 0,
311
312    /**
313     * Dynamic configuration.
314     * @syscap SystemCapability.Communication.NetManager.Ethernet
315     * @systemapi Hide this for inner system use.
316     * @since 9
317     */
318    DHCP = 1
319  }
320
321  /**
322   * Defines the mac address info of the Ethernet.
323   * @interface MacAddressInfo
324   * @syscap SystemCapability.Communication.NetManager.Ethernet
325   * @systemapi Hide this for inner system use.
326   * @since 13
327   */
328  export interface MacAddressInfo {
329    /**
330     * Ethernet interface name.
331     * @type {string}
332     * @syscap SystemCapability.Communication.NetManager.Ethernet
333     * @systemapi Hide this for inner system use.
334     * @since 13
335     */
336    iface: string;
337    /**
338     * Ethernet specific mac address.
339     * @type {string}
340     * @syscap SystemCapability.Communication.NetManager.Ethernet
341     * @systemapi Hide this for inner system use.
342     * @since 13
343     */
344    macAddress: string;
345  }
346}
347
348export default ethernet;