1# WLAN 2 3The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with other devices over WLAN. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10## Modules to Import 11 12```js 13import wifiManager from '@ohos.wifiManager'; 14``` 15 16## wifi.enableWifi<sup>9+</sup> 17 18enableWifi(): void 19 20Enables WLAN. 21 22**System API**: This is a system API. 23 24**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 25 26**System capability**: SystemCapability.Communication.WiFi.STA 27 28**Return value** 29 30 | **Type**| **Description**| 31 | -------- | -------- | 32 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 33 34 35## wifi.disableWifi<sup>9+</sup> 36 37disableWifi(): void 38 39Disables WLAN. 40 41**System API**: This is a system API. 42 43**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 44 45**System capability**: SystemCapability.Communication.WiFi.STA 46 47**Return value** 48 49 | **Type**| **Description**| 50 | -------- | -------- | 51 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 52 53 54## wifi.isWifiActive<sup>9+</sup> 55 56isWifiActive(): boolean 57 58Checks whether WLAN is enabled. 59 60**Required permissions**: ohos.permission.GET_WIFI_INFO 61 62**System capability**: SystemCapability.Communication.WiFi.STA 63 64**Return value** 65 66 | **Type**| **Description**| 67 | -------- | -------- | 68 | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| 69 70 71## wifi.scan<sup>9+</sup> 72 73scan(): void 74 75Starts a scan for WLAN. 76 77**Required permissions**: **ohos.permission.SET_WIFI_INFO** and **ohos.permission.LOCATION** 78 79**System capability**: SystemCapability.Communication.WiFi.STA 80 81**Return value** 82 83 | **Type**| **Description**| 84 | -------- | -------- | 85 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 86 87 88## wifi.getScanResults<sup>9+</sup> 89 90getScanResults(): Promise<Array<WifiScanInfo>> 91 92Obtains the scan result. This API uses a promise to return the result. 93 94**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION) 95 96**System capability**: SystemCapability.Communication.WiFi.STA 97 98**Return value** 99 100 | **Type**| **Description**| 101 | -------- | -------- | 102 | Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | Promise used to return the detected hotspots.| 103 104 105## wifi.getScanResults<sup>9+</sup> 106 107getScanResults(callback: AsyncCallback<Array<WifiScanInfo>>): void 108 109Obtains the scan result. This API uses an asynchronous callback to return the result. 110 111**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION) 112 113**System capability**: SystemCapability.Communication.WiFi.STA 114 115**Parameters** 116 117 | **Name**| **Type**| **Mandatory**| **Description**| 118 | -------- | -------- | -------- | -------- | 119 | callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.| 120 121**Example** 122 ```js 123 import wifi from '@ohos.wifi'; 124 125 wifi.getScanInfos((err, result) => { 126 if (err) { 127 console.error("get scan info error"); 128 return; 129 } 130 131 var len = Object.keys(result).length; 132 console.log("wifi received scan info: " + len); 133 for (var i = 0; i < len; ++i) { 134 console.info("ssid: " + result[i].ssid); 135 console.info("bssid: " + result[i].bssid); 136 console.info("capabilities: " + result[i].capabilities); 137 console.info("securityType: " + result[i].securityType); 138 console.info("rssi: " + result[i].rssi); 139 console.info("band: " + result[i].band); 140 console.info("frequency: " + result[i].frequency); 141 console.info("channelWidth: " + result[i].channelWidth); 142 console.info("timestamp: " + result[i].timestamp); 143 } 144 }); 145 146 wifi.getScanInfos().then(result => { 147 var len = Object.keys(result).length; 148 console.log("wifi received scan info: " + len); 149 for (var i = 0; i < len; ++i) { 150 console.info("ssid: " + result[i].ssid); 151 console.info("bssid: " + result[i].bssid); 152 console.info("capabilities: " + result[i].capabilities); 153 console.info("securityType: " + result[i].securityType); 154 console.info("rssi: " + result[i].rssi); 155 console.info("band: " + result[i].band); 156 console.info("frequency: " + result[i].frequency); 157 console.info("channelWidth: " + result[i].channelWidth); 158 console.info("timestamp: " + result[i].timestamp); 159 } 160 }); 161 ``` 162 163 164## WifiScanInfo<sup>9+</sup> 165 166Represents WLAN hotspot information. 167 168**System capability**: SystemCapability.Communication.WiFi.STA 169 170 171| **Name**| **Type**| **Readable**| **Writable**| **Description**| 172| -------- | -------- | -------- | -------- | -------- | 173| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format.| 174| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot.| 175| capabilities | string | Yes| No| Hotspot capabilities.| 176| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| WLAN security type.| 177| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.| 178| band | number | Yes| No| Frequency band of the WLAN access point (AP).| 179| frequency | number | Yes| No| Frequency of the WLAN AP.| 180| channelWidth | number | Yes| No| Channel width of the WLAN AP.| 181| centerFrequency0 | number | Yes| No| Center frequency of the hotspot.| 182| centerFrequency1 | number | Yes| No| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.| 183| infoElems | Array<[WifiInfoElem](#wifiinfoelem9)> | Yes| No| Information elements.| 184| timestamp | number | Yes| No| Timestamp.| 185 186 187## WifiSecurityType<sup>9+</sup> 188 189Enumerates the WLAN security types. 190 191**System capability**: SystemCapability.Communication.WiFi.Core 192 193 194| **Name**| **Value**| **Description**| 195| -------- | -------- | -------- | 196| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.| 197| WIFI_SEC_TYPE_OPEN | 1 | Open security type.| 198| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP).| 199| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK).| 200| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).| 201| WIFI_SEC_TYPE_EAP<sup>9+</sup> | 5 | Extensible Authentication protocol (EAP).| 202| WIFI_SEC_TYPE_EAP_SUITE_B<sup>9+</sup> | 6 | Suite B 192-bit encryption.| 203| WIFI_SEC_TYPE_OWE<sup>9+</sup> | 7 | Opportunistic Wireless Encryption (OWE).| 204| WIFI_SEC_TYPE_WAPI_CERT<sup>9+</sup> | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).| 205| WIFI_SEC_TYPE_WAPI_PSK<sup>9+</sup> | 9 | WAPI-PSK.| 206 207 208## WifiInfoElem<sup>9+</sup> 209 210Represents a WLAN information element. 211 212**System capability**: SystemCapability.Communication.WiFi.STA 213 214 215| **Name**| **Type**| **Readable**| **Writable**| **Description**| 216| -------- | -------- | -------- | -------- | -------- | 217| eid | number | Yes| No| ID of the information element.| 218| content | Uint8Array | Yes| No| Content of the information element.| 219 220 221## WifiChannelWidth<sup>9+</sup> 222 223Enumerates the WLAN channel widths. 224 225**System capability**: SystemCapability.Communication.WiFi.STA 226 227 228| **Name**| **Value**| **Description**| 229| -------- | -------- | -------- | 230| WIDTH_20MHZ | 0 | 20 MHz.| 231| WIDTH_40MHZ | 1 | 40 MHz.| 232| WIDTH_80MHZ | 2 | 80 MHz.| 233| WIDTH_160MHZ | 3 | 160 MHz.| 234| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>.| 235| WIDTH_INVALID | 5 | Invalid value.| 236 237 238## wifi.getScanResultsSync<sup>9+</sup> 239 240getScanResultsSync(): Array<[WifiScanInfo](#wifiscaninfo)> 241 242Obtains the scan result. This API returns the result synchronously. 243 244**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION) 245 246**System capability**: SystemCapability.Communication.WiFi.STA 247 248**Return value** 249 250 | **Type**| **Description**| 251 | -------- | -------- | 252 | Array<[WifiScanInfo](#wifiscaninfo)> | Scan result obtained.| 253 254 255## wifi.addDeviceConfig<sup>9+</sup> 256 257addDeviceConfig(config: WifiDeviceConfig): Promise<number> 258 259Adds network configuration. This API uses a promise to return the result. 260 261**System API**: This is a system API. 262 263**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 264 265**System capability**: SystemCapability.Communication.WiFi.STA 266 267**Parameters** 268 269 | **Name**| **Type**| **Mandatory**| **Description**| 270 | -------- | -------- | -------- | -------- | 271 | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| 272 273**Return value** 274 275 | **Type**| **Description**| 276 | -------- | -------- | 277 | Promise<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.| 278 279## WifiDeviceConfig<sup>9+</sup> 280 281Represents the WLAN configuration. 282 283**System capability**: SystemCapability.Communication.WiFi.STA 284 285 286| **Name**| **Type**| **Readable**| **Writable**| **Description**| 287| -------- | -------- | -------- | -------- | -------- | 288| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| 289| bssid | string | Yes| No| BSSID of the hotspot.| 290| preSharedKey | string | Yes| No| PSK of the hotspot.| 291| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.| 292| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| 293| creatorUid | number | Yes| No| ID of the creator.<br> **System API**: This is a system API.| 294| disableReason | number | Yes| No| Reason for disabling WLAN.<br> **System API**: This is a system API.| 295| netId | number | Yes| No| Network ID.<br> **System API**: This is a system API.| 296| randomMacType | number | Yes| No| Random MAC type.<br> **System API**: This is a system API.| 297| randomMacAddr | string | Yes| No| Random MAC address.<br> **System API**: This is a system API.| 298| ipType | [IpType](#iptype9) | Yes| No| IP address type.<br> **System API**: This is a system API.| 299| staticIp | [IpConfig](#ipconfig9) | Yes| No| Static IP address configuration.<br> **System API**: This is a system API.| 300| eapConfig<sup>9+</sup> | [WifiEapConfig](#wifieapconfig9) | Yes| No| EAP configuration.<br> **System API**: This is a system API.| 301 302 303## IpType<sup>9+</sup> 304 305Enumerates the IP address types. 306 307**System API**: This is a system API. 308 309**System capability**: SystemCapability.Communication.WiFi.STA 310 311 312| Name| Value| Description| 313| -------- | -------- | -------- | 314| STATIC | 0 | Static IP address.| 315| DHCP | 1 | IP address allocated by DHCP.| 316| UNKNOWN | 2 | Not specified.| 317 318 319## IpConfig<sup>9+</sup> 320 321Represents IP configuration information. 322 323**System API**: This is a system API. 324 325**System capability**: SystemCapability.Communication.WiFi.STA 326 327| **Name**| **Type**| **Readable**| **Writable**| **Description**| 328| -------- | -------- | -------- | -------- | -------- | 329| ipAddress | number | Yes| No| IP address.| 330| gateway | number | Yes| No| Gateway.| 331| prefixLength | number | Yes| No| Subnet mask.| 332| dnsServers | number[] | Yes| No| Domain name server (DNS) information.| 333| domains | Array<string> | Yes| No| Domain information.| 334 335 336## WifiEapConfig<sup>9+</sup> 337 338Represents EAP configuration information. 339 340**System API**: This is a system API. 341 342**System capability**: SystemCapability.Communication.WiFi.STA 343 344| **Name**| **Type**| **Readable**| **Writable**| **Description**| 345| -------- | -------- | -------- | -------- | -------- | 346| eapMethod | [EapMethod](#eapmethod9) | Yes| No| EAP authentication method.| 347| phase2Method | [Phase2Method](#phase2method9) | Yes| No| Phase 2 authentication method.| 348| identity | string | Yes| No| Identity Information.| 349| anonymousIdentity | string | Yes| No| Anonymous identity.| 350| password | string | Yes| No| Password.| 351| caCertAliases | string | Yes| No| CA certificate alias.| 352| caPath | string | Yes| No| CA certificate path.| 353| clientCertAliases | string | Yes| No| Client certificate alias.| 354| altSubjectMatch | string | Yes| No| A string to match the alternate subject.| 355| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.| 356| realm | string | Yes| No| Realm for the passpoint credential.| 357| plmn | string | Yes| No| Public land mobile network (PLMN) of the passpoint credential provider.| 358| eapSubId | number | Yes| No| Sub-ID of the SIM card.| 359 360 361## EapMethod<sup>9+</sup> 362 363Enumerates the EAP authentication methods. 364 365**System API**: This is a system API. 366 367**System capability**: SystemCapability.Communication.WiFi.STA 368 369| Name| Value| Description| 370| -------- | -------- | -------- | 371| EAP_NONE | 0 | Not specified.| 372| EAP_PEAP | 1 | PEAP.| 373| EAP_TLS | 2 | TLS.| 374| EAP_TTLS | 3 | TTLS.| 375| EAP_PWD | 4 | Password.| 376| EAP_SIM | 5 | SIM.| 377| EAP_AKA | 6 | AKA.| 378| EAP_AKA_PRIME | 7 | AKA Prime.| 379| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.| 380 381 382## Phase2Method<sup>9+</sup> 383 384Enumerates the Phase 2 authentication methods. 385 386**System API**: This is a system API. 387 388**System capability**: SystemCapability.Communication.WiFi.STA 389 390| Name| Value| Description| 391| -------- | -------- | -------- | 392| PHASE2_NONE | 0 | Not specified.| 393| PHASE2_PAP | 1 | PAP.| 394| PHASE2_MSCHAP | 2 | MS-CHAP.| 395| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.| 396| PHASE2_GTC | 4 | GTC .| 397| PHASE2_SIM | 5 | SIM.| 398| PHASE2_AKA | 6 | AKA.| 399| PHASE2_AKA_PRIME | 7 | AKA Prime.| 400 401 402## wifi.addDeviceConfig<sup>9+</sup> 403 404addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 405 406Adds network configuration. This API uses an asynchronous callback to return the result. 407 408**System API**: This is a system API. 409 410**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 411 412**System capability**: SystemCapability.Communication.WiFi.STA 413 414**Parameters** 415 416 | **Name**| **Type**| **Mandatory**| **Description**| 417 | -------- | -------- | -------- | -------- | 418 | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| 419 | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| 420 421 422## wifi.addCandidateConfig<sup>9+</sup> 423 424addCandidateConfig(config: WifiDeviceConfig): Promise<number> 425 426Adds the configuration of a candidate network. This API uses a promise to return the result. 427 428**Required permissions**: ohos.permission.SET_WIFI_INFO 429 430**System capability**: SystemCapability.Communication.WiFi.STA 431 432**Parameters** 433 434 | **Name**| **Type**| **Mandatory**| **Description**| 435 | -------- | -------- | -------- | -------- | 436 | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| 437 438**Return value** 439 440 | **Type**| **Description**| 441 | -------- | -------- | 442 | Promise<number> | Promise used to return the network configuration ID.| 443 444 445## wifi.addCandidateConfig<sup>9+</sup> 446 447addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 448 449Adds the configuration of a candidate network. This API uses an asynchronous callback to return the result. 450 451**Required permissions**: ohos.permission.SET_WIFI_INFO 452 453**System capability**: SystemCapability.Communication.WiFi.STA 454 455**Parameters** 456 457 | **Name**| **Type**| **Mandatory**| **Description**| 458 | -------- | -------- | -------- | -------- | 459 | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| 460 | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| 461 462 463## wifi.removeCandidateConfig<sup>9+</sup> 464 465removeCandidateConfig(networkId: number): Promise<void> 466 467Removes the configuration of a candidate network. This API uses a promise to return the result. 468 469**Required permissions**: ohos.permission.SET_WIFI_INFO 470 471**System capability**: SystemCapability.Communication.WiFi.STA 472 473**Parameters** 474 475 | **Name**| **Type**| **Mandatory**| **Description**| 476 | -------- | -------- | -------- | -------- | 477 | networkId | number | Yes| ID of the network configuration to remove.| 478 479**Return value** 480 481 | **Type**| **Description**| 482 | -------- | -------- | 483 | Promise<void> | Promise used to return the result.| 484 485 486## wifi.removeCandidateConfig<sup>9+</sup> 487 488removeCandidateConfig(networkId: number, callback: AsyncCallback<void>): void 489 490Removes the configuration of a candidate network. This API uses an asynchronous callback to return the result. 491 492**Required permissions**: ohos.permission.SET_WIFI_INFO 493 494**System capability**: SystemCapability.Communication.WiFi.STA 495 496**Parameters** 497 498 | **Name**| **Type**| **Mandatory**| **Description**| 499 | -------- | -------- | -------- | -------- | 500 | networkId | number | Yes| ID of the network configuration to remove.| 501 | callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, the value of **err** is **0**. If **err** is not **0**, an error has occurred.| 502 503 504## wifi.getCandidateConfigs<sup>9+</sup> 505 506getCandidateConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig)> 507 508Obtains candidate network configuration. 509 510**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 511 512**System capability**: SystemCapability.Communication.WiFi.STA 513 514**Return value** 515 516 | **Type**| **Description**| 517 | -------- | -------- | 518 | Array<[WifiDeviceConfig](#wifideviceconfig)> | Candidate network configuration obtained.| 519 520 521## wifi.connectToCandidateConfig<sup>9+</sup> 522 523connectToCandidateConfig(networkId: number): void 524 525Connects to a candidate network. 526 527**Required permissions**: ohos.permission.SET_WIFI_INFO 528 529**System capability**: SystemCapability.Communication.WiFi.STA 530 531**Parameters** 532 533 | **Name**| **Type**| **Mandatory**| **Description**| 534 | -------- | -------- | -------- | -------- | 535 | networkId | number | Yes| ID of the candidate network configuration.| 536 537 538## wifi.connectToNetwork<sup>9+</sup> 539 540connectToNetwork(networkId: number): void 541 542Connects to the specified network. 543 544**System API**: This is a system API. 545 546**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 547 548**System capability**: SystemCapability.Communication.WiFi.STA 549 550**Parameters** 551 552 | **Name**| **Type**| **Mandatory**| **Description**| 553 | -------- | -------- | -------- | -------- | 554 | networkId | number | Yes| Network configuration ID.| 555 556**Return value** 557 558 | **Type**| **Description**| 559 | -------- | -------- | 560 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 561 562 563## wifi.connectToDevice<sup>9+</sup> 564 565connectToDevice(config: WifiDeviceConfig): void 566 567Connects to the specified network. 568 569**System API**: This is a system API. 570 571**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications) 572 573**System capability**: 574 SystemCapability.Communication.WiFi.STA 575 576**Parameters** 577 578 | **Name**| **Type**| **Mandatory**| **Description**| 579 | -------- | -------- | -------- | -------- | 580 | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.| 581 582**Return value** 583 584 | **Type**| **Description**| 585 | -------- | -------- | 586 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 587 588 589## wifi.disconnect<sup>9+</sup> 590 591disconnect(): void 592 593Disconnects the network. 594 595**System API**: This is a system API. 596 597**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 598 599**System capability**: 600 SystemCapability.Communication.WiFi.STA 601 602**Return value** 603 604 | **Type**| **Description**| 605 | -------- | -------- | 606 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 607 608 609## wifi.getSignalLevel<sup>9+</sup> 610 611getSignalLevel(rssi: number, band: number): number 612 613Obtains the WLAN signal level. 614 615**Required permissions**: ohos.permission.GET_WIFI_INFO 616 617**System capability**: SystemCapability.Communication.WiFi.STA 618 619**Parameters** 620 621 | **Name**| **Type**| **Mandatory**| **Description**| 622 | -------- | -------- | -------- | -------- | 623 | rssi | number | Yes| RSSI of the hotspot, in dBm.| 624 | band | number | Yes| Frequency band of the WLAN AP.| 625 626**Return value** 627 628 | **Type**| **Description**| 629 | -------- | -------- | 630 | number | Signal level obtained. The value range is [0, 4].| 631 632 633## wifi.getLinkedInfo<sup>9+</sup> 634 635getLinkedInfo(): Promise<WifiLinkedInfo> 636 637Obtains WLAN connection information. This API uses a promise to return the result. 638 639**Required permissions**: ohos.permission.GET_WIFI_INFO 640 641**System capability**: SystemCapability.Communication.WiFi.STA 642 643**Return value** 644 645 | Type| Description| 646 | -------- | -------- | 647 | Promise<[WifiLinkedInfo](#wifilinkedinfo)> | Promise used to return the WLAN connection information obtained.| 648 649 650## wifi.getLinkedInfo<sup>9+</sup> 651 652getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void 653 654Obtains WLAN connection information. This API uses an asynchronous callback to return the result. 655 656**Required permissions**: ohos.permission.GET_WIFI_INFO 657 658**System capability**: SystemCapability.Communication.WiFi.STA 659 660**Parameters** 661 662 | Name| Type| Mandatory| Description| 663 | -------- | -------- | -------- | -------- | 664 | callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.| 665 666**Example** 667 ```js 668 import wifi from '@ohos.wifi'; 669 670 wifi.getLinkedInfo((err, data) => { 671 if (err) { 672 console.error("get linked info error"); 673 return; 674 } 675 console.info("get wifi linked info: " + JSON.stringify(data)); 676 }); 677 678 wifi.getLinkedInfo().then(data => { 679 console.info("get wifi linked info: " + JSON.stringify(data)); 680 }).catch(error => { 681 console.info("get linked info error"); 682 }); 683 ``` 684 685 686## WifiLinkedInfo<sup>9+</sup> 687 688Represents the WLAN connection information. 689 690**System capability**: SystemCapability.Communication.WiFi.STA 691 692| Name| Type| Readable| Writable| Description| 693| -------- | -------- | -------- | -------- | -------- | 694| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| 695| bssid | string | Yes| No| BSSID of the hotspot.| 696| networkId | number | Yes| No| Network configuration ID.<br> **System API**: This is a system API.| 697| rssi | number | Yes| No| RSSI of the hotspot, in dBm.| 698| band | number | Yes| No| Frequency band of the WLAN AP.| 699| linkSpeed | number | Yes| No| Speed of the WLAN AP.| 700| frequency | number | Yes| No| Frequency of the WLAN AP.| 701| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.| 702| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.| 703| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.| 704| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.| 705| macType<sup>9+</sup> | number | Yes| No| MAC address type.| 706| macAddress | string | Yes| No| MAC address of the device.| 707| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.| 708| suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br> **System API**: This is a system API.| 709| connState | [ConnState](#connstate) | Yes| No| WLAN connection state.| 710 711 712## ConnState<sup>9+</sup> 713 714Enumerates the WLAN connection states. 715 716**System capability**: SystemCapability.Communication.WiFi.STA 717 718| Name| Value| Description| 719| -------- | -------- | -------- | 720| SCANNING | 0 | The device is scanning for available APs.| 721| CONNECTING | 1 | A WLAN connection is being established.| 722| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.| 723| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.| 724| CONNECTED | 4 | A WLAN connection is established.| 725| DISCONNECTING | 5 | The WLAN connection is being disconnected.| 726| DISCONNECTED | 6 | The WLAN connection is disconnected.| 727| UNKNOWN | 7 | Failed to set up the WLAN connection.| 728 729 730## SuppState<sup>9+</sup> 731 732Enumerates the supplicant states. 733 734**System API**: This is a system API. 735 736**System capability**: SystemCapability.Communication.WiFi.STA 737 738| Name| Value| Description| 739| -------- | -------- | -------- | 740| DISCONNECTED | 0 | The supplicant is disconnected from the AP.| 741| INTERFACE_DISABLED | 1 | The network interface is disabled.| 742| INACTIVE | 2 | The supplicant is inactive.| 743| SCANNING | 3 | The supplicant is scanning for a WLAN connection.| 744| AUTHENTICATING | 4 | The supplicant is being authenticated.| 745| ASSOCIATING | 5 | The supplicant is being associated with an AP.| 746| ASSOCIATED | 6 | The supplicant is associated with an AP.| 747| FOUR_WAY_HANDSHAKE | 7 | A four-way handshake is being performed for the supplicant.| 748| GROUP_HANDSHAKE | 8 | A group handshake is being performed for the supplicant.| 749| COMPLETED | 9 | The authentication is complete.| 750| UNINITIALIZED | 10 | The supplicant failed to set up the connection.| 751| INVALID | 11 | Invalid value.| 752 753 754## wifi.isConnected<sup>9+</sup> 755 756isConnected(): boolean 757 758Checks whether the WLAN is connected. 759 760**Required permissions**: ohos.permission.GET_WIFI_INFO 761 762**System capability**: SystemCapability.Communication.WiFi.STA 763 764**Return value** 765 766 | **Type**| **Description**| 767 | -------- | -------- | 768 | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| 769 770 771## wifi.getSupportedFeatures<sup>9+</sup> 772 773getSupportedFeatures(): number 774 775Obtains the features supported by this device. 776 777**System API**: This is a system API. 778 779**Required permissions**: ohos.permission.GET_WIFI_INFO 780 781**System capability**: SystemCapability.Communication.WiFi.Core 782 783**Return value** 784 785 | **Type**| **Description**| 786 | -------- | -------- | 787 | number | Feature value. | 788 789**Feature IDs** 790 791| Value| Description| 792| -------- | -------- | 793| 0x0001 | WLAN infrastructure mode| 794| 0x0002 | 5 GHz feature| 795| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature| 796| 0x0008 | Wi-Fi Direct| 797| 0x0010 | SoftAP| 798| 0x0040 | Wi-Fi AWare| 799| 0x8000 | WLAN AP/STA concurrency| 800| 0x8000000 | WPA3 Personal (WPA-3 SAE)| 801| 0x10000000 | WPA3-Enterprise Suite B | 802| 0x20000000 | Enhanced open feature| 803 804 805## wifi.isFeatureSupported<sup>9+</sup> 806 807isFeatureSupported(featureId: number): boolean 808 809Checks whether the device supports the specified WLAN feature. 810 811**Required permissions**: ohos.permission.GET_WIFI_INFO 812 813**System capability**: SystemCapability.Communication.WiFi.Core 814 815**Parameters** 816 817 818 | **Name**| **Type**| Mandatory| **Description**| 819 | -------- | -------- | -------- | -------- | 820 | featureId | number | Yes| Feature ID.| 821 822**Return value** 823 824 | **Type**| **Description**| 825 | -------- | -------- | 826 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 827 828 829## wifi.getDeviceMacAddress<sup>9+</sup> 830 831getDeviceMacAddress(): string[] 832 833Obtains the device MAC address. 834 835**System API**: This is a system API. 836 837**Required permissions**: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications) 838 839**System capability**: SystemCapability.Communication.WiFi.STA 840 841**Return value** 842 843 | **Type**| **Description**| 844 | -------- | -------- | 845 | string[] | MAC address obtained.| 846 847 848## wifi.getIpInfo<sup>9+</sup> 849 850getIpInfo(): IpInfo 851 852Obtains IP information. 853 854**Required permissions**: ohos.permission.GET_WIFI_INFO 855 856**System capability**: SystemCapability.Communication.WiFi.STA 857 858**Return value** 859 860 | **Type**| **Description**| 861 | -------- | -------- | 862 | [IpInfo](#ipinfo9) | IP information obtained.| 863 864 865## IpInfo<sup>9+</sup> 866 867Represents IP information. 868 869**System capability**: SystemCapability.Communication.WiFi.STA 870 871| **Name**| **Type**| **Readable**| **Writable**| **Description**| 872| -------- | -------- | -------- | -------- | -------- | 873| ipAddress | number | Yes| No| IP address.| 874| gateway | number | Yes| No| Gateway.| 875| netmask | number | Yes| No| Subnet mask.| 876| primaryDns | number | Yes| No| IP address of the preferred DNS server.| 877| secondDns | number | Yes| No| IP address of the alternate DNS server.| 878| serverIp | number | Yes| No| IP address of the DHCP server.| 879| leaseDuration | number | Yes| No| Lease duration of the IP address.| 880 881 882## wifi.getCountryCode<sup>9+</sup> 883 884getCountryCode(): string 885 886Obtains the country code. 887 888**Required permissions**: ohos.permission.GET_WIFI_INFO 889 890**System capability**: SystemCapability.Communication.WiFi.Core 891 892**Return value** 893 894 | **Type**| **Description**| 895 | -------- | -------- | 896 | string | Country code obtained.| 897 898 899## wifi.reassociate<sup>9+</sup> 900 901reassociate(): void 902 903Re-associates with the network. 904 905**System API**: This is a system API. 906 907**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 908 909**System capability**: SystemCapability.Communication.WiFi.STA 910 911**Return value** 912 913 | **Type**| **Description**| 914 | -------- | -------- | 915 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 916 917 918## wifi.reconnect<sup>9+</sup> 919 920reconnect(): void 921 922Reconnects to the network. 923 924**System API**: This is a system API. 925 926**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 927 928**System capability**: SystemCapability.Communication.WiFi.STA 929 930**Return value** 931 932 | **Type**| **Description**| 933 | -------- | -------- | 934 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 935 936 937## wifi.getDeviceConfigs<sup>9+</sup> 938 939getDeviceConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig)> 940 941Obtains network configuration. 942 943**System API**: This is a system API. 944 945**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.GET_WIFI_CONFIG 946 947**System capability**: SystemCapability.Communication.WiFi.STA 948 949**Return value** 950 951 | **Type**| **Description**| 952 | -------- | -------- | 953 | Array<[WifiDeviceConfig](#wifideviceconfig)> | Array of network configuration obtained.| 954 955 956## wifi.updateNetwork<sup>9+</sup> 957 958updateNetwork(config: WifiDeviceConfig): number 959 960Updates network configuration. 961 962**System API**: This is a system API. 963 964**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 965 966**System capability**: SystemCapability.Communication.WiFi.STA 967 968**Parameters** 969 970 | **Name**| **Type**| **Mandatory**| **Description**| 971 | -------- | -------- | -------- | -------- | 972| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.| 973 974**Return value** 975 976 | **Type**| **Description**| 977 | -------- | -------- | 978 | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| 979 980 981## wifi.disableNetwork<sup>9+</sup> 982 983disableNetwork(netId: number): void 984 985Disables network configuration. 986 987**System API**: This is a system API. 988 989**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 990 991**System capability**: SystemCapability.Communication.WiFi.STA 992 993**Parameters** 994 995 | **Name**| **Type**| **Mandatory**| **Description**| 996 | -------- | -------- | -------- | -------- | 997 | netId | number | Yes| ID of the network configuration to disable.| 998 999**Return value** 1000 1001 | **Type**| **Description**| 1002 | -------- | -------- | 1003 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1004 1005 1006## wifi.removeAllNetwork<sup>9+</sup> 1007 1008removeAllNetwork(): void 1009 1010Removes the configuration of all networks. 1011 1012**System API**: This is a system API. 1013 1014**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1015 1016**System capability**: SystemCapability.Communication.WiFi.STA 1017 1018**Return value** 1019 1020 | **Type**| **Description**| 1021 | -------- | -------- | 1022 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1023 1024 1025## wifi.removeDevice<sup>9+</sup> 1026 1027removeDevice(id: number): void 1028 1029Removes the specified network configuration. 1030 1031**System API**: This is a system API. 1032 1033**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1034 1035**System capability**: SystemCapability.Communication.WiFi.STA 1036 1037**Parameters** 1038 1039 | **Name**| **Type**| **Mandatory**| **Description**| 1040 | -------- | -------- | -------- | -------- | 1041| id | number | Yes| ID of the network configuration to remove.| 1042 1043**Return value** 1044 1045 | **Type**| **Description**| 1046 | -------- | -------- | 1047 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1048 1049 1050## wifi.enableHotspot<sup>9+</sup> 1051 1052enableHotspot(): void 1053 1054Enables this hotspot. 1055 1056**System API**: This is a system API. 1057 1058**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1059 1060**System capability**: SystemCapability.Communication.WiFi.AP.Core 1061 1062**Return value** 1063 1064 | **Type**| **Description**| 1065 | -------- | -------- | 1066 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1067 1068 1069## wifi.disableHotspot<sup>9+</sup> 1070 1071disableHotspot(): void 1072 1073Disables this hotspot. 1074 1075**System API**: This is a system API. 1076 1077**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1078 1079**System capability**: SystemCapability.Communication.WiFi.AP.Core 1080 1081**Return value** 1082 1083 | **Type**| **Description**| 1084 | -------- | -------- | 1085 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1086 1087 1088## wifi.isHotspotDualBandSupported<sup>9+</sup> 1089 1090isHotspotDualBandSupported(): boolean 1091 1092Checks whether the hotspot supports dual band. 1093 1094**System API**: This is a system API. 1095 1096**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1097 1098**System capability**: SystemCapability.Communication.WiFi.AP.Core 1099 1100**Return value** 1101 1102 | **Type**| **Description**| 1103 | -------- | -------- | 1104 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1105 1106 1107## wifi.isHotspotActive<sup>9+</sup> 1108 1109isHotspotActive(): boolean 1110 1111Checks whether this hotspot is active. 1112 1113**System API**: This is a system API. 1114 1115**Required permissions**: ohos.permission.GET_WIFI_INFO 1116 1117**System capability**: SystemCapability.Communication.WiFi.AP.Core 1118 1119**Return value** 1120 1121 | **Type**| **Description**| 1122 | -------- | -------- | 1123 | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| 1124 1125 1126## wifi.setHotspotConfig<sup>9+</sup> 1127 1128setHotspotConfig(config: HotspotConfig): void 1129 1130Sets hotspot configuration. 1131 1132**System API**: This is a system API. 1133 1134**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1135 1136**System capability**: SystemCapability.Communication.WiFi.AP.Core 1137 1138**Parameters** 1139 1140 | **Name**| **Type**| **Mandatory**| **Description**| 1141 | -------- | -------- | -------- | -------- | 1142 | config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| 1143 1144**Return value** 1145 1146 | **Type**| **Description**| 1147 | -------- | -------- | 1148 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1149 1150 1151## HotspotConfig<sup>9+</sup> 1152 1153Represents the hotspot configuration. 1154 1155**System API**: This is a system API. 1156 1157**System capability**: SystemCapability.Communication.WiFi.AP.Core 1158 1159| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1160| -------- | -------- | -------- | -------- | -------- | 1161| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| 1162| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| 1163| band | number | Yes| No| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.| 1164| preSharedKey | string | Yes| No| PSK of the hotspot.| 1165| maxConn | number | Yes| No| Maximum number of connections allowed.| 1166 1167 1168## wifi.getHotspotConfig<sup>9+</sup> 1169 1170getHotspotConfig(): HotspotConfig 1171 1172obtains hotspot configuration. 1173 1174**System API**: This is a system API. 1175 1176**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1177 1178**System capability**: SystemCapability.Communication.WiFi.AP.Core 1179 1180**Return value** 1181 1182 | **Type**| **Description**| 1183 | -------- | -------- | 1184 | [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| 1185 1186 1187## wifi.getStations<sup>9+</sup> 1188 1189getStations(): Array<[StationInfo](#stationinfo9)> 1190 1191Obtains information about the connected stations. 1192 1193**System API**: This is a system API. 1194 1195**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1196 1197**System capability**: SystemCapability.Communication.WiFi.AP.Core 1198 1199**Return value** 1200 1201 | **Type**| **Description**| 1202 | -------- | -------- | 1203 | Array<[StationInfo](#stationinfo9)> | Connected stations obtained.| 1204 1205 1206## StationInfo<sup>9+</sup> 1207 1208Represents the station information. 1209 1210**System API**: This is a system API. 1211 1212**System capability**: SystemCapability.Communication.WiFi.AP.Core 1213 1214| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1215| -------- | -------- | -------- | -------- | -------- | 1216| name | string | Yes| No| Device name.| 1217| macAddress | string | Yes| No| MAC address.| 1218| ipAddress | string | Yes| No| IP address.| 1219 1220 1221## wifi.getP2pLinkedInfo<sup>9+</sup> 1222 1223getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo> 1224 1225Obtains P2P link information. This API uses a promise to return the result. 1226 1227**Required permissions**: ohos.permission.GET_WIFI_INFO 1228 1229**System capability**: SystemCapability.Communication.WiFi.P2P 1230 1231**Return value** 1232 1233 | Type| Description| 1234 | -------- | -------- | 1235 | Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Promise used to return the P2P link information obtained.| 1236 1237 1238 1239## WifiP2pLinkedInfo<sup>9+</sup> 1240 1241Represents the P2P link information. 1242 1243**System capability**: SystemCapability.Communication.WiFi.P2P 1244 1245| Name| Type| Readable| Writable| Description| 1246| -------- | -------- | -------- | -------- | -------- | 1247| connectState | [P2pConnectState](#p2pconnectstate9) | Yes| No| P2P connection state.| 1248| isGroupOwner | boolean | Yes| No| Whether the device is the group owner.| 1249| groupOwnerAddr | string | Yes| No| MAC address of the group. 1250 1251 1252## P2pConnectState<sup>9+</sup> 1253 1254Enumerates the P2P connection states. 1255 1256**System capability**: SystemCapability.Communication.WiFi.P2P 1257 1258| Name| Value| Description| 1259| -------- | -------- | -------- | 1260| DISCONNECTED | 0 | Disconnected.| 1261| CONNECTED | 1 | Connected.| 1262 1263 1264## wifi.getP2pLinkedInfo<sup>9+</sup> 1265 1266getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void 1267 1268Obtains P2P link information. This API uses an asynchronous callback to return the result. 1269 1270**Required permissions**: ohos.permission.GET_WIFI_INFO 1271 1272**System capability**: SystemCapability.Communication.WiFi.P2P 1273 1274**Parameters** 1275 1276 | Name| Type| Mandatory| Description| 1277 | -------- | -------- | -------- | -------- | 1278 | callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.| 1279 1280 1281## wifi.getCurrentGroup<sup>9+</sup> 1282 1283getCurrentGroup(): Promise<WifiP2pGroupInfo> 1284 1285Obtains the current P2P group information. This API uses a promise to return the result. 1286 1287**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1288 1289**System capability**: SystemCapability.Communication.WiFi.P2P 1290 1291**Return value** 1292 1293 | Type| Description| 1294 | -------- | -------- | 1295 | Promise<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Promise used to return the P2P group information obtained.| 1296 1297 1298## wifi.getCurrentGroup<sup>9+</sup> 1299 1300getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void 1301 1302Obtains the current P2P group information. This API uses an asynchronous callback to return the result. 1303 1304**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1305 1306**System capability**: SystemCapability.Communication.WiFi.P2P 1307 1308**Parameters** 1309 1310 | Name| Type| Mandatory| Description| 1311 | -------- | -------- | -------- | -------- | 1312 | callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| 1313 1314 1315## wifi.getP2pPeerDevices<sup>9+</sup> 1316 1317getP2pPeerDevices(): Promise<WifiP2pDevice[]> 1318 1319Obtains the peer device list in the P2P connection. This API uses a promise to return the result. 1320 1321**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1322 1323**System capability**: SystemCapability.Communication.WiFi.P2P 1324 1325**Return value** 1326 1327 | Type| Description| 1328 | -------- | -------- | 1329 | Promise<[WifiP2pDevice[]](#wifip2pdevice9)> | Promise used to return the peer device list.| 1330 1331 1332## wifi.getP2pPeerDevices<sup>9+</sup> 1333 1334getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void 1335 1336Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result. 1337 1338**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1339 1340**System capability**: SystemCapability.Communication.WiFi.P2P 1341 1342**Parameters** 1343 1344 | Name| Type| Mandatory| Description| 1345 | -------- | -------- | -------- | -------- | 1346 | callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.| 1347 1348 1349## WifiP2pDevice<sup>9+</sup> 1350 1351Represents the P2P device information. 1352 1353**System capability**: SystemCapability.Communication.WiFi.P2P 1354 1355| Name| Type| Readable| Writable| Description| 1356| -------- | -------- | -------- | -------- | -------- | 1357| deviceName | string | Yes| No| Device name.| 1358| deviceAddress | string | Yes| No| MAC address of the device.| 1359| primaryDeviceType | string | Yes| No| Type of the primary device.| 1360| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus9) | Yes| No| Device status.| 1361| groupCapabilities | number | Yes| No| Group capabilities.| 1362 1363 1364## P2pDeviceStatus<sup>9+</sup> 1365 1366Enumerates the P2P device states. 1367 1368**System capability**: SystemCapability.Communication.WiFi.P2P 1369 1370| Name| Value| Description| 1371| -------- | -------- | -------- | 1372| CONNECTED | 0 | Connected.| 1373| INVITED | 1 | Invited.| 1374| FAILED | 2 | Failed.| 1375| AVAILABLE | 3 | Available.| 1376| UNAVAILABLE | 4 | Unavailable.| 1377 1378 1379## wifi.getP2pLocalDevice<sup>9+</sup> 1380 1381getP2pLocalDevice(): Promise<WifiP2pDevice> 1382 1383Obtains the local device information in the P2P connection. This API uses a promise to return the result. 1384 1385**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1386 1387**System capability**: SystemCapability.Communication.WiFi.P2P 1388 1389**Return value** 1390 1391 | Type| Description| 1392 | -------- | -------- | 1393 | Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| 1394 1395 1396## wifi.getP2pLocalDevice<sup>9+</sup> 1397 1398getP2pLocalDevice(callback: AsyncCallback<WifiP2pDevice>): void 1399 1400Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result. 1401 1402**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1403 1404**System capability**: SystemCapability.Communication.WiFi.P2P 1405 1406**Parameters** 1407 1408 | Name| Type| Mandatory| Description| 1409 | -------- | -------- | -------- | -------- | 1410 | callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.| 1411 1412 1413## wifi.createGroup<sup>9+</sup> 1414 1415createGroup(config: WifiP2PConfig): void 1416 1417Creates a P2P group. 1418 1419**Required permissions**: ohos.permission.GET_WIFI_INFO 1420 1421**System capability**: SystemCapability.Communication.WiFi.P2P 1422 1423**Parameters** 1424 1425 | **Name**| **Type**| Mandatory| **Description**| 1426 | -------- | -------- | -------- | -------- | 1427 | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration.| 1428 1429**Return value** 1430 1431 | Type| Description| 1432 | -------- | -------- | 1433 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1434 1435 1436## WifiP2PConfig<sup>9+</sup> 1437 1438Represents P2P group configuration. 1439 1440**System capability**: SystemCapability.Communication.WiFi.P2P 1441 1442| Name| Type| Readable| Writable| Description| 1443| -------- | -------- | -------- | -------- | -------- | 1444| deviceAddress | string | Yes| No| Device address.| 1445| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.| 1446| passphrase | string | Yes| No| Passphrase of the group.| 1447| groupName | string | Yes| No| Name of the group.| 1448| goBand | [GroupOwnerBand](#groupownerband9) | Yes| No| Frequency band of the group.| 1449 1450 1451## GroupOwnerBand<sup>9+</sup> 1452 1453Enumerates the P2P group frequency bands. 1454 1455**System capability**: SystemCapability.Communication.WiFi.P2P 1456 1457| Name| Value| Description| 1458| -------- | -------- | -------- | 1459| GO_BAND_AUTO | 0 | Auto.| 1460| GO_BAND_2GHZ | 1 | 2 GHz.| 1461| GO_BAND_5GHZ | 2 | 5 GHz.| 1462 1463 1464## wifi.removeGroup<sup>9+</sup> 1465 1466removeGroup(): void 1467 1468Removes this P2P group. 1469 1470**Required permissions**: ohos.permission.GET_WIFI_INFO 1471 1472**System capability**: SystemCapability.Communication.WiFi.P2P 1473 1474**Return value** 1475 1476 | Type| Description| 1477 | -------- | -------- | 1478 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1479 1480 1481## wifi.p2pConnect<sup>9+</sup> 1482 1483p2pConnect(config: WifiP2PConfig): void 1484 1485Sets up a P2P connection. 1486 1487**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1488 1489**System capability**: SystemCapability.Communication.WiFi.P2P 1490 1491**Parameters** 1492 1493 1494 | **Name**| **Type**| Mandatory| **Description**| 1495 | -------- | -------- | -------- | -------- | 1496 | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration.| 1497 1498**Return value** 1499 1500 | Type| Description| 1501 | -------- | -------- | 1502 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1503 1504 1505**Example** 1506 ```js 1507 import wifi from '@ohos.wifi'; 1508 1509 var recvP2pConnectionChangeFunc = result => { 1510 console.info("p2p connection change receive event: " + JSON.stringify(result)); 1511 wifi.getP2pLinkedInfo((err, data) => { 1512 if (err) { 1513 console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); 1514 return; 1515 } 1516 console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); 1517 }); 1518 } 1519 wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 1520 1521 var recvP2pDeviceChangeFunc = result => { 1522 console.info("p2p device change receive event: " + JSON.stringify(result)); 1523 } 1524 wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 1525 1526 var recvP2pPeerDeviceChangeFunc = result => { 1527 console.info("p2p peer device change receive event: " + JSON.stringify(result)); 1528 wifi.getP2pPeerDevices((err, data) => { 1529 if (err) { 1530 console.error('failed to get peer devices: ' + JSON.stringify(err)); 1531 return; 1532 } 1533 console.info("get peer devices: " + JSON.stringify(data)); 1534 var len = Object.keys(data).length; 1535 for (var i = 0; i < len; ++i) { 1536 if (data[i].deviceName === "my_test_device") { 1537 console.info("p2p connect to test device: " + data[i].deviceAddress); 1538 var config = { 1539 "deviceAddress":data[i].deviceAddress, 1540 "netId":-2, 1541 "passphrase":"", 1542 "groupName":"", 1543 "goBand":0, 1544 } 1545 wifi.p2pConnect(config); 1546 } 1547 } 1548 }); 1549 } 1550 wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 1551 1552 var recvP2pPersistentGroupChangeFunc = () => { 1553 console.info("p2p persistent group change receive event"); 1554 1555 wifi.getCurrentGroup((err, data) => { 1556 if (err) { 1557 console.error('failed to get current group: ' + JSON.stringify(err)); 1558 return; 1559 } 1560 console.info("get current group: " + JSON.stringify(data)); 1561 }); 1562 } 1563 wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 1564 1565 setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); 1566 setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); 1567 setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); 1568 setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); 1569 console.info("start discover devices -> " + wifi.startDiscoverDevices()); 1570 ``` 1571 1572## wifi.p2pCancelConnect<sup>9+</sup> 1573 1574p2pCancelConnect(): void 1575 1576Cancels this P2P connection. 1577 1578**Required permissions**: ohos.permission.GET_WIFI_INFO 1579 1580**System capability**: SystemCapability.Communication.WiFi.P2P 1581 1582**Return value** 1583 1584 | Type| Description| 1585 | -------- | -------- | 1586 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1587 1588 1589## wifi.startDiscoverDevices<sup>9+</sup> 1590 1591startDiscoverDevices(): void 1592 1593Starts to discover devices. 1594 1595**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1596 1597**System capability**: SystemCapability.Communication.WiFi.P2P 1598 1599**Return value** 1600 1601 | Type| Description| 1602 | -------- | -------- | 1603 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1604 1605 1606## wifi.stopDiscoverDevices<sup>9+</sup> 1607 1608stopDiscoverDevices(): void 1609 1610Stops discovering devices. 1611 1612**Required permissions**: ohos.permission.GET_WIFI_INFO 1613 1614**System capability**: SystemCapability.Communication.WiFi.P2P 1615 1616**Return value** 1617 1618 | Type| Description| 1619 | -------- | -------- | 1620 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1621 1622 1623## wifi.deletePersistentGroup<sup>9+</sup> 1624 1625deletePersistentGroup(netId: number): void 1626 1627Deletes a persistent group. 1628 1629**System API**: This is a system API. 1630 1631**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 1632 1633**System capability**: SystemCapability.Communication.WiFi.P2P 1634 1635**Parameters** 1636 1637 1638 | **Name**| **Type**| Mandatory| **Description**| 1639 | -------- | -------- | -------- | -------- | 1640 | netId | number | Yes| ID of the group to delete.| 1641 1642**Return value** 1643 1644 | Type| Description| 1645 | -------- | -------- | 1646 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1647 1648 1649## wifi.getP2pGroups<sup>9+</sup> 1650 1651getP2pGroups(): Promise<Array<WifiP2pGroupInfo>> 1652 1653Obtains information about all P2P groups. This API uses a promise to return the result. 1654 1655**System API**: This is a system API. 1656 1657**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1658 1659**System capability**: SystemCapability.Communication.WiFi.P2P 1660 1661**Return value** 1662 1663 | Type| Description| 1664 | -------- | -------- | 1665 | Promise< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> > | Promise used to return the group information obtained.| 1666 1667 1668## WifiP2pGroupInfo<sup>9+</sup> 1669 1670Represents the P2P group information. 1671 1672**System capability**: SystemCapability.Communication.WiFi.P2P 1673 1674| Name| Type| Readable| Writable| Description| 1675| -------- | -------- | -------- | -------- | -------- | 1676| isP2pGo | boolean | Yes| No| Whether the device is the group owner.| 1677| ownerInfo | [WifiP2pDevice](#wifip2pdevice9) | Yes| No| Device information of the group.| 1678| passphrase | string | Yes| No| Passphrase of the group.| 1679| interface | string | Yes| No| Interface name.| 1680| groupName | string | Yes| No| Group name.| 1681| networkId | number | Yes| No| Network ID.| 1682| frequency | number | Yes| No| Frequency of the group.| 1683| clientDevices | [WifiP2pDevice[]](#wifip2pdevice9) | Yes| No| List of connected devices.| 1684| goIpAddress | string | Yes| No| IP address of the group.| 1685 1686 1687## wifi.getP2pGroups<sup>9+</sup> 1688 1689getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void 1690 1691Obtains information about all P2P groups. This API uses an asynchronous callback to return the result. 1692 1693**System API**: This is a system API. 1694 1695**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 1696 1697**System capability**: SystemCapability.Communication.WiFi.P2P 1698 1699**Parameters** 1700 1701 | Name| Type| Mandatory| Description| 1702 | -------- | -------- | -------- | -------- | 1703 | callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.| 1704 1705 1706## wifi.setDeviceName<sup>9+</sup> 1707 1708setDeviceName(devName: string): void 1709 1710Sets the device name. 1711 1712**System API**: This is a system API. 1713 1714**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1715 1716**System capability**: SystemCapability.Communication.WiFi.P2P 1717 1718**Parameters** 1719 1720 | **Name**| **Type**| **Mandatory**| **Description**| 1721 | -------- | -------- | -------- | -------- | 1722 | devName | string | Yes| Device name to set.| 1723 1724**Return value** 1725 1726 | **Type**| **Description**| 1727 | -------- | -------- | 1728 | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 1729 1730 1731## wifi.on('wifiStateChange')<sup>9+</sup> 1732 1733on(type: "wifiStateChange", callback: Callback<number>): void 1734 1735Registers the WLAN state change events. 1736 1737**Required permissions**: ohos.permission.GET_WIFI_INFO 1738 1739**System capability**: SystemCapability.Communication.WiFi.STA 1740 1741**Parameters** 1742 1743 | **Name**| **Type**| **Mandatory**| **Description**| 1744 | -------- | -------- | -------- | -------- | 1745 | type | string | Yes| Event type. The value is **wifiStateChange**.| 1746 | callback | Callback<number> | Yes| Callback invoked to return the WLAN state.| 1747 1748**WLAN states** 1749 1750| **Value**| **Description**| 1751| -------- | -------- | 1752| 0 | Deactivated| 1753| 1 | Activated| 1754| 2 | Activating| 1755| 3 | Deactivating| 1756 1757 1758## wifi.off('wifiStateChange')<sup>9+</sup> 1759 1760off(type: "wifiStateChange", callback?: Callback<number>): void 1761 1762Unregisters the WLAN state change events. 1763 1764**Required permissions**: ohos.permission.GET_WIFI_INFO 1765 1766**System capability**: SystemCapability.Communication.WiFi.STA 1767 1768**Parameters** 1769 1770 | **Name**| **Type**| **Mandatory**| **Description**| 1771 | -------- | -------- | -------- | -------- | 1772 | type | string | Yes| Event type. The value is **wifiStateChange**.| 1773 | callback | Callback<number> | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 1774 1775**Example** 1776 ```js 1777 import wifi from '@ohos.wifi'; 1778 1779 var recvPowerNotifyFunc = result => { 1780 console.info("Receive power state change event: " + result); 1781 } 1782 1783 // Register an event. 1784 wifi.on("wifiStateChange", recvPowerNotifyFunc); 1785 1786 // Unregister an event. 1787 wifi.off("wifiStateChange", recvPowerNotifyFunc); 1788 ``` 1789 1790 1791## wifi.on('wifiConnectionChange')<sup>7+</sup> 1792 1793on(type: "wifiConnectionChange", callback: Callback<number>): void 1794 1795Registers the WLAN connection state change events. 1796 1797**Required permissions**: ohos.permission.GET_WIFI_INFO 1798 1799**System capability**: SystemCapability.Communication.WiFi.STA 1800 1801**Parameters** 1802 1803 | **Name**| **Type**| **Mandatory**| **Description**| 1804 | -------- | -------- | -------- | -------- | 1805 | type | string | Yes| Event type. The value is **wifiConnectionChange**.| 1806 | callback | Callback<number> | Yes| Callback invoked to return the WLAN connection state.| 1807 1808**WLAN connection states** 1809 1810| **Value**| **Description**| 1811| -------- | -------- | 1812| 0 | Disconnected.| 1813| 1 | Connected.| 1814 1815 1816## wifi.off('wifiConnectionChange')<sup>9+</sup> 1817 1818off(type: "wifiConnectionChange", callback?: Callback<number>): void 1819 1820Unregisters the WLAN connection state change events. 1821 1822**Required permissions**: ohos.permission.GET_WIFI_INFO 1823 1824**System capability**: SystemCapability.Communication.WiFi.STA 1825 1826**Parameters** 1827 1828 | **Name**| **Type**| **Mandatory**| **Description**| 1829 | -------- | -------- | -------- | -------- | 1830 | type | string | Yes| Event type. The value is **wifiConnectionChange**.| 1831 | callback | Callback<number> | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 1832 1833 1834## wifi.on('wifiScanStateChange')<sup>9+</sup> 1835 1836on(type: "wifiScanStateChange", callback: Callback<number>): void 1837 1838Registers the WLAN scan state change events. 1839 1840**Required permissions**: ohos.permission.GET_WIFI_INFO 1841 1842**System capability**: SystemCapability.Communication.WiFi.STA 1843 1844**Parameters** 1845 1846 | **Name**| **Type**| **Mandatory**| **Description**| 1847 | -------- | -------- | -------- | -------- | 1848 | type | string | Yes| Event type. The value is **wifiScanStateChange**.| 1849 | callback | Callback<number> | Yes| Callback invoked to return the WLAN scan state.| 1850 1851**WLAN scan states** 1852 1853| **Value**| **Description**| 1854| -------- | -------- | 1855| 0 | Scan failed.| 1856| 1 | Scan successful.| 1857 1858 1859## wifi.off('wifiScanStateChange')<sup>9+</sup> 1860 1861off(type: "wifiScanStateChange", callback?: Callback<number>): void 1862 1863Unregisters the WLAN scan state change events. 1864 1865**Required permissions**: ohos.permission.GET_WIFI_INFO 1866 1867**System capability**: SystemCapability.Communication.WiFi.STA 1868 1869**Parameters** 1870 1871| **Name**| **Type**| **Mandatory**| **Description**| 1872| -------- | -------- | -------- | -------- | 1873| type | string | Yes| Event type. The value is **wifiScanStateChange**.| 1874| callback | Callback<number> | No| Callback for the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 1875 1876 1877## wifi.on('wifiRssiChange')<sup>9+</sup> 1878 1879on(type: "wifiRssiChange", callback: Callback<number>): void 1880 1881Registers the RSSI change events. 1882 1883**Required permissions**: ohos.permission.GET_WIFI_INFO 1884 1885**System capability**: SystemCapability.Communication.WiFi.STA 1886 1887**Parameters** 1888 1889 | **Name**| **Type**| **Mandatory**| **Description**| 1890 | -------- | -------- | -------- | -------- | 1891 | type | string | Yes| Event type. The value is **wifiRssiChange**.| 1892 | callback | Callback<number> | Yes| Callback invoked to return the RSSI, in dBm.| 1893 1894 1895## wifi.off('wifiRssiChange')<sup>9+</sup> 1896 1897off(type: "wifiRssiChange", callback?: Callback<number>): void 1898 1899Unregisters the RSSI change events. 1900 1901**Required permissions**: ohos.permission.GET_WIFI_INFO 1902 1903**System capability**: SystemCapability.Communication.WiFi.STA 1904 1905**Parameters** 1906 1907 | **Name**| **Type**| **Mandatory**| **Description**| 1908 | -------- | -------- | -------- | -------- | 1909 | type | string | Yes| Event type. The value is **wifiRssiChange**.| 1910| callback | Callback<number> | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 1911 1912 1913## wifi.on('hotspotStateChange')<sup>9+</sup> 1914 1915on(type: "hotspotStateChange", callback: Callback<number>): void 1916 1917Registers the hotspot state change events. 1918 1919**Required permissions**: ohos.permission.GET_WIFI_INFO 1920 1921**System capability**: SystemCapability.Communication.WiFi.AP.Core 1922 1923**Parameters** 1924 1925 | **Name**| **Type**| **Mandatory**| **Description**| 1926 | -------- | -------- | -------- | -------- | 1927 | type | string | Yes| Event type. The value is **hotspotStateChange**.| 1928 | callback | Callback<number> | Yes| Callback invoked to return the hotspot state.| 1929 1930**Hotspot states** 1931 1932| **Value**| **Description**| 1933| -------- | -------- | 1934| 0 | Deactivated| 1935| 1 | Activated| 1936| 2 | Activating| 1937| 3 | Deactivating| 1938 1939 1940## wifi.off('hotspotStateChange')<sup>9+</sup> 1941 1942off(type: "hotspotStateChange", callback?: Callback<number>): void 1943 1944Unregisters the hotspot state change events. 1945 1946**Required permissions**: ohos.permission.GET_WIFI_INFO 1947 1948**System capability**: SystemCapability.Communication.WiFi.AP.Core 1949 1950**Parameters** 1951 1952 | **Name**| **Type**| **Mandatory**| **Description**| 1953 | -------- | -------- | -------- | -------- | 1954 | type | string | Yes| Event type. The value is **hotspotStateChange**.| 1955| callback | Callback<number> | No| Callback for the hotspot state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 1956 1957 1958## wifi.on('p2pStateChange')<sup>9+</sup> 1959 1960on(type: "p2pStateChange", callback: Callback<number>): void 1961 1962Registers the P2P state change events. 1963 1964**Required permissions**: ohos.permission.GET_WIFI_INFO 1965 1966**System capability**: SystemCapability.Communication.WiFi.P2P 1967 1968**Parameters** 1969 1970 | **Name**| **Type**| **Mandatory**| **Description**| 1971 | -------- | -------- | -------- | -------- | 1972 | type | string | Yes| Event type. The value is **p2pStateChange**.| 1973 | callback | Callback<number> | Yes| Callback invoked to return the P2P state.| 1974 1975**P2P states** 1976 1977| **Value**| **Description**| 1978| -------- | -------- | 1979| 1 | Available| 1980| 2 | Opening| 1981| 3 | Opened| 1982| 4 | Closing| 1983| 5 | Closed| 1984 1985## wifi.off('p2pStateChange')<sup>9+</sup> 1986 1987off(type: "p2pStateChange", callback?: Callback<number>): void 1988 1989Unregisters the P2P state change events. 1990 1991**Required permissions**: ohos.permission.GET_WIFI_INFO 1992 1993**System capability**: SystemCapability.Communication.WiFi.P2P 1994 1995**Parameters** 1996 1997 | **Name**| **Type**| **Mandatory**| **Description**| 1998 | -------- | -------- | -------- | -------- | 1999 | type | string | Yes| Event type. The value is **p2pStateChange**.| 2000| callback | Callback<number> | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2001 2002 2003 ## wifi.on('p2pConnectionChange')<sup>9+</sup> 2004 2005on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void 2006 2007Registers the P2P connection state change events. 2008 2009**Required permissions**: ohos.permission.GET_WIFI_INFO 2010 2011**System capability**: SystemCapability.Communication.WiFi.P2P 2012 2013**Parameters** 2014 2015 | **Name**| **Type**| **Mandatory**| **Description**| 2016 | -------- | -------- | -------- | -------- | 2017 | type | string | Yes| Event type. The value is **p2pConnectionChange**.| 2018 | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the P2P connection state.| 2019 2020 2021## wifi.off('p2pConnectionChange')<sup>9+</sup> 2022 2023off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): void 2024 2025Unregisters the P2P connection state change events. 2026 2027**Required permissions**: ohos.permission.GET_WIFI_INFO 2028 2029**System capability**: SystemCapability.Communication.WiFi.P2P 2030 2031**Parameters** 2032 2033 | **Name**| **Type**| **Mandatory**| **Description**| 2034 | -------- | -------- | -------- | -------- | 2035 | type | string | Yes| Event type. The value is **p2pConnectionChange**.| 2036 | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2037 2038 2039## wifi.on('p2pDeviceChange')<sup>9+</sup> 2040 2041on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void 2042 2043Registers the P2P device state change events. 2044 2045**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 2046 2047**System capability**: SystemCapability.Communication.WiFi.P2P 2048 2049**Parameters** 2050 2051 | **Name**| **Type**| **Mandatory**| **Description**| 2052 | -------- | -------- | -------- | -------- | 2053 | type | string | Yes| Event type. The value is **p2pDeviceChange**.| 2054 | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the P2P device state.| 2055 2056 2057## wifi.off('p2pDeviceChange')<sup>9+</sup> 2058 2059off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void 2060 2061Unregisters the P2P device state change events. 2062 2063**Required permissions**: ohos.permission.LOCATION 2064 2065**System capability**: SystemCapability.Communication.WiFi.P2P 2066 2067**Parameters** 2068 2069 | **Name**| **Type**| **Mandatory**| **Description**| 2070 | -------- | -------- | -------- | -------- | 2071 | type | string | Yes| Event type. The value is **p2pDeviceChange**.| 2072 | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2073 2074 2075## wifi.on('p2pPeerDeviceChange')<sup>9+</sup> 2076 2077on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void 2078 2079Registers the P2P peer device state change events. 2080 2081**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION 2082 2083**System capability**: SystemCapability.Communication.WiFi.P2P 2084 2085**Parameters** 2086 2087 | **Name**| **Type**| **Mandatory**| **Description**| 2088 | -------- | -------- | -------- | -------- | 2089 | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| 2090 | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the P2P peer device state.| 2091 2092 2093## wifi.off('p2pPeerDeviceChange')<sup>9+</sup> 2094 2095off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): void 2096 2097Unregisters the P2P peer device state change events. 2098 2099**Required permissions**: ohos.permission.LOCATION 2100 2101**System capability**: SystemCapability.Communication.WiFi.P2P 2102 2103**Parameters** 2104 2105 | **Name**| **Type**| **Mandatory**| **Description**| 2106 | -------- | -------- | -------- | -------- | 2107 | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| 2108 | callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2109 2110 2111## wifi.on('p2pPersistentGroupChange')<sup>9+</sup> 2112 2113on(type: "p2pPersistentGroupChange", callback: Callback<void>): void 2114 2115Registers the P2P persistent group state change events. 2116 2117**Required permissions**: ohos.permission.GET_WIFI_INFO 2118 2119**System capability**: SystemCapability.Communication.WiFi.P2P 2120 2121**Parameters** 2122 2123 | **Name**| **Type**| **Mandatory**| **Description**| 2124 | -------- | -------- | -------- | -------- | 2125 | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| 2126 | callback | Callback<void> | Yes| Callback invoked to return the P2P persistent group state.| 2127 2128 2129## wifi.off('p2pPersistentGroupChange')<sup>9+</sup> 2130 2131off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void 2132 2133Unregisters the P2P persistent group state change events. 2134 2135**Required permissions**: ohos.permission.GET_WIFI_INFO 2136 2137**System capability**: SystemCapability.Communication.WiFi.P2P 2138 2139**Parameters** 2140 2141 | **Name**| **Type**| **Mandatory**| **Description**| 2142 | -------- | -------- | -------- | -------- | 2143 | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| 2144 | callback | Callback<void> | No| Callback for the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2145 2146 2147## wifi.on('p2pDiscoveryChange')<sup>9+</sup> 2148 2149on(type: "p2pDiscoveryChange", callback: Callback<number>): void 2150 2151Registers the P2P device discovery state change events. 2152 2153**Required permissions**: ohos.permission.GET_WIFI_INFO 2154 2155**System capability**: SystemCapability.Communication.WiFi.P2P 2156 2157**Parameters** 2158 2159 | **Name**| **Type**| **Mandatory**| **Description**| 2160 | -------- | -------- | -------- | -------- | 2161 | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| 2162 | callback | Callback<number> | Yes| Callback invoked to return the P2P device discovery state.| 2163 2164**P2P discovered device states** 2165 2166| **Value**| **Description**| 2167| -------- | -------- | 2168| 0 | Initial state.| 2169| 1 | Discovered.| 2170 2171 2172## wifi.off('p2pDiscoveryChange')<sup>9+</sup> 2173 2174off(type: "p2pDiscoveryChange", callback?: Callback<number>): void 2175 2176Unregisters the P2P device discovery state change events. 2177 2178**Required permissions**: ohos.permission.GET_WIFI_INFO 2179 2180**System capability**: SystemCapability.Communication.WiFi.P2P 2181 2182**Parameters** 2183 2184 | **Name**| **Type**| **Mandatory**| **Description**| 2185 | -------- | -------- | -------- | -------- | 2186 | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| 2187 | callback | Callback<number> | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 2188