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   * 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   * Get the ethernet mac address list.
203   * @permission ohos.permission.GET_ETHERNET_LOCAL_MAC
204   * @returns { Promise<Array<MacAddressInfo>> } the promise returned by the function.
205   * @throws { BusinessError } 201 - Permission denied.
206   * @throws { BusinessError } 2200002 - Operation failed. Cannot connect to service.
207   * @throws { BusinessError } 2201005 - Device information does not exist.
208   * @syscap SystemCapability.Communication.NetManager.Ethernet
209   * @since 13
210   */
211  function getMacAddress(): Promise<Array<MacAddressInfo>>;
212
213  /**
214   * Defines the network configuration for the Ethernet connection.
215   * @interface InterfaceConfiguration
216   * @syscap SystemCapability.Communication.NetManager.Ethernet
217   * @systemapi Hide this for inner system use.
218   * @since 9
219   */
220  export interface InterfaceConfiguration {
221    /**
222     * @type {IPSetMode}
223     * See {@link IPSetMode}
224     * @syscap SystemCapability.Communication.NetManager.Ethernet
225     * @systemapi Hide this for inner system use.
226     * @since 9
227     */
228    mode: IPSetMode;
229    /**
230     * Ethernet connection static configuration IP information.
231     * The address value range is 0-255.0-255.0-255.0-255.0-255
232     * (DHCP mode does not need to be configured)
233     * @type {string}
234     * @syscap SystemCapability.Communication.NetManager.Ethernet
235     * @systemapi Hide this for inner system use.
236     * @since 9
237     */
238    ipAddr: string;
239
240    /**
241     * Ethernet connection static configuration route information.
242     * The address value range is 0-255.0-255.0-255.0-255.0-255
243     * (DHCP mode does not need to be configured)
244     * @type {string}
245     * @syscap SystemCapability.Communication.NetManager.Ethernet
246     * @systemapi Hide this for inner system use.
247     * @since 9
248     */
249    route: string;
250
251    /**
252     * Ethernet connection static configuration gateway information.
253     * The address value range is 0-255.0-255.0-255.0-255.0-255
254     * (DHCP mode does not need to be configured)
255     * @type {string}
256     * @syscap SystemCapability.Communication.NetManager.Ethernet
257     * @systemapi Hide this for inner system use.
258     * @since 9
259     */
260    gateway: string;
261
262    /**
263     * Ethernet connection static configuration netMask information.
264     * The address value range is 0-255.0-255.0-255.0-255.0-255
265     * (DHCP mode does not need to be configured)
266     * @type {string}
267     * @syscap SystemCapability.Communication.NetManager.Ethernet
268     * @systemapi Hide this for inner system use.
269     * @since 9
270     */
271    netMask: string;
272
273    /**
274     * The Ethernet connection is configured with the dns service address.
275     * The address value range is 0-255.0-255.0-255.0-255.0-255
276     * (DHCP mode does not need to be configured, Multiple addresses are separated by ",")
277     * @type {string}
278     * @syscap SystemCapability.Communication.NetManager.Ethernet
279     * @systemapi Hide this for inner system use.
280     * @since 9
281     */
282    dnsServers: string;
283
284    /**
285     * Indicates the HttpProxy settings, Default does not use HttpProxy.
286     * @type {?HttpProxy}
287     * @syscap SystemCapability.Communication.NetManager.Ethernet
288     * @since 10
289     */
290    httpProxy?: HttpProxy;
291  }
292
293  /**
294   * Defines the configuration mode of the Ethernet connection.
295   * @enum {number}
296   * @syscap SystemCapability.Communication.NetManager.Ethernet
297   * @systemapi Hide this for inner system use.
298   * @since 9
299   */
300  export enum IPSetMode {
301    /**
302     * Static configuration.
303     * @syscap SystemCapability.Communication.NetManager.Ethernet
304     * @systemapi Hide this for inner system use.
305     * @since 9
306     */
307    STATIC = 0,
308
309    /**
310     * Dynamic configuration.
311     * @syscap SystemCapability.Communication.NetManager.Ethernet
312     * @systemapi Hide this for inner system use.
313     * @since 9
314     */
315    DHCP = 1
316  }
317
318  /**
319   * Defines the mac address info of the Ethernet.
320   * @interface MacAddressInfo
321   * @syscap SystemCapability.Communication.NetManager.Ethernet
322   * @systemapi Hide this for inner system use.
323   * @since 13
324   */
325  export interface MacAddressInfo {
326    /**
327     * Ethernet interface name.
328     * @type {string}
329     * @syscap SystemCapability.Communication.NetManager.Ethernet
330     * @systemapi Hide this for inner system use.
331     * @since 13
332     */
333    iface: string;
334    /**
335     * Ethernet specific mac address.
336     * @type {string}
337     * @syscap SystemCapability.Communication.NetManager.Ethernet
338     * @systemapi Hide this for inner system use.
339     * @since 13
340     */
341    macAddress: string;
342  }
343}
344
345export default ethernet;