• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 "./basic";
17
18/**
19 * Provides interfaces to manage ethernet.
20 *
21 * @since 9
22 * @syscap SystemCapability.Communication.NetManager.Ethernet
23 */
24declare namespace ethernet {
25  /**
26   * Get the specified network interface information.
27   *
28   * @param iface Indicates the network interface name.
29   * @permission ohos.permission.GET_NETWORK_INFO
30   * @systemapi Hide this for inner system use.
31   * @throws {BusinessError} 201 - Permission denied.
32   * @throws {BusinessError} 401 - Parameter error.
33   * @throws {BusinessError} 2200001 - Invalid parameter value.
34   * @throws {BusinessError} 2200002 - Operation failed. Cannot connect to service.
35   * @throws {BusinessError} 2200003 - System internal error.
36   * @throws {BusinessError} 2201005 - Device information does not exist.
37   */
38  function getIfaceConfig(iface: string, callback: AsyncCallback<InterfaceConfiguration>): void;
39  function getIfaceConfig(iface: string): Promise<InterfaceConfiguration>;
40
41  /**
42   * Set the specified network interface parameters.
43   *
44   * @param iface Indicates the network interface name of the network parameter.
45   * @param ic Indicates the ic. See {@link InterfaceConfiguration}.
46   * @permission ohos.permission.CONNECTIVITY_INTERNAL
47   * @systemapi Hide this for inner system use.
48   * @throws {BusinessError} 201 - Permission denied.
49   * @throws {BusinessError} 401 - Parameter error.
50   * @throws {BusinessError} 2200001 - Invalid parameter value.
51   * @throws {BusinessError} 2200002 - Operation failed. Cannot connect to service.
52   * @throws {BusinessError} 2200003 - System internal error.
53   * @throws {BusinessError} 2201004 - Invalid Ethernet profile.
54   * @throws {BusinessError} 2201005 - Device information does not exist.
55   * @throws {BusinessError} 2201006 - Ethernet device not connected.
56   * @throws {BusinessError} 2201007 - Ethernet failed to write user configuration information.
57   */
58  function setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback<void>): void;
59  function setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise<void>;
60
61  /**
62   * Check whether the specified network is active.
63   *
64   * @param iface Indicates the network interface name.
65   * @permission ohos.permission.GET_NETWORK_INFO
66   * @systemapi Hide this for inner system use.
67   * @throws {BusinessError} 201 - Permission denied.
68   * @throws {BusinessError} 401 - Parameter error.
69   * @throws {BusinessError} 2200001 - Invalid parameter value.
70   * @throws {BusinessError} 2200002 - Operation failed. Cannot connect to service.
71   * @throws {BusinessError} 2200003 - System internal error.
72   * @throws {BusinessError} 2201005 - Device information does not exist.
73   */
74  function isIfaceActive(iface: string, callback: AsyncCallback<number>): void;
75  function isIfaceActive(iface: string): Promise<number>;
76
77  /**
78   * Gets the names of all active network interfaces.
79   *
80   * @permission ohos.permission.GET_NETWORK_INFO
81   * @systemapi Hide this for inner system use.
82   * @throws {BusinessError} 201 - Permission denied.
83   * @throws {BusinessError} 2200002 - Operation failed. Cannot connect to service.
84   * @throws {BusinessError} 2200003 - System internal error.
85   */
86  function getAllActiveIfaces(callback: AsyncCallback<Array<string>>): void;
87  function getAllActiveIfaces(): Promise<Array<string>>;
88
89  /**
90   * @systemapi Hide this for inner system use.
91   */
92  export interface InterfaceConfiguration {
93    /**
94     * See {@link IPSetMode}
95     */
96    mode: IPSetMode;
97   /**
98     * Ethernet connection static configuration IP information.
99     * The address value range is 0-255.0-255.0-255.0-255.0-255
100     * (DHCP mode does not need to be configured)
101     */
102    ipAddr: string;
103
104    /**
105     * Ethernet connection static configuration route information.
106     * The address value range is 0-255.0-255.0-255.0-255.0-255
107     * (DHCP mode does not need to be configured)
108     */
109    route: string;
110
111    /**
112     * Ethernet connection static configuration gateway information.
113     * The address value range is 0-255.0-255.0-255.0-255.0-255
114     * (DHCP mode does not need to be configured)
115     */
116    gateway: string;
117
118    /**
119     * Ethernet connection static configuration netMask information.
120     * The address value range is 0-255.0-255.0-255.0-255.0-255
121     * (DHCP mode does not need to be configured)
122     */
123    netMask: string;
124
125    /**
126     * The Ethernet connection is configured with the dns service address.
127     * The address value range is 0-255.0-255.0-255.0-255.0-255
128     * (DHCP mode does not need to be configured, Multiple addresses are separated by ",")
129     */
130    dnsServers: string;
131  }
132
133  /**
134   * @systemapi Hide this for inner system use.
135   */
136  export enum IPSetMode {
137    STATIC = 0,
138    DHCP = 1
139  }
140}
141
142export default ethernet;
143