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