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 NETMANAGER_EXT_ERR_PERMISSION_DENIED 32 * @throws {BusinessError} 2200105 NETMANAGER_EXT_ERR_LOCAL_PTR_NULL 33 * @throws {BusinessError} 2200202 NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL 34 * @throws {BusinessError} 2200204 NETMANAGER_EXT_ERR_WRITE_REPLY_FAIL 35 * @throws {BusinessError} 2200205 NETMANAGER_EXT_ERR_READ_DATA_FAIL 36 * @throws {BusinessError} 2200207 NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL 37 * @throws {BusinessError} 2201005 ETHERNET_ERR_DEVICE_INFORMATION_NOT_EXIST 38 */ 39 function getIfaceConfig(iface: string, callback: AsyncCallback<InterfaceConfiguration>): void; 40 function getIfaceConfig(iface: string): Promise<InterfaceConfiguration>; 41 42 /** 43 * Set the specified network interface parameters. 44 * 45 * @param iface Indicates the network interface name of the network parameter. 46 * @param ic Indicates the ic. See {@link InterfaceConfiguration}. 47 * @permission ohos.permission.CONNECTIVITY_INTERNAL 48 * @systemapi Hide this for inner system use. 49 * @throws {BusinessError} 201 NETMANAGER_EXT_ERR_PERMISSION_DENIED 50 * @throws {BusinessError} 2200105 NETMANAGER_EXT_ERR_LOCAL_PTR_NULL 51 * @throws {BusinessError} 2200202 NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL 52 * @throws {BusinessError} 2200205 NETMANAGER_EXT_ERR_READ_DATA_FAIL 53 * @throws {BusinessError} 2200207 NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL 54 * @throws {BusinessError} 2201004 ETHERNET_ERR_DEVICE_CONFIGURATION_INVALID 55 * @throws {BusinessError} 2201005 ETHERNET_ERR_DEVICE_INFORMATION_NOT_EXIST 56 * @throws {BusinessError} 2201006 ETHERNET_ERR_DEVICE_NOT_LINK 57 * @throws {BusinessError} 2201007 ETHERNET_ERR_USER_CONIFGURATION_WRITE_FAIL 58 */ 59 function setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback<void>): void; 60 function setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise<void>; 61 62 /** 63 * Check whether the specified network is active. 64 * 65 * @param iface Indicates the network interface name. 66 * @permission ohos.permission.GET_NETWORK_INFO 67 * @systemapi Hide this for inner system use. 68 * @throws {BusinessError} 201 NETMANAGER_EXT_ERR_PERMISSION_DENIED 69 * @throws {BusinessError} 2200105 NETMANAGER_EXT_ERR_LOCAL_PTR_NULL 70 * @throws {BusinessError} 2200202 NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL 71 * @throws {BusinessError} 2200204 NETMANAGER_EXT_ERR_WRITE_REPLY_FAIL 72 * @throws {BusinessError} 2200205 NETMANAGER_EXT_ERR_READ_DATA_FAIL 73 * @throws {BusinessError} 2200207 NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL 74 * @throws {BusinessError} 2201005 ETHERNET_ERR_DEVICE_INFORMATION_NOT_EXIST 75 */ 76 function isIfaceActive(iface?: string, callback: AsyncCallback<number>): void; 77 function isIfaceActive(iface?: string): Promise<number>; 78 79 /** 80 * Gets the names of all active network interfaces. 81 * 82 * @permission ohos.permission.GET_NETWORK_INFO 83 * @systemapi Hide this for inner system use. 84 * @throws {BusinessError} 201 NETMANAGER_EXT_ERR_PERMISSION_DENIED 85 * @throws {BusinessError} 2200105 NETMANAGER_EXT_ERR_LOCAL_PTR_NULL 86 * @throws {BusinessError} 2200202 NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL 87 * @throws {BusinessError} 2200204 NETMANAGER_EXT_ERR_WRITE_REPLY_FAIL 88 * @throws {BusinessError} 2200205 NETMANAGER_EXT_ERR_READ_DATA_FAIL 89 * @throws {BusinessError} 2200207 NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL 90 */ 91 function getAllActiveIfaces(callback: AsyncCallback<Array<string>>): void; 92 function getAllActiveIfaces(): Promise<Array<string>>; 93 94 /** 95 * @systemapi Hide this for inner system use. 96 */ 97 export interface InterfaceConfiguration { 98 /*See {@link IPSetMode}*/ 99 mode: IPSetMode; 100 ipAddr: string; 101 route: string; 102 gateway: string; 103 netMask: string; 104 dnsServers: string; 105 domain: string; 106 } 107 108 /** 109 * @systemapi Hide this for inner system use. 110 */ 111 export enum IPSetMode { 112 STATIC = 0, 113 DHCP = 1 114 } 115} 116 117export default ethernet; 118