• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 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 } from "./basic";
17
18/**
19 * Provides methods to operate or manage Wi-Fi.
20 *
21 * @SysCap SystemCapability.Communication.WifiDevice
22 * @devices phone, tablet
23 * @since 6
24 */
25declare namespace wifi {
26    /**
27     * Enables Wi-Fi.
28     *
29     * @return Returns {@code true} if the operation is successful; returns {@code false} otherwise.
30     *
31     * @since 6
32     * @hide SystemApi
33     */
34    function enableWifi(): boolean;
35
36    /**
37     * Disables Wi-Fi.
38     *
39     * @return Returns {@code true} if the operation is successful; returns {@code false} otherwise.
40     *
41     * @since 6
42     * @hide SystemApi
43     */
44    function disableWifi(): boolean;
45
46    /**
47     * Queries the Wi-Fi status
48     *
49     * @return Returns {@code true} if the Wi-Fi is active; returns {@code false} otherwise.
50     *
51     * @since 6
52     */
53    function isWifiActive(): boolean;
54
55    /**
56     * Scans Wi-Fi hotspots with parameters.
57     *
58     * <p>This API works in asynchronous mode.</p>
59     *
60     * @return Returns {@code true} if the scanning is successful; returns {@code false} otherwise.
61     *
62     * @since 6
63     */
64    function scan(): boolean;
65
66    /**
67     * Obtains the hotspot information that scanned.
68     *
69     * @return Returns information about scanned Wi-Fi hotspots if any.
70     *
71     * @since 6
72     */
73    function getScanInfos(): Promise<Array<WifiScanInfo>>;
74    function getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void;
75
76    /**
77     * Adds Wi-Fi connection configuration to the device.
78     *
79     * <p>The configuration will be updated when the configuration is added.</p>
80     *
81     * @return Returns {@code networkId} if the configuration is added; returns {@code -1} otherwise.
82     *
83     * @devices phone, tablet
84     * @since 6
85     * @hide SystemApi
86     */
87    function addDeviceConfig(config: WifiDeviceConfig): Promise<number>;
88    function addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void;
89
90    /**
91     * Connects to Wi-Fi network.
92     *
93     * @param networkId ID of the connected network.
94     * @return Returns {@code true} if the network connection is successful; returns {@code false} otherwise.
95     *
96     * @since 6
97     * @hide SystemApi
98     */
99    function connectToNetwork(networkId: number): boolean;
100
101    /**
102     * Connects to Wi-Fi network.
103     *
104     * @param config Indicates the device configuration for connection to the Wi-Fi network.
105     * @return Returns {@code true} if the network connection is successful; returns {@code false} otherwise.
106     *
107     * @devices phone, tablet
108     * @since 6
109     * @hide SystemApi
110     */
111    function connectToDevice(config: WifiDeviceConfig): boolean;
112
113    /**
114     * Disconnects Wi-Fi network.
115     *
116     * @return Returns {@code true} for disconnecting network success, returns {@code false} otherwise.
117     *
118     * @since 6
119     * @hide SystemApi
120     */
121    function disconnect(): boolean;
122
123    /**
124     * Calculates the Wi-Fi signal level based on the Wi-Fi RSSI and frequency band.
125     *
126     * @param rssi Indicates the Wi-Fi RSSI.
127     * @band Indicates the Wi-Fi frequency band.
128     * @return Returns Wi-Fi signal level ranging from 0 to 4.
129     *
130     * @since 6
131     */
132    function getSignalLevel(rssi: number, band: number): number;
133
134    /**
135     * Wi-Fi device configuration information.
136     *
137     * @devices phone, tablet
138     * @since 6
139     * @hide SystemApi
140     */
141    interface WifiDeviceConfig {
142        /** Wi-Fi SSID: the maximum length is 32 */
143        ssid: string;
144
145        /** Wi-Fi bssid(MAC): the length is 6 */
146        bssid: string;
147
148        /** Wi-Fi key: maximum length is 64 */
149        preSharedKey: string;
150
151        /** Hide SSID or not, false(default): not hide */
152        isHiddenSsid: boolean;
153
154        /** Security type: reference definition of WifiSecurityType */
155        securityType: number;
156    }
157
158    /**
159     * Describes the scanned Wi-Fi information.
160     *
161     * @devices phone, tablet
162     * @since 6
163     */
164    interface WifiScanInfo {
165        /** Wi-Fi SSID: the maximum length is 32 */
166        ssid: string;
167
168        /** Wi-Fi bssid(MAC): the length is 6 */
169        bssid: string;
170
171        /** Security type: reference definition of WifiSecurityType */
172        securityType: number;
173
174        /** Received signal strength indicator (RSSI) */
175        rssi: number;
176
177        /** Frequency band */
178        band: number;
179
180        /** Frequency */
181        frequency: number;
182
183        /** Time stamp */
184        timestamp: number;
185    }
186
187    /**
188     * Describes the wifi security type.
189     *
190     * @devices phone, tablet
191     * @since 6
192     */
193    enum WifiSecurityType {
194        WIFI_SEC_TYPE_INVALID = 0, /* Invalid security type */
195        WIFI_SEC_TYPE_OPEN = 1, /* Open */
196        WIFI_SEC_TYPE_WEP = 2, /* Wired Equivalent Privacy (WEP) */
197        WIFI_SEC_TYPE_PSK = 3, /* Pre-shared key (PSK) */
198        WIFI_SEC_TYPE_SAE = 4, /* Simultaneous Authentication of Equals (SAE) */
199    }
200}
201
202export default wifi;
203