• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-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 methods to operate or manage Wi-Fi.
20 *
21 * @since 6
22 * @import import wifi from '@ohos.wifi';
23 */
24declare namespace wifi {
25    /**
26     * Enables Wi-Fi.
27     *
28     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
29     *
30     * @since 6
31     * @syscap SystemCapability.Communication.WiFi.STA
32     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
33     * @systemapi Hide this for inner system use.
34     */
35    function enableWifi(): boolean;
36
37    /**
38     * Disables Wi-Fi.
39     *
40     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
41     *
42     * @since 6
43     * @syscap SystemCapability.Communication.WiFi.STA
44     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
45     * @systemapi Hide this for inner system use.
46     */
47    function disableWifi(): boolean;
48
49    /**
50     * Queries the Wi-Fi status
51     *
52     * @return Returns {@code true} if the Wi-Fi is active, returns {@code false} otherwise.
53     *
54     * @since 6
55     * @syscap SystemCapability.Communication.WiFi.STA
56     * @permission ohos.permission.GET_WIFI_INFO
57     */
58    function isWifiActive(): boolean;
59
60    /**
61     * Scans Wi-Fi hotspots.
62     *
63     * <p>This API works in asynchronous mode.</p>
64     *
65     * @return Returns {@code true} if the scanning is successful, returns {@code false} otherwise.
66     *
67     * @since 6
68     * @syscap SystemCapability.Communication.WiFi.STA
69     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.LOCATION
70     */
71    function scan(): boolean;
72
73    /**
74     * Obtains the hotspot information that scanned.
75     *
76     * @return Returns information about scanned Wi-Fi hotspots if any.
77     *
78     * @since 6
79     * @syscap SystemCapability.Communication.WiFi.STA
80     * @permission ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or ohos.permission.LOCATION)
81     */
82    function getScanInfos(): Promise<Array<WifiScanInfo>>;
83    function getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void;
84
85    /**
86     * Adds Wi-Fi connection configuration to the device.
87     *
88     * <p>The configuration will be updated when the configuration is added.</p>
89     *
90     * @param config Indicates the device configuration for connection to the Wi-Fi network.
91     * @return Returns {@code networkId} if the configuration is added; returns {@code -1} otherwise.
92     *
93     * @since 6
94     * @syscap SystemCapability.Communication.WiFi.STA
95     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG
96     * @systemapi Hide this for inner system use.
97     */
98    function addDeviceConfig(config: WifiDeviceConfig): Promise<number>;
99    function addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void;
100
101    /**
102     * Adds a specified untrusted hotspot configuration.
103     *
104     * <p>This method adds one configuration at a time. After this configuration is added,
105     *     your device will determine whether to connect to the hotspot.
106     *
107     * @return Returns {@code true} if the untrusted hotspot configuration is added, returns {@code false} otherwise.
108     * @since 7
109     * @syscap SystemCapability.Communication.WiFi.STA
110     * @permission ohos.permission.SET_WIFI_INFO
111     */
112     function addUntrustedConfig(config: WifiDeviceConfig): Promise<boolean>;
113     function addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boolean>): void;
114
115     /**
116      * Removes a specified untrusted hotspot configuration.
117      *
118      * <p>This method removes one configuration at a time.
119      *
120      * @return Returns {@code true} if the untrusted hotspot configuration is removed, returns {@code false} otherwise.
121      * @since 7
122      * @syscap SystemCapability.Communication.WiFi.STA
123      * @permission ohos.permission.SET_WIFI_INFO
124      */
125     function removeUntrustedConfig(config: WifiDeviceConfig): Promise<boolean>;
126     function removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback<boolean>): void;
127
128    /**
129     * Connects to Wi-Fi network.
130     *
131     * @param networkId ID of the connected network.
132     * @return Returns {@code true} if the network connection is successful, returns {@code false} otherwise.
133     *
134     * @since 6
135     * @syscap SystemCapability.Communication.WiFi.STA
136     * @permission ohos.permission.MANAGE_WIFI_CONNECTION
137     * @systemapi Hide this for inner system use.
138     */
139    function connectToNetwork(networkId: number): boolean;
140
141    /**
142     * Connects to Wi-Fi network.
143     *
144     * @param config Indicates the device configuration for connection to the Wi-Fi network.
145     * @return Returns {@code true} if the network connection is successful, returns {@code false} otherwise.
146     *
147     * @since 6
148     * @syscap SystemCapability.Communication.WiFi.STA
149     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG and
150     * ohos.permission.MANAGE_WIFI_CONNECTION
151     * @systemapi Hide this for inner system use.
152     */
153    function connectToDevice(config: WifiDeviceConfig): boolean;
154
155    /**
156     * Disconnects Wi-Fi network.
157     *
158     * @return Returns {@code true} for disconnecting network success, returns {@code false} otherwise.
159     *
160     * @since 6
161     * @syscap SystemCapability.Communication.WiFi.STA
162     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
163     * @systemapi Hide this for inner system use.
164     */
165    function disconnect(): boolean;
166
167    /**
168     * Calculates the Wi-Fi signal level based on the Wi-Fi RSSI and frequency band.
169     *
170     * @param rssi Indicates the Wi-Fi RSSI.
171     * @band Indicates the Wi-Fi frequency band.
172     * @return Returns Wi-Fi signal level ranging from 0 to 4.
173     *
174     * @since 6
175     * @syscap SystemCapability.Communication.WiFi.STA
176     * @permission ohos.permission.GET_WIFI_INFO
177     */
178    function getSignalLevel(rssi: number, band: number): number;
179
180    /**
181     * Obtains information about a Wi-Fi connection.
182     *
183     * @return Returns the Wi-Fi connection information.
184     * @since 6
185     * @syscap SystemCapability.Communication.WiFi.STA
186     * @permission ohos.permission.GET_WIFI_INFO
187     */
188    function getLinkedInfo(): Promise<WifiLinkedInfo>;
189    function getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void;
190
191    /**
192     * Checks whether a Wi-Fi connection has been set up.
193     *
194     * @return Returns {@code true} if a Wi-Fi connection has been set up, returns {@code false} otherwise.
195     * @since 7
196     * @syscap SystemCapability.Communication.WiFi.STA
197     * @permission ohos.permission.GET_WIFI_INFO
198     */
199    function isConnected(): boolean;
200
201    /**
202     * Obtains the features supported by this device.
203     *
204     * <p>To check whether this device supports a specified feature.
205     *
206     * @return Returns the features supported by this device.
207     * @since 7
208     * @syscap SystemCapability.Communication.WiFi.Core
209     * @permission ohos.permission.GET_WIFI_INFO
210     * @systemapi Hide this for inner system use.
211     */
212    function getSupportedFeatures(): number;
213
214    /**
215     * Checks whether this device supports a specified feature.
216     *
217     * @param featureId Indicates the ID of the feature.
218     * @return Returns {@code true} if this device supports the specified feature, returns {@code false} otherwise.
219     * @since 7
220     * @syscap SystemCapability.Communication.WiFi.Core
221     * @permission ohos.permission.GET_WIFI_INFO
222     */
223    function isFeatureSupported(featureId: number): boolean;
224
225    /**
226     * Obtains the MAC address of a Wi-Fi device. Wi-Fi must be enabled.
227     *
228     * <p>The MAC address is unique and cannot be changed.
229     *
230     * @return Returns the MAC address of the Wi-Fi device.
231     * @since 7
232     * @syscap SystemCapability.Communication.WiFi.STA
233     * @permission ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO
234     * @systemapi Hide this for inner system use.
235     */
236    function getDeviceMacAddress(): string[];
237
238    /**
239     * Obtains the IP information of a Wi-Fi connection.
240     *
241     * <p>The IP information includes the host IP address, gateway address, and DNS information.
242     *
243     * @return Returns the IP information of the Wi-Fi connection.
244     * @since 7
245     * @syscap SystemCapability.Communication.WiFi.STA
246     * @permission ohos.permission.GET_WIFI_INFO
247     */
248    function getIpInfo(): IpInfo;
249
250    /**
251     * Obtains the country code of this device.
252     *
253     * @return Returns the country code of this device.
254     * @since 7
255     * @syscap SystemCapability.Communication.WiFi.Core
256     * @permission ohos.permission.GET_WIFI_INFO
257     */
258    function getCountryCode(): string;
259
260    /**
261     * Re-associates to current network.
262     *
263     * @return {@code true} if the Wi-Fi network is re-associate successfully.
264     * @since 7
265     * @syscap SystemCapability.Communication.WiFi.STA
266     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
267     * @systemapi Hide this for inner system use.
268     */
269    function reassociate(): boolean;
270
271    /**
272     * Re-connects to current network.
273     *
274     * @return {@code true} if the Wi-Fi network is re-connect successfully.
275     * @since 7
276     * @syscap SystemCapability.Communication.WiFi.STA
277     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
278     * @systemapi Hide this for inner system use.
279     */
280    function reconnect(): boolean;
281
282    /**
283     * Obtains the list of all existing Wi-Fi configurations.
284     *
285     * <p>You can obtain only the Wi-Fi configurations you created on your own application.
286     *
287     * @return Returns the list of all existing Wi-Fi configurations you created on your application.
288     * @since 7
289     * @syscap SystemCapability.Communication.WiFi.STA
290     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION and ohos.permission.GET_WIFI_CONFIG
291     * @systemapi Hide this for inner system use.
292     */
293    function getDeviceConfigs(): Array<WifiDeviceConfig>;
294
295    /**
296     * Updates the specified Wi-Fi configuration.
297     *
298     * @param config Indicates the Wi-Fi configuration to update.
299     *
300     * @return Returns the network ID in the updated Wi-Fi configuration if the update is successful;
301     *     returns {@code -1} if the specified Wi-Fi configuration is not contained in the list.
302     * @since 7
303     * @syscap SystemCapability.Communication.WiFi.STA
304     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG
305     * @systemapi Hide this for inner system use.
306     */
307    function updateNetwork(config: WifiDeviceConfig): number;
308
309    /**
310     * Disables a specified network.
311     *
312     * <p>The disabled network will not be associated with again.
313     *
314     * @param netId Identifies the network to disable.
315     * @return Returns {@code true} if the specified network is disabled, returns {@code false} otherwise.
316     * @since 7
317     * @syscap SystemCapability.Communication.WiFi.STA
318     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
319     * @systemapi Hide this for inner system use.
320     */
321    function disableNetwork(netId: number): boolean;
322
323    /**
324     * Removes all the saved Wi-Fi configurations.
325     *
326     * @return Returns {@code true} if all the saved Wi-Fi configurations are removed;
327     *     returns {@code false} otherwise.
328     * @since 7
329     * @syscap SystemCapability.Communication.WiFi.STA
330     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
331     * @systemapi Hide this for inner system use.
332     */
333    function removeAllNetwork(): boolean;
334
335    /**
336     * Deletes a Wi-Fi network with a specified ID.
337     *
338     * <p>After a Wi-Fi network is deleted, its configuration will be deleted from the list of Wi-Fi configurations.
339     * If the Wi-Fi network is being connected, the connection will be interrupted.
340     * The application can only delete Wi-Fi networks it has created.
341     *
342     * @param id Indicates the ID of the Wi-Fi network,
343     *     which can be obtained using the {@link #addDeviceConfig} or {@link #getLinkedInfo} method.
344     * @return Returns {@code true} if the Wi-Fi network is deleted successfully, returns {@code false} otherwise.
345     * @since 7
346     * @syscap SystemCapability.Communication.WiFi.STA
347     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
348     * @systemapi Hide this for inner system use.
349     */
350    function removeDevice(id: number): boolean;
351
352    /**
353     * Enables a Wi-Fi hotspot.
354     *
355     * <p>This method is asynchronous. After the Wi-Fi hotspot is enabled, Wi-Fi may be disabled.
356     *
357     * @return Returns {@code true} if this method is called successfully, returns {@code false} otherwise.
358     * @since 7
359     * @syscap SystemCapability.Communication.WiFi.AP.Core
360     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
361     * @systemapi Hide this for inner system use.
362     */
363    function enableHotspot(): boolean;
364
365    /**
366     * Disables a Wi-Fi hotspot.
367     *
368     * <p>This method is asynchronous. If Wi-Fi is enabled after the Wi-Fi hotspot is disabled, Wi-Fi may be re-enabled.
369     *
370     * @return Returns {@code true} if this method is called successfully, returns {@code false} otherwise.
371     * @since 7
372     * @syscap SystemCapability.Communication.WiFi.AP.Core
373     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
374     * @systemapi Hide this for inner system use.
375     */
376    function disableHotspot(): boolean;
377
378    /**
379     * Checks whether a device serving as a Wi-Fi hotspot supports both the 2.4 GHz and 5 GHz Wi-Fi.
380     *
381     * @return Returns {@code true} if the method is called successfully, returns {@code false} otherwise.
382     * @since 7
383     * @syscap SystemCapability.Communication.WiFi.AP.Core
384     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT
385     * @systemapi Hide this for inner system use.
386     */
387     function isHotspotDualBandSupported(): boolean;
388
389    /**
390     * Checks whether Wi-Fi hotspot is active on a device.
391     *
392     * @return Returns {@code true} if Wi-Fi hotspot is enabled, returns {@code false} otherwise.
393     * @since 7
394     * @syscap SystemCapability.Communication.WiFi.AP.Core
395     * @permission ohos.permission.GET_WIFI_INFO
396     * @systemapi Hide this for inner system use.
397     */
398    function isHotspotActive(): boolean;
399
400    /**
401     * Sets the hotspot for a device.
402     *
403     * <p>Only OPEN and WPA2 PSK hotspots can be configured.
404     *
405     * @param config Indicates the Wi-Fi hotspot configuration.
406     *     The SSID and {@code securityType} must be available and correct.
407     *     If {@code securityType} is not {@code open}, {@code preSharedKey} must be available and correct.
408     * @return Returns {@code true} if the method is called successfully, returns {@code false} otherwise.
409     * @since 7
410     * @syscap SystemCapability.Communication.WiFi.AP.Core
411     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
412     * @systemapi Hide this for inner system use.
413     */
414    function setHotspotConfig(config: HotspotConfig): boolean;
415
416    /**
417     * Obtains the Wi-Fi hotspot configuration.
418     *
419     * @return Returns the configuration of an existing or enabled Wi-Fi hotspot.
420     * @since 7
421     * @syscap SystemCapability.Communication.WiFi.AP.Core
422     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
423     * @systemapi Hide this for inner system use.
424     */
425    function getHotspotConfig(): HotspotConfig;
426
427    /**
428     * Obtains the list of clients that are connected to a Wi-Fi hotspot.
429     *
430     * <p>This method can only be used on a device that serves as a Wi-Fi hotspot.
431     *
432     * @return Returns the list of clients that are connected to the Wi-Fi hotspot.
433     * @since 7
434     * @syscap SystemCapability.Communication.WiFi.AP.Core
435     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION and ohos.permission.MANAGE_WIFI_HOTSPOT
436     * @systemapi Hide this for inner system use.
437     */
438    function getStations(): Array<StationInfo>;
439
440    /**
441     * Obtains information about a P2P connection.
442     *
443     * @return Returns the P2P connection information.
444     * @since 8
445     * @syscap SystemCapability.Communication.WiFi.P2P
446     * @permission ohos.permission.GET_WIFI_INFO
447     */
448    function getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo>;
449    function getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void;
450
451    /**
452     * Obtains information about the current group.
453     *
454     * @return Returns the current group information.
455     * @since 8
456     * @syscap SystemCapability.Communication.WiFi.P2P
457     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
458     */
459    function getCurrentGroup(): Promise<WifiP2pGroupInfo>;
460    function getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void;
461
462    /**
463     * Obtains the information about the found devices.
464     *
465     * @return Returns the found devices list.
466     * @since 8
467     * @syscap SystemCapability.Communication.WiFi.P2P
468     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
469     */
470    function getP2pPeerDevices(): Promise<WifiP2pDevice[]>;
471    function getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void;
472
473    /**
474     * Creates a P2P group.
475     *
476     * @param config Indicates the configuration for creating a group.
477     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
478     * @since 8
479     * @syscap SystemCapability.Communication.WiFi.P2P
480     * @permission ohos.permission.GET_WIFI_INFO
481     */
482    function createGroup(config: WifiP2PConfig): boolean;
483
484    /**
485     * Removes a P2P group.
486     *
487     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
488     * @since 8
489     * @syscap SystemCapability.Communication.WiFi.P2P
490     * @permission ohos.permission.GET_WIFI_INFO
491     */
492    function removeGroup(): boolean;
493
494    /**
495     * Initiates a P2P connection to a device with the specified configuration.
496     *
497     * @param config Indicates the configuration for connecting to a specific group.
498     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
499     * @since 8
500     * @syscap SystemCapability.Communication.WiFi.P2P
501     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
502     */
503    function p2pConnect(config: WifiP2PConfig): boolean;
504
505    /**
506     * Canceling a P2P connection.
507     *
508     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
509     * @since 8
510     * @syscap SystemCapability.Communication.WiFi.P2P
511     * @permission ohos.permission.GET_WIFI_INFO
512     */
513    function p2pCancelConnect(): boolean;
514
515    /**
516     * Discovers Wi-Fi P2P devices.
517     *
518     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
519     * @since 8
520     * @syscap SystemCapability.Communication.WiFi.P2P
521     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
522     */
523    function startDiscoverDevices(): boolean;
524
525    /**
526     * Stops discovering Wi-Fi P2P devices.
527     *
528     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
529     * @since 8
530     * @syscap SystemCapability.Communication.WiFi.P2P
531     * @permission ohos.permission.GET_WIFI_INFO
532     */
533    function stopDiscoverDevices(): boolean;
534
535    /**
536     * Deletes the persistent P2P group with the specified network ID.
537     *
538     * @param netId Indicates the network ID of the group to be deleted.
539     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
540     * @since 8
541     * @syscap SystemCapability.Communication.WiFi.P2P
542     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
543     * @systemapi Hide this for inner system use.
544     */
545    function deletePersistentGroup(netId: number): boolean;
546
547    /**
548     * Sets the name of the Wi-Fi P2P device.
549     *
550     * @param devName Indicates the name to be set.
551     * @return Returns {@code true} if the operation is successful, returns {@code false} otherwise.
552     * @since 8
553     * @syscap SystemCapability.Communication.WiFi.P2P
554     * @permission ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
555     * @systemapi Hide this for inner system use.
556     */
557    function setDeviceName(devName: string): boolean;
558
559    /**
560     * Subscribe Wi-Fi status change events.
561     *
562     * @return Returns 0: inactive, 1: active, 2: activating, 3: deactivating
563     * @since 7
564     * @syscap SystemCapability.Communication.WiFi.STA
565     * @permission ohos.permission.GET_WIFI_INFO
566     */
567    function on(type: "wifiStateChange", callback: Callback<number>): void;
568
569    /**
570     * Unsubscribe Wi-Fi status change events.
571     *
572     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
573     *
574     * @since 7
575     * @syscap SystemCapability.Communication.WiFi.STA
576     * @permission ohos.permission.GET_WIFI_INFO
577     */
578    function off(type: "wifiStateChange", callback?: Callback<number>): void;
579
580    /**
581     * Subscribe Wi-Fi connection change events.
582     *
583     * @return Returns 0: disconnected, 1: connected
584     * @since 7
585     * @syscap SystemCapability.Communication.WiFi.STA
586     * @permission ohos.permission.GET_WIFI_INFO
587     */
588    function on(type: "wifiConnectionChange", callback: Callback<number>): void;
589
590    /**
591     * Unsubscribe Wi-Fi connection change events.
592     *
593     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
594     *
595     * @since 7
596     * @syscap SystemCapability.Communication.WiFi.STA
597     * @permission ohos.permission.GET_WIFI_INFO
598     */
599    function off(type: "wifiConnectionChange", callback?: Callback<number>): void;
600
601    /**
602     * Subscribe Wi-Fi scan status change events.
603     *
604     * @return Returns 0: scan fail, 1: scan success
605     * @since 7
606     * @syscap SystemCapability.Communication.WiFi.STA
607     * @permission ohos.permission.GET_WIFI_INFO
608     */
609    function on(type: "wifiScanStateChange", callback: Callback<number>): void;
610
611    /**
612     * Unsubscribe Wi-Fi scan status change events.
613     *
614     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
615     *
616     * @since 7
617     * @syscap SystemCapability.Communication.WiFi.STA
618     * @permission ohos.permission.GET_WIFI_INFO
619     */
620    function off(type: "wifiScanStateChange", callback?: Callback<number>): void;
621
622    /**
623     * Subscribe Wi-Fi rssi change events.
624     *
625     * @return Returns RSSI value in dBm
626     * @since 7
627     * @syscap SystemCapability.Communication.WiFi.STA
628     * @permission ohos.permission.GET_WIFI_INFO
629     */
630    function on(type: "wifiRssiChange", callback: Callback<number>): void;
631
632    /**
633     * Unsubscribe Wi-Fi rssi change events.
634     *
635     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
636     *
637     * @since 7
638     * @syscap SystemCapability.Communication.WiFi.STA
639     * @permission ohos.permission.GET_WIFI_INFO
640     */
641    function off(type: "wifiRssiChange", callback?: Callback<number>): void;
642
643    /**
644     * Subscribe Wi-Fi stream change events.
645     *
646     * @return Returns 0: stream none, 1: stream down, 2: stream up, 3: stream bidirectional
647     * @since 7
648     * @syscap SystemCapability.Communication.WiFi.STA
649     * @permission ohos.permission.MANAGE_WIFI_CONNECTION
650     * @systemapi Hide this for inner system use.
651     */
652     function on(type: "streamChange", callback: Callback<number>): void;
653
654     /**
655      * Unsubscribe Wi-Fi stream change events.
656      *
657      * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
658      *
659      * @since 7
660      * @syscap SystemCapability.Communication.WiFi.STA
661      * @permission ohos.permission.MANAGE_WIFI_CONNECTION
662      * @systemapi Hide this for inner system use.
663      */
664     function off(type: "streamChange", callback?: Callback<number>): void;
665
666    /**
667     * Subscribe Wi-Fi hotspot state change events.
668     *
669     * @return Returns 0: inactive, 1: active, 2: activating, 3: deactivating
670     * @since 7
671     * @syscap SystemCapability.Communication.WiFi.AP.Core
672     * @permission ohos.permission.GET_WIFI_INFO
673     */
674    function on(type: "hotspotStateChange", callback: Callback<number>): void;
675
676    /**
677     * Unsubscribe Wi-Fi hotspot state change events.
678     *
679     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
680     *
681     * @since 7
682     * @syscap SystemCapability.Communication.WiFi.AP.Core
683     * @permission ohos.permission.GET_WIFI_INFO
684     */
685    function off(type: "hotspotStateChange", callback?: Callback<number>): void;
686
687    /**
688     * Subscribe Wi-Fi hotspot sta join events.
689     *
690     * @return Returns StationInfo
691     * @since 7
692     * @syscap SystemCapability.Communication.WiFi.AP.Core
693     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
694     * @systemapi Hide this for inner system use.
695     */
696    function on(type: "hotspotStaJoin", callback: Callback<StationInfo>): void;
697
698    /**
699     * Unsubscribe Wi-Fi hotspot sta join events.
700     *
701     * <p>All callback functions will be deregistered If there is no specific callback parameter.</p>
702     *
703     * @since 7
704     * @syscap SystemCapability.Communication.WiFi.AP.Core
705     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
706     * @systemapi Hide this for inner system use.
707     */
708    function off(type: "hotspotStaJoin", callback?: Callback<StationInfo>): void;
709
710    /**
711     * Subscribe Wi-Fi hotspot sta leave events.
712     *
713     * @return Returns {@link #StationInfo} object
714     * @since 7
715     * @syscap SystemCapability.Communication.WiFi.AP.Core
716     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
717     * @systemapi Hide this for inner system use.
718     */
719    function on(type: "hotspotStaLeave", callback: Callback<StationInfo>): void;
720
721    /**
722     * Unsubscribe Wi-Fi hotspot sta leave events.
723     *
724     * @return Returns {@link #StationInfo} object
725     * @since 7
726     * @syscap SystemCapability.Communication.WiFi.AP.Core
727     * @permission ohos.permission.MANAGE_WIFI_HOTSPOT
728     * @systemapi Hide this for inner system use.
729     */
730    function off(type: "hotspotStaLeave", callback?: Callback<StationInfo>): void;
731
732    /**
733     * Subscribe P2P status change events.
734     *
735     * @return Returns 1: idle, 2: starting, 3:started, 4: closing, 5: closed
736     * @since 8
737     * @syscap SystemCapability.Communication.WiFi.P2P
738     * @permission ohos.permission.GET_WIFI_INFO
739     */
740    function on(type: "p2pStateChange", callback: Callback<number>): void;
741
742    /**
743     * Unsubscribe P2P status change events.
744     *
745     * @since 8
746     * @syscap SystemCapability.Communication.WiFi.P2P
747     * @permission ohos.permission.GET_WIFI_INFO
748     */
749    function off(type: "p2pStateChange", callback?: Callback<number>): void;
750
751    /**
752     * Subscribe P2P connection change events.
753     *
754     * @return Returns WifiP2pLinkedInfo
755     * @since 8
756     * @syscap SystemCapability.Communication.WiFi.P2P
757     * @permission ohos.permission.GET_WIFI_INFO
758     */
759    function on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void;
760
761    /**
762     * Unsubscribe P2P connection change events.
763     *
764     * @since 8
765     * @syscap SystemCapability.Communication.WiFi.P2P
766     * @permission ohos.permission.GET_WIFI_INFO
767     */
768    function off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): void;
769
770    /**
771     * Subscribe P2P local device change events.
772     *
773     * @return Returns WifiP2pDevice
774     * @since 8
775     * @syscap SystemCapability.Communication.WiFi.P2P
776     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
777     */
778    function on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void;
779
780    /**
781     * Unsubscribe P2P local device change events.
782     *
783     * @return Returns WifiP2pDevice
784     * @since 8
785     * @syscap SystemCapability.Communication.WiFi.P2P
786     * @permission ohos.permission.LOCATION
787     */
788    function off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void;
789
790    /**
791     * Subscribe P2P peer device change events.
792     *
793     * @return Returns WifiP2pDevice[]
794     * @since 8
795     * @syscap SystemCapability.Communication.WiFi.P2P
796     * @permission ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
797     */
798    function on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void;
799
800    /**
801     * Unsubscribe P2P peer device change events.
802     *
803     * @since 8
804     * @syscap SystemCapability.Communication.WiFi.P2P
805     * @permission ohos.permission.LOCATION
806     */
807    function off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): void;
808
809    /**
810     * Subscribe P2P persistent group change events.
811     *
812     * @return Returns void
813     * @since 8
814     * @syscap SystemCapability.Communication.WiFi.P2P
815     * @permission ohos.permission.GET_WIFI_INFO
816     */
817    function on(type: "p2pPersistentGroupChange", callback: Callback<void>): void;
818
819    /**
820     * Unsubscribe P2P persistent group change events.
821     *
822     * @since 8
823     * @syscap SystemCapability.Communication.WiFi.P2P
824     * @permission ohos.permission.GET_WIFI_INFO
825     */
826    function off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void;
827
828    /**
829     * Subscribe P2P discovery events.
830     *
831     * @return Returns 0: initial state, 1: discovery succeeded
832     * @since 8
833     * @syscap SystemCapability.Communication.WiFi.P2P
834     * @permission ohos.permission.GET_WIFI_INFO
835     */
836    function on(type: "p2pDiscoveryChange", callback: Callback<number>): void;
837
838    /**
839     * Unsubscribe P2P discovery events.
840     *
841     * @since 8
842     * @syscap SystemCapability.Communication.WiFi.P2P
843     * @permission ohos.permission.GET_WIFI_INFO
844     */
845    function off(type: "p2pDiscoveryChange", callback?: Callback<number>): void;
846
847    /**
848     * Wi-Fi device configuration information.
849     *
850     * @since 6
851     * @syscap SystemCapability.Communication.WiFi.STA
852     */
853    interface WifiDeviceConfig {
854        /** Wi-Fi SSID: the maximum length is 32 */
855        ssid: string;
856
857        /** Wi-Fi bssid(MAC): the length is 6 */
858        bssid: string;
859
860        /** Wi-Fi key: maximum length is 64 */
861        preSharedKey: string;
862
863        /** Hide SSID or not, false(default): not hide */
864        isHiddenSsid: boolean;
865
866        /** Security type: reference definition of WifiSecurityType */
867        securityType: WifiSecurityType;
868
869        /** The UID of the Wi-Fi configuration creator */
870        /* @systemapi */
871        creatorUid: number;
872
873        /** Disable reason */
874        /* @systemapi */
875        disableReason: number;
876
877        /** Allocated networkId */
878        /* @systemapi */
879        netId: number;
880
881        /** Random mac type */
882        /* @systemapi */
883        randomMacType: number;
884
885        /** Random mac address, the length is 6 */
886        /* @systemapi */
887        randomMacAddr: string;
888
889        /** IP Type */
890        /* @systemapi */
891        ipType: IpType;
892
893        /** IP config of static */
894        /* @systemapi */
895        staticIp: IpConfig;
896    }
897
898    /**
899     * Wi-Fi IP configuration information.
900     *
901     * @since 7
902     * @systemapi Hide this for inner system use.
903     * @syscap SystemCapability.Communication.WiFi.STA
904     */
905    interface IpConfig {
906        ipAddress: number;
907        gateway: number;
908        dnsServers: number[];
909        domains: Array<string>;
910    }
911
912    /**
913     * Describes the scanned Wi-Fi information.
914     *
915     * @since 6
916     * @syscap SystemCapability.Communication.WiFi.STA
917     */
918    interface WifiScanInfo {
919        /** Wi-Fi SSID: the maximum length is 32 */
920        ssid: string;
921
922        /** Wi-Fi bssid(MAC): the length is 6 */
923        bssid: string;
924
925        /** Hotspot capability */
926        capabilities: string;
927
928        /** Security type: reference definition of WifiSecurityType */
929        securityType: WifiSecurityType;
930
931        /** Received signal strength indicator (RSSI) */
932        rssi: number;
933
934        /** Frequency band, 1: 2.4G, 2: 5G */
935        band: number;
936
937        /** Frequency */
938        frequency: number;
939
940        /** Channel width */
941        channelWidth: number;
942
943        /** Time stamp */
944        timestamp: number;
945    }
946
947    /**
948     * Describes the wifi security type.
949     *
950     * @since 6
951     * @syscap SystemCapability.Communication.WiFi.Core
952     */
953    enum WifiSecurityType {
954        /** Invalid security type */
955        WIFI_SEC_TYPE_INVALID = 0,
956
957        /** Open */
958        WIFI_SEC_TYPE_OPEN = 1,
959
960        /** Wired Equivalent Privacy (WEP) */
961        WIFI_SEC_TYPE_WEP = 2,
962
963        /** Pre-shared key (PSK) */
964        WIFI_SEC_TYPE_PSK = 3,
965
966        /** Simultaneous Authentication of Equals (SAE) */
967        WIFI_SEC_TYPE_SAE = 4,
968    }
969
970    /**
971     * Wi-Fi connection information.
972     *
973     * @since 6
974     * @syscap SystemCapability.Communication.WiFi.STA
975     */
976    interface WifiLinkedInfo {
977        /** The SSID of the Wi-Fi hotspot */
978        ssid: string;
979
980        /** The BSSID of the Wi-Fi hotspot */
981        bssid: string;
982
983        /** The ID(uniquely identifies) of a Wi-Fi connection. */
984        /* @systemapi */
985        networkId: number;
986
987        /** The RSSI(dBm) of a Wi-Fi access point. */
988        rssi: number;
989
990        /** The frequency band of a Wi-Fi access point. */
991        band: number;
992
993        /** The speed of a Wi-Fi access point. */
994        linkSpeed: number;
995
996        /** The frequency of a Wi-Fi access point. */
997        frequency: number;
998
999        /** Whether the SSID of the access point (AP) of this Wi-Fi connection is hidden. */
1000        isHidden: boolean;
1001
1002        /** Whether this Wi-Fi connection restricts the data volume. */
1003        isRestricted: boolean;
1004
1005        /** The load value of this Wi-Fi connection. A greater value indicates a higher load. */
1006        /* @systemapi */
1007        chload: number;
1008
1009        /** The signal-to-noise ratio (SNR) of this Wi-Fi connection. */
1010        /* @systemapi */
1011        snr: number;
1012
1013        /** The Wi-Fi MAC address of a device. */
1014        macAddress: string;
1015
1016        /** The IP address of this Wi-Fi connection. */
1017        ipAddress: number;
1018
1019        /** The state of the supplicant of this Wi-Fi connection. */
1020        /* @systemapi */
1021        suppState: SuppState;
1022
1023        /** The state of this Wi-Fi connection. */
1024        connState: ConnState;
1025    }
1026
1027    /**
1028     * Wi-Fi IP information.
1029     *
1030     * @since 7
1031     * @syscap SystemCapability.Communication.WiFi.STA
1032     */
1033    interface IpInfo {
1034        /** The IP address of the Wi-Fi connection */
1035        ipAddress: number;
1036
1037        /** The gateway of the Wi-Fi connection */
1038        gateway: number;
1039
1040        /** The network mask of the Wi-Fi connection */
1041        netmask: number;
1042
1043        /** The primary DNS server IP address of the Wi-Fi connection */
1044        primaryDns: number;
1045
1046        /** The secondary DNS server IP address of the Wi-Fi connection */
1047        secondDns: number;
1048
1049        /** The DHCP server IP address of the Wi-Fi connection */
1050        serverIp: number;
1051
1052        /** The IP address lease duration of the Wi-Fi connection */
1053        leaseDuration: number;
1054    }
1055
1056    /**
1057     * Wi-Fi hotspot configuration information.
1058     *
1059     * @since 7
1060     * @systemapi Hide this for inner system use.
1061     * @syscap SystemCapability.Communication.WiFi.AP.Core
1062     */
1063    interface HotspotConfig {
1064        /** The SSID of the Wi-Fi hotspot */
1065        ssid: string;
1066
1067        /** The encryption mode of the Wi-Fi hotspot */
1068        securityType: WifiSecurityType;
1069
1070        /** The frequency band of the Wi-Fi hotspot */
1071        band: number;
1072
1073        /** The password of the Wi-Fi hotspot */
1074        preSharedKey: string;
1075
1076        /** The maximum number of connections allowed by the Wi-Fi hotspot */
1077        maxConn: number;
1078    }
1079
1080    /**
1081     * Wi-Fi station information.
1082     *
1083     * @since 7
1084     * @systemapi Hide this for inner system use.
1085     * @syscap SystemCapability.Communication.WiFi.AP.Core
1086     */
1087    interface StationInfo {
1088        /** the network name of the Wi-Fi client */
1089        name: string;
1090
1091        /** The MAC address of the Wi-Fi client */
1092        macAddress: string;
1093
1094        /** The IP address of the Wi-Fi client */
1095        ipAddress: string;
1096    }
1097
1098    /**
1099     * Wi-Fi IP type enumeration.
1100     *
1101     * @since 7
1102     * @systemapi Hide this for inner system use.
1103     * @syscap SystemCapability.Communication.WiFi.STA
1104     */
1105     enum IpType {
1106        /** Use statically configured IP settings */
1107        STATIC,
1108
1109        /** Use dynamically configured IP settings */
1110        DHCP,
1111
1112        /** No IP details are assigned */
1113        UNKNOWN,
1114    }
1115
1116    /**
1117     * The state of the supplicant enumeration.
1118     *
1119     * @since 6
1120     * @systemapi Hide this for inner system use.
1121     * @syscap SystemCapability.Communication.WiFi.STA
1122     */
1123    export enum SuppState {
1124        /** The supplicant is not associated with or is disconnected from the AP. */
1125        DISCONNECTED,
1126
1127        /** The network interface is disabled. */
1128        INTERFACE_DISABLED,
1129
1130        /** The supplicant is disabled. */
1131        INACTIVE,
1132
1133        /** The supplicant is scanning for a Wi-Fi connection. */
1134        SCANNING,
1135
1136        /** The supplicant is authenticating with a specified AP. */
1137        AUTHENTICATING,
1138
1139        /** The supplicant is associating with a specified AP. */
1140        ASSOCIATING,
1141
1142        /** The supplicant is associated with a specified AP. */
1143        ASSOCIATED,
1144
1145        /** The four-way handshake is ongoing. */
1146        FOUR_WAY_HANDSHAKE,
1147
1148        /** The group handshake is ongoing. */
1149        GROUP_HANDSHAKE,
1150
1151        /** All authentication is completed. */
1152        COMPLETED,
1153
1154        /** Failed to establish a connection to the supplicant. */
1155        UNINITIALIZED,
1156
1157        /** The supplicant is in an unknown or invalid state. */
1158        INVALID
1159    }
1160
1161    /**
1162     * The state of Wi-Fi connection enumeration.
1163     *
1164     * @since 6
1165     * @syscap SystemCapability.Communication.WiFi.STA
1166     */
1167    export enum ConnState {
1168        /** The device is searching for an available AP. */
1169        SCANNING,
1170
1171        /** The Wi-Fi connection is being set up. */
1172        CONNECTING,
1173
1174        /** The Wi-Fi connection is being authenticated. */
1175        AUTHENTICATING,
1176
1177        /** The IP address of the Wi-Fi connection is being obtained. */
1178        OBTAINING_IPADDR,
1179
1180        /** The Wi-Fi connection has been set up. */
1181        CONNECTED,
1182
1183        /** The Wi-Fi connection is being torn down. */
1184        DISCONNECTING,
1185
1186        /** The Wi-Fi connection has been torn down. */
1187        DISCONNECTED,
1188
1189        /** Failed to set up the Wi-Fi connection. */
1190        UNKNOWN
1191    }
1192
1193    /**
1194     * P2P device information.
1195     *
1196     * @since 8
1197     * @syscap SystemCapability.Communication.WiFi.P2P
1198     */
1199    interface WifiP2pDevice {
1200        /** Device name */
1201        deviceName: string;
1202
1203        /** Device mac address */
1204        deviceAddress: string;
1205
1206        /** Primary device type */
1207        primaryDeviceType: string;
1208
1209        /** Device status */
1210        deviceStatus: P2pDeviceStatus;
1211
1212        /** Device group capabilitys */
1213        groupCapabilitys: number;
1214    }
1215
1216    /**
1217     * P2P config.
1218     *
1219     * @since 8
1220     * @syscap SystemCapability.Communication.WiFi.P2P
1221     */
1222    interface WifiP2PConfig {
1223        /** Device mac address */
1224        deviceAddress: string;
1225
1226        /**
1227         * Group network ID. When creating a group, -1 indicates creates a temporary group,
1228         * -2: indicates creates a persistent group
1229         */
1230        netId: number;
1231
1232        /* The passphrase of this {@code WifiP2pConfig} instance */
1233        passphrase: string;
1234
1235        /** Group name */
1236        groupName: string;
1237
1238        /** Group owner band */
1239        goBand: GroupOwnerBand;
1240    }
1241
1242    /**
1243     * P2P group information.
1244     *
1245     * @since 8
1246     * @syscap SystemCapability.Communication.WiFi.P2P
1247     */
1248    interface WifiP2pGroupInfo {
1249        /** Indicates whether it is group owner */
1250        isP2pGo: boolean;
1251
1252        /** Group owner information */
1253        ownerInfo: WifiP2pDevice;
1254
1255        /** The group passphrase */
1256        passphrase: string;
1257
1258        /** Interface name */
1259        interface: string;
1260
1261        /** Group name */
1262        groupName: string;
1263
1264        /** Network ID */
1265        networkId: number;
1266
1267        /** Frequency */
1268        frequency: number;
1269
1270        /** Client list */
1271        clientDevices: WifiP2pDevice[];
1272
1273        /** Group owner IP address */
1274        goIpAddress: string;
1275    }
1276
1277    /**
1278     * P2P connection status.
1279     *
1280     * @since 8
1281     * @syscap SystemCapability.Communication.WiFi.P2P
1282     */
1283    enum P2pConnectState {
1284        DISCONNECTED = 0,
1285        CONNECTED = 1,
1286    }
1287
1288    /**
1289     * P2P linked information.
1290     *
1291     * @since 8
1292     * @syscap SystemCapability.Communication.WiFi.P2P
1293     */
1294    interface WifiP2pLinkedInfo {
1295        /** Connection status */
1296        connectState: P2pConnectState;
1297
1298        /** Indicates whether it is group owner */
1299        isGroupOwner: boolean;
1300
1301        /** Group owner address */
1302        groupOwnerAddr: string;
1303    }
1304
1305    /**
1306     * P2P device status.
1307     *
1308     * @since 8
1309     * @syscap SystemCapability.Communication.WiFi.P2P
1310     */
1311    enum P2pDeviceStatus {
1312        CONNECTED = 0,
1313        INVITED = 1,
1314        FAILED = 2,
1315        AVAILABLE = 3,
1316        UNAVAILABLE = 4,
1317    }
1318
1319    /**
1320     * P2P group owner band.
1321     *
1322     * @since 8
1323     * @syscap SystemCapability.Communication.WiFi.P2P
1324     */
1325    enum GroupOwnerBand {
1326        GO_BAND_AUTO = 0,
1327        GO_BAND_2GHZ = 1,
1328        GO_BAND_5GHZ = 2,
1329    }
1330}
1331
1332export default wifi;
1333