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